Chromium Code Reviews| 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 class WorkItem { | 5 class WorkItem { |
| 6 final Element element; | 6 final Element element; |
| 7 TreeElements resolutionTree; | 7 TreeElements resolutionTree; |
| 8 Function run; | 8 Function run; |
| 9 Map<int, BailoutInfo> bailouts = null; | 9 Map<int, BailoutInfo> bailouts = null; |
| 10 bool allowSpeculativeOptimization = true; | 10 bool allowSpeculativeOptimization = true; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 } | 118 } |
| 119 | 119 |
| 120 void internalError(String message, | 120 void internalError(String message, |
| 121 [Node node, Token token, HInstruction instruction, | 121 [Node node, Token token, HInstruction instruction, |
| 122 Element element]) { | 122 Element element]) { |
| 123 cancel("Internal Error: $message", node, token, instruction, element); | 123 cancel("Internal Error: $message", node, token, instruction, element); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void cancel([String reason, Node node, Token token, | 126 void cancel([String reason, Node node, Token token, |
| 127 HInstruction instruction, Element element]) { | 127 HInstruction instruction, Element element]) { |
| 128 SourceSpan span = const SourceSpan(null, null, null); | |
| 129 if (node !== null) { | |
| 130 span = spanFromNode(node); | |
| 131 } else if (token !== null) { | |
| 132 span = spanFromToken(token); | |
| 133 } else if (instruction !== null) { | |
| 134 span = spanFromElement(currentElement); | |
| 135 } else if (element !== null) { | |
| 136 span = spanFromElement(element); | |
| 137 } | |
| 138 reportDiagnostic(span.uri, span.begin, span.end, reason, true); | |
|
kasperl
2012/03/09 09:59:00
Maybe have a way of reporting diagnostics given a
ahe
2012/03/10 00:08:19
I like that better. Will do.
| |
| 128 throw new CompilerCancelledException(reason); | 139 throw new CompilerCancelledException(reason); |
| 129 } | 140 } |
| 130 | 141 |
| 131 void log(message) { | 142 void log(message) { |
| 132 // Do nothing. | 143 reportDiagnostic(null, null, null, message, false); |
| 133 } | 144 } |
| 134 | 145 |
| 135 void enqueue(WorkItem work) { | 146 void enqueue(WorkItem work) { |
| 136 worklist.add(work); | 147 worklist.add(work); |
| 137 } | 148 } |
| 138 | 149 |
| 139 bool run(Uri uri) { | 150 bool run(Uri uri) { |
| 140 try { | 151 try { |
| 141 runCompiler(uri); | 152 runCompiler(uri); |
| 142 } catch (CompilerCancelledException exception) { | 153 } catch (CompilerCancelledException exception) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 () => resolver.resolveSignature(element)); | 370 () => resolver.resolveSignature(element)); |
| 360 } | 371 } |
| 361 | 372 |
| 362 Object compileVariable(VariableElement element) { | 373 Object compileVariable(VariableElement element) { |
| 363 return withCurrentElement(element, () { | 374 return withCurrentElement(element, () { |
| 364 compile(new WorkItem.toCompile(element)); | 375 compile(new WorkItem.toCompile(element)); |
| 365 return constantHandler.compileVariable(element); | 376 return constantHandler.compileVariable(element); |
| 366 }); | 377 }); |
| 367 } | 378 } |
| 368 | 379 |
| 369 reportWarning(Node node, var message) {} | 380 reportWarning(Node node, var message) { |
| 381 SourceSpan span = spanFromNode(node); | |
| 382 reportDiagnostic(span.uri, span.begin, span.end, message.toString(), false); | |
| 383 } | |
| 370 | 384 |
| 371 reportError(Node node, var message) => cancel(message.toString(), node: node); | 385 reportError(Node node, var message) { |
| 386 SourceSpan span = spanFromNode(node); | |
| 387 reportDiagnostic(span.uri, span.begin, span.end, message.toString(), true); | |
| 388 throw new CompilerCancelledException(reason); | |
| 389 } | |
| 390 | |
| 391 abstract void reportDiagnostic(Uri uri, int begin, int end, | |
| 392 String message, bool fatal); | |
| 393 | |
| 394 SourceSpan spanFromTokens(Token begin, Token end) { | |
| 395 if (begin === null || end === null) { | |
| 396 throw 'cannot find tokens to produce error message'; | |
| 397 } | |
| 398 final startOffset = begin.charOffset; | |
| 399 // TODO(ahe): Compute proper end offset. | |
| 400 final endOffset = end.next.charOffset - 1; | |
| 401 Uri uri = currentElement.getCompilationUnit().script.uri; | |
| 402 return new SourceSpan(uri, startOffset, endOffset); | |
| 403 } | |
| 404 | |
| 405 SourceSpan spanFromNode(Node node) { | |
| 406 return spanFromTokens(node.getBeginToken(), node.getEndToken()); | |
| 407 } | |
| 408 | |
| 409 SourceSpan spanFromElement(Element element) { | |
| 410 if (element.position() === null) { | |
| 411 // Sometimes, the backend fakes up elements that have no | |
| 412 // position. So we use the enclosing element instead. It is | |
| 413 // not a good error location, but cancel really is "internal | |
| 414 // error" or "not implemented yet", so the vicinity is good | |
| 415 // enough for now. | |
| 416 element = element.enclosingElement; | |
| 417 // TODO(ahe): I plan to overhaul this infrastructure anyways. | |
| 418 } | |
| 419 if (element === null) { | |
| 420 element = currentElement; | |
| 421 } | |
| 422 Token position = element.position(); | |
| 423 if (position === null) { | |
| 424 // TODO(ahe): Find the enclosing library. | |
| 425 return const SourceSpan(null, null, null); | |
| 426 } | |
| 427 return spanFromTokens(position, position); | |
| 428 } | |
| 372 | 429 |
| 373 Script readScript(Uri uri, [ScriptTag node]) { | 430 Script readScript(Uri uri, [ScriptTag node]) { |
| 374 unimplemented('Compiler.readScript'); | 431 unimplemented('Compiler.readScript'); |
| 375 } | 432 } |
| 376 | 433 |
| 377 String get legDirectory() { | 434 String get legDirectory() { |
| 378 unimplemented('Compiler.legDirectory'); | 435 unimplemented('Compiler.legDirectory'); |
| 379 } | 436 } |
| 380 | 437 |
| 381 Element findHelper(SourceString name) => jsHelperLibrary.find(name); | 438 Element findHelper(SourceString name) => jsHelperLibrary.find(name); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 | 480 |
| 424 // TODO(ahe): Remove when the VM supports implicit interfaces. | 481 // TODO(ahe): Remove when the VM supports implicit interfaces. |
| 425 class LTracer implements Tracer { | 482 class LTracer implements Tracer { |
| 426 const LTracer(); | 483 const LTracer(); |
| 427 final bool enabled = false; | 484 final bool enabled = false; |
| 428 void traceGraph(String name, var graph) { | 485 void traceGraph(String name, var graph) { |
| 429 } | 486 } |
| 430 void close() { | 487 void close() { |
| 431 } | 488 } |
| 432 } | 489 } |
| 490 | |
| 491 class SourceSpan { | |
| 492 final Uri uri; | |
| 493 final int begin; | |
| 494 final int end; | |
| 495 | |
| 496 const SourceSpan(this.uri, this.begin, this.end); | |
| 497 } | |
| OLD | NEW |