| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A special element for the extra parameter taken by intercepted | 8 * A special element for the extra parameter taken by intercepted |
| 9 * methods. We need to implement [TypedElement.type] because our | 9 * methods. We need to implement [TypedElement.type] because our |
| 10 * optimizers may look at its declared type. | 10 * optimizers may look at its declared type. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } else { | 56 } else { |
| 57 compiler.internalError(element, 'Unexpected element kind $kind.'); | 57 compiler.internalError(element, 'Unexpected element kind $kind.'); |
| 58 } | 58 } |
| 59 assert(graph.isValid()); | 59 assert(graph.isValid()); |
| 60 if (!identical(kind, ElementKind.FIELD)) { | 60 if (!identical(kind, ElementKind.FIELD)) { |
| 61 FunctionElement function = element; | 61 FunctionElement function = element; |
| 62 FunctionSignature signature = function.functionSignature; | 62 FunctionSignature signature = function.functionSignature; |
| 63 signature.forEachOptionalParameter((Element parameter) { | 63 signature.forEachOptionalParameter((Element parameter) { |
| 64 // This ensures the default value will be computed. | 64 // This ensures the default value will be computed. |
| 65 Constant constant = | 65 Constant constant = |
| 66 compiler.constantHandler.getConstantForVariable(parameter); | 66 backend.constantHandler.getConstantForVariable(parameter); |
| 67 backend.registerCompileTimeConstant(constant, work.resolutionTree); | 67 backend.registerCompileTimeConstant(constant, work.resolutionTree); |
| 68 compiler.constantHandler.addCompileTimeConstantForEmission( | 68 backend.constantHandler.addCompileTimeConstantForEmission(constant); |
| 69 constant); | |
| 70 }); | 69 }); |
| 71 } | 70 } |
| 72 if (compiler.tracer.enabled) { | 71 if (compiler.tracer.enabled) { |
| 73 String name; | 72 String name; |
| 74 if (element.isMember()) { | 73 if (element.isMember()) { |
| 75 String className = element.getEnclosingClass().name; | 74 String className = element.getEnclosingClass().name; |
| 76 String memberName = element.name; | 75 String memberName = element.name; |
| 77 name = "$className.$memberName"; | 76 name = "$className.$memberName"; |
| 78 if (element.isGenerativeConstructorBody()) { | 77 if (element.isGenerativeConstructorBody()) { |
| 79 name = "$name (body)"; | 78 name = "$name (body)"; |
| (...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 // The [sourceElementStack] contains declaration elements. | 1301 // The [sourceElementStack] contains declaration elements. |
| 1303 sourceElementStack.add(element.declaration); | 1302 sourceElementStack.add(element.declaration); |
| 1304 var result = f(); | 1303 var result = f(); |
| 1305 sourceElementStack.removeLast(); | 1304 sourceElementStack.removeLast(); |
| 1306 return result; | 1305 return result; |
| 1307 }); | 1306 }); |
| 1308 } | 1307 } |
| 1309 | 1308 |
| 1310 HInstruction handleConstantForOptionalParameter(Element parameter) { | 1309 HInstruction handleConstantForOptionalParameter(Element parameter) { |
| 1311 Constant constant = | 1310 Constant constant = |
| 1312 compiler.constantHandler.getConstantForVariable(parameter); | 1311 backend.constantHandler.getConstantForVariable(parameter); |
| 1313 assert(invariant(parameter, constant != null, | 1312 assert(invariant(parameter, constant != null, |
| 1314 message: 'No constant computed for $parameter')); | 1313 message: 'No constant computed for $parameter')); |
| 1315 return graph.addConstant(constant, compiler); | 1314 return graph.addConstant(constant, compiler); |
| 1316 } | 1315 } |
| 1317 | 1316 |
| 1318 Element get currentNonClosureClass { | 1317 Element get currentNonClosureClass { |
| 1319 ClassElement cls = sourceElement.getEnclosingClass(); | 1318 ClassElement cls = sourceElement.getEnclosingClass(); |
| 1320 if (cls != null && cls.isClosure()) { | 1319 if (cls != null && cls.isClosure()) { |
| 1321 var closureClass = cls; | 1320 var closureClass = cls; |
| 1322 return closureClass.methodElement.getEnclosingClass(); | 1321 return closureClass.methodElement.getEnclosingClass(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1341 final List<DartType> currentInlinedInstantiations = <DartType>[]; | 1340 final List<DartType> currentInlinedInstantiations = <DartType>[]; |
| 1342 | 1341 |
| 1343 final List<AstInliningState> inliningStack = <AstInliningState>[]; | 1342 final List<AstInliningState> inliningStack = <AstInliningState>[]; |
| 1344 | 1343 |
| 1345 Element returnElement; | 1344 Element returnElement; |
| 1346 DartType returnType; | 1345 DartType returnType; |
| 1347 | 1346 |
| 1348 bool inTryStatement = false; | 1347 bool inTryStatement = false; |
| 1349 | 1348 |
| 1350 Constant getConstantForNode(ast.Node node) { | 1349 Constant getConstantForNode(ast.Node node) { |
| 1351 Constant constant = elements.getConstant(node); | 1350 Constant constant = |
| 1351 backend.constantHandler.getConstantForNode(node, elements); |
| 1352 assert(invariant(node, constant != null, | 1352 assert(invariant(node, constant != null, |
| 1353 message: 'No constant computed for $node')); | 1353 message: 'No constant computed for $node')); |
| 1354 return constant; | 1354 return constant; |
| 1355 } | 1355 } |
| 1356 | 1356 |
| 1357 HInstruction addConstant(ast.Node node) { | 1357 HInstruction addConstant(ast.Node node) { |
| 1358 return graph.addConstant(getConstantForNode(node), compiler); | 1358 return graph.addConstant(getConstantForNode(node), compiler); |
| 1359 } | 1359 } |
| 1360 | 1360 |
| 1361 bool isLazilyInitialized(VariableElement element) { | 1361 bool isLazilyInitialized(VariableElement element) { |
| 1362 Constant initialValue = | 1362 Constant initialValue = |
| 1363 compiler.constantHandler.getConstantForVariable(element); | 1363 backend.constantHandler.getConstantForVariable(element); |
| 1364 return initialValue == null; | 1364 return initialValue == null; |
| 1365 } | 1365 } |
| 1366 | 1366 |
| 1367 TypeMask cachedTypeOfThis; | 1367 TypeMask cachedTypeOfThis; |
| 1368 | 1368 |
| 1369 TypeMask getTypeOfThis() { | 1369 TypeMask getTypeOfThis() { |
| 1370 TypeMask result = cachedTypeOfThis; | 1370 TypeMask result = cachedTypeOfThis; |
| 1371 if (result == null) { | 1371 if (result == null) { |
| 1372 Element element = localsHandler.closureData.thisElement; | 1372 Element element = localsHandler.closureData.thisElement; |
| 1373 ClassElement cls = element.enclosingElement.getEnclosingClass(); | 1373 ClassElement cls = element.enclosingElement.getEnclosingClass(); |
| (...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2929 } | 2929 } |
| 2930 | 2930 |
| 2931 void generateGetter(ast.Send send, Element element) { | 2931 void generateGetter(ast.Send send, Element element) { |
| 2932 if (element != null && element.isForeign(compiler)) { | 2932 if (element != null && element.isForeign(compiler)) { |
| 2933 visitForeignGetter(send); | 2933 visitForeignGetter(send); |
| 2934 } else if (Elements.isStaticOrTopLevelField(element)) { | 2934 } else if (Elements.isStaticOrTopLevelField(element)) { |
| 2935 Constant value; | 2935 Constant value; |
| 2936 if (element.isField() && !element.isAssignable()) { | 2936 if (element.isField() && !element.isAssignable()) { |
| 2937 // A static final or const. Get its constant value and inline it if | 2937 // A static final or const. Get its constant value and inline it if |
| 2938 // the value can be compiled eagerly. | 2938 // the value can be compiled eagerly. |
| 2939 value = compiler.constantHandler.getConstantForVariable(element); | 2939 value = backend.constantHandler.getConstantForVariable(element); |
| 2940 } | 2940 } |
| 2941 if (value != null) { | 2941 if (value != null) { |
| 2942 HConstant instruction = graph.addConstant(value, compiler); | 2942 HConstant instruction = graph.addConstant(value, compiler); |
| 2943 stack.add(instruction); | 2943 stack.add(instruction); |
| 2944 // The inferrer may have found a better type than the constant | 2944 // The inferrer may have found a better type than the constant |
| 2945 // handler in the case of lists, because the constant handler | 2945 // handler in the case of lists, because the constant handler |
| 2946 // does not look at elements in the list. | 2946 // does not look at elements in the list. |
| 2947 TypeMask type = | 2947 TypeMask type = |
| 2948 TypeMaskFactory.inferredTypeForElement(element, compiler); | 2948 TypeMaskFactory.inferredTypeForElement(element, compiler); |
| 2949 if (!type.containsAll(compiler) && !instruction.isConstantNull()) { | 2949 if (!type.containsAll(compiler) && !instruction.isConstantNull()) { |
| (...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4333 generateThrowNoSuchMethod(node.send, | 4333 generateThrowNoSuchMethod(node.send, |
| 4334 getTargetName(error, 'constructor'), | 4334 getTargetName(error, 'constructor'), |
| 4335 argumentNodes: node.send.arguments); | 4335 argumentNodes: node.send.arguments); |
| 4336 } else { | 4336 } else { |
| 4337 Message message = error.messageKind.message(error.messageArguments); | 4337 Message message = error.messageKind.message(error.messageArguments); |
| 4338 generateRuntimeError(node.send, message.toString()); | 4338 generateRuntimeError(node.send, message.toString()); |
| 4339 } | 4339 } |
| 4340 } else if (node.isConst()) { | 4340 } else if (node.isConst()) { |
| 4341 stack.add(addConstant(node)); | 4341 stack.add(addConstant(node)); |
| 4342 if (isSymbolConstructor) { | 4342 if (isSymbolConstructor) { |
| 4343 ConstructedConstant symbol = elements.getConstant(node); | 4343 ConstructedConstant symbol = getConstantForNode(node); |
| 4344 StringConstant stringConstant = symbol.fields.single; | 4344 StringConstant stringConstant = symbol.fields.single; |
| 4345 String nameString = stringConstant.toDartString().slowToString(); | 4345 String nameString = stringConstant.toDartString().slowToString(); |
| 4346 compiler.enqueuer.codegen.registerConstSymbol(nameString, elements); | 4346 compiler.enqueuer.codegen.registerConstSymbol(nameString, elements); |
| 4347 } | 4347 } |
| 4348 } else { | 4348 } else { |
| 4349 handleNewSend(node); | 4349 handleNewSend(node); |
| 4350 } | 4350 } |
| 4351 } | 4351 } |
| 4352 | 4352 |
| 4353 void pushInvokeDynamic(ast.Node node, | 4353 void pushInvokeDynamic(ast.Node node, |
| (...skipping 1830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6184 DartType unaliased = type.unalias(builder.compiler); | 6184 DartType unaliased = type.unalias(builder.compiler); |
| 6185 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 6185 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
| 6186 unaliased.accept(this, builder); | 6186 unaliased.accept(this, builder); |
| 6187 } | 6187 } |
| 6188 | 6188 |
| 6189 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 6189 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
| 6190 ClassElement cls = builder.compiler.findHelper('DynamicRuntimeType'); | 6190 ClassElement cls = builder.compiler.findHelper('DynamicRuntimeType'); |
| 6191 builder.push(new HDynamicType(type, new TypeMask.exact(cls))); | 6191 builder.push(new HDynamicType(type, new TypeMask.exact(cls))); |
| 6192 } | 6192 } |
| 6193 } | 6193 } |
| OLD | NEW |