Charj: Fixed PUPing problem, blocks can overlap...methods do not.
authorJonathan Lifflander <jliffl2@illinois.edu>
Wed, 30 Jun 2010 23:35:26 +0000 (18:35 -0500)
committerJonathan Lifflander <jliffl2@illinois.edu>
Wed, 30 Jun 2010 23:35:26 +0000 (18:35 -0500)
Modified code so the rules do not overlap.

src/langs/charj/src/charj/translator/InitPUPCollector.g

index 994e182b92730ca76bbc6abad9b18a51b08e92b2..1d810f0ee7670102973526d4caa6124587a2e3f7 100644 (file)
@@ -14,19 +14,19 @@ package charj.translator;
 @members {
     Scope currentScope;
     ClassSymbol currentClass = null;
-    boolean inBlock = false;
+    boolean inMethod = false;
 }
 
 topdown
     :   enterClass
-    |   enterBlock
+    |   enterMethod
     |   enterDefaultConstructor
     |   enterMigrationConstructor
     |   varDeclaration
     ;
 
 bottomup
-    :   exitBlock
+    :   exitMethod
     ;
 
 enterClass
@@ -41,40 +41,42 @@ enterClass
     ;
 
 enterDefaultConstructor
-    :    ^((CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL)
-            (^(MODIFIER_LIST .*))? .
-            FORMAL_PARAM_LIST ^(BLOCK .*))
+    :    FORMAL_PARAM_LIST
         {
-            if (currentClass != null) {
+            if (($FORMAL_PARAM_LIST.hasParentOfType(CONSTRUCTOR_DECL) ||
+                 $FORMAL_PARAM_LIST.hasParentOfType(ENTRY_CONSTRUCTOR_DECL)) &&
+                currentClass != null) {
                 currentClass.hasDefaultConstructor = true;
             }
         }
     ;
 
 enterMigrationConstructor
-    :    ^((CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL)
-            (^(MODIFIER_LIST .*))? .
-                ^(FORMAL_PARAM_LIST ^(FORMAL_PARAM_STD_DECL
-                    ^(POINTER_TYPE ^(QUALIFIED_TYPE_IDENT IDENT)) .
-                )) ^(BLOCK .*))
+    :    ^(FORMAL_PARAM_LIST ^(FORMAL_PARAM_STD_DECL
+                ^(POINTER_TYPE ^(QUALIFIED_TYPE_IDENT IDENT)) .
+            ))
         {
-            if (currentClass != null && $IDENT.text.equals("CkMigrateMessage")) {
+            if (($FORMAL_PARAM_LIST.hasParentOfType(CONSTRUCTOR_DECL) ||
+                 $FORMAL_PARAM_LIST.hasParentOfType(ENTRY_CONSTRUCTOR_DECL)) &&
+                currentClass != null && $IDENT.text.equals("CkMigrateMessage")) {
                 currentClass.hasMigrationConstructor = true;
             }
         }
     ;
 
-enterBlock 
-    :   ^(BLOCK .*)
+enterMethod
+    :   ^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL
+            | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*)
         {
-            inBlock = true;
+            inMethod = true;
         }
     ;
 
-exitBlock 
-    :   ^(BLOCK .*)
+exitMethod
+    :   ^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL
+            | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*)
         {
-            inBlock = false;
+            inMethod = false;
         }
     ;
 
@@ -82,12 +84,12 @@ varDeclaration
     :   ^(VAR_DECLARATOR ^(IDENT .*) (expr=.)? )
         {
 
-            if (!inBlock && currentClass != null && $expr != null) {
+            if (!inMethod && currentClass != null && $expr != null) {
                 System.out.println("FOUND EXPR");
                 currentClass.initializers.add(new VariableInitializer($expr, $IDENT));
             }
 
-            if (!inBlock && currentClass != null) {
+            if (!inMethod && currentClass != null) {
                 currentClass.varsToPup.add($IDENT);
             }
         }