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

Side by Side Diff: pkg/front_end/lib/src/fasta/builder/scope.dart

Issue 2739343003: Implement correct label scope. (Closed)
Patch Set: Add method to lookup local labels. 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/kernel/body_builder.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.scope; 5 library fasta.scope;
6 6
7 import 'builder.dart' show Builder, MixedAccessor; 7 import 'builder.dart' show Builder, MixedAccessor;
8 8
9 import '../errors.dart' show internalError; 9 import '../errors.dart' show internalError;
10 10
11 class Scope { 11 class Scope {
12 /// Names declared in this scope. 12 /// Names declared in this scope.
13 final Map<String, Builder> local; 13 final Map<String, Builder> local;
14 14
15 /// The scope that this scope is nested within, or `null` if this is the top 15 /// The scope that this scope is nested within, or `null` if this is the top
16 /// level scope. 16 /// level scope.
17 final Scope parent; 17 final Scope parent;
18 18
19 /// Indicates whether an attempt to declare new names in this scope should 19 /// Indicates whether an attempt to declare new names in this scope should
20 /// succeed. 20 /// succeed.
21 final bool isModifiable; 21 final bool isModifiable;
22 22
23 Map<String, Builder> labels;
24
23 Scope(this.local, this.parent, {this.isModifiable: true}); 25 Scope(this.local, this.parent, {this.isModifiable: true});
24 26
25 Scope createNestedScope({bool isModifiable: true}) { 27 Scope createNestedScope({bool isModifiable: true}) {
26 return new Scope(<String, Builder>{}, this, isModifiable: isModifiable); 28 return new Scope(<String, Builder>{}, this, isModifiable: isModifiable);
27 } 29 }
28 30
29 Builder lookup(String name, int charOffset, Uri fileUri) { 31 Builder lookup(String name, int charOffset, Uri fileUri) {
30 Builder builder = local[name]; 32 Builder builder = local[name];
31 if (builder != null) { 33 if (builder != null) {
32 if (builder.next != null) { 34 if (builder.next != null) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } else { 81 } else {
80 return new AmbiguousBuilder(builder, charOffset, fileUri); 82 return new AmbiguousBuilder(builder, charOffset, fileUri);
81 } 83 }
82 current = current.next; 84 current = current.next;
83 } 85 }
84 assert(getterBuilder != null); 86 assert(getterBuilder != null);
85 assert(setterBuilder != null); 87 assert(setterBuilder != null);
86 return setter ? setterBuilder : getterBuilder; 88 return setter ? setterBuilder : getterBuilder;
87 } 89 }
88 90
91 bool hasLocalLabel(String name) => labels != null && labels.containsKey(name);
92
93 void declareLabel(String name, Builder target) {
94 if (isModifiable) {
95 labels ??= <String, Builder>{};
96 labels[name] = target;
97 } else {
98 internalError("Can't extend an unmodifiable scope.");
99 }
100 }
101
102 Builder lookupLabel(String name) {
103 return (labels == null ? null : labels[name]) ?? parent?.lookupLabel(name);
104 }
105
89 // TODO(ahe): Rename to extend or something. 106 // TODO(ahe): Rename to extend or something.
90 void operator []=(String name, Builder member) { 107 void operator []=(String name, Builder member) {
91 if (isModifiable) { 108 if (isModifiable) {
92 local[name] = member; 109 local[name] = member;
93 } else { 110 } else {
94 internalError("Can't extend an unmodifiable scope."); 111 internalError("Can't extend an unmodifiable scope.");
95 } 112 }
96 } 113 }
97 } 114 }
98 115
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 class AmbiguousBuilder extends Builder { 149 class AmbiguousBuilder extends Builder {
133 final Builder builder; 150 final Builder builder;
134 151
135 AmbiguousBuilder(this.builder, int charOffset, Uri fileUri) 152 AmbiguousBuilder(this.builder, int charOffset, Uri fileUri)
136 : super(null, charOffset, fileUri); 153 : super(null, charOffset, fileUri);
137 154
138 get target => null; 155 get target => null;
139 156
140 bool get hasProblem => true; 157 bool get hasProblem => true;
141 } 158 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698