Skip to content

Commit cc14696

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Add internal ast nodes for constructor/static/super invocation
This is a step towards ensuring that ArgumentImpl is always used from the body builder, so that ArgumentsImpl can be fully separated from Arguments. Change-Id: Id76d02543c36448e55b6e878d11a64513dbfde7b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448940 Reviewed-by: Erik Ernst <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent ea4afe3 commit cc14696

19 files changed

+274
-138
lines changed

pkg/front_end/lib/src/fragment/enum_element.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ class EnumElementDeclaration
327327
);
328328
MemberBuilder? constructorBuilder = result?.getable;
329329

330-
ArgumentsImpl arguments;
331330
List<Expression> enumSyntheticArguments = <Expression>[
332331
new IntLiteral(elementIndex),
333332
new StringLiteral(constant),
@@ -373,6 +372,7 @@ class EnumElementDeclaration
373372
);
374373
bodyBuilder.constantContext = ConstantContext.inferred;
375374

375+
ArgumentsImpl arguments;
376376
if (token != null) {
377377
arguments = bodyBuilder.parseArguments(token);
378378
// We pass `true` for [allowFurtherDelays] here because the members of
@@ -433,8 +433,7 @@ class EnumElementDeclaration
433433
_field!.initializer = initializer..parent = _field;
434434
}
435435
} else {
436-
arguments = new ArgumentsImpl(enumSyntheticArguments);
437-
setParents(enumSyntheticArguments, arguments);
436+
Arguments arguments = new Arguments(enumSyntheticArguments);
438437
if (constructorBuilder == null ||
439438
constructorBuilder is! SourceConstructorBuilder ||
440439
!constructorBuilder.isConst) {

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ class BodyBuilder extends StackListenerImpl
12621262
initializers = <Initializer>[node];
12631263
} else if (node is Generator) {
12641264
initializers = node.buildFieldInitializer(initializedFields);
1265-
} else if (node is ConstructorInvocation) {
1265+
} else if (node is InternalConstructorInvocation) {
12661266
// Coverage-ignore-block(suite): Not run.
12671267
initializers = <Initializer>[
12681268
// TODO(jensj): Does this offset make sense?
@@ -7248,8 +7248,11 @@ class BodyBuilder extends StackListenerImpl
72487248
}
72497249
Expression node;
72507250
if (typeAliasBuilder == null) {
7251-
node = new ConstructorInvocation(target, arguments, isConst: isConst)
7252-
..fileOffset = fileOffset;
7251+
node = new InternalConstructorInvocation(
7252+
target,
7253+
arguments,
7254+
isConst: isConst,
7255+
)..fileOffset = fileOffset;
72537256
libraryBuilder.checkBoundsInConstructorInvocation(
72547257
constructor: target,
72557258
typeArguments: arguments.types,
@@ -7326,7 +7329,7 @@ class BodyBuilder extends StackListenerImpl
73267329
@override
73277330
Expression buildStaticInvocation({
73287331
required Procedure target,
7329-
required Arguments arguments,
7332+
required ArgumentsImpl arguments,
73307333
required int fileOffset,
73317334
}) {
73327335
Expression? result = checkStaticArguments(
@@ -7338,7 +7341,7 @@ class BodyBuilder extends StackListenerImpl
73387341
return result;
73397342
}
73407343

7341-
return new StaticInvocation(target, arguments, isConst: false)
7344+
return new InternalStaticInvocation(target.name, target, arguments)
73427345
..fileOffset = fileOffset;
73437346
}
73447347

@@ -11012,14 +11015,12 @@ class BodyBuilder extends StackListenerImpl
1101211015
);
1101311016
MemberBuilder constructor = libraryBuilder.loader
1101411017
.getDuplicatedFieldInitializerError();
11015-
Expression invocation = buildConstructorInvocation(
11016-
constructor.invokeTarget!,
11017-
forest.createArguments(assignmentOffset, <Expression>[
11018-
forest.createStringLiteral(assignmentOffset, name),
11019-
]),
11020-
constness: Constness.explicitNew,
11021-
fileOffset: assignmentOffset,
11022-
);
11018+
Expression invocation = new ConstructorInvocation(
11019+
constructor.invokeTarget as Constructor,
11020+
new Arguments([
11021+
new StringLiteral(name)..fileOffset = assignmentOffset,
11022+
])..fileOffset = assignmentOffset,
11023+
)..fileOffset = assignmentOffset;
1102311024
return <Initializer>[
1102411025
builder.buildErroneousInitializer(
1102511026
forest.createThrow(assignmentOffset, invocation),
@@ -11427,7 +11428,7 @@ class BodyBuilder extends StackListenerImpl
1142711428
kind: UnresolvedKind.Method,
1142811429
);
1142911430
} else if (target is Procedure && !target.isAccessor) {
11430-
return new SuperMethodInvocation(name, arguments, target)
11431+
return new InternalSuperMethodInvocation(name, arguments, target)
1143111432
..fileOffset = offset;
1143211433
}
1143311434
if (isImplicitCall) {

pkg/front_end/lib/src/kernel/constant_evaluator.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6751,19 +6751,21 @@ abstract class ErrorReporter {
67516751
bool get hasSeenError;
67526752
}
67536753

6754-
// Coverage-ignore(suite): Not run.
67556754
class SimpleErrorReporter implements ErrorReporter {
67566755
const SimpleErrorReporter();
67576756

67586757
@override
6758+
// Coverage-ignore(suite): Not run.
67596759
bool get supportsTrackingReportedErrors => false;
67606760

67616761
@override
6762+
// Coverage-ignore(suite): Not run.
67626763
bool get hasSeenError {
67636764
return unsupported("SimpleErrorReporter.hasSeenError", -1, null);
67646765
}
67656766

67666767
@override
6768+
// Coverage-ignore(suite): Not run.
67676769
void report(LocatedMessage message, [List<LocatedMessage>? context]) {
67686770
_report(message);
67696771
if (context != null) {
@@ -6773,10 +6775,12 @@ class SimpleErrorReporter implements ErrorReporter {
67736775
}
67746776
}
67756777

6778+
// Coverage-ignore(suite): Not run.
67766779
void _report(LocatedMessage message) {
67776780
reportMessage(message.uri, message.charOffset, message.problemMessage);
67786781
}
67796782

6783+
// Coverage-ignore(suite): Not run.
67806784
void reportMessage(Uri? uri, int offset, String message) {
67816785
io.exitCode = 42;
67826786
io.stderr.writeln('$uri:$offset Constant evaluation error: $message');

pkg/front_end/lib/src/kernel/forest.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,13 +777,13 @@ class Forest {
777777
)..fileOffset = fileOffset;
778778
}
779779

780-
SuperMethodInvocation createSuperMethodInvocation(
780+
Expression createSuperMethodInvocation(
781781
int fileOffset,
782782
Name name,
783783
Procedure procedure,
784784
ArgumentsImpl arguments,
785785
) {
786-
return new SuperMethodInvocation(name, arguments, procedure)
786+
return new InternalSuperMethodInvocation(name, arguments, procedure)
787787
..fileOffset = fileOffset;
788788
}
789789

pkg/front_end/lib/src/kernel/internal_ast.dart

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4449,15 +4449,120 @@ class DotShorthandPropertyGet extends InternalExpression {
44494449
return visitor.visitDotShorthandPropertyGet(this, typeContext);
44504450
}
44514451

4452+
@override
4453+
// Coverage-ignore(suite): Not run.
4454+
void toTextInternal(AstPrinter printer) {
4455+
printer.write('.');
4456+
printer.writeName(name);
4457+
}
4458+
44524459
@override
44534460
String toString() {
44544461
return "DotShorthandPropertyGet(${toStringInternal()})";
44554462
}
4463+
}
4464+
4465+
class InternalConstructorInvocation extends InternalExpression {
4466+
final Constructor target;
4467+
final ArgumentsImpl arguments;
4468+
final bool isConst;
4469+
4470+
InternalConstructorInvocation(
4471+
this.target,
4472+
this.arguments, {
4473+
required this.isConst,
4474+
}) {
4475+
arguments.parent = this;
4476+
}
4477+
4478+
@override
4479+
ExpressionInferenceResult acceptInference(
4480+
InferenceVisitorImpl visitor,
4481+
DartType typeContext,
4482+
) {
4483+
return visitor.visitInternalConstructorInvocation(this, typeContext);
4484+
}
4485+
4486+
@override
4487+
// Coverage-ignore(suite): Not run.
4488+
void toTextInternal(AstPrinter printer) {
4489+
if (isConst) {
4490+
printer.write('const ');
4491+
} else {
4492+
printer.write('new ');
4493+
}
4494+
printer.writeClassName(target.enclosingClass.reference);
4495+
printer.writeTypeArguments(arguments.types);
4496+
if (target.name.text.isNotEmpty) {
4497+
printer.write('.');
4498+
printer.write(target.name.text);
4499+
}
4500+
arguments.toTextInternal(printer, includeTypeArguments: false);
4501+
}
4502+
4503+
@override
4504+
String toString() {
4505+
return "InternalConstructorInvocation(${toStringInternal()})";
4506+
}
4507+
}
4508+
4509+
class InternalStaticInvocation extends InternalExpression {
4510+
final Name name;
4511+
final Procedure target;
4512+
final ArgumentsImpl arguments;
4513+
4514+
InternalStaticInvocation(this.name, this.target, this.arguments) {
4515+
arguments.parent = this;
4516+
}
4517+
4518+
@override
4519+
ExpressionInferenceResult acceptInference(
4520+
InferenceVisitorImpl visitor,
4521+
DartType typeContext,
4522+
) {
4523+
return visitor.visitInternalStaticInvocation(this, typeContext);
4524+
}
44564525

44574526
@override
44584527
// Coverage-ignore(suite): Not run.
44594528
void toTextInternal(AstPrinter printer) {
4460-
printer.write('.');
44614529
printer.writeName(name);
4530+
arguments.toTextInternal(printer);
4531+
}
4532+
4533+
@override
4534+
String toString() {
4535+
return "InternalStaticInvocation(${toStringInternal()})";
4536+
}
4537+
}
4538+
4539+
class InternalSuperMethodInvocation extends InternalExpression {
4540+
final Name name;
4541+
final Procedure target;
4542+
final ArgumentsImpl arguments;
4543+
4544+
InternalSuperMethodInvocation(this.name, this.arguments, this.target) {
4545+
arguments.parent = this;
4546+
}
4547+
4548+
@override
4549+
ExpressionInferenceResult acceptInference(
4550+
InferenceVisitorImpl visitor,
4551+
DartType typeContext,
4552+
) {
4553+
return visitor.visitInternalSuperMethodInvocation(this, typeContext);
4554+
}
4555+
4556+
@override
4557+
// Coverage-ignore(suite): Not run.
4558+
void toTextInternal(AstPrinter printer) {
4559+
printer.write('super.');
4560+
printer.writeName(name);
4561+
arguments.toTextInternal(printer);
4562+
}
4563+
4564+
@override
4565+
String toString() {
4566+
return "InternalSuperMethodInvocation(${toStringInternal()})";
44624567
}
44634568
}

pkg/front_end/lib/src/type_inference/external_ast_helper.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ StaticInvocation createStaticInvocation(
3333
..fileOffset = fileOffset;
3434
}
3535

36+
/// Creates a super method invocation of [target] with the given arguments.
37+
SuperMethodInvocation createSuperMethodInvocation(
38+
Name name,
39+
Procedure target,
40+
Arguments arguments, {
41+
required int fileOffset,
42+
}) {
43+
return new SuperMethodInvocation(name, arguments, target)
44+
..fileOffset = fileOffset;
45+
}
46+
3647
/// Creates a `== null` test on [expression].
3748
EqualsNull createEqualsNull(Expression expression, {required int fileOffset}) {
3849
return new EqualsNull(expression)..fileOffset = fileOffset;

pkg/front_end/lib/src/type_inference/inference_results.dart

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,7 @@ class SuccessfulInferenceResult implements InvocationInferenceResult {
174174
assert(
175175
expression is InvocationExpression || expression is InvalidExpression,
176176
);
177-
if (expression is FactoryConstructorInvocation) {
178-
// Coverage-ignore-block(suite): Not run.
179-
return InvocationInferenceResult._insertHoistedExpressions(
180-
expression,
181-
hoistedArguments,
182-
);
183-
} else if (expression is TypeAliasedConstructorInvocation) {
184-
// Coverage-ignore-block(suite): Not run.
185-
return InvocationInferenceResult._insertHoistedExpressions(
186-
expression,
187-
hoistedArguments,
188-
);
189-
} else if (expression is TypeAliasedFactoryInvocation) {
190-
// Coverage-ignore-block(suite): Not run.
191-
return InvocationInferenceResult._insertHoistedExpressions(
192-
expression,
193-
hoistedArguments,
194-
);
195-
} else if (expression is ConstructorInvocation) {
177+
if (expression is ConstructorInvocation) {
196178
return InvocationInferenceResult._insertHoistedExpressions(
197179
expression,
198180
hoistedArguments,

0 commit comments

Comments
 (0)