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

Unified Diff: tools/gn/parse_tree.cc

Issue 607173002: gn format: fix comments at end of blocks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clang warning Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: tools/gn/parse_tree.cc
diff --git a/tools/gn/parse_tree.cc b/tools/gn/parse_tree.cc
index 35dccee9eb3cd0aef1a4029f83ca0a1223ac148f..6f5ead53bede5deac33dcbb969f2efb55adb0fbf 100644
--- a/tools/gn/parse_tree.cc
+++ b/tools/gn/parse_tree.cc
@@ -48,6 +48,7 @@ const ListNode* ParseNode::AsList() const { return NULL; }
const LiteralNode* ParseNode::AsLiteral() const { return NULL; }
const UnaryOpNode* ParseNode::AsUnaryOp() const { return NULL; }
const BlockCommentNode* ParseNode::AsBlockComment() const { return NULL; }
+const EndNode* ParseNode::AsEnd() const { return NULL; }
Comments* ParseNode::comments_mutable() {
if (!comments_)
@@ -263,8 +264,8 @@ Value BlockNode::Execute(Scope* containing_scope, Err* err) const {
LocationRange BlockNode::GetRange() const {
if (begin_token_.type() != Token::INVALID &&
- end_token_.type() != Token::INVALID) {
- return begin_token_.range().Union(end_token_.range());
+ end_->value().type() != Token::INVALID) {
+ return begin_token_.range().Union(end_->value().range());
} else if (!statements_.empty()) {
return statements_[0]->GetRange().Union(
statements_[statements_.size() - 1]->GetRange());
@@ -282,6 +283,8 @@ void BlockNode::Print(std::ostream& out, int indent) const {
PrintComments(out, indent);
for (size_t i = 0; i < statements_.size(); i++)
statements_[i]->Print(out, indent + 1);
+ if (end_ && end_->comments())
+ end_->Print(out, indent + 1);
}
Value BlockNode::ExecuteBlockInScope(Scope* our_scope, Err* err) const {
@@ -478,7 +481,8 @@ Value ListNode::Execute(Scope* scope, Err* err) const {
}
LocationRange ListNode::GetRange() const {
- return LocationRange(begin_token_.location(), end_token_.location());
+ return LocationRange(begin_token_.location(),
+ end_->value().location());
}
Err ListNode::MakeErrorDescribing(const std::string& msg,
@@ -491,6 +495,8 @@ void ListNode::Print(std::ostream& out, int indent) const {
PrintComments(out, indent);
for (size_t i = 0; i < contents_.size(); i++)
contents_[i]->Print(out, indent + 1);
+ if (end_ && end_->comments())
+ end_->Print(out, indent + 1);
}
// LiteralNode -----------------------------------------------------------------
@@ -610,3 +616,28 @@ void BlockCommentNode::Print(std::ostream& out, int indent) const {
out << IndentFor(indent) << "BLOCK_COMMENT(" << comment_.value() << ")\n";
PrintComments(out, indent);
}
+
+
+// EndNode ---------------------------------------------------------------------
+
+EndNode::EndNode() {
+}
+
+EndNode::EndNode(const Token& token) : IdentifierNode(token) {
+}
+
+EndNode::~EndNode() {
+}
+
+const IdentifierNode* EndNode::AsIdentifier() const {
+ return NULL;
+}
+
+const EndNode* EndNode::AsEnd() const {
+ return this;
+}
+
+void EndNode::Print(std::ostream& out, int indent) const {
+ out << IndentFor(indent) << "END(" << value().value() << ")\n";
+ PrintComments(out, indent);
+}
« tools/gn/parse_tree.h ('K') | « tools/gn/parse_tree.h ('k') | tools/gn/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698