OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 | 2 |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 import 'dart:collection' show HashMap, HashSet; | 6 import 'dart:collection' show HashMap, HashSet; |
7 import 'dart:math' show min, max; | 7 import 'dart:math' show min, max; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
11 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 11 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
12 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; | 12 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
13 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 13 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
14 import 'package:analyzer/dart/element/element.dart'; | 14 import 'package:analyzer/dart/element/element.dart'; |
15 import 'package:analyzer/dart/element/type.dart'; | 15 import 'package:analyzer/dart/element/type.dart'; |
| 16 import 'package:analyzer/src/dart/analysis/driver.dart'; |
16 import 'package:analyzer/src/dart/ast/token.dart' show StringToken; | 17 import 'package:analyzer/src/dart/ast/token.dart' show StringToken; |
17 import 'package:analyzer/src/dart/element/element.dart' | 18 import 'package:analyzer/src/dart/element/element.dart' |
18 show FieldElementImpl, LocalVariableElementImpl; | 19 show FieldElementImpl, LocalVariableElementImpl; |
19 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; | 20 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; |
20 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 21 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
21 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | |
22 import 'package:analyzer/src/generated/resolver.dart' | 22 import 'package:analyzer/src/generated/resolver.dart' |
23 show TypeProvider, NamespaceBuilder; | 23 show NamespaceBuilder, TypeProvider; |
24 import 'package:analyzer/src/generated/type_system.dart' | 24 import 'package:analyzer/src/generated/type_system.dart' |
25 show StrongTypeSystemImpl; | 25 show StrongTypeSystemImpl; |
26 import 'package:analyzer/src/summary/idl.dart' show UnlinkedUnit; | 26 import 'package:analyzer/src/summary/idl.dart' show UnlinkedUnit; |
27 import 'package:analyzer/src/summary/link.dart' as summary_link; | 27 import 'package:analyzer/src/summary/link.dart' as summary_link; |
28 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 28 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
29 import 'package:analyzer/src/summary/summarize_ast.dart' | 29 import 'package:analyzer/src/summary/summarize_ast.dart' |
30 show serializeAstUnlinked; | 30 show serializeAstUnlinked; |
31 import 'package:analyzer/src/summary/summarize_elements.dart' | 31 import 'package:analyzer/src/summary/summarize_elements.dart' |
32 show PackageBundleAssembler; | 32 show PackageBundleAssembler; |
33 import 'package:analyzer/src/summary/summary_sdk.dart'; | 33 import 'package:analyzer/src/summary/summary_sdk.dart'; |
34 import 'package:analyzer/src/task/strong/ast_properties.dart' | 34 import 'package:analyzer/src/task/strong/ast_properties.dart' |
35 show isDynamicInvoke, setIsDynamicInvoke, getImplicitAssignmentCast; | 35 show isDynamicInvoke, setIsDynamicInvoke, getImplicitAssignmentCast; |
| 36 import 'package:meta/meta.dart'; |
36 import 'package:path/path.dart' show isWithin, relative, separator; | 37 import 'package:path/path.dart' show isWithin, relative, separator; |
37 | 38 |
38 import '../closure/closure_annotator.dart' show ClosureAnnotator; | 39 import '../closure/closure_annotator.dart' show ClosureAnnotator; |
39 import '../js_ast/js_ast.dart' as JS; | 40 import '../js_ast/js_ast.dart' as JS; |
40 import '../js_ast/js_ast.dart' show js; | 41 import '../js_ast/js_ast.dart' show js; |
41 import 'ast_builder.dart' show AstBuilder; | 42 import 'ast_builder.dart' show AstBuilder; |
42 import 'compiler.dart' show BuildUnit, CompilerOptions, JSModuleFile; | 43 import 'compiler.dart' show BuildUnit, CompilerOptions, JSModuleFile; |
43 import 'element_helpers.dart'; | 44 import 'element_helpers.dart'; |
44 import 'extension_types.dart' show ExtensionTypeSet; | 45 import 'extension_types.dart' show ExtensionTypeSet; |
45 import 'js_interop.dart'; | 46 import 'js_interop.dart'; |
(...skipping 17 matching lines...) Expand all Loading... |
63 /// Dart code, whenever this is possible to do in the generated code. | 64 /// Dart code, whenever this is possible to do in the generated code. |
64 // | 65 // |
65 // TODO(jmesserly): we should use separate visitors for statements and | 66 // TODO(jmesserly): we should use separate visitors for statements and |
66 // expressions. Declarations are handled directly, and many minor component | 67 // expressions. Declarations are handled directly, and many minor component |
67 // AST nodes aren't visited, so the visitor pattern isn't helping except for | 68 // AST nodes aren't visited, so the visitor pattern isn't helping except for |
68 // expressions (which result in JS.Expression) and statements | 69 // expressions (which result in JS.Expression) and statements |
69 // (which result in (JS.Statement). | 70 // (which result in (JS.Statement). |
70 class CodeGenerator extends Object | 71 class CodeGenerator extends Object |
71 with ClosureAnnotator, JsTypeRefCodegen, NullableTypeInference | 72 with ClosureAnnotator, JsTypeRefCodegen, NullableTypeInference |
72 implements AstVisitor<JS.Node> { | 73 implements AstVisitor<JS.Node> { |
73 final AnalysisContext context; | 74 final AnalysisDriver driver; |
74 final SummaryDataStore summaryData; | 75 final SummaryDataStore summaryData; |
75 | 76 |
76 final CompilerOptions options; | 77 final CompilerOptions options; |
77 final StrongTypeSystemImpl rules; | 78 final StrongTypeSystemImpl rules; |
78 | 79 |
79 /// The set of libraries we are currently compiling, and the temporaries used | 80 /// The set of libraries we are currently compiling, and the temporaries used |
80 /// to refer to them. | 81 /// to refer to them. |
81 /// | 82 /// |
82 /// We sometimes special case codegen for a single library, as it simplifies | 83 /// We sometimes special case codegen for a single library, as it simplifies |
83 /// name scoping requirements. | 84 /// name scoping requirements. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 new HashMap<LibraryElement, HashMap<String, JS.TemporaryId>>(); | 117 new HashMap<LibraryElement, HashMap<String, JS.TemporaryId>>(); |
117 final _initializingFormalTemps = | 118 final _initializingFormalTemps = |
118 new HashMap<ParameterElement, JS.TemporaryId>(); | 119 new HashMap<ParameterElement, JS.TemporaryId>(); |
119 | 120 |
120 JS.Identifier _extensionSymbolsModule; | 121 JS.Identifier _extensionSymbolsModule; |
121 JS.Identifier _runtimeModule; | 122 JS.Identifier _runtimeModule; |
122 final namedArgumentTemp = new JS.TemporaryId('opts'); | 123 final namedArgumentTemp = new JS.TemporaryId('opts'); |
123 | 124 |
124 final _hasDeferredSupertype = new HashSet<ClassElement>(); | 125 final _hasDeferredSupertype = new HashSet<ClassElement>(); |
125 | 126 |
126 /// The type provider from the current Analysis [context]. | 127 /// The type provider for the SDK. |
127 final TypeProvider types; | 128 final TypeProvider types; |
128 | 129 |
129 final LibraryElement dartCoreLibrary; | 130 final LibraryElement dartCoreLibrary; |
130 final LibraryElement dartJSLibrary; | 131 final LibraryElement dartJSLibrary; |
131 | 132 |
132 /// The dart:async `StreamIterator<>` type. | 133 /// The dart:async `StreamIterator<>` type. |
133 final InterfaceType _asyncStreamIterator; | 134 final InterfaceType _asyncStreamIterator; |
134 | 135 |
135 /// The dart:_interceptors JSArray element. | 136 /// The dart:_interceptors JSArray element. |
136 final ClassElement _jsArray; | 137 final ClassElement _jsArray; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 186 |
186 /// Information about virtual and overridden fields/getters/setters in the | 187 /// Information about virtual and overridden fields/getters/setters in the |
187 /// class we're currently compiling, or `null` if we aren't compiling a class. | 188 /// class we're currently compiling, or `null` if we aren't compiling a class. |
188 ClassPropertyModel _classProperties; | 189 ClassPropertyModel _classProperties; |
189 | 190 |
190 /// Information about virtual fields for all libraries in the current build | 191 /// Information about virtual fields for all libraries in the current build |
191 /// unit. | 192 /// unit. |
192 final virtualFields = new VirtualFieldModel(); | 193 final virtualFields = new VirtualFieldModel(); |
193 | 194 |
194 CodeGenerator( | 195 CodeGenerator( |
195 AnalysisContext c, this.summaryData, this.options, this._extensionTypes) | 196 this.driver, this.summaryData, this.options, this._extensionTypes, |
196 : context = c, | 197 {@required this.types, |
197 rules = new StrongTypeSystemImpl(c.typeProvider), | 198 @required LibraryElement coreLibrary, |
198 types = c.typeProvider, | 199 @required LibraryElement asyncLibrary, |
199 _asyncStreamIterator = | 200 @required LibraryElement interceptorsLibrary, |
200 _getLibrary(c, 'dart:async').getType('StreamIterator').type, | 201 @required LibraryElement internalLibrary, |
201 _jsArray = _getLibrary(c, 'dart:_interceptors').getType('JSArray'), | 202 @required LibraryElement jsLibrary}) |
202 interceptorClass = | 203 : rules = new StrongTypeSystemImpl(types), |
203 _getLibrary(c, 'dart:_interceptors').getType('Interceptor'), | 204 _asyncStreamIterator = asyncLibrary.getType('StreamIterator').type, |
204 dartCoreLibrary = _getLibrary(c, 'dart:core'), | 205 _jsArray = interceptorsLibrary.getType('JSArray'), |
205 boolClass = _getLibrary(c, 'dart:core').getType('bool'), | 206 interceptorClass = interceptorsLibrary.getType('Interceptor'), |
206 intClass = _getLibrary(c, 'dart:core').getType('int'), | 207 dartCoreLibrary = coreLibrary, |
207 numClass = _getLibrary(c, 'dart:core').getType('num'), | 208 boolClass = coreLibrary.getType('bool'), |
208 nullClass = _getLibrary(c, 'dart:core').getType('Null'), | 209 intClass = coreLibrary.getType('int'), |
209 objectClass = _getLibrary(c, 'dart:core').getType('Object'), | 210 numClass = coreLibrary.getType('num'), |
210 stringClass = _getLibrary(c, 'dart:core').getType('String'), | 211 nullClass = coreLibrary.getType('Null'), |
211 functionClass = _getLibrary(c, 'dart:core').getType('Function'), | 212 objectClass = coreLibrary.getType('Object'), |
212 privateSymbolClass = | 213 stringClass = coreLibrary.getType('String'), |
213 _getLibrary(c, 'dart:_internal').getType('PrivateSymbol'), | 214 functionClass = coreLibrary.getType('Function'), |
214 dartJSLibrary = _getLibrary(c, 'dart:js'); | 215 privateSymbolClass = internalLibrary.getType('PrivateSymbol'), |
| 216 dartJSLibrary = jsLibrary; |
215 | 217 |
216 Element get currentElement => _currentElements.last; | 218 Element get currentElement => _currentElements.last; |
217 | 219 |
218 LibraryElement get currentLibrary => currentElement.library; | 220 LibraryElement get currentLibrary => currentElement.library; |
219 | 221 |
220 /// The main entry point to JavaScript code generation. | 222 /// The main entry point to JavaScript code generation. |
221 /// | 223 /// |
222 /// Takes the metadata for the build unit, as well as resolved trees and | 224 /// Takes the metadata for the build unit, as well as resolved trees and |
223 /// errors, and computes the output module code and optionally the source map. | 225 /// errors, and computes the output module code and optionally the source map. |
224 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, | 226 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, |
(...skipping 10 matching lines...) Expand all Loading... |
235 return new JSModuleFile(unit.name, errors, options, module, dartApiSummary); | 237 return new JSModuleFile(unit.name, errors, options, module, dartApiSummary); |
236 } | 238 } |
237 | 239 |
238 List<int> _summarizeModule(List<CompilationUnit> units) { | 240 List<int> _summarizeModule(List<CompilationUnit> units) { |
239 if (!options.summarizeApi) return null; | 241 if (!options.summarizeApi) return null; |
240 | 242 |
241 if (!units.any((u) => resolutionMap | 243 if (!units.any((u) => resolutionMap |
242 .elementDeclaredByCompilationUnit(u) | 244 .elementDeclaredByCompilationUnit(u) |
243 .librarySource | 245 .librarySource |
244 .isInSystemLibrary)) { | 246 .isInSystemLibrary)) { |
245 var sdk = context.sourceFactory.dartSdk; | 247 var sdk = driver.sourceFactory.dartSdk; |
246 summaryData.addBundle( | 248 summaryData.addBundle( |
247 null, | 249 null, |
248 sdk is SummaryBasedDartSdk | 250 sdk is SummaryBasedDartSdk |
249 ? sdk.bundle | 251 ? sdk.bundle |
250 : (sdk as FolderBasedDartSdk).getSummarySdkBundle(true)); | 252 : (sdk as FolderBasedDartSdk).getSummarySdkBundle(true)); |
251 } | 253 } |
252 | 254 |
253 var assembler = new PackageBundleAssembler(); | 255 var assembler = new PackageBundleAssembler(); |
254 assembler.recordDependencies(summaryData); | 256 assembler.recordDependencies(summaryData); |
255 | 257 |
256 var uriToUnit = new Map<String, UnlinkedUnit>.fromIterable(units, | 258 var uriToUnit = new Map<String, UnlinkedUnit>.fromIterable(units, |
257 key: (u) => u.element.source.uri.toString(), | 259 key: (u) => u.element.source.uri.toString(), |
258 value: (unit) { | 260 value: (unit) { |
259 var unlinked = serializeAstUnlinked(unit); | 261 var unlinked = serializeAstUnlinked(unit); |
260 assembler.addUnlinkedUnit(unit.element.source, unlinked); | 262 assembler.addUnlinkedUnit(unit.element.source, unlinked); |
261 return unlinked; | 263 return unlinked; |
262 }); | 264 }); |
263 | 265 |
264 summary_link | 266 summary_link |
265 .link( | 267 .link( |
266 uriToUnit.keys.toSet(), | 268 uriToUnit.keys.toSet(), |
267 (uri) => summaryData.linkedMap[uri], | 269 (uri) => summaryData.linkedMap[uri], |
268 (uri) => summaryData.unlinkedMap[uri] ?? uriToUnit[uri], | 270 (uri) => summaryData.unlinkedMap[uri] ?? uriToUnit[uri], |
269 context.declaredVariables.get, | 271 driver.declaredVariables.get, |
270 true) | 272 true) |
271 .forEach(assembler.addLinkedLibrary); | 273 .forEach(assembler.addLinkedLibrary); |
272 | 274 |
273 var bundle = assembler.assemble(); | 275 var bundle = assembler.assemble(); |
274 // Preserve only API-level information in the summary. | 276 // Preserve only API-level information in the summary. |
275 bundle.flushInformative(); | 277 bundle.flushInformative(); |
276 return bundle.toBuffer(); | 278 return bundle.toBuffer(); |
277 } | 279 } |
278 | 280 |
279 JS.Program _emitModule(List<CompilationUnit> compilationUnits, String name) { | 281 JS.Program _emitModule(List<CompilationUnit> compilationUnits, String name) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 // dart:_runtime has a magic module that holds extension method symbols. | 316 // dart:_runtime has a magic module that holds extension method symbols. |
315 // TODO(jmesserly): find a cleaner design for this. | 317 // TODO(jmesserly): find a cleaner design for this. |
316 if (isSdkInternalRuntime(library)) { | 318 if (isSdkInternalRuntime(library)) { |
317 items.add(new JS.ExportDeclaration(js | 319 items.add(new JS.ExportDeclaration(js |
318 .call('const # = Object.create(null)', [_extensionSymbolsModule]))); | 320 .call('const # = Object.create(null)', [_extensionSymbolsModule]))); |
319 } | 321 } |
320 } | 322 } |
321 | 323 |
322 // Collect all class/type Element -> Node mappings | 324 // Collect all class/type Element -> Node mappings |
323 // in case we need to forward declare any classes. | 325 // in case we need to forward declare any classes. |
324 _declarationNodes = new HashMap<TypeDefiningElement, AstNode>.identity(); | 326 _declarationNodes = new HashMap<TypeDefiningElement, AstNode>(); |
325 for (var unit in compilationUnits) { | 327 for (var unit in compilationUnits) { |
326 for (var declaration in unit.declarations) { | 328 for (var declaration in unit.declarations) { |
327 var element = declaration.element; | 329 var element = declaration.element; |
328 if (element is TypeDefiningElement) { | 330 if (element is TypeDefiningElement) { |
329 _declarationNodes[element] = declaration; | 331 _declarationNodes[element] = declaration; |
330 } | 332 } |
331 } | 333 } |
332 } | 334 } |
333 if (compilationUnits.isNotEmpty) { | 335 if (compilationUnits.isNotEmpty) { |
334 _constants = new ConstFieldVisitor(context, | 336 _constants = new ConstFieldVisitor(types, driver.declaredVariables, |
335 dummySource: resolutionMap | 337 dummySource: resolutionMap |
336 .elementDeclaredByCompilationUnit(compilationUnits.first) | 338 .elementDeclaredByCompilationUnit(compilationUnits.first) |
337 .source); | 339 .source); |
338 } | 340 } |
339 | 341 |
340 // Add implicit dart:core dependency so it is first. | 342 // Add implicit dart:core dependency so it is first. |
341 emitLibraryName(dartCoreLibrary); | 343 emitLibraryName(dartCoreLibrary); |
342 | 344 |
343 // Visit each compilation unit and emit its code. | 345 // Visit each compilation unit and emit its code. |
344 // | 346 // |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 544 |
543 var last = _currentElements.removeLast(); | 545 var last = _currentElements.removeLast(); |
544 assert(identical(e, last)); | 546 assert(identical(e, last)); |
545 } | 547 } |
546 | 548 |
547 /// Start generating top-level code for the element [e]. | 549 /// Start generating top-level code for the element [e]. |
548 /// | 550 /// |
549 /// Subsequent [emitDeclaration] calls will cause those elements to be | 551 /// Subsequent [emitDeclaration] calls will cause those elements to be |
550 /// generated before this one, until [finishTopLevel] is called. | 552 /// generated before this one, until [finishTopLevel] is called. |
551 void _startTopLevelCodeForClass(TypeDefiningElement e) { | 553 void _startTopLevelCodeForClass(TypeDefiningElement e) { |
552 assert(identical(e, currentElement)); | 554 assert(e == currentElement); |
553 _topLevelElements.add(e); | 555 _topLevelElements.add(e); |
554 } | 556 } |
555 | 557 |
556 /// Finishes the top-level code for the element [e]. | 558 /// Finishes the top-level code for the element [e]. |
557 void _finishTopLevelCodeForClass(TypeDefiningElement e) { | 559 void _finishTopLevelCodeForClass(TypeDefiningElement e) { |
558 var last = _topLevelElements.removeLast(); | 560 var last = _topLevelElements.removeLast(); |
559 assert(identical(e, last)); | 561 assert(identical(e, last)); |
560 } | 562 } |
561 | 563 |
562 /// To emit top-level module items, we sometimes need to reorder them. | 564 /// To emit top-level module items, we sometimes need to reorder them. |
563 /// | 565 /// |
564 /// This function takes care of that, and also detects cases where reordering | 566 /// This function takes care of that, and also detects cases where reordering |
565 /// failed, and we need to resort to lazy loading, by marking the element as | 567 /// failed, and we need to resort to lazy loading, by marking the element as |
566 /// lazy. All elements need to be aware of this possibility and generate code | 568 /// lazy. All elements need to be aware of this possibility and generate code |
567 /// accordingly. | 569 /// accordingly. |
568 /// | 570 /// |
569 /// If we are not emitting top-level code, this does nothing, because all | 571 /// If we are not emitting top-level code, this does nothing, because all |
570 /// declarations are assumed to be available before we start execution. | 572 /// declarations are assumed to be available before we start execution. |
571 /// See [startTopLevel]. | 573 /// See [startTopLevel]. |
572 void _declareBeforeUse(TypeDefiningElement e) { | 574 void _declareBeforeUse(TypeDefiningElement e) { |
573 if (e == null) return; | 575 if (e == null) return; |
574 | 576 |
575 var topLevel = _topLevelElements; | 577 var topLevel = _topLevelElements; |
576 if (topLevel.isNotEmpty && identical(currentElement, topLevel.last)) { | 578 if (topLevel.isNotEmpty && currentElement == topLevel.last) { |
577 // If the item is from our library, try to emit it now. | 579 // If the item is from our library, try to emit it now. |
578 _emitTypeDeclaration(e); | 580 _emitTypeDeclaration(e); |
579 } | 581 } |
580 } | 582 } |
581 | 583 |
582 @override | 584 @override |
583 visitCompilationUnit(CompilationUnit unit) { | 585 visitCompilationUnit(CompilationUnit unit) { |
584 // NOTE: this method isn't the right place to initialize | 586 // NOTE: this method isn't the right place to initialize |
585 // per-compilation-unit state. Declarations can be visited out of order, | 587 // per-compilation-unit state. Declarations can be visited out of order, |
586 // this is only to catch things that haven't been emitted yet. | 588 // this is only to catch things that haven't been emitted yet. |
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 lookup = classElem.type.lookUpInheritedGetter; | 1915 lookup = classElem.type.lookUpInheritedGetter; |
1914 tMember = node.isStatic ? tStaticGetters : tInstanceGetters; | 1916 tMember = node.isStatic ? tStaticGetters : tInstanceGetters; |
1915 } else if (node.isSetter) { | 1917 } else if (node.isSetter) { |
1916 elementToType = (ExecutableElement element) => element.type; | 1918 elementToType = (ExecutableElement element) => element.type; |
1917 getOverride = classElem.lookUpInheritedConcreteSetter; | 1919 getOverride = classElem.lookUpInheritedConcreteSetter; |
1918 lookup = classElem.type.lookUpInheritedSetter; | 1920 lookup = classElem.type.lookUpInheritedSetter; |
1919 tMember = node.isStatic ? tStaticSetters : tInstanceSetters; | 1921 tMember = node.isStatic ? tStaticSetters : tInstanceSetters; |
1920 } else { | 1922 } else { |
1921 // Method | 1923 // Method |
1922 // Swap in "Object" for parameter types that are covariant overrides. | 1924 // Swap in "Object" for parameter types that are covariant overrides. |
1923 var objectType = context.typeProvider.objectType; | 1925 var objectType = types.objectType; |
1924 elementToType = | 1926 elementToType = |
1925 (MethodElement element) => element.getReifiedType(objectType); | 1927 (MethodElement element) => element.getReifiedType(objectType); |
1926 getOverride = classElem.lookUpInheritedConcreteMethod; | 1928 getOverride = classElem.lookUpInheritedConcreteMethod; |
1927 lookup = classElem.type.lookUpInheritedMethod; | 1929 lookup = classElem.type.lookUpInheritedMethod; |
1928 tMember = node.isStatic ? tStaticMethods : tInstanceMethods; | 1930 tMember = node.isStatic ? tStaticMethods : tInstanceMethods; |
1929 } | 1931 } |
1930 | 1932 |
1931 DartType reifiedType = elementToType(element); | 1933 DartType reifiedType = elementToType(element); |
1932 // Don't add redundant signatures for inherited methods whose signature | 1934 // Don't add redundant signatures for inherited methods whose signature |
1933 // did not change. If we are not overriding, or if the thing we are | 1935 // did not change. If we are not overriding, or if the thing we are |
(...skipping 2392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4326 int _asIntInRange(Expression expr, int low, int high) { | 4328 int _asIntInRange(Expression expr, int low, int high) { |
4327 expr = expr.unParenthesized; | 4329 expr = expr.unParenthesized; |
4328 if (expr is IntegerLiteral) { | 4330 if (expr is IntegerLiteral) { |
4329 if (expr.value >= low && expr.value <= high) return expr.value; | 4331 if (expr.value >= low && expr.value <= high) return expr.value; |
4330 return null; | 4332 return null; |
4331 } | 4333 } |
4332 int finishIdentifier(SimpleIdentifier identifier) { | 4334 int finishIdentifier(SimpleIdentifier identifier) { |
4333 Element staticElement = identifier.staticElement; | 4335 Element staticElement = identifier.staticElement; |
4334 if (staticElement is PropertyAccessorElement && staticElement.isGetter) { | 4336 if (staticElement is PropertyAccessorElement && staticElement.isGetter) { |
4335 PropertyInducingElement variable = staticElement.variable; | 4337 PropertyInducingElement variable = staticElement.variable; |
4336 int value = variable?.computeConstantValue()?.toIntValue(); | 4338 int value = variable?.constantValue?.toIntValue(); |
4337 if (value != null && value >= low && value <= high) return value; | 4339 if (value != null && value >= low && value <= high) return value; |
4338 } | 4340 } |
4339 return null; | 4341 return null; |
4340 } | 4342 } |
4341 | 4343 |
4342 if (expr is SimpleIdentifier) { | 4344 if (expr is SimpleIdentifier) { |
4343 return finishIdentifier(expr); | 4345 return finishIdentifier(expr); |
4344 } else if (expr is PrefixedIdentifier && !expr.isDeferred) { | 4346 } else if (expr is PrefixedIdentifier && !expr.isDeferred) { |
4345 return finishIdentifier(expr.identifier); | 4347 return finishIdentifier(expr.identifier); |
4346 } | 4348 } |
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5907 : super.forNode(name); | 5909 : super.forNode(name); |
5908 | 5910 |
5909 int get hashCode => identityHashCode(this); | 5911 int get hashCode => identityHashCode(this); |
5910 | 5912 |
5911 bool operator ==(Object other) => identical(this, other); | 5913 bool operator ==(Object other) => identical(this, other); |
5912 } | 5914 } |
5913 | 5915 |
5914 bool isLibraryPrefix(Expression node) => | 5916 bool isLibraryPrefix(Expression node) => |
5915 node is SimpleIdentifier && node.staticElement is PrefixElement; | 5917 node is SimpleIdentifier && node.staticElement is PrefixElement; |
5916 | 5918 |
5917 LibraryElement _getLibrary(AnalysisContext c, String uri) => | |
5918 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | |
5919 | |
5920 /// Returns `true` if [target] is a prefix for a deferred library and [name] | 5919 /// Returns `true` if [target] is a prefix for a deferred library and [name] |
5921 /// is "loadLibrary". | 5920 /// is "loadLibrary". |
5922 /// | 5921 /// |
5923 /// If so, the expression should be compiled to call the runtime's | 5922 /// If so, the expression should be compiled to call the runtime's |
5924 /// "loadLibrary" helper function. | 5923 /// "loadLibrary" helper function. |
5925 bool _isDeferredLoadLibrary(Expression target, SimpleIdentifier name) { | 5924 bool _isDeferredLoadLibrary(Expression target, SimpleIdentifier name) { |
5926 if (name.name != "loadLibrary") return false; | 5925 if (name.name != "loadLibrary") return false; |
5927 | 5926 |
5928 if (target is! SimpleIdentifier) return false; | 5927 if (target is! SimpleIdentifier) return false; |
5929 var targetIdentifier = target as SimpleIdentifier; | 5928 var targetIdentifier = target as SimpleIdentifier; |
5930 | 5929 |
5931 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5930 if (targetIdentifier.staticElement is! PrefixElement) return false; |
5932 var prefix = targetIdentifier.staticElement as PrefixElement; | 5931 var prefix = targetIdentifier.staticElement as PrefixElement; |
5933 | 5932 |
5934 // The library the prefix is referring to must come from a deferred import. | 5933 // The library the prefix is referring to must come from a deferred import. |
5935 var containingLibrary = resolutionMap | 5934 var containingLibrary = resolutionMap |
5936 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 5935 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
5937 .library; | 5936 .library; |
5938 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5937 var imports = containingLibrary.getImportsWithPrefix(prefix); |
5939 return imports.length == 1 && imports[0].isDeferred; | 5938 return imports.length == 1 && imports[0].isDeferred; |
5940 } | 5939 } |
OLD | NEW |