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

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 10387080: Accept more labels per switch case. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 Type getType(TypeAnnotation annotation); 8 Type getType(TypeAnnotation annotation);
9 } 9 }
10 10
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 target.isContinueTarget = true; 1204 target.isContinueTarget = true;
1205 } else { 1205 } else {
1206 String labelName = node.target.source.slowToString(); 1206 String labelName = node.target.source.slowToString();
1207 LabelElement label = statementScope.lookupLabel(labelName); 1207 LabelElement label = statementScope.lookupLabel(labelName);
1208 if (label === null) { 1208 if (label === null) {
1209 error(node.target, MessageKind.UNBOUND_LABEL, [labelName]); 1209 error(node.target, MessageKind.UNBOUND_LABEL, [labelName]);
1210 return; 1210 return;
1211 } 1211 }
1212 target = label.target; 1212 target = label.target;
1213 if (!target.statement.isValidContinueTarget()) { 1213 if (!target.statement.isValidContinueTarget()) {
1214 print(target);
karlklose 2012/05/11 09:29:31 Remove debug code.
Lasse Reichstein Nielsen 2012/05/11 14:17:09 Done.
1214 error(node.target, MessageKind.INVALID_CONTINUE, [labelName]); 1215 error(node.target, MessageKind.INVALID_CONTINUE, [labelName]);
1215 } 1216 }
1217 // TODO(lrn): Handle continues to switch cases.
1218 if (target.statement is SwitchCase) {
1219 unimplemented(node, "continue to switch case");
1220 }
1216 label.setContinueTarget(); 1221 label.setContinueTarget();
1217 mapping[node.target] = label; 1222 mapping[node.target] = label;
1218 } 1223 }
1219 mapping[node] = target; 1224 mapping[node] = target;
1220 } 1225 }
1221 1226
1222 visitForIn(ForIn node) { 1227 visitForIn(ForIn node) {
1223 visit(node.expression); 1228 visit(node.expression);
1224 Scope scope = new BlockScope(context); 1229 Scope scope = new BlockScope(context);
1225 Node declaration = node.declaredIdentifier; 1230 Node declaration = node.declaredIdentifier;
1226 visitIn(declaration, scope); 1231 visitIn(declaration, scope);
1227 visitLoopBodyIn(node, node.body, scope); 1232 visitLoopBodyIn(node, node.body, scope);
1228 1233
1229 // TODO(lrn): Also allow a single identifier. 1234 // TODO(lrn): Also allow a single identifier.
1230 if ((declaration is !Send || declaration.asSend().selector is !Identifier) 1235 if ((declaration is !Send || declaration.asSend().selector is !Identifier)
1231 && (declaration is !VariableDefinitions || 1236 && (declaration is !VariableDefinitions ||
1232 !declaration.asVariableDefinitions().definitions.nodes.tail.isEmpty())) 1237 !declaration.asVariableDefinitions().definitions.nodes.tail.isEmpty()))
1233 { 1238 {
1234 // The variable declaration is either not an identifier, not a 1239 // The variable declaration is either not an identifier, not a
1235 // declaration, or it's declaring more than one variable. 1240 // declaration, or it's declaring more than one variable.
1236 error(node.declaredIdentifier, MessageKind.INVALID_FOR_IN, []); 1241 error(node.declaredIdentifier, MessageKind.INVALID_FOR_IN, []);
1237 } 1242 }
1238 } 1243 }
1239 1244
1245 visitLabel(Label node) {
1246
karlklose 2012/05/11 09:29:31 Remove empty line.
Lasse Reichstein Nielsen 2012/05/11 14:17:09 Done.
1247 }
1248
1240 visitLabeledStatement(LabeledStatement node) { 1249 visitLabeledStatement(LabeledStatement node) {
1241 String labelName = node.label.slowToString(); 1250 String labelName = node.label.slowToString();
1242 LabelElement existingElement = statementScope.lookupLabel(labelName); 1251 LabelElement existingElement = statementScope.lookupLabel(labelName);
1243 if (existingElement !== null) { 1252 if (existingElement !== null) {
1244 warning(node.label, MessageKind.DUPLICATE_LABEL, [labelName]); 1253 warning(node.label, MessageKind.DUPLICATE_LABEL, [labelName]);
1245 warning(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]); 1254 warning(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]);
1246 } 1255 }
1247 Node body = node.getBody(); 1256 Node body = node.getBody();
1248 TargetElement targetElement = getOrCreateTargetElement(body); 1257 TargetElement targetElement = getOrCreateTargetElement(body);
1249 1258
(...skipping 26 matching lines...) Expand all
1276 } 1285 }
1277 1286
1278 visitSwitchStatement(SwitchStatement node) { 1287 visitSwitchStatement(SwitchStatement node) {
1279 node.expression.accept(this); 1288 node.expression.accept(this);
1280 1289
1281 TargetElement breakElement = getOrCreateTargetElement(node); 1290 TargetElement breakElement = getOrCreateTargetElement(node);
1282 Map<String, LabelElement> continueLabels = <LabelElement>{}; 1291 Map<String, LabelElement> continueLabels = <LabelElement>{};
1283 Link<Node> cases = node.cases.nodes; 1292 Link<Node> cases = node.cases.nodes;
1284 while (!cases.isEmpty()) { 1293 while (!cases.isEmpty()) {
1285 SwitchCase switchCase = cases.head; 1294 SwitchCase switchCase = cases.head;
1286 if (switchCase.label !== null) { 1295 for (Label label in switchCase.labels) {
1287 Label label = switchCase.label;
1288 String labelName = label.slowToString(); 1296 String labelName = label.slowToString();
1289 1297
1290 LabelElement existingElement = continueLabels[labelName]; 1298 LabelElement existingElement = continueLabels[labelName];
1291 if (existingElement !== null) { 1299 if (existingElement !== null) {
1292 // It's an error if the same label occurs twice in the same switch. 1300 // It's an error if the same label occurs twice in the same switch.
1293 warning(label, MessageKind.DUPLICATE_LABEL, [labelName]); 1301 warning(label, MessageKind.DUPLICATE_LABEL, [labelName]);
1294 error(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]); 1302 error(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]);
1295 } else { 1303 } else {
1296 // It's only a warning if it shadows another label. 1304 // It's only a warning if it shadows another label.
1297 existingElement = statementScope.lookupLabel(labelName); 1305 existingElement = statementScope.lookupLabel(labelName);
(...skipping 18 matching lines...) Expand all
1316 } 1324 }
1317 cases = cases.tail; 1325 cases = cases.tail;
1318 if (switchCase.defaultKeyword !== null && !cases.isEmpty()) { 1326 if (switchCase.defaultKeyword !== null && !cases.isEmpty()) {
1319 error(switchCase, MessageKind.INVALID_CASE_DEFAULT); 1327 error(switchCase, MessageKind.INVALID_CASE_DEFAULT);
1320 } 1328 }
1321 } 1329 }
1322 statementScope.enterSwitch(breakElement, continueLabels); 1330 statementScope.enterSwitch(breakElement, continueLabels);
1323 node.cases.accept(this); 1331 node.cases.accept(this);
1324 statementScope.exitSwitch(); 1332 statementScope.exitSwitch();
1325 1333
1326 // Clean-up unused labels 1334 // Clean-up unused labels.
1327 continueLabels.forEach((String key, LabelElement label) { 1335 continueLabels.forEach((String key, LabelElement label) {
1328 TargetElement targetElement = label.target; 1336 TargetElement targetElement = label.target;
1329 SwitchCase switchCase = targetElement.statement; 1337 SwitchCase switchCase = targetElement.statement;
1330 if (!label.isContinueTarget) { 1338 if (!label.isContinueTarget) {
1331 mapping.remove(switchCase); 1339 mapping.remove(switchCase);
1332 mapping.remove(label.label); 1340 mapping.remove(label.label);
1333 } 1341 }
1334 }); 1342 });
1335 } 1343 }
1336 1344
1337 visitSwitchCase(SwitchCase node) { 1345 visitSwitchCase(SwitchCase node) {
1338 // The label was handled in [visitSwitchStatement(SwitchStatement)]. 1346 // The labels were handled in [visitSwitchStatement(SwitchStatement)].
1339 node.expressions.accept(this); 1347 node.cases.accept(this);
1340 visitIn(node.statements, new BlockScope(context)); 1348 visitIn(node.statements, new BlockScope(context));
1341 } 1349 }
1342 1350
1351 visitCaseMatch(CaseMatch node) {
1352 visit(node.expression);
1353 }
1354
1343 visitTryStatement(TryStatement node) { 1355 visitTryStatement(TryStatement node) {
1344 visit(node.tryBlock); 1356 visit(node.tryBlock);
1345 if (node.catchBlocks.isEmpty() && node.finallyBlock == null) { 1357 if (node.catchBlocks.isEmpty() && node.finallyBlock == null) {
1346 // TODO(ngeoffray): The precise location is 1358 // TODO(ngeoffray): The precise location is
1347 // node.getEndtoken.next. Adjust when issue #1581 is fixed. 1359 // node.getEndtoken.next. Adjust when issue #1581 is fixed.
1348 error(node, MessageKind.NO_CATCH_NOR_FINALLY); 1360 error(node, MessageKind.NO_CATCH_NOR_FINALLY);
1349 } 1361 }
1350 visit(node.catchBlocks); 1362 visit(node.catchBlocks);
1351 visit(node.finallyBlock); 1363 visit(node.finallyBlock);
1352 } 1364 }
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 1938
1927 TopScope(LibraryElement library) : super(null, library); 1939 TopScope(LibraryElement library) : super(null, library);
1928 Element lookup(SourceString name) { 1940 Element lookup(SourceString name) {
1929 return library.find(name); 1941 return library.find(name);
1930 } 1942 }
1931 1943
1932 Element add(Element newElement) { 1944 Element add(Element newElement) {
1933 throw "Cannot add an element in the top scope"; 1945 throw "Cannot add an element in the top scope";
1934 } 1946 }
1935 } 1947 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698