fix symbol resolving code left in CFGBuilder
[charm.git] / src / langs / charj / src / charj / translator / CFGBuilder.g
1
2
3 tree grammar CFGBuilder;
4
5 options {
6     tokenVocab = Charj;
7     ASTLabelType = CharjAST;
8     filter = true;
9 }
10
11 @header {
12 package charj.translator;
13 import java.util.Iterator;
14 }
15
16 @members {
17     SymbolTable symtab;
18     Scope currentScope;
19     ClassSymbol currentClass = null;
20     MethodSymbol currentMethod = null;
21
22     public CFGBuilder(TreeNodeStream input, SymbolTable symtab) {
23         this(input);
24         this.symtab = symtab;
25         this.currentScope = symtab.getDefaultPkg();
26     }
27 }
28
29
30 topdown
31     :   enterClass
32     |   enterMethod
33     |   expression
34     |   assignment
35     ;
36
37 bottomup
38     :   exitClass
39     |   exitMethod
40     ;
41
42 enterMethod
43     :   ^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL)
44             (^(MODIFIER_LIST .*))?
45             (^(GENERIC_TYPE_PARAM_LIST .*))? 
46             type IDENT .*) { currentMethod = (MethodSymbol)$IDENT.def; }
47     |   ^((CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL)
48             (^(MODIFIER_LIST .*))?
49             (^(GENERIC_TYPE_PARAM_LIST .*))? 
50             IDENT .*) { currentMethod = (MethodSymbol)$IDENT.def; }
51     ;
52
53 exitMethod
54     :   ^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL)
55             (^(MODIFIER_LIST .*))?
56             (^(GENERIC_TYPE_PARAM_LIST .*))? 
57             type IDENT .*) { currentMethod = null; }
58     |   ^((CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL)
59             (^(MODIFIER_LIST .*))?
60             (^(GENERIC_TYPE_PARAM_LIST .*))? 
61             IDENT .*) { currentMethod = null; }
62     ;
63
64 enterClass
65     :   ^(TYPE classType IDENT
66             (^('extends' parent=type))?
67             (^('implements' type+))?
68             (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | DIVCON_METHOD_DECL |  PRIMITIVE_VAR_DECLARATION |
69                 OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
70         { currentClass = (ClassSymbol)$IDENT.def.type; }
71     ;
72
73 exitClass
74     :   ^(TYPE classType IDENT
75             (^('extends' parent=type))?
76             (^('implements' type+))?
77             (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | DIVCON_METHOD_DECL |  PRIMITIVE_VAR_DECLARATION |
78                 OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
79         { currentClass = null; }
80     ;
81
82 expression returns [Type type]
83     :   ^(EXPR expr)
84     ;
85
86 assignment
87     :   ^(ASSIGNMENT IDENT expr)
88     ;
89
90 binary_op
91     : ASSIGNMENT
92     | PLUS_EQUALS
93     | MINUS_EQUALS
94     | TIMES_EQUALS
95     | DIVIDE_EQUALS
96     | AND_EQUALS
97     | OR_EQUALS
98     | POWER_EQUALS
99     | MOD_EQUALS
100     | '>>>='
101     | '>>='
102     | '<<='
103     | '?'
104     | OR
105     | AND
106     | BITWISE_OR
107     | POWER
108     | BITWISE_AND
109     | EQUALS
110     | NOT_EQUALS
111     | INSTANCEOF
112     | LTE
113     | GTE
114     | '>>>'
115     | '>>'
116     | GT
117     | '<<'
118     | LT
119     | PLUS
120     | MINUS
121     | TIMES
122     | DIVIDE
123     | MOD
124     ;
125
126 unary_op
127     : UNARY_PLUS
128     | UNARY_MINUS
129     | PRE_INC
130     | PRE_DEC
131     | POST_INC
132     | POST_DEC
133     | TILDE
134     | NOT
135     | CAST_EXPR
136     ;
137
138
139 expr returns [Type type]
140     :   ^(binary_op e1=expr e2=expr)
141     |   ^(unary_op e1=expr) 
142     |   primaryExpression 
143     ;
144
145 primaryExpression
146     :   IDENT 
147     |   THIS 
148     |   SUPER 
149     |   ^((DOT | ARROW) e=expr
150             (   IDENT 
151             |   THIS 
152             |   SUPER 
153             ))
154     |   ^(PAREN_EXPR expression)
155     |   ^(METHOD_CALL e=expr .*)
156     |   ^(ENTRY_METHOD_CALL e=expr .*)
157     |   ^(THIS_CONSTRUCTOR_CALL .*)
158     |   ^(SUPER_CONSTRUCTOR_CALL .*)
159     |   ^(ARRAY_ELEMENT_ACCESS expr expression)
160     |   literal
161     |   ^(NEW t=type .*)
162     |   GETNUMPES
163     |   GETNUMNODES
164     |   GETMYPE
165     |   GETMYNODE
166     |   GETMYRANK
167         |       THISINDEX
168         |       THISPROXY
169     ;
170
171 literal
172     :   (HEX_LITERAL | OCTAL_LITERAL | DECIMAL_LITERAL)
173     |   FLOATING_POINT_LITERAL
174     |   CHARACTER_LITERAL
175     |   STRING_LITERAL
176     |   (TRUE | FALSE)
177     |   NULL
178     ;
179
180 literalVal
181     :   (HEX_LITERAL | OCTAL_LITERAL | DECIMAL_LITERAL)
182     |   FLOATING_POINT_LITERAL
183     |   CHARACTER_LITERAL
184     |   STRING_LITERAL
185     |   (TRUE | FALSE)
186     |   NULL
187     ;
188
189 type
190     :   VOID
191     |   ^(SIMPLE_TYPE t=. .*)
192     |   ^(OBJECT_TYPE 
193             ^(QUALIFIED_TYPE_IDENT (^(IDENT (^(TEMPLATE_INST
194                 (t1=type | lit1=literalVal )*))?))+) .*)
195     |   ^(REFERENCE_TYPE 
196             ^(QUALIFIED_TYPE_IDENT (^(IDENT .*))+) .*)
197     |   ^(PROXY_TYPE 
198             ^(QUALIFIED_TYPE_IDENT (^(IDENT .*))+) .*)
199         |       ^(ARRAY_SECTION_TYPE 
200                         ^(QUALIFIED_TYPE_IDENT (^(IDENT .*))+) .*)
201     |   ^(POINTER_TYPE 
202             ^(QUALIFIED_TYPE_IDENT (^(IDENT (^(TEMPLATE_INST
203                         (t1=type | lit1=literalVal)*))?))+) .*)
204     ;
205
206 classType
207     :   CLASS
208     |   CHARE
209     |   GROUP
210     |   NODEGROUP
211     |   MAINCHARE
212     |   ^(CHARE_ARRAY ARRAY_DIMENSION)
213     ;
214