OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 js_backend.backend; | 5 library js_backend.backend; |
6 | 6 |
7 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 7 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/backend_api.dart' | 10 import '../common/backend_api.dart' |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 String get patchVersion => emitter.patchVersion; | 309 String get patchVersion => emitter.patchVersion; |
310 | 310 |
311 /// Returns true if the backend supports reflection. | 311 /// Returns true if the backend supports reflection. |
312 bool get supportsReflection => emitter.supportsReflection; | 312 bool get supportsReflection => emitter.supportsReflection; |
313 | 313 |
314 final Annotations annotations; | 314 final Annotations annotations; |
315 | 315 |
316 /// Set of classes that need to be considered for reflection although not | 316 /// Set of classes that need to be considered for reflection although not |
317 /// otherwise visible during resolution. | 317 /// otherwise visible during resolution. |
318 Iterable<ClassElement> get classesRequiredForReflection { | 318 Iterable<ClassEntity> get classesRequiredForReflection { |
319 // TODO(herhut): Clean this up when classes needed for rti are tracked. | 319 // TODO(herhut): Clean this up when classes needed for rti are tracked. |
320 return [helpers.closureClass, helpers.jsIndexableClass]; | 320 return [helpers.closureClass, helpers.jsIndexableClass]; |
321 } | 321 } |
322 | 322 |
323 FunctionCompiler functionCompiler; | 323 FunctionCompiler functionCompiler; |
324 | 324 |
325 CodeEmitterTask emitter; | 325 CodeEmitterTask emitter; |
326 | 326 |
327 /** | 327 /** |
328 * The generated code as a js AST for compiled methods. | 328 * The generated code as a js AST for compiled methods. |
329 */ | 329 */ |
330 final Map<Element, jsAst.Expression> generatedCode = | 330 final Map<MemberElement, jsAst.Expression> generatedCode = |
331 <Element, jsAst.Expression>{}; | 331 <MemberElement, jsAst.Expression>{}; |
332 | 332 |
333 FunctionInlineCache inlineCache = new FunctionInlineCache(); | 333 FunctionInlineCache inlineCache = new FunctionInlineCache(); |
334 | 334 |
335 /// If [true], the compiler will emit code that logs whenever a method is | 335 /// If [true], the compiler will emit code that logs whenever a method is |
336 /// called. When TRACE_METHOD is 'console' this will be logged | 336 /// called. When TRACE_METHOD is 'console' this will be logged |
337 /// directly in the JavaScript console. When TRACE_METHOD is 'post' the | 337 /// directly in the JavaScript console. When TRACE_METHOD is 'post' the |
338 /// information will be sent to a server via a POST request. | 338 /// information will be sent to a server via a POST request. |
339 static const String TRACE_METHOD = const String.fromEnvironment('traceCalls'); | 339 static const String TRACE_METHOD = const String.fromEnvironment('traceCalls'); |
340 static const bool TRACE_CALLS = | 340 static const bool TRACE_CALLS = |
341 TRACE_METHOD == 'post' || TRACE_METHOD == 'console'; | 341 TRACE_METHOD == 'post' || TRACE_METHOD == 'console'; |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 backendUsage, | 953 backendUsage, |
954 rtiNeed, | 954 rtiNeed, |
955 customElementsCodegenAnalysis, | 955 customElementsCodegenAnalysis, |
956 typeVariableCodegenAnalysis, | 956 typeVariableCodegenAnalysis, |
957 lookupMapAnalysis, | 957 lookupMapAnalysis, |
958 mirrorsCodegenAnalysis, | 958 mirrorsCodegenAnalysis, |
959 nativeCodegenEnqueuer)); | 959 nativeCodegenEnqueuer)); |
960 } | 960 } |
961 | 961 |
962 WorldImpact codegen(CodegenWorkItem work) { | 962 WorldImpact codegen(CodegenWorkItem work) { |
963 Element element = work.element; | 963 MemberElement element = work.element; |
964 if (compiler.elementHasCompileTimeError(element)) { | 964 if (compiler.elementHasCompileTimeError(element)) { |
965 DiagnosticMessage message = | 965 DiagnosticMessage message = |
966 // If there's more than one error, the first is probably most | 966 // If there's more than one error, the first is probably most |
967 // informative, as the following errors may be side-effects of the | 967 // informative, as the following errors may be side-effects of the |
968 // first error. | 968 // first error. |
969 compiler.elementsWithCompileTimeErrors[element].first; | 969 compiler.elementsWithCompileTimeErrors[element].first; |
970 String messageText = message.message.computeMessage(); | 970 String messageText = message.message.computeMessage(); |
971 jsAst.LiteralString messageLiteral = | 971 jsAst.LiteralString messageLiteral = |
972 js.escapedString("Compile time error in $element: $messageText"); | 972 js.escapedString("Compile time error in $element: $messageText"); |
973 generatedCode[element] = | 973 generatedCode[element] = |
974 js("function () { throw new Error(#); }", [messageLiteral]); | 974 js("function () { throw new Error(#); }", [messageLiteral]); |
975 return const CodegenImpact(); | 975 return const CodegenImpact(); |
976 } | 976 } |
977 var kind = element.kind; | 977 var kind = element.kind; |
978 if (kind == ElementKind.TYPEDEF) { | 978 if (kind == ElementKind.TYPEDEF) { |
979 return const WorldImpact(); | 979 return const WorldImpact(); |
980 } | 980 } |
981 if (element.isConstructor && | 981 if (element.isConstructor && |
982 element.enclosingClass == helpers.jsNullClass) { | 982 element.enclosingClass == helpers.jsNullClass) { |
983 // Work around a problem compiling JSNull's constructor. | 983 // Work around a problem compiling JSNull's constructor. |
984 return const CodegenImpact(); | 984 return const CodegenImpact(); |
985 } | 985 } |
986 if (kind.category == ElementCategory.VARIABLE) { | 986 if (kind.category == ElementCategory.VARIABLE) { |
987 // ignore: INVALID_ASSIGNMENT | 987 FieldElement variableElement = element; |
988 VariableElement variableElement = element; | |
989 ConstantExpression constant = variableElement.constant; | 988 ConstantExpression constant = variableElement.constant; |
990 if (constant != null) { | 989 if (constant != null) { |
991 ConstantValue initialValue = constants.getConstantValue(constant); | 990 ConstantValue initialValue = constants.getConstantValue(constant); |
992 if (initialValue != null) { | 991 if (initialValue != null) { |
993 work.registry.worldImpact | 992 work.registry.worldImpact |
994 .registerConstantUse(new ConstantUse.init(initialValue)); | 993 .registerConstantUse(new ConstantUse.init(initialValue)); |
995 // We don't need to generate code for static or top-level | 994 // We don't need to generate code for static or top-level |
996 // variables. For instance variables, we may need to generate | 995 // variables. For instance variables, we may need to generate |
997 // the checked setter. | 996 // the checked setter. |
998 if (Elements.isStaticOrTopLevel(element)) { | 997 if (Elements.isStaticOrTopLevel(element)) { |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 | 1606 |
1608 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { | 1607 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { |
1609 return !selector.isGetter; | 1608 return !selector.isGetter; |
1610 } | 1609 } |
1611 | 1610 |
1612 /// Returns `true` if [member] is called from a subclass via `super`. | 1611 /// Returns `true` if [member] is called from a subclass via `super`. |
1613 bool isAliasedSuperMember(MemberEntity member) { | 1612 bool isAliasedSuperMember(MemberEntity member) { |
1614 return _aliasedSuperMembers.contains(member); | 1613 return _aliasedSuperMembers.contains(member); |
1615 } | 1614 } |
1616 } | 1615 } |
OLD | NEW |