OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:js_runtime/shared/embedded_names.dart'; | 5 import 'package:js_runtime/shared/embedded_names.dart'; |
6 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
7 | 7 |
8 import '../closure.dart'; | 8 import '../closure.dart'; |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../compiler.dart'; | 10 import '../compiler.dart'; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 /// Sometimes for resolution the resolved AST element needs to change (for | 54 /// Sometimes for resolution the resolved AST element needs to change (for |
55 /// example, if we're inlining, or if we're in a constructor, but then also | 55 /// example, if we're inlining, or if we're in a constructor, but then also |
56 /// constructing the field values). We keep track of this with a stack. | 56 /// constructing the field values). We keep track of this with a stack. |
57 final List<ResolvedAst> _resolvedAstStack = <ResolvedAst>[]; | 57 final List<ResolvedAst> _resolvedAstStack = <ResolvedAst>[]; |
58 | 58 |
59 final native.BehaviorBuilder nativeBehaviorBuilder; | 59 final native.BehaviorBuilder nativeBehaviorBuilder; |
60 | 60 |
61 KernelAstAdapter(this.kernel, this._backend, this._resolvedAst, | 61 KernelAstAdapter(this.kernel, this._backend, this._resolvedAst, |
62 this._nodeToAst, this._nodeToElement) | 62 this._nodeToAst, this._nodeToElement) |
63 : nativeBehaviorBuilder = | 63 : nativeBehaviorBuilder = new native.ResolverBehaviorBuilder( |
64 new native.ResolverBehaviorBuilder(_backend.compiler) { | 64 _backend.compiler, _backend.nativeData) { |
65 KernelJumpTarget.index = 0; | 65 KernelJumpTarget.index = 0; |
66 // TODO(het): Maybe just use all of the kernel maps directly? | 66 // TODO(het): Maybe just use all of the kernel maps directly? |
67 for (FieldElement fieldElement in kernel.fields.keys) { | 67 for (FieldElement fieldElement in kernel.fields.keys) { |
68 _nodeToElement[kernel.fields[fieldElement]] = fieldElement; | 68 _nodeToElement[kernel.fields[fieldElement]] = fieldElement; |
69 } | 69 } |
70 for (FunctionElement functionElement in kernel.functions.keys) { | 70 for (FunctionElement functionElement in kernel.functions.keys) { |
71 _nodeToElement[kernel.functions[functionElement]] = functionElement; | 71 _nodeToElement[kernel.functions[functionElement]] = functionElement; |
72 } | 72 } |
73 for (ClassElement classElement in kernel.classes.keys) { | 73 for (ClassElement classElement in kernel.classes.keys) { |
74 _nodeToElement[kernel.classes[classElement]] = classElement; | 74 _nodeToElement[kernel.classes[classElement]] = classElement; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 GlobalTypeInferenceResults get _globalInferenceResults => | 141 GlobalTypeInferenceResults get _globalInferenceResults => |
142 _compiler.globalInference.results; | 142 _compiler.globalInference.results; |
143 | 143 |
144 GlobalTypeInferenceElementResult _resultOf(MemberElement e) => | 144 GlobalTypeInferenceElementResult _resultOf(MemberElement e) => |
145 _globalInferenceResults | 145 _globalInferenceResults |
146 .resultOfMember(e is ConstructorBodyElementX ? e.constructor : e); | 146 .resultOfMember(e is ConstructorBodyElementX ? e.constructor : e); |
147 | 147 |
148 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { | 148 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { |
149 if (kernel.syntheticNodes.contains(node)) { | 149 if (kernel.syntheticNodes.contains(node)) { |
150 return _backend.constantSystem.createSymbol( | 150 return _backend.constantSystem |
151 _compiler.commonElements, _backend.backendClasses, node.value); | 151 .createSymbol(_compiler.commonElements, node.value); |
152 } | 152 } |
153 ast.Node astNode = getNode(node); | 153 ast.Node astNode = getNode(node); |
154 ConstantValue constantValue = _backend.constants | 154 ConstantValue constantValue = _backend.constants |
155 .getConstantValueForNode(astNode, _resolvedAst.elements); | 155 .getConstantValueForNode(astNode, _resolvedAst.elements); |
156 assert(invariant(astNode, constantValue != null, | 156 assert(invariant(astNode, constantValue != null, |
157 message: 'No constant computed for $node')); | 157 message: 'No constant computed for $node')); |
158 return constantValue; | 158 return constantValue; |
159 } | 159 } |
160 | 160 |
161 // TODO(johnniwinther): Use the more precise functions below. | 161 // TODO(johnniwinther): Use the more precise functions below. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // String is indexable but not iterable. | 285 // String is indexable but not iterable. |
286 !mask.satisfies(_compiler.commonElements.jsStringClass, closedWorld); | 286 !mask.satisfies(_compiler.commonElements.jsStringClass, closedWorld); |
287 } | 287 } |
288 | 288 |
289 bool isFixedLength(TypeMask mask, ClosedWorld closedWorld) { | 289 bool isFixedLength(TypeMask mask, ClosedWorld closedWorld) { |
290 if (mask.isContainer && (mask as ContainerTypeMask).length != null) { | 290 if (mask.isContainer && (mask as ContainerTypeMask).length != null) { |
291 // A container on which we have inferred the length. | 291 // A container on which we have inferred the length. |
292 return true; | 292 return true; |
293 } | 293 } |
294 // TODO(sra): Recognize any combination of fixed length indexables. | 294 // TODO(sra): Recognize any combination of fixed length indexables. |
295 if (mask.containsOnly(closedWorld.backendClasses.fixedListClass) || | 295 if (mask.containsOnly(closedWorld.commonElements.jsFixedArrayClass) || |
296 mask.containsOnly(closedWorld.backendClasses.constListClass) || | 296 mask.containsOnly( |
| 297 closedWorld.commonElements.jsUnmodifiableArrayClass) || |
297 mask.containsOnlyString(closedWorld) || | 298 mask.containsOnlyString(closedWorld) || |
298 closedWorld.commonMasks.isTypedArray(mask)) { | 299 closedWorld.commonMasks.isTypedArray(mask)) { |
299 return true; | 300 return true; |
300 } | 301 } |
301 return false; | 302 return false; |
302 } | 303 } |
303 | 304 |
304 TypeMask inferredIndexType(ir.ForInStatement forInStatement) { | 305 TypeMask inferredIndexType(ir.ForInStatement forInStatement) { |
305 return TypeMaskFactory.inferredTypeForSelector(new Selector.index(), | 306 return TypeMaskFactory.inferredTypeForSelector(new Selector.index(), |
306 typeOfIterator(forInStatement), _globalInferenceResults); | 307 typeOfIterator(forInStatement), _globalInferenceResults); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 // defaultExpression.accept(new Constantifier(this)); | 342 // defaultExpression.accept(new Constantifier(this)); |
342 // assert(constantExpression != null); | 343 // assert(constantExpression != null); |
343 ConstantExpression constantExpression = | 344 ConstantExpression constantExpression = |
344 kernel.parameterInitializerNodeToConstant[defaultExpression]; | 345 kernel.parameterInitializerNodeToConstant[defaultExpression]; |
345 if (constantExpression == null) return null; | 346 if (constantExpression == null) return null; |
346 return _backend.constants.getConstantValue(constantExpression); | 347 return _backend.constants.getConstantValue(constantExpression); |
347 } | 348 } |
348 | 349 |
349 ConstantValue getConstantForType(ir.DartType irType) { | 350 ConstantValue getConstantForType(ir.DartType irType) { |
350 ResolutionDartType type = getDartType(irType); | 351 ResolutionDartType type = getDartType(irType); |
351 return _backend.constantSystem.createType( | 352 return _backend.constantSystem |
352 _compiler.commonElements, _backend.backendClasses, type.asRaw()); | 353 .createType(_compiler.commonElements, type.asRaw()); |
353 } | 354 } |
354 | 355 |
355 bool isIntercepted(ir.Node node) { | 356 bool isIntercepted(ir.Node node) { |
356 Selector selector = getSelector(node); | 357 Selector selector = getSelector(node); |
357 return _backend.interceptorData.isInterceptedSelector(selector); | 358 return _backend.interceptorData.isInterceptedSelector(selector); |
358 } | 359 } |
359 | 360 |
360 bool isInterceptedSelector(Selector selector) { | 361 bool isInterceptedSelector(Selector selector) { |
361 return _backend.interceptorData.isInterceptedSelector(selector); | 362 return _backend.interceptorData.isInterceptedSelector(selector); |
362 } | 363 } |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 JumpTarget continueTarget = | 822 JumpTarget continueTarget = |
822 astAdapter.getJumpTarget(switchCase, isContinueTarget: true); | 823 astAdapter.getJumpTarget(switchCase, isContinueTarget: true); |
823 assert(continueTarget is KernelJumpTarget); | 824 assert(continueTarget is KernelJumpTarget); |
824 targetIndexMap[continueTarget] = switchIndex; | 825 targetIndexMap[continueTarget] = switchIndex; |
825 assert(builder.jumpTargets[continueTarget] == null); | 826 assert(builder.jumpTargets[continueTarget] == null); |
826 builder.jumpTargets[continueTarget] = this; | 827 builder.jumpTargets[continueTarget] = this; |
827 switchIndex++; | 828 switchIndex++; |
828 } | 829 } |
829 } | 830 } |
830 } | 831 } |
OLD | NEW |