{-- JVM-Bridge -- bridge from FP languages and others to the Java VM Copyright (C) 2001 Ashley Yakeley This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --} module Platform.JavaVM.Types.TypeSig where { import Platform.JavaVM.Types.Text; type TypeSig = JavaString; data ValueType = MkBooleanType | MkByteType | MkCharType | MkShortType | MkIntType | MkLongType | MkFloatType | MkDoubleType | MkObjectType ClassName | MkArrayType ValueType; instance Show ValueType where { show MkBooleanType = "boolean"; show MkByteType = "byte"; show MkCharType = "char"; show MkShortType = "short"; show MkIntType = "int"; show MkLongType = "long"; show MkFloatType = "float"; show MkDoubleType = "double"; show (MkObjectType name) = showJavaString name; show (MkArrayType baseType) = (show baseType) ++ "[]"; }; valueTypeSig :: ValueType -> TypeSig; valueTypeSig MkBooleanType = [toJChar 'Z']; valueTypeSig MkByteType = [toJChar 'B']; valueTypeSig MkCharType = [toJChar 'C']; valueTypeSig MkShortType = [toJChar 'S']; valueTypeSig MkIntType = [toJChar 'I']; valueTypeSig MkLongType = [toJChar 'J']; valueTypeSig MkFloatType = [toJChar 'F']; valueTypeSig MkDoubleType = [toJChar 'D']; valueTypeSig (MkObjectType name) = [toJChar 'L'] ++ name ++ [toJChar ';']; valueTypeSig (MkArrayType baseType) = [toJChar '['] ++ (valueTypeSig baseType); data MemberNameType t = MkMemberNameType { ntName :: MemberName, ntType :: t }; instance (Show t) => Show (MemberNameType t) where { show (MkMemberNameType name t) = (show name) ++ ":" ++ (show t); }; data MemberRef t = MkMemberRef { rClassName :: ClassName, rNameType :: MemberNameType t }; type FieldNameType = MemberNameType ValueType; type FieldRef = MemberRef ValueType; data ReturnType = MkVoidType | MkValueType ValueType; instance Show ReturnType where { show MkVoidType = "void"; show (MkValueType vt) = show vt; }; returnTypeSig :: ReturnType -> TypeSig; returnTypeSig MkVoidType = [toJChar 'V']; returnTypeSig (MkValueType v) = valueTypeSig v; data FunctionType = MkFunctionType { ftArgs :: [ValueType], ftReturns :: ReturnType }; instance Show FunctionType where { show (MkFunctionType args returns) = (show returns) ++ " (" ++ (show args) ++ ")"; }; argumentsTypeSig :: [ValueType] -> TypeSig; argumentsTypeSig args = concat (fmap valueTypeSig args); functionTypeSig :: FunctionType -> TypeSig; functionTypeSig (MkFunctionType args ret) = [toJChar '('] ++ (argumentsTypeSig args) ++ [toJChar ')'] ++ (returnTypeSig ret); type MethodNameType = MemberNameType FunctionType; type MethodRef = MemberRef FunctionType; }