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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2804843003: Fix some crashes. (Closed)
Patch Set: 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
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 library fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import '../fasta_codes.dart' 7 import '../fasta_codes.dart'
8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody;
9 9
10 import '../parser/parser.dart' show FormalParameterType, optional; 10 import '../parser/parser.dart' show FormalParameterType, optional;
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 } else if (context.inDeclaration) { 724 } else if (context.inDeclaration) {
725 if (context == IdentifierContext.topLevelVariableDeclaration || 725 if (context == IdentifierContext.topLevelVariableDeclaration ||
726 context == IdentifierContext.fieldDeclaration) { 726 context == IdentifierContext.fieldDeclaration) {
727 constantExpressionRequired = member.isConst; 727 constantExpressionRequired = member.isConst;
728 } 728 }
729 } else if (constantExpressionRequired && 729 } else if (constantExpressionRequired &&
730 !context.allowedInConstantExpression) { 730 !context.allowedInConstantExpression) {
731 addCompileTimeError( 731 addCompileTimeError(
732 token.charOffset, "Not a constant expression: $context"); 732 token.charOffset, "Not a constant expression: $context");
733 } 733 }
734 push(new Identifier(name)..fileOffset = token.charOffset); 734 push(new Identifier(name, token.charOffset));
735 } 735 }
736 736
737 /// Look up [name] in [scope] using [charOffset] to report any 737 /// Look up [name] in [scope] using [charOffset] to report any
738 /// problems. [isQualified] should be true if [name] is a qualified access 738 /// problems. [isQualified] should be true if [name] is a qualified access
739 /// (which implies that it shouldn't be turned into a [ThisPropertyAccessor] 739 /// (which implies that it shouldn't be turned into a [ThisPropertyAccessor]
740 /// if the name doesn't resolve in the scope). 740 /// if the name doesn't resolve in the scope).
741 @override 741 @override
742 scopeLookup(Scope scope, String name, int charOffset, 742 scopeLookup(Scope scope, String name, int charOffset,
743 {bool isQualified: false}) { 743 {bool isQualified: false}) {
744 Builder builder = scope.lookup(name, charOffset, uri); 744 Builder builder = scope.lookup(name, charOffset, uri);
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 push(formals.toFunctionType(returnType)); 1457 push(formals.toFunctionType(returnType));
1458 push(name); 1458 push(name);
1459 functionNestingLevel--; 1459 functionNestingLevel--;
1460 } 1460 }
1461 1461
1462 @override 1462 @override
1463 void handleValuedFormalParameter(Token equals, Token token) { 1463 void handleValuedFormalParameter(Token equals, Token token) {
1464 debugEvent("ValuedFormalParameter"); 1464 debugEvent("ValuedFormalParameter");
1465 Expression initializer = popForValue(); 1465 Expression initializer = popForValue();
1466 Identifier name = pop(); 1466 Identifier name = pop();
1467 push(new InitializedIdentifier(name.name, initializer)); 1467 push(new InitializedIdentifier(name.name, initializer, name.fileOffset));
1468 } 1468 }
1469 1469
1470 @override 1470 @override
1471 void handleFormalParameterWithoutValue(Token token) { 1471 void handleFormalParameterWithoutValue(Token token) {
1472 debugEvent("FormalParameterWithoutValue"); 1472 debugEvent("FormalParameterWithoutValue");
1473 } 1473 }
1474 1474
1475 @override 1475 @override
1476 void endFormalParameters(int count, Token beginToken, Token endToken) { 1476 void endFormalParameters(int count, Token beginToken, Token endToken) {
1477 debugEvent("FormalParameters"); 1477 debugEvent("FormalParameters");
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 if (type is List) { 1655 if (type is List) {
1656 var prefix = type[0]; 1656 var prefix = type[0];
1657 identifier = type[1]; 1657 identifier = type[1];
1658 if (prefix is PrefixBuilder) { 1658 if (prefix is PrefixBuilder) {
1659 type = scopeLookup(prefix.exports, identifier.name, start.charOffset, 1659 type = scopeLookup(prefix.exports, identifier.name, start.charOffset,
1660 isQualified: true); 1660 isQualified: true);
1661 identifier = null; 1661 identifier = null;
1662 } else if (prefix is ClassBuilder) { 1662 } else if (prefix is ClassBuilder) {
1663 type = prefix; 1663 type = prefix;
1664 } else { 1664 } else {
1665 type = new Identifier(start.lexeme)..fileOffset = start.charOffset; 1665 type = new Identifier(start.lexeme, start.charOffset);
1666 } 1666 }
1667 } 1667 }
1668 String name; 1668 String name;
1669 if (identifier != null && suffix != null) { 1669 if (identifier != null && suffix != null) {
1670 name = "${identifier.name}.${suffix.name}"; 1670 name = "${identifier.name}.${suffix.name}";
1671 } else if (identifier != null) { 1671 } else if (identifier != null) {
1672 name = identifier.name; 1672 name = identifier.name;
1673 } else if (suffix != null) { 1673 } else if (suffix != null) {
1674 name = suffix.name; 1674 name = suffix.name;
1675 } else { 1675 } else {
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 } 2387 }
2388 2388
2389 @override 2389 @override
2390 void handleOperator(Token token) { 2390 void handleOperator(Token token) {
2391 debugEvent("Operator"); 2391 debugEvent("Operator");
2392 push(new Operator(token.stringValue)..fileOffset = token.charOffset); 2392 push(new Operator(token.stringValue)..fileOffset = token.charOffset);
2393 } 2393 }
2394 2394
2395 @override 2395 @override
2396 void handleSymbolVoid(Token token) { 2396 void handleSymbolVoid(Token token) {
2397 logEvent("SymbolVoid"); 2397 debugEvent("SymbolVoid");
2398 push(new Identifier(token.stringValue, token.charOffset));
2398 } 2399 }
2399 2400
2400 dynamic addCompileTimeError(int charOffset, String message, 2401 dynamic addCompileTimeError(int charOffset, String message,
2401 {bool silent: false}) { 2402 {bool silent: false}) {
2402 // TODO(ahe): If constantExpressionRequired is set, set it to false to 2403 // TODO(ahe): If constantExpressionRequired is set, set it to false to
2403 // avoid a long list of errors. 2404 // avoid a long list of errors.
2404 return library.addCompileTimeError(charOffset, message, fileUri: uri); 2405 return library.addCompileTimeError(charOffset, message, fileUri: uri);
2405 } 2406 }
2406 2407
2407 @override 2408 @override
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 @override 2442 @override
2442 void debugEvent(String name) { 2443 void debugEvent(String name) {
2443 // printEvent(name); 2444 // printEvent(name);
2444 } 2445 }
2445 } 2446 }
2446 2447
2447 // TODO(ahe): Shouldn't need to be an expression. 2448 // TODO(ahe): Shouldn't need to be an expression.
2448 class Identifier extends InvalidExpression { 2449 class Identifier extends InvalidExpression {
2449 final String name; 2450 final String name;
2450 2451
2451 Identifier(this.name); 2452 Identifier(this.name, int charOffset) {
2453 fileOffset = charOffset;
2454 }
2452 2455
2453 Expression get initializer => null; 2456 Expression get initializer => null;
2454 2457
2455 String toString() => "identifier($name)"; 2458 String toString() => "identifier($name)";
2456 } 2459 }
2457 2460
2458 // TODO(ahe): Shouldn't need to be an expression. 2461 // TODO(ahe): Shouldn't need to be an expression.
2459 class Operator extends InvalidExpression { 2462 class Operator extends InvalidExpression {
2460 final String name; 2463 final String name;
2461 2464
2462 Operator(this.name); 2465 Operator(this.name);
2463 2466
2464 String toString() => "operator($name)"; 2467 String toString() => "operator($name)";
2465 } 2468 }
2466 2469
2467 class InitializedIdentifier extends Identifier { 2470 class InitializedIdentifier extends Identifier {
2468 final Expression initializer; 2471 final Expression initializer;
2469 2472
2470 InitializedIdentifier(String name, this.initializer) : super(name); 2473 InitializedIdentifier(String name, this.initializer, int charOffset)
2474 : super(name, charOffset);
2471 2475
2472 String toString() => "initialized-identifier($name, $initializer)"; 2476 String toString() => "initialized-identifier($name, $initializer)";
2473 } 2477 }
2474 2478
2475 // TODO(ahe): Shouldn't need to be an expression. 2479 // TODO(ahe): Shouldn't need to be an expression.
2476 class Label extends InvalidExpression { 2480 class Label extends InvalidExpression {
2477 String name; 2481 String name;
2478 2482
2479 Label(this.name); 2483 Label(this.name);
2480 2484
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
2900 } else if (node is PrefixBuilder) { 2904 } else if (node is PrefixBuilder) {
2901 return node.name; 2905 return node.name;
2902 } else if (node is ThisAccessor) { 2906 } else if (node is ThisAccessor) {
2903 return node.isSuper ? "super" : "this"; 2907 return node.isSuper ? "super" : "this";
2904 } else if (node is FastaAccessor) { 2908 } else if (node is FastaAccessor) {
2905 return node.plainNameForRead; 2909 return node.plainNameForRead;
2906 } else { 2910 } else {
2907 return internalError("Unhandled: ${node.runtimeType}"); 2911 return internalError("Unhandled: ${node.runtimeType}");
2908 } 2912 }
2909 } 2913 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/fasta.dart ('k') | pkg/front_end/lib/src/fasta/source/source_loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698