| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 ir.StaticInvocation node); | 143 ir.StaticInvocation node); |
| 140 | 144 |
| 141 /// Computes the [native.NativeBehavior] for a call to the | 145 /// Computes the [native.NativeBehavior] for a call to the |
| 142 /// [JS_EMBEDDED_GLOBAL] function. | 146 /// [JS_EMBEDDED_GLOBAL] function. |
| 143 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall( | 147 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall( |
| 144 ir.StaticInvocation node); | 148 ir.StaticInvocation node); |
| 145 | 149 |
| 146 /// Compute the kind of foreign helper function called by [node], if any. | 150 /// Compute the kind of foreign helper function called by [node], if any. |
| 147 ForeignKind getForeignKind(ir.StaticInvocation node); | 151 ForeignKind getForeignKind(ir.StaticInvocation node); |
| 148 | 152 |
| 153 /// Returns the [js.Name] for the `JsGetName` [constant] value. |
| 154 js.Name getNameForJsGetName(ConstantValue constant, Namer namer); |
| 155 |
| 156 /// Returns the [js.Template] for the `JsBuiltin` [constant] value. |
| 157 js.Template getJsBuiltinTemplate( |
| 158 ConstantValue constant, CodeEmitterTask emitter); |
| 159 |
| 149 /// Computes the [InterfaceType] referenced by a call to the | 160 /// Computes the [InterfaceType] referenced by a call to the |
| 150 /// [JS_INTERCEPTOR_CONSTANT] function, if any. | 161 /// [JS_INTERCEPTOR_CONSTANT] function, if any. |
| 151 InterfaceType getInterfaceTypeForJsInterceptorCall(ir.StaticInvocation node); | 162 InterfaceType getInterfaceTypeForJsInterceptorCall(ir.StaticInvocation node); |
| 152 | 163 |
| 153 /// Computes the [ConstantValue] for the constant [expression]. | 164 /// Computes the [ConstantValue] for the constant [expression]. |
| 154 ConstantValue getConstantValue(ir.Expression expression, | 165 ConstantValue getConstantValue(ir.Expression expression, |
| 155 {bool requireConstant: true, bool implicitNull: false}); | 166 {bool requireConstant: true, bool implicitNull: false}); |
| 156 | 167 |
| 157 /// Return the [ConstantValue] the initial value of [field] or `null` if | 168 /// Return the [ConstantValue] the initial value of [field] or `null` if |
| 158 /// the initializer is not a constant expression. | 169 /// the initializer is not a constant expression. |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 // `Object.superNoSuchMethod`. | 538 // `Object.superNoSuchMethod`. |
| 528 break; | 539 break; |
| 529 } | 540 } |
| 530 } | 541 } |
| 531 FunctionEntity function = elementEnvironment.lookupClassMember( | 542 FunctionEntity function = elementEnvironment.lookupClassMember( |
| 532 commonElements.objectClass, Identifiers.noSuchMethod_); | 543 commonElements.objectClass, Identifiers.noSuchMethod_); |
| 533 assert(function != null, | 544 assert(function != null, |
| 534 failedAt(cls, "No super noSuchMethod found for class $cls.")); | 545 failedAt(cls, "No super noSuchMethod found for class $cls.")); |
| 535 return function; | 546 return function; |
| 536 } | 547 } |
| 548 |
| 549 js.Name getNameForJsGetName(ConstantValue constant, Namer namer) { |
| 550 int index = _extractEnumIndexFromConstantValue( |
| 551 constant, commonElements.jsGetNameEnum); |
| 552 if (index == null) return null; |
| 553 return namer.getNameForJsGetName( |
| 554 CURRENT_ELEMENT_SPANNABLE, JsGetName.values[index]); |
| 555 } |
| 556 |
| 557 js.Template getJsBuiltinTemplate( |
| 558 ConstantValue constant, CodeEmitterTask emitter) { |
| 559 int index = _extractEnumIndexFromConstantValue( |
| 560 constant, commonElements.jsBuiltinEnum); |
| 561 if (index == null) return null; |
| 562 return emitter.builtinTemplateFor(JsBuiltin.values[index]); |
| 563 } |
| 564 |
| 565 int _extractEnumIndexFromConstantValue( |
| 566 ConstantValue constant, ClassEntity classElement) { |
| 567 if (constant is ConstructedConstantValue) { |
| 568 if (constant.type.element == classElement) { |
| 569 assert(constant.fields.length == 1 || constant.fields.length == 2); |
| 570 ConstantValue indexConstant = constant.fields.values.first; |
| 571 if (indexConstant is IntConstantValue) { |
| 572 return indexConstant.primitiveValue; |
| 573 } |
| 574 } |
| 575 } |
| 576 return null; |
| 577 } |
| 537 } | 578 } |
| 538 | 579 |
| 539 /// Visitor that converts string literals and concatenations of string literals | 580 /// Visitor that converts string literals and concatenations of string literals |
| 540 /// into the string value. | 581 /// into the string value. |
| 541 class Stringifier extends ir.ExpressionVisitor<String> { | 582 class Stringifier extends ir.ExpressionVisitor<String> { |
| 542 @override | 583 @override |
| 543 String visitStringLiteral(ir.StringLiteral node) => node.value; | 584 String visitStringLiteral(ir.StringLiteral node) => node.value; |
| 544 | 585 |
| 545 @override | 586 @override |
| 546 String visitStringConcatenation(ir.StringConcatenation node) { | 587 String visitStringConcatenation(ir.StringConcatenation node) { |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 /// [closureClassMaps]. | 1083 /// [closureClassMaps]. |
| 1043 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( | 1084 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( |
| 1044 ClosureDataLookup closureLookup, ir.TreeNode node); | 1085 ClosureDataLookup closureLookup, ir.TreeNode node); |
| 1045 } | 1086 } |
| 1046 | 1087 |
| 1047 /// Comparator for the canonical order or named arguments. | 1088 /// Comparator for the canonical order or named arguments. |
| 1048 // TODO(johnniwinther): Remove this when named parameters are sorted in dill. | 1089 // TODO(johnniwinther): Remove this when named parameters are sorted in dill. |
| 1049 int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) { | 1090 int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) { |
| 1050 return a.name.compareTo(b.name); | 1091 return a.name.compareTo(b.name); |
| 1051 } | 1092 } |
| OLD | NEW |