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 class Interceptors { | 5 class Interceptors { |
6 Compiler compiler; | 6 Compiler compiler; |
7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
8 | 8 |
9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 // initializers and constructor bodies. | 1191 // initializers and constructor bodies. |
1192 List<FunctionElement> constructors = <FunctionElement>[functionElement]; | 1192 List<FunctionElement> constructors = <FunctionElement>[functionElement]; |
1193 buildInitializers(functionElement, constructors, fieldValues); | 1193 buildInitializers(functionElement, constructors, fieldValues); |
1194 | 1194 |
1195 // Call the JavaScript constructor with the fields as argument. | 1195 // Call the JavaScript constructor with the fields as argument. |
1196 List<HInstruction> constructorArguments = <HInstruction>[]; | 1196 List<HInstruction> constructorArguments = <HInstruction>[]; |
1197 classElement.forEachInstanceField( | 1197 classElement.forEachInstanceField( |
1198 includeBackendMembers: true, | 1198 includeBackendMembers: true, |
1199 includeSuperMembers: true, | 1199 includeSuperMembers: true, |
1200 f: (ClassElement enclosingClass, Element member) { | 1200 f: (ClassElement enclosingClass, Element member) { |
1201 constructorArguments.add(fieldValues[member]); | 1201 constructorArguments.add( |
| 1202 potentiallyCheckType(fieldValues[member], member)); |
1202 }); | 1203 }); |
1203 | 1204 |
1204 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); | 1205 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); |
1205 add(newObject); | 1206 add(newObject); |
1206 | 1207 |
1207 // If the class has type variables, create the runtime type | 1208 // If the class has type variables, create the runtime type |
1208 // information with the type parameters provided. | 1209 // information with the type parameters provided. |
1209 if (!classElement.typeVariables.isEmpty()) { | 1210 if (!classElement.typeVariables.isEmpty()) { |
1210 List<String> typeVariables = <String>[]; | 1211 List<String> typeVariables = <String>[]; |
1211 List<HInstruction> rtiInputs = <HInstruction>[]; | 1212 List<HInstruction> rtiInputs = <HInstruction>[]; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 HParameterValue param = new HParameterValue(typeVariable.element); | 1334 HParameterValue param = new HParameterValue(typeVariable.element); |
1334 add(param); | 1335 add(param); |
1335 localsHandler.directLocals[typeVariable.element] = param; | 1336 localsHandler.directLocals[typeVariable.element] = param; |
1336 }); | 1337 }); |
1337 } | 1338 } |
1338 } | 1339 } |
1339 | 1340 |
1340 HInstruction potentiallyCheckType(HInstruction original, | 1341 HInstruction potentiallyCheckType(HInstruction original, |
1341 Element sourceElement) { | 1342 Element sourceElement) { |
1342 if (!compiler.enableTypeAssertions) return original; | 1343 if (!compiler.enableTypeAssertions) return original; |
1343 return convertType(original, sourceElement, | 1344 HInstruction other = original.convertType( |
1344 HTypeConversion.CHECKED_MODE_CHECK); | 1345 compiler, sourceElement, HTypeConversion.CHECKED_MODE_CHECK); |
1345 } | 1346 if (other != original) add(other); |
1346 | 1347 return other; |
1347 HInstruction convertType(HInstruction original, | |
1348 Element sourceElement, | |
1349 int kind) { | |
1350 DartType type = sourceElement.computeType(compiler); | |
1351 if (type === null) return original; | |
1352 if (type.element === compiler.dynamicClass) return original; | |
1353 if (type.element === compiler.objectClass) return original; | |
1354 | |
1355 // If the original can't be null, type conversion also can't produce null. | |
1356 bool canBeNull = original.guaranteedType.canBeNull(); | |
1357 HType convertedType = | |
1358 new HType.fromBoundedType(type, compiler, canBeNull); | |
1359 | |
1360 // No need to convert if we know the instruction has | |
1361 // [convertedType] as a bound. | |
1362 if (original.guaranteedType == convertedType) { | |
1363 return original; | |
1364 } | |
1365 | |
1366 HInstruction instruction = | |
1367 new HTypeConversion(convertedType, original, kind); | |
1368 add(instruction); | |
1369 return instruction; | |
1370 } | 1348 } |
1371 | 1349 |
1372 HGraph closeFunction() { | 1350 HGraph closeFunction() { |
1373 // TODO(kasperl): Make this goto an implicit return. | 1351 // TODO(kasperl): Make this goto an implicit return. |
1374 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); | 1352 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); |
1375 graph.finalize(); | 1353 graph.finalize(); |
1376 return graph; | 1354 return graph; |
1377 } | 1355 } |
1378 | 1356 |
1379 HBasicBlock addNewBlock() { | 1357 HBasicBlock addNewBlock() { |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 instruction = new HNot(instruction); | 2165 instruction = new HNot(instruction); |
2188 } | 2166 } |
2189 push(instruction); | 2167 push(instruction); |
2190 } | 2168 } |
2191 } else if (const SourceString("as") == op.source) { | 2169 } else if (const SourceString("as") == op.source) { |
2192 visit(node.receiver); | 2170 visit(node.receiver); |
2193 HInstruction expression = pop(); | 2171 HInstruction expression = pop(); |
2194 Node argument = node.arguments.head; | 2172 Node argument = node.arguments.head; |
2195 TypeAnnotation typeAnnotation = argument.asTypeAnnotation(); | 2173 TypeAnnotation typeAnnotation = argument.asTypeAnnotation(); |
2196 DartType type = elements.getType(typeAnnotation); | 2174 DartType type = elements.getType(typeAnnotation); |
2197 HInstruction converted = convertType(expression, type.element, | 2175 HInstruction converted = expression.convertType( |
2198 HTypeConversion.CAST_TYPE_CHECK); | 2176 compiler, type.element, HTypeConversion.CAST_TYPE_CHECK); |
| 2177 if (converted != expression) add(converted); |
2199 stack.add(converted); | 2178 stack.add(converted); |
2200 } else { | 2179 } else { |
2201 visit(node.receiver); | 2180 visit(node.receiver); |
2202 visit(node.argumentsNode); | 2181 visit(node.argumentsNode); |
2203 var right = pop(); | 2182 var right = pop(); |
2204 var left = pop(); | 2183 var left = pop(); |
2205 visitBinary(left, op, right); | 2184 visitBinary(left, op, right); |
2206 } | 2185 } |
2207 } | 2186 } |
2208 | 2187 |
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4026 new HSubGraphBlockInformation(elseBranch.graph)); | 4005 new HSubGraphBlockInformation(elseBranch.graph)); |
4027 | 4006 |
4028 HBasicBlock conditionStartBlock = conditionBranch.block; | 4007 HBasicBlock conditionStartBlock = conditionBranch.block; |
4029 conditionStartBlock.setBlockFlow(info, joinBlock); | 4008 conditionStartBlock.setBlockFlow(info, joinBlock); |
4030 SubGraph conditionGraph = conditionBranch.graph; | 4009 SubGraph conditionGraph = conditionBranch.graph; |
4031 HIf branch = conditionGraph.end.last; | 4010 HIf branch = conditionGraph.end.last; |
4032 assert(branch is HIf); | 4011 assert(branch is HIf); |
4033 branch.blockInformation = conditionStartBlock.blockFlow; | 4012 branch.blockInformation = conditionStartBlock.blockFlow; |
4034 } | 4013 } |
4035 } | 4014 } |
OLD | NEW |