User: rinkrank
Date: 02/10/23 18:56:22
Modified: javacc Tag: XDOCLET_2_0 Java1.2-b.jjt
Log:
Tried to reuse the parser (for optimisation), before I discovered that they need to
be pooled.
Revision Changes Path
No revision
No revision
1.32.2.3 +64 -10 xjavadoc/javacc/Java1.2-b.jjt
Index: Java1.2-b.jjt
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/javacc/Java1.2-b.jjt,v
retrieving revision 1.32.2.2
retrieving revision 1.32.2.3
diff -u -w -r1.32.2.2 -r1.32.2.3
--- Java1.2-b.jjt 18 Oct 2002 14:50:17 -0000 1.32.2.2
+++ Java1.2-b.jjt 24 Oct 2002 01:56:22 -0000 1.32.2.3
@@ -45,7 +45,7 @@
JAVA_UNICODE_ESCAPE=false;
UNICODE_INPUT=false;
STATIC=false;
- MULTI=true;
+ MULTI=false;
VISITOR=false;
NODE_USES_PARSER=true;
CACHE_TOKENS=true;
@@ -57,12 +57,14 @@
import java.lang.reflect.Modifier;
import java.util.*;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
public class @parser-class@ implements JavaParser
{
private String _packageName = "";
private SourceClass _outerClass;
- private Stack sourceClassStack = new Stack();
+ private Stack _sourceClassStack = new Stack();
private static final void setToken(AbstractProgramElement element, Token token) {
element.setToken( token );
@@ -82,7 +84,7 @@
public String name;
public int dimension;
}
- private Parameter _parameter = new Parameter();
+ private Parameter _parameter;
// Reference to the first token in a Name() production.
private Token _nameToken;
@@ -95,12 +97,12 @@
// push the outer class. Otherwise, instantiate a new (inner) class
// and push that instead.
SourceClass clazz = null;
- if( sourceClassStack.isEmpty() ) {
+ if( _sourceClassStack.isEmpty() ) {
clazz = _outerClass;
} else {
clazz = new SourceClass(currentClass());
}
- sourceClassStack.push(clazz);
+ _sourceClassStack.push(clazz);
return clazz;
}
@@ -108,7 +110,7 @@
* Should be called after UnmodifiedClassDeclaration or
UnmodifiedInterfaceDeclaration
*/
private void popAndAddInner() {
- SourceClass clazz = (SourceClass) sourceClassStack.pop();
+ SourceClass clazz = (SourceClass) _sourceClassStack.pop();
if( clazz != _outerClass ) {
// Add the class as an inner class
currentClass().addInnerClass(clazz);
@@ -117,9 +119,62 @@
}
private SourceClass currentClass() {
- return (SourceClass)sourceClassStack.peek();
+ return (SourceClass)_sourceClassStack.peek();
}
+ /**
+ * This constructor was added to allow the re-use of parsers.
+ * The normal constructor takes a single argument which
+ * an InputStream. This simply creates a re-usable parser
+ * object, we satisfy the requirement of an InputStream
+ * by using a newline character as an input stream.
+ */
+ public @parser-class@()
+ {
+ this(new ByteArrayInputStream("\n".getBytes()));
+ }
+
+ /**
+ * This was also added to allow parsers to be
+ * re-usable. Normal JavaCC use entails passing an
+ * input stream to the constructor and the parsing
+ * process is carried out once. We want to be able
+ * to re-use parsers: we do this by adding this
+ * method and re-initializing the lexer with
+ * the new stream that we want parsed.
+ */
+ public void populate(SourceClass sourceClass)
+ throws ParseException
+ {
+ _outerClass = sourceClass;
+
+ // Reset state
+ _sourceClassStack.clear();
+ _packageName = "";
+ _parameter = new Parameter();
+ _nameToken = null;
+ clearNameBuffer();
+
+ try
+ {
+
+ // now reinit the Parser with this CharStream
+ //
+ ReInit(sourceClass.getReader());
+
+ // Start the parsing.
+ CompilationUnit( sourceClass );
+ }
+ catch (ParseException pe)
+ {
+ throw new ParseException (pe.currentToken,
+ pe.expectedTokenSequences, pe.tokenImage);
+ }
+ catch (TokenMgrError tme)
+ {
+ throw new ParseException("Lexical error: " + tme.toString());
+ }
+ }
}
PARSER_END(@parser-class@)
@@ -394,7 +449,6 @@
void CompilationUnit( SourceClass sourceClass ) :
{
- _outerClass = sourceClass;
}
{
[ PackageDeclaration() ]
@@ -413,8 +467,8 @@
}
*/
- if( sourceClassStack.size() != 0 ) {
- throw new IllegalStateException("There should be no more classes on the
stack:" + sourceClassStack.size());
+ if( _sourceClassStack.size() != 0 ) {
+ throw new IllegalStateException("There should be no more classes on the
stack:" + _sourceClassStack.size());
}
}
}
-------------------------------------------------------
This sf.net email is sponsored by: Influence the future
of Java(TM) technology. Join the Java Community
Process(SM) (JCP(SM)) program now.
http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0002en
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel