Added tree adaptor for new AST node type
authorAaron Becker <abecker3@illinois.edu>
Mon, 9 Jun 2008 21:15:48 +0000 (21:15 +0000)
committerAaron Becker <abecker3@illinois.edu>
Mon, 9 Jun 2008 21:15:48 +0000 (21:15 +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/Translator.java

index 7f33e14bea1402abe1d4b0e4076fd51b4782b4f4..aec74fc50e30e9d62499d7c3b45b6f79ea55652a 100644 (file)
@@ -296,7 +296,7 @@ typeDeclaration
         )
     ;
     
-classTypeDeclaration[CommonTree modifiers]
+classTypeDeclaration[CharjAST modifiers]
     :   CLASS IDENT genericTypeParameterList? classExtendsClause? implementsClause? classBody
         ->  ^(CLASS {$modifiers} IDENT genericTypeParameterList? classExtendsClause? implementsClause? classBody)
     ;
@@ -341,7 +341,7 @@ bound
         ->  ^(EXTENDS_BOUND_LIST[$EXTENDS, "EXTENDS_BOUND_LIST"] type+)
     ;
 
-enumTypeDeclaration[CommonTree modifiers]
+enumTypeDeclaration[CharjAST modifiers]
     :   ENUM IDENT implementsClause? enumBody
         ->  ^(ENUM {$modifiers} IDENT implementsClause? enumBody)
     ;
@@ -368,7 +368,7 @@ enumConstant
     :   IDENT^ arguments? classBody?
     ;
     
-interfaceTypeDeclaration[CommonTree modifiers]
+interfaceTypeDeclaration[CharjAST modifiers]
     :   INTERFACE IDENT genericTypeParameterList? interfaceExtendsClause? interfaceBody
         ->  ^(INTERFACE {$modifiers} IDENT genericTypeParameterList? interfaceExtendsClause? interfaceBody)
     ;
index a89d9dacbb538c363a8e369efb457cba810a6782..d94e85f6483bcd2e88cbd10e720af6e7de65d67e 100644 (file)
@@ -101,6 +101,19 @@ funcMethodDecl_h(modl,
 >>
 
 
+funcMethodDecl_ci(modl, 
+            gtpl,
+            ty,
+            id,
+            fpl,
+            adl,
+            tc,
+            block) ::=
+<<
+entry <ty> <gtpl> <id><fpl> <adl> <tc>;
+>>
+
+
 funcMethodDecl_cc(modl, 
             gtpl,
             ty,
index 5dd936daca541e367a57e0f412c04a2654d78515..6021ea8754c81564b62c4a4c0ac71968a5f20fb1 100644 (file)
@@ -191,6 +191,7 @@ classTopLevelScope
     ;
     
 classScopeDeclarations
+//@init { boolean entry = false; }
     :   ^(CLASS_INSTANCE_INITIALIZER block)
         -> template(t={$text}) "/*cii*/ <t>"
     |   ^(CLASS_STATIC_INITIALIZER block)
@@ -198,6 +199,15 @@ classScopeDeclarations
     |   ^(FUNCTION_METHOD_DECL m=modifierList g=genericTypeParameterList? 
             ty=type IDENT f=formalParameterList a=arrayDeclaratorList? 
             tc=throwsClause? b=block?)
+//        { 
+//            // determine whether this is an entry method
+//            CharjAST modList = (CharjAST)$m.start;
+//            for (CharjAST mod : (List<CharjAST>)modList.getChildren()) {
+//                if (mod.token.getType() == ENTRY) {
+//                    entry = true;
+//                }
+//            }
+//        }
         -> {emitCC()}? funcMethodDecl_cc(
                 modl={$m.st}, 
                 gtpl={$g.st}, 
@@ -216,6 +226,15 @@ classScopeDeclarations
                 adl={$a.st},
                 tc={$tc.st}, 
                 block={$b.st})
+//        -> {(emitCI() && entry)}? funcMethodDecl_ci(
+//                modl={$m.st}, 
+//                gtpl={$g.st}, 
+//                ty={$ty.text},
+//                id={$IDENT.text}, 
+//                fpl={$f.st}, 
+//                adl={$a.st},
+//                tc={$tc.st}, 
+//                block={$b.st})
         ->
     |   ^(VOID_METHOD_DECL m=modifierList g=genericTypeParameterList? IDENT 
             f=formalParameterList t=throwsClause? b=block?)
index b2a2b3dab93c6f39030b8bf4792c914773865825..b7c2a8051662667ced52ba8b1c503d4699b56e6b 100644 (file)
@@ -38,6 +38,19 @@ public class Translator {
         m_errorCondition = false;
     }
 
+    public static TreeAdaptor adaptor = new CommonTreeAdaptor() {
+        public Object create(Token token) {
+            return new CharjAST(token);
+        }
+        
+        public Object dupNode(Object t) {
+            if (t == null) {
+                return null;
+            }
+            return create(((CharjAST)t).token);
+        }
+    };
+
     public String translate(String filename) throws Exception 
     {
         ANTLRFileStream input = new ANTLRFileStream(filename);
@@ -73,12 +86,14 @@ public class Translator {
         // Use lexer tokens to feed tree parser
         CommonTokenStream tokens = new CommonTokenStream(lexer);
         CharjParser parser = new CharjParser(tokens);
+        parser.setTreeAdaptor(adaptor);
         CharjParser.charjSource_return r = parser.charjSource();
 
         // Create node stream for emitters
         CommonTree t = (CommonTree)r.getTree();
         CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
         nodes.setTokenStream(tokens);
+        nodes.setTreeAdaptor(adaptor);
 
         String output = emit(nodes, m);
         return output;