Charj: Added the detection and generation of default constructors if not present.
authorJonathan Lifflander <jliffl2@illinois.edu>
Tue, 29 Jun 2010 05:59:18 +0000 (00:59 -0500)
committerJonathan Lifflander <jliffl2@illinois.edu>
Tue, 29 Jun 2010 05:59:18 +0000 (00:59 -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

index dd2fae847d4da762be058e3c5976238a683f3ac8..2f45cd67d04e60e0b8f1b88173b868864a5f025b 100644 (file)
@@ -121,18 +121,18 @@ chare_epilogue_h(sym) ::=
 <type_epilogue_h(sym)>
 >>
 
-classDeclaration_h(sym, ident, ext, csds, tident) ::=
+classDeclaration_h(sym, ident, ext, csds, tident, hasDefaultCtor) ::=
 <<
 <type_preamble_h(sym)>
 <if(tident)>
-<templateDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, tident = tident)>
+<templateDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, tident = tident, hasDefaultCtor = hasDefaultCtor)>
 <else>
-<classDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds)>
+<classDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, hasDefaultCtor = hasDefaultCtor)>
 <endif>
 <type_epilogue_h(sym)>
 >>
 
-classDeclaration_h_cont(pds, sym, ident, ext, csds) ::=
+classDeclaration_h_cont(pds, sym, ident, ext, csds, hasDefaultCtor) ::=
 <<
 <if(first(pds))>namespace <first(pds)>
 {
@@ -146,45 +146,55 @@ class <ident> {
 <endif>
 
     <csds; separator="\n\n">
+    <if(!hasDefaultCtor)>
+    public: <ident>();
+    <endif>
 };
 <endif>
 >>
 
-templateDeclaration_h(pds, sym, ident, ext, csds, tident) ::=
+templateDeclaration_h(pds, sym, ident, ext, csds, tident, hasDefaultCtor) ::=
 <<
 template \<class <tident; separator=", class ">\>
-<classDeclaration_h_cont(pds=pds, sym=sym, ident=ident, ext=ext, csds=csds)>
+<classDeclaration_h_cont(pds=pds, sym=sym, ident=ident, ext=ext, csds=csds, hasDefaultCtor=hasDefaultCtor)>
 >>
 
-classDeclaration_cc(sym, ident, ext, csds) ::=
+classDeclaration_cc(sym, ident, ext, csds, hasDefaultCtor) ::=
 <<
-<classDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds)>
+<classDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, hasDefaultCtor = hasDefaultCtor)>
 >>
 
-classDeclaration_cc_cont(pds, sym, ident, ext, csds) ::=
+classDeclaration_cc_cont(pds, sym, ident, ext, csds, hasDefaultCtor) ::=
 <<
 <if(first(pds))>namespace <first(pds)>
 {
-    <classDeclaration_cc_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds)>
+    <classDeclaration_cc_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, hasDefaultCtor = hasDefaultCtor)>
 } // namespace <first(pds)>
 <else>
 <csds; separator="\n\n">
+
+<if(!hasDefaultCtor)>
+<ident>::<ident>()
+{
+    constructorHelper();
+}
+<endif>
 <endif>
 >>
 
 
-chareDeclaration_cc(sym, ident, ext, csds, pupers, pupInits) ::=
+chareDeclaration_cc(sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor) ::=
 <<
 #include "<ident>.decl.h"
-<chareDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits)>
+<chareDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor)>
 #include "<ident>.def.h"
 >>
 
-chareDeclaration_cc_cont(pds, sym, ident, ext, csds, pupers, pupInits) ::=
+chareDeclaration_cc_cont(pds, sym, ident, ext, csds, pupers, pupInits, hasDefaultCtor) ::=
 <<
 <if(first(pds))>namespace <first(pds)>
 {
-    <chareDeclaration_cc_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits)>
+    <chareDeclaration_cc_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, pupers = pupers, pupInits = pupInits, hasDefaultCtor = hasDefaultCtor)>
 } // namespace <first(pds)>
 <else>
 <csds; separator="\n\n">
@@ -204,28 +214,38 @@ void <ident>::pup(PUP::er &p)
 <endif>
     <pupers; separator="\n">
 }
+
+<if(!hasDefaultCtor)>
+<ident>::<ident>()
+{
+    constructorHelper();
+}
+<endif>
 <endif>
 >>
 
-chareDeclaration_h(sym, ident, ext, csds) ::=
+chareDeclaration_h(sym, ident, ext, csds, hasDefaultCtor) ::=
 <<
 <chare_preamble_h(sym)>
 #include "<ident>.decl.h"
-<chareDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds)>
+<chareDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, hasDefaultCtor = hasDefaultCtor)>
 <chare_epilogue_h(sym)>
 >>
 
-chareDeclaration_h_cont(pds, sym, ident, ext, csds) ::=
+chareDeclaration_h_cont(pds, sym, ident, ext, csds, hasDefaultCtor) ::=
 <<
 <if(first(pds))>namespace <first(pds)>
 {
-    <chareDeclaration_h_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds)>
+    <chareDeclaration_h_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds, hasDefaultCtor = hasDefaultCtor)>
 } // namespace <first(pds)>
 <else>
 <if(ext)>/* superclass: <ext> */<endif>
 class <ident>: public CBase_<ident> {
     <csds; separator="\n">
     public: void pup(PUP::er& p);
+    <if(!hasDefaultCtor)>
+    public: <ident>();
+    <endif>
 };
 <endif>
 >>
index cd55d9d374621f89def9ee1badac34c4b240c880..ea2ac121193caa2e5fff32f2e0e6479406632831 100644 (file)
@@ -141,19 +141,22 @@ typeDeclaration
                 sym={currentClass},
                 ident={$IDENT.text}, 
                 ext={$su.st}, 
-                csds={$csds})
+                csds={$csds},
+                hasDefaultCtor={currentClass.hasDefaultConstructor})
         -> {emitH()}?  classDeclaration_h(
                 sym={currentClass},
                 ident={$IDENT.text}, 
                 ext={$su.st}, 
-                csds={$csds})
+                csds={$csds},
+                hasDefaultCtor={currentClass.hasDefaultConstructor})
         ->
     |   ^('template' (i0+=IDENT*) ^('class' i1=IDENT (^('extends' su=type))? (^('implements' type+))? (csds+=classScopeDeclaration)*))
         -> {emitH()}? templateDeclaration_h(
             tident={$i0},
             ident={$i1.text},
             ext={$su.st},
-            csds={$csds})
+            csds={$csds},
+            hasDefaultCtor={currentClass.hasDefaultConstructor})
         -> 
     |   ^(INTERFACE IDENT (^('extends' type+))? interfaceScopeDeclaration*)
         -> template(t={$text}) "/*INTERFACE-not implemented*/ <t>"
@@ -170,7 +173,8 @@ typeDeclaration
                 ext={$su.st}, 
                 csds={$csds},
                 pupInits={currentClass.generateInits()},
-                pupers={currentClass.generatePUPers()})
+                pupers={currentClass.generatePUPers()},
+                hasDefaultCtor={currentClass.hasDefaultConstructor})
         -> {emitCI()}? chareDeclaration_ci(
                 sym={currentClass},
                 chareType={$chareType.st},
@@ -182,7 +186,8 @@ typeDeclaration
                 sym={currentClass},
                 ident={$IDENT.text}, 
                 ext={$su.st}, 
-                csds={$csds})
+                csds={$csds},
+                hasDefaultCtor={currentClass.hasDefaultConstructor})
         ->
     ;
 
index a00be4139897c191bfc35d1ca1eed7b66ad44e75..fc7047c2b575371b2c792c9637d9a79e1d19c480 100644 (file)
@@ -28,6 +28,7 @@ public class ClassSymbol extends SymbolWithScope implements Scope, Type {
     public boolean isPrimitive = false;
     public boolean isChare = false;
     public boolean isMainChare = false;
+    public boolean hasDefaultConstructor = false;
 
     public CharjAST migrationCtor = null;