Chromium Code Reviews| 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 '../compiler.dart' show | 7 import '../compiler.dart' show |
| 8 Compiler; | 8 Compiler; |
| 9 import '../constants/constant_constructors.dart'; | 9 import '../constants/constant_constructors.dart'; |
| 10 import '../constants/constructors.dart'; | 10 import '../constants/constructors.dart'; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 ? enclosingElement.name | 218 ? enclosingElement.name |
| 219 : '${enclosingElement.kind}?'; | 219 : '${enclosingElement.kind}?'; |
| 220 return '$kind($holderName#${nameText})'; | 220 return '$kind($holderName#${nameText})'; |
| 221 } else { | 221 } else { |
| 222 return '$kind(${nameText})'; | 222 return '$kind(${nameText})'; |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 String _fixedBackendName = null; | 226 String _fixedBackendName = null; |
| 227 bool _isNative = false; | 227 bool _isNative = false; |
| 228 bool get isNative => _isNative; | 228 String _jsInteropName = null; |
| 229 bool get hasFixedBackendName => _fixedBackendName != null; | 229 |
| 230 String get fixedBackendName => _fixedBackendName; | 230 bool get isJsInterop => _jsInteropName != null; |
| 231 | |
| 232 void setJsInterop(String name) { _jsInteropName = name; } | |
| 233 | |
| 234 bool get isNative => _isNative || isJsInterop; | |
| 235 bool get hasFixedBackendName => fixedBackendName != null || isJsInterop; | |
| 236 | |
| 237 String get fixedBackendName { | |
| 238 if (_fixedBackendName != null) return _fixedBackendName; | |
| 239 if (isJsInterop) { | |
| 240 String nameHelper(e) { | |
| 241 if (e._jsInteropName != null && e._jsInteropName.isNotEmpty) | |
| 242 return e._jsInteropName; | |
| 243 return e.isLibrary ? 'self' : e.name; | |
| 244 } | |
| 245 | |
| 246 var sb = new StringBuffer(); | |
| 247 if (!isLibrary && !isInstanceMember) { | |
| 248 sb..write(nameHelper(library))..write('.'); | |
| 249 if (enclosingClass != null && enclosingClass != this) { | |
| 250 sb.write(nameHelper(enclosingClass)); | |
| 251 if (!isConstructor) sb.write('.'); | |
| 252 } | |
| 253 } | |
| 254 if (!isConstructor) sb.write(nameHelper(this)); | |
|
Siggi Cherem (dart-lang)
2015/09/18 20:34:10
are named constructors not supported?
Jacob
2015/10/01 00:47:33
they are supported.
Suppose you have a JavaScript
| |
| 255 return sb.toString(); | |
| 256 } | |
| 257 return null; | |
| 258 } | |
| 259 | |
| 231 // Marks this element as a native element. | 260 // Marks this element as a native element. |
| 232 void setNative(String name) { | 261 void setNative(String name) { |
| 233 _isNative = true; | 262 _isNative = true; |
| 234 _fixedBackendName = name; | 263 _fixedBackendName = name; |
| 235 } | 264 } |
| 236 | 265 |
| 237 FunctionElement asFunctionElement() => null; | 266 FunctionElement asFunctionElement() => null; |
| 238 | 267 |
| 239 bool get isAbstract => modifiers.isAbstract; | 268 bool get isAbstract => modifiers.isAbstract; |
| 240 | 269 |
| (...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1795 }); | 1824 }); |
| 1796 return functionSignatureCache; | 1825 return functionSignatureCache; |
| 1797 } | 1826 } |
| 1798 | 1827 |
| 1799 FunctionSignature get functionSignature { | 1828 FunctionSignature get functionSignature { |
| 1800 assert(invariant(this, functionSignatureCache != null, | 1829 assert(invariant(this, functionSignatureCache != null, |
| 1801 message: "Function signature has not been computed for $this.")); | 1830 message: "Function signature has not been computed for $this.")); |
| 1802 return functionSignatureCache; | 1831 return functionSignatureCache; |
| 1803 } | 1832 } |
| 1804 | 1833 |
| 1834 /** | |
| 1835 * An function is part of JsInterop if it has a jsInteropName annotation or it | |
| 1836 * is an external class or top level member of a class or library tagged as | |
| 1837 * JsInterop. | |
| 1838 */ | |
| 1839 bool get isJsInterop { | |
| 1840 if (super.isJsInterop) return true; | |
|
Siggi Cherem (dart-lang)
2015/09/18 20:34:10
are there any cases where this is true if the two
Jacob
2015/10/01 00:47:33
yes. super.isJsInterop checks whether the member i
| |
| 1841 if (isClassMember) return contextClass.isJsInterop && isExternal; | |
|
Siggi Cherem (dart-lang)
2015/09/18 20:34:10
it might be worth checking for isExternal upfront,
Jacob
2015/10/01 00:47:33
done.
| |
| 1842 if (isTopLevel) return library.isJsInterop && isExternal; | |
| 1843 return false; | |
| 1844 } | |
| 1845 | |
| 1805 List<ParameterElement> get parameters { | 1846 List<ParameterElement> get parameters { |
| 1806 // TODO(johnniwinther): Store the list directly, possibly by using List | 1847 // TODO(johnniwinther): Store the list directly, possibly by using List |
| 1807 // instead of Link in FunctionSignature. | 1848 // instead of Link in FunctionSignature. |
| 1808 List<ParameterElement> list = <ParameterElement>[]; | 1849 List<ParameterElement> list = <ParameterElement>[]; |
| 1809 functionSignature.forEachParameter((e) => list.add(e)); | 1850 functionSignature.forEachParameter((e) => list.add(e)); |
| 1810 return list; | 1851 return list; |
| 1811 } | 1852 } |
| 1812 | 1853 |
| 1813 FunctionType computeType(Compiler compiler) { | 1854 FunctionType computeType(Compiler compiler) { |
| 1814 if (typeCache != null) return typeCache; | 1855 if (typeCache != null) return typeCache; |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2412 } | 2453 } |
| 2413 | 2454 |
| 2414 void forEachBackendMember(void f(Element member)) { | 2455 void forEachBackendMember(void f(Element member)) { |
| 2415 backendMembers.forEach(f); | 2456 backendMembers.forEach(f); |
| 2416 } | 2457 } |
| 2417 | 2458 |
| 2418 bool implementsFunction(Compiler compiler) { | 2459 bool implementsFunction(Compiler compiler) { |
| 2419 return asInstanceOf(compiler.functionClass) != null || callType != null; | 2460 return asInstanceOf(compiler.functionClass) != null || callType != null; |
| 2420 } | 2461 } |
| 2421 | 2462 |
| 2422 bool get isNative => nativeTagInfo != null; | 2463 bool get isNative => nativeTagInfo != null || isJsInterop; |
| 2423 | 2464 |
| 2424 void setNative(String name) { | 2465 void setNative(String name) { |
| 2425 // TODO(johnniwinther): Assert that this is only called once. The memory | 2466 // TODO(johnniwinther): Assert that this is only called once. The memory |
| 2426 // compiler copies pre-processed elements into a new compiler through | 2467 // compiler copies pre-processed elements into a new compiler through |
| 2427 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this | 2468 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this |
| 2428 // method. | 2469 // method. |
| 2429 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, | 2470 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, |
| 2430 message: "Native tag info set inconsistently on $this: " | 2471 message: "Native tag info set inconsistently on $this: " |
| 2431 "Existing name '$nativeTagInfo', new name '$name'.")); | 2472 "Existing name '$nativeTagInfo', new name '$name'.")); |
| 2432 nativeTagInfo = name; | 2473 nativeTagInfo = name; |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2914 AstElement get definingElement; | 2955 AstElement get definingElement; |
| 2915 | 2956 |
| 2916 bool get hasResolvedAst => definingElement.hasTreeElements; | 2957 bool get hasResolvedAst => definingElement.hasTreeElements; |
| 2917 | 2958 |
| 2918 ResolvedAst get resolvedAst { | 2959 ResolvedAst get resolvedAst { |
| 2919 return new ResolvedAst(declaration, | 2960 return new ResolvedAst(declaration, |
| 2920 definingElement.node, definingElement.treeElements); | 2961 definingElement.node, definingElement.treeElements); |
| 2921 } | 2962 } |
| 2922 | 2963 |
| 2923 } | 2964 } |
| OLD | NEW |