Charj: if a module contains a mainchare, it should be a mainmodule
authorAaron Becker <akbecker@gmail.com>
Sun, 30 May 2010 02:11:28 +0000 (21:11 -0500)
committerAaron Becker <akbecker@gmail.com>
Sun, 30 May 2010 02:11:28 +0000 (21:11 -0500)
src/langs/charj/src/charj/translator/Charj.stg
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/ClassSymbol.java

index 0f277a4201a6b52c13f9dc61ce54f769c7e7a6b1..89ef6bd4ab2753cf50fbbfcdbfc267c33c063ea4 100644 (file)
@@ -148,7 +148,7 @@ class <ident>: public CBase_<ident> {
 
 chareDeclaration_ci(sym, chareType, arrayDim, ident, ext, csds) ::=
 <<
-module <ident> {
+<if(sym.isMainChare)>main<endif>module <ident> {
 <if(ext)>
     extern module <ext>;
 <endif>
index 079c9130f219092e39cf64bcd0d5caead6ebbc37..c8aaa256a83b5f880c7bc5a79bb544761838074c 100644 (file)
@@ -120,7 +120,7 @@ importDeclarations returns [List<CharjAST> packageNames]
 
 typeDeclaration[List<CharjAST> imports] returns [ClassSymbol sym]
 scope ScopeStack; // top-level type scope
-    :   ^(TYPE (CLASS | chareType) IDENT
+    :   ^(TYPE classType IDENT
             (^('extends' parent=type))? (^('implements' type+))?
             {
                 Scope outerScope = $ScopeStack[-1]::current;
@@ -131,6 +131,20 @@ scope ScopeStack; // top-level type scope
                 $sym.definitionTokenStream = input.getTokenStream();
                 $IDENT.symbol = $sym;
                 $ScopeStack::current = $sym;
+                String classTypeName = $classType.text;
+                if (classTypeName.equals("class")) {
+                } else if (classTypeName.equals("chare")) {
+                    currentClass.isChare = true;
+                } else if (classTypeName.equals("group")) {
+                    currentClass.isChare = true;
+                } else if (classTypeName.equals("nodegroup")) {
+                    currentClass.isChare = true;
+                } else if (classTypeName.equals("chare_array")) {
+                    currentClass.isChare = true;
+                } else if (classTypeName.equals("mainchare")) {
+                    currentClass.isChare = true;
+                    currentClass.isMainChare = true;
+                } else System.out.println("Error: type " + classTypeName + " not recognized.");
                 importPackages($sym, $imports);
             }
             classScopeDeclaration*)
@@ -144,6 +158,11 @@ scope ScopeStack; // top-level type scope
     |   ^('enum' IDENT (^('implements' type+))? enumConstant+ classScopeDeclaration*)
     ;
 
+classType
+    :   CLASS
+    |   chareType
+    ;
+
 chareType
     :   CHARE
     |   GROUP
index cf45b5e1156082e4942f852c3a9939c6d0ad62e0..d4baa9d4e8f7ee930e36019e12ba55c026d27dee 100644 (file)
@@ -20,6 +20,8 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
 
     public boolean hasCopyCtor = false;
     public boolean isPrimitive = false;
+    public boolean isChare = false;
+    public boolean isMainChare = false;
 
     public ClassSymbol(
             SymbolTable symtab,