| OLD | NEW |
| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if (isConstructor) { | 131 if (isConstructor) { |
| 132 // Even if there is no initializer list we still have to do the | 132 // Even if there is no initializer list we still have to do the |
| 133 // resolution in case there is an implicit super constructor call. | 133 // resolution in case there is an implicit super constructor call. |
| 134 InitializerResolver resolver = new InitializerResolver(visitor); | 134 InitializerResolver resolver = new InitializerResolver(visitor); |
| 135 FunctionElement redirection = | 135 FunctionElement redirection = |
| 136 resolver.resolveInitializers(element, tree); | 136 resolver.resolveInitializers(element, tree); |
| 137 if (redirection !== null) { | 137 if (redirection !== null) { |
| 138 resolveRedirectingConstructor(resolver, tree, element, redirection); | 138 resolveRedirectingConstructor(resolver, tree, element, redirection); |
| 139 } | 139 } |
| 140 } else if (tree.initializers != null) { | 140 } else if (tree.initializers != null) { |
| 141 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER); | 141 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER); |
| 142 } | 142 } |
| 143 visitor.visit(tree.body); | 143 visitor.visit(tree.body); |
| 144 | 144 |
| 145 // Resolve the type annotations encountered in the method. | 145 // Resolve the type annotations encountered in the method. |
| 146 while (!toResolve.isEmpty()) { | 146 while (!toResolve.isEmpty()) { |
| 147 ClassElement classElement = toResolve.removeFirst(); | 147 ClassElement classElement = toResolve.removeFirst(); |
| 148 classElement.ensureResolved(compiler); | 148 classElement.ensureResolved(compiler); |
| 149 } | 149 } |
| 150 if (isConstructor) { | 150 if (isConstructor) { |
| 151 constructorElements[element] = visitor.mapping; | 151 constructorElements[element] = visitor.mapping; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 for (Link<Node> link = initializers; | 395 for (Link<Node> link = initializers; |
| 396 !link.isEmpty(); | 396 !link.isEmpty(); |
| 397 link = link.tail) { | 397 link = link.tail) { |
| 398 if (link.head.asSendSet() != null) { | 398 if (link.head.asSendSet() != null) { |
| 399 final SendSet init = link.head.asSendSet(); | 399 final SendSet init = link.head.asSendSet(); |
| 400 resolveFieldInitializer(constructor, init); | 400 resolveFieldInitializer(constructor, init); |
| 401 } else if (link.head.asSend() !== null) { | 401 } else if (link.head.asSend() !== null) { |
| 402 final Send call = link.head.asSend(); | 402 final Send call = link.head.asSend(); |
| 403 if (Initializers.isSuperConstructorCall(call)) { | 403 if (Initializers.isSuperConstructorCall(call)) { |
| 404 if (resolvedSuper) { | 404 if (resolvedSuper) { |
| 405 error(call, MessageKind.DUPLICATE_SUPER_INITIALIZER); | 405 error(call, MessageKind.DUPLICATE_SUPER_INITIALIZER); |
| 406 } | 406 } |
| 407 resolveSuperOrThisForSend(constructor, functionNode, call); | 407 resolveSuperOrThisForSend(constructor, functionNode, call); |
| 408 resolvedSuper = true; | 408 resolvedSuper = true; |
| 409 } else if (Initializers.isConstructorRedirect(call)) { | 409 } else if (Initializers.isConstructorRedirect(call)) { |
| 410 // Check that there is no body (Language specification 7.5.1). | 410 // Check that there is no body (Language specification 7.5.1). |
| 411 if (functionNode.hasBody()) { | 411 if (functionNode.hasBody()) { |
| 412 error(functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY); | 412 error(functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY); |
| 413 } | 413 } |
| 414 // Check that there are no other initializers. | 414 // Check that there are no other initializers. |
| 415 if (!initializers.tail.isEmpty()) { | 415 if (!initializers.tail.isEmpty()) { |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 && (declaration is !VariableDefinitions || | 1231 && (declaration is !VariableDefinitions || |
| 1232 !declaration.asVariableDefinitions().definitions.nodes.tail.isEmpty())) | 1232 !declaration.asVariableDefinitions().definitions.nodes.tail.isEmpty())) |
| 1233 { | 1233 { |
| 1234 // The variable declaration is either not an identifier, not a | 1234 // The variable declaration is either not an identifier, not a |
| 1235 // declaration, or it's declaring more than one variable. | 1235 // declaration, or it's declaring more than one variable. |
| 1236 error(node.declaredIdentifier, MessageKind.INVALID_FOR_IN, []); | 1236 error(node.declaredIdentifier, MessageKind.INVALID_FOR_IN, []); |
| 1237 } | 1237 } |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 visitLabeledStatement(LabeledStatement node) { | 1240 visitLabeledStatement(LabeledStatement node) { |
| 1241 String labelName = node.label.source.slowToString(); | 1241 String labelName = node.label.slowToString(); |
| 1242 LabelElement existingElement = statementScope.lookupLabel(labelName); | 1242 LabelElement existingElement = statementScope.lookupLabel(labelName); |
| 1243 if (existingElement !== null) { | 1243 if (existingElement !== null) { |
| 1244 warning(node.label, MessageKind.DUPLICATE_LABEL, [labelName]); | 1244 warning(node.label, MessageKind.DUPLICATE_LABEL, [labelName]); |
| 1245 warning(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]); | 1245 warning(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]); |
| 1246 } | 1246 } |
| 1247 Node body = node.getBody(); | 1247 Node body = node.getBody(); |
| 1248 TargetElement targetElement = getOrCreateTargetElement(body); | 1248 TargetElement targetElement = getOrCreateTargetElement(body); |
| 1249 | 1249 |
| 1250 LabelElement element = targetElement.addLabel(node.label, labelName); | 1250 LabelElement element = targetElement.addLabel(node.label, labelName); |
| 1251 statementScope.enterLabelScope(element); | 1251 statementScope.enterLabelScope(element); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1277 | 1277 |
| 1278 visitSwitchStatement(SwitchStatement node) { | 1278 visitSwitchStatement(SwitchStatement node) { |
| 1279 node.expression.accept(this); | 1279 node.expression.accept(this); |
| 1280 | 1280 |
| 1281 TargetElement breakElement = getOrCreateTargetElement(node); | 1281 TargetElement breakElement = getOrCreateTargetElement(node); |
| 1282 Map<String, LabelElement> continueLabels = <LabelElement>{}; | 1282 Map<String, LabelElement> continueLabels = <LabelElement>{}; |
| 1283 Link<Node> cases = node.cases.nodes; | 1283 Link<Node> cases = node.cases.nodes; |
| 1284 while (!cases.isEmpty()) { | 1284 while (!cases.isEmpty()) { |
| 1285 SwitchCase switchCase = cases.head; | 1285 SwitchCase switchCase = cases.head; |
| 1286 if (switchCase.label !== null) { | 1286 if (switchCase.label !== null) { |
| 1287 Identifier labelIdentifier = switchCase.label; | 1287 Label label = switchCase.label; |
| 1288 String labelName = labelIdentifier.source.slowToString(); | 1288 String labelName = label.slowToString(); |
| 1289 | 1289 |
| 1290 LabelElement existingElement = continueLabels[labelName]; | 1290 LabelElement existingElement = continueLabels[labelName]; |
| 1291 if (existingElement !== null) { | 1291 if (existingElement !== null) { |
| 1292 // It's an error if the same label occurs twice in the same switch. | 1292 // It's an error if the same label occurs twice in the same switch. |
| 1293 warning(labelIdentifier, MessageKind.DUPLICATE_LABEL, [labelName]); | 1293 warning(label, MessageKind.DUPLICATE_LABEL, [labelName]); |
| 1294 error(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]); | 1294 error(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]); |
| 1295 } else { | 1295 } else { |
| 1296 // It's only a warning if it shadows another label. | 1296 // It's only a warning if it shadows another label. |
| 1297 existingElement = statementScope.lookupLabel(labelName); | 1297 existingElement = statementScope.lookupLabel(labelName); |
| 1298 if (existingElement !== null) { | 1298 if (existingElement !== null) { |
| 1299 warning(labelIdentifier, MessageKind.DUPLICATE_LABEL, [labelName]); | 1299 warning(label, MessageKind.DUPLICATE_LABEL, [labelName]); |
| 1300 warning(existingElement.label, | 1300 warning(existingElement.label, |
| 1301 MessageKind.EXISTING_LABEL, [labelName]); | 1301 MessageKind.EXISTING_LABEL, [labelName]); |
| 1302 } | 1302 } |
| 1303 } | 1303 } |
| 1304 | 1304 |
| 1305 TargetElement targetElement = | 1305 TargetElement targetElement = |
| 1306 new TargetElement(switchCase, | 1306 new TargetElement(switchCase, |
| 1307 statementScope.nestingLevel, | 1307 statementScope.nestingLevel, |
| 1308 enclosingElement); | 1308 enclosingElement); |
| 1309 mapping[switchCase] = targetElement; | 1309 mapping[switchCase] = targetElement; |
| 1310 | 1310 |
| 1311 LabelElement label = | 1311 LabelElement labelElement = |
| 1312 new LabelElement(labelIdentifier, labelName, | 1312 new LabelElement(label, labelName, |
| 1313 targetElement, enclosingElement); | 1313 targetElement, enclosingElement); |
| 1314 mapping[labelIdentifier] = label; | 1314 mapping[label] = labelElement; |
| 1315 continueLabels[labelName] = label; | 1315 continueLabels[labelName] = labelElement; |
| 1316 } | 1316 } |
| 1317 cases = cases.tail; | 1317 cases = cases.tail; |
| 1318 if (switchCase.defaultKeyword !== null && !cases.isEmpty()) { | 1318 if (switchCase.defaultKeyword !== null && !cases.isEmpty()) { |
| 1319 error(switchCase, MessageKind.INVALID_CASE_DEFAULT); | 1319 error(switchCase, MessageKind.INVALID_CASE_DEFAULT); |
| 1320 } | 1320 } |
| 1321 } | 1321 } |
| 1322 statementScope.enterSwitch(breakElement, continueLabels); | 1322 statementScope.enterSwitch(breakElement, continueLabels); |
| 1323 node.cases.accept(this); | 1323 node.cases.accept(this); |
| 1324 statementScope.exitSwitch(); | 1324 statementScope.exitSwitch(); |
| 1325 | 1325 |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1926 | 1926 |
| 1927 TopScope(LibraryElement library) : super(null, library); | 1927 TopScope(LibraryElement library) : super(null, library); |
| 1928 Element lookup(SourceString name) { | 1928 Element lookup(SourceString name) { |
| 1929 return library.find(name); | 1929 return library.find(name); |
| 1930 } | 1930 } |
| 1931 | 1931 |
| 1932 Element add(Element newElement) { | 1932 Element add(Element newElement) { |
| 1933 throw "Cannot add an element in the top scope"; | 1933 throw "Cannot add an element in the top scope"; |
| 1934 } | 1934 } |
| 1935 } | 1935 } |
| OLD | NEW |