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

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

Issue 10911091: Add empty mapping entries for the ranges of generated JavaScript that don't map to any Dart source … (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 3 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
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 /** 5 /**
6 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 26 matching lines...) Expand all
37 NativeEmitter nativeEmitter; 37 NativeEmitter nativeEmitter;
38 CodeBuffer boundClosureBuffer; 38 CodeBuffer boundClosureBuffer;
39 CodeBuffer mainBuffer; 39 CodeBuffer mainBuffer;
40 /** Shorter access to [isolatePropertiesName]. Both here in the code, as 40 /** Shorter access to [isolatePropertiesName]. Both here in the code, as
41 well as in the generated code. */ 41 well as in the generated code. */
42 String isolateProperties; 42 String isolateProperties;
43 String classesCollector; 43 String classesCollector;
44 final Map<int, String> boundClosureCache; 44 final Map<int, String> boundClosureCache;
45 45
46 final bool generateSourceMap; 46 final bool generateSourceMap;
47 final SourceMapBuilder sourceMapBuilder;
48 47
49 CodeEmitterTask(Compiler compiler, [bool generateSourceMap = false]) 48 CodeEmitterTask(Compiler compiler, [bool generateSourceMap = false])
50 : namer = compiler.namer, 49 : namer = compiler.namer,
51 boundClosureBuffer = new CodeBuffer(), 50 boundClosureBuffer = new CodeBuffer(),
52 mainBuffer = new CodeBuffer(), 51 mainBuffer = new CodeBuffer(),
53 boundClosureCache = new Map<int, String>(), 52 boundClosureCache = new Map<int, String>(),
54 generateSourceMap = generateSourceMap, 53 generateSourceMap = generateSourceMap,
55 sourceMapBuilder = new SourceMapBuilder(),
56 super(compiler) { 54 super(compiler) {
57 nativeEmitter = new NativeEmitter(this); 55 nativeEmitter = new NativeEmitter(this);
58 } 56 }
59 57
60 String get name => 'CodeEmitter'; 58 String get name => 'CodeEmitter';
61 59
62 String get defineClassName 60 String get defineClassName
63 => '${namer.ISOLATE}.\$defineClass'; 61 => '${namer.ISOLATE}.\$defineClass';
64 String get finishClassesName 62 String get finishClassesName
65 => '${namer.ISOLATE}.\$finishClasses'; 63 => '${namer.ISOLATE}.\$finishClasses';
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 583
586 void emitInstanceMembers(ClassElement classElement, 584 void emitInstanceMembers(ClassElement classElement,
587 CodeBuffer buffer, 585 CodeBuffer buffer,
588 bool needsLeadingComma) { 586 bool needsLeadingComma) {
589 bool needsComma = needsLeadingComma; 587 bool needsComma = needsLeadingComma;
590 void defineInstanceMember(String name, CodeBuffer memberBuffer) { 588 void defineInstanceMember(String name, CodeBuffer memberBuffer) {
591 if (needsComma) buffer.add(','); 589 if (needsComma) buffer.add(',');
592 needsComma = true; 590 needsComma = true;
593 buffer.add('\n'); 591 buffer.add('\n');
594 buffer.add(' $name: '); 592 buffer.add(' $name: ');
595 addMappings(memberBuffer, buffer.length);
596 buffer.add(memberBuffer); 593 buffer.add(memberBuffer);
597 } 594 }
598 595
599 classElement.forEachMember(includeBackendMembers: true, 596 classElement.forEachMember(includeBackendMembers: true,
600 f: (ClassElement enclosing, Element member) { 597 f: (ClassElement enclosing, Element member) {
601 if (member.isInstanceMember()) { 598 if (member.isInstanceMember()) {
602 addInstanceMember(member, defineInstanceMember); 599 addInstanceMember(member, defineInstanceMember);
603 } 600 }
604 }); 601 });
605 602
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 buffer.add("$classesCollector = {};\n"); 739 buffer.add("$classesCollector = {};\n");
743 } 740 }
744 } 741 }
745 742
746 void emitStaticFunctionWithNamer(CodeBuffer buffer, 743 void emitStaticFunctionWithNamer(CodeBuffer buffer,
747 Element element, 744 Element element,
748 CodeBuffer functionBuffer, 745 CodeBuffer functionBuffer,
749 String functionNamer(Element element)) { 746 String functionNamer(Element element)) {
750 String functionName = functionNamer(element); 747 String functionName = functionNamer(element);
751 buffer.add('$isolateProperties.$functionName = '); 748 buffer.add('$isolateProperties.$functionName = ');
752 addMappings(functionBuffer, buffer.length);
753 buffer.add(functionBuffer); 749 buffer.add(functionBuffer);
754 buffer.add(';\n\n'); 750 buffer.add(';\n\n');
755 } 751 }
756 void emitStaticFunctionsWithNamer(CodeBuffer buffer, 752 void emitStaticFunctionsWithNamer(CodeBuffer buffer,
757 Map<Element, CodeBuffer> generatedCode, 753 Map<Element, CodeBuffer> generatedCode,
758 String functionNamer(Element element)) { 754 String functionNamer(Element element)) {
759 generatedCode.forEach((Element element, CodeBuffer functionBuffer) { 755 generatedCode.forEach((Element element, CodeBuffer functionBuffer) {
760 if (!element.isInstanceMember() && !element.isField()) { 756 if (!element.isInstanceMember() && !element.isField()) {
761 emitStaticFunctionWithNamer( 757 emitStaticFunctionWithNamer(
762 buffer, element, functionBuffer,functionNamer); 758 buffer, element, functionBuffer,functionNamer);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 // closure that constructs the initial value. 945 // closure that constructs the initial value.
950 buffer.add("$lazyInitializerName("); 946 buffer.add("$lazyInitializerName(");
951 buffer.add(isolateProperties); 947 buffer.add(isolateProperties);
952 buffer.add(", '"); 948 buffer.add(", '");
953 buffer.add(element.name.slowToString()); 949 buffer.add(element.name.slowToString());
954 buffer.add("', '"); 950 buffer.add("', '");
955 buffer.add(namer.getName(element)); 951 buffer.add(namer.getName(element));
956 buffer.add("', '"); 952 buffer.add("', '");
957 buffer.add(namer.getLazyInitializerName(element)); 953 buffer.add(namer.getLazyInitializerName(element));
958 buffer.add("', "); 954 buffer.add("', ");
959 addMappings(code, buffer.length);
960 buffer.add(code); 955 buffer.add(code);
961 buffer.add(");\n"); 956 buffer.add(");\n");
962 } 957 }
963 } 958 }
964 } 959 }
965 960
966 void emitCompileTimeConstants(CodeBuffer buffer) { 961 void emitCompileTimeConstants(CodeBuffer buffer) {
967 ConstantHandler handler = compiler.constantHandler; 962 ConstantHandler handler = compiler.constantHandler;
968 List<Constant> constants = handler.getConstantsForEmission(); 963 List<Constant> constants = handler.getConstantsForEmission();
969 bool addedMakeConstantList = false; 964 bool addedMakeConstantList = false;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 mainBuffer.add('function init() {\n'); 1266 mainBuffer.add('function init() {\n');
1272 mainBuffer.add('$isolateProperties = {};\n'); 1267 mainBuffer.add('$isolateProperties = {};\n');
1273 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); 1268 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer);
1274 addLazyInitializerFunctionIfNecessary(mainBuffer); 1269 addLazyInitializerFunctionIfNecessary(mainBuffer);
1275 emitFinishIsolateConstructor(mainBuffer); 1270 emitFinishIsolateConstructor(mainBuffer);
1276 mainBuffer.add('}\n'); 1271 mainBuffer.add('}\n');
1277 compiler.assembledCode = mainBuffer.toString(); 1272 compiler.assembledCode = mainBuffer.toString();
1278 1273
1279 if (generateSourceMap) { 1274 if (generateSourceMap) {
1280 SourceFile compiledFile = new SourceFile(null, compiler.assembledCode); 1275 SourceFile compiledFile = new SourceFile(null, compiler.assembledCode);
1281 String sourceMap = sourceMapBuilder.build(compiledFile); 1276 String sourceMap = buildSourceMap(mainBuffer, compiledFile);
1282 // TODO(podivilov): We should find a better way to return source maps to 1277 // TODO(podivilov): We should find a better way to return source maps to
1283 // compiler. Using diagnostic handler for that purpose is a temporary 1278 // compiler. Using diagnostic handler for that purpose is a temporary
1284 // hack. 1279 // hack.
1285 compiler.reportDiagnostic( 1280 compiler.reportDiagnostic(
1286 null, sourceMap, new api.Diagnostic(-1, 'source map')); 1281 null, sourceMap, new api.Diagnostic(-1, 'source map'));
1287 } 1282 }
1288 }); 1283 });
1289 return compiler.assembledCode; 1284 return compiler.assembledCode;
1290 } 1285 }
1291 1286
1292 void addMappings(CodeBuffer buffer, int bufferOffset) { 1287 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) {
1288 SourceMapBuilder sourceMapBuilder = new SourceMapBuilder();
1293 buffer.forEachSourceLocation((Element element, Token token, int offset) { 1289 buffer.forEachSourceLocation((Element element, Token token, int offset) {
1290 if (element == null) {
1291 sourceMapBuilder.addMapping(null, null, null, offset);
1292 return;
1293 }
1294 SourceFile sourceFile = element.getCompilationUnit().script.file; 1294 SourceFile sourceFile = element.getCompilationUnit().script.file;
1295 String sourceName = null; 1295 String sourceName = null;
1296 if (token.kind === IDENTIFIER_TOKEN) { 1296 if (token.kind === IDENTIFIER_TOKEN) {
1297 sourceName = token.slowToString(); 1297 sourceName = token.slowToString();
1298 } 1298 }
1299 int totalOffset = bufferOffset + offset;
1300 sourceMapBuilder.addMapping( 1299 sourceMapBuilder.addMapping(
1301 sourceFile, token.charOffset, sourceName, totalOffset); 1300 sourceFile, token.charOffset, sourceName, offset);
1302 }); 1301 });
1302 return sourceMapBuilder.build(compiledFile);
1303 } 1303 }
1304 } 1304 }
1305 1305
1306 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition); 1306 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition);
OLDNEW
« no previous file with comments | « lib/compiler/implementation/js/printer.dart ('k') | lib/compiler/implementation/source_map_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698