/* Generated By:JavaCC: Do not edit this line. JavaCCParser.java */
package recoder.parser;
import java.io.*;
import java.util.*;
import recoder.*;
import recoder.list.generic.*;
import recoder.java.*;
import recoder.java.declaration.*;
import recoder.java.declaration.modifier.*;
import recoder.java.expression.*;
import recoder.java.expression.literal.*;
import recoder.java.expression.operator.*;
import recoder.java.reference.*;
import recoder.java.statement.*;
import recoder.io.*;
import recoder.abstraction.TypeArgument.WildcardMode;
/**
JavaCC AST generation specification based on the original Java1.1
grammar that comes with javacc, and includes the modification of D. Williams
to accept the Java 1.2 strictfp modifier.
Several patches have been added to allow semicola after member declarations.
@author RN
@author AL
@author Tobias Gutzmann
*/
public class JavaCCParser implements JavaCCParserConstants {
public final static void initialize(Reader r) {
current = null;
comments.clear();
ReInit(r);
JavaCharStream.setTabSize(4);
}
/** the JavaProgramFactory instance that is used to create
parse results
*/
private static JavaProgramFactory factory
= JavaProgramFactory.getInstance();
static boolean superAllowed = true;
private static boolean isSuperAllowed() { return superAllowed; }
private static void setAllowSuper(boolean b) { superAllowed = b; }
static boolean jdk1_4 = false;
static boolean jdk1_5 = false;
public static boolean isAwareOfAssert() {
return jdk1_4;
}
public static void setAwareOfAssert(boolean yes) {
jdk1_4 = yes;
if (yes == false) jdk1_5 = false;
}
public static boolean isJava5() {
return jdk1_5;
}
public static void setJava5(boolean yes) {
jdk1_5 = yes;
if (yes)
jdk1_4 = true;
}
public static void setTabSize(int tabSize) {
JavaCharStream.setTabSize(tabSize);
}
public static int getTabSize() {
return JavaCharStream.getTabSize(0); // whatever...
}
/** temporary valid variable that is used to return an additional
argument from parser method VariableDeclaratorId, since such an
id may have a dimension
*/
private static int tmpDimension;
/** current token, follows the next links when necessary */
private static Token current;
/** all comments in a global list. */
private static List<Comment> comments = new ArrayList<Comment>();
/** reuseable position object. */
private static SourceElement.Position position = new SourceElement.Position(0, 0);
private static void copyPrefixInfo(SourceElement oldResult,
SourceElement newResult) {
newResult.setRelativePosition(oldResult.getRelativePosition());
newResult.setStartPosition(oldResult.getStartPosition());
newResult.setEndPosition(oldResult.getEndPosition());
}
private static void shiftToken() {
if (current != token) {
if (current != null) {
while (current.next != token) {
current = current.next;
}
}
Token prev;
if (token.specialToken != null) {
prev = token.specialToken;
} else {
prev = current;
}
if (prev != null) {
int col = token.beginColumn - 1;
int lf = token.beginLine - prev.endLine;
if (lf <= 0) {
col -= prev.endColumn; // - 1;
if (col < 0) {
col = 0;
}
}
position.setPosition(lf, col);
}
current = token;
}
}
/**
Sets indentation information.
*/
private static void setPrefixInfo(SourceElement constrResult) {
position.setPosition(0, 0);
shiftToken();
constrResult.setRelativePosition(position);
position.setPosition(current.beginLine, current.beginColumn);
constrResult.setStartPosition(position);
}
private static void setPostfixInfo(SourceElement constrResult) {
shiftToken();
position.setPosition(current.endLine, current.endColumn);
constrResult.setEndPosition(position);
}
private static void addComment(Comment c, Token tok) {
Token prev = tok.specialToken;
if (prev == null) {
prev = token;
// in case we are inside a lookahead we skip to the last known
// non-special token
while (prev.next != null) {
prev = prev.next;
}
}
position.setPosition(0, 0);
int internalIndentation = 0;
int internalLinefeeds = 0;
if (prev.image != null) {
int col = tok.beginColumn - 1;
int lf = tok.beginLine - prev.endLine;
if (lf <= 0) {
col -= prev.endColumn; // - 1;
}
position.setPosition(lf, col);
}
c.setRelativePosition(position);
position.setPosition(tok.endLine, tok.endColumn);
c.setEndPosition(position);
position.setPosition(tok.beginLine, tok.beginColumn);
c.setStartPosition(position);
if (!(c instanceof DocComment)) {
boolean hasEmptyLine = c.getRelativePosition().getLine() > 1;
c.setPrefixed(hasEmptyLine);
if (tok.specialToken != null && !hasEmptyLine) {
c.setPrefixed(comments.get(comments.size() - 1).isPrefixed());
}
}
comments.add(c);
}
static void addSingleLineComment(Token tok) {
addComment(factory.createSingleLineComment(tok.image.trim()), tok);
}
static void addMultiLineComment(Token tok) {
addComment(factory.createComment(tok.image), tok);
}
static void addDocComment(Token tok) {
addComment(factory.createDocComment(tok.image), tok);
}
public static List<Comment> getComments() {
return comments;
}
/** inner class that is only used to return results from
primary suffix syntax rule
@author RN
*/
static class PrimarySuffixReturnValue {
// the following constants represent the various sub rules
/** indicates that the result is currently undefined */
static final int UNDEFINED = -1;
/** production was <pre>"." "this"</pre> */
static final int THIS = 0;
/** production was <pre>"." AllocationExpression</pre> */
static final int ALLOCATION_EXPR = 1;
/** production was <pre>"[" Expression "]"</pre> */
static final int INDEX_EXPR = 2;
/** production was <pre>"." <IDENTIFIER></pre> */
static final int IDENTIFIER = 3;
/** production was <pre>Arguments</pre> */
static final int ARGUMENTS = 4;
/** production was <pre>super</pre> */
static final int SUPER = 5;
/** indicates the type of the result */
int type = UNDEFINED;
/** valid iff <tt>type</tt> is <tt>ALLOCATION_EXPR</tt> or
<tt>INDEX_EXPR</tt> */
Expression expr = null;
/** valid iff <tt>type</tt> is <tt>IDENTIFIER</tt> */
Identifier id = null;
/** valid iff <tt>type</tt> is <tt>ARGUMENTS</tt> */
ASTList<Expression> args = null;
/** valid iff <tt>type</tt> is <tt>IDENTIFIER</tt> and
* it is an explicit generic method invocati
评论1
最新资源