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 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 | 1066 |
1067 localsHandler.startFunction(functionElement, node); | 1067 localsHandler.startFunction(functionElement, node); |
1068 close(new HGoto()).addSuccessor(block); | 1068 close(new HGoto()).addSuccessor(block); |
1069 | 1069 |
1070 open(block); | 1070 open(block); |
1071 } | 1071 } |
1072 | 1072 |
1073 HInstruction potentiallyCheckType(HInstruction original, | 1073 HInstruction potentiallyCheckType(HInstruction original, |
1074 Element sourceElement) { | 1074 Element sourceElement) { |
1075 if (!compiler.enableTypeAssertions) return original; | 1075 if (!compiler.enableTypeAssertions) return original; |
| 1076 return convertType(original, sourceElement, HTypeConversion.CHECKED); |
| 1077 } |
1076 | 1078 |
| 1079 HInstruction convertType(HInstruction original, |
| 1080 Element sourceElement, |
| 1081 int kind) { |
1077 Type type = sourceElement.computeType(compiler); | 1082 Type type = sourceElement.computeType(compiler); |
1078 if (type === null) return original; | 1083 if (type === null) return original; |
1079 if (type.element === compiler.dynamicClass) return original; | 1084 if (type.element === compiler.dynamicClass) return original; |
1080 if (type.element === compiler.objectClass) return original; | 1085 if (type.element === compiler.objectClass) return original; |
1081 | 1086 |
1082 HType convertedType = new HType.fromBoundedType(type, compiler, true); | 1087 HType convertedType = new HType.fromBoundedType(type, compiler, true); |
1083 | 1088 |
1084 // No need to convert if we know the instruction has | 1089 // No need to convert if we know the instruction has |
1085 // [convertedType] as a bound. | 1090 // [convertedType] as a bound. |
1086 if (original.guaranteedType == convertedType) { | 1091 if (original.guaranteedType == convertedType) { |
1087 return original; | 1092 return original; |
1088 } | 1093 } |
1089 | 1094 |
1090 HInstruction instruction = | 1095 HInstruction instruction = |
1091 new HTypeConversion(convertedType, original, true); | 1096 new HTypeConversion(convertedType, original, kind); |
1092 add(instruction); | 1097 add(instruction); |
1093 return instruction; | 1098 return instruction; |
1094 } | 1099 } |
1095 | 1100 |
1096 HGraph closeFunction() { | 1101 HGraph closeFunction() { |
1097 // TODO(kasperl): Make this goto an implicit return. | 1102 // TODO(kasperl): Make this goto an implicit return. |
1098 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); | 1103 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); |
1099 graph.finalize(); | 1104 graph.finalize(); |
1100 return graph; | 1105 return graph; |
1101 } | 1106 } |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 instruction = new HIs.withTypeInfoCall(type, expression, typeInfo); | 1957 instruction = new HIs.withTypeInfoCall(type, expression, typeInfo); |
1953 } else { | 1958 } else { |
1954 instruction = new HIs(type, expression); | 1959 instruction = new HIs(type, expression); |
1955 } | 1960 } |
1956 if (isNot) { | 1961 if (isNot) { |
1957 add(instruction); | 1962 add(instruction); |
1958 instruction = new HNot(instruction); | 1963 instruction = new HNot(instruction); |
1959 } | 1964 } |
1960 push(instruction); | 1965 push(instruction); |
1961 } | 1966 } |
| 1967 } else if (const SourceString("as") == op.source) { |
| 1968 visit(node.receiver); |
| 1969 HInstruction expression = pop(); |
| 1970 Node argument = node.arguments.head; |
| 1971 TypeAnnotation typeAnnotation = argument.asTypeAnnotation(); |
| 1972 Type type = elements.getType(typeAnnotation); |
| 1973 HInstruction converted = |
| 1974 convertType(expression, type.element, HTypeConversion.CAST); |
| 1975 stack.add(converted); |
1962 } else { | 1976 } else { |
1963 visit(node.receiver); | 1977 visit(node.receiver); |
1964 visit(node.argumentsNode); | 1978 visit(node.argumentsNode); |
1965 var right = pop(); | 1979 var right = pop(); |
1966 var left = pop(); | 1980 var left = pop(); |
1967 visitBinary(left, op, right); | 1981 visitBinary(left, op, right); |
1968 } | 1982 } |
1969 } | 1983 } |
1970 | 1984 |
1971 void addDynamicSendArgumentsToList(Send node, List<HInstruction> list) { | 1985 void addDynamicSendArgumentsToList(Send node, List<HInstruction> list) { |
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3430 void visitNodeList(NodeList node) { | 3444 void visitNodeList(NodeList node) { |
3431 node.visitChildren(this); | 3445 node.visitChildren(this); |
3432 } | 3446 } |
3433 | 3447 |
3434 HInstruction concat(HInstruction left, HInstruction right) { | 3448 HInstruction concat(HInstruction left, HInstruction right) { |
3435 HInstruction instruction = new HStringConcat(left, right, node); | 3449 HInstruction instruction = new HStringConcat(left, right, node); |
3436 builder.add(instruction); | 3450 builder.add(instruction); |
3437 return instruction; | 3451 return instruction; |
3438 } | 3452 } |
3439 } | 3453 } |
OLD | NEW |