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

Side by Side 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, 2 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 unified diff | Download patch
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/parse_tree.h" 5 #include "tools/gn/parse_tree.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 30 matching lines...) Expand all
41 const AccessorNode* ParseNode::AsAccessor() const { return NULL; } 41 const AccessorNode* ParseNode::AsAccessor() const { return NULL; }
42 const BinaryOpNode* ParseNode::AsBinaryOp() const { return NULL; } 42 const BinaryOpNode* ParseNode::AsBinaryOp() const { return NULL; }
43 const BlockNode* ParseNode::AsBlock() const { return NULL; } 43 const BlockNode* ParseNode::AsBlock() const { return NULL; }
44 const ConditionNode* ParseNode::AsConditionNode() const { return NULL; } 44 const ConditionNode* ParseNode::AsConditionNode() const { return NULL; }
45 const FunctionCallNode* ParseNode::AsFunctionCall() const { return NULL; } 45 const FunctionCallNode* ParseNode::AsFunctionCall() const { return NULL; }
46 const IdentifierNode* ParseNode::AsIdentifier() const { return NULL; } 46 const IdentifierNode* ParseNode::AsIdentifier() const { return NULL; }
47 const ListNode* ParseNode::AsList() const { return NULL; } 47 const ListNode* ParseNode::AsList() const { return NULL; }
48 const LiteralNode* ParseNode::AsLiteral() const { return NULL; } 48 const LiteralNode* ParseNode::AsLiteral() const { return NULL; }
49 const UnaryOpNode* ParseNode::AsUnaryOp() const { return NULL; } 49 const UnaryOpNode* ParseNode::AsUnaryOp() const { return NULL; }
50 const BlockCommentNode* ParseNode::AsBlockComment() const { return NULL; } 50 const BlockCommentNode* ParseNode::AsBlockComment() const { return NULL; }
51 const EndNode* ParseNode::AsEnd() const { return NULL; }
51 52
52 Comments* ParseNode::comments_mutable() { 53 Comments* ParseNode::comments_mutable() {
53 if (!comments_) 54 if (!comments_)
54 comments_.reset(new Comments); 55 comments_.reset(new Comments);
55 return comments_.get(); 56 return comments_.get();
56 } 57 }
57 58
58 void ParseNode::PrintComments(std::ostream& out, int indent) const { 59 void ParseNode::PrintComments(std::ostream& out, int indent) const {
59 if (comments_) { 60 if (comments_) {
60 std::string ind = IndentFor(indent + 1); 61 std::string ind = IndentFor(indent + 1);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 257
257 // Check for unused vars in the scope. 258 // Check for unused vars in the scope.
258 our_scope.CheckForUnusedVars(err); 259 our_scope.CheckForUnusedVars(err);
259 return ret; 260 return ret;
260 } 261 }
261 return ExecuteBlockInScope(containing_scope, err); 262 return ExecuteBlockInScope(containing_scope, err);
262 } 263 }
263 264
264 LocationRange BlockNode::GetRange() const { 265 LocationRange BlockNode::GetRange() const {
265 if (begin_token_.type() != Token::INVALID && 266 if (begin_token_.type() != Token::INVALID &&
266 end_token_.type() != Token::INVALID) { 267 end_->value().type() != Token::INVALID) {
267 return begin_token_.range().Union(end_token_.range()); 268 return begin_token_.range().Union(end_->value().range());
268 } else if (!statements_.empty()) { 269 } else if (!statements_.empty()) {
269 return statements_[0]->GetRange().Union( 270 return statements_[0]->GetRange().Union(
270 statements_[statements_.size() - 1]->GetRange()); 271 statements_[statements_.size() - 1]->GetRange());
271 } 272 }
272 return LocationRange(); 273 return LocationRange();
273 } 274 }
274 275
275 Err BlockNode::MakeErrorDescribing(const std::string& msg, 276 Err BlockNode::MakeErrorDescribing(const std::string& msg,
276 const std::string& help) const { 277 const std::string& help) const {
277 return Err(GetRange(), msg, help); 278 return Err(GetRange(), msg, help);
278 } 279 }
279 280
280 void BlockNode::Print(std::ostream& out, int indent) const { 281 void BlockNode::Print(std::ostream& out, int indent) const {
281 out << IndentFor(indent) << "BLOCK\n"; 282 out << IndentFor(indent) << "BLOCK\n";
282 PrintComments(out, indent); 283 PrintComments(out, indent);
283 for (size_t i = 0; i < statements_.size(); i++) 284 for (size_t i = 0; i < statements_.size(); i++)
284 statements_[i]->Print(out, indent + 1); 285 statements_[i]->Print(out, indent + 1);
286 if (end_ && end_->comments())
287 end_->Print(out, indent + 1);
285 } 288 }
286 289
287 Value BlockNode::ExecuteBlockInScope(Scope* our_scope, Err* err) const { 290 Value BlockNode::ExecuteBlockInScope(Scope* our_scope, Err* err) const {
288 for (size_t i = 0; i < statements_.size() && !err->has_error(); i++) { 291 for (size_t i = 0; i < statements_.size() && !err->has_error(); i++) {
289 // Check for trying to execute things with no side effects in a block. 292 // Check for trying to execute things with no side effects in a block.
290 const ParseNode* cur = statements_[i]; 293 const ParseNode* cur = statements_[i];
291 if (cur->AsList() || cur->AsLiteral() || cur->AsUnaryOp() || 294 if (cur->AsList() || cur->AsLiteral() || cur->AsUnaryOp() ||
292 cur->AsIdentifier()) { 295 cur->AsIdentifier()) {
293 *err = cur->MakeErrorDescribing( 296 *err = cur->MakeErrorDescribing(
294 "This statement has no effect.", 297 "This statement has no effect.",
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 *err = cur->MakeErrorDescribing( 474 *err = cur->MakeErrorDescribing(
472 "This does not evaluate to a value.", 475 "This does not evaluate to a value.",
473 "I can't do something with nothing."); 476 "I can't do something with nothing.");
474 return Value(); 477 return Value();
475 } 478 }
476 } 479 }
477 return result_value; 480 return result_value;
478 } 481 }
479 482
480 LocationRange ListNode::GetRange() const { 483 LocationRange ListNode::GetRange() const {
481 return LocationRange(begin_token_.location(), end_token_.location()); 484 return LocationRange(begin_token_.location(),
485 end_->value().location());
482 } 486 }
483 487
484 Err ListNode::MakeErrorDescribing(const std::string& msg, 488 Err ListNode::MakeErrorDescribing(const std::string& msg,
485 const std::string& help) const { 489 const std::string& help) const {
486 return Err(begin_token_, msg, help); 490 return Err(begin_token_, msg, help);
487 } 491 }
488 492
489 void ListNode::Print(std::ostream& out, int indent) const { 493 void ListNode::Print(std::ostream& out, int indent) const {
490 out << IndentFor(indent) << "LIST\n"; 494 out << IndentFor(indent) << "LIST\n";
491 PrintComments(out, indent); 495 PrintComments(out, indent);
492 for (size_t i = 0; i < contents_.size(); i++) 496 for (size_t i = 0; i < contents_.size(); i++)
493 contents_[i]->Print(out, indent + 1); 497 contents_[i]->Print(out, indent + 1);
498 if (end_ && end_->comments())
499 end_->Print(out, indent + 1);
494 } 500 }
495 501
496 // LiteralNode ----------------------------------------------------------------- 502 // LiteralNode -----------------------------------------------------------------
497 503
498 LiteralNode::LiteralNode() { 504 LiteralNode::LiteralNode() {
499 } 505 }
500 506
501 LiteralNode::LiteralNode(const Token& token) : value_(token) { 507 LiteralNode::LiteralNode(const Token& token) : value_(token) {
502 } 508 }
503 509
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 609
604 Err BlockCommentNode::MakeErrorDescribing(const std::string& msg, 610 Err BlockCommentNode::MakeErrorDescribing(const std::string& msg,
605 const std::string& help) const { 611 const std::string& help) const {
606 return Err(comment_, msg, help); 612 return Err(comment_, msg, help);
607 } 613 }
608 614
609 void BlockCommentNode::Print(std::ostream& out, int indent) const { 615 void BlockCommentNode::Print(std::ostream& out, int indent) const {
610 out << IndentFor(indent) << "BLOCK_COMMENT(" << comment_.value() << ")\n"; 616 out << IndentFor(indent) << "BLOCK_COMMENT(" << comment_.value() << ")\n";
611 PrintComments(out, indent); 617 PrintComments(out, indent);
612 } 618 }
619
620
621 // EndNode ---------------------------------------------------------------------
622
623 EndNode::EndNode() {
624 }
625
626 EndNode::EndNode(const Token& token) : IdentifierNode(token) {
627 }
628
629 EndNode::~EndNode() {
630 }
631
632 const IdentifierNode* EndNode::AsIdentifier() const {
633 return NULL;
634 }
635
636 const EndNode* EndNode::AsEnd() const {
637 return this;
638 }
639
640 void EndNode::Print(std::ostream& out, int indent) const {
641 out << IndentFor(indent) << "END(" << value().value() << ")\n";
642 PrintComments(out, indent);
643 }
OLDNEW
« 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