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 _jsNameHelper(e) { | |
|
sra1
2015/10/01 20:55:27
Element e
or some more specific type.
Jacob
2015/10/02 20:08:15
Done.
| |
| 238 if (e._jsInteropName != null && e._jsInteropName.isNotEmpty) | |
| 239 return e._jsInteropName; | |
| 240 return e.isLibrary ? 'self' : e.name; | |
| 241 } | |
| 242 | |
| 243 String get fixedBackendName { | |
| 244 if (_fixedBackendName != null) return _fixedBackendName; | |
| 245 if (isJsInterop) { | |
| 246 return _jsNameHelper(isConstructor ? enclosingClass : this); | |
| 247 } | |
| 248 return null; | |
| 249 } | |
| 250 | |
| 251 String get fixedBackendReceiver { | |
|
sra1
2015/10/01 20:55:27
All this 'backend' logic must be in the js_backend
Jacob
2015/10/02 20:08:15
moved to js_backend/namer.dart
| |
| 252 if (!isJsInterop) return null; | |
| 253 if (isInstanceMember) return 'this'; | |
| 254 if (isConstructor) return enclosingClass.fixedBackendReceiver; | |
| 255 if (isLibrary) return 'self'; | |
| 256 var sb = new StringBuffer(); | |
| 257 sb..write(_jsNameHelper(library)); | |
| 258 | |
| 259 if (enclosingClass != null && enclosingClass != this) { | |
| 260 sb..write('.')..write(_jsNameHelper(enclosingClass)); | |
| 261 } | |
| 262 return sb.toString(); | |
|
sra1
2015/10/01 20:55:27
So what is this computing?
Jacob
2015/10/02 20:08:15
discussed offline and changed name to
fixedBacken
| |
| 263 } | |
| 264 | |
| 231 // Marks this element as a native element. | 265 // Marks this element as a native element. |
| 232 void setNative(String name) { | 266 void setNative(String name) { |
| 233 _isNative = true; | 267 _isNative = true; |
| 234 _fixedBackendName = name; | 268 _fixedBackendName = name; |
| 235 } | 269 } |
| 236 | 270 |
| 237 FunctionElement asFunctionElement() => null; | 271 FunctionElement asFunctionElement() => null; |
| 238 | 272 |
| 239 bool get isAbstract => modifiers.isAbstract; | 273 bool get isAbstract => modifiers.isAbstract; |
| 240 | 274 |
| (...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1795 }); | 1829 }); |
| 1796 return functionSignatureCache; | 1830 return functionSignatureCache; |
| 1797 } | 1831 } |
| 1798 | 1832 |
| 1799 FunctionSignature get functionSignature { | 1833 FunctionSignature get functionSignature { |
| 1800 assert(invariant(this, functionSignatureCache != null, | 1834 assert(invariant(this, functionSignatureCache != null, |
| 1801 message: "Function signature has not been computed for $this.")); | 1835 message: "Function signature has not been computed for $this.")); |
| 1802 return functionSignatureCache; | 1836 return functionSignatureCache; |
| 1803 } | 1837 } |
| 1804 | 1838 |
| 1839 /** | |
| 1840 * An function is part of JsInterop if it has a jsInteropName annotation or it | |
| 1841 * is an external class or top level member of a class or library tagged as | |
| 1842 * JsInterop. | |
| 1843 */ | |
| 1844 bool get isJsInterop { | |
| 1845 if (!isExternal) return false; | |
| 1846 | |
| 1847 if (super.isJsInterop) return true; | |
| 1848 if (isClassMember) return contextClass.isJsInterop; | |
| 1849 if (isTopLevel) return library.isJsInterop; | |
| 1850 return false; | |
| 1851 } | |
| 1852 | |
| 1805 List<ParameterElement> get parameters { | 1853 List<ParameterElement> get parameters { |
| 1806 // TODO(johnniwinther): Store the list directly, possibly by using List | 1854 // TODO(johnniwinther): Store the list directly, possibly by using List |
| 1807 // instead of Link in FunctionSignature. | 1855 // instead of Link in FunctionSignature. |
| 1808 List<ParameterElement> list = <ParameterElement>[]; | 1856 List<ParameterElement> list = <ParameterElement>[]; |
| 1809 functionSignature.forEachParameter((e) => list.add(e)); | 1857 functionSignature.forEachParameter((e) => list.add(e)); |
| 1810 return list; | 1858 return list; |
| 1811 } | 1859 } |
| 1812 | 1860 |
| 1813 FunctionType computeType(Compiler compiler) { | 1861 FunctionType computeType(Compiler compiler) { |
| 1814 if (typeCache != null) return typeCache; | 1862 if (typeCache != null) return typeCache; |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2412 } | 2460 } |
| 2413 | 2461 |
| 2414 void forEachBackendMember(void f(Element member)) { | 2462 void forEachBackendMember(void f(Element member)) { |
| 2415 backendMembers.forEach(f); | 2463 backendMembers.forEach(f); |
| 2416 } | 2464 } |
| 2417 | 2465 |
| 2418 bool implementsFunction(Compiler compiler) { | 2466 bool implementsFunction(Compiler compiler) { |
| 2419 return asInstanceOf(compiler.functionClass) != null || callType != null; | 2467 return asInstanceOf(compiler.functionClass) != null || callType != null; |
| 2420 } | 2468 } |
| 2421 | 2469 |
| 2422 bool get isNative => nativeTagInfo != null; | 2470 bool get isNative => nativeTagInfo != null || isJsInterop; |
| 2423 | 2471 |
| 2424 void setNative(String name) { | 2472 void setNative(String name) { |
| 2425 // TODO(johnniwinther): Assert that this is only called once. The memory | 2473 // TODO(johnniwinther): Assert that this is only called once. The memory |
| 2426 // compiler copies pre-processed elements into a new compiler through | 2474 // compiler copies pre-processed elements into a new compiler through |
| 2427 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this | 2475 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this |
| 2428 // method. | 2476 // method. |
| 2429 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, | 2477 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, |
| 2430 message: "Native tag info set inconsistently on $this: " | 2478 message: "Native tag info set inconsistently on $this: " |
| 2431 "Existing name '$nativeTagInfo', new name '$name'.")); | 2479 "Existing name '$nativeTagInfo', new name '$name'.")); |
| 2432 nativeTagInfo = name; | 2480 nativeTagInfo = name; |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2914 AstElement get definingElement; | 2962 AstElement get definingElement; |
| 2915 | 2963 |
| 2916 bool get hasResolvedAst => definingElement.hasTreeElements; | 2964 bool get hasResolvedAst => definingElement.hasTreeElements; |
| 2917 | 2965 |
| 2918 ResolvedAst get resolvedAst { | 2966 ResolvedAst get resolvedAst { |
| 2919 return new ResolvedAst(declaration, | 2967 return new ResolvedAst(declaration, |
| 2920 definingElement.node, definingElement.treeElements); | 2968 definingElement.node, definingElement.treeElements); |
| 2921 } | 2969 } |
| 2922 | 2970 |
| 2923 } | 2971 } |
| OLD | NEW |