| 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 DartType getType(TypeAnnotation annotation); | 8 DartType getType(TypeAnnotation annotation); |
| 9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
| 10 } | 10 } |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); | 983 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); |
| 984 } | 984 } |
| 985 return result; | 985 return result; |
| 986 } | 986 } |
| 987 | 987 |
| 988 // Create, or reuse an already created, statement element for a statement. | 988 // Create, or reuse an already created, statement element for a statement. |
| 989 TargetElement getOrCreateTargetElement(Node statement) { | 989 TargetElement getOrCreateTargetElement(Node statement) { |
| 990 TargetElement element = mapping[statement]; | 990 TargetElement element = mapping[statement]; |
| 991 if (element === null) { | 991 if (element === null) { |
| 992 element = new TargetElement(statement, | 992 element = new TargetElement(statement, |
| 993 statementScope.nestingLevel, | 993 statementScope.nestingLevel, |
| 994 enclosingElement); | 994 enclosingElement); |
| 995 mapping[statement] = element; | 995 mapping[statement] = element; |
| 996 } | 996 } |
| 997 return element; | 997 return element; |
| 998 } | 998 } |
| 999 | 999 |
| 1000 inStaticContext(action()) { | 1000 inStaticContext(action()) { |
| 1001 bool wasInstanceContext = inInstanceContext; | 1001 bool wasInstanceContext = inInstanceContext; |
| 1002 inInstanceContext = false; | 1002 inInstanceContext = false; |
| 1003 var result = action(); | 1003 var result = action(); |
| 1004 inInstanceContext = wasInstanceContext; | 1004 inInstanceContext = wasInstanceContext; |
| 1005 return result; | 1005 return result; |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 visitInStaticContext(Node node) { | 1008 visitInStaticContext(Node node) { |
| 1009 inStaticContext(() => visit(node)); | 1009 inStaticContext(() => visit(node)); |
| 1010 } | 1010 } |
| 1011 | 1011 |
| 1012 ErroneousElement warnAndCreateErroneousElement(Node node, |
| 1013 SourceString name, |
| 1014 MessageKind kind, |
| 1015 List<Node> arguments) { |
| 1016 ResolutionWarning warning = new ResolutionWarning(kind, arguments); |
| 1017 compiler.reportWarning(node, warning); |
| 1018 return new ErroneousElement(warning.message, name, enclosingElement); |
| 1019 } |
| 1020 |
| 1012 Element visitIdentifier(Identifier node) { | 1021 Element visitIdentifier(Identifier node) { |
| 1013 if (node.isThis()) { | 1022 if (node.isThis()) { |
| 1014 if (!inInstanceContext) { | 1023 if (!inInstanceContext) { |
| 1015 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); | 1024 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); |
| 1016 } | 1025 } |
| 1017 return null; | 1026 return null; |
| 1018 } else if (node.isSuper()) { | 1027 } else if (node.isSuper()) { |
| 1019 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC); | 1028 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC); |
| 1020 if ((ElementCategory.SUPER & allowedCategory) == 0) { | 1029 if ((ElementCategory.SUPER & allowedCategory) == 0) { |
| 1021 error(node, MessageKind.INVALID_USE_OF_SUPER); | 1030 error(node, MessageKind.INVALID_USE_OF_SUPER); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 return null; | 1231 return null; |
| 1223 } | 1232 } |
| 1224 if (currentClass.supertype === null) { | 1233 if (currentClass.supertype === null) { |
| 1225 // This is just to guard against internal errors, so no need | 1234 // This is just to guard against internal errors, so no need |
| 1226 // for a real error message. | 1235 // for a real error message. |
| 1227 error(node.receiver, MessageKind.GENERIC, ["Object has no superclass"]); | 1236 error(node.receiver, MessageKind.GENERIC, ["Object has no superclass"]); |
| 1228 } | 1237 } |
| 1229 target = currentClass.lookupSuperMember(name); | 1238 target = currentClass.lookupSuperMember(name); |
| 1230 // [target] may be null which means invoking noSuchMethod on | 1239 // [target] may be null which means invoking noSuchMethod on |
| 1231 // super. | 1240 // super. |
| 1232 } else if (Element.isInvalid(resolvedReceiver)) { | 1241 } else if (Element.isUnresolved(resolvedReceiver)) { |
| 1233 return null; | 1242 return null; |
| 1234 } else if (resolvedReceiver.kind === ElementKind.CLASS) { | 1243 } else if (resolvedReceiver.kind === ElementKind.CLASS) { |
| 1235 ClassElement receiverClass = resolvedReceiver; | 1244 ClassElement receiverClass = resolvedReceiver; |
| 1236 target = receiverClass.ensureResolved(compiler).lookupLocalMember(name); | 1245 target = receiverClass.ensureResolved(compiler).lookupLocalMember(name); |
| 1237 if (target === null) { | 1246 if (target === null) { |
| 1238 error(node, MessageKind.METHOD_NOT_FOUND, [receiverClass.name, name]); | 1247 return warnAndCreateErroneousElement(node, name, |
| 1248 MessageKind.METHOD_NOT_FOUND, |
| 1249 [receiverClass.name, name]); |
| 1239 } else if (target.isInstanceMember()) { | 1250 } else if (target.isInstanceMember()) { |
| 1240 error(node, MessageKind.MEMBER_NOT_STATIC, [receiverClass.name, name]); | 1251 error(node, MessageKind.MEMBER_NOT_STATIC, [receiverClass.name, name]); |
| 1241 } | 1252 } |
| 1242 } else if (resolvedReceiver.kind === ElementKind.PREFIX) { | 1253 } else if (resolvedReceiver.kind === ElementKind.PREFIX) { |
| 1243 PrefixElement prefix = resolvedReceiver; | 1254 PrefixElement prefix = resolvedReceiver; |
| 1244 target = prefix.lookupLocalMember(name); | 1255 target = prefix.lookupLocalMember(name); |
| 1245 if (target == null) { | 1256 if (target == null) { |
| 1246 error(node, MessageKind.NO_SUCH_LIBRARY_MEMBER, [prefix.name, name]); | 1257 error(node, MessageKind.NO_SUCH_LIBRARY_MEMBER, [prefix.name, name]); |
| 1247 } | 1258 } |
| 1248 } | 1259 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 if (argument.asNamedArgument() != null) { | 1336 if (argument.asNamedArgument() != null) { |
| 1326 seenNamedArgument = true; | 1337 seenNamedArgument = true; |
| 1327 } else if (seenNamedArgument) { | 1338 } else if (seenNamedArgument) { |
| 1328 error(argument, MessageKind.INVALID_ARGUMENT_AFTER_NAMED); | 1339 error(argument, MessageKind.INVALID_ARGUMENT_AFTER_NAMED); |
| 1329 } | 1340 } |
| 1330 } | 1341 } |
| 1331 } | 1342 } |
| 1332 | 1343 |
| 1333 visitSend(Send node) { | 1344 visitSend(Send node) { |
| 1334 Element target = resolveSend(node); | 1345 Element target = resolveSend(node); |
| 1335 if (!Element.isInvalid(target) | 1346 if (!Element.isUnresolved(target) |
| 1336 && target.kind == ElementKind.ABSTRACT_FIELD) { | 1347 && target.kind == ElementKind.ABSTRACT_FIELD) { |
| 1337 AbstractFieldElement field = target; | 1348 AbstractFieldElement field = target; |
| 1338 target = field.getter; | 1349 target = field.getter; |
| 1339 if (Element.isInvalid(target) && !inInstanceContext) { | 1350 if (Element.isUnresolved(target) && !inInstanceContext) { |
| 1340 // TODO(karlklose): make this a runtime error. | |
| 1341 error(node.selector, MessageKind.CANNOT_RESOLVE_GETTER); | 1351 error(node.selector, MessageKind.CANNOT_RESOLVE_GETTER); |
| 1342 } | 1352 } |
| 1343 } | 1353 } |
| 1344 | 1354 |
| 1345 bool resolvedArguments = false; | 1355 bool resolvedArguments = false; |
| 1346 if (node.isOperator) { | 1356 if (node.isOperator) { |
| 1347 String operatorString = node.selector.asOperator().source.stringValue; | 1357 String operatorString = node.selector.asOperator().source.stringValue; |
| 1348 if (operatorString === 'is' || operatorString === 'as') { | 1358 if (operatorString === 'is' || operatorString === 'as') { |
| 1349 assert(node.arguments.tail.isEmpty()); | 1359 assert(node.arguments.tail.isEmpty()); |
| 1350 resolveTypeTest(node.arguments.head); | 1360 resolveTypeTest(node.arguments.head); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1365 | 1375 |
| 1366 // If the selector is null, it means that we will not be generating | 1376 // If the selector is null, it means that we will not be generating |
| 1367 // code for this as a send. | 1377 // code for this as a send. |
| 1368 Selector selector = mapping.getSelector(node); | 1378 Selector selector = mapping.getSelector(node); |
| 1369 if (selector === null) return; | 1379 if (selector === null) return; |
| 1370 | 1380 |
| 1371 // If we don't know what we're calling or if we are calling a getter, | 1381 // If we don't know what we're calling or if we are calling a getter, |
| 1372 // we need to register that fact that we may be calling a closure | 1382 // we need to register that fact that we may be calling a closure |
| 1373 // with the same arguments. | 1383 // with the same arguments. |
| 1374 if (node.isCall && | 1384 if (node.isCall && |
| 1375 (Element.isInvalid(target) || | 1385 (Element.isUnresolved(target) || |
| 1376 target.isGetter() || | 1386 target.isGetter() || |
| 1377 Elements.isClosureSend(node, target))) { | 1387 Elements.isClosureSend(node, target))) { |
| 1378 Selector call = new Selector.callClosureFrom(selector); | 1388 Selector call = new Selector.callClosureFrom(selector); |
| 1379 world.registerDynamicInvocation(call.name, call); | 1389 world.registerDynamicInvocation(call.name, call); |
| 1380 } | 1390 } |
| 1381 | 1391 |
| 1382 // TODO(ngeoffray): We should do the check in | 1392 // TODO(ngeoffray): We should do the check in |
| 1383 // visitExpressionStatement instead. | 1393 // visitExpressionStatement instead. |
| 1384 if (target === compiler.assertMethod && !node.isCall) { | 1394 if (target === compiler.assertMethod && !node.isCall) { |
| 1385 // We can only use assert by calling it. | 1395 // We can only use assert by calling it. |
| 1386 if (!inInstanceContext) { | 1396 if (!inInstanceContext) { |
| 1387 error(node, MessageKind.MISSING_ARGUMENTS_TO_ASSERT, [node]); | 1397 error(node, MessageKind.MISSING_ARGUMENTS_TO_ASSERT, [node]); |
| 1388 } | 1398 } |
| 1389 target = null; | 1399 target = null; |
| 1390 } | 1400 } |
| 1391 | 1401 |
| 1392 // TODO(ngeoffray): Warn if target is null and the send is | 1402 // TODO(ngeoffray): Warn if target is null and the send is |
| 1393 // unqualified. | 1403 // unqualified. |
| 1394 useElement(node, target); | 1404 useElement(node, target); |
| 1395 registerSend(selector, target); | 1405 registerSend(selector, target); |
| 1396 return node.isPropertyAccess ? target : null; | 1406 return node.isPropertyAccess ? target : null; |
| 1397 } | 1407 } |
| 1398 | 1408 |
| 1399 visitSendSet(SendSet node) { | 1409 visitSendSet(SendSet node) { |
| 1400 Element target = resolveSend(node); | 1410 Element target = resolveSend(node); |
| 1401 Element setter = target; | 1411 Element setter = target; |
| 1402 Element getter = target; | 1412 Element getter = target; |
| 1403 String source = node.assignmentOperator.source.stringValue; | 1413 String source = node.assignmentOperator.source.stringValue; |
| 1404 bool isComplex = source !== '='; | 1414 bool isComplex = source !== '='; |
| 1405 if (target != null && target.kind == ElementKind.ABSTRACT_FIELD) { | 1415 if (!Element.isUnresolved(target) |
| 1416 && target.kind == ElementKind.ABSTRACT_FIELD) { |
| 1406 AbstractFieldElement field = target; | 1417 AbstractFieldElement field = target; |
| 1407 setter = field.setter; | 1418 setter = field.setter; |
| 1408 getter = field.getter; | 1419 getter = field.getter; |
| 1409 if (Element.isInvalid(setter) && !inInstanceContext) { | 1420 if (setter == null && !inInstanceContext) { |
| 1410 // TODO(karlklose): make this a runtime error. | |
| 1411 error(node.selector, MessageKind.CANNOT_RESOLVE_SETTER); | 1421 error(node.selector, MessageKind.CANNOT_RESOLVE_SETTER); |
| 1412 } | 1422 } |
| 1413 if (isComplex && Element.isInvalid(getter) && !inInstanceContext) { | 1423 if (isComplex && getter == null && !inInstanceContext) { |
| 1414 // TODO(karlklose): make this a runtime error. | |
| 1415 error(node.selector, MessageKind.CANNOT_RESOLVE_GETTER); | 1424 error(node.selector, MessageKind.CANNOT_RESOLVE_GETTER); |
| 1416 } | 1425 } |
| 1417 } | 1426 } |
| 1418 | 1427 |
| 1419 visit(node.argumentsNode); | 1428 visit(node.argumentsNode); |
| 1420 | 1429 |
| 1421 // TODO(ngeoffray): Check if the target can be assigned. | 1430 // TODO(ngeoffray): Check if the target can be assigned. |
| 1422 // TODO(ngeoffray): Warn if target is null and the send is | 1431 // TODO(ngeoffray): Warn if target is null and the send is |
| 1423 // unqualified. | 1432 // unqualified. |
| 1424 | 1433 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 visitParenthesizedExpression(ParenthesizedExpression node) { | 1543 visitParenthesizedExpression(ParenthesizedExpression node) { |
| 1535 visit(node.expression); | 1544 visit(node.expression); |
| 1536 } | 1545 } |
| 1537 | 1546 |
| 1538 visitNewExpression(NewExpression node) { | 1547 visitNewExpression(NewExpression node) { |
| 1539 Node selector = node.send.selector; | 1548 Node selector = node.send.selector; |
| 1540 FunctionElement constructor = resolveConstructor(node); | 1549 FunctionElement constructor = resolveConstructor(node); |
| 1541 resolveSelector(node.send); | 1550 resolveSelector(node.send); |
| 1542 resolveArguments(node.send.argumentsNode); | 1551 resolveArguments(node.send.argumentsNode); |
| 1543 useElement(node.send, constructor); | 1552 useElement(node.send, constructor); |
| 1544 if (Element.isInvalid(constructor)) return constructor; | 1553 if (Element.isUnresolved(constructor)) return constructor; |
| 1545 // TODO(karlklose): handle optional arguments. | 1554 // TODO(karlklose): handle optional arguments. |
| 1546 if (node.send.argumentCount() != constructor.parameterCount(compiler)) { | 1555 if (node.send.argumentCount() != constructor.parameterCount(compiler)) { |
| 1547 // TODO(ngeoffray): resolution error with wrong number of | 1556 // TODO(ngeoffray): resolution error with wrong number of |
| 1548 // parameters. We cannot do this rigth now because of the | 1557 // parameters. We cannot do this rigth now because of the |
| 1549 // List constructor. | 1558 // List constructor. |
| 1550 } | 1559 } |
| 1551 world.registerStaticUse(constructor); | 1560 world.registerStaticUse(constructor); |
| 1552 compiler.withCurrentElement(constructor, () { | 1561 compiler.withCurrentElement(constructor, () { |
| 1553 FunctionExpression tree = constructor.parseNode(compiler); | 1562 FunctionExpression tree = constructor.parseNode(compiler); |
| 1554 compiler.resolver.resolveConstructorImplementation(constructor, tree); | 1563 compiler.resolver.resolveConstructorImplementation(constructor, tree); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1570 * Note: this function may return an ErroneousFunctionElement instead of | 1579 * Note: this function may return an ErroneousFunctionElement instead of |
| 1571 * [null], if there is no corresponding constructor, class or library. | 1580 * [null], if there is no corresponding constructor, class or library. |
| 1572 */ | 1581 */ |
| 1573 FunctionElement resolveConstructor(NewExpression node) { | 1582 FunctionElement resolveConstructor(NewExpression node) { |
| 1574 // Resolve the constructor that [node] refers to. | 1583 // Resolve the constructor that [node] refers to. |
| 1575 ConstructorResolver visitor = | 1584 ConstructorResolver visitor = |
| 1576 new ConstructorResolver(compiler, this, node.isConst()); | 1585 new ConstructorResolver(compiler, this, node.isConst()); |
| 1577 FunctionElement constructor = node.accept(visitor); | 1586 FunctionElement constructor = node.accept(visitor); |
| 1578 // Try to resolve the type that the new-expression constructs. | 1587 // Try to resolve the type that the new-expression constructs. |
| 1579 TypeAnnotation annotation = node.send.getTypeAnnotation(); | 1588 TypeAnnotation annotation = node.send.getTypeAnnotation(); |
| 1580 if (Element.isInvalid(constructor)) { | 1589 if (Element.isUnresolved(constructor)) { |
| 1581 // Resolve the type arguments. We cannot create a type and check the | 1590 // Resolve the type arguments. We cannot create a type and check the |
| 1582 // number of type arguments for this annotation, because we do not know | 1591 // number of type arguments for this annotation, because we do not know |
| 1583 // the element. | 1592 // the element. |
| 1584 Link arguments = const EmptyLink<Node>(); | 1593 Link arguments = const EmptyLink<Node>(); |
| 1585 if (annotation.typeArguments != null) { | 1594 if (annotation.typeArguments != null) { |
| 1586 arguments = annotation.typeArguments.nodes; | 1595 arguments = annotation.typeArguments.nodes; |
| 1587 } | 1596 } |
| 1588 for (Node argument in arguments) { | 1597 for (Node argument in arguments) { |
| 1589 resolveTypeRequired(argument); | 1598 resolveTypeRequired(argument); |
| 1590 } | 1599 } |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 | 2462 |
| 2454 ConstructorResolver(Compiler compiler, this.resolver, | 2463 ConstructorResolver(Compiler compiler, this.resolver, |
| 2455 [bool this.inConstContext = false]) | 2464 [bool this.inConstContext = false]) |
| 2456 : super(compiler); | 2465 : super(compiler); |
| 2457 | 2466 |
| 2458 visitNode(Node node) { | 2467 visitNode(Node node) { |
| 2459 throw 'not supported'; | 2468 throw 'not supported'; |
| 2460 } | 2469 } |
| 2461 | 2470 |
| 2462 failOrReturnErroneousElement(Element enclosing, Node diagnosticNode, | 2471 failOrReturnErroneousElement(Element enclosing, Node diagnosticNode, |
| 2463 MessageKind kind, List arguments) { | 2472 SourceString targetName, MessageKind kind, |
| 2473 List arguments) { |
| 2464 if (inConstContext) { | 2474 if (inConstContext) { |
| 2465 error(diagnosticNode, kind, arguments); | 2475 error(diagnosticNode, kind, arguments); |
| 2466 } else { | 2476 } else { |
| 2467 ResolutionWarning warning = new ResolutionWarning(kind, arguments); | 2477 ResolutionWarning warning = new ResolutionWarning(kind, arguments); |
| 2468 compiler.reportWarning(diagnosticNode, warning); | 2478 compiler.reportWarning(diagnosticNode, warning); |
| 2469 return new ErroneousFunctionElement(warning.message, enclosing); | 2479 return new ErroneousFunctionElement(warning.message, targetName, |
| 2480 enclosing); |
| 2470 } | 2481 } |
| 2471 } | 2482 } |
| 2472 | 2483 |
| 2473 FunctionElement lookupConstructor(ClassElement cls, | 2484 FunctionElement lookupConstructor(ClassElement cls, |
| 2474 Node diagnosticNode, | 2485 Node diagnosticNode, |
| 2475 SourceString constructorName) { | 2486 SourceString constructorName) { |
| 2476 cls.ensureResolved(compiler); | 2487 cls.ensureResolved(compiler); |
| 2477 Element result = cls.lookupConstructor(cls.name, constructorName); | 2488 Element result = cls.lookupConstructor(cls.name, constructorName); |
| 2478 if (result === null) { | 2489 if (result === null) { |
| 2479 String fullConstructorName = cls.name.slowToString(); | 2490 String fullConstructorName = cls.name.slowToString(); |
| 2480 if (constructorName !== const SourceString('')) { | 2491 if (constructorName !== const SourceString('')) { |
| 2481 fullConstructorName = '$fullConstructorName' | 2492 fullConstructorName = '$fullConstructorName' |
| 2482 '.${constructorName.slowToString()}'; | 2493 '.${constructorName.slowToString()}'; |
| 2483 } | 2494 } |
| 2484 return failOrReturnErroneousElement(cls, diagnosticNode, | 2495 return failOrReturnErroneousElement(cls, diagnosticNode, |
| 2496 new SourceString(fullConstructorName), |
| 2485 MessageKind.CANNOT_FIND_CONSTRUCTOR, | 2497 MessageKind.CANNOT_FIND_CONSTRUCTOR, |
| 2486 [fullConstructorName]); | 2498 [fullConstructorName]); |
| 2487 } | 2499 } |
| 2488 return result; | 2500 return result; |
| 2489 } | 2501 } |
| 2490 | 2502 |
| 2491 visitNewExpression(NewExpression node) { | 2503 visitNewExpression(NewExpression node) { |
| 2492 Node selector = node.send.selector; | 2504 Node selector = node.send.selector; |
| 2493 Element e = visit(selector); | 2505 Element e = visit(selector); |
| 2494 if (!Element.isInvalid(e) && e.kind === ElementKind.CLASS) { | 2506 if (!Element.isUnresolved(e) && e.kind === ElementKind.CLASS) { |
| 2495 ClassElement cls = e; | 2507 ClassElement cls = e; |
| 2496 cls.ensureResolved(compiler); | 2508 cls.ensureResolved(compiler); |
| 2497 if (cls.isInterface() && (cls.defaultClass === null)) { | 2509 if (cls.isInterface() && (cls.defaultClass === null)) { |
| 2498 error(selector, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); | 2510 error(selector, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); |
| 2499 } | 2511 } |
| 2500 e = lookupConstructor(cls, selector, const SourceString('')); | 2512 e = lookupConstructor(cls, selector, const SourceString('')); |
| 2501 } | 2513 } |
| 2502 return e; | 2514 return e; |
| 2503 } | 2515 } |
| 2504 | 2516 |
| 2505 visitTypeAnnotation(TypeAnnotation node) { | 2517 visitTypeAnnotation(TypeAnnotation node) { |
| 2506 return visit(node.typeName); | 2518 return visit(node.typeName); |
| 2507 } | 2519 } |
| 2508 | 2520 |
| 2509 visitSend(Send node) { | 2521 visitSend(Send node) { |
| 2510 Element e = visit(node.receiver); | 2522 Element e = visit(node.receiver); |
| 2511 if (Element.isInvalid(e)) return e; | 2523 if (Element.isUnresolved(e)) return e; |
| 2512 Identifier name = node.selector.asIdentifier(); | 2524 Identifier name = node.selector.asIdentifier(); |
| 2513 if (name === null) internalError(node.selector, 'unexpected node'); | 2525 if (name === null) internalError(node.selector, 'unexpected node'); |
| 2514 | 2526 |
| 2515 if (e.kind === ElementKind.CLASS) { | 2527 if (e.kind === ElementKind.CLASS) { |
| 2516 ClassElement cls = e; | 2528 ClassElement cls = e; |
| 2517 cls.ensureResolved(compiler); | 2529 cls.ensureResolved(compiler); |
| 2518 if (cls.isInterface() && (cls.defaultClass === null)) { | 2530 if (cls.isInterface() && (cls.defaultClass === null)) { |
| 2519 error(node.receiver, MessageKind.CANNOT_INSTANTIATE_INTERFACE, | 2531 error(node.receiver, MessageKind.CANNOT_INSTANTIATE_INTERFACE, |
| 2520 [cls.name]); | 2532 [cls.name]); |
| 2521 } | 2533 } |
| 2522 return lookupConstructor(cls, name, name.source); | 2534 return lookupConstructor(cls, name, name.source); |
| 2523 } else if (e.kind === ElementKind.PREFIX) { | 2535 } else if (e.kind === ElementKind.PREFIX) { |
| 2524 PrefixElement prefix = e; | 2536 PrefixElement prefix = e; |
| 2525 e = prefix.lookupLocalMember(name.source); | 2537 e = prefix.lookupLocalMember(name.source); |
| 2526 if (e === null) { | 2538 if (e === null) { |
| 2527 return failOrReturnErroneousElement(resolver.enclosingElement, name, | 2539 return failOrReturnErroneousElement(resolver.enclosingElement, name, |
| 2540 name.source, |
| 2528 MessageKind.CANNOT_RESOLVE, | 2541 MessageKind.CANNOT_RESOLVE, |
| 2529 [name]); | 2542 [name]); |
| 2530 } else if (e.kind !== ElementKind.CLASS) { | 2543 } else if (e.kind !== ElementKind.CLASS) { |
| 2531 error(node, MessageKind.NOT_A_TYPE, [name]); | 2544 error(node, MessageKind.NOT_A_TYPE, [name]); |
| 2532 } | 2545 } |
| 2533 } else { | 2546 } else { |
| 2534 internalError(node.receiver, 'unexpected element $e'); | 2547 internalError(node.receiver, 'unexpected element $e'); |
| 2535 } | 2548 } |
| 2536 return e; | 2549 return e; |
| 2537 } | 2550 } |
| 2538 | 2551 |
| 2539 Element visitIdentifier(Identifier node) { | 2552 Element visitIdentifier(Identifier node) { |
| 2540 SourceString name = node.source; | 2553 SourceString name = node.source; |
| 2541 Element e = resolver.lookup(node, name); | 2554 Element e = resolver.lookup(node, name); |
| 2542 if (e === null) { | 2555 if (e === null) { |
| 2543 return failOrReturnErroneousElement(resolver.enclosingElement, node, | 2556 return failOrReturnErroneousElement(resolver.enclosingElement, node, name, |
| 2544 MessageKind.CANNOT_RESOLVE, [name]); | 2557 MessageKind.CANNOT_RESOLVE, [name]); |
| 2545 } else if (e.kind === ElementKind.TYPEDEF) { | 2558 } else if (e.kind === ElementKind.TYPEDEF) { |
| 2546 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); | 2559 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); |
| 2547 } else if (e.kind !== ElementKind.CLASS && e.kind !== ElementKind.PREFIX) { | 2560 } else if (e.kind !== ElementKind.CLASS && e.kind !== ElementKind.PREFIX) { |
| 2548 error(node, MessageKind.NOT_A_TYPE, [name]); | 2561 error(node, MessageKind.NOT_A_TYPE, [name]); |
| 2549 } | 2562 } |
| 2550 return e; | 2563 return e; |
| 2551 } | 2564 } |
| 2552 } | 2565 } |
| 2553 | 2566 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2666 TopScope(LibraryElement library) : super(null, library); | 2679 TopScope(LibraryElement library) : super(null, library); |
| 2667 Element lookup(SourceString name) { | 2680 Element lookup(SourceString name) { |
| 2668 return library.find(name); | 2681 return library.find(name); |
| 2669 } | 2682 } |
| 2670 | 2683 |
| 2671 Element add(Element newElement) { | 2684 Element add(Element newElement) { |
| 2672 throw "Cannot add an element in the top scope"; | 2685 throw "Cannot add an element in the top scope"; |
| 2673 } | 2686 } |
| 2674 String toString() => '$element'; | 2687 String toString() => '$element'; |
| 2675 } | 2688 } |
| OLD | NEW |