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

Side by Side Diff: pkg/compiler/lib/src/compiler.dart

Issue 1248483008: Split MessageKind into a MessageKind key and a MessageTemplate. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 5 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/dart2jslib.dart » ('j') | 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 dart2js; 5 part of dart2js;
6 6
7 /** 7 /**
8 * If true, print a warning for each method that was resolved, but not 8 * If true, print a warning for each method that was resolved, but not
9 * compiled. 9 * compiled.
10 */ 10 */
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 void internalError(Spannable node, reason) { 1155 void internalError(Spannable node, reason) {
1156 String message = tryToString(reason); 1156 String message = tryToString(reason);
1157 reportDiagnosticInternal( 1157 reportDiagnosticInternal(
1158 node, MessageKind.GENERIC, {'text': message}, api.Diagnostic.CRASH); 1158 node, MessageKind.GENERIC, {'text': message}, api.Diagnostic.CRASH);
1159 throw 'Internal Error: $message'; 1159 throw 'Internal Error: $message';
1160 } 1160 }
1161 1161
1162 void unhandledExceptionOnElement(Element element) { 1162 void unhandledExceptionOnElement(Element element) {
1163 if (hasCrashed) return; 1163 if (hasCrashed) return;
1164 hasCrashed = true; 1164 hasCrashed = true;
1165 reportDiagnostic(element, 1165 reportDiagnostic(
1166 MessageKind.COMPILER_CRASHED.message(), 1166 element,
1167 api.Diagnostic.CRASH); 1167 MessageTemplate.TEMPLATES[MessageKind.COMPILER_CRASHED].message(),
1168 api.Diagnostic.CRASH);
1168 pleaseReportCrash(); 1169 pleaseReportCrash();
1169 } 1170 }
1170 1171
1171 void pleaseReportCrash() { 1172 void pleaseReportCrash() {
1172 print(MessageKind.PLEASE_REPORT_THE_CRASH.message({'buildId': buildId})); 1173 print(
1174 MessageTemplate.TEMPLATES[MessageKind.PLEASE_REPORT_THE_CRASH]
1175 .message({'buildId': buildId}));
1173 } 1176 }
1174 1177
1175 SourceSpan spanFromSpannable(Spannable node) { 1178 SourceSpan spanFromSpannable(Spannable node) {
1176 // TODO(johnniwinther): Disallow `node == null` ? 1179 // TODO(johnniwinther): Disallow `node == null` ?
1177 if (node == null) return null; 1180 if (node == null) return null;
1178 if (node == CURRENT_ELEMENT_SPANNABLE) { 1181 if (node == CURRENT_ELEMENT_SPANNABLE) {
1179 node = currentElement; 1182 node = currentElement;
1180 } else if (node == NO_LOCATION_SPANNABLE) { 1183 } else if (node == NO_LOCATION_SPANNABLE) {
1181 if (currentElement == null) return null; 1184 if (currentElement == null) return null;
1182 node = currentElement; 1185 node = currentElement;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 } else if (node is HInstruction) { 1221 } else if (node is HInstruction) {
1219 element = _elementFromHInstruction(node); 1222 element = _elementFromHInstruction(node);
1220 } else if (node is MetadataAnnotation) { 1223 } else if (node is MetadataAnnotation) {
1221 element = node.annotatedElement; 1224 element = node.annotatedElement;
1222 } 1225 }
1223 return element != null ? element : currentElement; 1226 return element != null ? element : currentElement;
1224 } 1227 }
1225 1228
1226 void log(message) { 1229 void log(message) {
1227 reportDiagnostic(null, 1230 reportDiagnostic(null,
1228 MessageKind.GENERIC.message({'text': '$message'}), 1231 MessageTemplate.TEMPLATES[MessageKind.GENERIC]
1232 .message({'text': '$message'}),
1229 api.Diagnostic.VERBOSE_INFO); 1233 api.Diagnostic.VERBOSE_INFO);
1230 } 1234 }
1231 1235
1232 Future<bool> run(Uri uri) { 1236 Future<bool> run(Uri uri) {
1233 totalCompileTime.start(); 1237 totalCompileTime.start();
1234 1238
1235 return new Future.sync(() => runCompiler(uri)).catchError((error) { 1239 return new Future.sync(() => runCompiler(uri)).catchError((error) {
1236 try { 1240 try {
1237 if (!hasCrashed) { 1241 if (!hasCrashed) {
1238 hasCrashed = true; 1242 hasCrashed = true;
1239 if (error is SpannableAssertionFailure) { 1243 if (error is SpannableAssertionFailure) {
1240 reportAssertionFailure(error); 1244 reportAssertionFailure(error);
1241 } else { 1245 } else {
1242 reportDiagnostic(new SourceSpan(uri, 0, 0), 1246 reportDiagnostic(
1243 MessageKind.COMPILER_CRASHED.message(), 1247 new SourceSpan(uri, 0, 0),
1244 api.Diagnostic.CRASH); 1248 MessageTemplate.TEMPLATES[MessageKind.COMPILER_CRASHED]
1249 .message(),
1250 api.Diagnostic.CRASH);
1245 } 1251 }
1246 pleaseReportCrash(); 1252 pleaseReportCrash();
1247 } 1253 }
1248 } catch (doubleFault) { 1254 } catch (doubleFault) {
1249 // Ignoring exceptions in exception handling. 1255 // Ignoring exceptions in exception handling.
1250 } 1256 }
1251 throw error; 1257 throw error;
1252 }).whenComplete(() { 1258 }).whenComplete(() {
1253 tracer.close(); 1259 tracer.close();
1254 totalCompileTime.stop(); 1260 totalCompileTime.stop();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 return true; 1378 return true;
1373 }); 1379 });
1374 1380
1375 if (!backend.supportsReflection) { 1381 if (!backend.supportsReflection) {
1376 reportError(NO_LOCATION_SPANNABLE, 1382 reportError(NO_LOCATION_SPANNABLE,
1377 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND); 1383 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND);
1378 } else { 1384 } else {
1379 reportWarning(NO_LOCATION_SPANNABLE, 1385 reportWarning(NO_LOCATION_SPANNABLE,
1380 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, 1386 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS,
1381 {'importChain': importChains.join( 1387 {'importChain': importChains.join(
1382 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}); 1388 MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)});
1383 } 1389 }
1384 } 1390 }
1385 1391
1386 functionClass.ensureResolved(this); 1392 functionClass.ensureResolved(this);
1387 functionApplyMethod = functionClass.lookupLocalMember('apply'); 1393 functionApplyMethod = functionClass.lookupLocalMember('apply');
1388 1394
1389 proxyConstant = 1395 proxyConstant =
1390 constants.getConstantValue( 1396 constants.getConstantValue(
1391 resolver.constantCompiler.compileConstant( 1397 resolver.constantCompiler.compileConstant(
1392 coreLibrary.find('proxy'))); 1398 coreLibrary.find('proxy')));
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 enqueuer.resolution.logSummary(log); 1614 enqueuer.resolution.logSummary(log);
1609 1615
1610 if (!showPackageWarnings && !suppressWarnings) { 1616 if (!showPackageWarnings && !suppressWarnings) {
1611 suppressedWarnings.forEach((Uri uri, SuppressionInfo info) { 1617 suppressedWarnings.forEach((Uri uri, SuppressionInfo info) {
1612 MessageKind kind = MessageKind.HIDDEN_WARNINGS_HINTS; 1618 MessageKind kind = MessageKind.HIDDEN_WARNINGS_HINTS;
1613 if (info.warnings == 0) { 1619 if (info.warnings == 0) {
1614 kind = MessageKind.HIDDEN_HINTS; 1620 kind = MessageKind.HIDDEN_HINTS;
1615 } else if (info.hints == 0) { 1621 } else if (info.hints == 0) {
1616 kind = MessageKind.HIDDEN_WARNINGS; 1622 kind = MessageKind.HIDDEN_WARNINGS;
1617 } 1623 }
1624 MessageTemplate template = MessageTemplate.TEMPLATES[kind];
1618 reportDiagnostic(null, 1625 reportDiagnostic(null,
1619 kind.message({'warnings': info.warnings, 1626 template.message(
1620 'hints': info.hints, 1627 {'warnings': info.warnings,
1621 'uri': uri}, 1628 'hints': info.hints,
1622 terseDiagnostics), 1629 'uri': uri},
1630 terseDiagnostics),
1623 api.Diagnostic.HINT); 1631 api.Diagnostic.HINT);
1624 }); 1632 });
1625 } 1633 }
1626 1634
1627 if (compilationFailed){ 1635 if (compilationFailed){
1628 if (!generateCodeWithCompileTimeErrors) return; 1636 if (!generateCodeWithCompileTimeErrors) return;
1629 if (!backend.enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) { 1637 if (!backend.enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) {
1630 return; 1638 return;
1631 } 1639 }
1632 } 1640 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 } 1898 }
1891 break; 1899 break;
1892 case api.Diagnostic.INFO: 1900 case api.Diagnostic.INFO:
1893 if (lastDiagnosticWasFiltered) { 1901 if (lastDiagnosticWasFiltered) {
1894 return; 1902 return;
1895 } 1903 }
1896 break; 1904 break;
1897 } 1905 }
1898 } 1906 }
1899 lastDiagnosticWasFiltered = false; 1907 lastDiagnosticWasFiltered = false;
1908 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind];
1900 reportDiagnostic( 1909 reportDiagnostic(
1901 node, messageKind.message(arguments, terseDiagnostics), kind); 1910 node,
1911 template.message(arguments, terseDiagnostics),
1912 kind);
1902 } 1913 }
1903 1914
1904 void reportDiagnostic(Spannable span, 1915 void reportDiagnostic(Spannable span,
1905 Message message, 1916 Message message,
1906 api.Diagnostic kind); 1917 api.Diagnostic kind);
1907 1918
1908 void reportAssertionFailure(SpannableAssertionFailure ex) { 1919 void reportAssertionFailure(SpannableAssertionFailure ex) {
1909 String message = (ex.message != null) ? tryToString(ex.message) 1920 String message = (ex.message != null) ? tryToString(ex.message)
1910 : tryToString(ex); 1921 : tryToString(ex);
1911 reportDiagnosticInternal( 1922 reportDiagnosticInternal(
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 InterfaceType streamType([DartType elementType]) { 2510 InterfaceType streamType([DartType elementType]) {
2500 InterfaceType type = streamClass.computeType(compiler); 2511 InterfaceType type = streamClass.computeType(compiler);
2501 if (elementType == null) { 2512 if (elementType == null) {
2502 return streamClass.rawType; 2513 return streamClass.rawType;
2503 } 2514 }
2504 return type.createInstantiation([elementType]); 2515 return type.createInstantiation([elementType]);
2505 } 2516 }
2506 } 2517 }
2507 2518
2508 typedef void InternalErrorFunction(Spannable location, String message); 2519 typedef void InternalErrorFunction(Spannable location, String message);
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/dart2jslib.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698