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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.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 | « pkg/front_end/lib/src/fasta/builder/scope.dart ('k') | tests/co19/co19-kernel.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/kernel/body_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index 5112edbd1f0d9b870c6392f3fe2dfad52f40df3f..b460e20609e4e450d9450d397a1c7d61ba9b413f 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -1927,7 +1927,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
enterLocalScope();
LabelTarget target = new LabelTarget(member, token.charOffset);
for (Label label in labels) {
- scope[label.name] = target;
+ scope.declareLabel(label.name, target);
}
push(target);
}
@@ -2030,11 +2030,10 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
assert(scope == switchScope);
for (Label label in labels) {
- Builder existing = scope.local[label.name];
- if (existing == null) {
- scope[label.name] = createGotoTarget(firstToken.charOffset);
- } else {
+ if (scope.hasLocalLabel(label.name)) {
// TODO(ahe): Should validate this is a goto target and not duplicated.
+ } else {
+ scope.declareLabel(label.name, createGotoTarget(firstToken.charOffset));
}
}
push(expressions);
@@ -2074,8 +2073,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
List<Label> labels = pop();
SwitchCase current = cases[i] = pop();
for (Label label in labels) {
- JumpTarget target =
- switchScope.lookup(label.name, label.fileOffset, uri);
+ JumpTarget target = switchScope.lookupLabel(label.name);
if (target != null) {
target.resolveGotos(current);
}
@@ -2109,7 +2107,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
if (hasTarget) {
Identifier identifier = pop();
name = identifier.name;
- target = scope.lookup(identifier.name, breakKeyword.next.charOffset, uri);
+ target = scope.lookupLabel(identifier.name);
}
if (target == null && name == null) {
push(compileTimeErrorInLoopOrSwitch = buildCompileTimeErrorStatement(
@@ -2136,8 +2134,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
if (hasTarget) {
Identifier identifier = pop();
name = identifier.name;
- target =
- scope.lookup(identifier.name, continueKeyword.next.charOffset, uri);
+ target = scope.lookupLabel(identifier.name);
if (target != null && target is! JumpTarget) {
push(compileTimeErrorInLoopOrSwitch = buildCompileTimeErrorStatement(
"Target of continue must be a label.", continueKeyword.charOffset));
@@ -2149,8 +2146,8 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
"Can't find label '$name'.", continueKeyword.next.charOffset));
return;
}
- switchScope[identifier.name] =
- target = createGotoTarget(identifier.fileOffset);
+ switchScope.declareLabel(
+ identifier.name, target = createGotoTarget(identifier.fileOffset));
}
if (target.isGotoTarget) {
ContinueSwitchStatement statement = new ContinueSwitchStatement(null);
« no previous file with comments | « pkg/front_end/lib/src/fasta/builder/scope.dart ('k') | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698