lots of code gen improvements, working on symtab import
authorAaron Becker <abecker3@illinois.edu>
Tue, 16 Dec 2008 21:44:15 +0000 (21:44 +0000)
committerAaron Becker <abecker3@illinois.edu>
Tue, 16 Dec 2008 21:44:15 +0000 (21:44 +0000)
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/src/charj/translator/SymbolTable.java

index 777a53789f985b51141fcfec1d3b267dde1d2c23..d25bd94bfd5f1732656271963945c3ab222fa769 100644 (file)
@@ -179,11 +179,53 @@ embed_cc(str, blk) ::=
 
 primitive_var_decl(modList, type, declList) ::=
 <<
-<modList> <type> <declList>;
+<if(modList)>
+<modList>: <type> <declList>;
+<else>
+<type> <declList>;
+<endif>
 >>
 
 
 object_var_decl(modList, type, declList) ::=
 <<
-<modList> <type>* <declList>;
+<if(modList)>
+<modList>: <type>* <declList>;
+<else>
+<type>* <declList>;
+<endif>
+>>
+
+
+type(typeID, arrDeclList) ::=
+<<
+<typeID><arrDeclList>
+>>
+
+/*
+object_type(typeID, arrDeclList) ::=
+<<
+<typeID>*<arrDeclList>
+>>
+
+
+chare_type(typeID, arrDeclList) ::=
+<<
+CProxy_<typeID><arrDeclList>
+>>*/
+
+
+formal_param_list(sdecl, vdecl) ::=
+<<
+<if(vdecl)>
+(<sdecl; separator=", ">, <vdecl>)
+<else>
+(<sdecl; separator=", ">)
+<endif>
+>>
+
+
+formal_param_decl(modList, type, declID) ::=
+<<
+    <modList> <type> <declID>
 >>
\ No newline at end of file
index 0191dbf01c1df185033ad01d1afdaae045cffb74..3542bd0e25506d294da5a6714118b78b74b8f9a9 100644 (file)
@@ -302,9 +302,17 @@ classScopeDeclarations
                 block={$b.st})
         ->
     |   ^(PRIMITIVE_VAR_DECLARATION modifierList simpleType variableDeclaratorList)
-        -> template(t={$text}) "primvardecl <t>"
+        -> {emitCC() || emitH()}? primitive_var_decl(
+            modList={$modifierList.st},
+            type={$simpleType.st},
+            declList={$variableDeclaratorList.st})
+        ->
     |   ^(OBJECT_VAR_DECLARATION modifierList objectType variableDeclaratorList)
-        -> template(t={$text}) "objvardecl <t>"
+        -> {emitCC() || emitH()}? object_var_decl(
+            modList={$modifierList.st},
+            type={$objectType.st},
+            declList={$variableDeclaratorList.st})
+        ->
     |   ^(CONSTRUCTOR_DECL m=modifierList g=genericTypeParameterList? IDENT f=formalParameterList 
             t=throwsClause? b=block)
         { 
@@ -334,7 +342,7 @@ classScopeDeclarations
                 block={$b.st})
         ->
     |   d=typeDeclaration
-        -> template(t={$d.st}) "type <t>"
+        -> template(t={$d.st}) "/*typeDeclaration*/ <t>"
     ;
     
 interfaceTopLevelScope
@@ -443,17 +451,19 @@ localModifier
     
 type
     :   simpleType
+        -> template(type={$simpleType.st}) "<type>"
     |   objectType 
+        -> template(type={$objectType.st}) "<type>"
     ;
 
 simpleType
     :   ^(TYPE primitiveType arrayDeclaratorList?)
-        -> template(t={$text}) "<t>"
+        -> type(typeID={$primitiveType.st}, arrDeclList={$arrayDeclaratorList.st})
     ;
 
 objectType
     :   ^(TYPE qualifiedTypeIdent arrayDeclaratorList?)
-        -> template(t={$text}) "<t>"
+        -> type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
     ;
 
 qualifiedTypeIdent
@@ -468,7 +478,7 @@ typeIdent
 
 primitiveType
     :   BOOLEAN
-        -> template(t={$text}) "<t>"
+        -> template() "bool"
     |   CHAR
         -> template(t={$text}) "<t>"
     |   BYTE
@@ -505,18 +515,19 @@ genericWildcardBoundType
     ;
 
 formalParameterList
-    :   ^(FORMAL_PARAM_LIST formalParameterStandardDecl* formalParameterVarargDecl?) 
-        -> template(t={$text}) "<t>"
+    :   ^(FORMAL_PARAM_LIST (fpsd+=formalParameterStandardDecl)* fpvd=formalParameterVarargDecl?)
+        -> formal_param_list(sdecl={$fpsd}, vdecl={$fpvd.st})
     ;
     
 formalParameterStandardDecl
-    :   ^(FORMAL_PARAM_STD_DECL localModifierList type variableDeclaratorId)
-        -> template(t={$text}) "<t>"
+    :   ^(FORMAL_PARAM_STD_DECL lms=localModifierList t=type vdid=variableDeclaratorId)
+        -> formal_param_decl(modList={$lms.st}, type={$t.st}, declID={$vdid.st})
+        //-> template(t={$text}) "/*fpsd*/ <t>"
     ;
     
 formalParameterVarargDecl
     :   ^(FORMAL_PARAM_VARARG_DECL localModifierList type variableDeclaratorId)
-        -> template(t={$text}) "<t>"
+        -> template(t={$text}) "/*fpvd*/ <t>"
     ;
     
 qualifiedIdentifier
@@ -548,12 +559,12 @@ blockStatement
 localVariableDeclaration
     :   ^(PRIMITIVE_VAR_DECLARATION localModifierList simpleType variableDeclaratorList)
         -> primitive_var_decl(
-            modList={$localModifierList.st},
+            modList={null},
             type={$simpleType.st},
             declList={$variableDeclaratorList.st})
     |   ^(OBJECT_VAR_DECLARATION localModifierList objectType variableDeclaratorList)
         -> object_var_decl(
-            modList={$localModifierList.st},
+            modList={null},
             type={$objectType.st},
             declList={$variableDeclaratorList.st})
     ;
@@ -594,7 +605,6 @@ statement
         -> template(t={$text}) "<t>"
     |   ^(EMBED STRING_LITERAL EMBED_BLOCK)
         ->  embed_cc(str={$STRING_LITERAL.text}, blk={$EMBED_BLOCK.text})
-//template(t={$EMBED_BLOCK.text}) "<t>"
     |   SEMI // Empty statement.
         -> template(t={$text}) "<t>"
     ;
index e8794401f25ca850c1c99d217bfc5d44ceec7c39..d07e5bd05c92e32ab5a6478d7ded56d911048e3d 100644 (file)
@@ -140,10 +140,10 @@ scope ScopeStack; // default scope
     // there is exactly one public type and return that one.
     :   ^(CHARJ_SOURCE 
         (packageDeclaration)? 
-        (importDeclaration)* 
-        (typeDeclaration))
+        (importDeclarations) 
+        (typeDeclaration[$importDeclarations.packageNames]))
         //(typeDeclaration)*)
-        { $cs = null; }
+        { $cs = $typeDeclaration.sym; }
     ;
 
 // note: no new scope here--this replaces the default scope
@@ -164,11 +164,16 @@ packageDeclaration
         }
     ;
     
-importDeclaration
-    :   ^(IMPORT STATIC? qualifiedIdentifier DOTSTAR?)
+importDeclarations returns [List<CharjAST> packageNames]
+@init {
+       packageNames = new ArrayList<CharjAST>();
+}
+    :   (^(IMPORT STATIC? qualifiedIdentifier DOTSTAR?)
+               { packageNames.add($qualifiedIdentifier.start); })*
     ;
-    
-typeDeclaration returns [ClassSymbol sym]
+
+
+typeDeclaration[List<CharjAST> imports] returns [ClassSymbol sym]
 scope ScopeStack; // top-level type scope
     :   ^(CLASS m=modifierList IDENT g=genericTypeParameterList? 
                 e=classExtendsClause? i=implementsClause? c=classTopLevelScope) 
@@ -181,6 +186,7 @@ scope ScopeStack; // top-level type scope
             $sym.definitionTokenStream = input.getTokenStream();
             $IDENT.symbol = $sym;
             $ScopeStack::current = $sym;
+                       importPackages($sym, $imports);
         }
     |   ^(INTERFACE modifierList IDENT genericTypeParameterList? 
                 interfaceExtendsClause? interfaceTopLevelScope)
@@ -237,7 +243,7 @@ classScopeDeclarations
     |   ^(OBJECT_VAR_DECLARATION modifierList objectType variableDeclaratorList)
     |   ^(CONSTRUCTOR_DECL m=modifierList g=genericTypeParameterList? IDENT f=formalParameterList 
             t=throwsClause? b=block)
-    |   d=typeDeclaration
+    |   d=typeDeclaration[null]
     ;
     
 interfaceTopLevelScope
@@ -252,7 +258,7 @@ interfaceScopeDeclarations
         // there's an obligatory initializer.
     |   ^(PRIMITIVE_VAR_DECLARATION modifierList simpleType variableDeclaratorList)
     |   ^(OBJECT_VAR_DECLARATION modifierList objectType variableDeclaratorList)
-    |   typeDeclaration
+    |   typeDeclaration[null]
     ;
 
 variableDeclaratorList
@@ -383,7 +389,7 @@ block
     
 blockStatement
     :   localVariableDeclaration
-    |   typeDeclaration
+    |   typeDeclaration[null]
     |   statement
     ;
     
index 6f0262c63897cc4f4c21f158fd46d68765250a6b..260b22089de9d12d50624dc60280e58d7ab2e002 100644 (file)
@@ -64,6 +64,7 @@ public class SymbolTable {
         primitiveTypes.put("double", new ClassSymbol(this, "double", null, lang));
         primitiveTypes.put("char",   new ClassSymbol(this, "char",   null, lang)); 
         primitiveTypes.put("short",  new ClassSymbol(this, "short",  null, lang)); 
+        primitiveTypes.put("bool",   new ClassSymbol(this, "bool",   null, lang)); 
     }
 
     public ClassSymbol resolveBuiltinType(String type) {