Charj: Fixed initializers. Removed dead code from AstModifier.
authorJonathan Lifflander <jliffl2@illinois.edu>
Wed, 30 Jun 2010 21:33:53 +0000 (16:33 -0500)
committerJonathan Lifflander <jliffl2@illinois.edu>
Wed, 30 Jun 2010 21:33:53 +0000 (16:33 -0500)
src/langs/charj/src/charj/translator/AstModifier.java
src/langs/charj/src/charj/translator/Charj.stg
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/ClassSymbol.java
src/langs/charj/src/charj/translator/InitPUPCollector.g
src/langs/charj/src/charj/translator/Translator.java

index 0593b6532e4e4a89defab79a5fc677c699fcaf08..ffc49cab17f62617975790c4fb5bfcc663013a4d 100644 (file)
@@ -7,381 +7,13 @@ import java.util.*;
 
 class AstModifier
 {
-    private CharjAST pupNode;
-    private CharjAST initNode;
-    private CharjAST migrationCtor;
-    private CharjAST constructorHelper;
-
-    AstModifier()
-    {
-        createPupNode();
-        createInitNode();
-        createCtorHelperNode();
-    }
-
-    protected CharjAST getPupRoutineNode()
-    {
-        return pupNode;
-    }
-
-    protected CharjAST getInitRoutineNode()
-    {
-        return initNode;
-    }
-
-    protected CharjAST getCtorHelperNode()
-    {
-        return constructorHelper;
-    }
+    public AstModifier() { }
 
     private CharjAST createNode(int type, String text)
     {
         return new CharjAST(new CommonToken(type, text));
     }   
 
-    private void createCtorHelperNode()
-    {
-        constructorHelper = createNode(CharjParser.FUNCTION_METHOD_DECL, "FUNCTION_METHOD_DECL");
-        constructorHelper.addChild(createNode(CharjParser.MODIFIER_LIST, "MODIFIER_LIST"));
-        constructorHelper.getChild(0).addChild(createNode(CharjParser.ACCESS_MODIFIER_LIST, "ACCESS_MODIFIER_LIST"));
-        constructorHelper.getChild(0).getChild(0).addChild(createNode(CharjParser.PROTECTED, "protected"));
-        constructorHelper.addChild(createNode(CharjParser.VOID, "void"));
-        constructorHelper.addChild(createNode(CharjParser.IDENT, "constructorHelper"));
-        constructorHelper.addChild(createNode(CharjParser.FORMAL_PARAM_LIST, "FORMAL_PARAM_LIST"));
-        constructorHelper.addChild(createNode(CharjParser.BLOCK, "BLOCK"));
-    }
-    
-    private void createInitNode()
-    {
-        initNode = createNode(CharjParser.FUNCTION_METHOD_DECL, "FUNCTION_METHOD_DECL");
-
-       initNode.addChild(createNode(CharjParser.MODIFIER_LIST, "MODIFIER_LIST"));
-        initNode.addChild(createNode(CharjParser.VOID, "void"));
-        initNode.addChild(createNode(CharjParser.IDENT, "initMethod"));
-        initNode.addChild(createNode(CharjParser.FORMAL_PARAM_LIST, "FORMAL_PARAM_LIST"));
-        initNode.addChild(createNode(CharjParser.BLOCK, "BLOCK"));
-
-        initNode.getChild(0).addChild(createNode(CharjParser.ACCESS_MODIFIER_LIST, "ACCESS_MODIFIER_LIST"));
-        initNode.getChild(0).getChild(0).addChild(createNode(CharjParser.PRIVATE, "private"));
-    }
-
-    private void createPupNode()
-    {
-        pupNode = createNode(CharjParser.FUNCTION_METHOD_DECL, "FUNCTION_METHOD_DECL");
-
-       pupNode.addChild(createNode(CharjParser.MODIFIER_LIST, "MODIFIER_LIST"));
-        pupNode.addChild(createNode(CharjParser.VOID, "void"));
-        pupNode.addChild(createNode(CharjParser.IDENT, "pup"));
-        pupNode.addChild(createNode(CharjParser.FORMAL_PARAM_LIST, "FORMAL_PARAM_LIST"));
-        pupNode.addChild(createNode(CharjParser.BLOCK, "BLOCK"));
-
-        pupNode.getChild(0).addChild(createNode(CharjParser.ACCESS_MODIFIER_LIST, "ACCESS_MODIFIER_LIST"));
-        pupNode.getChild(0).getChild(0).addChild(createNode(CharjParser.PUBLIC, "public"));
-
-        pupNode.getChild(3).addChild(createNode(CharjParser.FORMAL_PARAM_STD_DECL, "FORMAL_PARAM_STD_DECL"));
-        pupNode.getChild(3).getChild(0).addChild(createNode(CharjParser.REFERENCE_TYPE, "REFERENCE_TYPE"));
-        pupNode.getChild(3).getChild(0).getChild(0).addChild(createNode(CharjParser.QUALIFIED_TYPE_IDENT, "QUALIFIED_TYPE_IDENT"));
-        pupNode.getChild(3).getChild(0).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "PUP::er"));
-
-        pupNode.getChild(3).getChild(0).addChild(createNode(CharjParser.IDENT, "p"));
-    }
-
-    protected CharjAST getEnclosingType(CharjAST varDeclNode)
-    {
-        for(CharjAST p = varDeclNode.getParent(); p != null; p = p.getParent())
-            if(p.getType() == CharjParser.TYPE)
-                return p;
-        return null;
-    }         
-
-    protected void varPup(CharjAST idNode)
-    {
-        int type = -1;
-
-        for(CharjAST p = idNode.getParent(); p != null; p = p.getParent())
-        {
-            switch(p.getType())
-            {
-                case CharjParser.PRIMITIVE_VAR_DECLARATION:
-                    //System.out.println("found primitive var: " + idNode.getText());
-                    type = p.getType();
-                    break;
-                case CharjParser.OBJECT_VAR_DECLARATION:
-                    //System.out.println("found object var: " + idNode.getText());
-                    type = p.getChildAfterType(CharjParser.MODIFIER_LIST).getType();
-                    break;
-                case CharjParser.FUNCTION_METHOD_DECL:
-                case CharjParser.BLOCK:
-                case CharjParser.FORMAL_PARAM_LIST:
-                    return;
-                case CharjParser.TYPE:
-                    switch(type)
-                    {
-                        case CharjParser.REFERENCE_TYPE:
-                            //System.out.println("puping a reference type");
-                            break;
-                        case CharjParser.PRIMITIVE_VAR_DECLARATION:
-                            //System.out.println("puping a primitive type");
-                            primitiveVarPup(idNode);
-                            break;
-                        case CharjParser.POINTER_TYPE:
-                            //System.out.println("puping a pointer type");
-                            pointerVarPup(idNode);
-                            break;
-                        case CharjParser.PROXY_TYPE:
-                            //System.out.println("puping a proxy type");
-                            proxyVarPup(idNode);
-                            break;
-                        default:
-                            System.out.println("AstModifier.varPup: unknown type " + idNode);
-                            break;
-                    }
-                    return;
-            }
-        }
-        System.out.println("AstModifier.varPup: could not pup variable " + idNode);
-    }
-
-    protected void primitiveVarPup(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.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 proxyVarPup(CharjAST idNode)
-    {
-        // For now, just do a basic PUP. More complex handling may be needed later.
-        primitiveVarPup(idNode);
-    }
-    
-    private boolean generatedIf = false;
-
-    protected void pointerVarPup(CharjAST idNode)
-    {
-        if(!generatedIf)
-        {
-            generateIf();
-            generatedIf = true;
-        }
-
-        // add stuff to the initMethod routine
-        initNode.getChild(4).addChild(createNode(CharjParser.EXPR, "EXPR"));
-
-        int index = initNode.getChild(4).getChildren().size() - 1;
-
-        initNode.getChild(4).getChild(index).addChild(createNode(CharjParser.ASSIGNMENT, "="));
-        initNode.getChild(4).getChild(index).getChild(0).addChild(idNode.dupNode());
-        initNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.NEW, "new"));
-        initNode.getChild(4).getChild(index).getChild(0).getChild(1).addChild(createNode(CharjParser.OBJECT_TYPE, "OBJECT_TYPE"));
-        initNode.getChild(4).getChild(index).getChild(0).getChild(1).getChild(0).addChild(createNode(CharjParser.QUALIFIED_TYPE_IDENT, "QUALIFIED_TYPE_IDENT"));
-        initNode.getChild(4).getChild(index).getChild(0).getChild(1).getChild(0).getChild(0).addChild(idNode.getParent().getParent().getParent().getChildOfType(CharjParser.POINTER_TYPE).getChild(0).getChild(0).dupTree());
-        initNode.getChild(4).getChild(index).getChild(0).getChild(1).addChild(createNode(CharjParser.ARGUMENT_LIST, "ARGUMENT_LIST"));
-
-        // add stuff to the pup routine
-        pupNode.getChild(4).addChild(createNode(CharjParser.EXPR, "EXPR"));
-
-        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.ARROW, "ARROW"));
-        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"));
-    }
-
-    protected void generateIf()
-    {
-        pupNode.getChild(4).addChild(createNode(CharjParser.IF, "if"));
-        
-        int index = pupNode.getChild(4).getChildren().size() - 1;
-       
-        pupNode.getChild(4).getChild(index).addChild(createNode(CharjParser.PAREN_EXPR, "PAREN_EXPR"));
-        pupNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.EXPR, "EXPR"));
-        pupNode.getChild(4).getChild(index).getChild(0).getChild(0).addChild(createNode(CharjParser.METHOD_CALL, "METHOD_CALL"));
-        pupNode.getChild(4).getChild(index).getChild(0).getChild(0).getChild(0).addChild(createNode(CharjParser.DOT, "."));
-        pupNode.getChild(4).getChild(index).getChild(0).getChild(0).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "p"));
-        pupNode.getChild(4).getChild(index).getChild(0).getChild(0).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "isUnpacking"));
-        pupNode.getChild(4).getChild(index).getChild(0).getChild(0).getChild(0).addChild(createNode(CharjParser.ARGUMENT_LIST, "ARGUMENT_LIST"));
-        pupNode.getChild(4).getChild(index).addChild(createNode(CharjParser.BLOCK, "BLOCK"));
-        pupNode.getChild(4).getChild(index).getChild(1).addChild(createNode(CharjParser.EXPR, "EXPR"));
-        pupNode.getChild(4).getChild(index).getChild(1).getChild(0).addChild(createNode(CharjParser.METHOD_CALL, "METHOD_CALL"));
-        pupNode.getChild(4).getChild(index).getChild(1).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "initMethod"));
-        pupNode.getChild(4).getChild(index).getChild(1).getChild(0).getChild(0).addChild(createNode(CharjParser.ARGUMENT_LIST, "ARGUMENT_LIST"));
-    }
-
-    protected void insertHelperRoutineCall(CharjAST ctordecl)
-    {
-        CharjAST expr = createNode(CharjParser.EXPR, "EXPR");
-        expr.addChild(createNode(CharjParser.METHOD_CALL, "METHOD_CALL"));
-        expr.getChild(0).addChild(createNode(CharjParser.IDENT, "constructorHelper"));
-        expr.getChild(0).addChild(createNode(CharjParser.ARGUMENT_LIST, "ARGUMENT_LIST"));
-
-        ctordecl.getChild(3).insertChild(0, expr);   
-    }
-
-    protected void dealWithInit(CharjAST vardecl)
-    {
-        if(vardecl.getChildCount() > 1) // has an initialization expression
-        {
-            boolean localScope = false;
-            for(CharjAST temp = vardecl; temp != null; temp = temp.getParent())
-                if(temp.getType() == CharjParser.FUNCTION_METHOD_DECL || temp.getType() == CharjParser.CONSTRUCTOR_DECL)
-                {
-                    localScope = true;
-                    break;
-                }
-            if(!localScope)
-            {
-                // add current variable initialization to constructorHelper
-                CharjAST expr = createNode(CharjParser.EXPR, "EXPR");
-                expr.addChild(createNode(CharjParser.ASSIGNMENT, "="));
-                expr.getChild(0).addChild(vardecl.getChild(0).dupNode());
-                expr.getChild(0).addChild(vardecl.getChild(1).getChild(0).dupTree());
-                constructorHelper.getChild(4).addChild(expr);
-            }
-        }
-    }
-
-    private boolean hasMigrationCtor = false;
-    private CharjAST defaultCtor;
-
-    protected void checkForDefaultCtor(CharjAST ctordecl, CharjAST ctordecltree)
-    {
-        if(defaultCtor != null)
-            return;
-
-        CharjAST params = null;
-        for(CharjAST node : ctordecl.getChildren()) {
-            if(node.getType() == CharjParser.FORMAL_PARAM_LIST)
-            {
-                params = node;
-                break;
-            }
-        }
-        if(params.getChildren() == null)
-            defaultCtor = ctordecltree;
-        else 
-            try
-            {
-                if(params.getChildren().size() == 1 && params.getChild(0).getChild(0).getChild(0).getChild(0).getText().equals("CkArgMsg"))
-                    for(CharjAST temp = ctordecl; temp != null; temp = temp.getParent())
-                        if(temp.getType() == CharjParser.TYPE && temp.getChild(0).getType() == CharjParser.MAINCHARE)
-                        {
-                            defaultCtor = ctordecltree;
-                            return;
-                        }
-            }
-            catch(NullPointerException npe)
-            {
-                // argument is a simple type, so one of the getChild(0) calls above returns null
-            }
-    }
-
-    protected boolean isMigrationCtor(CharjAST ctordecl)
-    {
-        CharjAST params = null;
-        for(CharjAST node : ctordecl.getChildren()) {
-            if(node.getType() == CharjParser.FORMAL_PARAM_LIST)
-            {
-                params = node;
-                break;
-            }
-        }
-        
-        if (params == null || params.getChildren() == null) return false;
-        if (params.getChildren().size() != 1) return false;
-        params = params.getChild(0);
-        if (params == null || params.getType() != CharjParser.FORMAL_PARAM_STD_DECL) return false;
-        params = params.getChild(0);
-        if (params == null || params.getType() != CharjParser.POINTER_TYPE) return false ;
-        params = params.getChild(0);
-        if (params == null || params.getType() != CharjParser.QUALIFIED_TYPE_IDENT) return false;
-        params = params.getChild(0);
-        if (params.toString().equals("CkMigrateMessage")) return true;
-        return false;
-
-    }
-
-    protected void checkForMigrationCtor(CharjAST ctordecl)
-    {
-        if(hasMigrationCtor) return;
-        if (isMigrationCtor(ctordecl)) {
-            hasMigrationCtor = true;
-            migrationCtor = ctordecl;
-        }
-    }
-
-    protected void ensureDefaultCtor(CharjAST typenode)
-    {
-        if(defaultCtor != null && typenode.getChild(0).getType() == CharjParser.MAINCHARE && defaultCtor.getChild(2).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)
-        {
-            defaultCtor = createNode(CharjParser.CONSTRUCTOR_DECL, "CONSTRUCTOR_DECL");
-            defaultCtor.addChild(createNode(CharjParser.MODIFIER_LIST, "MODIFIER_LIST"));
-            defaultCtor.getChild(0).addChild(createNode(CharjParser.ACCESS_MODIFIER_LIST, "ACCESS_MODIFIER_LIST"));
-            defaultCtor.getChild(0).getChild(0).addChild(createNode(CharjParser.PUBLIC, "public"));
-            defaultCtor.addChild(typenode.getChild(1).dupNode());
-            defaultCtor.addChild(createNode(CharjParser.FORMAL_PARAM_LIST, "FORMAL_PARAM_LIST"));
-            defaultCtor.addChild(createNode(CharjParser.BLOCK, "BLOCK"));
-
-            insertHelperRoutineCall(defaultCtor);
-
-            if(typenode.getChild(0).getType() == CharjParser.MAINCHARE)
-            {
-                // fill CkMsgArg* argument
-                defaultCtor.getChild(0).addChild(createNode(CharjParser.CHARJ_MODIFIER_LIST, "CHARJ_MODIFIER_LIST"));
-                defaultCtor.getChild(0).getChild(1).addChild(createNode(CharjParser.ENTRY, "entry"));
-                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"));
-            }
-
-            typenode.addChild(defaultCtor);
-        }
-    }
-
-    protected CharjAST ensureMigrationCtor(CharjAST typenode)
-    {
-        if(hasMigrationCtor)
-            return migrationCtor;
-        
-        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.getChild(0).addChild(createNode(CharjParser.CHARJ_MODIFIER_LIST, "CHARJ_MODIFIER_LIST"));
-        ctor.getChild(0).getChild(1).addChild(createNode(CharjParser.ENTRY, "entry"));
-        ctor.addChild(typenode.getChild(1).dupNode());
-        CharjAST args = createNode(CharjParser.FORMAL_PARAM_LIST, "FORMAL_PARAM_LIST");
-        args.addChild(createNode(CharjParser.FORMAL_PARAM_STD_DECL, "FORMAL_PARAM_STD_DECL"));
-        args.getChild(0).addChild(createNode(CharjParser.POINTER_TYPE, "POINTER_TYPE"));
-        args.getChild(0).getChild(0).addChild(createNode(CharjParser.QUALIFIED_TYPE_IDENT, "QUALIFIED_TYPE_IDENT"));
-        args.getChild(0).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "CkMigrateMessage"));
-        args.getChild(0).addChild(createNode(CharjParser.IDENT, "m"));
-        ctor.addChild(args);
-        ctor.addChild(createNode(CharjParser.BLOCK, "BLOCK"));
-        typenode.addChild(ctor);
-        migrationCtor = ctor;
-        return migrationCtor;
-    }
-
     protected void makePointerDereference(CharjAST node)
     {
         CharjAST deref = createNode(CharjParser.POINTER_DEREFERENCE, "POINTER_DEREFERENCE");
index 0b3a75548428e31c1b2eecc756a3ec3e4b05f4b0..14261faa318aa5048aad6463584738d33539d06d 100644 (file)
@@ -189,18 +189,18 @@ void <ident>::constructorHelper()
 >>
 
 
-chareDeclaration_cc(sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor, needsMigration) ::=
+chareDeclaration_cc(sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor, needsMigration, inits) ::=
 <<
 #include "<ident>.decl.h"
-<chareDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor, needsMigration = needsMigration)>
+<chareDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor, needsMigration = needsMigration, inits = inits)>
 #include "<ident>.def.h"
 >>
 
-chareDeclaration_cc_cont(pds, sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor, needsMigration) ::=
+chareDeclaration_cc_cont(pds, sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor, needsMigration, inits) ::=
 <<
 <if(first(pds))>namespace <first(pds)>
 {
-    <chareDeclaration_cc_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor, needsMigration = needsMigration)>
+    <chareDeclaration_cc_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor, needsMigration = needsMigration, inits = inits)>
 } // namespace <first(pds)>
 <else>
 <csds; separator="\n\n">
@@ -230,7 +230,7 @@ void <ident>::pup(PUP::er &p)
 
 void <ident>::constructorHelper()
 {
-
+    <inits; separator="\n">
 }
 
 <if(needsMigration)>
index 834fdb9879d60459811383f66cc2cd3af1e3fbf3..c34570a6a379a4bd8ce0e6c0e2e5f9cd2802199d 100644 (file)
@@ -66,25 +66,15 @@ typeOfType returns [boolean array_type]
 
 typeDeclaration
 @init {
-    boolean array_type = false;
-    CharjAST chelperNode = new CharjAST(new CommonToken(CharjParser.IDENT, "constructorHelper"));
     astmod = new AstModifier();
 }
     :   ^(TYPE typeOfType IDENT
         (^('extends' parent=type))? (^('implements' type+))? classScopeDeclaration*)
         {
-            array_type = $typeOfType.array_type;
-            //$TYPE.tree.addChild(astmod.getPupRoutineNode());
-            //$TYPE.tree.addChild(astmod.getInitRoutineNode());
-            //$TYPE.tree.addChild(astmod.getCtorHelperNode());
-            //astmod.ensureDefaultCtor($TYPE.tree);
-            //if (array_type) astmod.ensureMigrationCtor($TYPE.tree);
         }
         -> ^(TYPE typeOfType IDENT
             (^('extends' type))? (^('implements' type+))? classScopeDeclaration* 
-        ^(FUNCTION_METHOD_DECL 
-            ^(MODIFIER_LIST ^(ACCESS_MODIFIER_LIST PROTECTED) LOCAL_MODIFIER_LIST CHARJ_MODIFIER_LIST OTHER_MODIFIER_LIST)
-            VOID {chelperNode} FORMAL_PARAM_LIST BLOCK))
+        )
     |   ^(INTERFACE IDENT (^('extends' type+))?  interfaceScopeDeclaration*)
     |   ^(ENUM IDENT (^('implements' type+))? enumConstant+ classScopeDeclaration*)
     ;
@@ -126,14 +116,6 @@ classScopeDeclaration
             objectType variableDeclaratorList)
     |   ^(cd=CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
             ^(BLOCK (blockStatement*)))
-        {
-            astmod.insertHelperRoutineCall($CONSTRUCTOR_DECL.tree);
-            astmod.checkForDefaultCtor($CONSTRUCTOR_DECL, $CONSTRUCTOR_DECL.tree);
-            astmod.checkForMigrationCtor($CONSTRUCTOR_DECL);
-
-            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*))
@@ -157,16 +139,10 @@ variableDeclaratorList
 
 variableDeclarator
     :   ^(VAR_DECLARATOR variableDeclaratorId variableInitializer?)
-        {
-            astmod.dealWithInit($VAR_DECLARATOR);
-        }
     ;
     
 variableDeclaratorId
     :   ^(IDENT domainExpression?)
-        {
-            if (!($IDENT.hasParentOfType(CharjParser.READONLY))) astmod.varPup($IDENT);
-        }
     ;
 
 variableInitializer
index 2eca60bb9042bfe16ab22a20785434dfa3b13ac0..0e650cae68c43f25a454b84b4b1abb0a6c132500 100644 (file)
@@ -134,6 +134,7 @@ importDeclaration
 typeDeclaration
 @init {
     boolean needsMigration = false;
+    List<String> initializers = new ArrayList<String>();
 }
     :   ^(TYPE CLASS IDENT (^('extends' su=type))? (^('implements' type+))?
         {
@@ -169,6 +170,10 @@ typeDeclaration
         {
             currentClass = (ClassSymbol)$IDENT.def;
             needsMigration = currentClass.isChareArray && !currentClass.hasMigrationConstructor;
+
+            for (VariableInitializer init : currentClass.initializers) {
+                initializers.add(init.emit());
+            }
         }
         (csds+=classScopeDeclaration)*)
         -> {emitCC()}? chareDeclaration_cc(
@@ -179,7 +184,8 @@ typeDeclaration
                 pupInits={currentClass.generateInits()},
                 pupers={currentClass.generatePUPers()},
                 hasDefaultCtor={currentClass.hasDefaultConstructor},
-                needsMigration={needsMigration})
+                needsMigration={needsMigration},
+                inits={initializers})
         -> {emitCI()}? chareDeclaration_ci(
                 sym={currentClass},
                 chareType={$chareType.st},
index 663d0f230ac54d94f85e259fd3a46dccad494d81..14197fc162250f42bcbf51d2d2e2a5d24094cae3 100644 (file)
@@ -8,7 +8,7 @@ public class ClassSymbol extends SymbolWithScope implements Scope, Type {
     public ClassSymbol superClass;
     public List<String> interfaceImpls;
     public List<String> templateArgs;
-    public List<CharjAST> initializers;
+    public List<VariableInitializer> initializers;
     public List<CharjAST> varsToPup;
 
     public CharjAST constructor;
@@ -42,7 +42,7 @@ public class ClassSymbol extends SymbolWithScope implements Scope, Type {
         for (String pkg : SymbolTable.AUTO_IMPORTS) {
             importPackage(pkg);
         }
-       initializers = new ArrayList<CharjAST>();
+       initializers = new ArrayList<VariableInitializer>();
         varsToPup = new ArrayList<CharjAST>();
        constructor = null;
     }
@@ -56,8 +56,8 @@ public class ClassSymbol extends SymbolWithScope implements Scope, Type {
         this.superClass = superClass;
         this.scope = scope;
         this.type = this;
-       this.initializers = new ArrayList<CharjAST>();
        constructor = null;
+       this.initializers = new ArrayList<VariableInitializer>();
 
         // manually add automatic class methods and symbols here
         this.includes.add("charm++.h");
index 7b383458a6d4b125692e36d5010d8f5a1d322a41..994e182b92730ca76bbc6abad9b18a51b08e92b2 100644 (file)
@@ -79,18 +79,17 @@ exitBlock
     ;
 
 varDeclaration
-    :   ^((PRIMITIVE_VAR_DECLARATION | OBJECT_VAR_DECLARATION)
-            (^(MODIFIER_LIST .*))? .
-            ^(VAR_DECLARATOR_LIST (^(VAR_DECLARATOR ^(IDENT .*) .*)
-            {
-                if (!inBlock && currentClass != null) {
-                    currentClass.varsToPup.add($IDENT);
-                }
-            }
-                )+))
-    |   ^(FORMAL_PARAM_STD_DECL (^(MODIFIER_LIST .+))? . ^(IDENT .*))
+    :   ^(VAR_DECLARATOR ^(IDENT .*) (expr=.)? )
         {
-            
+
+            if (!inBlock && currentClass != null && $expr != null) {
+                System.out.println("FOUND EXPR");
+                currentClass.initializers.add(new VariableInitializer($expr, $IDENT));
+            }
+
+            if (!inBlock && currentClass != null) {
+                currentClass.varsToPup.add($IDENT);
+            }
         }
     ;
 
index d7b3ed52b5913ee15b4a02d6f585b66b49ec4a30..fce9d4f1aa85f708722ae5962e5265f621a17fd1 100644 (file)
@@ -101,10 +101,6 @@ public class Translator {
         preSemanticPass();
         if (m_printAST) printAST("Before Semantic Pass", "before_sem.html");
 
-        // FIXME: no longer guaranteed one class per file, go through each type instead.
-       //semanticPass();
-       //modifyNodes(sem);
-
         resolveTypes();
         if (m_printAST) printAST("After Semantic Pass", "after_sem.html");
 
@@ -195,59 +191,6 @@ public class Translator {
         collector.downup(m_ast);
     }
 
-    private CharjAST addConstructor(ClassSymbol sem) {
-       CharjAST ast1 = new CharjAST(CharjParser.CONSTRUCTOR_DECL, 
-                                    "CONSTRUCTOR_DECL");
-       CharjAST ast2 = new CharjAST(CharjParser.IDENT, 
-                                    sem.getScopeName());
-       CharjAST ast3 = new CharjAST(CharjParser.FORMAL_PARAM_LIST, 
-                                    "FORMAL_PARAM_LIST");
-       CharjAST ast4 = new CharjAST(CharjParser.BLOCK, "BLOCK");
-       
-       ast1.addChild(ast2);
-       ast1.addChild(ast3);
-       ast1.addChild(ast4);
-       sem.definition.addChild(ast1);
-       return ast1;
-    }
-
-    private void modifyNodes(ClassSymbol sem) {
-       /* Add constructor */
-
-       if (sem.constructor == null) {
-           sem.constructor = addConstructor(sem);
-       }
-
-       /* Insert array initializers into the constructor */
-
-       for (CharjAST init : sem.initializers) {
-           System.out.println("processing init token = " + init.getType());
-
-           if (init.getType() == CharjParser.IDENT) {
-               CharjAST ast1 = new CharjAST(CharjParser.EXPR, "EXPR");
-               CharjAST ast2 = new CharjAST(CharjParser.METHOD_CALL, "METHOD_CALL");
-               CharjAST ast2_1 = new CharjAST(CharjParser.DOT, ".");
-               CharjAST ast2_2 = new CharjAST(CharjParser.IDENT, init.getText());
-               CharjAST ast2_3 = new CharjAST(CharjParser.IDENT, "init");
-               CharjAST ast4 = new CharjAST(CharjParser.ARGUMENT_LIST, "ARGUMENT_LIST");
-
-               ast1.addChild(ast2);
-               ast2.addChild(ast2_1);
-               ast2_1.addChild(ast2_2);
-               ast2_1.addChild(ast2_3);
-               ast2.addChild(ast4);
-               ast4.addChildren(init.getChildren());
-
-               //System.out.println(sem.constructor.toStringTree());
-
-               sem.constructor.getChild(2).addChild(ast1);
-           } else if (init.getType() == CharjParser.NEW_EXPRESSION) {
-               //(OBJECT_VAR_DECLARATION (TYPE (QUALIFIED_TYPE_IDENT (Array (TEMPLATE_INST (TYPE double(Symbol(double_primitive, ClassSymbol[double]: {}, ))))))) (VAR_DECLARATOR_LIST (VAR_DECLARATOR ccc (NEW_EXPRESSION (ARGUMENT_LIST (EXPR get)) (DOMAIN_EXPRESSION (RANGE_EXPRESSION 1))))))
-           }
-           
-       }
-    }
-
     private String translationPass(OutputMode m) throws
         RecognitionException, IOException, InterruptedException
     {
@@ -260,7 +203,7 @@ public class Translator {
         return st.toString();
     }
 
-    private StringTemplateGroup getTemplates(String templateFile) {
+    public static StringTemplateGroup getTemplates(String templateFile) {
         StringTemplateGroup templates = null;
         try {
             ClassLoader loader = Thread.currentThread().getContextClassLoader();
@@ -270,7 +213,8 @@ public class Translator {
             templates = new StringTemplateGroup(reader);
             reader.close();
         } catch(IOException ex) {
-            error("Failed to load template file", ex); 
+            System.err.println(ex.getMessage());
+            ex.printStackTrace(System.err);
         }
         return templates;
     }