| OLD | NEW |
| 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 dart2js.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink, Future; | 7 import 'dart:async' show EventSink, Future; |
| 8 | 8 |
| 9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
| 10 import 'cache_strategy.dart' show CacheStrategy; | 10 import 'cache_strategy.dart' show CacheStrategy; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 /// The [int.fromEnvironment] constructor. | 207 /// The [int.fromEnvironment] constructor. |
| 208 ConstructorElement intEnvironment; | 208 ConstructorElement intEnvironment; |
| 209 | 209 |
| 210 /// The [bool.fromEnvironment] constructor. | 210 /// The [bool.fromEnvironment] constructor. |
| 211 ConstructorElement boolEnvironment; | 211 ConstructorElement boolEnvironment; |
| 212 | 212 |
| 213 /// The [String.fromEnvironment] constructor. | 213 /// The [String.fromEnvironment] constructor. |
| 214 ConstructorElement stringEnvironment; | 214 ConstructorElement stringEnvironment; |
| 215 | 215 |
| 216 // TODO(zarah): Remove this map and incorporate compile-time errors |
| 217 // in the model. |
| 216 /// Tracks elements with compile-time errors. | 218 /// Tracks elements with compile-time errors. |
| 217 final Set<Element> elementsWithCompileTimeErrors = new Set<Element>(); | 219 final Map<Element, List<DiagnosticMessage>> elementsWithCompileTimeErrors = |
| 220 new Map<Element, List<DiagnosticMessage>>(); |
| 218 | 221 |
| 219 final Environment environment; | 222 final Environment environment; |
| 220 // TODO(sigmund): delete once we migrate the rest of the compiler to use | 223 // TODO(sigmund): delete once we migrate the rest of the compiler to use |
| 221 // `environment` directly. | 224 // `environment` directly. |
| 222 @deprecated | 225 @deprecated |
| 223 fromEnvironment(String name) => environment.valueOf(name); | 226 fromEnvironment(String name) => environment.valueOf(name); |
| 224 | 227 |
| 225 Element get currentElement => _reporter.currentElement; | 228 Element get currentElement => _reporter.currentElement; |
| 226 | 229 |
| 227 List<CompilerTask> tasks; | 230 List<CompilerTask> tasks; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 bool get shouldPrintProgress { | 268 bool get shouldPrintProgress { |
| 266 return options.verbose && progress.elapsedMilliseconds > 500; | 269 return options.verbose && progress.elapsedMilliseconds > 500; |
| 267 } | 270 } |
| 268 | 271 |
| 269 static const int PHASE_SCANNING = 0; | 272 static const int PHASE_SCANNING = 0; |
| 270 static const int PHASE_RESOLVING = 1; | 273 static const int PHASE_RESOLVING = 1; |
| 271 static const int PHASE_DONE_RESOLVING = 2; | 274 static const int PHASE_DONE_RESOLVING = 2; |
| 272 static const int PHASE_COMPILING = 3; | 275 static const int PHASE_COMPILING = 3; |
| 273 int phase; | 276 int phase; |
| 274 | 277 |
| 275 bool compilationFailedInternal = false; | 278 bool compilationFailed = false; |
| 276 | |
| 277 bool get compilationFailed => compilationFailedInternal; | |
| 278 | |
| 279 void set compilationFailed(bool value) { | |
| 280 if (value) { | |
| 281 elementsWithCompileTimeErrors.add(currentElement); | |
| 282 } | |
| 283 compilationFailedInternal = value; | |
| 284 } | |
| 285 | 279 |
| 286 Compiler( | 280 Compiler( |
| 287 {CompilerOptions options, | 281 {CompilerOptions options, |
| 288 api.CompilerOutput outputProvider, | 282 api.CompilerOutput outputProvider, |
| 289 this.environment: const _EmptyEnvironment(), | 283 this.environment: const _EmptyEnvironment(), |
| 290 MakeBackendFuncion makeBackend, | 284 MakeBackendFuncion makeBackend, |
| 291 MakeReporterFunction makeReporter}) | 285 MakeReporterFunction makeReporter}) |
| 292 : this.options = options, | 286 : this.options = options, |
| 293 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), | 287 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), |
| 294 this.userOutputProvider = outputProvider == null | 288 this.userOutputProvider = outputProvider == null |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 return true; | 1083 return true; |
| 1090 } | 1084 } |
| 1091 return !BENIGN_ERRORS.contains(message.message.kind); | 1085 return !BENIGN_ERRORS.contains(message.message.kind); |
| 1092 } | 1086 } |
| 1093 | 1087 |
| 1094 void fatalDiagnosticReported(DiagnosticMessage message, | 1088 void fatalDiagnosticReported(DiagnosticMessage message, |
| 1095 List<DiagnosticMessage> infos, api.Diagnostic kind) { | 1089 List<DiagnosticMessage> infos, api.Diagnostic kind) { |
| 1096 if (markCompilationAsFailed(message, kind)) { | 1090 if (markCompilationAsFailed(message, kind)) { |
| 1097 compilationFailed = true; | 1091 compilationFailed = true; |
| 1098 } | 1092 } |
| 1093 registerCompiletimeError(currentElement, message); |
| 1099 } | 1094 } |
| 1100 | 1095 |
| 1101 /** | 1096 /** |
| 1102 * Reads the script specified by the [readableUri]. | 1097 * Reads the script specified by the [readableUri]. |
| 1103 * | 1098 * |
| 1104 * See [LibraryLoader] for terminology on URIs. | 1099 * See [LibraryLoader] for terminology on URIs. |
| 1105 */ | 1100 */ |
| 1106 Future<Script> readScript(Uri readableUri, [Spannable node]) { | 1101 Future<Script> readScript(Uri readableUri, [Spannable node]) { |
| 1107 unimplemented(node, 'Compiler.readScript'); | 1102 unimplemented(node, 'Compiler.readScript'); |
| 1108 return null; | 1103 return null; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 enqueuer.forgetElement(element); | 1219 enqueuer.forgetElement(element); |
| 1225 if (element is MemberElement) { | 1220 if (element is MemberElement) { |
| 1226 for (Element closure in element.nestedClosures) { | 1221 for (Element closure in element.nestedClosures) { |
| 1227 // TODO(ahe): It would be nice to reuse names of nested closures. | 1222 // TODO(ahe): It would be nice to reuse names of nested closures. |
| 1228 closureToClassMapper.forgetElement(closure); | 1223 closureToClassMapper.forgetElement(closure); |
| 1229 } | 1224 } |
| 1230 } | 1225 } |
| 1231 backend.forgetElement(element); | 1226 backend.forgetElement(element); |
| 1232 } | 1227 } |
| 1233 | 1228 |
| 1229 /// Returns [true] if a compile-time error has been reported for element. |
| 1234 bool elementHasCompileTimeError(Element element) { | 1230 bool elementHasCompileTimeError(Element element) { |
| 1235 return elementsWithCompileTimeErrors.contains(element); | 1231 return elementsWithCompileTimeErrors.containsKey(element); |
| 1232 } |
| 1233 |
| 1234 /// Associate [element] with a compile-time error [message]. |
| 1235 void registerCompiletimeError(Element element, DiagnosticMessage message) { |
| 1236 // The information is only needed if [generateCodeWithCompileTimeErrors]. |
| 1237 if (options.generateCodeWithCompileTimeErrors) { |
| 1238 if (element == null) { |
| 1239 // Record as global error. |
| 1240 // TODO(zarah): Extend element model to represent compile-time |
| 1241 // errors instead of using a map. |
| 1242 element = mainFunction; |
| 1243 } |
| 1244 elementsWithCompileTimeErrors. |
| 1245 putIfAbsent(element, () => <DiagnosticMessage>[]).add(message); |
| 1246 } |
| 1236 } | 1247 } |
| 1237 | 1248 |
| 1238 EventSink<String> outputProvider(String name, String extension) { | 1249 EventSink<String> outputProvider(String name, String extension) { |
| 1239 if (compilationFailed) { | 1250 if (compilationFailed) { |
| 1240 if (!options.generateCodeWithCompileTimeErrors || options.testMode) { | 1251 if (!options.generateCodeWithCompileTimeErrors || options.testMode) { |
| 1241 // Disable output in test mode: The build bot currently uses the time | 1252 // Disable output in test mode: The build bot currently uses the time |
| 1242 // stamp of the generated file to determine whether the output is | 1253 // stamp of the generated file to determine whether the output is |
| 1243 // up-to-date. | 1254 // up-to-date. |
| 1244 return new NullSink('$name.$extension'); | 1255 return new NullSink('$name.$extension'); |
| 1245 } | 1256 } |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 lastDiagnosticWasFiltered = false; | 1499 lastDiagnosticWasFiltered = false; |
| 1489 reportDiagnostic(message, infos, kind); | 1500 reportDiagnostic(message, infos, kind); |
| 1490 } | 1501 } |
| 1491 | 1502 |
| 1492 void reportDiagnostic(DiagnosticMessage message, | 1503 void reportDiagnostic(DiagnosticMessage message, |
| 1493 List<DiagnosticMessage> infos, api.Diagnostic kind) { | 1504 List<DiagnosticMessage> infos, api.Diagnostic kind) { |
| 1494 compiler.reportDiagnostic(message, infos, kind); | 1505 compiler.reportDiagnostic(message, infos, kind); |
| 1495 if (kind == api.Diagnostic.ERROR || | 1506 if (kind == api.Diagnostic.ERROR || |
| 1496 kind == api.Diagnostic.CRASH || | 1507 kind == api.Diagnostic.CRASH || |
| 1497 (options.fatalWarnings && kind == api.Diagnostic.WARNING)) { | 1508 (options.fatalWarnings && kind == api.Diagnostic.WARNING)) { |
| 1509 Element errorElement; |
| 1510 if (message.spannable is Element) { |
| 1511 errorElement = message.spannable; |
| 1512 } else { |
| 1513 errorElement = currentElement; |
| 1514 } |
| 1515 compiler.registerCompiletimeError(errorElement, message); |
| 1498 compiler.fatalDiagnosticReported(message, infos, kind); | 1516 compiler.fatalDiagnosticReported(message, infos, kind); |
| 1499 } | 1517 } |
| 1500 } | 1518 } |
| 1501 | 1519 |
| 1502 /** | 1520 /** |
| 1503 * Perform an operation, [f], returning the return value from [f]. If an | 1521 * Perform an operation, [f], returning the return value from [f]. If an |
| 1504 * error occurs then report it as having occurred during compilation of | 1522 * error occurs then report it as having occurred during compilation of |
| 1505 * [element]. Can be nested. | 1523 * [element]. Can be nested. |
| 1506 */ | 1524 */ |
| 1507 withCurrentElement(Element element, f()) { | 1525 withCurrentElement(Element element, f()) { |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2029 _ElementScanner(this.scanner); | 2047 _ElementScanner(this.scanner); |
| 2030 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2048 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2031 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2049 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2032 } | 2050 } |
| 2033 | 2051 |
| 2034 class _EmptyEnvironment implements Environment { | 2052 class _EmptyEnvironment implements Environment { |
| 2035 const _EmptyEnvironment(); | 2053 const _EmptyEnvironment(); |
| 2036 | 2054 |
| 2037 String valueOf(String key) => null; | 2055 String valueOf(String key) => null; |
| 2038 } | 2056 } |
| OLD | NEW |