Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 16114013: Reland "Add --version option to dart2js and add version information (if available) to generated cod… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix formatting. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart2js.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 2930 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 } 2941 }
2942 2942
2943 String assembleProgram() { 2943 String assembleProgram() {
2944 measure(() { 2944 measure(() {
2945 // Compute the required type checks to know which classes need a 2945 // Compute the required type checks to know which classes need a
2946 // 'is$' method. 2946 // 'is$' method.
2947 computeRequiredTypeChecks(); 2947 computeRequiredTypeChecks();
2948 2948
2949 computeNeededClasses(); 2949 computeNeededClasses();
2950 2950
2951 mainBuffer.add(GENERATED_BY); 2951 mainBuffer.add(buildGeneratedBy());
2952 addComment(HOOKS_API_USAGE, mainBuffer); 2952 addComment(HOOKS_API_USAGE, mainBuffer);
2953 mainBuffer.add('function ${namer.isolateName}()$_{}\n'); 2953 mainBuffer.add('function ${namer.isolateName}()$_{}\n');
2954 mainBuffer.add('init()$N$n'); 2954 mainBuffer.add('init()$N$n');
2955 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary. 2955 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary.
2956 isolateProperties = namer.CURRENT_ISOLATE; 2956 isolateProperties = namer.CURRENT_ISOLATE;
2957 mainBuffer.add( 2957 mainBuffer.add(
2958 'var $isolateProperties$_=$_$isolatePropertiesName$N'); 2958 'var $isolateProperties$_=$_$isolatePropertiesName$N');
2959 2959
2960 if (!regularClasses.isEmpty || 2960 if (!regularClasses.isEmpty ||
2961 !deferredClasses.isEmpty || 2961 !deferredClasses.isEmpty ||
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 String code = buffer.getText(); 3166 String code = buffer.getText();
3167 compiler.outputProvider('part', 'js') 3167 compiler.outputProvider('part', 'js')
3168 ..add(code) 3168 ..add(code)
3169 ..close(); 3169 ..close();
3170 outputSourceMap(buffer, compiler.assembledCode, 'part'); 3170 outputSourceMap(buffer, compiler.assembledCode, 'part');
3171 } 3171 }
3172 3172
3173 void emitDeferredPreambleWhenEmpty(CodeBuffer buffer) { 3173 void emitDeferredPreambleWhenEmpty(CodeBuffer buffer) {
3174 if (!buffer.isEmpty) return; 3174 if (!buffer.isEmpty) return;
3175 3175
3176 buffer.write(GENERATED_BY); 3176 buffer.write(buildGeneratedBy());
3177 3177
3178 buffer.write('var old${namer.CURRENT_ISOLATE}$_=' 3178 buffer.write('var old${namer.CURRENT_ISOLATE}$_='
3179 '$_${namer.CURRENT_ISOLATE}$N'); 3179 '$_${namer.CURRENT_ISOLATE}$N');
3180 3180
3181 // TODO(ahe): This defines a lot of properties on the 3181 // TODO(ahe): This defines a lot of properties on the
3182 // Isolate.prototype object. We know this will turn it into a 3182 // Isolate.prototype object. We know this will turn it into a
3183 // slow object in V8, so instead we should do something similar to 3183 // slow object in V8, so instead we should do something similar to
3184 // Isolate.$finishIsolateConstructor. 3184 // Isolate.$finishIsolateConstructor.
3185 buffer.write('${namer.CURRENT_ISOLATE}$_=' 3185 buffer.write('${namer.CURRENT_ISOLATE}$_='
3186 '$_${namer.isolateName}.prototype$N$n'); 3186 '$_${namer.isolateName}.prototype$N$n');
3187 } 3187 }
3188 3188
3189 String buildGeneratedBy() {
3190 var suffix = '';
3191 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}';
3192 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n';
3193 }
3194
3189 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) { 3195 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) {
3190 SourceMapBuilder sourceMapBuilder = 3196 SourceMapBuilder sourceMapBuilder =
3191 new SourceMapBuilder(compiler.sourceMapUri); 3197 new SourceMapBuilder(compiler.sourceMapUri);
3192 buffer.forEachSourceLocation(sourceMapBuilder.addMapping); 3198 buffer.forEachSourceLocation(sourceMapBuilder.addMapping);
3193 return sourceMapBuilder.build(compiledFile); 3199 return sourceMapBuilder.build(compiledFile);
3194 } 3200 }
3195 3201
3196 void outputSourceMap(CodeBuffer buffer, String code, String name) { 3202 void outputSourceMap(CodeBuffer buffer, String code, String name) {
3197 if (!generateSourceMap) return; 3203 if (!generateSourceMap) return;
3198 SourceFile compiledFile = new SourceFile(null, compiler.assembledCode); 3204 SourceFile compiledFile = new SourceFile(null, compiler.assembledCode);
3199 String sourceMap = buildSourceMap(mainBuffer, compiledFile); 3205 String sourceMap = buildSourceMap(mainBuffer, compiledFile);
3200 compiler.outputProvider(name, 'js.map') 3206 compiler.outputProvider(name, 'js.map')
3201 ..add(sourceMap) 3207 ..add(sourceMap)
3202 ..close(); 3208 ..close();
3203 } 3209 }
3204 3210
3205 bool isDeferred(Element element) { 3211 bool isDeferred(Element element) {
3206 return compiler.deferredLoadTask.isDeferred(element); 3212 return compiler.deferredLoadTask.isDeferred(element);
3207 } 3213 }
3208 3214
3209 // TODO(ahe): Remove this when deferred loading is fully implemented. 3215 // TODO(ahe): Remove this when deferred loading is fully implemented.
3210 void warnNotImplemented(Element element, String message) { 3216 void warnNotImplemented(Element element, String message) {
3211 compiler.reportMessage(compiler.spanFromSpannable(element), 3217 compiler.reportMessage(compiler.spanFromSpannable(element),
3212 MessageKind.GENERIC.error({'text': message}), 3218 MessageKind.GENERIC.error({'text': message}),
3213 api.Diagnostic.WARNING); 3219 api.Diagnostic.WARNING);
3214 } 3220 }
3215 } 3221 }
3216 3222
3217 const String GENERATED_BY = """
3218 // Generated by dart2js, the Dart to JavaScript compiler.
3219 """;
3220
3221 const String HOOKS_API_USAGE = """ 3223 const String HOOKS_API_USAGE = """
3222 // The code supports the following hooks: 3224 // The code supports the following hooks:
3223 // dartPrint(message) - if this function is defined it is called 3225 // dartPrint(message) - if this function is defined it is called
3224 // instead of the Dart [print] method. 3226 // instead of the Dart [print] method.
3225 // dartMainRunner(main) - if this function is defined, the Dart [main] 3227 // dartMainRunner(main) - if this function is defined, the Dart [main]
3226 // method will not be invoked directly. 3228 // method will not be invoked directly.
3227 // Instead, a closure that will invoke [main] is 3229 // Instead, a closure that will invoke [main] is
3228 // passed to [dartMainRunner]. 3230 // passed to [dartMainRunner].
3229 """; 3231 """;
3230 3232
(...skipping 20 matching lines...) Expand all
3251 functions.push(property); 3253 functions.push(property);
3252 } else { 3254 } else {
3253 $$[property] = element; 3255 $$[property] = element;
3254 classes.push(property); 3256 classes.push(property);
3255 classes.push(element[""]); 3257 classes.push(element[""]);
3256 } 3258 }
3257 } 3259 }
3258 libraries.push([name, uri, classes, functions]); 3260 libraries.push([name, uri, classes, functions]);
3259 } 3261 }
3260 })'''; 3262 })''';
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart2js.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698