Made modifications to allow templates to be parsed and generated. Problem with genera...
authorJonathan Lifflander <jliffl2@illinois.edu>
Tue, 13 Apr 2010 20:45:15 +0000 (15:45 -0500)
committerJonathan Lifflander <jliffl2@illinois.edu>
Tue, 13 Apr 2010 20:50:49 +0000 (15:50 -0500)
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

index 4db1134c3e8e1ef516327d18df400643d9cecabe..3d4f1001cd2cfc05521ba482c3cfa8517a46dd13 100644 (file)
@@ -137,14 +137,20 @@ importDeclaration
 
 typeDeclaration
     :   classDefinition
+    |   templateDeclaration
     |   interfaceDefinition
     |   enumDefinition
     |   chareDefinition
     |   chareArrayDefinition
     ;
 
+templateDeclaration
+    : 'template' '<' 'class' IDENT '>' classDefinition
+        -> ^('template' '<' 'class' IDENT '>' classDefinition)
+    ;
+
 classDefinition
-    :   'public'? 'class' IDENT ('extends' type)? ('implements' typeList)? '{'
+    : 'public'? 'class' IDENT ('extends' type)? ('implements' typeList)? '{'
             classScopeDeclaration*
         '}' ';'?
         -> ^('class' IDENT ^('extends' type)? ^('implements' typeList)? classScopeDeclaration*)
index 2710848a3bf45d9d3f9a087c54dbc1185fb8966b..66ea745ac60a6a904dde5484f16bec6ae52176e2 100644 (file)
@@ -80,7 +80,6 @@ interfaceExtends(ts) ::=
 : public <ts; separator=", public ">
 >>
 
-
 classDeclaration_h(ident, ext, csds) ::=
 <<
 <if(debug)>/* \<typeDeclaration> */<endif>
@@ -94,6 +93,12 @@ class <ident>: public CBase_<ident> {
 
 >>
 
+templateDeclaration_h(ident, class1) ::=
+<<
+template \<class <ident>\>
+<class1>
+>>
+
 classDeclaration_cc(ident, ext, csds) ::=
 <<
 <if(debug)>/* \<typeDeclaration> */<endif>
index da06b69a72dfc9daa15504abe70a767cbcd5039c..162fd0109cc212cc087559ce537727a2ece8d9ca 100644 (file)
@@ -136,13 +136,18 @@ importDeclaration
     ;
     
 typeDeclaration
-    :   ^('class' IDENT (^('extends' su=type))? (^('implements' type+))? (csds+=classScopeDeclaration)*)
+    :   ^('template' '<' 'class' IDENT '>' td=typeDeclaration)
+        -> {emitH()}? templateDeclaration_h(
+            ident={$IDENT.text},
+            class1={$td.st})
+        ->
+    |   ^('class' i1=IDENT (^('extends' su=type))? (^('implements' type+))? (csds+=classScopeDeclaration)*)
         -> {emitCC()}? classDeclaration_cc(
-                ident={$IDENT.text}, 
+                ident={$i1.text}, 
                 ext={$su.st}, 
                 csds={$csds})
         -> {emitH()}? classDeclaration_h(
-                ident={$IDENT.text}, 
+                ident={$i1.text}, 
                 ext={$su.st}, 
                 csds={$csds})
         ->
index 4220abe1855d011030100bb5c3fe9d440d0f9e0e..6bbd9765b1d395da039d3b6ecb68976556594001 100644 (file)
@@ -119,15 +119,15 @@ importDeclarations returns [List<CharjAST> packageNames]
 
 typeDeclaration[List<CharjAST> imports] returns [ClassSymbol sym]
 scope ScopeStack; // top-level type scope
-    :   ^('class' IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
+    :   ^('template' '<' 'class' i1=IDENT '>' 'class' i2=IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
         {
             Scope outerScope = $ScopeStack[-1]::current;
-            $sym = new ClassSymbol(symtab, $IDENT.text, null, outerScope);
+            $sym = new ClassSymbol(symtab, $i2.text, null, outerScope);
             outerScope.define($sym.name, $sym);
             currentClass = $sym;
             $sym.definition = $typeDeclaration.start;
             $sym.definitionTokenStream = input.getTokenStream();
-            $IDENT.symbol = $sym;
+            $i2.symbol = $sym;
             $ScopeStack::current = $sym;
             importPackages($sym, $imports);
         }