| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library elements.modelx; | 5 library elements.modelx; |
| 6 | 6 |
| 7 import 'elements.dart'; | 7 import 'elements.dart'; |
| 8 import '../tree/tree.dart'; | 8 import '../tree/tree.dart'; |
| 9 import '../util/util.dart'; | 9 import '../util/util.dart'; |
| 10 import '../resolution/resolution.dart'; | 10 import '../resolution/resolution.dart'; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 | 70 |
| 71 bool isFunction() => identical(kind, ElementKind.FUNCTION); | 71 bool isFunction() => identical(kind, ElementKind.FUNCTION); |
| 72 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor(); | 72 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor(); |
| 73 bool isClosure() => false; | 73 bool isClosure() => false; |
| 74 bool isMember() { | 74 bool isMember() { |
| 75 // Check that this element is defined in the scope of a Class. | 75 // Check that this element is defined in the scope of a Class. |
| 76 return enclosingElement != null && enclosingElement.isClass(); | 76 return enclosingElement != null && enclosingElement.isClass(); |
| 77 } | 77 } |
| 78 bool isInstanceMember() => false; | 78 bool isInstanceMember() => false; |
| 79 bool isDeferredLoaderGetter() => false; |
| 79 | 80 |
| 80 bool isFactoryConstructor() => modifiers.isFactory(); | 81 bool isFactoryConstructor() => modifiers.isFactory(); |
| 81 bool isGenerativeConstructor() => | 82 bool isGenerativeConstructor() => |
| 82 identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR); | 83 identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR); |
| 83 bool isGenerativeConstructorBody() => | 84 bool isGenerativeConstructorBody() => |
| 84 identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR_BODY); | 85 identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR_BODY); |
| 85 bool isCompilationUnit() => identical(kind, ElementKind.COMPILATION_UNIT); | 86 bool isCompilationUnit() => identical(kind, ElementKind.COMPILATION_UNIT); |
| 86 bool isClass() => identical(kind, ElementKind.CLASS); | 87 bool isClass() => identical(kind, ElementKind.CLASS); |
| 87 bool isPrefix() => identical(kind, ElementKind.PREFIX); | 88 bool isPrefix() => identical(kind, ElementKind.PREFIX); |
| 88 bool isVariable() => identical(kind, ElementKind.VARIABLE); | 89 bool isVariable() => identical(kind, ElementKind.VARIABLE); |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 * detection of ambiguous uses of imported names. | 690 * detection of ambiguous uses of imported names. |
| 690 */ | 691 */ |
| 691 void addImport(Element enclosingElement, | 692 void addImport(Element enclosingElement, |
| 692 Element element, | 693 Element element, |
| 693 Import import, | 694 Import import, |
| 694 DiagnosticListener listener) { | 695 DiagnosticListener listener) { |
| 695 LibraryElementX library = enclosingElement.getLibrary(); | 696 LibraryElementX library = enclosingElement.getLibrary(); |
| 696 Importers importers = library.importers; | 697 Importers importers = library.importers; |
| 697 | 698 |
| 698 String name = element.name; | 699 String name = element.name; |
| 700 |
| 701 // The loadLibrary function always shadows existing bindings to that name. |
| 702 if (element.isDeferredLoaderGetter()) { |
| 703 importScope.remove(name); |
| 704 // TODO(sigurdm): Print a hint. |
| 705 } |
| 699 Element existing = importScope.putIfAbsent(name, () => element); | 706 Element existing = importScope.putIfAbsent(name, () => element); |
| 700 importers.registerImport(element, import); | 707 importers.registerImport(element, import); |
| 701 | 708 |
| 702 void registerWarnOnUseElement(Import import, | 709 void registerWarnOnUseElement(Import import, |
| 703 MessageKind messageKind, | 710 MessageKind messageKind, |
| 704 Element hidingElement, | 711 Element hidingElement, |
| 705 Element hiddenElement) { | 712 Element hiddenElement) { |
| 706 Uri hiddenUri = hiddenElement.getLibrary().canonicalUri; | 713 Uri hiddenUri = hiddenElement.getLibrary().canonicalUri; |
| 707 Uri hidingUri = hidingElement.getLibrary().canonicalUri; | 714 Uri hidingUri = hidingElement.getLibrary().canonicalUri; |
| 708 Element element = new WarnOnUseElementX( | 715 Element element = new WarnOnUseElementX( |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 } | 1025 } |
| 1019 | 1026 |
| 1020 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this); | 1027 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this); |
| 1021 } | 1028 } |
| 1022 | 1029 |
| 1023 class PrefixElementX extends ElementX implements PrefixElement { | 1030 class PrefixElementX extends ElementX implements PrefixElement { |
| 1024 Token firstPosition; | 1031 Token firstPosition; |
| 1025 | 1032 |
| 1026 final ImportScope importScope = new ImportScope(); | 1033 final ImportScope importScope = new ImportScope(); |
| 1027 | 1034 |
| 1028 bool isDeferred = false; | 1035 bool get isDeferred => _deferredImport != null; |
| 1036 |
| 1037 // Only needed for deferred imports. |
| 1038 Import _deferredImport; |
| 1039 Import get deferredImport => _deferredImport; |
| 1029 | 1040 |
| 1030 PrefixElementX(String prefix, Element enclosing, this.firstPosition) | 1041 PrefixElementX(String prefix, Element enclosing, this.firstPosition) |
| 1031 : super(prefix, ElementKind.PREFIX, enclosing); | 1042 : super(prefix, ElementKind.PREFIX, enclosing); |
| 1032 | 1043 |
| 1033 Element lookupLocalMember(String memberName) => importScope[memberName]; | 1044 Element lookupLocalMember(String memberName) => importScope[memberName]; |
| 1034 | 1045 |
| 1035 DartType computeType(Compiler compiler) => compiler.types.dynamicType; | 1046 DartType computeType(Compiler compiler) => compiler.types.dynamicType; |
| 1036 | 1047 |
| 1037 Token position() => firstPosition; | 1048 Token position() => firstPosition; |
| 1038 | 1049 |
| 1039 void addImport(Element element, Import import, DiagnosticListener listener) { | 1050 void addImport(Element element, Import import, DiagnosticListener listener) { |
| 1040 importScope.addImport(this, element, import, listener); | 1051 importScope.addImport(this, element, import, listener); |
| 1041 } | 1052 } |
| 1042 | 1053 |
| 1043 accept(ElementVisitor visitor) => visitor.visitPrefixElement(this); | 1054 accept(ElementVisitor visitor) => visitor.visitPrefixElement(this); |
| 1044 | 1055 |
| 1045 void markAsDeferred() { | 1056 void markAsDeferred(Import deferredImport) { |
| 1046 isDeferred = true; | 1057 _deferredImport = deferredImport; |
| 1047 } | 1058 } |
| 1048 } | 1059 } |
| 1049 | 1060 |
| 1050 class TypedefElementX extends ElementX | 1061 class TypedefElementX extends ElementX |
| 1051 with AnalyzableElement, TypeDeclarationElementX<TypedefType> | 1062 with AnalyzableElement, TypeDeclarationElementX<TypedefType> |
| 1052 implements TypedefElement { | 1063 implements TypedefElement { |
| 1053 Typedef cachedNode; | 1064 Typedef cachedNode; |
| 1054 | 1065 |
| 1055 /** | 1066 /** |
| 1056 * The type annotation which defines this typedef. | 1067 * The type annotation which defines this typedef. |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 | 1659 |
| 1649 bool get isAbstract { | 1660 bool get isAbstract { |
| 1650 return !modifiers.isExternal() && | 1661 return !modifiers.isExternal() && |
| 1651 (isFunction() || isAccessor()) && | 1662 (isFunction() || isAccessor()) && |
| 1652 _hasNoBody; | 1663 _hasNoBody; |
| 1653 } | 1664 } |
| 1654 | 1665 |
| 1655 accept(ElementVisitor visitor) => visitor.visitFunctionElement(this); | 1666 accept(ElementVisitor visitor) => visitor.visitFunctionElement(this); |
| 1656 } | 1667 } |
| 1657 | 1668 |
| 1669 class DeferredLoaderGetterElementX extends FunctionElementX { |
| 1670 |
| 1671 final PrefixElement prefix; |
| 1672 |
| 1673 DeferredLoaderGetterElementX(PrefixElement prefix) |
| 1674 : this.prefix = prefix, |
| 1675 super("loadLibrary", |
| 1676 ElementKind.FUNCTION, |
| 1677 Modifiers.EMPTY, |
| 1678 prefix, true); |
| 1679 |
| 1680 FunctionSignature computeSignature(Compiler compiler) { |
| 1681 if (functionSignature != null) return functionSignature; |
| 1682 compiler.withCurrentElement(this, () { |
| 1683 DartType inner = new FunctionType(this, compiler.types.dynamicType); |
| 1684 functionSignature = new FunctionSignatureX(const Link(), |
| 1685 const Link(), 0, 0, false, inner); |
| 1686 }); |
| 1687 return functionSignature; |
| 1688 } |
| 1689 |
| 1690 bool isMember() => false; |
| 1691 |
| 1692 bool isForeign(Compiler compiler) => true; |
| 1693 |
| 1694 bool get isSynthesized => true; |
| 1695 |
| 1696 bool isFunction() => false; |
| 1697 |
| 1698 bool isDeferredLoaderGetter() => true; |
| 1699 |
| 1700 bool isGetter() => true; |
| 1701 |
| 1702 // By having position null, the enclosing elements location is printed in |
| 1703 // error messages. |
| 1704 Token position() => null; |
| 1705 } |
| 1706 |
| 1658 class ConstructorBodyElementX extends FunctionElementX | 1707 class ConstructorBodyElementX extends FunctionElementX |
| 1659 implements ConstructorBodyElement { | 1708 implements ConstructorBodyElement { |
| 1660 FunctionElement constructor; | 1709 FunctionElement constructor; |
| 1661 | 1710 |
| 1662 ConstructorBodyElementX(FunctionElement constructor) | 1711 ConstructorBodyElementX(FunctionElement constructor) |
| 1663 : this.constructor = constructor, | 1712 : this.constructor = constructor, |
| 1664 super(constructor.name, | 1713 super(constructor.name, |
| 1665 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, | 1714 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, |
| 1666 Modifiers.EMPTY, | 1715 Modifiers.EMPTY, |
| 1667 constructor.enclosingElement, false) { | 1716 constructor.enclosingElement, false) { |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2570 | 2619 |
| 2571 ParameterMetadataAnnotation(Metadata this.metadata); | 2620 ParameterMetadataAnnotation(Metadata this.metadata); |
| 2572 | 2621 |
| 2573 Node parseNode(DiagnosticListener listener) => metadata.expression; | 2622 Node parseNode(DiagnosticListener listener) => metadata.expression; |
| 2574 | 2623 |
| 2575 Token get beginToken => metadata.getBeginToken(); | 2624 Token get beginToken => metadata.getBeginToken(); |
| 2576 | 2625 |
| 2577 Token get endToken => metadata.getEndToken(); | 2626 Token get endToken => metadata.getEndToken(); |
| 2578 } | 2627 } |
| 2579 | 2628 |
| OLD | NEW |