blob: 2b659550ad5a9ec5919bbe6341db01544ac82ecc [file] [log] [blame]
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import '../compile_time_constants.dart';
import '../compiler.dart' show Compiler;
import '../elements/entities.dart';
/// [ConstantCompilerTask] for compilation of constants for the JavaScript
/// backend.
///
/// Since this task needs to distinguish between frontend and backend constants
/// the actual compilation of the constants is forwarded to a
/// [DartConstantCompiler] for the frontend interpretation of the constants and
/// to a [JavaScriptConstantCompiler] for the backend interpretation.
class JavaScriptConstantTask extends ConstantCompilerTask {
JavaScriptConstantCompiler jsConstantCompiler;
JavaScriptConstantTask(Compiler compiler)
: this.jsConstantCompiler = new JavaScriptConstantCompiler(),
super(compiler.measurer);
@override
String get name => 'ConstantHandler';
}
/// The [JavaScriptConstantCompiler] is used to keep track of compile-time
/// constants, initializations of global and static fields, and default values
/// of optional parameters for the JavaScript interpretation of constants.
class JavaScriptConstantCompiler implements BackendConstantEnvironment {
// TODO(johnniwinther): Move this to the backend constant handler.
/// Caches the statics where the initial value cannot be eagerly compiled.
final Set<FieldEntity> lazyStatics = new Set<FieldEntity>();
JavaScriptConstantCompiler();
@override
void registerLazyStatic(FieldEntity element) {
lazyStatics.add(element);
}
List<FieldEntity> getLazilyInitializedFieldsForEmission() {
return new List<FieldEntity>.from(lazyStatics);
}
}