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