Charj: Simplified method handling, methods now registered with parents
authorAaron Becker <akbecker@gmail.com>
Sun, 23 May 2010 02:01:56 +0000 (21:01 -0500)
committerAaron Becker <akbecker@gmail.com>
Sun, 23 May 2010 02:01:56 +0000 (21:01 -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
src/langs/charj/src/charj/translator/SymbolTable.java

index 36e47d887db529f0175bd4b8d4879b1fa3c14e6e..3e929c34136cca9c43bf5724d0a89b152b026ec5 100644 (file)
@@ -100,7 +100,6 @@ tokens {
     OBJECT_VAR_DECLARATION;
     VAR_DECLARATOR;
     VAR_DECLARATOR_LIST;
-    VOID_METHOD_DECL;
 }
 
 @header {
@@ -197,8 +196,6 @@ classScopeDeclaration
             (   type IDENT formalParameterList arrayDeclaratorList? (block | ';')
                 ->  ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? type IDENT
                     formalParameterList arrayDeclaratorList? block?)
-            |   'void' IDENT formalParameterList (block | ';')
-                ->  ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList block?)
             |   ident=IDENT formalParameterList block
                 ->  ^(CONSTRUCTOR_DECL[$ident, "CONSTRUCTOR_DECL"] modifierList? genericTypeParameterList? IDENT
                         formalParameterList block)
@@ -216,8 +213,6 @@ interfaceScopeDeclaration
             (   type IDENT formalParameterList arrayDeclaratorList? ';'
                 ->  ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList?
                         type IDENT formalParameterList arrayDeclaratorList?)
-            |   'void' IDENT formalParameterList ';'
-                ->  ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList)
             )
         |   simpleType interfaceFieldDeclaratorList ';'
             ->  ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType interfaceFieldDeclaratorList)
@@ -324,6 +319,7 @@ localModifier
 type
     :   simpleType
     |   objectType
+    |   'void'
     ;
 
 simpleType
index 1990632695c9f9402c85e3ce674ac088c2f4d1fb..5286fefa68f4e3a7c41e0fede0dfe5ca3bea86cc 100644 (file)
@@ -166,26 +166,6 @@ funcMethodDecl_cc(modl, gtpl, ty, id, fpl, adl, block) ::=
 >>
 
 
-voidMethodDecl_ci(modl, gtpl, id, fpl, block) ::=
-<<
-entry void<gtpl> <id><fpl>;
->>
-
-
-voidMethodDecl_h(modl, gtpl, id, fpl, block) ::=
-<<
-<if(modl)><modl>: <endif>void<gtpl> <id><fpl>;
->>
-
-
-voidMethodDecl_cc(modl, gtpl, id, fpl, block) ::=
-<<
-<if(modl)><modl>: <endif>void<gtpl> <id><fpl> {
-    <block>
-}
->>
-
-
 ctorDecl_ci(modl, gtpl, id, fpl, block) ::=
 <<
 entry void<gtpl> <id><fpl>;
index a39bad5f90378e38009ff56ebf4a47c74ee29d7a..e6e3ff3492bcec184b86e78cfac381d0fb6c8853 100644 (file)
@@ -214,33 +214,6 @@ classScopeDeclaration
                 adl={$a.st},
                 block={$b.st})
         ->
-    |   ^(VOID_METHOD_DECL m=modifierList? g=genericTypeParameterList? IDENT 
-            f=formalParameterList b=block?)
-        { 
-            // determine whether this is an entry method
-            if ($m.st != null) {
-                entry = listContainsToken($m.start.getChildren(), ENTRY);
-            }
-        }
-        -> {emitCC()}? voidMethodDecl_cc(
-                modl={$m.st}, 
-                gtpl={$g.st}, 
-                id={$IDENT.text}, 
-                fpl={$f.st}, 
-                block={$b.st})
-        -> {emitCI() && entry}? voidMethodDecl_ci(
-                modl={$m.st}, 
-                gtpl={$g.st}, 
-                id={$IDENT.text}, 
-                fpl={$f.st}, 
-                block={$b.st})
-        -> {emitH()}? voidMethodDecl_h(
-                modl={$m.st}, 
-                gtpl={$g.st}, 
-                id={$IDENT.text}, 
-                fpl={$f.st}, 
-                block={$b.st})
-        ->
     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
         -> {emitCC() || emitH()}? class_var_decl(
             modl={$modifierList.st},
@@ -284,8 +257,6 @@ classScopeDeclaration
 interfaceScopeDeclaration
     :   ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? type IDENT formalParameterList arrayDeclaratorList?)
         -> template(t={$text}) "/*interfaceScopeDeclarations-not implemented */ <t>"
-    |   ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList)
-        -> template(t={$text}) "/*interfaceScopeDeclarations-not implemented */ <t>"
     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
         -> template(t={$text}) "/*interfaceScopeDeclarations-not implemented */ <t>"
     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList)
index b5ff63f26104a326ef9ba7355ac0333062027ca2..3ec2101328fba6e1254454ce0480a314b5fe84ee 100644 (file)
@@ -148,11 +148,19 @@ enumConstant
     ;
     
 classScopeDeclaration
+scope ScopeStack;
     :   ^(FUNCTION_METHOD_DECL m=modifierList? g=genericTypeParameterList? 
             ty=type IDENT f=formalParameterList a=arrayDeclaratorList? 
             b=block?)
-    |   ^(VOID_METHOD_DECL m=modifierList? g=genericTypeParameterList? IDENT 
-            f=formalParameterList b=block?)
+        {
+            ClassSymbol returnType = currentClass.resolveType($ty.text);
+            MethodSymbol sym = new MethodSymbol(symtab, $IDENT.text, currentClass, returnType);
+            currentMethod = sym;
+            sym.definition = $classScopeDeclaration.start;
+            sym.definitionTokenStream = input.getTokenStream();
+            currentClass.members.put($IDENT.text, sym);
+            $FUNCTION_METHOD_DECL.symbol = sym;
+        }
     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList)
     |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
@@ -162,7 +170,6 @@ classScopeDeclaration
 interfaceScopeDeclaration
     :   ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? 
             type IDENT formalParameterList arrayDeclaratorList?)
-    |   ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList)
         // Interface constant declarations have been switched to variable
         // declarations by Charj.g; the parser has already checked that
         // there's an obligatory initializer.
index 59b9037f0f8974dc2951502b6c81e81b76a8a6eb..e557f8dcc64caffe4cc4ed0c48ed84ee925d87e8 100644 (file)
@@ -59,6 +59,7 @@ public class SymbolTable {
         objectRoot.define("EOF", new VariableSymbol(this,"EOF",null));
         lang.define("Object", objectRoot);
 
+        primitiveTypes.put("void",   new ClassSymbol(this, "void",   null, lang));
         primitiveTypes.put("int",    new ClassSymbol(this, "int",    null, lang));
         primitiveTypes.put("long",   new ClassSymbol(this, "long",   null, lang));
         primitiveTypes.put("float",  new ClassSymbol(this, "float",  null, lang));