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

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

Issue 12294028: Fix warnings spotted by dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 10 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 library source_map_builder; 5 library source_map_builder;
6 6
7 import 'util/util.dart'; 7 import 'util/util.dart';
8 import 'scanner/scannerlib.dart' show Token; 8 import 'scanner/scannerlib.dart' show Token;
9 import 'source_file.dart'; 9 import 'source_file.dart';
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 previousSourceNameIndex = 0; 47 previousSourceNameIndex = 0;
48 firstEntryInLine = true; 48 firstEntryInLine = true;
49 } 49 }
50 50
51 void addMapping(int targetOffset, SourceFileLocation sourceLocation) { 51 void addMapping(int targetOffset, SourceFileLocation sourceLocation) {
52 entries.add(new SourceMapEntry(sourceLocation, targetOffset)); 52 entries.add(new SourceMapEntry(sourceLocation, targetOffset));
53 } 53 }
54 54
55 void printStringListOn(List<String> strings, StringBuffer buffer) { 55 void printStringListOn(List<String> strings, StringBuffer buffer) {
56 bool first = true; 56 bool first = true;
57 buffer.add('['); 57 buffer.write('[');
58 for (String string in strings) { 58 for (String string in strings) {
59 if (!first) buffer.add(','); 59 if (!first) buffer.write(',');
60 buffer.add('"'); 60 buffer.write('"');
61 writeJsonEscapedCharsOn(string, buffer); 61 writeJsonEscapedCharsOn(string, buffer);
62 buffer.add('"'); 62 buffer.write('"');
63 first = false; 63 first = false;
64 } 64 }
65 buffer.add(']'); 65 buffer.write(']');
66 } 66 }
67 67
68 String build(SourceFile targetFile) { 68 String build(SourceFile targetFile) {
69 StringBuffer mappingsBuffer = new StringBuffer(); 69 StringBuffer mappingsBuffer = new StringBuffer();
70 entries.forEach((SourceMapEntry entry) => writeEntry(entry, targetFile, 70 entries.forEach((SourceMapEntry entry) => writeEntry(entry, targetFile,
71 mappingsBuffer)); 71 mappingsBuffer));
72 StringBuffer buffer = new StringBuffer(); 72 StringBuffer buffer = new StringBuffer();
73 buffer.add('{\n'); 73 buffer.write('{\n');
74 buffer.add(' "version": 3,\n'); 74 buffer.write(' "version": 3,\n');
75 buffer.add(' "sourceRoot": "",\n'); 75 buffer.write(' "sourceRoot": "",\n');
76 buffer.add(' "sources": '); 76 buffer.write(' "sources": ');
77 printStringListOn(sourceUrlList, buffer); 77 printStringListOn(sourceUrlList, buffer);
78 buffer.add(',\n'); 78 buffer.write(',\n');
79 buffer.add(' "names": '); 79 buffer.write(' "names": ');
80 printStringListOn(sourceNameList, buffer); 80 printStringListOn(sourceNameList, buffer);
81 buffer.add(',\n'); 81 buffer.write(',\n');
82 buffer.add(' "mappings": "'); 82 buffer.write(' "mappings": "');
83 buffer.add(mappingsBuffer); 83 buffer.write(mappingsBuffer);
84 buffer.add('"\n}\n'); 84 buffer.write('"\n}\n');
85 return buffer.toString(); 85 return buffer.toString();
86 } 86 }
87 87
88 void writeEntry(SourceMapEntry entry, SourceFile targetFile, StringBuffer outp ut) { 88 void writeEntry(SourceMapEntry entry, SourceFile targetFile, StringBuffer outp ut) {
89 int targetLine = targetFile.getLine(entry.targetOffset); 89 int targetLine = targetFile.getLine(entry.targetOffset);
90 int targetColumn = targetFile.getColumn(targetLine, entry.targetOffset); 90 int targetColumn = targetFile.getColumn(targetLine, entry.targetOffset);
91 91
92 if (targetLine > previousTargetLine) { 92 if (targetLine > previousTargetLine) {
93 for (int i = previousTargetLine; i < targetLine; ++i) { 93 for (int i = previousTargetLine; i < targetLine; ++i) {
94 output.add(';'); 94 output.write(';');
95 } 95 }
96 previousTargetLine = targetLine; 96 previousTargetLine = targetLine;
97 previousTargetColumn = 0; 97 previousTargetColumn = 0;
98 firstEntryInLine = true; 98 firstEntryInLine = true;
99 } 99 }
100 100
101 if (!firstEntryInLine) { 101 if (!firstEntryInLine) {
102 output.add(','); 102 output.write(',');
103 } 103 }
104 firstEntryInLine = false; 104 firstEntryInLine = false;
105 105
106 encodeVLQ(output, targetColumn - previousTargetColumn); 106 encodeVLQ(output, targetColumn - previousTargetColumn);
107 previousTargetColumn = targetColumn; 107 previousTargetColumn = targetColumn;
108 108
109 if (entry.sourceLocation == null) return; 109 if (entry.sourceLocation == null) return;
110 110
111 String sourceUrl = entry.sourceLocation.getSourceUrl(); 111 String sourceUrl = entry.sourceLocation.getSourceUrl();
112 int sourceLine = entry.sourceLocation.getLine(); 112 int sourceLine = entry.sourceLocation.getLine();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 signBit = 1; 145 signBit = 1;
146 value = -value; 146 value = -value;
147 } 147 }
148 value = (value << 1) | signBit; 148 value = (value << 1) | signBit;
149 do { 149 do {
150 int digit = value & VLQ_BASE_MASK; 150 int digit = value & VLQ_BASE_MASK;
151 value >>= VLQ_BASE_SHIFT; 151 value >>= VLQ_BASE_SHIFT;
152 if (value > 0) { 152 if (value > 0) {
153 digit |= VLQ_CONTINUATION_BIT; 153 digit |= VLQ_CONTINUATION_BIT;
154 } 154 }
155 output.add(BASE64_DIGITS[digit]); 155 output.write(BASE64_DIGITS[digit]);
156 } while (value > 0); 156 } while (value > 0);
157 } 157 }
158 } 158 }
159 159
160 class SourceMapEntry { 160 class SourceMapEntry {
161 SourceFileLocation sourceLocation; 161 SourceFileLocation sourceLocation;
162 int targetOffset; 162 int targetOffset;
163 163
164 SourceMapEntry(this.sourceLocation, this.targetOffset); 164 SourceMapEntry(this.sourceLocation, this.targetOffset);
165 } 165 }
(...skipping 16 matching lines...) Expand all
182 182
183 int getColumn() => sourceFile.getColumn(getLine(), token.charOffset); 183 int getColumn() => sourceFile.getColumn(getLine(), token.charOffset);
184 184
185 String getSourceName() { 185 String getSourceName() {
186 if (token.isIdentifier()) return token.slowToString(); 186 if (token.isIdentifier()) return token.slowToString();
187 return null; 187 return null;
188 } 188 }
189 189
190 bool isValid() => token.charOffset < sourceFile.text.length; 190 bool isValid() => token.charOffset < sourceFile.text.length;
191 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698