Charj: Added generator for migration constructors for chare arrays.
authorJonathan Lifflander <jliffl2@illinois.edu>
Tue, 29 Jun 2010 17:16:20 +0000 (12:16 -0500)
committerJonathan Lifflander <jliffl2@illinois.edu>
Tue, 29 Jun 2010 17:16:20 +0000 (12:16 -0500)
src/langs/charj/src/charj/translator/Charj.stg
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/SymbolDefiner.g

index c4411cede2c2859ae517c0e61bffbc5eb8ec51c1..0b3a75548428e31c1b2eecc756a3ec3e4b05f4b0 100644 (file)
@@ -136,7 +136,7 @@ classDeclaration_h_cont(pds, sym, ident, ext, csds, hasDefaultCtor) ::=
 <<
 <if(first(pds))>namespace <first(pds)>
 {
-    <classDeclaration_h_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds)>
+    <classDeclaration_h_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, hasDefaultCtor = hasDefaultCtor)>
 } // namespace <first(pds)>
 <else>
 <if(ext)>
@@ -189,18 +189,18 @@ void <ident>::constructorHelper()
 >>
 
 
-chareDeclaration_cc(sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor) ::=
+chareDeclaration_cc(sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor, needsMigration) ::=
 <<
 #include "<ident>.decl.h"
-<chareDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor)>
+<chareDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor, needsMigration = needsMigration)>
 #include "<ident>.def.h"
 >>
 
-chareDeclaration_cc_cont(pds, sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor) ::=
+chareDeclaration_cc_cont(pds, sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor, needsMigration) ::=
 <<
 <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)>
+    <chareDeclaration_cc_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor, needsMigration = needsMigration)>
 } // namespace <first(pds)>
 <else>
 <csds; separator="\n\n">
@@ -232,22 +232,29 @@ void <ident>::constructorHelper()
 {
 
 }
+
+<if(needsMigration)>
+<ident>::<ident>(CkMigrateMessage *m)
+{
+    constructorHelper();
+}
+<endif>
 <endif>
 >>
 
-chareDeclaration_h(sym, ident, ext, csds, needsPupInit, hasDefaultCtor) ::=
+chareDeclaration_h(sym, ident, ext, csds, needsPupInit, hasDefaultCtor, needsMigration) ::=
 <<
 <chare_preamble_h(sym)>
 #include "<ident>.decl.h"
-<chareDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, needsPupInit = needsPupInit, hasDefaultCtor = hasDefaultCtor)>
+<chareDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, needsPupInit = needsPupInit, hasDefaultCtor = hasDefaultCtor, needsMigration = needsMigration)>
 <chare_epilogue_h(sym)>
 >>
 
-chareDeclaration_h_cont(pds, sym, ident, ext, csds, needsPupInit, hasDefaultCtor) ::=
+chareDeclaration_h_cont(pds, sym, ident, ext, csds, needsPupInit, hasDefaultCtor, needsMigration) ::=
 <<
 <if(first(pds))>namespace <first(pds)>
 {
-    <chareDeclaration_h_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, needsPupInit = needsPupInit, hasDefaultCtor = hasDefaultCtor)>
+    <chareDeclaration_h_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, needsPupInit = needsPupInit, hasDefaultCtor = hasDefaultCtor, needsMigration = needsMigration)>
 } // namespace <first(pds)>
 <else>
 <if(ext)>/* superclass: <ext> */<endif>
@@ -261,6 +268,9 @@ class <ident>: public CBase_<ident> {
     public: <ident>();
     <endif>
     protected: void constructorHelper();
+    <if(needsMigration)>
+    public: <ident>(CkMigrateMessage*);
+    <endif>
 };
 <endif>
 >>
index 6d33e449bbabf1405a586415939c44d5f8370e04..2eca60bb9042bfe16ab22a20785434dfa3b13ac0 100644 (file)
@@ -132,6 +132,9 @@ importDeclaration
     ;
     
 typeDeclaration
+@init {
+    boolean needsMigration = false;
+}
     :   ^(TYPE CLASS IDENT (^('extends' su=type))? (^('implements' type+))?
         {
             currentClass = (ClassSymbol)$IDENT.def;
@@ -165,6 +168,7 @@ typeDeclaration
     |   ^(TYPE chareType IDENT (^('extends' type))? (^('implements' type+))?
         {
             currentClass = (ClassSymbol)$IDENT.def;
+            needsMigration = currentClass.isChareArray && !currentClass.hasMigrationConstructor;
         }
         (csds+=classScopeDeclaration)*)
         -> {emitCC()}? chareDeclaration_cc(
@@ -174,7 +178,8 @@ typeDeclaration
                 csds={$csds},
                 pupInits={currentClass.generateInits()},
                 pupers={currentClass.generatePUPers()},
-                hasDefaultCtor={currentClass.hasDefaultConstructor})
+                hasDefaultCtor={currentClass.hasDefaultConstructor},
+                needsMigration={needsMigration})
         -> {emitCI()}? chareDeclaration_ci(
                 sym={currentClass},
                 chareType={$chareType.st},
@@ -188,7 +193,8 @@ typeDeclaration
                 ext={$su.st}, 
                 csds={$csds},
                 needsPupInit={currentClass.generateInits() != null},
-                hasDefaultCtor={currentClass.hasDefaultConstructor})
+                hasDefaultCtor={currentClass.hasDefaultConstructor},
+                needsMigration={needsMigration})
         ->
     ;
 
index fc7047c2b575371b2c792c9637d9a79e1d19c480..663d0f230ac54d94f85e259fd3a46dccad494d81 100644 (file)
@@ -28,7 +28,9 @@ public class ClassSymbol extends SymbolWithScope implements Scope, Type {
     public boolean isPrimitive = false;
     public boolean isChare = false;
     public boolean isMainChare = false;
+    public boolean isChareArray = false;
     public boolean hasDefaultConstructor = false;
+    public boolean hasMigrationConstructor = false;
 
     public CharjAST migrationCtor = null;
 
index b7bdf6cb14c8c2b4607057e88bfacd0ca40ec258..7b383458a6d4b125692e36d5010d8f5a1d322a41 100644 (file)
@@ -51,6 +51,19 @@ enterDefaultConstructor
         }
     ;
 
+enterMigrationConstructor
+    :    ^((CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL)
+            (^(MODIFIER_LIST .*))? .
+                ^(FORMAL_PARAM_LIST ^(FORMAL_PARAM_STD_DECL
+                    ^(POINTER_TYPE ^(QUALIFIED_TYPE_IDENT IDENT)) .
+                )) ^(BLOCK .*))
+        {
+            if (currentClass != null && $IDENT.text.equals("CkMigrateMessage")) {
+                currentClass.hasMigrationConstructor = true;
+            }
+        }
+    ;
+
 enterBlock 
     :   ^(BLOCK .*)
         {
index e7df213c4eb9348c8a3d85379514b39ed7b10121..e1ca96ffd844944ad42ec3680d6668502fe16db4 100644 (file)
@@ -159,7 +159,9 @@ enterClass
                 currentClass.isChare = true;
             } else if (classTypeName.equals("chare_array")) {
                 // TODO: test this; might need to use startswith instead of equals
+                // TODO: should "isChare" be set to true?
                 currentClass.isChare = true;
+                currentClass.isChareArray = true;
             } else if (classTypeName.equals("mainchare")) {
                 currentClass.isChare = true;
                 currentClass.isMainChare = true;