OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 js_backend; | 5 part of js_backend; |
6 | 6 |
7 class CheckedModeHelper { | 7 class CheckedModeHelper { |
8 final String name; | 8 final String name; |
9 | 9 |
10 const CheckedModeHelper(String this.name); | 10 const CheckedModeHelper(String this.name); |
11 | 11 |
12 Element getElement(Compiler compiler) { | 12 StaticUse getStaticUse(Compiler compiler) { |
13 JavaScriptBackend backend = compiler.backend; | 13 JavaScriptBackend backend = compiler.backend; |
14 return backend.helpers.findHelper(name); | 14 return new StaticUse.staticInvoke( |
| 15 backend.helpers.findHelper(name), callStructure); |
15 } | 16 } |
16 | 17 |
| 18 CallStructure get callStructure => CallStructure.ONE_ARG; |
| 19 |
17 jsAst.Expression generateCall(SsaCodeGenerator codegen, | 20 jsAst.Expression generateCall(SsaCodeGenerator codegen, |
18 HTypeConversion node) { | 21 HTypeConversion node) { |
19 Element helperElement = getElement(codegen.compiler); | 22 StaticUse staticUse = getStaticUse(codegen.compiler); |
20 codegen.registry.registerStaticUse(helperElement); | 23 codegen.registry.registerStaticUse(staticUse); |
21 List<jsAst.Expression> arguments = <jsAst.Expression>[]; | 24 List<jsAst.Expression> arguments = <jsAst.Expression>[]; |
22 codegen.use(node.checkedInput); | 25 codegen.use(node.checkedInput); |
23 arguments.add(codegen.pop()); | 26 arguments.add(codegen.pop()); |
24 generateAdditionalArguments(codegen, node, arguments); | 27 generateAdditionalArguments(codegen, node, arguments); |
25 jsAst.Expression helper = | 28 jsAst.Expression helper = |
26 codegen.backend.emitter.staticFunctionAccess(helperElement); | 29 codegen.backend.emitter.staticFunctionAccess(staticUse.element); |
27 return new jsAst.Call(helper, arguments); | 30 return new jsAst.Call(helper, arguments); |
28 } | 31 } |
29 | 32 |
30 void generateAdditionalArguments(SsaCodeGenerator codegen, | 33 void generateAdditionalArguments(SsaCodeGenerator codegen, |
31 HTypeConversion node, | 34 HTypeConversion node, |
32 List<jsAst.Expression> arguments) { | 35 List<jsAst.Expression> arguments) { |
33 // No additional arguments needed. | 36 // No additional arguments needed. |
34 } | 37 } |
35 | 38 |
36 static const List<CheckedModeHelper> helpers = const <CheckedModeHelper> [ | 39 static const List<CheckedModeHelper> helpers = const <CheckedModeHelper> [ |
(...skipping 29 matching lines...) Expand all Loading... |
66 const SubtypeCheckedModeHelper('assertSubtype'), | 69 const SubtypeCheckedModeHelper('assertSubtype'), |
67 const TypeVariableCheckedModeHelper('subtypeOfRuntimeTypeCast'), | 70 const TypeVariableCheckedModeHelper('subtypeOfRuntimeTypeCast'), |
68 const TypeVariableCheckedModeHelper('assertSubtypeOfRuntimeType'), | 71 const TypeVariableCheckedModeHelper('assertSubtypeOfRuntimeType'), |
69 const PropertyCheckedModeHelper('propertyTypeCast'), | 72 const PropertyCheckedModeHelper('propertyTypeCast'), |
70 const PropertyCheckedModeHelper('propertyTypeCheck')]; | 73 const PropertyCheckedModeHelper('propertyTypeCheck')]; |
71 } | 74 } |
72 | 75 |
73 class MalformedCheckedModeHelper extends CheckedModeHelper { | 76 class MalformedCheckedModeHelper extends CheckedModeHelper { |
74 const MalformedCheckedModeHelper(String name) : super(name); | 77 const MalformedCheckedModeHelper(String name) : super(name); |
75 | 78 |
| 79 CallStructure get callStructure => CallStructure.TWO_ARGS; |
| 80 |
76 void generateAdditionalArguments(SsaCodeGenerator codegen, | 81 void generateAdditionalArguments(SsaCodeGenerator codegen, |
77 HTypeConversion node, | 82 HTypeConversion node, |
78 List<jsAst.Expression> arguments) { | 83 List<jsAst.Expression> arguments) { |
79 ErroneousElement element = node.typeExpression.element; | 84 ErroneousElement element = node.typeExpression.element; |
80 arguments.add(js.escapedString(element.message)); | 85 arguments.add(js.escapedString(element.message)); |
81 } | 86 } |
82 } | 87 } |
83 | 88 |
84 class PropertyCheckedModeHelper extends CheckedModeHelper { | 89 class PropertyCheckedModeHelper extends CheckedModeHelper { |
85 const PropertyCheckedModeHelper(String name) : super(name); | 90 const PropertyCheckedModeHelper(String name) : super(name); |
86 | 91 |
| 92 CallStructure get callStructure => CallStructure.TWO_ARGS; |
| 93 |
87 void generateAdditionalArguments(SsaCodeGenerator codegen, | 94 void generateAdditionalArguments(SsaCodeGenerator codegen, |
88 HTypeConversion node, | 95 HTypeConversion node, |
89 List<jsAst.Expression> arguments) { | 96 List<jsAst.Expression> arguments) { |
90 DartType type = node.typeExpression; | 97 DartType type = node.typeExpression; |
91 jsAst.Name additionalArgument = codegen.backend.namer.operatorIsType(type); | 98 jsAst.Name additionalArgument = codegen.backend.namer.operatorIsType(type); |
92 arguments.add(js.quoteName(additionalArgument)); | 99 arguments.add(js.quoteName(additionalArgument)); |
93 } | 100 } |
94 } | 101 } |
95 | 102 |
96 class TypeVariableCheckedModeHelper extends CheckedModeHelper { | 103 class TypeVariableCheckedModeHelper extends CheckedModeHelper { |
97 const TypeVariableCheckedModeHelper(String name) : super(name); | 104 const TypeVariableCheckedModeHelper(String name) : super(name); |
98 | 105 |
| 106 CallStructure get callStructure => CallStructure.TWO_ARGS; |
| 107 |
99 void generateAdditionalArguments(SsaCodeGenerator codegen, | 108 void generateAdditionalArguments(SsaCodeGenerator codegen, |
100 HTypeConversion node, | 109 HTypeConversion node, |
101 List<jsAst.Expression> arguments) { | 110 List<jsAst.Expression> arguments) { |
102 assert(node.typeExpression.isTypeVariable); | 111 assert(node.typeExpression.isTypeVariable); |
103 codegen.use(node.typeRepresentation); | 112 codegen.use(node.typeRepresentation); |
104 arguments.add(codegen.pop()); | 113 arguments.add(codegen.pop()); |
105 } | 114 } |
106 } | 115 } |
107 | 116 |
108 class SubtypeCheckedModeHelper extends CheckedModeHelper { | 117 class SubtypeCheckedModeHelper extends CheckedModeHelper { |
109 const SubtypeCheckedModeHelper(String name) : super(name); | 118 const SubtypeCheckedModeHelper(String name) : super(name); |
110 | 119 |
| 120 CallStructure get callStructure => const CallStructure.unnamed(4); |
| 121 |
111 void generateAdditionalArguments(SsaCodeGenerator codegen, | 122 void generateAdditionalArguments(SsaCodeGenerator codegen, |
112 HTypeConversion node, | 123 HTypeConversion node, |
113 List<jsAst.Expression> arguments) { | 124 List<jsAst.Expression> arguments) { |
114 DartType type = node.typeExpression; | 125 DartType type = node.typeExpression; |
115 Element element = type.element; | 126 Element element = type.element; |
116 jsAst.Name isField = codegen.backend.namer.operatorIs(element); | 127 jsAst.Name isField = codegen.backend.namer.operatorIs(element); |
117 arguments.add(js.quoteName(isField)); | 128 arguments.add(js.quoteName(isField)); |
118 codegen.use(node.typeRepresentation); | 129 codegen.use(node.typeRepresentation); |
119 arguments.add(codegen.pop()); | 130 arguments.add(codegen.pop()); |
120 jsAst.Name asField = codegen.backend.namer.substitutionName(element); | 131 jsAst.Name asField = codegen.backend.namer.substitutionName(element); |
121 arguments.add(js.quoteName(asField)); | 132 arguments.add(js.quoteName(asField)); |
122 } | 133 } |
123 } | 134 } |
OLD | NEW |