| 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
| 8 | 8 |
| 9 import '../closure.dart'; | 9 import '../closure.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 import 'jump_handler.dart'; | 47 import 'jump_handler.dart'; |
| 48 import 'locals_handler.dart'; | 48 import 'locals_handler.dart'; |
| 49 import 'loop_handler.dart'; | 49 import 'loop_handler.dart'; |
| 50 import 'nodes.dart'; | 50 import 'nodes.dart'; |
| 51 import 'optimize.dart'; | 51 import 'optimize.dart'; |
| 52 import 'ssa.dart'; | 52 import 'ssa.dart'; |
| 53 import 'ssa_branch_builder.dart'; | 53 import 'ssa_branch_builder.dart'; |
| 54 import 'type_builder.dart'; | 54 import 'type_builder.dart'; |
| 55 import 'types.dart'; | 55 import 'types.dart'; |
| 56 | 56 |
| 57 abstract class SsaAstBuilderBase implements SsaBuilder { | 57 abstract class SsaAstBuilderBase extends SsaBuilderFieldMixin |
| 58 implements SsaBuilder { |
| 58 final CompilerTask task; | 59 final CompilerTask task; |
| 59 final JavaScriptBackend backend; | 60 final JavaScriptBackend backend; |
| 60 | 61 |
| 61 SsaAstBuilderBase(this.task, this.backend); | 62 SsaAstBuilderBase(this.task, this.backend); |
| 62 | 63 |
| 63 /// Handle field initializer of `work.element`. Returns `true` if no code | 64 ConstantValue getFieldInitialConstantValue(FieldElement field) { |
| 64 /// is needed for the field. | 65 ConstantExpression constant = field.constant; |
| 65 /// | 66 if (constant != null) { |
| 66 /// If `work.element` is a field with a constant initializer, the value is | 67 ConstantValue initialValue = backend.constants.getConstantValue(constant); |
| 67 /// registered with the world impact. Otherwise the cyclic-throw helper is | 68 if (initialValue == null) { |
| 68 /// registered for the lazy value computation. | 69 assert( |
| 69 /// | 70 field.isInstanceMember || |
| 70 /// If the field is constant, no code is needed for the field and the method | 71 constant.isImplicit || |
| 71 /// return `true`. | 72 constant.isPotential, |
| 72 bool handleConstantField( | 73 failedAt( |
| 73 ElementCodegenWorkItem work, ClosedWorld closedWorld) { | 74 field, |
| 74 MemberElement element = work.element; | 75 "Constant expression without value: " |
| 75 if (element.isField) { | 76 "${constant.toStructuredText()}.")); |
| 76 FieldElement field = element; | |
| 77 ConstantExpression constant = field.constant; | |
| 78 if (constant != null) { | |
| 79 ConstantValue initialValue = | |
| 80 backend.constants.getConstantValue(constant); | |
| 81 if (initialValue != null) { | |
| 82 work.registry.worldImpact | |
| 83 .registerConstantUse(new ConstantUse.init(initialValue)); | |
| 84 // We don't need to generate code for static or top-level | |
| 85 // variables. For instance variables, we may need to generate | |
| 86 // the checked setter. | |
| 87 if (field.isStatic || field.isTopLevel) { | |
| 88 /// No code is created for this field. | |
| 89 return true; | |
| 90 } | |
| 91 } else { | |
| 92 assert( | |
| 93 field.isInstanceMember || | |
| 94 constant.isImplicit || | |
| 95 constant.isPotential, | |
| 96 failedAt( | |
| 97 field, | |
| 98 "Constant expression without value: " | |
| 99 "${constant.toStructuredText()}.")); | |
| 100 } | |
| 101 } else { | |
| 102 // If the constant-handler was not able to produce a result we have to | |
| 103 // go through the builder (below) to generate the lazy initializer for | |
| 104 // the static variable. | |
| 105 // We also need to register the use of the cyclic-error helper. | |
| 106 work.registry.worldImpact.registerStaticUse(new StaticUse.staticInvoke( | |
| 107 closedWorld.commonElements.cyclicThrowHelper, | |
| 108 CallStructure.ONE_ARG)); | |
| 109 } | 77 } |
| 78 return initialValue; |
| 110 } | 79 } |
| 111 return false; | 80 return null; |
| 112 } | 81 } |
| 113 } | 82 } |
| 114 | 83 |
| 115 class SsaAstBuilder extends SsaAstBuilderBase { | 84 class SsaAstBuilder extends SsaAstBuilderBase { |
| 116 final CodeEmitterTask emitter; | 85 final CodeEmitterTask emitter; |
| 117 final SourceInformationStrategy sourceInformationFactory; | 86 final SourceInformationStrategy sourceInformationFactory; |
| 118 | 87 |
| 119 SsaAstBuilder(CompilerTask task, JavaScriptBackend backend, | 88 SsaAstBuilder(CompilerTask task, JavaScriptBackend backend, |
| 120 this.sourceInformationFactory) | 89 this.sourceInformationFactory) |
| 121 : emitter = backend.emitter, | 90 : emitter = backend.emitter, |
| 122 super(task, backend); | 91 super(task, backend); |
| 123 | 92 |
| 124 DiagnosticReporter get reporter => backend.reporter; | 93 DiagnosticReporter get reporter => backend.reporter; |
| 125 | 94 |
| 126 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { | 95 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { |
| 127 return task.measure(() { | 96 return task.measure(() { |
| 128 if (handleConstantField(work, closedWorld)) { | 97 if (handleConstantField(work.element, work.registry, closedWorld)) { |
| 129 // No code is generated for `work.element`. | 98 // No code is generated for `work.element`. |
| 130 return null; | 99 return null; |
| 131 } | 100 } |
| 132 MemberElement element = work.element.implementation; | 101 MemberElement element = work.element.implementation; |
| 133 return reporter.withCurrentElement(element, () { | 102 return reporter.withCurrentElement(element, () { |
| 134 SsaAstGraphBuilder builder = new SsaAstGraphBuilder( | 103 SsaAstGraphBuilder builder = new SsaAstGraphBuilder( |
| 135 work.element.implementation, | 104 work.element.implementation, |
| 136 work.resolvedAst, | 105 work.resolvedAst, |
| 137 work.registry, | 106 work.registry, |
| 138 backend, | 107 backend, |
| (...skipping 6735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6874 this.oldReturnLocal, | 6843 this.oldReturnLocal, |
| 6875 this.oldReturnType, | 6844 this.oldReturnType, |
| 6876 this.oldResolvedAst, | 6845 this.oldResolvedAst, |
| 6877 this.oldStack, | 6846 this.oldStack, |
| 6878 this.oldLocalsHandler, | 6847 this.oldLocalsHandler, |
| 6879 this.inTryStatement, | 6848 this.inTryStatement, |
| 6880 this.allFunctionsCalledOnce, | 6849 this.allFunctionsCalledOnce, |
| 6881 this.oldElementInferenceResults) | 6850 this.oldElementInferenceResults) |
| 6882 : super(function); | 6851 : super(function); |
| 6883 } | 6852 } |
| OLD | NEW |