public static NodeLocation getLocation(TerminalNode terminalNode) { requireNonNull(terminalNode, "terminalNode is null"); return getLocation(terminalNode.getSymbol()); }
private static NodeLocation getLocation(final TerminalNode terminalNode) { requireNonNull(terminalNode, "terminalNode is null"); return getLocation(terminalNode.getSymbol()); }
@Override public Object visitFspareswitch(SmaliParser.FspareswitchContext ctx) { List<TerminalNode> ints = ctx.INT(); List<TerminalNode> ts = ctx.LABEL(); int cases[] = new int[ts.size()]; DexLabel labels[] = new DexLabel[ts.size()]; for (int i = 0; i < ts.size(); i++) { cases[i] = parseInt(ints.get(i).getSymbol().getText()); labels[i] = getLabel(ts.get(i).getSymbol().getText()); } scv.dSparseSwitch(cases, labels); return null; }
static private int collectAccess(SmaliParser.SAccListContext ctx) { int access = 0; for (TerminalNode acc : ctx.ACC()) { access |= Utils.getAcc(acc.getSymbol().getText()); } return access; } }
@Override public Object visitFpackageswitch(SmaliParser.FpackageswitchContext ctx) { int start = parseInt(ctx.start.getText()); List<TerminalNode> ts = ctx.LABEL(); DexLabel labels[] = new DexLabel[ts.size()]; for (int i = 0; i < ts.size(); i++) { labels[i] = getLabel(ts.get(i).getSymbol().getText()); } scv.dPackedSwitch(start, labels); return null; }
@Override public Object visitFt5c(SmaliParser.Ft5cContext ctx) { Op op = getOp(ctx.op); List<TerminalNode> ts = ctx.REGISTER(); int rs[] = new int[ts.size()]; for (int i = 0; i < ts.size(); i++) { rs[i] = m.pareReg(ts.get(i).getSymbol().getText()); } scv.visitFilledNewArrayStmt(op, rs, unEscapeId(ctx.type.getText())); return null; }
@Override public Object visitFm5c(SmaliParser.Fm5cContext ctx) { Op op = getOp(ctx.op); List<TerminalNode> ts = ctx.REGISTER(); int rs[] = new int[ts.size()]; for (int i = 0; i < ts.size(); i++) { rs[i] = m.pareReg(ts.get(i).getSymbol().getText()); } scv.visitMethodStmt(op, rs, parseMethodAndUnescape(ctx.method.getText())); return null; }
/** * Gets line number from ParseTree node. * @param tree * ParseTree node * @return line number */ private static int getLine(ParseTree tree) { final int line; if (tree instanceof TerminalNode) { line = ((TerminalNode) tree).getSymbol().getLine() - 1; } else { final ParserRuleContext rule = (ParserRuleContext) tree; line = rule.start.getLine() - 1; } return line; }
/** * Gets column number from ParseTree node. * @param tree * ParseTree node * @return column number */ private static int getColumn(ParseTree tree) { final int column; if (tree instanceof TerminalNode) { column = ((TerminalNode) tree).getSymbol().getCharPositionInLine(); } else { final ParserRuleContext rule = (ParserRuleContext) tree; column = rule.start.getCharPositionInLine(); } return column; }
@Override public void exitUnaryOpExpr(ExprParser.UnaryOpExprContext ctx) { int opCode = ((TerminalNode) ctx.getChild(0)).getSymbol().getType(); switch (opCode) { case ExprParser.MINUS: nodes.put(ctx, new UnaryMinusExpr((Expr) nodes.get(ctx.getChild(1)))); break; case ExprParser.NOT: nodes.put(ctx, new UnaryNotExpr((Expr) nodes.get(ctx.getChild(1)))); break; default: throw new RuntimeException("Unrecognized unary operator " + ctx.getChild(0).getText()); } }
@Override public void exitDigitIdentifier(SqlBaseParser.DigitIdentifierContext context) { Token token = context.DIGIT_IDENTIFIER().getSymbol(); throw new ParsingException( "identifiers must not start with a digit; surround the identifier with double quotes", null, token.getLine(), token.getCharPositionInLine()); }
@Override public void exitBackQuotedIdentifier(SqlBaseParser.BackQuotedIdentifierContext context) { Token token = context.BACKQUOTED_IDENTIFIER().getSymbol(); throw new ParsingException( "backquoted identifiers are not supported; use double quotes to quote identifiers", null, token.getLine(), token.getCharPositionInLine()); }
@Override public void exitUnquotedIdentifier(SqlBaseParser.UnquotedIdentifierContext context) { String identifier = context.IDENTIFIER().getText(); for (IdentifierSymbol identifierSymbol : EnumSet.complementOf(allowedIdentifierSymbols)) { char symbol = identifierSymbol.getSymbol(); if (identifier.indexOf(symbol) >= 0) { throw new ParsingException("identifiers must not contain '" + identifierSymbol.getSymbol() + "'", null, context.IDENTIFIER().getSymbol().getLine(), context.IDENTIFIER().getSymbol().getCharPositionInLine()); } } }
/** * Gets token type of ParseTree node from JavadocTokenTypes class. * @param node ParseTree node. * @return token type from JavadocTokenTypes */ private static int getTokenType(ParseTree node) { final int tokenType; if (node.getChildCount() == 0) { tokenType = ((TerminalNode) node).getSymbol().getType(); } else { final String className = getNodeClassNameWithoutContext(node); final String typeName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, className); tokenType = JavadocUtil.getTokenId(typeName); } return tokenType; }
@Override public void exitAddSubExpr(ExprParser.AddSubExprContext ctx) { int opCode = ((TerminalNode) ctx.getChild(1)).getSymbol().getType(); switch (opCode) { case ExprParser.PLUS: nodes.put( ctx, new BinPlusExpr( ctx.getChild(1).getText(), (Expr) nodes.get(ctx.getChild(0)), (Expr) nodes.get(ctx.getChild(2)) ) ); break; case ExprParser.MINUS: nodes.put( ctx, new BinMinusExpr( ctx.getChild(1).getText(), (Expr) nodes.get(ctx.getChild(0)), (Expr) nodes.get(ctx.getChild(2)) ) ); break; default: throw new RuntimeException("Unrecognized binary operator " + ctx.getChild(1).getText()); } }
@Override public Node visitQuantifiedComparison(SqlBaseParser.QuantifiedComparisonContext context) { return new QuantifiedComparisonExpression( getLocation(context.comparisonOperator()), getComparisonOperator(((TerminalNode) context.comparisonOperator().getChild(0)).getSymbol()), getComparisonQuantifier(((TerminalNode) context.comparisonQuantifier().getChild(0)).getSymbol()), (Expression) visit(context.value), new SubqueryExpression(getLocation(context.query()), (Query) visit(context.query()))); }
@Override public Node visitComparison(SqlBaseParser.ComparisonContext context) { return new ComparisonExpression( getLocation(context.comparisonOperator()), getComparisonOperator(((TerminalNode) context.comparisonOperator().getChild(0)).getSymbol()), (Expression) visit(context.value), (Expression) visit(context.right)); }
private ExpressionSegment extractFunctionExpressionSegment(final ParserRuleContext functionNode) { return new FunctionExpressionSegment(functionNode.getChild(0).getText(), functionNode.getStart().getStartIndex(), ((TerminalNode) functionNode.getChild(1)).getSymbol().getStartIndex(), functionNode.getStop().getStopIndex(), -1); }
@Override public Node visitComparison(final SqlBaseParser.ComparisonContext context) { return new ComparisonExpression( getLocation(context.comparisonOperator()), getComparisonOperator( ((TerminalNode) context.comparisonOperator().getChild(0)).getSymbol()), (Expression) visit(context.value), (Expression) visit(context.right) ); }