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

Side by Side Diff: dart/frog/leg/compiler.dart

Issue 9646030: Find diagnostic locations for use in new compiler API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix crashes and address review comments Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « dart/frog/leg/apiimpl.dart ('k') | dart/frog/leg/elements/elements.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 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
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
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 throw 'cannot find tokens to produce error message';
ngeoffray 2012/03/10 10:36:58 Should that be return const SourceSpan(null, null,
ahe 2012/03/10 10:50:58 I'm really torn about this. It really is an intern
396 }
397 final startOffset = begin.charOffset;
398 // TODO(ahe): Compute proper end offset.
399 final endOffset =
400 (end.next !== null) ? end.next.charOffset - 1 : startOffset + 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
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 }
OLDNEW
« no previous file with comments | « dart/frog/leg/apiimpl.dart ('k') | dart/frog/leg/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698