nicer syntax for declaring chare,group,etc subtypes
authorAaron Becker <abecker3@illinois.edu>
Tue, 16 Jun 2009 02:05:18 +0000 (02:05 +0000)
committerAaron Becker <abecker3@illinois.edu>
Tue, 16 Jun 2009 02:05:18 +0000 (02:05 +0000)
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/Charj.stg
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/tests/unit/SimpleChare.cj [new file with mode: 0644]
src/langs/charj/tests/unit/SimpleChareArray.cj [new file with mode: 0644]
src/langs/charj/tests/unit/TODO

index 874c56238c043ea5729337b4f6d6cd529507c598..4db1134c3e8e1ef516327d18df400643d9cecabe 100644 (file)
@@ -139,6 +139,8 @@ typeDeclaration
     :   classDefinition
     |   interfaceDefinition
     |   enumDefinition
+    |   chareDefinition
+    |   chareArrayDefinition
     ;
 
 classDefinition
@@ -148,6 +150,26 @@ classDefinition
         -> ^('class' IDENT ^('extends' type)? ^('implements' typeList)? classScopeDeclaration*)
     ;
 
+chareType
+    :   'chare'
+    |   'group'
+    |   'nodegroup'
+    ;
+
+chareDefinition
+    :   'public'? chareType IDENT ('extends' type)? ('implements' typeList)? '{'
+            classScopeDeclaration*
+        '}' ';'?
+        -> ^(chareType IDENT ^('extends' type)? ^('implements' typeList)? classScopeDeclaration*)
+    ;
+
+chareArrayDefinition
+    :   'public'? 'chare_array' '[' ARRAY_DIMENSION ']' IDENT ('extends' type)? ('implements' typeList)? '{'
+            classScopeDeclaration*
+        '}' ';'?
+        -> ^('chare_array' ARRAY_DIMENSION IDENT ^('extends' type)? ^('implements' typeList)? classScopeDeclaration*)
+    ;
+
 interfaceDefinition
     :   'interface' IDENT ('extends' typeList)?  '{'
             interfaceScopeDeclaration*
@@ -726,6 +748,9 @@ DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*) INTEGER_TYPE_SUFFIX? ;
 
 OCTAL_LITERAL : '0' ('0'..'7')+ INTEGER_TYPE_SUFFIX? ;
 
+//fragment
+ARRAY_DIMENSION :  '1'..'6' ('d'|'D') ;
+
 fragment
 HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
 
index 4f424699a650f4d71bdbef3167d5a827dd878215..2710848a3bf45d9d3f9a087c54dbc1185fb8966b 100644 (file)
@@ -81,24 +81,6 @@ interfaceExtends(ts) ::=
 >>
 
 
-classDeclaration_ci(ident, ext, csds) ::=
-<<
-<if(debug)>/* \<typeDeclaration> */<endif>
-module <ident> {
-<if(ext)>
-    extern module <ext>;
-    chare <ident>: <ext> {
-<else>
-    chare <ident> {
-<endif>
-        <csds; separator="\n">
-    }
-}
-<if(debug)>/* \</typeDeclaration> */<endif>
-
->>
-
-
 classDeclaration_h(ident, ext, csds) ::=
 <<
 <if(debug)>/* \<typeDeclaration> */<endif>
@@ -110,7 +92,6 @@ class <ident>: public CBase_<ident> {
 };
 <if(debug)>/* \</typeDeclaration> */<endif>
 
-
 >>
 
 classDeclaration_cc(ident, ext, csds) ::=
@@ -126,6 +107,24 @@ class <ident>: public CBase_<ident> {
 #include "<ident>.def.h"
 <if(debug)>/* \</typeDeclaration> */<endif>
 
+>>
+
+
+charedeclaration_ci(chareType, arrayDim, ident, ext, csds) ::=
+<<
+<if(debug)>/* \<typeDeclaration> */<endif>
+module <ident> {
+<if(ext)>
+    extern module <ext>;
+    <chareType><if(arrayDim)> [<arrayDim>]<endif> <ident>: <ext> {
+<else>
+    <chareType><if(arrayDim)> [<arrayDim>]<endif> <ident> {
+<endif>
+        <csds; separator="\n">
+    }
+}
+
+<if(debug)>/* \</typeDeclaration> */<endif>
 
 >>
 
index 6e0d891c8d8eaa65f01c4ba8df47a0e545e17c69..e982e5afa0cc8a976a236d625066e3edb929c535 100644 (file)
@@ -141,10 +141,6 @@ typeDeclaration
                 ident={$IDENT.text}, 
                 ext={$su.st}, 
                 csds={$csds})
-        -> {emitCI()}? classDeclaration_ci(
-                ident={$IDENT.text}, 
-                ext={$su.st}, 
-                csds={$csds})
         -> {emitH()}? classDeclaration_h(
                 ident={$IDENT.text}, 
                 ext={$su.st}, 
@@ -154,6 +150,39 @@ typeDeclaration
         -> template(t={$text}) "/*INTERFACE-not implemented*/ <t>"
     |   ^('enum' IDENT (^('implements' type+))? classScopeDeclaration*)
         -> template(t={$text}) "/*ENUM-not implemented*/ <t>"
+    |   ^(chareType IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
+        -> {emitCC()}? classDeclaration_cc(
+                ident={$IDENT.text}, 
+                ext={$su.st}, 
+                csds={$csds})
+        -> {emitCI()}? charedeclaration_ci(
+                chareType={$chareType.st},
+                arrayDim={null},
+                ident={$IDENT.text}, 
+                ext={$su.st}, 
+                csds={$csds})
+        -> {emitH()}? classDeclaration_h(
+                ident={$IDENT.text}, 
+                ext={$su.st}, 
+                csds={$csds})
+        ->
+    |   ^('chare_array' ARRAY_DIMENSION IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
+        -> {emitCI()}? charedeclaration_ci(
+                chareType={"array"},
+                arrayDim={$ARRAY_DIMENSION.text.toUpperCase()},
+                ident={$IDENT.text}, 
+                ext={$su.st}, 
+                csds={$csds})
+        ->
+    ;
+
+chareType
+@init {
+$st = %{$start.getText()};
+}
+    :   'chare'
+    |   'group'
+    |   'nodegroup'
     ;
 
 enumConstant
index 267a903c57465742e81e3d3ce86729b9a6c5d9f5..e405eea9768dc115bcd3c536a3c498c1e540bd54 100644 (file)
@@ -133,6 +133,14 @@ scope ScopeStack; // top-level type scope
         }
     |   ^('interface' IDENT (^('extends' type+))?  interfaceScopeDeclaration*)
     |   ^('enum' IDENT (^('implements' type+))? enumConstant+ classScopeDeclaration*)
+    |   ^(chareType IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
+    |   ^('chare_array' ARRAY_DIMENSION IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
+    ;
+
+chareType
+    :   'chare'
+    |   'group'
+    |   'nodegroup'
     ;
 
 enumConstant
diff --git a/src/langs/charj/tests/unit/SimpleChare.cj b/src/langs/charj/tests/unit/SimpleChare.cj
new file mode 100644 (file)
index 0000000..2c9930b
--- /dev/null
@@ -0,0 +1,6 @@
+package tests.unit;
+
+public chare SimpleChare {
+    int x;
+    entry void test();
+}
diff --git a/src/langs/charj/tests/unit/SimpleChareArray.cj b/src/langs/charj/tests/unit/SimpleChareArray.cj
new file mode 100644 (file)
index 0000000..466bb99
--- /dev/null
@@ -0,0 +1,6 @@
+package tests.unit;
+
+public chare_array [5d] SimpleChareArray {
+    int x;
+    entry void test();
+}
index bf05d4b75c062b134e7df997336787ba9162df10..19dfdf8b591ff0f385f53e0c9e9df2c72ae0d2b0 100644 (file)
@@ -2,6 +2,7 @@
 test modifiers for both fields and local vars
 fix codegen for 'entry' modifier
 fix colon placement for access modifiers in field definitions
+make sure entry methods appear in .ci files, and have entry modifier stripped off in .h/.cc
 
 thorough expression/primary statment tests
 method chaining