OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 'package:js_runtime/shared/embedded_names.dart'; |
5 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
6 | 7 |
7 import '../closure.dart'; | 8 import '../closure.dart'; |
8 import '../common.dart'; | 9 import '../common.dart'; |
9 import '../common/names.dart'; | 10 import '../common/names.dart'; |
10 import '../constants/constructors.dart'; | 11 import '../constants/constructors.dart'; |
11 import '../constants/expressions.dart'; | 12 import '../constants/expressions.dart'; |
12 import '../constants/values.dart'; | 13 import '../constants/values.dart'; |
13 import '../common_elements.dart'; | 14 import '../common_elements.dart'; |
14 import '../elements/entities.dart'; | 15 import '../elements/entities.dart'; |
15 import '../elements/jumps.dart'; | 16 import '../elements/jumps.dart'; |
16 import '../elements/names.dart'; | 17 import '../elements/names.dart'; |
17 import '../elements/operators.dart'; | 18 import '../elements/operators.dart'; |
18 import '../elements/types.dart'; | 19 import '../elements/types.dart'; |
| 20 import '../js/js.dart' as js; |
19 import '../js_backend/backend.dart' show JavaScriptBackend; | 21 import '../js_backend/backend.dart' show JavaScriptBackend; |
| 22 import '../js_backend/namer.dart'; |
| 23 import '../js_emitter/code_emitter_task.dart'; |
20 import '../native/native.dart' as native; | 24 import '../native/native.dart' as native; |
21 import '../types/types.dart'; | 25 import '../types/types.dart'; |
22 import '../universe/call_structure.dart'; | 26 import '../universe/call_structure.dart'; |
23 import '../universe/selector.dart'; | 27 import '../universe/selector.dart'; |
24 import '../world.dart'; | 28 import '../world.dart'; |
25 import 'kernel_debug.dart'; | 29 import 'kernel_debug.dart'; |
26 | 30 |
27 /// Interface that translates between Kernel IR nodes and entities. | 31 /// Interface that translates between Kernel IR nodes and entities. |
28 abstract class KernelToElementMap { | 32 abstract class KernelToElementMap { |
29 /// Access to the commonly used elements and types. | 33 /// Access to the commonly used elements and types. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 ir.StaticInvocation node); | 144 ir.StaticInvocation node); |
141 | 145 |
142 /// Computes the [native.NativeBehavior] for a call to the | 146 /// Computes the [native.NativeBehavior] for a call to the |
143 /// [JS_EMBEDDED_GLOBAL] function. | 147 /// [JS_EMBEDDED_GLOBAL] function. |
144 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall( | 148 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall( |
145 ir.StaticInvocation node); | 149 ir.StaticInvocation node); |
146 | 150 |
147 /// Compute the kind of foreign helper function called by [node], if any. | 151 /// Compute the kind of foreign helper function called by [node], if any. |
148 ForeignKind getForeignKind(ir.StaticInvocation node); | 152 ForeignKind getForeignKind(ir.StaticInvocation node); |
149 | 153 |
| 154 /// Returns the [js.Name] for the `JsGetName` [constant] value. |
| 155 js.Name getNameForJsGetName(ConstantValue constant, Namer namer); |
| 156 |
| 157 /// Returns the [js.Template] for the `JsBuiltin` [constant] value. |
| 158 js.Template getJsBuiltinTemplate( |
| 159 ConstantValue constant, CodeEmitterTask emitter); |
| 160 |
150 /// Computes the [InterfaceType] referenced by a call to the | 161 /// Computes the [InterfaceType] referenced by a call to the |
151 /// [JS_INTERCEPTOR_CONSTANT] function, if any. | 162 /// [JS_INTERCEPTOR_CONSTANT] function, if any. |
152 InterfaceType getInterfaceTypeForJsInterceptorCall(ir.StaticInvocation node); | 163 InterfaceType getInterfaceTypeForJsInterceptorCall(ir.StaticInvocation node); |
153 | 164 |
154 /// Computes the [ConstantValue] for the constant [expression]. | 165 /// Computes the [ConstantValue] for the constant [expression]. |
155 ConstantValue getConstantValue(ir.Expression expression, | 166 ConstantValue getConstantValue(ir.Expression expression, |
156 {bool requireConstant: true, bool implicitNull: false}); | 167 {bool requireConstant: true, bool implicitNull: false}); |
157 | 168 |
158 /// Return the [ConstantValue] the initial value of [field] or `null` if | 169 /// Return the [ConstantValue] the initial value of [field] or `null` if |
159 /// the initializer is not a constant expression. | 170 /// the initializer is not a constant expression. |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 // `Object.superNoSuchMethod`. | 539 // `Object.superNoSuchMethod`. |
529 break; | 540 break; |
530 } | 541 } |
531 } | 542 } |
532 FunctionEntity function = elementEnvironment.lookupClassMember( | 543 FunctionEntity function = elementEnvironment.lookupClassMember( |
533 commonElements.objectClass, Identifiers.noSuchMethod_); | 544 commonElements.objectClass, Identifiers.noSuchMethod_); |
534 assert(function != null, | 545 assert(function != null, |
535 failedAt(cls, "No super noSuchMethod found for class $cls.")); | 546 failedAt(cls, "No super noSuchMethod found for class $cls.")); |
536 return function; | 547 return function; |
537 } | 548 } |
| 549 |
| 550 js.Name getNameForJsGetName(ConstantValue constant, Namer namer) { |
| 551 int index = _extractEnumIndexFromConstantValue( |
| 552 constant, commonElements.jsGetNameEnum); |
| 553 if (index == null) return null; |
| 554 return namer.getNameForJsGetName( |
| 555 CURRENT_ELEMENT_SPANNABLE, JsGetName.values[index]); |
| 556 } |
| 557 |
| 558 js.Template getJsBuiltinTemplate( |
| 559 ConstantValue constant, CodeEmitterTask emitter) { |
| 560 int index = _extractEnumIndexFromConstantValue( |
| 561 constant, commonElements.jsBuiltinEnum); |
| 562 if (index == null) return null; |
| 563 return emitter.builtinTemplateFor(JsBuiltin.values[index]); |
| 564 } |
| 565 |
| 566 int _extractEnumIndexFromConstantValue( |
| 567 ConstantValue constant, ClassEntity classElement) { |
| 568 if (constant is ConstructedConstantValue) { |
| 569 if (constant.type.element == classElement) { |
| 570 assert(constant.fields.length == 1 || constant.fields.length == 2); |
| 571 ConstantValue indexConstant = constant.fields.values.first; |
| 572 if (indexConstant is IntConstantValue) { |
| 573 return indexConstant.primitiveValue; |
| 574 } |
| 575 } |
| 576 } |
| 577 return null; |
| 578 } |
538 } | 579 } |
539 | 580 |
540 /// Visitor that converts string literals and concatenations of string literals | 581 /// Visitor that converts string literals and concatenations of string literals |
541 /// into the string value. | 582 /// into the string value. |
542 class Stringifier extends ir.ExpressionVisitor<String> { | 583 class Stringifier extends ir.ExpressionVisitor<String> { |
543 @override | 584 @override |
544 String visitStringLiteral(ir.StringLiteral node) => node.value; | 585 String visitStringLiteral(ir.StringLiteral node) => node.value; |
545 | 586 |
546 @override | 587 @override |
547 String visitStringConcatenation(ir.StringConcatenation node) { | 588 String visitStringConcatenation(ir.StringConcatenation node) { |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 | 1078 |
1038 /// Returns the [JumpTarget] for the branch in [node]. | 1079 /// Returns the [JumpTarget] for the branch in [node]. |
1039 // TODO(johnniwinther): Split this by kind of [node]? | 1080 // TODO(johnniwinther): Split this by kind of [node]? |
1040 JumpTarget getJumpTarget(ir.TreeNode node, {bool isContinueTarget: false}); | 1081 JumpTarget getJumpTarget(ir.TreeNode node, {bool isContinueTarget: false}); |
1041 | 1082 |
1042 /// Returns the [LoopClosureRepresentationInfo] for the loop [node] in | 1083 /// Returns the [LoopClosureRepresentationInfo] for the loop [node] in |
1043 /// [closureClassMaps]. | 1084 /// [closureClassMaps]. |
1044 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( | 1085 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( |
1045 ClosureDataLookup closureLookup, ir.TreeNode node); | 1086 ClosureDataLookup closureLookup, ir.TreeNode node); |
1046 } | 1087 } |
OLD | NEW |