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

Side by Side Diff: tools/gn/parser.cc

Issue 2556613002: gn: Fix stale references in Parser::AssignComments(). (Closed)
Patch Set: Created 4 years 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 | « no previous file | no next file » | 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) 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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 // Assign suffix to syntax immediately before. 844 // Assign suffix to syntax immediately before.
845 cur_comment = static_cast<int>(suffix_comment_tokens_.size() - 1); 845 cur_comment = static_cast<int>(suffix_comment_tokens_.size() - 1);
846 for (std::vector<const ParseNode*>::const_reverse_iterator i = post.rbegin(); 846 for (std::vector<const ParseNode*>::const_reverse_iterator i = post.rbegin();
847 i != post.rend(); 847 i != post.rend();
848 ++i) { 848 ++i) {
849 // Don't assign suffix comments to the function, list, or block, but instead 849 // Don't assign suffix comments to the function, list, or block, but instead
850 // to the last thing inside. 850 // to the last thing inside.
851 if ((*i)->AsFunctionCall() || (*i)->AsList() || (*i)->AsBlock()) 851 if ((*i)->AsFunctionCall() || (*i)->AsList() || (*i)->AsBlock())
852 continue; 852 continue;
853 853
854 const Location& start = (*i)->GetRange().begin(); 854 Location start = (*i)->GetRange().begin();
855 const Location& end = (*i)->GetRange().end(); 855 Location end = (*i)->GetRange().end();
856 856
857 // Don't assign suffix comments to something that starts on an earlier 857 // Don't assign suffix comments to something that starts on an earlier
858 // line, so that in: 858 // line, so that in:
859 // 859 //
860 // sources = [ "a", 860 // sources = [ "a",
861 // "b" ] # comment 861 // "b" ] # comment
862 // 862 //
863 // it's attached to "b", not sources = [ ... ]. 863 // it's attached to "b", not sources = [ ... ].
864 if (start.line_number() != end.line_number()) 864 if (start.line_number() != end.line_number())
865 continue; 865 continue;
866 866
867 while (cur_comment >= 0) { 867 while (cur_comment >= 0) {
868 if (end.byte() <= suffix_comment_tokens_[cur_comment].location().byte()) { 868 if (end.byte() <= suffix_comment_tokens_[cur_comment].location().byte()) {
869 const_cast<ParseNode*>(*i)->comments_mutable()->append_suffix( 869 const_cast<ParseNode*>(*i)->comments_mutable()->append_suffix(
870 suffix_comment_tokens_[cur_comment]); 870 suffix_comment_tokens_[cur_comment]);
871 --cur_comment; 871 --cur_comment;
872 } else { 872 } else {
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698