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 import '../common.dart'; | 5 import '../common.dart'; |
6 import '../common_elements.dart'; | 6 import '../common_elements.dart'; |
7 import '../elements/elements.dart' show ErroneousElement; | 7 import '../elements/elements.dart' show ErroneousElement; |
8 import '../elements/entities.dart'; | 8 import '../elements/entities.dart'; |
9 import '../elements/resolution_types.dart' show MalformedType; | 9 import '../elements/resolution_types.dart' show MalformedType; |
10 import '../elements/types.dart'; | 10 import '../elements/types.dart'; |
11 import '../js/js.dart' as jsAst; | 11 import '../js/js.dart' as jsAst; |
12 import '../js/js.dart' show js; | 12 import '../js/js.dart' show js; |
13 import '../ssa/codegen.dart' show SsaCodeGenerator; | 13 import '../ssa/codegen.dart' show SsaCodeGenerator; |
14 import '../ssa/nodes.dart' show HTypeConversion; | 14 import '../ssa/nodes.dart' show HTypeConversion; |
15 import '../universe/call_structure.dart' show CallStructure; | 15 import '../universe/call_structure.dart' show CallStructure; |
16 import '../universe/use.dart' show StaticUse; | 16 import '../universe/use.dart' show StaticUse; |
17 import 'backend_helpers.dart'; | 17 import 'backend_helpers.dart'; |
| 18 import 'namer.dart' show Namer; |
18 | 19 |
19 class CheckedModeHelper { | 20 class CheckedModeHelper { |
20 final String name; | 21 final String name; |
21 | 22 |
22 const CheckedModeHelper(String this.name); | 23 const CheckedModeHelper(String this.name); |
23 | 24 |
24 StaticUse getStaticUse(BackendHelpers helpers) { | 25 StaticUse getStaticUse(BackendHelpers helpers) { |
25 // TODO(johnniwinther): Refactor this to avoid looking up directly in the | 26 // TODO(johnniwinther): Refactor this to avoid looking up directly in the |
26 // js helper library but instead access helpers directly on backend helpers. | 27 // js helper library but instead access helpers directly on backend helpers. |
27 return new StaticUse.staticInvoke( | 28 return new StaticUse.staticInvoke( |
28 helpers.findHelperFunction(name), callStructure); | 29 helpers.findHelperFunction(name), callStructure); |
29 } | 30 } |
30 | 31 |
31 CallStructure get callStructure => CallStructure.ONE_ARG; | 32 CallStructure get callStructure => CallStructure.ONE_ARG; |
32 | 33 |
33 jsAst.Expression generateCall( | 34 void generateAdditionalArguments(SsaCodeGenerator codegen, Namer namer, |
34 SsaCodeGenerator codegen, HTypeConversion node) { | |
35 StaticUse staticUse = getStaticUse(codegen.backend.helpers); | |
36 codegen.registry.registerStaticUse(staticUse); | |
37 List<jsAst.Expression> arguments = <jsAst.Expression>[]; | |
38 codegen.use(node.checkedInput); | |
39 arguments.add(codegen.pop()); | |
40 generateAdditionalArguments(codegen, node, arguments); | |
41 jsAst.Expression helper = | |
42 codegen.backend.emitter.staticFunctionAccess(staticUse.element); | |
43 return new jsAst.Call(helper, arguments); | |
44 } | |
45 | |
46 void generateAdditionalArguments(SsaCodeGenerator codegen, | |
47 HTypeConversion node, List<jsAst.Expression> arguments) { | 35 HTypeConversion node, List<jsAst.Expression> arguments) { |
48 // No additional arguments needed. | 36 // No additional arguments needed. |
49 } | 37 } |
50 } | 38 } |
51 | 39 |
52 class MalformedCheckedModeHelper extends CheckedModeHelper { | 40 class MalformedCheckedModeHelper extends CheckedModeHelper { |
53 const MalformedCheckedModeHelper(String name) : super(name); | 41 const MalformedCheckedModeHelper(String name) : super(name); |
54 | 42 |
55 CallStructure get callStructure => CallStructure.TWO_ARGS; | 43 CallStructure get callStructure => CallStructure.TWO_ARGS; |
56 | 44 |
57 void generateAdditionalArguments(SsaCodeGenerator codegen, | 45 void generateAdditionalArguments(SsaCodeGenerator codegen, Namer namer, |
58 HTypeConversion node, List<jsAst.Expression> arguments) { | 46 HTypeConversion node, List<jsAst.Expression> arguments) { |
59 // TODO(johnniwinther): Support malformed types in [types.dart]. | 47 // TODO(johnniwinther): Support malformed types in [types.dart]. |
60 MalformedType type = node.typeExpression; | 48 MalformedType type = node.typeExpression; |
61 ErroneousElement element = type.element; | 49 ErroneousElement element = type.element; |
62 arguments.add(js.escapedString(element.message)); | 50 arguments.add(js.escapedString(element.message)); |
63 } | 51 } |
64 } | 52 } |
65 | 53 |
66 class PropertyCheckedModeHelper extends CheckedModeHelper { | 54 class PropertyCheckedModeHelper extends CheckedModeHelper { |
67 const PropertyCheckedModeHelper(String name) : super(name); | 55 const PropertyCheckedModeHelper(String name) : super(name); |
68 | 56 |
69 CallStructure get callStructure => CallStructure.TWO_ARGS; | 57 CallStructure get callStructure => CallStructure.TWO_ARGS; |
70 | 58 |
71 void generateAdditionalArguments(SsaCodeGenerator codegen, | 59 void generateAdditionalArguments(SsaCodeGenerator codegen, Namer namer, |
72 HTypeConversion node, List<jsAst.Expression> arguments) { | 60 HTypeConversion node, List<jsAst.Expression> arguments) { |
73 DartType type = node.typeExpression; | 61 DartType type = node.typeExpression; |
74 jsAst.Name additionalArgument = codegen.backend.namer.operatorIsType(type); | 62 jsAst.Name additionalArgument = namer.operatorIsType(type); |
75 arguments.add(js.quoteName(additionalArgument)); | 63 arguments.add(js.quoteName(additionalArgument)); |
76 } | 64 } |
77 } | 65 } |
78 | 66 |
79 class TypeVariableCheckedModeHelper extends CheckedModeHelper { | 67 class TypeVariableCheckedModeHelper extends CheckedModeHelper { |
80 const TypeVariableCheckedModeHelper(String name) : super(name); | 68 const TypeVariableCheckedModeHelper(String name) : super(name); |
81 | 69 |
82 CallStructure get callStructure => CallStructure.TWO_ARGS; | 70 CallStructure get callStructure => CallStructure.TWO_ARGS; |
83 | 71 |
84 void generateAdditionalArguments(SsaCodeGenerator codegen, | 72 void generateAdditionalArguments(SsaCodeGenerator codegen, Namer namer, |
85 HTypeConversion node, List<jsAst.Expression> arguments) { | 73 HTypeConversion node, List<jsAst.Expression> arguments) { |
86 assert(node.typeExpression.isTypeVariable); | 74 assert(node.typeExpression.isTypeVariable); |
87 codegen.use(node.typeRepresentation); | 75 codegen.use(node.typeRepresentation); |
88 arguments.add(codegen.pop()); | 76 arguments.add(codegen.pop()); |
89 } | 77 } |
90 } | 78 } |
91 | 79 |
92 class FunctionTypeRepresentationCheckedModeHelper extends CheckedModeHelper { | 80 class FunctionTypeRepresentationCheckedModeHelper extends CheckedModeHelper { |
93 const FunctionTypeRepresentationCheckedModeHelper(String name) : super(name); | 81 const FunctionTypeRepresentationCheckedModeHelper(String name) : super(name); |
94 | 82 |
95 CallStructure get callStructure => CallStructure.TWO_ARGS; | 83 CallStructure get callStructure => CallStructure.TWO_ARGS; |
96 | 84 |
97 void generateAdditionalArguments(SsaCodeGenerator codegen, | 85 void generateAdditionalArguments(SsaCodeGenerator codegen, Namer namer, |
98 HTypeConversion node, List<jsAst.Expression> arguments) { | 86 HTypeConversion node, List<jsAst.Expression> arguments) { |
99 assert(node.typeExpression.isFunctionType); | 87 assert(node.typeExpression.isFunctionType); |
100 codegen.use(node.typeRepresentation); | 88 codegen.use(node.typeRepresentation); |
101 arguments.add(codegen.pop()); | 89 arguments.add(codegen.pop()); |
102 } | 90 } |
103 } | 91 } |
104 | 92 |
105 class SubtypeCheckedModeHelper extends CheckedModeHelper { | 93 class SubtypeCheckedModeHelper extends CheckedModeHelper { |
106 const SubtypeCheckedModeHelper(String name) : super(name); | 94 const SubtypeCheckedModeHelper(String name) : super(name); |
107 | 95 |
108 CallStructure get callStructure => const CallStructure.unnamed(4); | 96 CallStructure get callStructure => const CallStructure.unnamed(4); |
109 | 97 |
110 void generateAdditionalArguments(SsaCodeGenerator codegen, | 98 void generateAdditionalArguments(SsaCodeGenerator codegen, Namer namer, |
111 HTypeConversion node, List<jsAst.Expression> arguments) { | 99 HTypeConversion node, List<jsAst.Expression> arguments) { |
112 // TODO(sra): Move these calls into the SSA graph so that the arguments can | 100 // TODO(sra): Move these calls into the SSA graph so that the arguments can |
113 // be optimized, e,g, GVNed. | 101 // be optimized, e,g, GVNed. |
114 InterfaceType type = node.typeExpression; | 102 InterfaceType type = node.typeExpression; |
115 ClassEntity element = type.element; | 103 ClassEntity element = type.element; |
116 jsAst.Name isField = codegen.backend.namer.operatorIs(element); | 104 jsAst.Name isField = namer.operatorIs(element); |
117 arguments.add(js.quoteName(isField)); | 105 arguments.add(js.quoteName(isField)); |
118 codegen.use(node.typeRepresentation); | 106 codegen.use(node.typeRepresentation); |
119 arguments.add(codegen.pop()); | 107 arguments.add(codegen.pop()); |
120 jsAst.Name asField = codegen.backend.namer.substitutionName(element); | 108 jsAst.Name asField = namer.substitutionName(element); |
121 arguments.add(js.quoteName(asField)); | 109 arguments.add(js.quoteName(asField)); |
122 } | 110 } |
123 } | 111 } |
124 | 112 |
125 class CheckedModeHelpers { | 113 class CheckedModeHelpers { |
126 final CommonElements _commonElements; | 114 final CommonElements _commonElements; |
127 final BackendHelpers _helpers; | 115 final BackendHelpers _helpers; |
128 | 116 |
129 CheckedModeHelpers(this._commonElements, this._helpers); | 117 CheckedModeHelpers(this._commonElements, this._helpers); |
130 | 118 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 292 |
305 if (nativeCheck) { | 293 if (nativeCheck) { |
306 // TODO(karlklose): can we get rid of this branch when we use | 294 // TODO(karlklose): can we get rid of this branch when we use |
307 // interceptors? | 295 // interceptors? |
308 return 'intercepted$suffix'; | 296 return 'intercepted$suffix'; |
309 } else { | 297 } else { |
310 return 'property$suffix'; | 298 return 'property$suffix'; |
311 } | 299 } |
312 } | 300 } |
313 } | 301 } |
OLD | NEW |