OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.js_emitter.startup_emitter; | 5 library dart2js.js_emitter.startup_emitter; |
6 | 6 |
7 import 'package:js_runtime/shared/embedded_names.dart' show | 7 import 'package:js_runtime/shared/embedded_names.dart' |
8 JsBuiltin, | 8 show JsBuiltin, METADATA, STATIC_FUNCTION_NAME_TO_CLOSURE, TYPES; |
9 METADATA, | |
10 STATIC_FUNCTION_NAME_TO_CLOSURE, | |
11 TYPES; | |
12 | 9 |
13 import '../../common.dart'; | 10 import '../../common.dart'; |
14 import '../../compiler.dart' show | 11 import '../../compiler.dart' show Compiler; |
15 Compiler; | 12 import '../../constants/values.dart' show ConstantValue; |
16 import '../../constants/values.dart' show | 13 import '../../elements/elements.dart' |
17 ConstantValue; | 14 show ClassElement, Element, FieldElement, FunctionElement; |
18 import '../../elements/elements.dart' show | |
19 ClassElement, | |
20 Element, | |
21 FieldElement, | |
22 FunctionElement; | |
23 import '../../js/js.dart' as js; | 15 import '../../js/js.dart' as js; |
24 import '../../js_backend/js_backend.dart' show | 16 import '../../js_backend/js_backend.dart' show JavaScriptBackend, Namer; |
25 JavaScriptBackend, | |
26 Namer; | |
27 | 17 |
28 import '../js_emitter.dart' show | 18 import '../js_emitter.dart' show NativeEmitter; |
29 NativeEmitter; | 19 import '../js_emitter.dart' as emitterTask show Emitter; |
30 import '../js_emitter.dart' as emitterTask show | |
31 Emitter; | |
32 import '../program_builder/program_builder.dart' show ProgramBuilder; | 20 import '../program_builder/program_builder.dart' show ProgramBuilder; |
33 import '../model.dart'; | 21 import '../model.dart'; |
34 | 22 |
35 import 'model_emitter.dart'; | 23 import 'model_emitter.dart'; |
36 | 24 |
37 class Emitter implements emitterTask.Emitter { | 25 class Emitter implements emitterTask.Emitter { |
38 final Compiler _compiler; | 26 final Compiler _compiler; |
39 final Namer namer; | 27 final Namer namer; |
40 final ModelEmitter _emitter; | 28 final ModelEmitter _emitter; |
41 | 29 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 78 |
91 js.PropertyAccess _globalPropertyAccess(Element element) { | 79 js.PropertyAccess _globalPropertyAccess(Element element) { |
92 js.Name name = namer.globalPropertyName(element); | 80 js.Name name = namer.globalPropertyName(element); |
93 js.PropertyAccess pa = new js.PropertyAccess( | 81 js.PropertyAccess pa = new js.PropertyAccess( |
94 new js.VariableUse(namer.globalObjectFor(element)), name); | 82 new js.VariableUse(namer.globalObjectFor(element)), name); |
95 return pa; | 83 return pa; |
96 } | 84 } |
97 | 85 |
98 @override | 86 @override |
99 js.Expression isolateLazyInitializerAccess(FieldElement element) { | 87 js.Expression isolateLazyInitializerAccess(FieldElement element) { |
100 return js.js('#.#', [namer.globalObjectFor(element), | 88 return js.js('#.#', |
101 namer.lazyInitializerName(element)]); | 89 [namer.globalObjectFor(element), namer.lazyInitializerName(element)]); |
102 } | 90 } |
103 | 91 |
104 @override | 92 @override |
105 js.Expression isolateStaticClosureAccess(FunctionElement element) { | 93 js.Expression isolateStaticClosureAccess(FunctionElement element) { |
106 return _emitter.generateStaticClosureAccess(element); | 94 return _emitter.generateStaticClosureAccess(element); |
107 } | 95 } |
108 | 96 |
109 @override | 97 @override |
110 js.PropertyAccess staticFieldAccess(FieldElement element) { | 98 js.PropertyAccess staticFieldAccess(FieldElement element) { |
111 return _globalPropertyAccess(element); | 99 return _globalPropertyAccess(element); |
112 } | 100 } |
113 | 101 |
114 @override | 102 @override |
115 js.PropertyAccess staticFunctionAccess(FunctionElement element) { | 103 js.PropertyAccess staticFunctionAccess(FunctionElement element) { |
116 return _globalPropertyAccess(element); | 104 return _globalPropertyAccess(element); |
117 } | 105 } |
118 | 106 |
119 @override | 107 @override |
120 js.PropertyAccess constructorAccess(ClassElement element) { | 108 js.PropertyAccess constructorAccess(ClassElement element) { |
121 return _globalPropertyAccess(element); | 109 return _globalPropertyAccess(element); |
122 } | 110 } |
123 | 111 |
124 @override | 112 @override |
125 js.PropertyAccess prototypeAccess(ClassElement element, | 113 js.PropertyAccess prototypeAccess( |
126 bool hasBeenInstantiated) { | 114 ClassElement element, bool hasBeenInstantiated) { |
127 js.Expression constructor = | 115 js.Expression constructor = |
128 hasBeenInstantiated ? constructorAccess(element) : typeAccess(element); | 116 hasBeenInstantiated ? constructorAccess(element) : typeAccess(element); |
129 return js.js('#.prototype', constructor); | 117 return js.js('#.prototype', constructor); |
130 } | 118 } |
131 | 119 |
132 @override | 120 @override |
133 js.Expression interceptorClassAccess(ClassElement element) { | 121 js.Expression interceptorClassAccess(ClassElement element) { |
134 return _globalPropertyAccess(element); | 122 return _globalPropertyAccess(element); |
135 } | 123 } |
136 | 124 |
(...skipping 21 matching lines...) Expand all Loading... |
158 case JsBuiltin.rawRtiToJsConstructorName: | 146 case JsBuiltin.rawRtiToJsConstructorName: |
159 return js.js.expressionTemplateFor("#.$typeNameProperty"); | 147 return js.js.expressionTemplateFor("#.$typeNameProperty"); |
160 | 148 |
161 case JsBuiltin.rawRuntimeType: | 149 case JsBuiltin.rawRuntimeType: |
162 return js.js.expressionTemplateFor("#.constructor"); | 150 return js.js.expressionTemplateFor("#.constructor"); |
163 | 151 |
164 case JsBuiltin.createFunctionTypeRti: | 152 case JsBuiltin.createFunctionTypeRti: |
165 return _backend.rtiEncoder.templateForCreateFunctionType; | 153 return _backend.rtiEncoder.templateForCreateFunctionType; |
166 | 154 |
167 case JsBuiltin.isSubtype: | 155 case JsBuiltin.isSubtype: |
168 // TODO(floitsch): move this closer to where is-check properties are | 156 // TODO(floitsch): move this closer to where is-check properties are |
169 // built. | 157 // built. |
170 String isPrefix = namer.operatorIsPrefix; | 158 String isPrefix = namer.operatorIsPrefix; |
171 return js.js.expressionTemplateFor("('$isPrefix' + #) in #.prototype"); | 159 return js.js.expressionTemplateFor("('$isPrefix' + #) in #.prototype"); |
172 | 160 |
173 case JsBuiltin.isGivenTypeRti: | 161 case JsBuiltin.isGivenTypeRti: |
174 return js.js.expressionTemplateFor('#.$typeNameProperty === #'); | 162 return js.js.expressionTemplateFor('#.$typeNameProperty === #'); |
175 | 163 |
176 case JsBuiltin.getMetadata: | 164 case JsBuiltin.getMetadata: |
177 String metadataAccess = | 165 String metadataAccess = |
178 _emitter.generateEmbeddedGlobalAccessString(METADATA); | 166 _emitter.generateEmbeddedGlobalAccessString(METADATA); |
179 return js.js.expressionTemplateFor("$metadataAccess[#]"); | 167 return js.js.expressionTemplateFor("$metadataAccess[#]"); |
180 | 168 |
181 case JsBuiltin.getType: | 169 case JsBuiltin.getType: |
182 String typesAccess = | 170 String typesAccess = _emitter.generateEmbeddedGlobalAccessString(TYPES); |
183 _emitter.generateEmbeddedGlobalAccessString(TYPES); | |
184 return js.js.expressionTemplateFor("$typesAccess[#]"); | 171 return js.js.expressionTemplateFor("$typesAccess[#]"); |
185 | 172 |
186 case JsBuiltin.createDartClosureFromNameOfStaticFunction: | 173 case JsBuiltin.createDartClosureFromNameOfStaticFunction: |
187 String functionAccess = _emitter.generateEmbeddedGlobalAccessString( | 174 String functionAccess = _emitter.generateEmbeddedGlobalAccessString( |
188 STATIC_FUNCTION_NAME_TO_CLOSURE); | 175 STATIC_FUNCTION_NAME_TO_CLOSURE); |
189 return js.js.expressionTemplateFor("$functionAccess(#)"); | 176 return js.js.expressionTemplateFor("$functionAccess(#)"); |
190 | 177 |
191 default: | 178 default: |
192 reporter.internalError(NO_LOCATION_SPANNABLE, | 179 reporter.internalError( |
193 "Unhandled Builtin: $builtin"); | 180 NO_LOCATION_SPANNABLE, "Unhandled Builtin: $builtin"); |
194 return null; | 181 return null; |
195 } | 182 } |
196 } | 183 } |
197 | 184 |
198 @override | 185 @override |
199 void invalidateCaches() { | 186 void invalidateCaches() {} |
200 } | |
201 } | 187 } |
OLD | NEW |