OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.messages; | 5 library fasta.messages; |
6 | 6 |
7 import 'package:kernel/ast.dart' show Location; | 7 import 'package:kernel/ast.dart' show Library, Location, Program, TreeNode; |
8 | 8 |
9 import 'util/relativize.dart' show relativizeUri; | 9 import 'util/relativize.dart' show relativizeUri; |
10 | 10 |
11 import 'compiler_context.dart' show CompilerContext; | 11 import 'compiler_context.dart' show CompilerContext; |
12 | 12 |
13 import 'errors.dart' show InputError; | 13 import 'errors.dart' show InputError; |
14 | 14 |
15 import 'colors.dart' show cyan, magenta; | 15 import 'colors.dart' show cyan, magenta; |
16 | 16 |
17 const bool hideWarnings = false; | 17 const bool hideWarnings = false; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (charOffset == -1) return null; | 85 if (charOffset == -1) return null; |
86 String path = relativizeUri(uri); | 86 String path = relativizeUri(uri); |
87 return getLocation(path, charOffset); | 87 return getLocation(path, charOffset); |
88 } | 88 } |
89 | 89 |
90 String getSourceLine(Location location) { | 90 String getSourceLine(Location location) { |
91 if (location == null) return null; | 91 if (location == null) return null; |
92 return CompilerContext.current.uriToSource[location.file] | 92 return CompilerContext.current.uriToSource[location.file] |
93 ?.getTextLine(location.line); | 93 ?.getTextLine(location.line); |
94 } | 94 } |
| 95 |
| 96 Location getLocationFromNode(TreeNode node) { |
| 97 if (node.enclosingProgram == null) { |
| 98 TreeNode parent = node; |
| 99 while (parent != null && parent is! Library) { |
| 100 parent = parent.parent; |
| 101 } |
| 102 if (parent is Library) { |
| 103 Program program = |
| 104 new Program(uriToSource: CompilerContext.current.uriToSource); |
| 105 program.libraries.add(parent); |
| 106 parent.parent = program; |
| 107 Location result = node.location; |
| 108 program.libraries.clear(); |
| 109 parent.parent = null; |
| 110 return result; |
| 111 } else { |
| 112 return null; |
| 113 } |
| 114 } else { |
| 115 return node.location; |
| 116 } |
| 117 } |
OLD | NEW |