| 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('frog_leg'); | 5 #library('frog_leg'); |
| 6 | 6 |
| 7 #import('../../lib/uri/uri.dart'); | 7 #import('../../lib/uri/uri.dart'); |
| 8 #import('../lang.dart', prefix: 'frog'); | 8 #import('../lang.dart', prefix: 'frog'); |
| 9 #import('elements/elements.dart'); | 9 #import('elements/elements.dart'); |
| 10 #import('io/io.dart', prefix: 'io'); | 10 #import('io/io.dart', prefix: 'io'); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return success; | 47 return success; |
| 48 } | 48 } |
| 49 | 49 |
| 50 spanFromNode(Node node, Script current) { | 50 spanFromNode(Node node, Script current) { |
| 51 final begin = node.getBeginToken(); | 51 final begin = node.getBeginToken(); |
| 52 final end = node.getEndToken(); | 52 final end = node.getEndToken(); |
| 53 if (begin === null || end === null) { | 53 if (begin === null || end === null) { |
| 54 cancel('cannot find tokens to produce error message for $node.'); | 54 cancel('cannot find tokens to produce error message for $node.'); |
| 55 } | 55 } |
| 56 final startOffset = begin.charOffset; | 56 final startOffset = begin.charOffset; |
| 57 final endOffset = end.charOffset + end.toString().length; | 57 // TODO(ahe): Compute proper end offset. |
| 58 final endOffset = end.charOffset + 1; |
| 58 return new frog.SourceSpan(current.file, startOffset, endOffset); | 59 return new frog.SourceSpan(current.file, startOffset, endOffset); |
| 59 } | 60 } |
| 60 | 61 |
| 61 currentScript() { | 62 currentScript() { |
| 62 if (currentElement === null) return null; | 63 if (currentElement === null) return null; |
| 63 CompilationUnitElement compilationUnit = | 64 CompilationUnitElement compilationUnit = |
| 64 currentElement.getCompilationUnit(); | 65 currentElement.getCompilationUnit(); |
| 65 if (compilationUnit === null) return null; | 66 if (compilationUnit === null) return null; |
| 66 return compilationUnit.script; | 67 return compilationUnit.script; |
| 67 } | 68 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 96 return new Script(uri, sourceFile); | 97 return new Script(uri, sourceFile); |
| 97 } | 98 } |
| 98 | 99 |
| 99 String get legDirectory() => io.join([frog.options.libDir, '..', 'leg']); | 100 String get legDirectory() => io.join([frog.options.libDir, '..', 'leg']); |
| 100 | 101 |
| 101 void cancel([String reason, Node node, token, instruction, element]) { | 102 void cancel([String reason, Node node, token, instruction, element]) { |
| 102 Script script = currentScript(); | 103 Script script = currentScript(); |
| 103 if (node !== null) { | 104 if (node !== null) { |
| 104 print(spanFromNode(node, script).toMessageString("cancel leg: $reason")); | 105 print(spanFromNode(node, script).toMessageString("cancel leg: $reason")); |
| 105 } else if (token !== null) { | 106 } else if (token !== null) { |
| 106 String tokenString = token.toString(); | |
| 107 int begin = token.charOffset; | 107 int begin = token.charOffset; |
| 108 int end = begin + tokenString.length; | 108 int end = begin + 1; // TODO(ahe): Compute proper length. |
| 109 print(script.file.getLocationMessage("cancel leg: $reason", | 109 print(script.file.getLocationMessage("cancel leg: $reason", |
| 110 begin, end, true)); | 110 begin, end, true)); |
| 111 } else if (element !== null) { | 111 } else if (element !== null) { |
| 112 if (element.position() === null) { | 112 if (element.position() === null) { |
| 113 // Sometimes, the backend fakes up elements that have no | 113 // Sometimes, the backend fakes up elements that have no |
| 114 // position. So we use the enclosing element instead. It is | 114 // position. So we use the enclosing element instead. It is |
| 115 // not a good error location, but cancel really is "internal | 115 // not a good error location, but cancel really is "internal |
| 116 // error" or "not implemented yet", so the vicinity is good | 116 // error" or "not implemented yet", so the vicinity is good |
| 117 // enough for now. | 117 // enough for now. |
| 118 element = element.enclosingElement; | 118 element = element.enclosingElement; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 131 } | 131 } |
| 132 super.cancel(reason, node, token, instruction); | 132 super.cancel(reason, node, token, instruction); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 class AbortLeg { | 136 class AbortLeg { |
| 137 final message; | 137 final message; |
| 138 AbortLeg(this.message); | 138 AbortLeg(this.message); |
| 139 toString() => 'Aborted due to --throw-on-error: $message'; | 139 toString() => 'Aborted due to --throw-on-error: $message'; |
| 140 } | 140 } |
| OLD | NEW |