Charj : added basic support for automatic puping of pointer types
authorMinas Charalambides <charala1@illinois.edu>
Wed, 26 May 2010 07:34:10 +0000 (02:34 -0500)
committerMinas Charalambides <charala1@illinois.edu>
Wed, 26 May 2010 07:34:10 +0000 (02:34 -0500)
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/PupRoutineCreator.java

index 5dfc8f4d294dc4fb68613ea2ea970385b6724dc3..95191f91eba71e4ec73a6629175d82146d967227 100644 (file)
@@ -67,6 +67,7 @@ tokens {
     THROW                   = 'throw'           ;
     BREAK                   = 'break'           ;
 
+    DOT                     = '.'               ;
     NEW                     = 'new'             ;
     BITWISE_OR              = '|'               ;
     BITWISE_AND             = '&'               ;
@@ -700,7 +701,7 @@ postfixedExpression
         )
         // ... and than the optional things that may follow a primary
         // expression 0 or more times.
-        (   outerDot='.'                 
+        (   outerDot=DOT                 
             // Note: generic type arguments are only valid for method calls,
             // i.e. if there is an argument list
             (   (   genericTypeArgumentList?  
@@ -712,10 +713,10 @@ postfixedExpression
                 )?
             |   THIS
                 ->  ^($outerDot $postfixedExpression THIS)
-            |   s='super' arguments
+            |   s=SUPER arguments
                 ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"] $postfixedExpression arguments)
-            |   (   'super' innerDot='.' IDENT
-                    ->  ^($innerDot ^($outerDot $postfixedExpression 'super') IDENT)
+            |   (   SUPER innerDot=DOT IDENT
+                    ->  ^($innerDot ^($outerDot $postfixedExpression SUPER) IDENT)
                 )
                 (   arguments
                     ->  ^(METHOD_CALL $postfixedExpression arguments)
@@ -736,11 +737,11 @@ primaryExpression
     |   newExpression
     |   qualifiedIdentExpression
     |   genericTypeArgumentList 
-        (   s='super'
+        (   s=SUPER
             (   arguments
                 ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"] genericTypeArgumentList arguments)
             |   IDENT arguments
-                ->  ^(METHOD_CALL ^('.' 'super' IDENT) genericTypeArgumentList arguments)
+                ->  ^(METHOD_CALL ^(DOT SUPER IDENT) genericTypeArgumentList arguments)
             )
         |   IDENT arguments
             ->  ^(METHOD_CALL IDENT genericTypeArgumentList arguments)
@@ -753,13 +754,13 @@ primaryExpression
         (   arguments
             ->  ^(THIS_CONSTRUCTOR_CALL[$t, "THIS_CONSTRUCTOR_CALL"] arguments)
         )?
-    |   s='super' arguments
+    |   s=SUPER arguments
         ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"] arguments)
-    |   (   'super' '.' IDENT
+    |   (   SUPER DOT IDENT
         )
         (   arguments
-            ->  ^(METHOD_CALL ^('.' 'super' IDENT) arguments)
-        |   ->  ^('.' 'super' IDENT)
+            ->  ^(METHOD_CALL ^(DOT SUPER IDENT) arguments)
+        |   ->  ^(DOT SUPER IDENT)
         )
     ;
     
@@ -773,18 +774,18 @@ qualifiedIdentExpression
             ->  ^(METHOD_CALL qualifiedIdentifier arguments)
         |   outerDot='.'
             (   genericTypeArgumentList 
-                (   s='super' arguments
+                (   s=SUPER arguments
                     ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"]
                             qualifiedIdentifier genericTypeArgumentList arguments)
-                |   'super' innerDot='.' IDENT arguments
-                    ->  ^(METHOD_CALL ^($innerDot ^($outerDot qualifiedIdentifier 'super') IDENT)
+                |   SUPER innerDot='.' IDENT arguments
+                    ->  ^(METHOD_CALL ^($innerDot ^($outerDot qualifiedIdentifier SUPER) IDENT)
                             genericTypeArgumentList arguments)
                 |   IDENT arguments
                     ->  ^(METHOD_CALL ^($outerDot qualifiedIdentifier IDENT) genericTypeArgumentList arguments)
                 )
             |   THIS
                 ->  ^($outerDot qualifiedIdentifier THIS)
-            |   s='super' arguments
+            |   s=SUPER arguments
                 ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"] qualifiedIdentifier arguments)
             )
         )?
index a87844470257df290ec4eaa44df1fecb69dfa29b..484cb4816a621603c026861a410cce837b4a5b7e 100644 (file)
@@ -340,7 +340,7 @@ expr
     ;
     
 primaryExpression
-    :   ^(  '.' primaryExpression
+    :   ^(DOT primaryExpression
                 (   IDENT
                 |   THIS
                 |   SUPER
index 81353f56b630147d7ab9280d2e9bbdb0994e839a..06643f6e3eeea0a148463d5ca75dcbe7f2875181 100644 (file)
@@ -639,8 +639,8 @@ expr
     ;
 
 primaryExpression
-    :   ^('.' prim=primaryExpression
-            ( IDENT     -> template(id={$IDENT}, prim={$prim.st}) "<prim>-><id>"
+    :   ^(DOT prim=primaryExpression
+            ( IDENT   -> template(id={$IDENT}, prim={$prim.st}) "<prim>-><id>"
             | THIS    -> template(prim={$prim.st}) "<prim>->this"
             | SUPER   -> template(prim={$prim.st}) "<prim>->super"
             )
index e51d637ac96aaa723ea3d82f656e8dbac8dab231..6cb869742ce965698eacbb5793beddaad4ef9c1f 100644 (file)
@@ -425,7 +425,7 @@ expr
     ;
     
 primaryExpression
-    :   ^(  '.' primaryExpression
+    :   ^(  DOT primaryExpression
                 (   IDENT
                 |   THIS
                 |   SUPER
index 95c778e6b1315acc6b9832fe59e4c6145dbc8c5c..fac6454a39fa9aecf76aa154f7200b72e9be1b78 100644 (file)
@@ -55,30 +55,66 @@ class PupRoutineCreator
 
     protected void varPup(CharjAST idNode)
     {
-        boolean primitive = false;
+        System.out.println("in var pup: " + idNode.getText());
+        int type = -1;
 
         for(CharjAST p = idNode.getParent(); p != null; p = p.getParent())
-            if(p.getType() == CharjParser.PRIMITIVE_VAR_DECLARATION)
-                primitive = true;
-            else if(p.getType() == CharjParser.FUNCTION_METHOD_DECL)
-                break;
-            else if(p.getType() == CharjParser.TYPE)
+        {
+            switch(p.getType())
             {
-                if(primitive)
-                    primitiveVarPup(idNode);
-                else
-                    objectVarPup(idNode);
-                break;
+                case CharjParser.PRIMITIVE_VAR_DECLARATION:
+                    System.out.println("got the type, it's primitive");
+                    type = p.getType();
+                    break;
+                case CharjParser.OBJECT_VAR_DECLARATION:
+                    System.out.println("got the type, it's an object!");
+                    type = p.getChild(0).getType();
+                    break;
+                case CharjParser.FUNCTION_METHOD_DECL:
+                    System.out.println("local var, not puping...");
+                    return;
+                case CharjParser.TYPE:
+                    System.out.println("class member var, puping... type " + type);
+                    switch(type)
+                    {
+                        case CharjParser.REFERENCE_TYPE: System.out.println("found ref");
+                        case CharjParser.PRIMITIVE_VAR_DECLARATION: System.out.println("found simple or ref");
+                            primitiveVarPup(idNode);
+                            break;
+                        case CharjParser.POINTER_TYPE: System.out.println("found pointer");
+                            pointerVarPup(idNode);
+                            break;
+                    }
+                    return;
             }
+        }
+        System.out.println("after for");
     }
 
     protected void primitiveVarPup(CharjAST idNode)
     {
         pupNode.getChild(4).addChild(createNode(CharjParser.EXPR, "EXPR"));
-        pupNode.getChild(4).getChild(0).addChild(createNode(CharjParser.BITWISE_OR, "|"));
-        pupNode.getChild(4).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "p"));
-        pupNode.getChild(4).getChild(0).getChild(0).addChild(idNode.dupNode());
+        
+        int index = pupNode.getChild(4).getChildren().size() - 1;
+
+        pupNode.getChild(4).getChild(index).addChild(createNode(CharjParser.BITWISE_OR, "|"));
+        pupNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.IDENT, "p"));
+        pupNode.getChild(4).getChild(index).getChild(0).addChild(idNode.dupNode());
     }
     
-    protected void objectVarPup(CharjAST varDeclNode){}
+    protected void pointerVarPup(CharjAST idNode)
+    {
+        pupNode.getChild(4).addChild(createNode(CharjParser.EXPR, "EXPR"));
+        
+        int index = pupNode.getChild(4).getChildren().size() - 1;
+
+        pupNode.getChild(4).getChild(index).addChild(createNode(CharjParser.METHOD_CALL, "METHOD_CALL"));
+        pupNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.DOT, "."));
+        pupNode.getChild(4).getChild(index).getChild(0).getChild(0).addChild(idNode.dupNode());
+        pupNode.getChild(4).getChild(index).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "pup"));
+        pupNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.ARGUMENT_LIST, "ARGUMENT_LIST"));
+        pupNode.getChild(4).getChild(index).getChild(0).getChild(1).addChild(createNode(CharjParser.EXPR, "EXPR"));
+        pupNode.getChild(4).getChild(index).getChild(0).getChild(1).getChild(0).addChild(createNode(CharjParser.IDENT, "p"));
+    }
+
 }