Chromium Code Reviews| 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 /// ----------------------------------------------------------------------- | 5 /// ----------------------------------------------------------------------- |
| 6 /// ERROR HANDLING | 6 /// ERROR HANDLING |
| 7 /// ----------------------------------------------------------------------- | 7 /// ----------------------------------------------------------------------- |
| 8 /// | 8 /// |
| 9 /// As a rule of thumb, errors that can be detected statically are handled by | 9 /// As a rule of thumb, errors that can be detected statically are handled by |
| 10 /// the frontend, typically by translating the erroneous code into a 'throw' or | 10 /// the frontend, typically by translating the erroneous code into a 'throw' or |
| (...skipping 3486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3497 } | 3497 } |
| 3498 | 3498 |
| 3499 // ------------------------------------------------------------------------ | 3499 // ------------------------------------------------------------------------ |
| 3500 // PROGRAM | 3500 // PROGRAM |
| 3501 // ------------------------------------------------------------------------ | 3501 // ------------------------------------------------------------------------ |
| 3502 | 3502 |
| 3503 /// A way to bundle up all the libraries in a program. | 3503 /// A way to bundle up all the libraries in a program. |
| 3504 class Program extends TreeNode { | 3504 class Program extends TreeNode { |
| 3505 final List<Library> libraries; | 3505 final List<Library> libraries; |
| 3506 | 3506 |
| 3507 /// Map from a source file uri to a line-starts table. | 3507 /// Map from a source file uri to a line-starts table and source code. |
| 3508 /// Given a source file uri and a offset in that file one can translate | 3508 /// Given a source file uri and a offset in that file one can translate |
| 3509 /// it to a line:column position in that file. | 3509 /// it to a line:column position in that file. |
| 3510 final Map<String, List<int>> uriToLineStarts; | 3510 final Map<String, LineStartsAndSource> uriToLineStartsAndSource; |
| 3511 | 3511 |
| 3512 /// Reference to the main method in one of the libraries. | 3512 /// Reference to the main method in one of the libraries. |
| 3513 Procedure mainMethod; | 3513 Procedure mainMethod; |
| 3514 | 3514 |
| 3515 Program([List<Library> libraries, Map<String, List<int>> uriToLineStarts]) | 3515 Program( |
| 3516 [List<Library> libraries, | |
| 3517 Map<String, LineStartsAndSource> uriToLineStartsAndSource]) | |
| 3516 : libraries = libraries ?? <Library>[], | 3518 : libraries = libraries ?? <Library>[], |
| 3517 uriToLineStarts = uriToLineStarts ?? {} { | 3519 uriToLineStartsAndSource = uriToLineStartsAndSource ?? {} { |
|
Kevin Millikin (Google)
2016/12/20 12:03:33
Should be <String, LineStartsAndSource>{}.
Can't
jensj
2016/12/20 13:30:22
In loader.dart we add to it. We only have it up-fr
| |
| 3518 setParents(libraries, this); | 3520 setParents(libraries, this); |
| 3519 } | 3521 } |
| 3520 | 3522 |
| 3521 accept(TreeVisitor v) => v.visitProgram(this); | 3523 accept(TreeVisitor v) => v.visitProgram(this); |
| 3522 | 3524 |
| 3523 visitChildren(Visitor v) { | 3525 visitChildren(Visitor v) { |
| 3524 visitList(libraries, v); | 3526 visitList(libraries, v); |
| 3525 mainMethod?.acceptReference(v); | 3527 mainMethod?.acceptReference(v); |
| 3526 } | 3528 } |
| 3527 | 3529 |
| 3528 transformChildren(Transformer v) { | 3530 transformChildren(Transformer v) { |
| 3529 transformList(libraries, v, this); | 3531 transformList(libraries, v, this); |
| 3530 } | 3532 } |
| 3531 | 3533 |
| 3532 Program get enclosingProgram => this; | 3534 Program get enclosingProgram => this; |
| 3533 | 3535 |
| 3534 /// Translates an offset to line and column numbers in the given file. | 3536 /// Translates an offset to line and column numbers in the given file. |
| 3535 Location getLocation(String file, int offset) { | 3537 Location getLocation(String file, int offset) { |
| 3536 List<int> lines = uriToLineStarts[file]; | 3538 List<int> lines = uriToLineStartsAndSource[file].lineStarts; |
| 3537 int low = 0, high = lines.length - 1; | 3539 int low = 0, high = lines.length - 1; |
| 3538 while (low < high) { | 3540 while (low < high) { |
| 3539 int mid = high - ((high - low) >> 1); // Get middle, rounding up. | 3541 int mid = high - ((high - low) >> 1); // Get middle, rounding up. |
| 3540 int pivot = lines[mid]; | 3542 int pivot = lines[mid]; |
| 3541 if (pivot <= offset) { | 3543 if (pivot <= offset) { |
| 3542 low = mid; | 3544 low = mid; |
| 3543 } else { | 3545 } else { |
| 3544 high = mid - 1; | 3546 high = mid - 1; |
| 3545 } | 3547 } |
| 3546 } | 3548 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3644 | 3646 |
| 3645 @override | 3647 @override |
| 3646 defaultTreeNode(TreeNode node) { | 3648 defaultTreeNode(TreeNode node) { |
| 3647 if (node == child) { | 3649 if (node == child) { |
| 3648 return replacement; | 3650 return replacement; |
| 3649 } else { | 3651 } else { |
| 3650 return node; | 3652 return node; |
| 3651 } | 3653 } |
| 3652 } | 3654 } |
| 3653 } | 3655 } |
| 3656 | |
| 3657 class LineStartsAndSource { | |
|
Kevin Millikin (Google)
2016/12/20 12:03:33
I would just call this "Source", not describe the
jensj
2016/12/20 13:30:22
Done.
| |
| 3658 final List<int> lineStarts; | |
| 3659 final String source; | |
| 3660 | |
| 3661 LineStartsAndSource(this.lineStarts, this.source); | |
| 3662 } | |
| OLD | NEW |