| 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 | 5 |
| 6 /** | 6 /** |
| 7 * If true, print a warning for each method that was resolved, but not | 7 * If true, print a warning for each method that was resolved, but not |
| 8 * compiled. | 8 * compiled. |
| 9 */ | 9 */ |
| 10 const bool REPORT_EXCESS_RESOLUTION = false; | 10 const bool REPORT_EXCESS_RESOLUTION = false; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 static const int PHASE_SCANNING = 0; | 188 static const int PHASE_SCANNING = 0; |
| 189 static const int PHASE_RESOLVING = 1; | 189 static const int PHASE_RESOLVING = 1; |
| 190 static const int PHASE_COMPILING = 2; | 190 static const int PHASE_COMPILING = 2; |
| 191 int phase; | 191 int phase; |
| 192 | 192 |
| 193 bool compilationFailed = false; | 193 bool compilationFailed = false; |
| 194 | 194 |
| 195 bool hasCrashed = false; | 195 bool hasCrashed = false; |
| 196 | 196 |
| 197 Compiler([this.tracer = const Tracer(), | 197 Compiler({this.tracer: const Tracer(), |
| 198 this.enableTypeAssertions = false, | 198 this.enableTypeAssertions: false, |
| 199 this.enableUserAssertions = false, | 199 this.enableUserAssertions: false, |
| 200 this.enableConcreteTypeInference = false, | 200 this.enableConcreteTypeInference: false, |
| 201 this.enableMinification = false, | 201 this.enableMinification: false, |
| 202 bool emitJavaScript = true, | 202 bool emitJavaScript: true, |
| 203 bool generateSourceMap = true, | 203 bool generateSourceMap: true, |
| 204 List<String> strips = const []]) | 204 List<String> strips: const []}) |
| 205 : libraries = new Map<String, LibraryElement>(), | 205 : libraries = new Map<String, LibraryElement>(), |
| 206 progress = new Stopwatch() { | 206 progress = new Stopwatch() { |
| 207 progress.start(); | 207 progress.start(); |
| 208 world = new World(this); | 208 world = new World(this); |
| 209 scanner = new ScannerTask(this); | 209 scanner = new ScannerTask(this); |
| 210 dietParser = new DietParserTask(this); | 210 dietParser = new DietParserTask(this); |
| 211 parser = new ParserTask(this); | 211 parser = new ParserTask(this); |
| 212 patchParser = new PatchParserTask(this); | 212 patchParser = new PatchParserTask(this); |
| 213 libraryLoader = new LibraryLoaderTask(this); | 213 libraryLoader = new LibraryLoaderTask(this); |
| 214 validator = new TreeValidatorTask(this); | 214 validator = new TreeValidatorTask(this); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 229 Universe get resolverWorld => enqueuer.resolution.universe; | 229 Universe get resolverWorld => enqueuer.resolution.universe; |
| 230 Universe get codegenWorld => enqueuer.codegen.universe; | 230 Universe get codegenWorld => enqueuer.codegen.universe; |
| 231 | 231 |
| 232 int getNextFreeClassId() => nextFreeClassId++; | 232 int getNextFreeClassId() => nextFreeClassId++; |
| 233 | 233 |
| 234 void ensure(bool condition) { | 234 void ensure(bool condition) { |
| 235 if (!condition) cancel('failed assertion in leg'); | 235 if (!condition) cancel('failed assertion in leg'); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void unimplemented(String methodName, | 238 void unimplemented(String methodName, |
| 239 [Node node, Token token, HInstruction instruction, | 239 {Node node, Token token, HInstruction instruction, |
| 240 Element element]) { | 240 Element element}) { |
| 241 internalError("$methodName not implemented", | 241 internalError("$methodName not implemented", |
| 242 node, token, instruction, element); | 242 node: node, token: token, |
| 243 instruction: instruction, element: element); |
| 243 } | 244 } |
| 244 | 245 |
| 245 void internalError(String message, | 246 void internalError(String message, |
| 246 [Node node, Token token, HInstruction instruction, | 247 {Node node, Token token, HInstruction instruction, |
| 247 Element element]) { | 248 Element element}) { |
| 248 cancel('Internal error: $message', node, token, instruction, element); | 249 cancel('Internal error: $message', |
| 250 node: node, token: token, |
| 251 instruction: instruction, element: element); |
| 249 } | 252 } |
| 250 | 253 |
| 251 void internalErrorOnElement(Element element, String message) { | 254 void internalErrorOnElement(Element element, String message) { |
| 252 internalError(message, element: element); | 255 internalError(message, element: element); |
| 253 } | 256 } |
| 254 | 257 |
| 255 void unhandledExceptionOnElement(Element element) { | 258 void unhandledExceptionOnElement(Element element) { |
| 256 if (hasCrashed) return; | 259 if (hasCrashed) return; |
| 257 hasCrashed = true; | 260 hasCrashed = true; |
| 258 reportDiagnostic(spanFromElement(element), | 261 reportDiagnostic(spanFromElement(element), |
| 259 MessageKind.COMPILER_CRASHED.error().toString(), | 262 MessageKind.COMPILER_CRASHED.error().toString(), |
| 260 api.Diagnostic.CRASH); | 263 api.Diagnostic.CRASH); |
| 261 print(MessageKind.PLEASE_REPORT_THE_CRASH.message([BUILD_ID])); | 264 print(MessageKind.PLEASE_REPORT_THE_CRASH.message([BUILD_ID])); |
| 262 } | 265 } |
| 263 | 266 |
| 264 void cancel([String reason, Node node, Token token, | 267 void cancel(String reason, {Node node, Token token, |
| 265 HInstruction instruction, Element element]) { | 268 HInstruction instruction, Element element}) { |
| 266 assembledCode = null; // Compilation failed. Make sure that we | 269 assembledCode = null; // Compilation failed. Make sure that we |
| 267 // don't return a bogus result. | 270 // don't return a bogus result. |
| 268 SourceSpan span = null; | 271 SourceSpan span = null; |
| 269 if (node !== null) { | 272 if (node !== null) { |
| 270 span = spanFromNode(node); | 273 span = spanFromNode(node); |
| 271 } else if (token !== null) { | 274 } else if (token !== null) { |
| 272 span = spanFromTokens(token, token); | 275 span = spanFromTokens(token, token); |
| 273 } else if (instruction !== null) { | 276 } else if (instruction !== null) { |
| 274 span = spanFromElement(currentElement); | 277 span = spanFromElement(currentElement); |
| 275 } else if (element !== null) { | 278 } else if (element !== null) { |
| 276 span = spanFromElement(element); | 279 span = spanFromElement(element); |
| 277 } else { | 280 } else { |
| 278 throw 'No error location for error: $reason'; | 281 throw 'No error location for error: $reason'; |
| 279 } | 282 } |
| 280 reportDiagnostic(span, reason, api.Diagnostic.ERROR); | 283 reportDiagnostic(span, reason, api.Diagnostic.ERROR); |
| 281 throw new CompilerCancelledException(reason); | 284 throw new CompilerCancelledException(reason); |
| 282 } | 285 } |
| 283 | 286 |
| 284 void reportFatalError(String reason, Element element, | 287 void reportFatalError(String reason, Element element, |
| 285 [Node node, Token token, HInstruction instruction]) { | 288 {Node node, Token token, HInstruction instruction}) { |
| 286 withCurrentElement(element, () { | 289 withCurrentElement(element, () { |
| 287 cancel(reason, node, token, instruction, element); | 290 cancel(reason, node: node, token: token, instruction: instruction, |
| 291 element: element); |
| 288 }); | 292 }); |
| 289 } | 293 } |
| 290 | 294 |
| 291 void log(message) { | 295 void log(message) { |
| 292 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); | 296 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); |
| 293 } | 297 } |
| 294 | 298 |
| 295 bool run(Uri uri) { | 299 bool run(Uri uri) { |
| 296 try { | 300 try { |
| 297 runCompiler(uri); | 301 runCompiler(uri); |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 855 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 852 // information on assertion errors. | 856 // information on assertion errors. |
| 853 if (condition is Function){ | 857 if (condition is Function){ |
| 854 condition = condition(); | 858 condition = condition(); |
| 855 } | 859 } |
| 856 if (!condition && message != null) { | 860 if (!condition && message != null) { |
| 857 print('assertion failed: $message'); | 861 print('assertion failed: $message'); |
| 858 } | 862 } |
| 859 return spannable != null && condition; | 863 return spannable != null && condition; |
| 860 } | 864 } |
| OLD | NEW |