Charj : the main chare's default constructor is filled with the
authorMinas Charalambides <charala1@illinois.edu>
Fri, 4 Jun 2010 23:05:13 +0000 (18:05 -0500)
committerMinas Charalambides <charala1@illinois.edu>
Fri, 4 Jun 2010 23:05:13 +0000 (18:05 -0500)
            usual CkArgMsg argument

src/langs/charj/src/charj/translator/AstModifier.java
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/ClassSymbol.java

index 74e2ea817d1bf96292233acb8acfde46829cccc0..7cf13aa5b4f42dd3121164793c1ba1163695769b 100644 (file)
@@ -271,12 +271,12 @@ class AstModifier
             declNode.addChild(c);
     }
 
             declNode.addChild(c);
     }
 
-    private boolean hasDefaultCtor = false;
     private boolean hasMigrationCtor = false;
     private boolean hasMigrationCtor = false;
+    private CharjAST defaultCtor;
 
 
-    protected void checkForDefaultCtor(CharjAST ctordecl)
+    protected void checkForDefaultCtor(CharjAST ctordecl, CharjAST ctordecltree)
     {
     {
-        if(hasDefaultCtor)
+        if(defaultCtor != null)
             return;
 
         CharjAST params = null;
             return;
 
         CharjAST params = null;
@@ -288,7 +288,7 @@ class AstModifier
             }
         }
         if(params.getChildren() == null)
             }
         }
         if(params.getChildren() == null)
-            hasDefaultCtor = true;
+            defaultCtor = ctordecltree;
     }
 
     protected boolean isMigrationCtor(CharjAST ctordecl)
     }
 
     protected boolean isMigrationCtor(CharjAST ctordecl)
@@ -327,18 +327,27 @@ class AstModifier
 
     protected void ensureDefaultCtor(CharjAST typenode)
     {
 
     protected void ensureDefaultCtor(CharjAST typenode)
     {
-        if(hasDefaultCtor)
-            return;
-        
-        CharjAST ctor = createNode(CharjParser.CONSTRUCTOR_DECL, "CONSTRUCTOR_DECL");
-        ctor.addChild(createNode(CharjParser.MODIFIER_LIST, "MODIFIER_LIST"));
-        ctor.getChild(0).addChild(createNode(CharjParser.ACCESS_MODIFIER_LIST, "ACCESS_MODIFIER_LIST"));
-        ctor.getChild(0).getChild(0).addChild(createNode(CharjParser.PUBLIC, "public"));
-        ctor.addChild(typenode.getChild(1).dupNode());
-        ctor.addChild(createNode(CharjParser.FORMAL_PARAM_LIST, "FORMAL_PARAM_LIST"));
-        ctor.addChild(createNode(CharjParser.BLOCK, "BLOCK"));
-
-        typenode.addChild(ctor);
+        if(defaultCtor != null && typenode.getChild(0).getType() == CharjParser.MAINCHARE && defaultCtor.getChild(1).getChildren() == null)
+        {
+            // fill CkMsgArg* argument
+            defaultCtor.getChild(2).addChild(createNode(CharjParser.FORMAL_PARAM_STD_DECL, "FORMAL_PARAM_STD_DECL"));
+            defaultCtor.getChild(2).getChild(0).addChild(createNode(CharjParser.POINTER_TYPE, "POINTER_TYPE"));
+            defaultCtor.getChild(2).getChild(0).getChild(0).addChild(createNode(CharjParser.QUALIFIED_TYPE_IDENT, "QUALIFIED_TYPE_IDENT"));
+            defaultCtor.getChild(2).getChild(0).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "CkArgMsg"));
+            defaultCtor.getChild(2).getChild(0).addChild(createNode(CharjParser.IDENT, "m"));
+        }
+        else if(defaultCtor == null)
+        {
+            CharjAST ctor = createNode(CharjParser.CONSTRUCTOR_DECL, "CONSTRUCTOR_DECL");
+            ctor.addChild(createNode(CharjParser.MODIFIER_LIST, "MODIFIER_LIST"));
+            ctor.getChild(0).addChild(createNode(CharjParser.ACCESS_MODIFIER_LIST, "ACCESS_MODIFIER_LIST"));
+            ctor.getChild(0).getChild(0).addChild(createNode(CharjParser.PUBLIC, "public"));
+            ctor.addChild(typenode.getChild(1).dupNode());
+            ctor.addChild(createNode(CharjParser.FORMAL_PARAM_LIST, "FORMAL_PARAM_LIST"));
+            ctor.addChild(createNode(CharjParser.BLOCK, "BLOCK"));
+
+            typenode.addChild(ctor);
+        }
     }
 
     protected CharjAST ensureMigrationCtor(CharjAST typenode)
     }
 
     protected CharjAST ensureMigrationCtor(CharjAST typenode)
index faa6c93729d37fcf52ceba48b74aa283ff2680f2..cf7b833e198ce659162121ec9eb922fa7d150059 100644 (file)
@@ -115,7 +115,7 @@ classScopeDeclaration
     |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
             b=block)
         {
     |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
             b=block)
         {
-            astmod.checkForDefaultCtor($CONSTRUCTOR_DECL);
+            astmod.checkForDefaultCtor($CONSTRUCTOR_DECL, $CONSTRUCTOR_DECL.tree);
             astmod.checkForMigrationCtor($CONSTRUCTOR_DECL);
             if($m.tree == null)
                 astmod.fillPrivateModifier($CONSTRUCTOR_DECL.tree);
             astmod.checkForMigrationCtor($CONSTRUCTOR_DECL);
             if($m.tree == null)
                 astmod.fillPrivateModifier($CONSTRUCTOR_DECL.tree);
index 3468ef29d922f97ea70c01f3f67e903fd1a28969..42f072a2974c8116ee1379ad73a2855c80a7d187 100644 (file)
@@ -57,6 +57,7 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
         this.usings.add("std::map");
         this.includes.add("iostream");
         this.usings.add("std::cout");
         this.usings.add("std::map");
         this.includes.add("iostream");
         this.usings.add("std::cout");
+        this.usings.add("std::endl");
     }
 
     public Scope getEnclosingScope() {
     }
 
     public Scope getEnclosingScope() {