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

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: review 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
« no previous file with comments | « tools/gn/parse_tree.h ('k') | tools/gn/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/parse_tree.cc
diff --git a/tools/gn/parse_tree.cc b/tools/gn/parse_tree.cc
index 35dccee9eb3cd0aef1a4029f83ca0a1223ac148f..f2ddb1cd66429e3bc7fa3368205778bda16d3ac8 100644
--- a/tools/gn/parse_tree.cc
+++ b/tools/gn/parse_tree.cc
@@ -40,14 +40,15 @@ ParseNode::~ParseNode() {
const AccessorNode* ParseNode::AsAccessor() const { return NULL; }
const BinaryOpNode* ParseNode::AsBinaryOp() const { return NULL; }
+const BlockCommentNode* ParseNode::AsBlockComment() const { return NULL; }
const BlockNode* ParseNode::AsBlock() const { return NULL; }
const ConditionNode* ParseNode::AsConditionNode() const { return NULL; }
+const EndNode* ParseNode::AsEnd() const { return NULL; }
const FunctionCallNode* ParseNode::AsFunctionCall() const { return NULL; }
const IdentifierNode* ParseNode::AsIdentifier() const { return NULL; }
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; }
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,34 @@ void BlockCommentNode::Print(std::ostream& out, int indent) const {
out << IndentFor(indent) << "BLOCK_COMMENT(" << comment_.value() << ")\n";
PrintComments(out, indent);
}
+
+
+// EndNode ---------------------------------------------------------------------
+
+EndNode::EndNode(const Token& token) : value_(token) {
+}
+
+EndNode::~EndNode() {
+}
+
+const EndNode* EndNode::AsEnd() const {
+ return this;
+}
+
+Value EndNode::Execute(Scope* scope, Err* err) const {
+ return Value();
+}
+
+LocationRange EndNode::GetRange() const {
+ return value_.range();
+}
+
+Err EndNode::MakeErrorDescribing(const std::string& msg,
+ const std::string& help) const {
+ return Err(value_, msg, help);
+}
+
+void EndNode::Print(std::ostream& out, int indent) const {
+ out << IndentFor(indent) << "END(" << value_.value() << ")\n";
+ PrintComments(out, indent);
+}
« no previous file with comments | « 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