implemented type loader, changed debug output to be more helpful, extended
authorAaron Becker <abecker3@illinois.edu>
Sun, 15 Jun 2008 04:19:54 +0000 (04:19 +0000)
committerAaron Becker <abecker3@illinois.edu>
Sun, 15 Jun 2008 04:19:54 +0000 (04:19 +0000)
error message capabilities.
to do: integrate type loading function in semantic tree walk

src/langs/charj/bin/charjc
src/langs/charj/build.xml
src/langs/charj/src/charj/Main.java
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/ClassSymbol.java
src/langs/charj/src/charj/translator/PackageScope.java
src/langs/charj/src/charj/translator/SymbolTable.java
src/langs/charj/src/charj/translator/SymbolWithScope.java
src/langs/charj/src/charj/translator/Translator.java

index daca53580d0b368e5bc34e1f0c5f4bce5ec921e5..e106cbbc033f563abc08b0edf9235293df694f0d 100755 (executable)
@@ -1,8 +1,9 @@
 #!/bin/bash
 
-CHARJCHOME=${0%${0##*/}}
+ECHO="false"                        # should we echo the our command to stdout?
+CHARJCHOME=${0%${0##*/}}            # location of charjc
+ANTLRHOME=$CHARJCHOME/../lib        # location of antlr jars
 ANTLR_VERSION="3.1"
-ANTLRHOME=$CHARJCHOME/../lib
 ANTLR_CLASSPATH=""
 
 if test "$ANTLR_VERSION" = "3.0"
@@ -32,6 +33,7 @@ CHARJ_JFLAGS="-classpath $CLASSPATH:$ANTLR_CLASSPATH:$JSAP_JAR:$CHARJ_JAR"
 # the charjc options alone.
 VERBOSE=false
 CHARMC=$CHARJCHOME../../../../bin/charmc
+STDLIB=$CHARJCHOME../charj/src/
 CHARMC_ARGS=
 FILES=
 ARGS=
@@ -52,8 +54,16 @@ processArgs() {
         "--stdout")
             ARGS="$ARGS $arg"
             ;;
+        "--stdlib")
+            STDLIB="$1"
+            shift
+            ;;
+        "--lib")
+            ARGS="$ARGS $arg $1"
+            shift
+            ;;
         "--charmc")
-            CHARMC="$arg"
+            CHARMC="$1"
             shift
             ;;
         *.cj)
@@ -69,8 +79,9 @@ processArgs() {
 }
 
 processArgs "$@"
-#if test "$VERBOSE" = "true"
-#then
-#    echo "java $CHARJ_JFLAGS charj.Main $ARGS $FILES"
-#fi
-java $CHARJ_JFLAGS charj.Main --charmc "$CHARMC" $ARGS $FILES
+if test "$ECHO" = "true"
+then
+    echo "java $CHARJ_JFLAGS charj.Main --charmc \"$CHARMC\" \
+    --stdlib $STDLIB $ARGS $FILES"
+fi
+java $CHARJ_JFLAGS charj.Main --charmc "$CHARMC" --stdlib $STDLIB $ARGS $FILES
index 8af0d6e204e04ca2d9149c0ea5d65698e12dc3d5..6a4bb28408d43e7a9624a54d19263a964fbfbe77 100644 (file)
             grammar.path="${buildsrc}/charj/translator"/>\r
     </target>\r
 \r
-    <target name="CharjEmitter" depends="Charj">\r
+    <target name="CharjSemantics" depends="Charj">\r
+        <antlr3 grammar.name="CharjSemantics.g" \r
+            grammar.path="${buildsrc}/charj/translator"/>\r
+    </target>\r
+\r
+    <target name="CharjEmitter" depends="CharjSemantics">\r
         <antlr3 grammar.name="CharjEmitter.g" \r
             grammar.path="${buildsrc}/charj/translator"/>\r
     </target>\r
 \r
-    <target name="compile" depends="Charj, CharjEmitter" description="compile">\r
+    <target name="compile" depends="CharjEmitter" description="compile">\r
         <javac debug="true" srcdir="${buildsrc}" destdir="${classes}"\r
                target="1.5" listfiles="Yes" deprecation="Yes">\r
                <classpath refid="${classpath}"/>\r
index 3943d950c549a33bd27c266eb18ba580f332aa09..db95c616f47e8738d464694ca7af4523eab72dd3 100644 (file)
@@ -2,12 +2,14 @@ package charj;
 
 import charj.translator.Translator;
 import java.io.FileInputStream;
-import java.util.Iterator;
+import java.util.*;
 import com.martiansoftware.jsap.*;
 
 public class Main 
 {
     public static String m_charmc;
+    public static String m_stdlib;
+    public static List<String> m_usrlibs;
     public static boolean m_debug;
     public static boolean m_verbose;
     public static boolean m_stdout;
@@ -15,7 +17,12 @@ public class Main
     public static void main(String[] args) throws Exception
     {
         String[] files = processArgs(args);
-        Translator t = new Translator(m_charmc, m_debug, m_verbose);
+        Translator t = new Translator(
+                m_charmc, 
+                m_debug, 
+                m_verbose,
+                m_stdlib,
+                m_usrlibs);
         for (String filename : files) { 
             if (!m_stdout) {
                 t.translate(filename);
@@ -38,6 +45,23 @@ public class Main
         _charmc.setHelp("Charm compiler used on generated charm code.");
         processor.registerParameter(_charmc);
 
+        FlaggedOption _stdlib = new FlaggedOption("stdlib")
+            .setStringParser(JSAP.STRING_PARSER)
+            .setRequired(false)
+            .setShortFlag(JSAP.NO_SHORTFLAG)
+            .setLongFlag("stdlib");
+        _stdlib.setHelp("Directory containing the Charj standard libary.");
+        processor.registerParameter(_stdlib);
+
+        FlaggedOption _usrlib = new FlaggedOption("usrlib")
+            .setStringParser(JSAP.STRING_PARSER)
+            .setRequired(false)
+            .setShortFlag(JSAP.NO_SHORTFLAG)
+            .setLongFlag("lib");
+        _usrlib.setHelp("Directories containing user Charj code, " +
+                "colon-delimited.");
+        processor.registerParameter(_usrlib);
+
         Switch _debug = new Switch("debug")
             .setShortFlag(JSAP.NO_SHORTFLAG)
             .setLongFlag("debug");
@@ -75,9 +99,18 @@ public class Main
         }
 
         m_charmc = config.getString("charmc") + charmcFlags;
+        m_stdlib = config.getString("stdlib");
         m_debug = config.getBoolean("debug", false);
         m_verbose = config.getBoolean("verbose", false);
         m_stdout = config.getBoolean("stdout", false);
+        
+        String usrlib = config.getString("usrlib");
+        if (usrlib != null) {
+            m_usrlibs = Arrays.asList(usrlib.split(":"));
+        } else {
+            m_usrlibs = null;
+        }
+
         String[] files = config.getStringArray("files");
         return files;
     }
index 44956c41780f47b0df02b0f50fb1c63168224053..d0fc158bb9a0cbd39a27c5352300ec28344f884e 100644 (file)
@@ -132,11 +132,11 @@ packageDeclaration
     List<String> names = null; 
 }
     :   ^(PACKAGE qualifiedIdentifier)  {
-            names =  java.util.Arrays.asList($qualifiedIdentifier.text.split("[.]"));
+            names =  java.util.Arrays.asList(
+                    $qualifiedIdentifier.text.split("[.]"));
         }
         -> {(emitCC() || emitH())}? packageDeclaration_cc_h(
             ids={names})
-            //ids={names})//{$qualifiedIdentifier.text.split("[.]")})
         ->
     ;
     
@@ -241,12 +241,6 @@ classScopeDeclarations
         { 
             // determine whether this is an entry method
             entry = listContainsToken($m.start.getChildren(), ENTRY);
-//            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}, 
@@ -280,12 +274,7 @@ classScopeDeclarations
             f=formalParameterList t=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;
-                }
-            }
+            entry = listContainsToken($m.start.getChildren(), ENTRY);
         }
         -> {emitCC()}? voidMethodDecl_cc(
                 modl={$m.st}, 
@@ -315,12 +304,7 @@ classScopeDeclarations
             t=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;
-                }
-            }
+            entry = listContainsToken($m.start.getChildren(), ENTRY);
         }
         -> {emitCC()}? ctorDecl_cc(
                 modl={$m.st}, 
index 772a88cdfd28a8c5997bcbd6297289c63b965b62..bc5a2dc34184acf7fcd1e4ba411dcb7958570aac 100644 (file)
@@ -108,7 +108,7 @@ package charj.translator;
         }
 
         for (CharjAST pkg : imports) {
-            String pkgName = pkg.getTokenStream().toString(
+            String pkgName = input.getTokenStream().toString(
                     pkg.getTokenStartIndex(),
                     pkg.getTokenStopIndex());
             // find imported class and add to cs.imports
@@ -134,6 +134,7 @@ charjSource[SymbolTable _symtab] returns [ClassSymbol cs]
         (p=packageDeclaration)? 
         (i+=importDeclaration)* 
         (t+=typeDeclaration)*)
+        { $cs = null; }
     ;
 
 packageDeclaration
@@ -141,7 +142,8 @@ packageDeclaration
     List<String> names = null; 
 }
     :   ^(PACKAGE qualifiedIdentifier)  {
-            names =  java.util.Arrays.asList($qualifiedIdentifier.text.split("[.]"));
+            names =  java.util.Arrays.asList(
+                    $qualifiedIdentifier.text.split("[.]"));
         }
     ;
     
index 7911c0441a7431b2af420b95ced64e3790753dcf..1f849bc7064792e8319eb9bbfdb3b8aead37d122 100644 (file)
@@ -88,7 +88,7 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
             return p;
         }
 
-        if ( symtab.translator.findPackage(packageName)!=null ) {
+        if ( symtab.translator.findPackage(packageName) != null ) {
             p = symtab.definePkg(packageName);
             imports.put(packageName, p);
         }
index 468b79bf19fb063299fe5be974d8dd87617580ed..939d148f775c2cf96a87d7b6fee318ccdd8376e1 100644 (file)
@@ -33,7 +33,7 @@ public class PackageScope extends SymbolWithScope {
     public ClassSymbol resolveType(String type) 
     {
         if (debug()) System.out.println(
-                "PackageScope.resolveType(" + type + 
+                " PackageScope.resolveType(" + type + 
                 "): examine " + toString());
 
         // look for type in this package's members (other packages, classes)
@@ -41,7 +41,7 @@ public class PackageScope extends SymbolWithScope {
             Symbol s = getMembers().get(type);
             if ( s!=null && s instanceof ClassSymbol ) {
                 if (debug()) System.out.println(
-                        "PackageScope.resolveType(" + type + "): found in " + 
+                        " PackageScope.resolveType(" + type + "): found in " + 
                         toString());
                 return (ClassSymbol)s;
             }
index bd886160e5e6ffd536e3a087303d5d0c67756545..f697c4d28fbe872ff5590ba31e693e8ed7f209a4 100644 (file)
@@ -74,7 +74,7 @@ public class SymbolTable {
         if ( outerPackage == null ) {
             if ( debug() ) {
                 System.out.println(
-                        "definePkg(" + packageName + 
+                        " SymbolTable.definePkg(" + packageName + 
                         "): defining outer pkg: " + outerPackageName);
             }
             outerPackage = new PackageScope(this,outerPackageName,defaultPkg);
@@ -87,7 +87,7 @@ public class SymbolTable {
             PackageScope p = (PackageScope)enclosingPackage.resolve(pname);
             if ( p==null ) {
                 if ( debug() ) System.out.println(
-                        "definePkg(" + packageName + 
+                        " SymbolTable.definePkg(" + packageName + 
                         "): defining inner pkg: " + pname +
                         " in "+enclosingPackage.toString());
                 
@@ -109,7 +109,7 @@ public class SymbolTable {
     public PackageScope resolvePackage(String packageName) 
     {
         if ( debug() ) System.out.println(
-                "SymbolTable.resolvePackage(" + packageName + 
+                " SymbolTable.resolvePackage(" + packageName + 
                 "): examine: " + topLevelPackageScopes.keySet());
         String[] packageNames = packageName.split("::");
         String outerPackageName = packageNames[0];
@@ -118,7 +118,8 @@ public class SymbolTable {
 
         if ( enclosingPackage==null ) {
             if ( debug() ) System.out.println(
-                    "resolvePackage(" + packageName + "): outer package " +
+                    " SymbolTable.resolvePackage(" + packageName + 
+                    "): outer package " +
                     outerPackageName + " not found in top level " +
                     topLevelPackageScopes.keySet());
             return null;
@@ -134,7 +135,7 @@ public class SymbolTable {
             p = (PackageScope)enclosingPackage.resolve(pname);
             if ( p==null ) {
                 if ( debug() ) System.out.println(
-                        "SymbolTable.resolvePackage(" + packageName +
+                        " SymbolTable.resolvePackage(" + packageName +
                         "): not found in " + topLevelPackageScopes.keySet());
                 return null;
             }
@@ -142,7 +143,7 @@ public class SymbolTable {
         }
 
         if ( p!=null && debug() ) System.out.println(
-                "SymbolTable.resolvePackage(" + packageName + "): found in " +
+                " SymbolTable.resolvePackage(" + packageName + "): found in " +
                 topLevelPackageScopes.keySet());
         return p;
     }
index b42967d53b2e5e2f7661eb5bad2de713250146ea..340607d259f684f66c16499fcc83fa74369cd83c 100644 (file)
@@ -146,7 +146,7 @@ public abstract class SymbolWithScope
         members.put(name, sym);
         sym.scope = this; // track the scope in each symbol
         
-        if (debug()) System.out.println("define " + name + " as " + sym);
+        if (debug()) System.out.println(" \tdefine " + name + " as " + sym);
         return sym;
     }
 
index 93113828a4b3581741741ca1bb8131fca9359766..77be0517ceb031f8d2566c02ad144031e1f847ff 100644 (file)
@@ -1,5 +1,3 @@
-/***
-***/
 
 package charj.translator;
 
@@ -19,7 +17,6 @@ import org.antlr.stringtemplate.*;
  */
 public class Translator {
 
-    // template file locations
     public static final String templateFile = "charj/translator/Charj.stg";
 
     // variables controlled by command-line arguments
@@ -32,6 +29,8 @@ public class Translator {
     private String m_stdlib;
     private List<String> m_usrlibs;
 
+    private SymbolTable m_symtab;
+
     public Translator(
             String _charmc,
             boolean _debug,
@@ -44,13 +43,14 @@ public class Translator {
         m_verbose   = _verbose;
         m_stdlib    = _stdlib;
         m_usrlibs   = _usrlibs;
+        m_symtab    = new SymbolTable(this);
         m_errorCondition = false;
     }
 
     public boolean debug()      { return m_debug; }
     public boolean verbose()    { return m_verbose; }
 
-    public static TreeAdaptor adaptor = new CommonTreeAdaptor() {
+    public static TreeAdaptor m_adaptor = new CommonTreeAdaptor() {
         public Object create(Token token) {
             return new CharjAST(token);
         }
@@ -68,6 +68,10 @@ public class Translator {
         ANTLRFileStream input = new ANTLRFileStream(filename);
             
         CharjLexer lexer = new CharjLexer(input);
+
+        semanticPass(lexer);
+
+        input.seek(0);
         String ciOutput = translationPass(lexer, OutputMode.ci);
         writeTempFile(filename, ciOutput, OutputMode.ci);
 
@@ -90,27 +94,160 @@ public class Translator {
             ccHeader + ccOutput + footer;
     }
 
-    private String translationPass(
-            CharjLexer lexer, 
-            OutputMode m) throws
+    private CommonTreeNodeStream prepareNodes(
+            CommonTokenStream tokens,
+            CharjLexer lexer) throws
         RecognitionException, IOException, InterruptedException
     {
         // Use lexer tokens to feed tree parser
-        CommonTokenStream tokens = new CommonTokenStream(lexer);
         CharjParser parser = new CharjParser(tokens);
-        parser.setTreeAdaptor(adaptor);
+        parser.setTreeAdaptor(m_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);
+        nodes.setTreeAdaptor(m_adaptor);
+        return nodes;
+    }
+
+    private String translationPass(
+            CharjLexer lexer, 
+            OutputMode m) throws
+        RecognitionException, IOException, InterruptedException
+    {
+        CommonTokenStream tokens = new CommonTokenStream(lexer);
+        CommonTreeNodeStream nodes = prepareNodes(tokens, lexer);
+        nodes.setTokenStream(tokens);
+        nodes.setTreeAdaptor(m_adaptor);
 
         String output = emit(nodes, m);
         return output;
     }
 
+    private ClassSymbol semanticPass(CharjLexer lexer) throws
+        RecognitionException, IOException, InterruptedException
+    {
+        CommonTokenStream tokens = new CommonTokenStream(lexer);
+        CommonTreeNodeStream nodes = prepareNodes(tokens, lexer);
+        nodes.setTokenStream(tokens);
+        nodes.setTreeAdaptor(m_adaptor);
+
+        CharjSemantics sem = new CharjSemantics(nodes);
+        ClassSymbol cs = sem.charjSource(m_symtab).cs;
+        return cs;
+    }
+
+    private String emit(
+            CommonTreeNodeStream nodes, 
+            OutputMode m) throws
+        RecognitionException, IOException, InterruptedException
+    {
+        CharjEmitter emitter = new CharjEmitter(nodes);
+        StringTemplateGroup templates = getTemplates(templateFile);
+        emitter.setTemplateLib(templates);
+        StringTemplate st = 
+            (StringTemplate)emitter.charjSource(m).getTemplate();
+        return st.toString();
+    }
+
+
+
+    private StringTemplateGroup getTemplates(String templateFile)
+    {
+        StringTemplateGroup templates = null;
+        try {
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            InputStream istream = loader.getResourceAsStream(templateFile);
+            BufferedReader reader = 
+                new BufferedReader(new InputStreamReader(istream));
+            templates = new StringTemplateGroup(reader);
+            reader.close();
+        } catch(IOException ex) {
+            error("Failed to load template file", ex); 
+        }
+        return templates;
+    }
+
+    public File findPackage(String packageName)
+    {
+        String packageDir = packageName.replaceAll("::", "/");
+        File p = new File(packageDir);
+        if ( debug() ) System.out.println(
+                " [charj] findPackage " + packageName + 
+                " trying " + p.getAbsoluteFile());
+       
+        // check current directory
+        if ( p.exists() ) {
+            return p;
+        }
+
+        // look in user libs if any
+        if ( m_usrlibs != null ) {
+            for (String lib : m_usrlibs) {
+                p = new File(lib, packageDir);
+                if (debug() ) System.out.println(
+                        " \tnot found, now trying " + p.getAbsoluteFile());
+                if ( p.exists() ) {
+                    return p;
+                }
+            }
+        }
+
+        // look in standard lib
+        p = new File(m_stdlib, packageDir);
+        if ( debug() ) System.out.println(
+                " \tnot found, now trying " + p.getAbsoluteFile());
+        if ( p.exists() ) {
+            return p;
+        }
+
+        return null;
+    }
+
+    /** Load a class from disk looking in lib/package
+     *  Side-effect: add class to symtab. This is used by ClassSymbol to
+     *  load unknown types from disk. packageName comes from the output
+     *  of PackageScope.getFullyQualifiedName
+     */
+    public ClassSymbol loadType(String packageName, String typeName)
+    {
+        if (debug()) System.out.println(
+                " [charj] loadType(" + typeName + ") from " + packageName);
+        
+        ClassSymbol cs = null;
+        try {
+            String packageDir = ".";
+            if ( packageName!=null ) {
+                packageDir = packageName.replaceAll("::", "/");
+            }
+            String fullName = packageDir + "/" + typeName + ".cj";
+               
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            boolean fileExists = (cl.getResource(fullName) == null);
+            if (!fileExists) {
+                if (debug()) System.out.println(
+                        " \tloadType(" + typeName + "): not found");
+                return null;
+            }
+
+            if (debug()) System.out.println(
+                    " \tloadType(" + typeName + "): parsing " + 
+                    packageName + "::" + typeName);
+            
+            ANTLRInputStream fs = new ANTLRInputStream(
+                    cl.getResourceAsStream(fullName));
+            fs.name = packageDir + "/" + typeName + ".cj";
+            CharjLexer lexer = new CharjLexer(fs);
+            
+            cs = semanticPass(lexer);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return cs;
+    }
+
     /**
      * Utility function to write a generated .ci or .cc
      * file to disk. Takes a .cj filename and writes a .cc
@@ -212,105 +349,46 @@ public class Translator {
         int retVal = p.exitValue();
         return retVal;
     }
-
-    private String emit(
-            CommonTreeNodeStream nodes, 
-            OutputMode m) throws
-        RecognitionException, IOException, InterruptedException
-    {
-        CharjEmitter emitter = new CharjEmitter(nodes);
-        StringTemplateGroup templates = getTemplates(templateFile);
-        emitter.setTemplateLib(templates);
-        StringTemplate st = (StringTemplate)emitter.charjSource(m).getTemplate();
-        return st.toString();
-    }
-
-    private StringTemplateGroup getTemplates(String templateFile)
-    {
-        StringTemplateGroup templates = null;
-        try {
-            ClassLoader loader = Thread.currentThread().getContextClassLoader();
-            InputStream istream = loader.getResourceAsStream(templateFile);
-            BufferedReader reader = 
-                new BufferedReader(new InputStreamReader(istream));
-            templates = new StringTemplateGroup(reader);
-            reader.close();
-        } catch(IOException ex) {
-            error("Failed to load template file", ex); 
-        }
-        return templates;
-    }
-
-    public File findPackage(String packageName)
+    
+    public void error(
+            BaseRecognizer recog, 
+            String msg, 
+            CharjAST node) 
     {
-        String packageDir = packageName.replaceAll("::", "/");
-        File p = new File(packageDir);
-        if ( debug() ) System.out.println(
-                "findPackage " + packageName + 
-                " trying " + p.getAbsoluteFile());
-       
-        // check current directory
-        if ( p.exists() ) {
-            return p;
-        }
-
-        // look in user libs if any
-        if ( m_usrlibs != null ) {
-            for (String lib : m_usrlibs) {
-                p = new File(lib, packageDir);
-                if (debug() ) System.out.println(
-                        "not found, now trying " + p.getAbsoluteFile());
-                if ( p.exists() ) {
-                    return p;
-                }
-            }
+        String sourceName = "";
+        if (recog == null) {
+            sourceName = "<anonymous>";
+        } else {
+            sourceName = recog.getSourceName();
         }
+        error(sourceName, msg, node);
+    } 
 
-        // look in standard lib
-        p = new File(m_stdlib, packageDir);
-        if ( debug() ) System.out.println(
-                "not found, now trying " + p.getAbsoluteFile());
-        if ( p.exists() ) {
-            return p;
-        }
-
-        return null;
-    }
-
-    /** Load a class from disk looking in lib/package
-     *  Side-effect: add class to symtab.
-     */
-    public ClassSymbol loadType(String packageName, String typeName)
-    {
-        // TODO: implement me
-        return null;
-    }
-    
     private void error(
             String sourceName, 
             String msg, 
-            CommonTree node) 
+            CharjAST node) 
     {
         m_errorCondition = true;
         String linecol = ":";
         if ( node!=null ) {
             CommonToken t = (CommonToken)node.getToken();
-            linecol = ": line " + t.getLine() + ":" + t.getCharPositionInLine();
+            linecol = ": line " + t.getLine() + ":" + 
+                t.getCharPositionInLine();
         }
         System.err.println(sourceName + linecol + " " + msg);
         System.err.flush();
     }
 
-
     private void error(
             String sourceName, 
             String msg) {
-        error(sourceName, msg, (CommonTree)null);
+        error(sourceName, msg, (CharjAST)null);
     }
 
 
     public void error(String msg) {
-        error(" [charjc] error", msg, (CommonTree)null);
+        error(" [charjc] error", msg, (CharjAST)null);
     }