|
@@ -28,6 +28,7 @@ import org.antlr.v4.runtime.RecognitionException;
|
|
|
import org.antlr.v4.runtime.Recognizer;
|
|
|
import org.antlr.v4.runtime.atn.PredictionMode;
|
|
|
import org.elasticsearch.painless.CompilerSettings;
|
|
|
+import org.elasticsearch.painless.Location;
|
|
|
import org.elasticsearch.painless.Operation;
|
|
|
import org.elasticsearch.painless.Variables.Reserved;
|
|
|
import org.elasticsearch.painless.antlr.PainlessParser.AfterthoughtContext;
|
|
@@ -135,25 +136,27 @@ import java.util.List;
|
|
|
*/
|
|
|
public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
|
|
|
- public static SSource buildPainlessTree(String source, Reserved reserved, CompilerSettings settings) {
|
|
|
- return new Walker(source, reserved, settings).source;
|
|
|
+ public static SSource buildPainlessTree(String name, String sourceText, Reserved reserved, CompilerSettings settings) {
|
|
|
+ return new Walker(name, sourceText, reserved, settings).source;
|
|
|
}
|
|
|
|
|
|
private final Reserved reserved;
|
|
|
private final SSource source;
|
|
|
private final CompilerSettings settings;
|
|
|
+ private final String sourceName;
|
|
|
|
|
|
- private Walker(String source, Reserved reserved, CompilerSettings settings) {
|
|
|
+ private Walker(String name, String sourceText, Reserved reserved, CompilerSettings settings) {
|
|
|
this.reserved = reserved;
|
|
|
this.settings = settings;
|
|
|
- this.source = (SSource)visit(buildAntlrTree(source));
|
|
|
+ this.sourceName = Location.computeSourceName(name, sourceText);
|
|
|
+ this.source = (SSource)visit(buildAntlrTree(sourceText));
|
|
|
}
|
|
|
|
|
|
private SourceContext buildAntlrTree(String source) {
|
|
|
ANTLRInputStream stream = new ANTLRInputStream(source);
|
|
|
- PainlessLexer lexer = new ErrorHandlingLexer(stream);
|
|
|
+ PainlessLexer lexer = new ErrorHandlingLexer(stream, sourceName);
|
|
|
PainlessParser parser = new PainlessParser(new CommonTokenStream(lexer));
|
|
|
- ParserErrorStrategy strategy = new ParserErrorStrategy();
|
|
|
+ ParserErrorStrategy strategy = new ParserErrorStrategy(sourceName);
|
|
|
|
|
|
lexer.removeErrorListeners();
|
|
|
parser.removeErrorListeners();
|
|
@@ -185,16 +188,8 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
|
|
|
}
|
|
|
|
|
|
- private int line(ParserRuleContext ctx) {
|
|
|
- return ctx.getStart().getLine();
|
|
|
- }
|
|
|
-
|
|
|
- private int offset(ParserRuleContext ctx) {
|
|
|
- return ctx.getStart().getStartIndex();
|
|
|
- }
|
|
|
-
|
|
|
- private String location(ParserRuleContext ctx) {
|
|
|
- return "[ " + ctx.getStart().getLine() + " : " + ctx.getStart().getCharPositionInLine() + " ]";
|
|
|
+ private Location location(ParserRuleContext ctx) {
|
|
|
+ return new Location(sourceName, ctx.getStart().getStartIndex());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -205,7 +200,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
statements.add((AStatement)visit(statement));
|
|
|
}
|
|
|
|
|
|
- return new SSource(line(ctx), offset(ctx), location(ctx), statements);
|
|
|
+ return new SSource(location(ctx), statements);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -216,9 +211,9 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
if (ctx.trailer().size() > 1) {
|
|
|
SBlock elseblock = (SBlock)visit(ctx.trailer(1));
|
|
|
|
|
|
- return new SIfElse(line(ctx), offset(ctx), location(ctx), expression, ifblock, elseblock);
|
|
|
+ return new SIfElse(location(ctx), expression, ifblock, elseblock);
|
|
|
} else {
|
|
|
- return new SIf(line(ctx), offset(ctx), location(ctx), expression, ifblock);
|
|
|
+ return new SIf(location(ctx), expression, ifblock);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -233,11 +228,11 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
if (ctx.trailer() != null) {
|
|
|
SBlock block = (SBlock)visit(ctx.trailer());
|
|
|
|
|
|
- return new SWhile(line(ctx), offset(ctx), location(ctx), settings.getMaxLoopCounter(), expression, block);
|
|
|
+ return new SWhile(location(ctx), settings.getMaxLoopCounter(), expression, block);
|
|
|
} else if (ctx.empty() != null) {
|
|
|
- return new SWhile(line(ctx), offset(ctx), location(ctx), settings.getMaxLoopCounter(), expression, null);
|
|
|
+ return new SWhile(location(ctx), settings.getMaxLoopCounter(), expression, null);
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException(" Illegal tree structure."));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -250,7 +245,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
AExpression expression = (AExpression)visitExpression(ctx.expression());
|
|
|
SBlock block = (SBlock)visit(ctx.block());
|
|
|
|
|
|
- return new SDo(line(ctx), offset(ctx), location(ctx), settings.getMaxLoopCounter(), block, expression);
|
|
|
+ return new SDo(location(ctx), settings.getMaxLoopCounter(), block, expression);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -266,13 +261,13 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
if (ctx.trailer() != null) {
|
|
|
SBlock block = (SBlock)visit(ctx.trailer());
|
|
|
|
|
|
- return new SFor(line(ctx), offset(ctx), location(ctx),
|
|
|
+ return new SFor(location(ctx),
|
|
|
settings.getMaxLoopCounter(), initializer, expression, afterthought, block);
|
|
|
} else if (ctx.empty() != null) {
|
|
|
- return new SFor(line(ctx), offset(ctx), location(ctx),
|
|
|
+ return new SFor(location(ctx),
|
|
|
settings.getMaxLoopCounter(), initializer, expression, afterthought, null);
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -283,19 +278,19 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
|
|
|
@Override
|
|
|
public Object visitContinue(ContinueContext ctx) {
|
|
|
- return new SContinue(line(ctx), offset(ctx), location(ctx));
|
|
|
+ return new SContinue(location(ctx));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitBreak(BreakContext ctx) {
|
|
|
- return new SBreak(line(ctx), offset(ctx), location(ctx));
|
|
|
+ return new SBreak(location(ctx));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitReturn(ReturnContext ctx) {
|
|
|
AExpression expression = (AExpression)visitExpression(ctx.expression());
|
|
|
|
|
|
- return new SReturn(line(ctx), offset(ctx), location(ctx), expression);
|
|
|
+ return new SReturn(location(ctx), expression);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -307,21 +302,21 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
catches.add((SCatch)visit(trap));
|
|
|
}
|
|
|
|
|
|
- return new STry(line(ctx), offset(ctx), location(ctx), block, catches);
|
|
|
+ return new STry(location(ctx), block, catches);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitThrow(ThrowContext ctx) {
|
|
|
AExpression expression = (AExpression)visitExpression(ctx.expression());
|
|
|
|
|
|
- return new SThrow(line(ctx), offset(ctx), location(ctx), expression);
|
|
|
+ return new SThrow(location(ctx), expression);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitExpr(ExprContext ctx) {
|
|
|
AExpression expression = (AExpression)visitExpression(ctx.expression());
|
|
|
|
|
|
- return new SExpression(line(ctx), offset(ctx), location(ctx), expression);
|
|
|
+ return new SExpression(location(ctx), expression);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -332,9 +327,9 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
List<AStatement> statements = new ArrayList<>();
|
|
|
statements.add((AStatement)visit(ctx.statement()));
|
|
|
|
|
|
- return new SBlock(line(ctx), offset(ctx), location(ctx), statements);
|
|
|
+ return new SBlock(location(ctx), statements);
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -349,13 +344,13 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
statements.add((AStatement)visit(statement));
|
|
|
}
|
|
|
|
|
|
- return new SBlock(line(ctx), offset(ctx), location(ctx), statements);
|
|
|
+ return new SBlock(location(ctx), statements);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitEmpty(EmptyContext ctx) {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -365,7 +360,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.expression() != null) {
|
|
|
return visitExpression(ctx.expression());
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -383,25 +378,25 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
String name = declvar.ID().getText();
|
|
|
AExpression expression = declvar.expression() == null ? null : (AExpression)visitExpression(declvar.expression());
|
|
|
|
|
|
- declarations.add(new SDeclaration(line(declvar), offset(declvar), location(declvar), type, name, expression));
|
|
|
+ declarations.add(new SDeclaration(location(declvar), type, name, expression));
|
|
|
}
|
|
|
|
|
|
- return new SDeclBlock(line(ctx), offset(ctx), location(ctx), declarations);
|
|
|
+ return new SDeclBlock(location(ctx), declarations);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitDecltype(DecltypeContext ctx) {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitFuncref(FuncrefContext ctx) {
|
|
|
- return new EFunctionRef(line(ctx), offset(ctx), location(ctx), ctx.TYPE().getText(), ctx.ID().getText());
|
|
|
+ return new EFunctionRef(location(ctx), ctx.TYPE().getText(), ctx.ID().getText());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitDeclvar(DeclvarContext ctx) {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -410,12 +405,12 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
String name = ctx.ID().getText();
|
|
|
SBlock block = (SBlock)visit(ctx.block());
|
|
|
|
|
|
- return new SCatch(line(ctx), offset(ctx), location(ctx), type, name, block);
|
|
|
+ return new SCatch(location(ctx), type, name, block);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitDelimiter(DelimiterContext ctx) {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
private Object visitExpression(ExpressionContext ctx) {
|
|
@@ -425,7 +420,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
List<ALink> links = (List<ALink>)expression;
|
|
|
|
|
|
- return new EChain(line(ctx), offset(ctx), location(ctx), links, false, false, null, null);
|
|
|
+ return new EChain(location(ctx), links, false, false, null, null);
|
|
|
} else {
|
|
|
return expression;
|
|
|
}
|
|
@@ -465,10 +460,10 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.BWOR() != null) {
|
|
|
operation = Operation.BWOR;
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + ": Unexpected state.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Unexpected state."));
|
|
|
}
|
|
|
|
|
|
- return new EBinary(line(ctx), offset(ctx), location(ctx), operation, left, right);
|
|
|
+ return new EBinary(location(ctx), operation, left, right);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -494,10 +489,10 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.NER() != null) {
|
|
|
operation = Operation.NER;
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + ": Unexpected state.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Unexpected state."));
|
|
|
}
|
|
|
|
|
|
- return new EComp(line(ctx), offset(ctx), location(ctx), operation, left, right);
|
|
|
+ return new EComp(location(ctx), operation, left, right);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -511,10 +506,10 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.BOOLOR() != null) {
|
|
|
operation = Operation.OR;
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + ": Unexpected state.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Unexpected state."));
|
|
|
}
|
|
|
|
|
|
- return new EBool(line(ctx), offset(ctx), location(ctx), operation, left, right);
|
|
|
+ return new EBool(location(ctx), operation, left, right);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -523,7 +518,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
AExpression left = (AExpression)visitExpression(ctx.expression(1));
|
|
|
AExpression right = (AExpression)visitExpression(ctx.expression(2));
|
|
|
|
|
|
- return new EConditional(line(ctx), offset(ctx), location(ctx), condition, left, right);
|
|
|
+ return new EConditional(location(ctx), condition, left, right);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -557,12 +552,12 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.AOR() != null) {
|
|
|
operation = Operation.BWOR;
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + ": Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
AExpression expression = (AExpression)visitExpression(ctx.expression());
|
|
|
|
|
|
- return new EChain(line(ctx), offset(ctx), location(ctx), links, false, false, operation, expression);
|
|
|
+ return new EChain(location(ctx), links, false, false, operation, expression);
|
|
|
}
|
|
|
|
|
|
private Object visitUnary(UnaryContext ctx) {
|
|
@@ -572,7 +567,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
List<ALink> links = (List<ALink>)expression;
|
|
|
|
|
|
- return new EChain(line(ctx), offset(ctx), location(ctx), links, false, false, null, null);
|
|
|
+ return new EChain(location(ctx), links, false, false, null, null);
|
|
|
} else {
|
|
|
return expression;
|
|
|
}
|
|
@@ -589,10 +584,10 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.DECR() != null) {
|
|
|
operation = Operation.DECR;
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + ": Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
- return new EChain(line(ctx), offset(ctx), location(ctx), links, true, false, operation, null);
|
|
|
+ return new EChain(location(ctx), links, true, false, operation, null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -606,10 +601,10 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.DECR() != null) {
|
|
|
operation = Operation.DECR;
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + ": Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
- return new EChain(line(ctx), offset(ctx), location(ctx), links, false, true, operation, null);
|
|
|
+ return new EChain(location(ctx), links, false, true, operation, null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -622,31 +617,31 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
final boolean negate = ctx.parent instanceof OperatorContext && ((OperatorContext)ctx.parent).SUB() != null;
|
|
|
|
|
|
if (ctx.DECIMAL() != null) {
|
|
|
- return new EDecimal(line(ctx), offset(ctx), location(ctx), (negate ? "-" : "") + ctx.DECIMAL().getText());
|
|
|
+ return new EDecimal(location(ctx), (negate ? "-" : "") + ctx.DECIMAL().getText());
|
|
|
} else if (ctx.HEX() != null) {
|
|
|
- return new ENumeric(line(ctx), offset(ctx), location(ctx), (negate ? "-" : "") + ctx.HEX().getText().substring(2), 16);
|
|
|
+ return new ENumeric(location(ctx), (negate ? "-" : "") + ctx.HEX().getText().substring(2), 16);
|
|
|
} else if (ctx.INTEGER() != null) {
|
|
|
- return new ENumeric(line(ctx), offset(ctx), location(ctx), (negate ? "-" : "") + ctx.INTEGER().getText(), 10);
|
|
|
+ return new ENumeric(location(ctx), (negate ? "-" : "") + ctx.INTEGER().getText(), 10);
|
|
|
} else if (ctx.OCTAL() != null) {
|
|
|
- return new ENumeric(line(ctx), offset(ctx), location(ctx), (negate ? "-" : "") + ctx.OCTAL().getText().substring(1), 8);
|
|
|
+ return new ENumeric(location(ctx), (negate ? "-" : "") + ctx.OCTAL().getText().substring(1), 8);
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + ": Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitTrue(TrueContext ctx) {
|
|
|
- return new EBoolean(line(ctx), offset(ctx), location(ctx), true);
|
|
|
+ return new EBoolean(location(ctx), true);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitFalse(FalseContext ctx) {
|
|
|
- return new EBoolean(line(ctx), offset(ctx), location(ctx), false);
|
|
|
+ return new EBoolean(location(ctx), false);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitNull(NullContext ctx) {
|
|
|
- return new ENull(line(ctx), offset(ctx), location(ctx));
|
|
|
+ return new ENull(location(ctx));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -666,10 +661,10 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.SUB() != null) {
|
|
|
operation = Operation.SUB;
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
- return new EUnary(line(ctx), offset(ctx), location(ctx), operation, expression);
|
|
|
+ return new EUnary(location(ctx), operation, expression);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -681,11 +676,11 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
if (child instanceof List) {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
List<ALink> links = (List<ALink>)child;
|
|
|
- links.add(new LCast(line(ctx), offset(ctx), location(ctx), type));
|
|
|
+ links.add(new LCast(location(ctx), type));
|
|
|
|
|
|
return links;
|
|
|
} else {
|
|
|
- return new EExplicit(line(ctx), offset(ctx), location(ctx), type, (AExpression)child);
|
|
|
+ return new EExplicit(location(ctx), type, (AExpression)child);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -703,7 +698,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
|
|
|
return links;
|
|
|
} else if (!ctx.secondary().isEmpty()) {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
} else {
|
|
|
return child;
|
|
|
}
|
|
@@ -714,7 +709,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
String type = ctx.decltype().getText();
|
|
|
List<ALink> links = new ArrayList<>();
|
|
|
|
|
|
- links.add(new LStatic(line(ctx), offset(ctx), location(ctx), type));
|
|
|
+ links.add(new LStatic(location(ctx), type));
|
|
|
links.add((ALink)visit(ctx.dot()));
|
|
|
|
|
|
for (SecondaryContext secondary : ctx.secondary()) {
|
|
@@ -734,7 +729,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
}
|
|
|
|
|
|
List<ALink> links = new ArrayList<>();
|
|
|
- links.add(new LNewArray(line(ctx), offset(ctx), location(ctx), type, expressions));
|
|
|
+ links.add(new LNewArray(location(ctx), type, expressions));
|
|
|
|
|
|
if (ctx.dot() != null) {
|
|
|
links.add((ALink)visit(ctx.dot()));
|
|
@@ -743,7 +738,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
links.add((ALink)visit(secondary));
|
|
|
}
|
|
|
} else if (!ctx.secondary().isEmpty()) {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
return links;
|
|
@@ -763,7 +758,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
public Object visitString(StringContext ctx) {
|
|
|
String string = ctx.STRING().getText().substring(1, ctx.STRING().getText().length() - 1);
|
|
|
List<ALink> links = new ArrayList<>();
|
|
|
- links.add(new LString(line(ctx), offset(ctx), location(ctx), string));
|
|
|
+ links.add(new LString(location(ctx), string));
|
|
|
|
|
|
return links;
|
|
|
}
|
|
@@ -772,7 +767,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
public Object visitVariable(VariableContext ctx) {
|
|
|
String name = ctx.ID().getText();
|
|
|
List<ALink> links = new ArrayList<>();
|
|
|
- links.add(new LVariable(line(ctx), offset(ctx), location(ctx), name));
|
|
|
+ links.add(new LVariable(location(ctx), name));
|
|
|
|
|
|
reserved.markReserved(name);
|
|
|
|
|
@@ -786,7 +781,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
List<AExpression> arguments = (List<AExpression>)visit(ctx.arguments());
|
|
|
|
|
|
List<ALink> links = new ArrayList<>();
|
|
|
- links.add(new LNewObj(line(ctx), offset(ctx), location(ctx), type, arguments));
|
|
|
+ links.add(new LNewObj(location(ctx), type, arguments));
|
|
|
|
|
|
return links;
|
|
|
}
|
|
@@ -798,7 +793,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.brace() != null) {
|
|
|
return visit(ctx.brace());
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -808,7 +803,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
List<AExpression> arguments = (List<AExpression>)visit(ctx.arguments());
|
|
|
|
|
|
- return new LCall(line(ctx), offset(ctx), location(ctx), name, arguments);
|
|
|
+ return new LCall(location(ctx), name, arguments);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -820,17 +815,17 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.DOTINTEGER() != null) {
|
|
|
value = ctx.DOTINTEGER().getText();
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
|
|
|
- return new LField(line(ctx), offset(ctx), location(ctx), value);
|
|
|
+ return new LField(location(ctx), value);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object visitBraceaccess(BraceaccessContext ctx) {
|
|
|
AExpression expression = (AExpression)visitExpression(ctx.expression());
|
|
|
|
|
|
- return new LBrace(line(ctx), offset(ctx), location(ctx), expression);
|
|
|
+ return new LBrace(location(ctx), expression);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -851,7 +846,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
|
|
|
} else if (ctx.funcref() != null) {
|
|
|
return visit(ctx.funcref());
|
|
|
} else {
|
|
|
- throw new IllegalStateException("Error " + location(ctx) + " Illegal tree structure.");
|
|
|
+ throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
|
|
|
}
|
|
|
}
|
|
|
}
|