| 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 '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show | 8 import '../common/resolution.dart' show |
| 9 Resolution, | 9 Resolution, |
| 10 Parsing; | 10 Parsing; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 if (enclosingElement != null && !isTopLevel) { | 225 if (enclosingElement != null && !isTopLevel) { |
| 226 String holderName = enclosingElement.name != null | 226 String holderName = enclosingElement.name != null |
| 227 ? enclosingElement.name | 227 ? enclosingElement.name |
| 228 : '${enclosingElement.kind}?'; | 228 : '${enclosingElement.kind}?'; |
| 229 return '$kind($holderName#${nameText})'; | 229 return '$kind($holderName#${nameText})'; |
| 230 } else { | 230 } else { |
| 231 return '$kind(${nameText})'; | 231 return '$kind(${nameText})'; |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 String _fixedBackendName = null; | |
| 236 bool _isNative = false; | |
| 237 String _jsInteropName = null; | |
| 238 bool _isJsInterop = false; | |
| 239 | |
| 240 /// Whether the element is implemented via typed JavaScript interop. | |
| 241 bool get isJsInterop => _isJsInterop; | |
| 242 /// JavaScript name for the element if it is implemented via typed JavaScript | |
| 243 /// interop. | |
| 244 String get jsInteropName => _jsInteropName; | |
| 245 | |
| 246 void markAsJsInterop() { | |
| 247 _isJsInterop = true; | |
| 248 } | |
| 249 | |
| 250 void setJsInteropName(String name) { | |
| 251 assert(invariant(this, | |
| 252 _isJsInterop, | |
| 253 message: 'Element is not js interop but given a js interop name.')); | |
| 254 _jsInteropName = name; | |
| 255 } | |
| 256 | |
| 257 /// Whether the element corresponds to a native JavaScript construct either | |
| 258 /// through the existing [setNative] mechanism which is only allowed | |
| 259 /// for internal libraries or via the new typed JavaScriptInterop mechanism | |
| 260 /// which is allowed for user libraries. | |
| 261 bool get isNative => _isNative || isJsInterop; | |
| 262 bool get hasFixedBackendName => fixedBackendName != null || isJsInterop; | |
| 263 | |
| 264 String _jsNameHelper(Element e) { | |
| 265 assert(invariant(this, | |
| 266 !(_isJsInterop && _jsInteropName == null), | |
| 267 message: | |
| 268 'Element is js interop but js interop name has not yet been' | |
| 269 'computed.')); | |
| 270 if (e.jsInteropName != null && e.jsInteropName.isNotEmpty) { | |
| 271 return e.jsInteropName; | |
| 272 } | |
| 273 return e.isLibrary ? 'self' : e.name; | |
| 274 } | |
| 275 | |
| 276 String get fixedBackendName { | |
| 277 if (_fixedBackendName == null && isJsInterop) { | |
| 278 // If an element isJsInterop but _isJsInterop is false that means it is | |
| 279 // considered interop as the parent class is interop. | |
| 280 _fixedBackendName = _jsNameHelper(isConstructor ? enclosingClass : this); | |
| 281 } | |
| 282 return _fixedBackendName; | |
| 283 } | |
| 284 | |
| 285 // Marks this element as a native element. | |
| 286 void setNative(String name) { | |
| 287 _isNative = true; | |
| 288 _fixedBackendName = name; | |
| 289 } | |
| 290 | |
| 291 FunctionElement asFunctionElement() => null; | 235 FunctionElement asFunctionElement() => null; |
| 292 | 236 |
| 293 bool get isAbstract => modifiers.isAbstract; | 237 bool get isAbstract => modifiers.isAbstract; |
| 294 | 238 |
| 295 bool get hasTreeElements => analyzableElement.hasTreeElements; | 239 bool get hasTreeElements => analyzableElement.hasTreeElements; |
| 296 | 240 |
| 297 TreeElements get treeElements => analyzableElement.treeElements; | 241 TreeElements get treeElements => analyzableElement.treeElements; |
| 298 | 242 |
| 299 AnalyzableElement get analyzableElement { | 243 AnalyzableElement get analyzableElement { |
| 300 Element element = outermostEnclosingMemberOrTopLevel; | 244 Element element = outermostEnclosingMemberOrTopLevel; |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 | 991 |
| 1048 /// True if the constructing script was synthesized. | 992 /// True if the constructing script was synthesized. |
| 1049 final bool isSynthesized; | 993 final bool isSynthesized; |
| 1050 | 994 |
| 1051 CompilationUnitElement entryCompilationUnit; | 995 CompilationUnitElement entryCompilationUnit; |
| 1052 Link<CompilationUnitElement> compilationUnits = | 996 Link<CompilationUnitElement> compilationUnits = |
| 1053 const Link<CompilationUnitElement>(); | 997 const Link<CompilationUnitElement>(); |
| 1054 LinkBuilder<LibraryTag> tagsBuilder = new LinkBuilder<LibraryTag>(); | 998 LinkBuilder<LibraryTag> tagsBuilder = new LinkBuilder<LibraryTag>(); |
| 1055 List<LibraryTag> tagsCache; | 999 List<LibraryTag> tagsCache; |
| 1056 LibraryName libraryTag; | 1000 LibraryName libraryTag; |
| 1057 bool canUseNative = false; | |
| 1058 Link<Element> localMembers = const Link<Element>(); | 1001 Link<Element> localMembers = const Link<Element>(); |
| 1059 final ScopeX localScope = new ScopeX(); | 1002 final ScopeX localScope = new ScopeX(); |
| 1060 final ImportScope importScope = new ImportScope(); | 1003 final ImportScope importScope = new ImportScope(); |
| 1061 | 1004 |
| 1062 /// A mapping from an imported element to the "import" tag. | 1005 /// A mapping from an imported element to the "import" tag. |
| 1063 final Importers importers = new Importers(); | 1006 final Importers importers = new Importers(); |
| 1064 | 1007 |
| 1065 /** | 1008 /** |
| 1066 * Link for elements exported either through export declarations or through | 1009 * Link for elements exported either through export declarations or through |
| 1067 * declaration. This field should not be accessed directly but instead through | 1010 * declaration. This field should not be accessed directly but instead through |
| (...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 | 1989 |
| 2047 void set functionSignature(FunctionSignature value) { | 1990 void set functionSignature(FunctionSignature value) { |
| 2048 // TODO(johnniwinther): Strengthen the invariant to `!hasFunctionSignature` | 1991 // TODO(johnniwinther): Strengthen the invariant to `!hasFunctionSignature` |
| 2049 // when checked mode checks are not enqueued eagerly. | 1992 // when checked mode checks are not enqueued eagerly. |
| 2050 assert(invariant(this, !hasFunctionSignature || type == value.type, | 1993 assert(invariant(this, !hasFunctionSignature || type == value.type, |
| 2051 message: "Function signature has already been computed for $this.")); | 1994 message: "Function signature has already been computed for $this.")); |
| 2052 _functionSignatureCache = value; | 1995 _functionSignatureCache = value; |
| 2053 typeCache = _functionSignatureCache.type; | 1996 typeCache = _functionSignatureCache.type; |
| 2054 } | 1997 } |
| 2055 | 1998 |
| 2056 /// An function is part of JsInterop in the following cases: | |
| 2057 /// * It has a jsInteropName annotation | |
| 2058 /// * It is external member of a class or library tagged as JsInterop. | |
| 2059 bool get isJsInterop { | |
| 2060 if (!isExternal) return false; | |
| 2061 | |
| 2062 if (super.isJsInterop) return true; | |
| 2063 if (isClassMember) return contextClass.isJsInterop; | |
| 2064 if (isTopLevel) return library.isJsInterop; | |
| 2065 return false; | |
| 2066 } | |
| 2067 | |
| 2068 List<ParameterElement> get parameters { | 1999 List<ParameterElement> get parameters { |
| 2069 // TODO(johnniwinther): Store the list directly, possibly by using List | 2000 // TODO(johnniwinther): Store the list directly, possibly by using List |
| 2070 // instead of Link in FunctionSignature. | 2001 // instead of Link in FunctionSignature. |
| 2071 List<ParameterElement> list = <ParameterElement>[]; | 2002 List<ParameterElement> list = <ParameterElement>[]; |
| 2072 functionSignature.forEachParameter((e) => list.add(e)); | 2003 functionSignature.forEachParameter((e) => list.add(e)); |
| 2073 return list; | 2004 return list; |
| 2074 } | 2005 } |
| 2075 | 2006 |
| 2076 FunctionType computeType(Resolution resolution) { | 2007 FunctionType computeType(Resolution resolution) { |
| 2077 if (typeCache != null) return typeCache; | 2008 if (typeCache != null) return typeCache; |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2550 AnalyzableElementX, | 2481 AnalyzableElementX, |
| 2551 ClassElementCommon, | 2482 ClassElementCommon, |
| 2552 TypeDeclarationElementX<InterfaceType>, | 2483 TypeDeclarationElementX<InterfaceType>, |
| 2553 PatchMixin<ClassElement>, | 2484 PatchMixin<ClassElement>, |
| 2554 ClassMemberMixin | 2485 ClassMemberMixin |
| 2555 implements ClassElement { | 2486 implements ClassElement { |
| 2556 final int id; | 2487 final int id; |
| 2557 | 2488 |
| 2558 DartType supertype; | 2489 DartType supertype; |
| 2559 Link<DartType> interfaces; | 2490 Link<DartType> interfaces; |
| 2560 String nativeTagInfo; | |
| 2561 int supertypeLoadState; | 2491 int supertypeLoadState; |
| 2562 int resolutionState; | 2492 int resolutionState; |
| 2563 bool isProxy = false; | 2493 bool isProxy = false; |
| 2564 bool hasIncompleteHierarchy = false; | 2494 bool hasIncompleteHierarchy = false; |
| 2565 | 2495 |
| 2566 // backendMembers are members that have been added by the backend to simplify | 2496 // backendMembers are members that have been added by the backend to simplify |
| 2567 // compilation. They don't have any user-side counter-part. | 2497 // compilation. They don't have any user-side counter-part. |
| 2568 Link<Element> backendMembers = const Link<Element>(); | 2498 Link<Element> backendMembers = const Link<Element>(); |
| 2569 | 2499 |
| 2570 OrderedTypeSet allSupertypesAndSelf; | 2500 OrderedTypeSet allSupertypesAndSelf; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2678 } | 2608 } |
| 2679 | 2609 |
| 2680 void forEachBackendMember(void f(Element member)) { | 2610 void forEachBackendMember(void f(Element member)) { |
| 2681 backendMembers.forEach(f); | 2611 backendMembers.forEach(f); |
| 2682 } | 2612 } |
| 2683 | 2613 |
| 2684 bool implementsFunction(Compiler compiler) { | 2614 bool implementsFunction(Compiler compiler) { |
| 2685 return asInstanceOf(compiler.functionClass) != null || callType != null; | 2615 return asInstanceOf(compiler.functionClass) != null || callType != null; |
| 2686 } | 2616 } |
| 2687 | 2617 |
| 2688 bool get isNative => nativeTagInfo != null || isJsInterop; | |
| 2689 | |
| 2690 void setNative(String name) { | |
| 2691 // TODO(johnniwinther): Assert that this is only called once. The memory | |
| 2692 // compiler copies pre-processed elements into a new compiler through | |
| 2693 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this | |
| 2694 // method. | |
| 2695 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, | |
| 2696 message: "Native tag info set inconsistently on $this: " | |
| 2697 "Existing name '$nativeTagInfo', new name '$name'.")); | |
| 2698 nativeTagInfo = name; | |
| 2699 } | |
| 2700 | |
| 2701 // TODO(johnniwinther): Remove these when issue 18630 is fixed. | 2618 // TODO(johnniwinther): Remove these when issue 18630 is fixed. |
| 2702 ClassElement get patch => super.patch; | 2619 ClassElement get patch => super.patch; |
| 2703 ClassElement get origin => super.origin; | 2620 ClassElement get origin => super.origin; |
| 2704 | 2621 |
| 2705 // A class declaration is defined by the declaration element. | 2622 // A class declaration is defined by the declaration element. |
| 2706 AstElement get definingElement => declaration; | 2623 AstElement get definingElement => declaration; |
| 2707 } | 2624 } |
| 2708 | 2625 |
| 2709 abstract class ClassElementX extends BaseClassElementX { | 2626 abstract class ClassElementX extends BaseClassElementX { |
| 2710 Link<Element> localMembersReversed = const Link<Element>(); | 2627 Link<Element> localMembersReversed = const Link<Element>(); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3183 AstElement get definingElement; | 3100 AstElement get definingElement; |
| 3184 | 3101 |
| 3185 bool get hasResolvedAst => definingElement.hasTreeElements; | 3102 bool get hasResolvedAst => definingElement.hasTreeElements; |
| 3186 | 3103 |
| 3187 ResolvedAst get resolvedAst { | 3104 ResolvedAst get resolvedAst { |
| 3188 return new ResolvedAst(declaration, | 3105 return new ResolvedAst(declaration, |
| 3189 definingElement.node, definingElement.treeElements); | 3106 definingElement.node, definingElement.treeElements); |
| 3190 } | 3107 } |
| 3191 | 3108 |
| 3192 } | 3109 } |
| OLD | NEW |