1 bstract 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
13 %************************************************************************
15 \subsection{Java type declararations}
17 %************************************************************************
26 | Field [Modifier] Type Name (Maybe Expr)
27 | Constructor [Modifier] Name [Parameter] [Statement]
28 -- Add Throws (list of Names)
30 | Method [Modifier] Type Name [Parameter] [Statement]
32 | Interface [Modifier] Name [Name] [Decl]
33 | Class [Modifier] Name [Name] [Name] [Decl]
37 = Parameter [Modifier] Type Name
45 | Declaration Decl -- variable = inner Field, Class = innerclass
46 | IfThenElse [(Expr,Statement)] (Maybe Statement)
47 | Switch Expr [(Expr, [Statement])] (Maybe [Statement])
56 | InstanceOf Expr Type
57 | Call Expr Name [Expr]
59 | New Type [Expr] (Maybe [Decl]) -- anonymous innerclass
60 | NewArray Type [Expr]
64 = Public | Protected | Private
66 | Abstract | Final | Native | Synchronized | Transient | Volatile
67 deriving (Show, Eq, Ord)
75 -- If you want qualified names, use Access <expr> <name>
76 -- Type's are already qualified.
81 | UIntLit Int -- Unboxed
82 | CharLit Char -- Boxed
83 | UCharLit Char -- Unboxed
88 = ObjectType -- Object *
89 | UnboxedIntType -- int
90 | UnboxedCharType -- char
92 data OVar = OVar Name OType
95 addModifier :: Modifier -> Decl -> Decl
96 addModifier = \m -> \d ->
98 { Import n -> Import n
99 ; Field ms t n e -> Field (m:ms) t n e
100 ; Constructor ms n as ss -> Constructor (m:ms) n as ss
101 ; Method ms t n as ss -> Method (m:ms) t n as ss
102 ; Comment ss -> Comment ss
103 ; Interface ms n xs ds -> Interface (m:ms) n xs ds
104 ; Class ms n xs is ds -> Class (m:ms) n xs is ds
107 areSimple :: [Expr] -> Bool
108 areSimple = \es -> all isSimple es
110 isSimple :: Expr -> Bool
113 { Cast t e -> isSimple e
114 ; Access e n -> isSimple e
115 ; Assign l r -> isSimple l && isSimple r
116 ; InstanceOf e t -> isSimple e
117 ; Call e n es -> isSimple e && areSimple es
118 ; Op e1 o e2 -> False
119 ; New n es Nothing -> areSimple es
120 ; New n es (Just ds) -> False