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

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

Issue 2769813007: Clean up use of identifier context. (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | pkg/front_end/lib/src/fasta/parser/identifier_context.dart » ('j') | 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 library fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import '../parser/parser.dart' show FormalParameterType, optional; 7 import '../parser/parser.dart' show FormalParameterType, optional;
8 8
9 import '../parser/error_kind.dart' show ErrorKind; 9 import '../parser/error_kind.dart' show ErrorKind;
10 10
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 debugEvent("handleIdentifier"); 746 debugEvent("handleIdentifier");
747 String name = token.lexeme; 747 String name = token.lexeme;
748 if (context.isScopeReference) { 748 if (context.isScopeReference) {
749 assert(!inInitializer || 749 assert(!inInitializer ||
750 this.scope == enclosingScope || 750 this.scope == enclosingScope ||
751 this.scope.parent == enclosingScope); 751 this.scope.parent == enclosingScope);
752 // This deals with this kind of initializer: `C(a) : a = a;` 752 // This deals with this kind of initializer: `C(a) : a = a;`
753 Scope scope = inInitializer ? enclosingScope : this.scope; 753 Scope scope = inInitializer ? enclosingScope : this.scope;
754 Builder builder = scope.lookup(name, token.charOffset, uri); 754 Builder builder = scope.lookup(name, token.charOffset, uri);
755 push(builderToFirstExpression(builder, name, token.charOffset)); 755 push(builderToFirstExpression(builder, name, token.charOffset));
756 } else { 756 return;
757 if (constantExpressionRequired) { 757 } else if (context.inDeclaration) {
758 if (context != IdentifierContext.namedArgumentReference && 758 if (context == IdentifierContext.topLevelVariableDeclaration ||
759 context != IdentifierContext.constructorReferenceContinuation && 759 context == IdentifierContext.fieldDeclaration) {
760 context != IdentifierContext.expressionContinuation && 760 constantExpressionRequired = member.isConst;
761 context != IdentifierContext.typeReferenceContinuation &&
762 context != IdentifierContext.localVariableDeclaration &&
763 context !=
764 IdentifierContext
765 .constructorReferenceContinuationAfterTypeArguments) {
766 addCompileTimeError(
767 token.charOffset, "Not a constant expression: $context");
768 }
769 } 761 }
770 push(new Identifier(name)..fileOffset = token.charOffset); 762 } else if (constantExpressionRequired &&
763 !context.allowedInConstantExpression) {
764 addCompileTimeError(
765 token.charOffset, "Not a constant expression: $context");
771 } 766 }
767 push(new Identifier(name)..fileOffset = token.charOffset);
772 } 768 }
773 769
774 @override 770 @override
775 builderToFirstExpression(Builder builder, String name, int charOffset, 771 builderToFirstExpression(Builder builder, String name, int charOffset,
776 {bool isPrefix: false}) { 772 {bool isPrefix: false}) {
777 if (builder == null || (!isInstanceContext && builder.isInstanceMember)) { 773 if (builder == null || (!isInstanceContext && builder.isInstanceMember)) {
778 Name n = new Name(name, library.library); 774 Name n = new Name(name, library.library);
779 if (!isPrefix && isInstanceContext) { 775 if (!isPrefix && isInstanceContext) {
780 assert(builder == null); 776 assert(builder == null);
781 if (constantExpressionRequired) { 777 if (constantExpressionRequired) {
(...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 } else if (node is PrefixBuilder) { 2872 } else if (node is PrefixBuilder) {
2877 return node.name; 2873 return node.name;
2878 } else if (node is ThisAccessor) { 2874 } else if (node is ThisAccessor) {
2879 return node.isSuper ? "super" : "this"; 2875 return node.isSuper ? "super" : "this";
2880 } else if (node is BuilderAccessor) { 2876 } else if (node is BuilderAccessor) {
2881 return node.plainNameForRead; 2877 return node.plainNameForRead;
2882 } else { 2878 } else {
2883 return internalError("Unhandled: ${node.runtimeType}"); 2879 return internalError("Unhandled: ${node.runtimeType}");
2884 } 2880 }
2885 } 2881 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/parser/identifier_context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698