Index: pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart |
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart |
index 056345b554da1136dfa5c49c9569878e5db0d346..b3be363b6691f8abd69cb8a0f748c8b93d5bb75c 100644 |
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart |
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart |
@@ -6,64 +6,50 @@ library dart2js.js_emitter.startup_emitter.model_emitter; |
import 'dart:convert' show JsonEncoder; |
-import 'package:js_runtime/shared/embedded_names.dart' show |
- CLASS_FIELDS_EXTRACTOR, |
- CLASS_ID_EXTRACTOR, |
- CREATE_NEW_ISOLATE, |
- DEFERRED_INITIALIZED, |
- DEFERRED_LIBRARY_URIS, |
- DEFERRED_LIBRARY_HASHES, |
- GET_TYPE_FROM_NAME, |
- INITIALIZE_EMPTY_INSTANCE, |
- INITIALIZE_LOADED_HUNK, |
- INSTANCE_FROM_CLASS_ID, |
- INTERCEPTORS_BY_TAG, |
- IS_HUNK_INITIALIZED, |
- IS_HUNK_LOADED, |
- LEAF_TAGS, |
- MANGLED_GLOBAL_NAMES, |
- MANGLED_NAMES, |
- METADATA, |
- NATIVE_SUPERCLASS_TAG_NAME, |
- STATIC_FUNCTION_NAME_TO_CLOSURE, |
- TYPE_TO_INTERCEPTOR_MAP, |
- TYPES; |
+import 'package:js_runtime/shared/embedded_names.dart' |
+ show |
+ CLASS_FIELDS_EXTRACTOR, |
+ CLASS_ID_EXTRACTOR, |
+ CREATE_NEW_ISOLATE, |
+ DEFERRED_INITIALIZED, |
+ DEFERRED_LIBRARY_URIS, |
+ DEFERRED_LIBRARY_HASHES, |
+ GET_TYPE_FROM_NAME, |
+ INITIALIZE_EMPTY_INSTANCE, |
+ INITIALIZE_LOADED_HUNK, |
+ INSTANCE_FROM_CLASS_ID, |
+ INTERCEPTORS_BY_TAG, |
+ IS_HUNK_INITIALIZED, |
+ IS_HUNK_LOADED, |
+ LEAF_TAGS, |
+ MANGLED_GLOBAL_NAMES, |
+ MANGLED_NAMES, |
+ METADATA, |
+ NATIVE_SUPERCLASS_TAG_NAME, |
+ STATIC_FUNCTION_NAME_TO_CLOSURE, |
+ TYPE_TO_INTERCEPTOR_MAP, |
+ TYPES; |
import '../../common.dart'; |
-import '../../constants/values.dart' show |
- ConstantValue, |
- FunctionConstantValue; |
-import '../../compiler.dart' show |
- Compiler; |
-import '../../core_types.dart' show |
- CoreClasses; |
-import '../../elements/elements.dart' show |
- ClassElement, |
- FunctionElement; |
-import '../../hash/sha1.dart' show |
- Hasher; |
+import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; |
+import '../../compiler.dart' show Compiler; |
+import '../../core_types.dart' show CoreClasses; |
+import '../../elements/elements.dart' show ClassElement, FunctionElement; |
+import '../../hash/sha1.dart' show Hasher; |
import '../../io/code_output.dart'; |
-import '../../io/line_column_provider.dart' show |
- LineColumnCollector, |
- LineColumnProvider; |
-import '../../io/source_map_builder.dart' show |
- SourceMapBuilder; |
+import '../../io/line_column_provider.dart' |
+ show LineColumnCollector, LineColumnProvider; |
+import '../../io/source_map_builder.dart' show SourceMapBuilder; |
import '../../js/js.dart' as js; |
-import '../../js_backend/js_backend.dart' show |
- JavaScriptBackend, |
- Namer, |
- ConstantEmitter; |
-import '../../util/uri_extras.dart' show |
- relativize; |
+import '../../js_backend/js_backend.dart' |
+ show JavaScriptBackend, Namer, ConstantEmitter; |
+import '../../util/uri_extras.dart' show relativize; |
import '../constant_ordering.dart' show deepCompareConstants; |
import '../headers.dart'; |
-import '../js_emitter.dart' show |
- NativeEmitter; |
+import '../js_emitter.dart' show NativeEmitter; |
-import '../js_emitter.dart' show |
- buildTearOffCode, |
- NativeGenerator; |
+import '../js_emitter.dart' show buildTearOffCode, NativeGenerator; |
import '../model.dart'; |
part 'deferred_fragment_hash.dart'; |
@@ -79,7 +65,6 @@ class ModelEmitter { |
// The full code that is written to each hunk part-file. |
final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{}; |
- |
JavaScriptBackend get backend => compiler.backend; |
/// For deferred loading we communicate the initializers via this global var. |
@@ -92,12 +77,11 @@ class ModelEmitter { |
static const String typeNameProperty = r"builtin$cls"; |
ModelEmitter(Compiler compiler, Namer namer, this.nativeEmitter, |
- this.shouldGenerateSourceMap) |
+ this.shouldGenerateSourceMap) |
: this.compiler = compiler, |
this.namer = namer { |
this.constantEmitter = new ConstantEmitter( |
- compiler, namer, this.generateConstantReference, |
- constantListGenerator); |
+ compiler, namer, this.generateConstantReference, constantListGenerator); |
} |
DiagnosticReporter get reporter => compiler.reporter; |
@@ -117,9 +101,9 @@ class ModelEmitter { |
} |
bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) { |
- if (constant.isFunction) return true; // Already emitted. |
- if (constant.isPrimitive) return true; // Inlined. |
- if (constant.isDummy) return true; // Inlined. |
+ if (constant.isFunction) return true; // Already emitted. |
+ if (constant.isPrimitive) return true; // Inlined. |
+ if (constant.isDummy) return true; // Inlined. |
return false; |
} |
@@ -162,8 +146,8 @@ class ModelEmitter { |
if (isConstantInlinedOrAlreadyEmitted(value)) { |
return constantEmitter.generate(value); |
} |
- return js.js('#.#', [namer.globalObjectForConstant(value), |
- namer.constantName(value)]); |
+ return js.js('#.#', |
+ [namer.globalObjectForConstant(value), namer.constantName(value)]); |
} |
int emitProgram(Program program) { |
@@ -175,7 +159,7 @@ class ModelEmitter { |
new FragmentEmitter(compiler, namer, backend, constantEmitter, this); |
Map<DeferredFragment, _DeferredFragmentHash> deferredHashTokens = |
- new Map<DeferredFragment, _DeferredFragmentHash>(); |
+ new Map<DeferredFragment, _DeferredFragmentHash>(); |
for (DeferredFragment fragment in deferredFragments) { |
deferredHashTokens[fragment] = new _DeferredFragmentHash(fragment); |
} |
@@ -190,7 +174,7 @@ class ModelEmitter { |
js.Expression types = |
program.metadataTypesForOutputUnit(fragment.outputUnit); |
deferredFragmentsCode[fragment] = fragmentEmitter.emitDeferredFragment( |
- fragment, types, program.holders); |
+ fragment, types, program.holders); |
} |
js.TokenCounter counter = new js.TokenCounter(); |
@@ -204,18 +188,16 @@ class ModelEmitter { |
// Now that we have written the deferred hunks, we can update the hash |
// tokens in the main-fragment. |
- deferredHashTokens.forEach((DeferredFragment key, |
- _DeferredFragmentHash token) { |
+ deferredHashTokens |
+ .forEach((DeferredFragment key, _DeferredFragmentHash token) { |
token.setHash(hunkHashes[key]); |
}); |
writeMainFragment(mainFragment, mainCode, |
- isSplit: program.deferredFragments.isNotEmpty); |
+ isSplit: program.deferredFragments.isNotEmpty); |
- if (backend.requiresPreamble && |
- !backend.htmlLibraryIsLoaded) { |
- reporter.reportHintMessage( |
- NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); |
+ if (backend.requiresPreamble && !backend.htmlLibraryIsLoaded) { |
+ reporter.reportHintMessage(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); |
} |
if (compiler.options.deferredMapUri != null) { |
@@ -252,7 +234,8 @@ class ModelEmitter { |
} |
js.Statement buildDeferredInitializerGlobal() { |
- return js.js.statement('self.#deferredInitializers = ' |
+ return js.js.statement( |
+ 'self.#deferredInitializers = ' |
'self.#deferredInitializers || Object.create(null);', |
{'deferredInitializers': deferredInitializersGlobal}); |
} |
@@ -270,18 +253,18 @@ class ModelEmitter { |
} |
CodeOutput mainOutput = new StreamCodeOutput( |
- compiler.outputProvider('', 'js'), |
- codeOutputListeners); |
+ compiler.outputProvider('', 'js'), codeOutputListeners); |
outputBuffers[fragment] = mainOutput; |
js.Program program = new js.Program([ |
- buildGeneratedBy(), |
- new js.Comment(HOOKS_API_USAGE), |
- isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), |
- code]); |
+ buildGeneratedBy(), |
+ new js.Comment(HOOKS_API_USAGE), |
+ isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), |
+ code |
+ ]); |
- mainOutput.addBuffer(js.createCodeBuffer(program, compiler, |
- monitor: compiler.dumpInfoTask)); |
+ mainOutput.addBuffer( |
+ js.createCodeBuffer(program, compiler, monitor: compiler.dumpInfoTask)); |
if (shouldGenerateSourceMap) { |
mainOutput.add(generateSourceMapTag( |
@@ -330,12 +313,13 @@ class ModelEmitter { |
// deferredInitializer[<hash>] = deferredInitializer.current; |
js.Program program = new js.Program([ |
- buildGeneratedBy(), |
- buildDeferredInitializerGlobal(), |
- js.js.statement('$deferredInitializersGlobal.current = #', code)]); |
+ buildGeneratedBy(), |
+ buildDeferredInitializerGlobal(), |
+ js.js.statement('$deferredInitializersGlobal.current = #', code) |
+ ]); |
- output.addBuffer(js.createCodeBuffer(program, compiler, |
- monitor: compiler.dumpInfoTask)); |
+ output.addBuffer( |
+ js.createCodeBuffer(program, compiler, monitor: compiler.dumpInfoTask)); |
// Make a unique hash of the code (before the sourcemaps are added) |
// This will be used to retrieve the initializing function from the global |
@@ -357,15 +341,15 @@ class ModelEmitter { |
String mapFileName = hunkFileName + ".map"; |
List<String> mapSegments = sourceMapUri.pathSegments.toList(); |
mapSegments[mapSegments.length - 1] = mapFileName; |
- mapUri = compiler.options.sourceMapUri |
- .replace(pathSegments: mapSegments); |
+ mapUri = |
+ compiler.options.sourceMapUri.replace(pathSegments: mapSegments); |
} |
if (outputUri != null) { |
List<String> partSegments = outputUri.pathSegments.toList(); |
partSegments[partSegments.length - 1] = hunkFileName; |
- partUri = compiler.options.outputUri |
- .replace(pathSegments: partSegments); |
+ partUri = |
+ compiler.options.outputUri.replace(pathSegments: partSegments); |
} |
output.add(generateSourceMapTag(mapUri, partUri)); |
@@ -389,17 +373,14 @@ class ModelEmitter { |
return ''; |
} |
- |
- void outputSourceMap(CodeOutput output, |
- LineColumnProvider lineColumnProvider, |
- String name, |
- [Uri sourceMapUri, |
- Uri fileUri]) { |
+ void outputSourceMap( |
+ CodeOutput output, LineColumnProvider lineColumnProvider, String name, |
+ [Uri sourceMapUri, Uri fileUri]) { |
if (!shouldGenerateSourceMap) return; |
// Create a source file for the compilation output. This allows using |
// [:getLine:] to transform offsets to line numbers in [SourceMapBuilder]. |
SourceMapBuilder sourceMapBuilder = |
- new SourceMapBuilder(sourceMapUri, fileUri, lineColumnProvider); |
+ new SourceMapBuilder(sourceMapUri, fileUri, lineColumnProvider); |
output.forEachSourceLocation(sourceMapBuilder.addMapping); |
String sourceMap = sourceMapBuilder.build(); |
compiler.outputProvider(name, 'js.map') |
@@ -419,7 +400,7 @@ class ModelEmitter { |
"needed for a given deferred library import."; |
mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
compiler.outputProvider( |
- compiler.options.deferredMapUri.path, 'deferred_map') |
+ compiler.options.deferredMapUri.path, 'deferred_map') |
..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
..close(); |
} |