PatchSet 7046 
Date: 2005/12/24 21:50:41
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Updated ANTLR in gjdoc to latest version

2005-12-24  Dalibor Topic  <[EMAIL PROTECTED]>

        * tools/gjdoc/javalb/antlr: Updated to ANTLR 2.7.6.

Members: 
        ChangeLog:1.4565->1.4566 
        tools/gjdoc/javalib/Makefile.am:1.20->1.21 
        tools/gjdoc/javalib/Makefile.in:1.69->1.70 
        tools/gjdoc/javalib/antlr/ANTLRException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/ANTLRHashString.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/ANTLRStringBuffer.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/ASTFactory.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/ASTNULLType.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/ASTPair.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/BaseAST.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/ByteBuffer.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/CharBuffer.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/CharFormatter.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/CharQueue.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/CharScanner.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/CharStreamException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/CharStreamIOException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/CommonAST.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/CommonToken.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/DefaultFileLineFormatter.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/FileLineFormatter.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/InputBuffer.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/LLkParser.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/LexerSharedInputState.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/MismatchedCharException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/MismatchedTokenException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/NoViableAltException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/NoViableAltForCharException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/Parser.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/ParserSharedInputState.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/RecognitionException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/SemanticException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/Token.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/TokenBuffer.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/TokenQueue.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/TokenStream.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/TokenStreamException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/TokenStreamIOException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/TokenStreamRecognitionException.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/TreeParser.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/TreeParserSharedInputState.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/Utils.java:INITIAL->1.1 
        tools/gjdoc/javalib/antlr/collections/AST.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/collections/ASTEnumeration.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/collections/Enumerator.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/collections/impl/ASTArray.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/collections/impl/ASTEnumerator.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/collections/impl/BitSet.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/collections/impl/IntRange.java:1.1->1.2 
        tools/gjdoc/javalib/antlr/collections/impl/Vector.java:1.1->1.2 
        
tools/gjdoc/javalib/antlr/collections/impl/VectorEnumerator.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4565 kaffe/ChangeLog:1.4566
--- kaffe/ChangeLog:1.4565      Sat Dec 24 19:56:46 2005
+++ kaffe/ChangeLog     Sat Dec 24 21:50:41 2005
@@ -1,5 +1,9 @@
 2005-12-24  Dalibor Topic  <[EMAIL PROTECTED]>
 
+        * tools/gjdoc/javalb/antlr: Updated to ANTLR 2.7.6.
+
+2005-12-24  Dalibor Topic  <[EMAIL PROTECTED]>
+
         * tools/gjdoc/javalib: Resynched GNU gjdoc.
 
 2005-12-23  Ito Kazumitsu  <[EMAIL PROTECTED]>
Index: kaffe/tools/gjdoc/javalib/Makefile.am
diff -u kaffe/tools/gjdoc/javalib/Makefile.am:1.20 
kaffe/tools/gjdoc/javalib/Makefile.am:1.21
--- kaffe/tools/gjdoc/javalib/Makefile.am:1.20  Sat Dec 24 19:56:51 2005
+++ kaffe/tools/gjdoc/javalib/Makefile.am       Sat Dec 24 21:50:45 2005
@@ -56,6 +56,7 @@
        antlr/TokenQueue.java \
        antlr/FileLineFormatter.java \
        antlr/BaseAST.java \
+       antlr/Utils.java \
        antlr/debug/MessageListener.java \
        antlr/debug/ParserListener.java \
        antlr/debug/ParserMatchListener.java \
Index: kaffe/tools/gjdoc/javalib/Makefile.in
diff -u kaffe/tools/gjdoc/javalib/Makefile.in:1.69 
kaffe/tools/gjdoc/javalib/Makefile.in:1.70
--- kaffe/tools/gjdoc/javalib/Makefile.in:1.69  Sat Dec 24 19:56:51 2005
+++ kaffe/tools/gjdoc/javalib/Makefile.in       Sat Dec 24 21:50:48 2005
@@ -390,6 +390,7 @@
        antlr/TokenQueue.java \
        antlr/FileLineFormatter.java \
        antlr/BaseAST.java \
+       antlr/Utils.java \
        antlr/debug/MessageListener.java \
        antlr/debug/ParserListener.java \
        antlr/debug/ParserMatchListener.java \
Index: kaffe/tools/gjdoc/javalib/antlr/ANTLRException.java
diff -u kaffe/tools/gjdoc/javalib/antlr/ANTLRException.java:1.1 
kaffe/tools/gjdoc/javalib/antlr/ANTLRException.java:1.2
--- kaffe/tools/gjdoc/javalib/antlr/ANTLRException.java:1.1     Sat Sep 17 
21:38:42 2005
+++ kaffe/tools/gjdoc/javalib/antlr/ANTLRException.java Sat Dec 24 21:50:48 2005
@@ -1,19 +1,27 @@
-package antlr;
-
-/* ANTLR Translator Generator
- * Project led by Terence Parr at http://www.jGuru.com
- * Software rights: http://www.antlr.org/license.html
- *
- * $Id: ANTLRException.java,v 1.1 2005/09/17 21:38:42 robilad Exp $
- */
-
-public class ANTLRException extends Exception {
-
-    public ANTLRException() {
-        super();
-    }
-
-    public ANTLRException(String s) {
-        super(s);
-    }
-}
+package antlr;
+
+/* ANTLR Translator Generator
+ * Project led by Terence Parr at http://www.cs.usfca.edu
+ * Software rights: http://www.antlr.org/license.html
+ *
+ * $Id: ANTLRException.java,v 1.2 2005/12/24 21:50:48 robilad Exp $
+ */
+
+public class ANTLRException extends Exception {
+
+    public ANTLRException() {
+        super();
+    }
+
+    public ANTLRException(String s) {
+        super(s);
+    }
+
+       public ANTLRException(String message, Throwable cause) {
+               super(message, cause);
+       }
+       
+       public ANTLRException(Throwable cause) {
+               super(cause);
+       }
+}
Index: kaffe/tools/gjdoc/javalib/antlr/ANTLRHashString.java
diff -u kaffe/tools/gjdoc/javalib/antlr/ANTLRHashString.java:1.1 
kaffe/tools/gjdoc/javalib/antlr/ANTLRHashString.java:1.2
--- kaffe/tools/gjdoc/javalib/antlr/ANTLRHashString.java:1.1    Sat Sep 17 
21:38:42 2005
+++ kaffe/tools/gjdoc/javalib/antlr/ANTLRHashString.java        Sat Dec 24 
21:50:48 2005
@@ -1,10 +1,10 @@
 package antlr;
 
 /* ANTLR Translator Generator
- * Project led by Terence Parr at http://www.jGuru.com
+ * Project led by Terence Parr at http://www.cs.usfca.edu
  * Software rights: http://www.antlr.org/license.html
  *
- * $Id: ANTLRHashString.java,v 1.1 2005/09/17 21:38:42 robilad Exp $
+ * $Id: ANTLRHashString.java,v 1.2 2005/12/24 21:50:48 robilad Exp $
  */
 
 // class implements a String-like object whose sole purpose is to be
Index: kaffe/tools/gjdoc/javalib/antlr/ANTLRStringBuffer.java
diff -u kaffe/tools/gjdoc/javalib/antlr/ANTLRStringBuffer.java:1.1 
kaffe/tools/gjdoc/javalib/antlr/ANTLRStringBuffer.java:1.2
--- kaffe/tools/gjdoc/javalib/antlr/ANTLRStringBuffer.java:1.1  Sat Sep 17 
21:38:42 2005
+++ kaffe/tools/gjdoc/javalib/antlr/ANTLRStringBuffer.java      Sat Dec 24 
21:50:48 2005
@@ -1,10 +1,10 @@
 package antlr;
 
 /* ANTLR Translator Generator
- * Project led by Terence Parr at http://www.jGuru.com
+ * Project led by Terence Parr at http://www.cs.usfca.edu
  * Software rights: http://www.antlr.org/license.html
  *
- * $Id: ANTLRStringBuffer.java,v 1.1 2005/09/17 21:38:42 robilad Exp $
+ * $Id: ANTLRStringBuffer.java,v 1.2 2005/12/24 21:50:48 robilad Exp $
  */
 
 // Implementation of a StringBuffer-like object that does not have the
Index: kaffe/tools/gjdoc/javalib/antlr/ASTFactory.java
diff -u kaffe/tools/gjdoc/javalib/antlr/ASTFactory.java:1.1 
kaffe/tools/gjdoc/javalib/antlr/ASTFactory.java:1.2
--- kaffe/tools/gjdoc/javalib/antlr/ASTFactory.java:1.1 Sat Sep 17 21:38:42 2005
+++ kaffe/tools/gjdoc/javalib/antlr/ASTFactory.java     Sat Dec 24 21:50:48 2005
@@ -1,410 +1,410 @@
-package antlr;
-
-/* ANTLR Translator Generator
- * Project led by Terence Parr at http://www.jGuru.com
- * Software rights: http://www.antlr.org/license.html
- *
- * $Id: ASTFactory.java,v 1.1 2005/09/17 21:38:42 robilad Exp $
- */
-
-import antlr.collections.AST;
-import antlr.collections.impl.ASTArray;
-
-import java.util.Hashtable;
-import java.lang.reflect.Constructor;
-
-/** AST Support code shared by TreeParser and Parser.
- *  We use delegation to share code (and have only one
- *  bit of code to maintain) rather than subclassing
- *  or superclassing (forces AST support code to be
- *  loaded even when you don't want to do AST stuff).
- *
- *  Typically, setASTNodeType is used to specify the
- *  homogeneous type of node to create, but you can override
- *  create to make heterogeneous nodes etc...
- */
-public class ASTFactory {
-    /** Name of AST class to create during tree construction.
-     *  Null implies that the create method should create
-     *  a default AST type such as CommonAST.  This is for
-        *  homogeneous nodes.
-     */
-    protected String theASTNodeType = null;
-    protected Class theASTNodeTypeClass = null;
-
-       /** How to specify the classname to create for a particular
-        *  token type.  Note that ANTLR allows you to say, for example,
-        *
-           tokens {
-         PLUS<AST=PLUSNode>;
-         ...
-        }
-        *
-        *  and it tracks everything statically.  #[PLUS] will make you
-        *  a PLUSNode w/o use of this table.
-        *
-        *  For tokens that ANTLR cannot track statically like #[i],
-        *  you can use this table to map PLUS (Integer) -> PLUSNode (Class)
-        *  etc... ANTLR sets the class map from the tokens {...} section
-        *  via the ASTFactory(Hashtable) ctor in antlr.Parser.
-        */
-       protected Hashtable tokenTypeToASTClassMap = null;
-
-       public ASTFactory() {
-       }
-
-       /** Create factory with a specific mapping from token type
-        *  to Java AST node type.  Your subclasses of ASTFactory
-        *  can override and reuse the map stuff.
-        */
-       public ASTFactory(Hashtable tokenTypeToClassMap) {
-               setTokenTypeToASTClassMap(tokenTypeToClassMap);
-       }
-
-       /** Specify an "override" for the Java AST object created for a
-        *  specific token.  It is provided as a convenience so
-        *  you can specify node types dynamically.  ANTLR sets
-        *  the token type mapping automatically from the tokens{...}
-        *  section, but you can change that mapping with this method.
-        *  ANTLR does it's best to statically determine the node
-        *  type for generating parsers, but it cannot deal with
-        *  dynamic values like #[LT(1)].  In this case, it relies
-        *  on the mapping.  Beware differences in the tokens{...}
-        *  section and what you set via this method.  Make sure
-        *  they are the same.
-        *
-        *  Set className to null to remove the mapping.
-        *
-        *  @since 2.7.2
-        */
-       public void setTokenTypeASTNodeType(int tokenType, String className)
-               throws IllegalArgumentException
-       {
-               if ( tokenTypeToASTClassMap==null ) {
-                       tokenTypeToASTClassMap = new Hashtable();
-               }
-               if ( className==null ) {
-                       tokenTypeToASTClassMap.remove(new Integer(tokenType));
-                       return;
-               }
-               Class c = null;
-               try {
-                       c = Class.forName(className);
-                       tokenTypeToASTClassMap.put(new Integer(tokenType), c);
-               }
-               catch (Exception e) {
-                       throw new IllegalArgumentException("Invalid class, 
"+className);
-               }
-       }
-
-       /** For a given token type, what is the AST node object type to create
-        *  for it?
-        *  @since 2.7.2
-        */
-       public Class getASTNodeType(int tokenType) {
-               // try node specific class
-               if ( tokenTypeToASTClassMap!=null ) {
-                       Class c = (Class)tokenTypeToASTClassMap.get(new 
Integer(tokenType));
-                       if ( c!=null ) {
-                               return c;
-                       }
-               }
-
-               // try a global specified class
-               if (theASTNodeTypeClass != null) {
-                       return theASTNodeTypeClass;
-               }
-
-               // default to the common type
-               return CommonAST.class;
-       }
-
-    /** Add a child to the current AST */
-    public void addASTChild(ASTPair currentAST, AST child) {
-        if (child != null) {
-            if (currentAST.root == null) {
-                // Make new child the current root
-                currentAST.root = child;
-            }
-            else {
-                if (currentAST.child == null) {
-                    // Add new child to current root
-                    currentAST.root.setFirstChild(child);
-                }
-                else {
-                    currentAST.child.setNextSibling(child);
-                }
-            }
-            // Make new child the current child
-            currentAST.child = child;
-            currentAST.advanceChildToEnd();
-        }
-    }
-
-    /** Create a new empty AST node; if the user did not specify
-     *  an AST node type, then create a default one: CommonAST.
-     */
-    public AST create() {
-               return create(Token.INVALID_TYPE);
-    }
-
-    public AST create(int type) {
-               Class c = getASTNodeType(type);
-               AST t = create(c);
-               if ( t!=null ) {
-                       t.initialize(type, "");
-               }
-               return t;
-       }
-
-       public AST create(int type, String txt) {
-        AST t = create(type);
-               if ( t!=null ) {
-                       t.initialize(type, txt);
-               }
-        return t;
-    }
-
-       /** Create an AST node with the token type and text passed in, but
-        *  with a specific Java object type. Typically called when you
-        *  say @[PLUS,"+",PLUSNode] in an antlr action.
-        *  @since 2.7.2
-        */
-       public AST create(int type, String txt, String className) {
-        AST t = create(className);
-               if ( t!=null ) {
-                       t.initialize(type, txt);
-               }
-        return t;
-    }
-
-    /** Create a new empty AST node; if the user did not specify
-     *  an AST node type, then create a default one: CommonAST.
-     */
-    public AST create(AST tr) {
-        if (tr == null) return null;           // create(null) == null
-        AST t = create(tr.getType());
-               if ( t!=null ) {
-                       t.initialize(tr);
-               }
-        return t;
-    }
-
-       public AST create(Token tok) {
-        AST t = create(tok.getType());
-               if ( t!=null ) {
-                       t.initialize(tok);
-               }
-        return t;
-    }
-
-       /** ANTLR generates reference to this when you reference a token
-        *  that has a specified heterogeneous AST node type.  This is
-        *  also a special case node creation routine for backward
-        *  compatibility.  Before, ANTLR generated "new T(tokenObject)"
-        *  and so I must call the appropriate constructor not T().
-        *
-        * @since 2.7.2
-        */
-       public AST create(Token tok, String className) {
-        AST t = createUsingCtor(tok,className);
-        return t;
-    }
-
-       /**
-        * @since 2.7.2
-        */
-       public AST create(String className) {
-               Class c = null;
-               try {
-                       c = Class.forName(className);
-               }
-               catch (Exception e) {
-                       throw new IllegalArgumentException("Invalid class, 
"+className);
-               }
-               return create(c);
-       }
-
-       /**
-        * @since 2.7.2
-        */
-       protected AST createUsingCtor(Token token, String className) {
-               Class c = null;
-               AST t = null;
-               try {
-                       c = Class.forName(className);
-                       Class[] tokenArgType = new Class[] { antlr.Token.class 
};
-                       try {
-                               Constructor ctor = 
c.getConstructor(tokenArgType);
-                               t = (AST)ctor.newInstance(new Object[]{token}); 
// make a new one
-                       }
-                       catch (NoSuchMethodException e){
-                               // just do the regular thing if you can't find 
the ctor
-                               // Your AST must have default ctor to use this.
-                               t = create(c);
-                               if ( t!=null ) {
-                                       t.initialize(token);
-                               }
-                       }
-               }
-               catch (Exception e) {
-                       throw new IllegalArgumentException("Invalid class or 
can't make instance, "+className);
-               }
-               return t;
-       }
-
-       /**
-        * @since 2.7.2
-        */
-       protected AST create(Class c) {
-               AST t = null;
-               try {
-                       t = (AST)c.newInstance(); // make a new one
-               }
-               catch (Exception e) {
-                       error("Can't create AST Node " + c.getName());
-                       return null;
-               }
-        return t;
-    }
-
-    /** Copy a single node with same Java AST objec type.
-        *  Ignore the tokenType->Class mapping since you know
-        *  the type of the node, t.getClass(), and doing a dup.
-        *
-        *  clone() is not used because we want all AST creation
-        *  to go thru the factory so creation can be
-     *  tracked.  Returns null if t is null.
-     */
-    public AST dup(AST t) {
-               if ( t==null ) {
-                       return null;
-               }
-               AST dup_t = create(t.getClass());
-               dup_t.initialize(t);
-               return dup_t;
-    }
-
-    /** Duplicate tree including siblings of root. */
-    public AST dupList(AST t) {
-        AST result = dupTree(t);            // if t == null, then result==null
-        AST nt = result;
-        while (t != null) {                                            // for 
each sibling of the root
-            t = t.getNextSibling();
-            nt.setNextSibling(dupTree(t));     // dup each subtree, building 
new tree
-            nt = nt.getNextSibling();
-        }
-        return result;
-    }
-
-    /**Duplicate a tree, assuming this is a root node of a tree--
-     * duplicate that node and what's below; ignore siblings of root node.
-     */
-    public AST dupTree(AST t) {
-        AST result = dup(t);           // make copy of root
-        // copy all children of root.
-        if (t != null) {
-            result.setFirstChild(dupList(t.getFirstChild()));
-        }
-        return result;
-    }
-
-    /** Make a tree from a list of nodes.  The first element in the
-     *  array is the root.  If the root is null, then the tree is
-     *  a simple list not a tree.  Handles null children nodes correctly.
-     *  For example, build(a, b, null, c) yields tree (a b c).  build(null,a,b)
-     *  yields tree (nil a b).
-     */
-    public AST make(AST[] nodes) {
-        if (nodes == null || nodes.length == 0) return null;
-        AST root = nodes[0];
-        AST tail = null;
-        if (root != null) {
-            root.setFirstChild(null);  // don't leave any old pointers set
-        }
-        // link in children;
-        for (int i = 1; i < nodes.length; i++) {
-            if (nodes[i] == null) continue;    // ignore null nodes
-            if (root == null) {
-                // Set the root and set it up for a flat list
-                root = tail = nodes[i];
-            }
-            else if (tail == null) {
-                root.setFirstChild(nodes[i]);
-                tail = root.getFirstChild();
-            }
-            else {
-                tail.setNextSibling(nodes[i]);
-                tail = tail.getNextSibling();
-            }
-            // Chase tail to last sibling
-            while (tail.getNextSibling() != null) {
-                tail = tail.getNextSibling();
-            }
-        }
-        return root;
-    }
-
-    /** Make a tree from a list of nodes, where the nodes are contained
-     * in an ASTArray object
-     */
-    public AST make(ASTArray nodes) {
-        return make(nodes.array);
-    }
-
-    /** Make an AST the root of current AST */
-    public void makeASTRoot(ASTPair currentAST, AST root) {
-        if (root != null) {
-            // Add the current root as a child of new root
-            root.addChild(currentAST.root);
-            // The new current child is the last sibling of the old root
-            currentAST.child = currentAST.root;
-            currentAST.advanceChildToEnd();
-            // Set the new root
-            currentAST.root = root;
-        }
-    }
-
-       public void setASTNodeClass(Class c) {
-               if ( c!=null ) {
-                       theASTNodeTypeClass = c;
-                       theASTNodeType = c.getName();
-               }
-       }
-
-    public void setASTNodeClass(String t) {
-        theASTNodeType = t;
-        try {
-            theASTNodeTypeClass = Class.forName(t); // get class def
-        }
-        catch (Exception e) {
-            // either class not found,
-            // class is interface/abstract, or
-            // class or initializer is not accessible.
-            error("Can't find/access AST Node type" + t);
-        }
-    }
-
-    /** Specify the type of node to create during tree building.
-     *         @deprecated since 2.7.1
-     */
-    public void setASTNodeType(String t) {
-        setASTNodeClass(t);
-    }
-
-       public Hashtable getTokenTypeToASTClassMap() {
-               return tokenTypeToASTClassMap;
-       }
-
-       public void setTokenTypeToASTClassMap(Hashtable tokenTypeToClassMap) {
-               this.tokenTypeToASTClassMap = tokenTypeToClassMap;
-       }
-
-    /** To change where error messages go, can subclass/override this method
-     *  and then setASTFactory in Parser and TreeParser.  This method removes
-     *  a prior dependency on class antlr.Tool.
-     */
-    public void error(String e) {
-        System.err.println(e);
-    }
-}
+package antlr;
+
+/* ANTLR Translator Generator
+ * Project led by Terence Parr at http://www.cs.usfca.edu
+ * Software rights: http://www.antlr.org/license.html
+ *
+ * $Id: ASTFactory.java,v 1.2 2005/12/24 21:50:48 robilad Exp $
+ */
+
+import java.lang.reflect.Constructor;
+import java.util.Hashtable;
+
+import antlr.collections.AST;
+import antlr.collections.impl.ASTArray;
+
+/** AST Support code shared by TreeParser and Parser.
+ *  We use delegation to share code (and have only one
+ *  bit of code to maintain) rather than subclassing
+ *  or superclassing (forces AST support code to be
+ *  loaded even when you don't want to do AST stuff).
+ *
+ *  Typically, setASTNodeType is used to specify the
+ *  homogeneous type of node to create, but you can override
+ *  create to make heterogeneous nodes etc...
+ */
+public class ASTFactory {
+    /** Name of AST class to create during tree construction.
+     *  Null implies that the create method should create
+     *  a default AST type such as CommonAST.  This is for
+        *  homogeneous nodes.
+     */
+    protected String theASTNodeType = null;
+    protected Class theASTNodeTypeClass = null;
+
+       /** How to specify the classname to create for a particular
+        *  token type.  Note that ANTLR allows you to say, for example,
+        *
+           tokens {
+         PLUS<AST=PLUSNode>;
+         ...
+        }
+        *
+        *  and it tracks everything statically.  #[PLUS] will make you
+        *  a PLUSNode w/o use of this table.
+        *
+        *  For tokens that ANTLR cannot track statically like #[i],
+        *  you can use this table to map PLUS (Integer) -> PLUSNode (Class)
+        *  etc... ANTLR sets the class map from the tokens {...} section
+        *  via the ASTFactory(Hashtable) ctor in antlr.Parser.
+        */
+       protected Hashtable tokenTypeToASTClassMap = null;
+
+       public ASTFactory() {
+       }
+
+       /** Create factory with a specific mapping from token type
+        *  to Java AST node type.  Your subclasses of ASTFactory
+        *  can override and reuse the map stuff.
+        */
+       public ASTFactory(Hashtable tokenTypeToClassMap) {
+               setTokenTypeToASTClassMap(tokenTypeToClassMap);
+       }
+
+       /** Specify an "override" for the Java AST object created for a
+        *  specific token.  It is provided as a convenience so
+        *  you can specify node types dynamically.  ANTLR sets
+        *  the token type mapping automatically from the tokens{...}
+        *  section, but you can change that mapping with this method.
+        *  ANTLR does it's best to statically determine the node
+        *  type for generating parsers, but it cannot deal with
+        *  dynamic values like #[LT(1)].  In this case, it relies
+        *  on the mapping.  Beware differences in the tokens{...}
+        *  section and what you set via this method.  Make sure
+        *  they are the same.
+        *
+        *  Set className to null to remove the mapping.
+        *
+        *  @since 2.7.2
+        */
+       public void setTokenTypeASTNodeType(int tokenType, String className)
+               throws IllegalArgumentException
+       {
+               if ( tokenTypeToASTClassMap==null ) {
+                       tokenTypeToASTClassMap = new Hashtable();
+               }
+               if ( className==null ) {
+                       tokenTypeToASTClassMap.remove(new Integer(tokenType));
+                       return;
+               }
+               Class c = null;
+               try {
+                       c = Utils.loadClass(className);
+                       tokenTypeToASTClassMap.put(new Integer(tokenType), c);
+               }
+               catch (Exception e) {
+                       throw new IllegalArgumentException("Invalid class, 
"+className);
+               }
+       }
+
+       /** For a given token type, what is the AST node object type to create
+        *  for it?
+        *  @since 2.7.2
+        */
+       public Class getASTNodeType(int tokenType) {
+               // try node specific class
+               if ( tokenTypeToASTClassMap!=null ) {
+                       Class c = (Class)tokenTypeToASTClassMap.get(new 
Integer(tokenType));
+                       if ( c!=null ) {
+                               return c;
+                       }
+               }
+
+               // try a global specified class
+               if (theASTNodeTypeClass != null) {
+                       return theASTNodeTypeClass;
+               }
+
+               // default to the common type
+               return CommonAST.class;
+       }
+
+    /** Add a child to the current AST */
+    public void addASTChild(ASTPair currentAST, AST child) {
+        if (child != null) {
+            if (currentAST.root == null) {
+                // Make new child the current root
+                currentAST.root = child;
+            }
+            else {
+                if (currentAST.child == null) {
+                    // Add new child to current root
+                    currentAST.root.setFirstChild(child);
+                }
+                else {
+                    currentAST.child.setNextSibling(child);
+                }
+            }
+            // Make new child the current child
+            currentAST.child = child;
+            currentAST.advanceChildToEnd();
+        }
+    }
+
+    /** Create a new empty AST node; if the user did not specify
+     *  an AST node type, then create a default one: CommonAST.
+     */
+    public AST create() {
+               return create(Token.INVALID_TYPE);
+    }
+
+    public AST create(int type) {
+               Class c = getASTNodeType(type);
+               AST t = create(c);
+               if ( t!=null ) {
+                       t.initialize(type, "");
+               }
+               return t;
+       }
+
+       public AST create(int type, String txt) {
+        AST t = create(type);
+               if ( t!=null ) {
+                       t.initialize(type, txt);
+               }
+        return t;
+    }
+
+       /** Create an AST node with the token type and text passed in, but
+        *  with a specific Java object type. Typically called when you
+        *  say @[PLUS,"+",PLUSNode] in an antlr action.
+        *  @since 2.7.2
+        */
+       public AST create(int type, String txt, String className) {
+        AST t = create(className);
+               if ( t!=null ) {
+                       t.initialize(type, txt);
+               }
+        return t;
+    }
+
+    /** Create a new empty AST node; if the user did not specify
+     *  an AST node type, then create a default one: CommonAST.
+     */
+    public AST create(AST tr) {
+        if (tr == null) return null;           // create(null) == null
+        AST t = create(tr.getType());
+               if ( t!=null ) {
+                       t.initialize(tr);
+               }
+        return t;
+    }
+
+       public AST create(Token tok) {
+        AST t = create(tok.getType());
+               if ( t!=null ) {
+                       t.initialize(tok);
+               }
+        return t;
+    }
+
+       /** ANTLR generates reference to this when you reference a token
+        *  that has a specified heterogeneous AST node type.  This is
+        *  also a special case node creation routine for backward
+        *  compatibility.  Before, ANTLR generated "new T(tokenObject)"
+        *  and so I must call the appropriate constructor not T().
+        *
+        * @since 2.7.2
+        */
+       public AST create(Token tok, String className) {
+        AST t = createUsingCtor(tok,className);
+        return t;
+    }
+
+       /**
+        * @since 2.7.2
+        */
+       public AST create(String className) {
+               Class c = null;
+               try {
+                       c = Utils.loadClass(className);
+               }
+               catch (Exception e) {
+                       throw new IllegalArgumentException("Invalid class, 
"+className);
+               }
+               return create(c);
+       }
+
+       /**
+        * @since 2.7.2
+        */
+       protected AST createUsingCtor(Token token, String className) {
+               Class c = null;
+               AST t = null;
+               try {
+                       c = Utils.loadClass(className);
+                       Class[] tokenArgType = new Class[] { antlr.Token.class 
};
+                       try {
+                               Constructor ctor = 
c.getConstructor(tokenArgType);
+                               t = (AST)ctor.newInstance(new Object[]{token}); 
// make a new one
+                       }
+                       catch (NoSuchMethodException e){
+                               // just do the regular thing if you can't find 
the ctor
+                               // Your AST must have default ctor to use this.
+                               t = create(c);
+                               if ( t!=null ) {
+                                       t.initialize(token);
+                               }
+                       }
+               }
+               catch (Exception e) {
+                       throw new IllegalArgumentException("Invalid class or 
can't make instance, "+className);
+               }
+               return t;
+       }
+
+       /**
+        * @since 2.7.2
+        */
+       protected AST create(Class c) {
+               AST t = null;
+               try {
+                       t = (AST)c.newInstance(); // make a new one
+               }
+               catch (Exception e) {
+                       error("Can't create AST Node " + c.getName());
+                       return null;
+               }
+        return t;
+    }
+
+    /** Copy a single node with same Java AST objec type.
+        *  Ignore the tokenType->Class mapping since you know
+        *  the type of the node, t.getClass(), and doing a dup.
+        *
+        *  clone() is not used because we want all AST creation
+        *  to go thru the factory so creation can be
+     *  tracked.  Returns null if t is null.
+     */
+    public AST dup(AST t) {
+               if ( t==null ) {
+                       return null;
+               }
+               AST dup_t = create(t.getClass());
+               dup_t.initialize(t);
+               return dup_t;
+    }
+
+    /** Duplicate tree including siblings of root. */
+    public AST dupList(AST t) {
+        AST result = dupTree(t);            // if t == null, then result==null
+        AST nt = result;
+        while (t != null) {                                            // for 
each sibling of the root
+            t = t.getNextSibling();
+            nt.setNextSibling(dupTree(t));     // dup each subtree, building 
new tree
+            nt = nt.getNextSibling();
+        }
+        return result;
+    }
+
+    /**Duplicate a tree, assuming this is a root node of a tree--
+     * duplicate that node and what's below; ignore siblings of root node.
+     */
+    public AST dupTree(AST t) {
+        AST result = dup(t);           // make copy of root
+        // copy all children of root.
+        if (t != null) {
+            result.setFirstChild(dupList(t.getFirstChild()));
+        }
+        return result;
+    }
+
+    /** Make a tree from a list of nodes.  The first element in the
+     *  array is the root.  If the root is null, then the tree is
+     *  a simple list not a tree.  Handles null children nodes correctly.
+     *  For example, build(a, b, null, c) yields tree (a b c).  build(null,a,b)
+     *  yields tree (nil a b).
+     */
+    public AST make(AST[] nodes) {
+        if (nodes == null || nodes.length == 0) return null;
+        AST root = nodes[0];
+        AST tail = null;
+        if (root != null) {
+            root.setFirstChild(null);  // don't leave any old pointers set
+        }
+        // link in children;
+        for (int i = 1; i < nodes.length; i++) {
+            if (nodes[i] == null) continue;    // ignore null nodes
+            if (root == null) {
+                // Set the root and set it up for a flat list
+                root = tail = nodes[i];
+            }
+            else if (tail == null) {
+                root.setFirstChild(nodes[i]);
+                tail = root.getFirstChild();
+            }
+            else {
+                tail.setNextSibling(nodes[i]);
+                tail = tail.getNextSibling();
+            }
+            // Chase tail to last sibling
+            while (tail.getNextSibling() != null) {
+                tail = tail.getNextSibling();
+            }
+        }
+        return root;
+    }
+
+    /** Make a tree from a list of nodes, where the nodes are contained
+     * in an ASTArray object
+     */
+    public AST make(ASTArray nodes) {
+        return make(nodes.array);
+    }
+
+    /** Make an AST the root of current AST */
+    public void makeASTRoot(ASTPair currentAST, AST root) {
+        if (root != null) {
+            // Add the current root as a child of new root
+            root.addChild(currentAST.root);
+            // The new current child is the last sibling of the old root
+            currentAST.child = currentAST.root;
+            currentAST.advanceChildToEnd();
+            // Set the new root
+            currentAST.root = root;
+        }
+    }
+
+       public void setASTNodeClass(Class c) {
+               if ( c!=null ) {
+                       theASTNodeTypeClass = c;
+                       theASTNodeType = c.getName();
+               }
+       }
+
+    public void setASTNodeClass(String t) {
+        theASTNodeType = t;
+        try {
+            theASTNodeTypeClass = Utils.loadClass(t); // get class def
+        }
+        catch (Exception e) {
+            // either class not found,
+            // class is interface/abstract, or
+            // class or initializer is not accessible.
+            error("Can't find/access AST Node type" + t);
+        }
+    }
+
+    /** Specify the type of node to create during tree building.
+     *         @deprecated since 2.7.1
+     */
+    public void setASTNodeType(String t) {
+        setASTNodeClass(t);
+    }
+
+       public Hashtable getTokenTypeToASTClassMap() {
+               return tokenTypeToASTClassMap;
+       }

*** Patch too long, truncated ***

_______________________________________________
kaffe mailing list
[email protected]
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe

Reply via email to