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/resolution.dart' show | 7 import '../common/resolution.dart' show |
8 Resolution, | 8 Resolution, |
9 Parsing; | 9 Parsing; |
10 import '../compiler.dart' show | 10 import '../compiler.dart' show |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 ? enclosingElement.name | 234 ? enclosingElement.name |
235 : '${enclosingElement.kind}?'; | 235 : '${enclosingElement.kind}?'; |
236 return '$kind($holderName#${nameText})'; | 236 return '$kind($holderName#${nameText})'; |
237 } else { | 237 } else { |
238 return '$kind(${nameText})'; | 238 return '$kind(${nameText})'; |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 String _fixedBackendName = null; | 242 String _fixedBackendName = null; |
243 bool _isNative = false; | 243 bool _isNative = false; |
244 bool get isNative => _isNative; | 244 String _jsInteropName = null; |
245 bool get hasFixedBackendName => _fixedBackendName != null; | 245 bool _isJsInterop = false; |
246 String get fixedBackendName => _fixedBackendName; | 246 bool get isJsInterop => _isJsInterop; |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
+ dartdoc
Jacob
2015/10/13 01:19:23
Done.
| |
247 String get jsInteropName => _jsInteropName; | |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
+ dartdoc
Jacob
2015/10/13 01:19:23
Done.
| |
248 | |
249 void setHasJsInterop() { | |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
setIsJsInterop? (to match the field name)
markAsJ
Jacob
2015/10/13 01:19:22
Done.
| |
250 _isJsInterop = true; | |
251 } | |
252 | |
253 void setJsInteropName(String name) { | |
254 assert(invariant(this, | |
255 _isJsInterop, | |
256 message: 'Element is not js interop but given a js interop name.')); | |
257 _jsInteropName = name; | |
258 } | |
259 | |
260 bool get isNative => _isNative || isJsInterop; | |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
questions/comments here:
- now that this is more
Jacob
2015/10/13 01:19:23
There are a ton of places where the code paths are
| |
261 bool get hasFixedBackendName => fixedBackendName != null || isJsInterop; | |
262 | |
263 String _jsNameHelper(Element e) { | |
264 if (e.jsInteropName != null && e.jsInteropName.isNotEmpty) | |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
style nit: add braces
Jacob
2015/10/13 01:19:22
Done.
| |
265 return e.jsInteropName; | |
266 return e.isLibrary ? 'self' : e.name; | |
267 } | |
268 | |
269 String get fixedBackendName { | |
270 if (_fixedBackendName != null) return _fixedBackendName; | |
271 if (isJsInterop) { | |
272 // If an element isJsInterop but _isJsInterop is false that means it is | |
273 // considered interop as the parent class is interop. | |
274 assert(invariant(this, | |
275 !(_isJsInterop && _jsInteropName == null), | |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
should the check here also involve isConstructor l
Jacob
2015/10/13 01:19:23
done.
| |
276 message: 'Element is js interop but js interop name has not yet been' | |
277 'computed.')); | |
sra1
2015/10/06 21:42:17
I'd try and indent this like
message:
' cccc
Jacob
2015/10/13 01:19:22
Done.
| |
278 return _jsNameHelper(isConstructor ? enclosingClass : this); | |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
could we memoize the result by writting _fixedBack
Jacob
2015/10/13 01:19:22
might as well. done.
| |
279 } | |
280 return null; | |
281 } | |
282 | |
247 // Marks this element as a native element. | 283 // Marks this element as a native element. |
248 void setNative(String name) { | 284 void setNative(String name) { |
249 _isNative = true; | 285 _isNative = true; |
250 _fixedBackendName = name; | 286 _fixedBackendName = name; |
251 } | 287 } |
252 | 288 |
253 FunctionElement asFunctionElement() => null; | 289 FunctionElement asFunctionElement() => null; |
254 | 290 |
255 bool get isAbstract => modifiers.isAbstract; | 291 bool get isAbstract => modifiers.isAbstract; |
256 | 292 |
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1979 functionSignatureCache = resolution.resolveSignature(this); | 2015 functionSignatureCache = resolution.resolveSignature(this); |
1980 return functionSignatureCache; | 2016 return functionSignatureCache; |
1981 } | 2017 } |
1982 | 2018 |
1983 FunctionSignature get functionSignature { | 2019 FunctionSignature get functionSignature { |
1984 assert(invariant(this, functionSignatureCache != null, | 2020 assert(invariant(this, functionSignatureCache != null, |
1985 message: "Function signature has not been computed for $this.")); | 2021 message: "Function signature has not been computed for $this.")); |
1986 return functionSignatureCache; | 2022 return functionSignatureCache; |
1987 } | 2023 } |
1988 | 2024 |
2025 /** | |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
nit, let's use /// (dart2js has both, but I'm tryi
Jacob
2015/10/13 01:19:22
Done.
| |
2026 * An function is part of JsInterop if it has a jsInteropName annotation or it | |
2027 * is an external class or top level member of a class or library tagged as | |
2028 * JsInterop. | |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
consider splitting the sentence into a set of bull
Jacob
2015/10/13 01:19:22
Done.
| |
2029 */ | |
2030 bool get isJsInterop { | |
2031 if (!isExternal) return false; | |
2032 | |
2033 if (super.isJsInterop) return true; | |
2034 if (isClassMember) return contextClass.isJsInterop; | |
2035 if (isTopLevel) return library.isJsInterop; | |
2036 return false; | |
2037 } | |
2038 | |
1989 List<ParameterElement> get parameters { | 2039 List<ParameterElement> get parameters { |
1990 // TODO(johnniwinther): Store the list directly, possibly by using List | 2040 // TODO(johnniwinther): Store the list directly, possibly by using List |
1991 // instead of Link in FunctionSignature. | 2041 // instead of Link in FunctionSignature. |
1992 List<ParameterElement> list = <ParameterElement>[]; | 2042 List<ParameterElement> list = <ParameterElement>[]; |
1993 functionSignature.forEachParameter((e) => list.add(e)); | 2043 functionSignature.forEachParameter((e) => list.add(e)); |
1994 return list; | 2044 return list; |
1995 } | 2045 } |
1996 | 2046 |
1997 FunctionType computeType(Resolution resolution) { | 2047 FunctionType computeType(Resolution resolution) { |
1998 if (typeCache != null) return typeCache; | 2048 if (typeCache != null) return typeCache; |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2598 } | 2648 } |
2599 | 2649 |
2600 void forEachBackendMember(void f(Element member)) { | 2650 void forEachBackendMember(void f(Element member)) { |
2601 backendMembers.forEach(f); | 2651 backendMembers.forEach(f); |
2602 } | 2652 } |
2603 | 2653 |
2604 bool implementsFunction(Compiler compiler) { | 2654 bool implementsFunction(Compiler compiler) { |
2605 return asInstanceOf(compiler.functionClass) != null || callType != null; | 2655 return asInstanceOf(compiler.functionClass) != null || callType != null; |
2606 } | 2656 } |
2607 | 2657 |
2608 bool get isNative => nativeTagInfo != null; | 2658 bool get isNative => nativeTagInfo != null || isJsInterop; |
Siggi Cherem (dart-lang)
2015/10/06 22:38:01
same here
Jacob
2015/10/13 01:19:23
The comment for the superclass still applies here
| |
2609 | 2659 |
2610 void setNative(String name) { | 2660 void setNative(String name) { |
2611 // TODO(johnniwinther): Assert that this is only called once. The memory | 2661 // TODO(johnniwinther): Assert that this is only called once. The memory |
2612 // compiler copies pre-processed elements into a new compiler through | 2662 // compiler copies pre-processed elements into a new compiler through |
2613 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this | 2663 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this |
2614 // method. | 2664 // method. |
2615 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, | 2665 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, |
2616 message: "Native tag info set inconsistently on $this: " | 2666 message: "Native tag info set inconsistently on $this: " |
2617 "Existing name '$nativeTagInfo', new name '$name'.")); | 2667 "Existing name '$nativeTagInfo', new name '$name'.")); |
2618 nativeTagInfo = name; | 2668 nativeTagInfo = name; |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3103 AstElement get definingElement; | 3153 AstElement get definingElement; |
3104 | 3154 |
3105 bool get hasResolvedAst => definingElement.hasTreeElements; | 3155 bool get hasResolvedAst => definingElement.hasTreeElements; |
3106 | 3156 |
3107 ResolvedAst get resolvedAst { | 3157 ResolvedAst get resolvedAst { |
3108 return new ResolvedAst(declaration, | 3158 return new ResolvedAst(declaration, |
3109 definingElement.node, definingElement.treeElements); | 3159 definingElement.node, definingElement.treeElements); |
3110 } | 3160 } |
3111 | 3161 |
3112 } | 3162 } |
OLD | NEW |