Skip to content

Commit ba2c26b

Browse files
kallentuCommit Queue
authored andcommitted
[cfe] Internal ASTs for dot shorthand exprs and head with no arguments.
Two new internal ASTs for the CFE representing the entire dot shorthand expression (DotShorthand) and the dot shorthand head (DotShorthandPropertyGet) without arguments. Static method invocations/constructor calls will be handled later. Setting up the ASTS first, there's no tests yet. I'll use these in the upcoming CLs. Bug: #59758 Change-Id: I91a052a3c954a00a424426d3be5c3007aaebc775 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410902 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 7ec6bdc commit ba2c26b

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,18 @@ class Forest {
927927
return new IfCaseStatement(expression, patternGuard, then, otherwise)
928928
..fileOffset = fileOffset;
929929
}
930+
931+
// Coverage-ignore(suite): Not run.
932+
DotShorthand createDotShorthandContext(
933+
int fileOffset, Expression innerExpression) {
934+
return new DotShorthand(innerExpression)..fileOffset = fileOffset;
935+
}
936+
937+
// Coverage-ignore(suite): Not run.
938+
DotShorthandPropertyGet createDotShorthandPropertyGet(
939+
int fileOffset, Name name) {
940+
return new DotShorthandPropertyGet(name)..fileOffset = fileOffset;
941+
}
930942
}
931943

932944
class _VariablesDeclaration extends AuxiliaryStatement {

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,3 +3221,59 @@ class ExtensionTypeRepresentationFieldInitializer extends InternalInitializer {
32213221
String toString() =>
32223222
'ExtensionTypeRepresentationFieldInitializer(${toStringInternal()})';
32233223
}
3224+
3225+
// Coverage-ignore(suite): Not run.
3226+
/// Internal expression for a dot shorthand.
3227+
///
3228+
/// This node wraps around the [innerExpression] and indicates to the
3229+
/// [InferenceVisitor] that we need to save the context type of the expression.
3230+
class DotShorthand extends InternalExpression {
3231+
/// The entire dot shorthand expression (e.g. `.zero` or `.parse(input)`).
3232+
Expression innerExpression;
3233+
3234+
DotShorthand(this.innerExpression);
3235+
3236+
@override
3237+
ExpressionInferenceResult acceptInference(
3238+
InferenceVisitorImpl visitor, DartType typeContext) {
3239+
return visitor.visitDotShorthand(this, typeContext);
3240+
}
3241+
3242+
@override
3243+
String toString() {
3244+
return "DotShorthand(${toStringInternal()})";
3245+
}
3246+
3247+
@override
3248+
void toTextInternal(AstPrinter printer) {
3249+
printer.writeExpression(innerExpression);
3250+
}
3251+
}
3252+
3253+
// Coverage-ignore(suite): Not run.
3254+
/// Internal expression for a dot shorthand head with no arguments.
3255+
/// (e.g. `.zero`).
3256+
///
3257+
/// This node could represent a shorthand of a static get or a tearoff.
3258+
class DotShorthandPropertyGet extends InternalExpression {
3259+
Name name;
3260+
3261+
DotShorthandPropertyGet(this.name);
3262+
3263+
@override
3264+
ExpressionInferenceResult acceptInference(
3265+
InferenceVisitorImpl visitor, DartType typeContext) {
3266+
return visitor.visitDotShorthandPropertyGet(this, typeContext);
3267+
}
3268+
3269+
@override
3270+
String toString() {
3271+
return "DotShorthandPropertyGet(${toStringInternal()})";
3272+
}
3273+
3274+
@override
3275+
void toTextInternal(AstPrinter printer) {
3276+
printer.write('.');
3277+
printer.writeName(name);
3278+
}
3279+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12103,6 +12103,20 @@ class InferenceVisitorImpl extends InferenceVisitorBase
1210312103
StatementInferenceResult visitAuxiliaryStatement(AuxiliaryStatement node) {
1210412104
return _unhandledStatement(node);
1210512105
}
12106+
12107+
// Coverage-ignore(suite): Not run.
12108+
ExpressionInferenceResult visitDotShorthand(
12109+
DotShorthand node, DartType typeContext) {
12110+
// TODO(kallentu): Implementation needed for dot shorthands.
12111+
return _unhandledExpression(node, typeContext);
12112+
}
12113+
12114+
// Coverage-ignore(suite): Not run.
12115+
ExpressionInferenceResult visitDotShorthandPropertyGet(
12116+
DotShorthandPropertyGet node, DartType typeContext) {
12117+
// TODO(kallentu): Implementation needed for dot shorthands.
12118+
return _unhandledExpression(node, typeContext);
12119+
}
1210612120
}
1210712121

1210812122
/// Offset and type information collection in [InferenceVisitor.inferMapEntry].

pkg/front_end/test/coverage_suite_expected.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
590590
),
591591
// 100.0%.
592592
"package:front_end/src/kernel/body_builder.dart": (
593-
hitCount: 7192,
593+
hitCount: 7188,
594594
missCount: 0,
595595
),
596596
// 100.0%.

0 commit comments

Comments
 (0)