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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/builder/scope.dart
diff --git a/pkg/front_end/lib/src/fasta/builder/scope.dart b/pkg/front_end/lib/src/fasta/builder/scope.dart
index 73560239088d53f87ef8df5b6923d2df30baff8b..159d2ba66905d6c0076b4c7c0191503fe5ab7811 100644
--- a/pkg/front_end/lib/src/fasta/builder/scope.dart
+++ b/pkg/front_end/lib/src/fasta/builder/scope.dart
@@ -20,6 +20,8 @@ class Scope {
/// succeed.
final bool isModifiable;
+ Map<String, Builder> labels;
+
Scope(this.local, this.parent, {this.isModifiable: true});
Scope createNestedScope({bool isModifiable: true}) {
@@ -86,6 +88,21 @@ class Scope {
return setter ? setterBuilder : getterBuilder;
}
+ bool hasLocalLabel(String name) => labels != null && labels.containsKey(name);
+
+ void declareLabel(String name, Builder target) {
+ if (isModifiable) {
+ labels ??= <String, Builder>{};
+ labels[name] = target;
+ } else {
+ internalError("Can't extend an unmodifiable scope.");
+ }
+ }
+
+ Builder lookupLabel(String name) {
+ return (labels == null ? null : labels[name]) ?? parent?.lookupLabel(name);
+ }
+
// TODO(ahe): Rename to extend or something.
void operator []=(String name, Builder member) {
if (isModifiable) {
« 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