| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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 extends CompilerTask | 57 abstract class SsaAstBuilderBase extends CompilerTask | 
| 58     with SsaBuilderFieldMixin |  | 
| 59     implements SsaBuilderTask { | 58     implements SsaBuilderTask { | 
| 60   final JavaScriptBackend backend; | 59   final JavaScriptBackend backend; | 
| 61 | 60 | 
| 62   SsaAstBuilderBase(this.backend) : super(backend.compiler.measurer); | 61   SsaAstBuilderBase(this.backend) : super(backend.compiler.measurer); | 
| 63 | 62 | 
| 64   ConstantValue getFieldInitialConstantValue(FieldElement field) { | 63   /// Handle field initializer of `work.element`. Returns `true` if no code | 
| 65     ConstantExpression constant = field.constant; | 64   /// is needed for the field. | 
| 66     if (constant != null) { | 65   /// | 
| 67       ConstantValue initialValue = backend.constants.getConstantValue(constant); | 66   /// If `work.element` is a field with a constant initializer, the value is | 
| 68       if (initialValue == null) { | 67   /// registered with the world impact. Otherwise the cyclic-throw helper is | 
| 69         assert( | 68   /// registered for the lazy value computation. | 
| 70             field.isInstanceMember || | 69   /// | 
| 71                 constant.isImplicit || | 70   /// If the field is constant, no code is needed for the field and the method | 
| 72                 constant.isPotential, | 71   /// return `true`. | 
| 73             failedAt( | 72   bool handleConstantField( | 
| 74                 field, | 73       ElementCodegenWorkItem work, ClosedWorld closedWorld) { | 
| 75                 "Constant expression without value: " | 74     MemberElement element = work.element; | 
| 76                 "${constant.toStructuredText()}.")); | 75     if (element.isField) { | 
|  | 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)); | 
| 77       } | 109       } | 
| 78       return initialValue; |  | 
| 79     } | 110     } | 
| 80     return null; | 111     return false; | 
| 81   } | 112   } | 
| 82 } | 113 } | 
| 83 | 114 | 
| 84 class SsaAstBuilderTask extends SsaAstBuilderBase { | 115 class SsaAstBuilderTask extends SsaAstBuilderBase { | 
| 85   final CodeEmitterTask emitter; | 116   final CodeEmitterTask emitter; | 
| 86   final SourceInformationStrategy sourceInformationFactory; | 117   final SourceInformationStrategy sourceInformationFactory; | 
| 87 | 118 | 
| 88   String get name => 'SSA builder'; | 119   String get name => 'SSA builder'; | 
| 89 | 120 | 
| 90   SsaAstBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) | 121   SsaAstBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) | 
| 91       : emitter = backend.emitter, | 122       : emitter = backend.emitter, | 
| 92         super(backend); | 123         super(backend); | 
| 93 | 124 | 
| 94   DiagnosticReporter get reporter => backend.reporter; | 125   DiagnosticReporter get reporter => backend.reporter; | 
| 95 | 126 | 
| 96   HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { | 127   HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { | 
| 97     return measure(() { | 128     return measure(() { | 
| 98       if (handleConstantField(work.element, work.registry, closedWorld)) { | 129       if (handleConstantField(work, closedWorld)) { | 
| 99         // No code is generated for `work.element`. | 130         // No code is generated for `work.element`. | 
| 100         return null; | 131         return null; | 
| 101       } | 132       } | 
| 102       MemberElement element = work.element.implementation; | 133       MemberElement element = work.element.implementation; | 
| 103       return reporter.withCurrentElement(element, () { | 134       return reporter.withCurrentElement(element, () { | 
| 104         SsaBuilder builder = new SsaBuilder( | 135         SsaBuilder builder = new SsaBuilder( | 
| 105             work.element.implementation, | 136             work.element.implementation, | 
| 106             work.resolvedAst, | 137             work.resolvedAst, | 
| 107             work.registry, | 138             work.registry, | 
| 108             backend, | 139             backend, | 
| (...skipping 6735 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 6844       this.oldReturnLocal, | 6875       this.oldReturnLocal, | 
| 6845       this.oldReturnType, | 6876       this.oldReturnType, | 
| 6846       this.oldResolvedAst, | 6877       this.oldResolvedAst, | 
| 6847       this.oldStack, | 6878       this.oldStack, | 
| 6848       this.oldLocalsHandler, | 6879       this.oldLocalsHandler, | 
| 6849       this.inTryStatement, | 6880       this.inTryStatement, | 
| 6850       this.allFunctionsCalledOnce, | 6881       this.allFunctionsCalledOnce, | 
| 6851       this.oldElementInferenceResults) | 6882       this.oldElementInferenceResults) | 
| 6852       : super(function); | 6883       : super(function); | 
| 6853 } | 6884 } | 
| OLD | NEW | 
|---|