1 Anbstract syntax for Java subset that is the target of Mondrian.
2 The syntax has been taken from "The Java Language Specification".
4 (c) Erik Meijer & Arjan van IJzendoorn
8 Major reworking to be usable for the intermeduate (GOO) language
9 for the backend of GHC and to target languauges like Java sucessfully.
17 %************************************************************************
19 \subsection{Java type declararations}
21 %************************************************************************
30 | Field [Modifier] Type Name (Maybe Expr)
31 | Constructor [Modifier] Name [Parameter] [Statement]
32 | Method [Modifier] Type Name [Parameter] [Exception] [Statement]
34 | Interface [Modifier] Name [TypeName] [Decl]
35 | Class [Modifier] Name [TypeName] [TypeName] [Decl]
39 = Parameter [Modifier] Type Name
44 | Return Expr -- This always comes last in a list
45 -- of statements, and it is understood
46 -- you might change this to something
47 -- else (like a variable assignment)
48 -- if this is not top level statements.
50 | ExprStatement Expr -- You are never interested in the result
51 -- of an ExprStatement
52 | Declaration Decl -- variable = inner Field, Class = innerclass
53 | IfThenElse [(Expr,Statement)] (Maybe Statement)
54 | Switch Expr [(Expr, [Statement])] (Maybe [Statement])
63 | InstanceOf Expr Type
64 | Call Expr Name [Expr]
66 | New Type [Expr] (Maybe [Decl]) -- anonymous innerclass
70 = Public | Protected | Private
72 | Abstract | Final | Native | Synchronized | Transient | Volatile
73 deriving (Show, Eq, Ord)
75 -- A type is used to refer in general to the shape of things,
76 -- or a specific class. Never use a name to refer to a class,
95 type PackageName = String -- A package name
96 -- like "java.awt.Button"
98 type Exception = TypeName -- A class name that must be an exception.
100 type TypeName = String -- a fully qualified type name
101 -- like "java.lang.Object".
103 type Name = String -- A class name or method etc,
104 -- at defintion time,
105 -- this generally not a qualified name.
108 = IntLit Int -- Boxed
109 | UIntLit Int -- Unboxed
110 | CharLit Char -- Boxed
111 | UCharLit Char -- Unboxed
115 addModifier :: Modifier -> Decl -> Decl
116 addModifier = \m -> \d ->
118 { Import n -> Import n
119 ; Field ms t n e -> Field (m:ms) t n e
120 ; Constructor ms n as ss -> Constructor (m:ms) n as ss
121 ; Method ms t n as ts ss -> Method (m:ms) t n as ts ss
122 ; Comment ss -> Comment ss
123 ; Interface ms n xs ds -> Interface (m:ms) n xs ds
124 ; Class ms n xs is ds -> Class (m:ms) n xs is ds
127 areSimple :: [Expr] -> Bool
128 areSimple = \es -> all isSimple es
130 isSimple :: Expr -> Bool
133 { Cast t e -> isSimple e
134 ; Access e n -> isSimple e
135 ; Assign l r -> isSimple l && isSimple r
136 ; InstanceOf e t -> isSimple e
137 ; Call e n es -> isSimple e && areSimple es
138 ; Op e1 o e2 -> False
139 ; New n es Nothing -> areSimple es
140 ; New n es (Just ds) -> False