1module IRTS.Java.ASTBuilding where
5import Language.Java.Syntax hiding (Name)
6import qualified Language.Java.Syntax as J
8toClassType :: J.Type -> ClassType
9toClassType (RefType (ClassRefType ct)) = ct
10toClassType t = error $ "Not a class type: " ++ (show t)
12toRefType :: J.Type -> RefType
13toRefType (RefType rt) = rt
14toRefType t = error $ "Not a ref type: " ++ (show t)
16class InvocationTarget a where
17 (~>) :: a -> String -> [Argument] -> Exp
19instance InvocationTarget ClassType where
20 (~>) (ClassType ts) method args =
21 MethodInv $ TypeMethodCall
23 (concatMap (map fromActType . snd) ts)
27 fromActType (ActualType refType) = refType
29instance InvocationTarget Exp where
30 (~>) exp method args =
31 MethodInv $ PrimaryMethodCall
37instance InvocationTarget J.Type where
38 (~>) t method args = ((toClassType t) ~> method) args
41 call :: a -> [Argument] -> Exp
43instance Callable String where
45 MethodInv $ MethodCall (J.Name [Ident method]) args
47instance Callable Ident where
49 MethodInv $ MethodCall (J.Name [method]) args
51instance Callable J.Name where
53 MethodInv $ MethodCall method args
55(<>) :: Type -> Exp -> Exp
58localVar :: Int -> Ident
59localVar i = Ident $ "loc" ++ show i
61(@!) :: Exp -> Int -> ArrayIndex
63 ArrayIndex target [Lit $ Int (toInteger pos)]
65(@:=) :: Either ArrayIndex Ident -> Exp -> BlockStmt
66(@:=) (Right lhs) rhs =
67 LocalVars [Final] objectType [VarDecl (VarId lhs) (Just $ InitExp rhs)]
69 BlockStmt . ExpStmt $ Assign (ArrayLhs lhs) EqualA rhs
71(~&&~) :: Exp -> Exp -> Exp
72(~&&~) e1 e2 = BinOp e1 CAnd e2
74(~==~) :: Exp -> Exp -> Exp
75(~==~) e1 e2 = BinOp e1 Equal e2
77addToBlock :: [BlockStmt] -> Exp -> [BlockStmt]
78addToBlock blk exp = blk ++ [BlockStmt $ ExpStmt exp]
80jName :: String -> J.Name
81jName n = J.Name [Ident n]
83jConst :: String -> Exp
84jConst = ExpName . jName
86jReturn :: Exp -> BlockStmt
87jReturn = BlockStmt . Return . Just
90jInt = Lit . Int . toInteger
92jString :: String -> Exp
95simpleMethod :: [Modifier] -> Maybe J.Type -> String -> [FormalParam] -> Block -> Decl
96simpleMethod mods t name params body =
97 MemberDecl $ MethodDecl
104 (MethodBody . Just $ body)
106declareFinalObjectArray :: Ident -> Maybe VarInit -> BlockStmt
107declareFinalObjectArray name init =
111 (VarDeclArray . VarId $ name)
115arrayInitExps :: [Exp] -> VarInit
116arrayInitExps = InitArray . ArrayInit . map (InitExp)
118extendWithNull :: [Exp] -> Int -> [Exp]
119extendWithNull exps additionalZeros =
120 exps ++ (replicate additionalZeros (Lit $ Null))
126 (toClassType idrisClosureType)
130 [Public, Final] (Just objectType) "call" []
131 (Block [jReturn body])
135bigInteger :: String -> Exp
139 (toClassType bigIntegerType)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list