Charj: Modified ANTLR code to change "type" of node when encountering a entry method...
authorJonathan Lifflander <jliffl2@illinois.edu>
Thu, 24 Jun 2010 01:16:57 +0000 (20:16 -0500)
committerJonathan Lifflander <jliffl2@illinois.edu>
Thu, 24 Jun 2010 01:16:57 +0000 (20:16 -0500)
Moved this functionality from the Java code to ANTLR.

src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjASTModifier2.g
src/langs/charj/src/charj/translator/CharjEmitter.g

index f0e81c9c532b7d0e6060714a043cf1f3f7a08ee7..0c73251d27626d8b22c5cd24bfc88cb06a9e7e3d 100644 (file)
@@ -118,6 +118,7 @@ tokens {
     PUP                     = 'pup'             ;
     INITMETHOD              = 'initMethod'      ;
     CTORHELPER              = 'ctorHelper'      ;
+    CHELPER                 = 'constructorHelper';
 
 
     // C++ keywords that aren't used in charj. 
index f26d7968530dbf510b712de1c5f7a1f9fdb134ec..e9d28d1f2be581a252749f93997e5baf2447cc58 100644 (file)
@@ -95,14 +95,14 @@ classScopeDeclaration
     :   ^(d=FUNCTION_METHOD_DECL m=modifierList? g=genericTypeParameterList? 
             ty=type IDENT f=formalParameterList a=domainExpression? 
             b=block?)
-        {
-            if(astmod.isEntry($d.tree))
-                $d.tree.setType(CharjParser.ENTRY_FUNCTION_DECL, "ENTRY_FUNCTION_DECL");
-        }
+        -> {$m.isEntry}? ^(ENTRY_FUNCTION_DECL modifierList? genericTypeParameterList? 
+            type IDENT formalParameterList domainExpression? block?)
+        -> ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? 
+            type IDENT formalParameterList domainExpression? block?)
     |   ^(PRIMITIVE_VAR_DECLARATION m = modifierList? simpleType variableDeclaratorList)
     |   ^(OBJECT_VAR_DECLARATION m = modifierList? objectType variableDeclaratorList)
     |   ^(cd=CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
-            b=block)
+            ^(BLOCK (blockStatement*)))
         {
             astmod.insertHelperRoutineCall($CONSTRUCTOR_DECL.tree);
             astmod.checkForDefaultCtor($CONSTRUCTOR_DECL, $CONSTRUCTOR_DECL.tree);
@@ -111,6 +111,10 @@ classScopeDeclaration
             if(astmod.isEntry($CONSTRUCTOR_DECL.tree))
                 $CONSTRUCTOR_DECL.tree.setType(CharjParser.ENTRY_CONSTRUCTOR_DECL, "ENTRY_CONSTRUCTOR_DECL");
         }
+        -> {$m.isEntry}? ^(ENTRY_CONSTRUCTOR_DECL modifierList? genericTypeParameterList? IDENT formalParameterList 
+            ^(BLOCK ^(EXPR ^(METHOD_CALL CHELPER ARGUMENT_LIST)) blockStatement*))
+        -> ^(CONSTRUCTOR_DECL modifierList? genericTypeParameterList? IDENT formalParameterList 
+            ^(BLOCK ^(EXPR ^(METHOD_CALL CHELPER ARGUMENT_LIST)) blockStatement*))
     ;
     
 interfaceScopeDeclaration
@@ -176,8 +180,8 @@ bound
     :   ^(EXTENDS_BOUND_LIST type+)
     ;
 
-modifierList
-    :   ^(MODIFIER_LIST (localModifier | (am+=accessModifier) | charjModifier | otherModifier)*)
+modifierList returns [boolean isEntry]
+    :   ^(MODIFIER_LIST (localModifier | (am+=accessModifier) | charjModifier {if ($charjModifier.isEntry) {$isEntry = true;}} | otherModifier)*)
         -> {$am == null}? ^(MODIFIER_LIST ^(ACCESS_MODIFIER_LIST 'private') ^(LOCAL_MODIFIER_LIST localModifier*) ^(CHARJ_MODIFIER_LIST charjModifier*) ^(OTHER_MODIFIER_LIST otherModifier*))
         -> ^(MODIFIER_LIST ^(ACCESS_MODIFIER_LIST accessModifier*) ^(LOCAL_MODIFIER_LIST localModifier*) ^(CHARJ_MODIFIER_LIST charjModifier*) ^(OTHER_MODIFIER_LIST otherModifier*)) 
     ;
@@ -194,8 +198,8 @@ accessModifier
     |   PRIVATE
     ;
 
-charjModifier
-    :   ENTRY
+charjModifier returns [boolean isEntry] 
+    :   ENTRY { $isEntry = true; }
     ;
 
 otherModifier
index 42cc64129ba24b2b8099a9c1f09a5ca2b6dfb535..fdf6b7e3c3048b0b3a610dfc30c6e68a9dd66603 100644 (file)
@@ -426,6 +426,7 @@ primaryExpression
         )
     |   parenthesizedExpression
     |   IDENT
+    |   CHELPER
     |   ^(METHOD_CALL primaryExpression genericTypeArgumentList? arguments)
     |   ^(ENTRY_METHOD_CALL primaryExpression genericTypeArgumentList? entryArguments)
     |   explicitConstructorCall
index de0f39ca82210c361c5a9d717d30a14c96b45cbb..529dcad3038c8f47c3060e81679772ff4c408db9 100644 (file)
@@ -814,6 +814,8 @@ primaryExpression
         -> {$parenthesizedExpression.st}
     |   IDENT
         -> {%{$IDENT.text}}
+    |   CHELPER
+        -> {%{"constructorHelper"}}
     |   ^(METHOD_CALL pe=primaryExpression gtal=genericTypeArgumentList? args=arguments)
         -> method_call(primary={$pe.st}, generic_types={$gtal.st}, args={$args.st})
     |   ^(ENTRY_METHOD_CALL pe=primaryExpression gtal=genericTypeArgumentList? args=arguments)