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

Side by Side Diff: pkg/kernel/lib/ast.dart

Issue 2587673004: Include source in kernel. (Closed)
Patch Set: Fixed some rebase errors Created 3 years, 11 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
« no previous file with comments | « pkg/kernel/lib/analyzer/loader.dart ('k') | pkg/kernel/lib/binary/ast_from_binary.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) 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
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, Source> uriToSource;
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([List<Library> libraries, Map<String, Source> uriToSource])
3516 : libraries = libraries ?? <Library>[], 3516 : libraries = libraries ?? <Library>[],
3517 uriToLineStarts = uriToLineStarts ?? {} { 3517 uriToSource = uriToSource ?? <String, Source>{} {
3518 setParents(libraries, this); 3518 setParents(libraries, this);
3519 } 3519 }
3520 3520
3521 accept(TreeVisitor v) => v.visitProgram(this); 3521 accept(TreeVisitor v) => v.visitProgram(this);
3522 3522
3523 visitChildren(Visitor v) { 3523 visitChildren(Visitor v) {
3524 visitList(libraries, v); 3524 visitList(libraries, v);
3525 mainMethod?.acceptReference(v); 3525 mainMethod?.acceptReference(v);
3526 } 3526 }
3527 3527
3528 transformChildren(Transformer v) { 3528 transformChildren(Transformer v) {
3529 transformList(libraries, v, this); 3529 transformList(libraries, v, this);
3530 } 3530 }
3531 3531
3532 Program get enclosingProgram => this; 3532 Program get enclosingProgram => this;
3533 3533
3534 /// Translates an offset to line and column numbers in the given file. 3534 /// Translates an offset to line and column numbers in the given file.
3535 Location getLocation(String file, int offset) { 3535 Location getLocation(String file, int offset) {
3536 List<int> lines = uriToLineStarts[file]; 3536 List<int> lines = uriToSource[file].lineStarts;
3537 int low = 0, high = lines.length - 1; 3537 int low = 0, high = lines.length - 1;
3538 while (low < high) { 3538 while (low < high) {
3539 int mid = high - ((high - low) >> 1); // Get middle, rounding up. 3539 int mid = high - ((high - low) >> 1); // Get middle, rounding up.
3540 int pivot = lines[mid]; 3540 int pivot = lines[mid];
3541 if (pivot <= offset) { 3541 if (pivot <= offset) {
3542 low = mid; 3542 low = mid;
3543 } else { 3543 } else {
3544 high = mid - 1; 3544 high = mid - 1;
3545 } 3545 }
3546 } 3546 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3644 3644
3645 @override 3645 @override
3646 defaultTreeNode(TreeNode node) { 3646 defaultTreeNode(TreeNode node) {
3647 if (node == child) { 3647 if (node == child) {
3648 return replacement; 3648 return replacement;
3649 } else { 3649 } else {
3650 return node; 3650 return node;
3651 } 3651 }
3652 } 3652 }
3653 } 3653 }
3654
3655 class Source {
3656 final List<int> lineStarts;
3657 final String source;
3658
3659 Source(this.lineStarts, this.source);
3660 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/analyzer/loader.dart ('k') | pkg/kernel/lib/binary/ast_from_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698