Charj: sdag atomic block infrastructure
authorAaron Becker <akbecker@gmail.com>
Fri, 17 Sep 2010 16:22:45 +0000 (11:22 -0500)
committerAaron Becker <akbecker@gmail.com>
Fri, 17 Sep 2010 16:22:45 +0000 (11:22 -0500)
src/langs/charj/build.xml
src/langs/charj/src/charj/translator/AtomicBlocks.g [new file with mode: 0644]
src/langs/charj/src/charj/translator/Charj.g

index 246af79c41a09126dd54c3d57b3969923736cfb1..eedc42629c4b11f161f100d5e7154d0f2a18bdb2 100644 (file)
         <antlr3 grammar.name="CharjSemantics.g"
             grammar.path="${buildsrc}/charj/translator"/>
     </target>
+    
+    <target name="AtomicBlocks" depends="Charj">
+        <antlr3 grammar.name="AtomicBlocks.g"
+            grammar.path="${buildsrc}/charj/translator"/>
+    </target>
 
-    <target name="CharjEmitter" depends="CharjSemantics,CharjASTModifier,CharjASTModifier2,SymbolDefiner,SymbolResolver,InitPUPCollector">
+    <target name="CharjEmitter" depends="Charj">
         <antlr3 grammar.name="CharjEmitter.g"
             grammar.path="${buildsrc}/charj/translator"/>
     </target>
diff --git a/src/langs/charj/src/charj/translator/AtomicBlocks.g b/src/langs/charj/src/charj/translator/AtomicBlocks.g
new file mode 100644 (file)
index 0000000..b1d42c1
--- /dev/null
@@ -0,0 +1,217 @@
+
+tree grammar AtomicBlocks;
+
+options {
+    tokenVocab = Charj;
+    ASTLabelType = CharjAST;
+    filter = true;
+}
+
+@header {
+package charj.translator;
+import java.util.Iterator;
+}
+
+@members {
+    SymbolTable symtab;
+    Scope currentScope;
+    ClassSymbol currentClass = null;
+
+    public SymbolResolver(TreeNodeStream input, SymbolTable symtab) {
+        this(input);
+        this.symtab = symtab;
+        this.currentScope = symtab.getDefaultPkg();
+    }
+}
+
+
+topdown
+    :   enterClass
+    |   enterMethod
+    |   varDeclaration
+    |   expression
+    |   assignment
+    ;
+
+bottomup
+    :   exitClass
+    ;
+
+enterMethod
+@init {
+boolean entry = false;
+}
+    :   ^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL {entry = true;})
+            (^(MODIFIER_LIST .*))?
+            (^(GENERIC_TYPE_PARAM_LIST .*))? 
+            type IDENT .*)
+        {
+            $IDENT.def.type = $type.sym;
+            $IDENT.symbolType = $IDENT.def.type;
+        }
+    |   ^((CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL {entry = true;})
+            (^(MODIFIER_LIST .*))?
+            (^(GENERIC_TYPE_PARAM_LIST .*))? 
+            IDENT .*)
+        {
+            $IDENT.def.type = (ClassSymbol)$IDENT.def.scope;
+            $IDENT.symbolType = $IDENT.def.type;
+        }
+    ;
+
+enterClass
+    :   ^(TYPE classType IDENT
+            (^('extends' parent=type))?
+            (^('implements' type+))?
+            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | PRIMITIVE_VAR_DECLARATION |
+                OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
+        {
+            currentClass = (ClassSymbol)$IDENT.def.type;
+        }
+    ;
+
+exitClass
+    :   ^(TYPE classType IDENT
+            (^('extends' parent=type))?
+            (^('implements' type+))?
+            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | PRIMITIVE_VAR_DECLARATION |
+                OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
+        { currentClass = null; }
+    ;
+
+varDeclaration
+    :   ^((PRIMITIVE_VAR_DECLARATION | OBJECT_VAR_DECLARATION)
+            (^(MODIFIER_LIST .*))? type
+            ^(VAR_DECLARATOR_LIST (^(VAR_DECLARATOR ^(IDENT .*) .*)
+            )+))
+    |   ^(FORMAL_PARAM_STD_DECL (^(MODIFIER_LIST .*))? type ^(IDENT .*))
+        {
+            $IDENT.def.type = $type.sym;
+            $IDENT.symbolType = $type.sym;
+        }
+    ;
+
+parenthesizedExpression
+    :   ^(PAREN_EXPR exp=expression)
+    ;
+
+expression 
+    :   ^(EXPR .*)
+    ;
+
+assignment
+    :   ^(ASSIGNMENT IDENT expr)
+    ;
+
+
+type
+    :   VOID {
+            scope = $VOID.scope;
+            typeText.add(new TypeName("void"));
+        }
+    |   ^(SIMPLE_TYPE t=. {
+            scope = $SIMPLE_TYPE.scope;
+            typeText.add(new TypeName($t.getText()));
+        } .*)
+    |   ^(OBJECT_TYPE { scope = $OBJECT_TYPE.scope; }
+            ^(QUALIFIED_TYPE_IDENT (^(IDENT (^(TEMPLATE_INST
+                (t1=type {tparams.add($t1.sym);} | lit1=literalVal {tparams.add($lit1.type);} )*))?
+                {typeText.add(new TypeName($IDENT.text, tparams));}))+) .*)
+    |   ^(REFERENCE_TYPE { scope = $REFERENCE_TYPE.scope; }
+            ^(QUALIFIED_TYPE_IDENT (^(IDENT  {typeText.add(new TypeName($IDENT.text));} .*))+) .*)
+    |   ^(PROXY_TYPE { scope = $PROXY_TYPE.scope; proxy = true; }
+            ^(QUALIFIED_TYPE_IDENT (^(IDENT {typeText.add(new TypeName($IDENT.text));} .*))+) .*)
+    |   ^(POINTER_TYPE { scope = $POINTER_TYPE.scope; pointer = true; }
+            ^(QUALIFIED_TYPE_IDENT (^(IDENT (^(TEMPLATE_INST
+            (t1=type {tparams.add($t1.sym);} | lit1=literalVal {tparams.add($lit1.type);} )*))?
+            {typeText.add(new TypeName($IDENT.text, tparams));}))+) .*)
+    ;
+
+classType
+    :   CLASS
+    |   CHARE
+    |   GROUP
+    |   NODEGROUP
+    |   MAINCHARE
+    |   ^(CHARE_ARRAY ARRAY_DIMENSION)
+    ;
+
+block returns [boolean containsSDAG]
+@init { boolean hasSDAGstatement = false; }
+    :   ^(BLOCK (sdagNonLeader |
+            sdagLeader {hasSDAGstatement = $sdagLeader.containsSDAG; } |
+            block {hasSDAGstatement |= $block.containsSDAG})*) {
+            $containsSDAG = hasSDAGstatement;
+        }
+    ;
+    
+statement
+    :   sdagNonLeader
+    |   sdagLeader
+    |   block
+    ;
+
+sdagLeader returns [boolean containsSDAG]
+    :   ^(OVERLAP block) {$containsSDAG = true;}
+    |   ^(WHEN (IDENT expression? formalParameterList)* block) {$containsSDAG = true;}
+    |   ^(IF parenthesizedExpression ifblock=block elseblock=block?) {
+            $containsSDAG = $ifblock.containsSDAG || $elseblock.containsSDAG;
+        }
+    |   ^(FOR forInit? FOR_EXPR expression? FOR_UPDATE expression* block) {
+            $containsSDAG = $block.containsSDAG;
+        }
+        -> {$containsSDAG}? ^(SDAG_FOR forInit? FOR_EXPR expression? FOR_UPDATE expression* block)
+        -> ^(FOR forInit? FOR_EXPR expression? FOR_UPDATE expression* block)
+    |   ^(FOR_EACH localModifierList? type IDENT expression block) {
+            $containsSDAG = $block.containsSDAG;
+        }
+    |   ^(WHILE parenthesizedExpression block) {
+            $containsSDAG = $block.containsSDAG;
+        }
+        -> {$containsSDAG}? ^(SDAG_WHILE parenthesizedExpression block)
+        -> ^(WHILE parenthesizedExpression block)
+    |   ^(DO block parenthesizedExpression) {
+            $containsSDAG = $block.containsSDAG;
+        }
+        -> {$containsSDAG}? ^(SDAG_DO block parenthesizedExpression)
+        -> ^(DO block parenthesizedExpression)
+    ;
+
+sdagNonLeader
+    :   ^(PRIMITIVE_VAR_DECLARATION .*)
+    |   ^(OBJECT_VAR_DECLARATION .*)
+    |   ^(ASSERT expression expression?)
+    |   ^(SWITCH parenthesizedExpression switchCaseLabel*)
+    |   ^(RETURN expression?)
+    |   ^(THROW expression)
+    |   ^(BREAK IDENT?) {
+            if ($IDENT != null) {
+                translator.error(this, "Labeled break not supported yet, ignoring.", $IDENT);
+            }
+        }
+    |   ^(CONTINUE IDENT?) {
+            if ($IDENT != null) {
+                translator.error(this, "Labeled continue not supported yet, ignoring.", $IDENT);
+            }
+        }
+    |   ^(LABELED_STATEMENT IDENT statement)
+    |   expression
+    |   ^('delete' expression)
+    |   ^(EMBED STRING_LITERAL EMBED_BLOCK)
+    |   ';' // Empty statement.
+    |   ^(PRINT expression*)
+    |   ^(PRINTLN expression*)
+    |   ^(EXIT expression?)
+    |   EXITALL
+    ;
+        
+switchCaseLabel
+    :   ^(CASE expression blockStatement*)
+    |   ^(DEFAULT blockStatement*)
+    ;
+    
+forInit
+    :   localVariableDeclaration 
+    |   expression+
+    ;
+
index 47090d455ceec12c6530b5f7fd661062620c9192..c9985822e5be26153a7a5cc9b6dbf41cec956e71 100644 (file)
@@ -200,6 +200,8 @@ tokens {
     PRE_INC;
     QUALIFIED_TYPE_IDENT;
     RANGE_EXPRESSION;
+    SDAG_DO;
+    SDAG_WHILE;
     STATIC_ARRAY_CREATOR;
     SUPER_CONSTRUCTOR_CALL;
     TEMPLATE_INST;