OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/parser.h" | 5 #include "tools/gn/parser.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 std::vector<const ParseNode*> post; | 817 std::vector<const ParseNode*> post; |
818 TraverseOrder(file, &pre, &post); | 818 TraverseOrder(file, &pre, &post); |
819 | 819 |
820 // Assign line comments to syntax immediately following. | 820 // Assign line comments to syntax immediately following. |
821 int cur_comment = 0; | 821 int cur_comment = 0; |
822 for (auto* node : pre) { | 822 for (auto* node : pre) { |
823 if (node->GetRange().is_null()) { | 823 if (node->GetRange().is_null()) { |
824 CHECK_EQ(node, file) << "Only expected on top file node"; | 824 CHECK_EQ(node, file) << "Only expected on top file node"; |
825 continue; | 825 continue; |
826 } | 826 } |
827 const Location& start = node->GetRange().begin(); | 827 const Location start = node->GetRange().begin(); |
828 while (cur_comment < static_cast<int>(line_comment_tokens_.size())) { | 828 while (cur_comment < static_cast<int>(line_comment_tokens_.size())) { |
829 if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) { | 829 if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) { |
830 const_cast<ParseNode*>(node)->comments_mutable()->append_before( | 830 const_cast<ParseNode*>(node)->comments_mutable()->append_before( |
831 line_comment_tokens_[cur_comment]); | 831 line_comment_tokens_[cur_comment]); |
832 ++cur_comment; | 832 ++cur_comment; |
833 } else { | 833 } else { |
834 break; | 834 break; |
835 } | 835 } |
836 } | 836 } |
837 } | 837 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 break; | 873 break; |
874 } | 874 } |
875 } | 875 } |
876 | 876 |
877 // Suffix comments were assigned in reverse, so if there were multiple on | 877 // Suffix comments were assigned in reverse, so if there were multiple on |
878 // the same node, they need to be reversed. | 878 // the same node, they need to be reversed. |
879 if ((*i)->comments() && !(*i)->comments()->suffix().empty()) | 879 if ((*i)->comments() && !(*i)->comments()->suffix().empty()) |
880 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); | 880 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); |
881 } | 881 } |
882 } | 882 } |
OLD | NEW |