| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "tools/gn/functions.h" | 8 #include "tools/gn/functions.h" |
| 9 #include "tools/gn/operators.h" | 9 #include "tools/gn/operators.h" |
| 10 #include "tools/gn/token.h" | 10 #include "tools/gn/token.h" |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 TraverseOrder(file, &pre, &post); | 543 TraverseOrder(file, &pre, &post); |
| 544 | 544 |
| 545 // Assign line comments to syntax immediately following. | 545 // Assign line comments to syntax immediately following. |
| 546 int j = 0; | 546 int j = 0; |
| 547 for (std::vector<const ParseNode*>::const_iterator i = pre.begin(); | 547 for (std::vector<const ParseNode*>::const_iterator i = pre.begin(); |
| 548 i != pre.end(); | 548 i != pre.end(); |
| 549 ++i) { | 549 ++i) { |
| 550 const Location& start = (*i)->GetRange().begin(); | 550 const Location& start = (*i)->GetRange().begin(); |
| 551 while (j < static_cast<int>(line_comment_tokens_.size())) { | 551 while (j < static_cast<int>(line_comment_tokens_.size())) { |
| 552 if (start.byte() >= line_comment_tokens_[j].location().byte()) { | 552 if (start.byte() >= line_comment_tokens_[j].location().byte()) { |
| 553 const_cast<ParseNode*>((*i))->comments_mutable()->append_before( | 553 const_cast<ParseNode*>(*i)->comments_mutable()->append_before( |
| 554 line_comment_tokens_[j]); | 554 line_comment_tokens_[j]); |
| 555 ++j; | 555 ++j; |
| 556 } else { | 556 } else { |
| 557 break; | 557 break; |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 } | 560 } |
| 561 | 561 |
| 562 // Remaining line comments go at end of file. | 562 // Remaining line comments go at end of file. |
| 563 for (; j < static_cast<int>(line_comment_tokens_.size()); ++j) | 563 for (; j < static_cast<int>(line_comment_tokens_.size()); ++j) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 581 // | 581 // |
| 582 // sources = [ "a", | 582 // sources = [ "a", |
| 583 // "b" ] # comment | 583 // "b" ] # comment |
| 584 // | 584 // |
| 585 // it's attached to "b", not sources = [ ... ]. | 585 // it's attached to "b", not sources = [ ... ]. |
| 586 if (start.line_number() != end.line_number()) | 586 if (start.line_number() != end.line_number()) |
| 587 continue; | 587 continue; |
| 588 | 588 |
| 589 while (j >= 0) { | 589 while (j >= 0) { |
| 590 if (end.byte() <= suffix_comment_tokens_[j].location().byte()) { | 590 if (end.byte() <= suffix_comment_tokens_[j].location().byte()) { |
| 591 const_cast<ParseNode*>((*i))->comments_mutable()->append_suffix( | 591 const_cast<ParseNode*>(*i)->comments_mutable()->append_suffix( |
| 592 suffix_comment_tokens_[j]); | 592 suffix_comment_tokens_[j]); |
| 593 --j; | 593 --j; |
| 594 } else { | 594 } else { |
| 595 break; | 595 break; |
| 596 } | 596 } |
| 597 } | 597 } |
| 598 |
| 599 // Suffix comments were assigned in reverse, so if there were multiple on |
| 600 // the same node, they need to be reversed. |
| 601 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); |
| 598 } | 602 } |
| 599 } | 603 } |
| OLD | NEW |