| 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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 | 704 |
| 705 void Parser::AssignComments(ParseNode* file) { | 705 void Parser::AssignComments(ParseNode* file) { |
| 706 // Start by generating a pre- and post- order traversal of the tree so we | 706 // Start by generating a pre- and post- order traversal of the tree so we |
| 707 // can determine what's before and after comments. | 707 // can determine what's before and after comments. |
| 708 std::vector<const ParseNode*> pre; | 708 std::vector<const ParseNode*> pre; |
| 709 std::vector<const ParseNode*> post; | 709 std::vector<const ParseNode*> post; |
| 710 TraverseOrder(file, &pre, &post); | 710 TraverseOrder(file, &pre, &post); |
| 711 | 711 |
| 712 // Assign line comments to syntax immediately following. | 712 // Assign line comments to syntax immediately following. |
| 713 int cur_comment = 0; | 713 int cur_comment = 0; |
| 714 for (const auto& node : pre) { | 714 for (auto* node : pre) { |
| 715 const Location& start = node->GetRange().begin(); | 715 const Location& start = node->GetRange().begin(); |
| 716 while (cur_comment < static_cast<int>(line_comment_tokens_.size())) { | 716 while (cur_comment < static_cast<int>(line_comment_tokens_.size())) { |
| 717 if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) { | 717 if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) { |
| 718 const_cast<ParseNode*>(node)->comments_mutable()->append_before( | 718 const_cast<ParseNode*>(node)->comments_mutable()->append_before( |
| 719 line_comment_tokens_[cur_comment]); | 719 line_comment_tokens_[cur_comment]); |
| 720 ++cur_comment; | 720 ++cur_comment; |
| 721 } else { | 721 } else { |
| 722 break; | 722 break; |
| 723 } | 723 } |
| 724 } | 724 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 break; | 761 break; |
| 762 } | 762 } |
| 763 } | 763 } |
| 764 | 764 |
| 765 // Suffix comments were assigned in reverse, so if there were multiple on | 765 // Suffix comments were assigned in reverse, so if there were multiple on |
| 766 // the same node, they need to be reversed. | 766 // the same node, they need to be reversed. |
| 767 if ((*i)->comments() && !(*i)->comments()->suffix().empty()) | 767 if ((*i)->comments() && !(*i)->comments()->suffix().empty()) |
| 768 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); | 768 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); |
| 769 } | 769 } |
| 770 } | 770 } |
| OLD | NEW |