use of org.antlr.runtime.tree.CommonTree in project freud by LMAX-Exchange.
the class JavaParser method genericTypeArgumentListSimplified.
// $ANTLR start "genericTypeArgumentListSimplified"
// /home/langera/dev/freud/trunk/src/grammar/Java.g:711:1: genericTypeArgumentListSimplified : LESS_THAN genericTypeArgumentSimplified ( COMMA genericTypeArgumentSimplified )* genericTypeListClosing -> ^( GENERIC_TYPE_ARG_LIST[$LESS_THAN, \"GENERIC_TYPE_ARG_LIST\"] ( genericTypeArgumentSimplified )+ ) ;
public final JavaParser.genericTypeArgumentListSimplified_return genericTypeArgumentListSimplified() throws RecognitionException {
JavaParser.genericTypeArgumentListSimplified_return retval = new JavaParser.genericTypeArgumentListSimplified_return();
retval.start = input.LT(1);
int genericTypeArgumentListSimplified_StartIndex = input.index();
CommonTree root_0 = null;
Token LESS_THAN195 = null;
Token COMMA197 = null;
JavaParser.genericTypeArgumentSimplified_return genericTypeArgumentSimplified196 = null;
JavaParser.genericTypeArgumentSimplified_return genericTypeArgumentSimplified198 = null;
JavaParser.genericTypeListClosing_return genericTypeListClosing199 = null;
CommonTree LESS_THAN195_tree = null;
CommonTree COMMA197_tree = null;
RewriteRuleTokenStream stream_COMMA = new RewriteRuleTokenStream(adaptor, "token COMMA");
RewriteRuleTokenStream stream_LESS_THAN = new RewriteRuleTokenStream(adaptor, "token LESS_THAN");
RewriteRuleSubtreeStream stream_genericTypeArgumentSimplified = new RewriteRuleSubtreeStream(adaptor, "rule genericTypeArgumentSimplified");
RewriteRuleSubtreeStream stream_genericTypeListClosing = new RewriteRuleSubtreeStream(adaptor, "rule genericTypeListClosing");
try {
if (state.backtracking > 0 && alreadyParsedRule(input, 53)) {
return retval;
}
// /home/langera/dev/freud/trunk/src/grammar/Java.g:712:5: ( LESS_THAN genericTypeArgumentSimplified ( COMMA genericTypeArgumentSimplified )* genericTypeListClosing -> ^( GENERIC_TYPE_ARG_LIST[$LESS_THAN, \"GENERIC_TYPE_ARG_LIST\"] ( genericTypeArgumentSimplified )+ ) )
// /home/langera/dev/freud/trunk/src/grammar/Java.g:712:9: LESS_THAN genericTypeArgumentSimplified ( COMMA genericTypeArgumentSimplified )* genericTypeListClosing
{
LESS_THAN195 = (Token) match(input, LESS_THAN, FOLLOW_LESS_THAN_in_genericTypeArgumentListSimplified7351);
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_LESS_THAN.add(LESS_THAN195);
}
pushFollow(FOLLOW_genericTypeArgumentSimplified_in_genericTypeArgumentListSimplified7353);
genericTypeArgumentSimplified196 = genericTypeArgumentSimplified();
state._fsp--;
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_genericTypeArgumentSimplified.add(genericTypeArgumentSimplified196.getTree());
}
// /home/langera/dev/freud/trunk/src/grammar/Java.g:712:49: ( COMMA genericTypeArgumentSimplified )*
loop69: do {
int alt69 = 2;
int LA69_0 = input.LA(1);
if ((LA69_0 == COMMA)) {
alt69 = 1;
}
switch(alt69) {
case 1:
// /home/langera/dev/freud/trunk/src/grammar/Java.g:712:50: COMMA genericTypeArgumentSimplified
{
COMMA197 = (Token) match(input, COMMA, FOLLOW_COMMA_in_genericTypeArgumentListSimplified7356);
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_COMMA.add(COMMA197);
}
pushFollow(FOLLOW_genericTypeArgumentSimplified_in_genericTypeArgumentListSimplified7358);
genericTypeArgumentSimplified198 = genericTypeArgumentSimplified();
state._fsp--;
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_genericTypeArgumentSimplified.add(genericTypeArgumentSimplified198.getTree());
}
}
break;
default:
break loop69;
}
} while (true);
pushFollow(FOLLOW_genericTypeListClosing_in_genericTypeArgumentListSimplified7362);
genericTypeListClosing199 = genericTypeListClosing();
state._fsp--;
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_genericTypeListClosing.add(genericTypeListClosing199.getTree());
}
// wildcard labels:
if (state.backtracking == 0) {
retval.tree = root_0;
RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.tree : null);
root_0 = (CommonTree) adaptor.nil();
// 713:9: -> ^( GENERIC_TYPE_ARG_LIST[$LESS_THAN, \"GENERIC_TYPE_ARG_LIST\"] ( genericTypeArgumentSimplified )+ )
{
// /home/langera/dev/freud/trunk/src/grammar/Java.g:713:13: ^( GENERIC_TYPE_ARG_LIST[$LESS_THAN, \"GENERIC_TYPE_ARG_LIST\"] ( genericTypeArgumentSimplified )+ )
{
CommonTree root_1 = (CommonTree) adaptor.nil();
root_1 = (CommonTree) adaptor.becomeRoot((CommonTree) adaptor.create(GENERIC_TYPE_ARG_LIST, LESS_THAN195, "GENERIC_TYPE_ARG_LIST"), root_1);
if (!(stream_genericTypeArgumentSimplified.hasNext())) {
throw new RewriteEarlyExitException();
}
while (stream_genericTypeArgumentSimplified.hasNext()) {
adaptor.addChild(root_1, stream_genericTypeArgumentSimplified.nextTree());
}
stream_genericTypeArgumentSimplified.reset();
adaptor.addChild(root_0, root_1);
}
}
retval.tree = root_0;
}
}
retval.stop = input.LT(-1);
if (state.backtracking == 0) {
retval.tree = (CommonTree) adaptor.rulePostProcessing(root_0);
adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
}
} catch (RecognitionException re) {
reportError(re);
recover(input, re);
retval.tree = (CommonTree) adaptor.errorNode(input, retval.start, input.LT(-1), re);
} finally {
if (state.backtracking > 0) {
memoize(input, 53, genericTypeArgumentListSimplified_StartIndex);
}
}
return retval;
}
use of org.antlr.runtime.tree.CommonTree in project freud by LMAX-Exchange.
the class JavaParser method arguments.
// $ANTLR start "arguments"
// /home/langera/dev/freud/trunk/src/grammar/Java.g:1151:1: arguments : LPAREN ( expressionList )? RPAREN -> ^( ARGUMENT_LIST[$LPAREN, \"ARGUMENT_LIST\"] ( expressionList )? ) ;
public final JavaParser.arguments_return arguments() throws RecognitionException {
JavaParser.arguments_return retval = new JavaParser.arguments_return();
retval.start = input.LT(1);
int arguments_StartIndex = input.index();
CommonTree root_0 = null;
Token LPAREN531 = null;
Token RPAREN533 = null;
JavaParser.expressionList_return expressionList532 = null;
CommonTree LPAREN531_tree = null;
CommonTree RPAREN533_tree = null;
RewriteRuleTokenStream stream_RPAREN = new RewriteRuleTokenStream(adaptor, "token RPAREN");
RewriteRuleTokenStream stream_LPAREN = new RewriteRuleTokenStream(adaptor, "token LPAREN");
RewriteRuleSubtreeStream stream_expressionList = new RewriteRuleSubtreeStream(adaptor, "rule expressionList");
try {
if (state.backtracking > 0 && alreadyParsedRule(input, 110)) {
return retval;
}
// /home/langera/dev/freud/trunk/src/grammar/Java.g:1152:5: ( LPAREN ( expressionList )? RPAREN -> ^( ARGUMENT_LIST[$LPAREN, \"ARGUMENT_LIST\"] ( expressionList )? ) )
// /home/langera/dev/freud/trunk/src/grammar/Java.g:1152:9: LPAREN ( expressionList )? RPAREN
{
LPAREN531 = (Token) match(input, LPAREN, FOLLOW_LPAREN_in_arguments14389);
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_LPAREN.add(LPAREN531);
}
// /home/langera/dev/freud/trunk/src/grammar/Java.g:1152:16: ( expressionList )?
int alt154 = 2;
int LA154_0 = input.LA(1);
if ((LA154_0 == DEC || LA154_0 == INC || LA154_0 == LESS_THAN || LA154_0 == LOGICAL_NOT || (LA154_0 >= LPAREN && LA154_0 <= MINUS) || LA154_0 == NOT || LA154_0 == PLUS || LA154_0 == BOOLEAN || LA154_0 == BYTE || LA154_0 == CHAR || LA154_0 == DOUBLE || LA154_0 == FALSE || LA154_0 == FLOAT || (LA154_0 >= INT && LA154_0 <= LONG) || (LA154_0 >= NEW && LA154_0 <= NULL) || LA154_0 == SHORT || LA154_0 == SUPER || LA154_0 == THIS || LA154_0 == TRUE || LA154_0 == VOID || (LA154_0 >= IDENT && LA154_0 <= STRING_LITERAL))) {
alt154 = 1;
}
switch(alt154) {
case 1:
// /home/langera/dev/freud/trunk/src/grammar/Java.g:0:0: expressionList
{
pushFollow(FOLLOW_expressionList_in_arguments14391);
expressionList532 = expressionList();
state._fsp--;
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_expressionList.add(expressionList532.getTree());
}
}
break;
}
RPAREN533 = (Token) match(input, RPAREN, FOLLOW_RPAREN_in_arguments14394);
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_RPAREN.add(RPAREN533);
}
// wildcard labels:
if (state.backtracking == 0) {
retval.tree = root_0;
RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.tree : null);
root_0 = (CommonTree) adaptor.nil();
// 1153:9: -> ^( ARGUMENT_LIST[$LPAREN, \"ARGUMENT_LIST\"] ( expressionList )? )
{
// /home/langera/dev/freud/trunk/src/grammar/Java.g:1153:13: ^( ARGUMENT_LIST[$LPAREN, \"ARGUMENT_LIST\"] ( expressionList )? )
{
CommonTree root_1 = (CommonTree) adaptor.nil();
root_1 = (CommonTree) adaptor.becomeRoot((CommonTree) adaptor.create(ARGUMENT_LIST, LPAREN531, "ARGUMENT_LIST"), root_1);
// /home/langera/dev/freud/trunk/src/grammar/Java.g:1153:55: ( expressionList )?
if (stream_expressionList.hasNext()) {
adaptor.addChild(root_1, stream_expressionList.nextTree());
}
stream_expressionList.reset();
adaptor.addChild(root_0, root_1);
}
}
retval.tree = root_0;
}
}
retval.stop = input.LT(-1);
if (state.backtracking == 0) {
retval.tree = (CommonTree) adaptor.rulePostProcessing(root_0);
adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
}
} catch (RecognitionException re) {
reportError(re);
recover(input, re);
retval.tree = (CommonTree) adaptor.errorNode(input, retval.start, input.LT(-1), re);
} finally {
if (state.backtracking > 0) {
memoize(input, 110, arguments_StartIndex);
}
}
return retval;
}
use of org.antlr.runtime.tree.CommonTree in project freud by LMAX-Exchange.
the class JavaParser method switchBlockLabels.
// $ANTLR start "switchBlockLabels"
// /home/langera/dev/freud/trunk/src/grammar/Java.g:885:1: switchBlockLabels : preCases= switchCaseLabels ( switchDefaultLabel )? postCases= switchCaseLabels -> ^( SWITCH_BLOCK_LABEL_LIST ( $preCases)? ( switchDefaultLabel )? ( $postCases)? ) ;
public final JavaParser.switchBlockLabels_return switchBlockLabels() throws RecognitionException {
JavaParser.switchBlockLabels_return retval = new JavaParser.switchBlockLabels_return();
retval.start = input.LT(1);
int switchBlockLabels_StartIndex = input.index();
CommonTree root_0 = null;
JavaParser.switchCaseLabels_return preCases = null;
JavaParser.switchCaseLabels_return postCases = null;
JavaParser.switchDefaultLabel_return switchDefaultLabel346 = null;
RewriteRuleSubtreeStream stream_switchDefaultLabel = new RewriteRuleSubtreeStream(adaptor, "rule switchDefaultLabel");
RewriteRuleSubtreeStream stream_switchCaseLabels = new RewriteRuleSubtreeStream(adaptor, "rule switchCaseLabels");
try {
if (state.backtracking > 0 && alreadyParsedRule(input, 79)) {
return retval;
}
// /home/langera/dev/freud/trunk/src/grammar/Java.g:886:5: (preCases= switchCaseLabels ( switchDefaultLabel )? postCases= switchCaseLabels -> ^( SWITCH_BLOCK_LABEL_LIST ( $preCases)? ( switchDefaultLabel )? ( $postCases)? ) )
// /home/langera/dev/freud/trunk/src/grammar/Java.g:886:9: preCases= switchCaseLabels ( switchDefaultLabel )? postCases= switchCaseLabels
{
pushFollow(FOLLOW_switchCaseLabels_in_switchBlockLabels9838);
preCases = switchCaseLabels();
state._fsp--;
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_switchCaseLabels.add(preCases.getTree());
}
// /home/langera/dev/freud/trunk/src/grammar/Java.g:886:35: ( switchDefaultLabel )?
int alt100 = 2;
int LA100_0 = input.LA(1);
if ((LA100_0 == DEFAULT)) {
alt100 = 1;
}
switch(alt100) {
case 1:
// /home/langera/dev/freud/trunk/src/grammar/Java.g:0:0: switchDefaultLabel
{
pushFollow(FOLLOW_switchDefaultLabel_in_switchBlockLabels9840);
switchDefaultLabel346 = switchDefaultLabel();
state._fsp--;
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_switchDefaultLabel.add(switchDefaultLabel346.getTree());
}
}
break;
}
pushFollow(FOLLOW_switchCaseLabels_in_switchBlockLabels9845);
postCases = switchCaseLabels();
state._fsp--;
if (state.failed) {
return retval;
}
if (state.backtracking == 0) {
stream_switchCaseLabels.add(postCases.getTree());
}
// wildcard labels:
if (state.backtracking == 0) {
retval.tree = root_0;
RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.tree : null);
RewriteRuleSubtreeStream stream_preCases = new RewriteRuleSubtreeStream(adaptor, "rule preCases", preCases != null ? preCases.tree : null);
RewriteRuleSubtreeStream stream_postCases = new RewriteRuleSubtreeStream(adaptor, "rule postCases", postCases != null ? postCases.tree : null);
root_0 = (CommonTree) adaptor.nil();
// 887:9: -> ^( SWITCH_BLOCK_LABEL_LIST ( $preCases)? ( switchDefaultLabel )? ( $postCases)? )
{
// /home/langera/dev/freud/trunk/src/grammar/Java.g:887:13: ^( SWITCH_BLOCK_LABEL_LIST ( $preCases)? ( switchDefaultLabel )? ( $postCases)? )
{
CommonTree root_1 = (CommonTree) adaptor.nil();
root_1 = (CommonTree) adaptor.becomeRoot((CommonTree) adaptor.create(SWITCH_BLOCK_LABEL_LIST, "SWITCH_BLOCK_LABEL_LIST"), root_1);
// /home/langera/dev/freud/trunk/src/grammar/Java.g:887:39: ( $preCases)?
if (stream_preCases.hasNext()) {
adaptor.addChild(root_1, stream_preCases.nextTree());
}
stream_preCases.reset();
// /home/langera/dev/freud/trunk/src/grammar/Java.g:887:50: ( switchDefaultLabel )?
if (stream_switchDefaultLabel.hasNext()) {
adaptor.addChild(root_1, stream_switchDefaultLabel.nextTree());
}
stream_switchDefaultLabel.reset();
// /home/langera/dev/freud/trunk/src/grammar/Java.g:887:70: ( $postCases)?
if (stream_postCases.hasNext()) {
adaptor.addChild(root_1, stream_postCases.nextTree());
}
stream_postCases.reset();
adaptor.addChild(root_0, root_1);
}
}
retval.tree = root_0;
}
}
retval.stop = input.LT(-1);
if (state.backtracking == 0) {
retval.tree = (CommonTree) adaptor.rulePostProcessing(root_0);
adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
}
} catch (RecognitionException re) {
reportError(re);
recover(input, re);
retval.tree = (CommonTree) adaptor.errorNode(input, retval.start, input.LT(-1), re);
} finally {
if (state.backtracking > 0) {
memoize(input, 79, switchBlockLabels_StartIndex);
}
}
return retval;
}
use of org.antlr.runtime.tree.CommonTree in project atlas by alibaba.
the class SmaliMod method assembleSmaliFile.
public static boolean assembleSmaliFile(File smaliFile, DexBuilder dexBuilder, boolean verboseErrors, boolean printTokens) throws IOException, RecognitionException {
CommonTokenStream tokens;
LexerErrorInterface lexer;
InputStream is = new FileInputStream(smaliFile);
InputStreamReader reader = new InputStreamReader(is, "UTF-8");
lexer = new smaliFlexLexer(reader);
((smaliFlexLexer) lexer).setSourceFile(smaliFile);
tokens = new CommonTokenStream((TokenSource) lexer);
if (printTokens) {
tokens.getTokens();
for (int i = 0; i < tokens.size(); i++) {
Token token = tokens.get(i);
if (token.getChannel() == smaliParser.HIDDEN) {
continue;
}
System.out.println(smaliParser.tokenNames[token.getType()] + ": " + token.getText());
}
}
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(verboseErrors);
smaliParser.smali_file_return result = parser.smali_file();
if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) {
return false;
}
CommonTree t = (CommonTree) result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.setVerboseErrors(verboseErrors);
dexGen.setDexBuilder(dexBuilder);
dexGen.smali_file();
return dexGen.getNumberOfSyntaxErrors() == 0;
}
use of org.antlr.runtime.tree.CommonTree in project smali by JesusFreke.
the class Smali method assembleSmaliFile.
private static boolean assembleSmaliFile(File smaliFile, DexBuilder dexBuilder, SmaliOptions options) throws Exception {
FileInputStream fis = null;
try {
fis = new FileInputStream(smaliFile);
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
LexerErrorInterface lexer = new smaliFlexLexer(reader);
((smaliFlexLexer) lexer).setSourceFile(smaliFile);
CommonTokenStream tokens = new CommonTokenStream((TokenSource) lexer);
if (options.printTokens) {
tokens.getTokens();
for (int i = 0; i < tokens.size(); i++) {
Token token = tokens.get(i);
if (token.getChannel() == smaliParser.HIDDEN) {
continue;
}
System.out.println(smaliParser.tokenNames[token.getType()] + ": " + token.getText());
}
System.out.flush();
}
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(options.verboseErrors);
parser.setAllowOdex(options.allowOdexOpcodes);
parser.setApiLevel(options.apiLevel);
smaliParser.smali_file_return result = parser.smali_file();
if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) {
return false;
}
CommonTree t = result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
if (options.printTokens) {
System.out.println(t.toStringTree());
}
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.setApiLevel(options.apiLevel);
dexGen.setVerboseErrors(options.verboseErrors);
dexGen.setDexBuilder(dexBuilder);
dexGen.smali_file();
return dexGen.getNumberOfSyntaxErrors() == 0;
} finally {
if (fis != null) {
fis.close();
}
}
}
Aggregations