| 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 = spanFromTokens(token, token); |
| 133 } else if (instruction !== null) { |
| 134 span = spanFromElement(currentElement); |
| 135 } else if (element !== null) { |
| 136 span = spanFromElement(element); |
| 137 } |
| 138 reportDiagnostic(span, reason, true); |
| 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, 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, 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, message.toString(), true); |
| 388 throw new CompilerCancelledException(message.toString()); |
| 389 } |
| 390 |
| 391 abstract void reportDiagnostic(SourceSpan span, String message, bool fatal); |
| 392 |
| 393 SourceSpan spanFromTokens(Token begin, Token end) { |
| 394 if (begin === null || end === null) { |
| 395 // TODO(ahe): We can almost always do better. Often it is only |
| 396 // end that is null. Otherwise, we probably know the current |
| 397 // URI. |
| 398 throw 'cannot find tokens to produce error message'; |
| 399 } |
| 400 final startOffset = begin.charOffset; |
| 401 // TODO(ahe): Compute proper end offset. |
| 402 final endOffset = |
| 403 (end.next !== null) ? end.next.charOffset - 1 : startOffset + 1; |
| 404 Uri uri = currentElement.getCompilationUnit().script.uri; |
| 405 return new SourceSpan(uri, startOffset, endOffset); |
| 406 } |
| 407 |
| 408 SourceSpan spanFromNode(Node node) { |
| 409 return spanFromTokens(node.getBeginToken(), node.getEndToken()); |
| 410 } |
| 411 |
| 412 SourceSpan spanFromElement(Element element) { |
| 413 if (element.position() === null) { |
| 414 // Sometimes, the backend fakes up elements that have no |
| 415 // position. So we use the enclosing element instead. It is |
| 416 // not a good error location, but cancel really is "internal |
| 417 // error" or "not implemented yet", so the vicinity is good |
| 418 // enough for now. |
| 419 element = element.enclosingElement; |
| 420 // TODO(ahe): I plan to overhaul this infrastructure anyways. |
| 421 } |
| 422 if (element === null) { |
| 423 element = currentElement; |
| 424 } |
| 425 Token position = element.position(); |
| 426 if (position === null) { |
| 427 // TODO(ahe): Find the enclosing library. |
| 428 return const SourceSpan(null, null, null); |
| 429 } |
| 430 return spanFromTokens(position, position); |
| 431 } |
| 372 | 432 |
| 373 Script readScript(Uri uri, [ScriptTag node]) { | 433 Script readScript(Uri uri, [ScriptTag node]) { |
| 374 unimplemented('Compiler.readScript'); | 434 unimplemented('Compiler.readScript'); |
| 375 } | 435 } |
| 376 | 436 |
| 377 String get legDirectory() { | 437 String get legDirectory() { |
| 378 unimplemented('Compiler.legDirectory'); | 438 unimplemented('Compiler.legDirectory'); |
| 379 } | 439 } |
| 380 | 440 |
| 381 Element findHelper(SourceString name) => jsHelperLibrary.find(name); | 441 Element findHelper(SourceString name) => jsHelperLibrary.find(name); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 483 |
| 424 // TODO(ahe): Remove when the VM supports implicit interfaces. | 484 // TODO(ahe): Remove when the VM supports implicit interfaces. |
| 425 class LTracer implements Tracer { | 485 class LTracer implements Tracer { |
| 426 const LTracer(); | 486 const LTracer(); |
| 427 final bool enabled = false; | 487 final bool enabled = false; |
| 428 void traceGraph(String name, var graph) { | 488 void traceGraph(String name, var graph) { |
| 429 } | 489 } |
| 430 void close() { | 490 void close() { |
| 431 } | 491 } |
| 432 } | 492 } |
| 493 |
| 494 class SourceSpan { |
| 495 final Uri uri; |
| 496 final int begin; |
| 497 final int end; |
| 498 |
| 499 const SourceSpan(this.uri, this.begin, this.end); |
| 500 } |
| OLD | NEW |