Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: pkg/kernel/lib/ast.dart

Issue 2768533002: Fasta type inference prototype #2
Patch Set: Rework atop 415c868589d02e98eb839f48150f4203d5cecdb0 Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/front_end/test/fasta/testing.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// ----------------------------------------------------------------------- 5 /// -----------------------------------------------------------------------
6 /// ERROR HANDLING 6 /// ERROR HANDLING
7 /// ----------------------------------------------------------------------- 7 /// -----------------------------------------------------------------------
8 /// 8 ///
9 /// As a rule of thumb, errors that can be detected statically are handled by 9 /// As a rule of thumb, errors that can be detected statically are handled by
10 /// the frontend, typically by translating the erroneous code into a 'throw' or 10 /// the frontend, typically by translating the erroneous code into a 'throw' or
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 1422
1423 visitChildren(Visitor v) {} 1423 visitChildren(Visitor v) {}
1424 transformChildren(Transformer v) {} 1424 transformChildren(Transformer v) {}
1425 } 1425 }
1426 1426
1427 /// Read a local variable, a local function, or a function parameter. 1427 /// Read a local variable, a local function, or a function parameter.
1428 class VariableGet extends Expression { 1428 class VariableGet extends Expression {
1429 VariableDeclaration variable; 1429 VariableDeclaration variable;
1430 DartType promotedType; // Null if not promoted. 1430 DartType promotedType; // Null if not promoted.
1431 1431
1432 VariableGet(this.variable, [this.promotedType]); 1432 VariableGet(VariableDeclaration variable, [DartType promotedType])
1433 : this.forMixin(variable, promotedType);
1434
1435 VariableGet.forMixin(this.variable, this.promotedType);
1433 1436
1434 DartType getStaticType(TypeEnvironment types) { 1437 DartType getStaticType(TypeEnvironment types) {
1435 return promotedType ?? variable.type; 1438 return promotedType ?? variable.type;
1436 } 1439 }
1437 1440
1438 accept(ExpressionVisitor v) => v.visitVariableGet(this); 1441 accept(ExpressionVisitor v) => v.visitVariableGet(this);
1439 accept1(ExpressionVisitor1 v, arg) => v.visitVariableGet(this, arg); 1442 accept1(ExpressionVisitor1 v, arg) => v.visitVariableGet(this, arg);
1440 1443
1441 visitChildren(Visitor v) { 1444 visitChildren(Visitor v) {
1442 promotedType?.accept(v); 1445 promotedType?.accept(v);
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 expression?.parent = this; 2526 expression?.parent = this;
2524 } 2527 }
2525 } 2528 }
2526 } 2529 }
2527 2530
2528 class ListLiteral extends Expression { 2531 class ListLiteral extends Expression {
2529 bool isConst; 2532 bool isConst;
2530 DartType typeArgument; // Not null, defaults to DynamicType. 2533 DartType typeArgument; // Not null, defaults to DynamicType.
2531 final List<Expression> expressions; 2534 final List<Expression> expressions;
2532 2535
2533 ListLiteral(this.expressions, 2536 ListLiteral(List<Expression> expressions,
2534 {this.typeArgument: const DynamicType(), this.isConst: false}) { 2537 {DartType typeArgument: const DynamicType(), bool isConst: false})
2538 : this.forMixin(expressions, typeArgument, isConst);
2539
2540 ListLiteral.forMixin(this.expressions, this.typeArgument, this.isConst) {
2535 assert(typeArgument != null); 2541 assert(typeArgument != null);
2536 setParents(expressions, this); 2542 setParents(expressions, this);
2537 } 2543 }
2538 2544
2539 DartType getStaticType(TypeEnvironment types) { 2545 DartType getStaticType(TypeEnvironment types) {
2540 return types.literalListType(typeArgument); 2546 return types.literalListType(typeArgument);
2541 } 2547 }
2542 2548
2543 accept(ExpressionVisitor v) => v.visitListLiteral(this); 2549 accept(ExpressionVisitor v) => v.visitListLiteral(this);
2544 accept1(ExpressionVisitor1 v, arg) => v.visitListLiteral(this, arg); 2550 accept1(ExpressionVisitor1 v, arg) => v.visitListLiteral(this, arg);
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 if (otherwise != null) { 3171 if (otherwise != null) {
3166 otherwise = otherwise.accept(v); 3172 otherwise = otherwise.accept(v);
3167 otherwise?.parent = this; 3173 otherwise?.parent = this;
3168 } 3174 }
3169 } 3175 }
3170 } 3176 }
3171 3177
3172 class ReturnStatement extends Statement { 3178 class ReturnStatement extends Statement {
3173 Expression expression; // May be null. 3179 Expression expression; // May be null.
3174 3180
3175 ReturnStatement([this.expression]) { 3181 ReturnStatement([Expression expression]) : this.forMixin(expression);
3182
3183 ReturnStatement.forMixin(this.expression) {
3176 expression?.parent = this; 3184 expression?.parent = this;
3177 } 3185 }
3178 3186
3179 accept(StatementVisitor v) => v.visitReturnStatement(this); 3187 accept(StatementVisitor v) => v.visitReturnStatement(this);
3180 accept1(StatementVisitor1 v, arg) => v.visitReturnStatement(this, arg); 3188 accept1(StatementVisitor1 v, arg) => v.visitReturnStatement(this, arg);
3181 3189
3182 visitChildren(Visitor v) { 3190 visitChildren(Visitor v) {
3183 expression?.accept(v); 3191 expression?.accept(v);
3184 } 3192 }
3185 3193
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
3354 int flags = 0; 3362 int flags = 0;
3355 DartType type; // Not null, defaults to dynamic. 3363 DartType type; // Not null, defaults to dynamic.
3356 InferredValue inferredValue; // May be null. 3364 InferredValue inferredValue; // May be null.
3357 3365
3358 /// For locals, this is the initial value. 3366 /// For locals, this is the initial value.
3359 /// For parameters, this is the default value. 3367 /// For parameters, this is the default value.
3360 /// 3368 ///
3361 /// Should be null in other cases. 3369 /// Should be null in other cases.
3362 Expression initializer; // May be null. 3370 Expression initializer; // May be null.
3363 3371
3364 VariableDeclaration(this.name, 3372 VariableDeclaration(String name,
3365 {this.initializer, 3373 {Expression initializer,
3366 this.type: const DynamicType(), 3374 DartType type: const DynamicType(),
3367 this.inferredValue, 3375 InferredValue inferredValue,
3368 bool isFinal: false, 3376 bool isFinal: false,
3369 bool isConst: false}) { 3377 bool isConst: false})
3378 : this.forMixin(name, initializer, type, inferredValue, isFinal, isConst);
3379
3380 VariableDeclaration.forMixin(this.name, this.initializer, this.type,
3381 this.inferredValue, bool isFinal, bool isConst) {
3370 assert(type != null); 3382 assert(type != null);
3371 initializer?.parent = this; 3383 initializer?.parent = this;
3372 this.isFinal = isFinal; 3384 this.isFinal = isFinal;
3373 this.isConst = isConst; 3385 this.isConst = isConst;
3374 } 3386 }
3375 3387
3376 /// Creates a synthetic variable with the given expression as initializer. 3388 /// Creates a synthetic variable with the given expression as initializer.
3377 VariableDeclaration.forValue(this.initializer, 3389 VariableDeclaration.forValue(this.initializer,
3378 {bool isFinal: true, 3390 {bool isFinal: true,
3379 bool isConst: false, 3391 bool isConst: false,
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
4100 /// library has not been assigned a canonical name yet. 4112 /// library has not been assigned a canonical name yet.
4101 /// 4113 ///
4102 /// Returns `null` if the library is `null`. 4114 /// Returns `null` if the library is `null`.
4103 CanonicalName getCanonicalNameOfLibrary(Library library) { 4115 CanonicalName getCanonicalNameOfLibrary(Library library) {
4104 if (library == null) return null; 4116 if (library == null) return null;
4105 if (library.canonicalName == null) { 4117 if (library.canonicalName == null) {
4106 throw '$library has no canonical name'; 4118 throw '$library has no canonical name';
4107 } 4119 }
4108 return library.canonicalName; 4120 return library.canonicalName;
4109 } 4121 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/fasta/testing.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698