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 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 // initializers and constructor bodies. | 1206 // initializers and constructor bodies. |
1207 List<FunctionElement> constructors = <FunctionElement>[functionElement]; | 1207 List<FunctionElement> constructors = <FunctionElement>[functionElement]; |
1208 buildInitializers(functionElement, constructors, fieldValues); | 1208 buildInitializers(functionElement, constructors, fieldValues); |
1209 | 1209 |
1210 // Call the JavaScript constructor with the fields as argument. | 1210 // Call the JavaScript constructor with the fields as argument. |
1211 List<HInstruction> constructorArguments = <HInstruction>[]; | 1211 List<HInstruction> constructorArguments = <HInstruction>[]; |
1212 classElement.forEachInstanceField( | 1212 classElement.forEachInstanceField( |
1213 includeBackendMembers: true, | 1213 includeBackendMembers: true, |
1214 includeSuperMembers: true, | 1214 includeSuperMembers: true, |
1215 f: (ClassElement enclosingClass, Element member) { | 1215 f: (ClassElement enclosingClass, Element member) { |
1216 constructorArguments.add(fieldValues[member]); | 1216 constructorArguments.add( |
| 1217 potentiallyCheckType(fieldValues[member], member)); |
1217 }); | 1218 }); |
1218 | 1219 |
1219 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); | 1220 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); |
1220 add(newObject); | 1221 add(newObject); |
1221 | 1222 |
1222 // If the class has type variables, create the runtime type | 1223 // If the class has type variables, create the runtime type |
1223 // information with the type parameters provided. | 1224 // information with the type parameters provided. |
1224 if (!classElement.typeVariables.isEmpty()) { | 1225 if (!classElement.typeVariables.isEmpty()) { |
1225 List<String> typeVariables = <String>[]; | 1226 List<String> typeVariables = <String>[]; |
1226 List<HInstruction> rtiInputs = <HInstruction>[]; | 1227 List<HInstruction> rtiInputs = <HInstruction>[]; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 HParameterValue param = new HParameterValue(typeVariable.element); | 1349 HParameterValue param = new HParameterValue(typeVariable.element); |
1349 add(param); | 1350 add(param); |
1350 localsHandler.directLocals[typeVariable.element] = param; | 1351 localsHandler.directLocals[typeVariable.element] = param; |
1351 }); | 1352 }); |
1352 } | 1353 } |
1353 } | 1354 } |
1354 | 1355 |
1355 HInstruction potentiallyCheckType(HInstruction original, | 1356 HInstruction potentiallyCheckType(HInstruction original, |
1356 Element sourceElement) { | 1357 Element sourceElement) { |
1357 if (!compiler.enableTypeAssertions) return original; | 1358 if (!compiler.enableTypeAssertions) return original; |
1358 return convertType(original, sourceElement, | 1359 HInstruction other = original.convertType( |
1359 HTypeConversion.CHECKED_MODE_CHECK); | 1360 compiler, sourceElement, HTypeConversion.CHECKED_MODE_CHECK); |
1360 } | 1361 if (other != original) add(other); |
1361 | 1362 return other; |
1362 HInstruction convertType(HInstruction original, | |
1363 Element sourceElement, | |
1364 int kind) { | |
1365 DartType type = sourceElement.computeType(compiler); | |
1366 if (type === null) return original; | |
1367 if (type.element === compiler.dynamicClass) return original; | |
1368 if (type.element === compiler.objectClass) return original; | |
1369 | |
1370 // If the original can't be null, type conversion also can't produce null. | |
1371 bool canBeNull = original.guaranteedType.canBeNull(); | |
1372 HType convertedType = | |
1373 new HType.fromBoundedType(type, compiler, canBeNull); | |
1374 | |
1375 // No need to convert if we know the instruction has | |
1376 // [convertedType] as a bound. | |
1377 if (original.guaranteedType == convertedType) { | |
1378 return original; | |
1379 } | |
1380 | |
1381 HInstruction instruction = | |
1382 new HTypeConversion(convertedType, original, kind); | |
1383 add(instruction); | |
1384 return instruction; | |
1385 } | 1363 } |
1386 | 1364 |
1387 HGraph closeFunction() { | 1365 HGraph closeFunction() { |
1388 // TODO(kasperl): Make this goto an implicit return. | 1366 // TODO(kasperl): Make this goto an implicit return. |
1389 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); | 1367 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); |
1390 graph.finalize(); | 1368 graph.finalize(); |
1391 return graph; | 1369 return graph; |
1392 } | 1370 } |
1393 | 1371 |
1394 HBasicBlock addNewBlock() { | 1372 HBasicBlock addNewBlock() { |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 instruction = new HNot(instruction); | 2182 instruction = new HNot(instruction); |
2205 } | 2183 } |
2206 push(instruction); | 2184 push(instruction); |
2207 } | 2185 } |
2208 } else if (const SourceString("as") == op.source) { | 2186 } else if (const SourceString("as") == op.source) { |
2209 visit(node.receiver); | 2187 visit(node.receiver); |
2210 HInstruction expression = pop(); | 2188 HInstruction expression = pop(); |
2211 Node argument = node.arguments.head; | 2189 Node argument = node.arguments.head; |
2212 TypeAnnotation typeAnnotation = argument.asTypeAnnotation(); | 2190 TypeAnnotation typeAnnotation = argument.asTypeAnnotation(); |
2213 DartType type = elements.getType(typeAnnotation); | 2191 DartType type = elements.getType(typeAnnotation); |
2214 HInstruction converted = convertType(expression, type.element, | 2192 HInstruction converted = expression.convertType( |
2215 HTypeConversion.CAST_TYPE_CHECK); | 2193 compiler, type.element, HTypeConversion.CAST_TYPE_CHECK); |
| 2194 if (converted != expression) add(converted); |
2216 stack.add(converted); | 2195 stack.add(converted); |
2217 } else { | 2196 } else { |
2218 visit(node.receiver); | 2197 visit(node.receiver); |
2219 visit(node.argumentsNode); | 2198 visit(node.argumentsNode); |
2220 var right = pop(); | 2199 var right = pop(); |
2221 var left = pop(); | 2200 var left = pop(); |
2222 visitBinary(left, op, right); | 2201 visitBinary(left, op, right); |
2223 } | 2202 } |
2224 } | 2203 } |
2225 | 2204 |
(...skipping 1827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4053 new HSubGraphBlockInformation(elseBranch.graph)); | 4032 new HSubGraphBlockInformation(elseBranch.graph)); |
4054 | 4033 |
4055 HBasicBlock conditionStartBlock = conditionBranch.block; | 4034 HBasicBlock conditionStartBlock = conditionBranch.block; |
4056 conditionStartBlock.setBlockFlow(info, joinBlock); | 4035 conditionStartBlock.setBlockFlow(info, joinBlock); |
4057 SubGraph conditionGraph = conditionBranch.graph; | 4036 SubGraph conditionGraph = conditionBranch.graph; |
4058 HIf branch = conditionGraph.end.last; | 4037 HIf branch = conditionGraph.end.last; |
4059 assert(branch is HIf); | 4038 assert(branch is HIf); |
4060 branch.blockInformation = conditionStartBlock.blockFlow; | 4039 branch.blockInformation = conditionStartBlock.blockFlow; |
4061 } | 4040 } |
4062 } | 4041 } |
OLD | NEW |