Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ECast node from the Painless user tree #52915

Merged
merged 7 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.Scope;
import org.elasticsearch.painless.ir.CastNode;
import org.elasticsearch.painless.ir.ClassNode;
import org.elasticsearch.painless.ir.ExpressionNode;
import org.elasticsearch.painless.lookup.PainlessCast;
Expand Down Expand Up @@ -83,10 +84,7 @@ public abstract class AExpression extends ANode {
*/
boolean internal = false;

/**
* Set to true by {@link ENull} to represent a null value.
*/
boolean isNull = false;
PainlessCast cast = null;
jdconrad marked this conversation as resolved.
Show resolved Hide resolved

/**
* Standard constructor with location used for error tracking.
Expand Down Expand Up @@ -116,23 +114,21 @@ public abstract class AExpression extends ANode {
*/
abstract ExpressionNode write(ClassNode classNode);

/**
* Inserts {@link ECast} nodes into the tree for implicit casts. Also replaces
* nodes with the constant variable set to a non-null value with {@link EConstant}.
* @return The new child node for the parent node calling this method.
*/
AExpression cast(ScriptRoot scriptRoot, Scope scope) {
PainlessCast cast = AnalyzerCaster.getLegalCast(location, actual, expected, explicit, internal);
void cast() {
cast = AnalyzerCaster.getLegalCast(location, actual, expected, explicit, internal);
}

ExpressionNode cast(ExpressionNode expressionNode) {
if (cast == null) {
return this;
} else {
ECast ecast = new ECast(location, this, cast);
ecast.statement = statement;
ecast.actual = expected;
ecast.isNull = isNull;

return ecast;
return expressionNode;
}

CastNode castNode = new CastNode();
castNode.setLocation(location);
castNode.setExpressionType(expected);
castNode.setCast(cast);
castNode.setChildNode(expressionNode);

return castNode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void analyzeCompound(ScriptRoot scriptRoot, Scope scope) {
rhs.expected = promote;
}

rhs = rhs.cast(scriptRoot, scope);
rhs.cast();

there = AnalyzerCaster.getLegalCast(location, lhs.actual, promote, false, false);
back = AnalyzerCaster.getLegalCast(location, promote, lhs.actual, true, false);
Expand Down Expand Up @@ -216,7 +216,7 @@ private void analyzeSimple(ScriptRoot scriptRoot, Scope scope) {
rhs.analyze(scriptRoot, scope);
}

rhs = rhs.cast(scriptRoot, scope);
rhs.cast();

this.statement = true;
this.actual = read ? lhs.actual : void.class;
Expand All @@ -233,7 +233,7 @@ AssignmentNode write(ClassNode classNode) {
AssignmentNode assignmentNode = new AssignmentNode();

assignmentNode.setLeftNode(lhs.write(classNode));
assignmentNode.setRightNode(rhs.write(classNode));
assignmentNode.setRightNode(rhs.cast(rhs.write(classNode)));

assignmentNode.setLocation(location);
assignmentNode.setExpressionType(actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ private void analyzeMul(ScriptRoot scriptRoot, Scope variables) {
right.expected = promote;
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeDiv(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -144,8 +144,8 @@ private void analyzeDiv(ScriptRoot scriptRoot, Scope variables) {
right.expected = promote;
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeRem(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -174,8 +174,8 @@ private void analyzeRem(ScriptRoot scriptRoot, Scope variables) {
right.expected = promote;
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeAdd(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -216,8 +216,8 @@ private void analyzeAdd(ScriptRoot scriptRoot, Scope variables) {
right.expected = promote;
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeSub(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -246,8 +246,8 @@ private void analyzeSub(ScriptRoot scriptRoot, Scope variables) {
right.expected = promote;
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeRegexOp(ScriptRoot scriptRoot, Scope variables) {
Expand All @@ -257,8 +257,8 @@ private void analyzeRegexOp(ScriptRoot scriptRoot, Scope variables) {
left.expected = String.class;
right.expected = Pattern.class;

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();

promote = boolean.class;
actual = boolean.class;
Expand Down Expand Up @@ -298,8 +298,8 @@ private void analyzeLSH(ScriptRoot scriptRoot, Scope variables) {
}
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeRSH(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -336,8 +336,8 @@ private void analyzeRSH(ScriptRoot scriptRoot, Scope variables) {
}
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeUSH(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -374,8 +374,8 @@ private void analyzeUSH(ScriptRoot scriptRoot, Scope variables) {
}
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeBWAnd(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -404,8 +404,8 @@ private void analyzeBWAnd(ScriptRoot scriptRoot, Scope variables) {
right.expected = promote;
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeXor(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -433,8 +433,8 @@ private void analyzeXor(ScriptRoot scriptRoot, Scope variables) {
right.expected = promote;
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

private void analyzeBWOr(ScriptRoot scriptRoot, Scope variables) {
Expand Down Expand Up @@ -462,16 +462,16 @@ private void analyzeBWOr(ScriptRoot scriptRoot, Scope variables) {
right.expected = promote;
}

left = left.cast(scriptRoot, variables);
right = right.cast(scriptRoot, variables);
left.cast();
right.cast();
}

@Override
BinaryMathNode write(ClassNode classNode) {
BinaryMathNode binaryMathNode = new BinaryMathNode();

binaryMathNode.setLeftNode(left.write(classNode));
binaryMathNode.setRightNode(right.write(classNode));
binaryMathNode.setLeftNode(left.cast(left.write(classNode)));
binaryMathNode.setRightNode(right.cast(right.write(classNode)));

binaryMathNode.setLocation(location);
binaryMathNode.setExpressionType(actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public EBool(Location location, Operation operation, AExpression left, AExpressi
void analyze(ScriptRoot scriptRoot, Scope scope) {
left.expected = boolean.class;
left.analyze(scriptRoot, scope);
left = left.cast(scriptRoot, scope);
left.cast();

right.expected = boolean.class;
right.analyze(scriptRoot, scope);
right = right.cast(scriptRoot, scope);
right.cast();

actual = boolean.class;
}
Expand All @@ -62,8 +62,8 @@ void analyze(ScriptRoot scriptRoot, Scope scope) {
BooleanNode write(ClassNode classNode) {
BooleanNode booleanNode = new BooleanNode();

booleanNode.setLeftNode(left.write(classNode));
booleanNode.setRightNode(right.write(classNode));
booleanNode.setLeftNode(left.cast(left.write(classNode)));
booleanNode.setRightNode(right.cast(right.write(classNode)));

booleanNode.setLocation(location);
booleanNode.setExpressionType(actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void analyze(ScriptRoot scriptRoot, Scope scope) {
expression.expected = typeParameters.get(argument + classBindingOffset);
expression.internal = true;
expression.analyze(scriptRoot, scope);
arguments.set(argument, expression.cast(scriptRoot, scope));
expression.cast();
}

statement = true;
Expand All @@ -155,7 +155,7 @@ MemberCallNode write(ClassNode classNode) {
MemberCallNode memberCallNode = new MemberCallNode();

for (AExpression argument : arguments) {
memberCallNode.addArgumentNode(argument.write(classNode));
memberCallNode.addArgumentNode(argument.cast(argument.write(classNode)));
}

memberCallNode.setLocation(location);
Expand Down

This file was deleted.

Loading