Skip to content

Commit 523e9ff

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Add EqualsExpression, BinaryExpression, UnaryExpression and ParenthesizedExpression
Change-Id: Ida185b192c329f21979f6d5fbf39aa17ef1b9c0c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123409 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Aske Simon Christensen <askesc@google.com>
1 parent a996783 commit 523e9ff

29 files changed

+1311
-927
lines changed

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 26 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,54 +1546,34 @@ class BodyBuilder extends ScopeListener<JumpTarget>
15461546
]));
15471547
Expression right = popForValue();
15481548
Object left = pop();
1549-
bool negate = false;
1550-
String operator = token.stringValue;
1551-
if (identical("!=", operator)) {
1552-
operator = "==";
1553-
negate = true;
1554-
}
15551549
int fileOffset = offsetForToken(token);
1556-
Name name = new Name(operator);
1557-
if (!isBinaryOperator(operator) && !isMinusOperator(operator)) {
1558-
if (isUserDefinableOperator(operator)) {
1559-
push(buildProblem(fasta.templateNotBinaryOperator.withArguments(token),
1560-
token.charOffset, token.length));
1550+
String operator = token.stringValue;
1551+
bool isNot = identical("!=", operator);
1552+
if (isNot || identical("==", operator)) {
1553+
if (left is Generator) {
1554+
push(left.buildEqualsOperation(token, right, isNot: isNot));
15611555
} else {
1562-
push(buildProblem(fasta.templateInvalidOperator.withArguments(token),
1563-
token.charOffset, token.length));
1556+
assert(left is Expression);
1557+
push(forest.createEquals(fileOffset, left, right, isNot: isNot));
15641558
}
1565-
} else if (left is ExplicitExtensionAccessGenerator) {
1566-
// TODO(johnniwinther): Use this code path for all generators. Currently
1567-
// TypeUseGenerator starts complaining about `Map<` not being a method
1568-
// instead of `<` not defined on `Type`.
1569-
Object result = left.buildPropertyAccess(
1570-
new SendAccessGenerator(this, token, name,
1571-
forest.createArguments(fileOffset, <Expression>[right]),
1572-
isPotentiallyConstant: true),
1573-
fileOffset,
1574-
false);
1575-
push(negate ? forest.createNot(fileOffset, toValue(result)) : result);
15761559
} else {
1577-
bool isSuper = false;
1578-
Expression leftValue;
1579-
if (left is ThisAccessGenerator && left.isSuper) {
1580-
ThisAccessGenerator thisAccessorReceiver = left;
1581-
isSuper = true;
1582-
leftValue =
1583-
forest.createThisExpression(thisAccessorReceiver.fileOffset);
1560+
Name name = new Name(operator);
1561+
if (!isBinaryOperator(operator) && !isMinusOperator(operator)) {
1562+
if (isUserDefinableOperator(operator)) {
1563+
push(buildProblem(
1564+
fasta.templateNotBinaryOperator.withArguments(token),
1565+
token.charOffset,
1566+
token.length));
1567+
} else {
1568+
push(buildProblem(fasta.templateInvalidOperator.withArguments(token),
1569+
token.charOffset, token.length));
1570+
}
1571+
} else if (left is Generator) {
1572+
push(left.buildBinaryOperation(token, name, right));
15841573
} else {
1585-
leftValue = toValue(left);
1574+
assert(left is Expression);
1575+
push(forest.createBinary(fileOffset, left, name, right));
15861576
}
1587-
Expression result = buildMethodInvocation(
1588-
leftValue,
1589-
name,
1590-
forest.createArguments(fileOffset, <Expression>[right]),
1591-
token.charOffset,
1592-
// This *could* be a constant expression, we can't know without
1593-
// evaluating [left] and [right].
1594-
isConstantExpression: !isSuper,
1595-
isSuper: isSuper);
1596-
push(negate ? forest.createNot(fileOffset, result) : result);
15971577
}
15981578
}
15991579

@@ -1854,9 +1834,6 @@ class BodyBuilder extends ScopeListener<JumpTarget>
18541834
return new ParserErrorGenerator(this, token, fasta.messageSyntheticToken);
18551835
}
18561836
Builder declaration = scope.lookup(name, charOffset, uri);
1857-
if (declaration is UnlinkedDeclaration) {
1858-
return new UnlinkedGenerator(this, token, declaration);
1859-
}
18601837
if (declaration == null &&
18611838
prefix == null &&
18621839
(classBuilder?.isPatch ?? false)) {
@@ -3479,33 +3456,11 @@ class BodyBuilder extends ScopeListener<JumpTarget>
34793456
}
34803457
int fileOffset = offsetForToken(token);
34813458
Name name = new Name(operator);
3482-
if (receiver is ExplicitExtensionAccessGenerator) {
3483-
// TODO(johnniwinther): Use this code path for all generators. Currently
3484-
// TypeUseGenerator starts complaining about `-Map` not being a method
3485-
// instead of `unary-` not defined on `Type`.
3486-
push(receiver.buildPropertyAccess(
3487-
new SendAccessGenerator(
3488-
this, token, name, forest.createArgumentsEmpty(fileOffset),
3489-
isPotentiallyConstant: true),
3490-
fileOffset,
3491-
false));
3459+
if (receiver is Generator) {
3460+
push(receiver.buildUnaryOperation(token, name));
34923461
} else {
3493-
bool isSuper = false;
3494-
Expression receiverValue;
3495-
if (receiver is ThisAccessGenerator && receiver.isSuper) {
3496-
ThisAccessGenerator thisAccessorReceiver = receiver;
3497-
isSuper = true;
3498-
receiverValue =
3499-
forest.createThisExpression(thisAccessorReceiver.fileOffset);
3500-
} else {
3501-
receiverValue = toValue(receiver);
3502-
}
3503-
push(buildMethodInvocation(receiverValue, name,
3504-
forest.createArgumentsEmpty(fileOffset), fileOffset,
3505-
// This *could* be a constant expression, we can't know without
3506-
// evaluating [receiver].
3507-
isConstantExpression: !isSuper,
3508-
isSuper: isSuper));
3462+
assert(receiver is Expression);
3463+
push(forest.createUnary(fileOffset, name, receiver));
35093464
}
35103465
}
35113466
}

0 commit comments

Comments
 (0)