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/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 29 matching lines...) Expand all Loading... | |
40 | 40 |
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 | 51 |
51 Comments* ParseNode::comments_mutable() { | 52 Comments* ParseNode::comments_mutable() { |
52 if (!comments_) | 53 if (!comments_) |
53 comments_.reset(new Comments); | 54 comments_.reset(new Comments); |
54 return comments_.get(); | 55 return comments_.get(); |
55 } | 56 } |
56 | 57 |
57 void ParseNode::PrintComments(std::ostream& out, int indent) const { | 58 void ParseNode::PrintComments(std::ostream& out, int indent) const { |
58 if (comments_) { | 59 if (comments_) { |
59 std::string ind = IndentFor(indent + 1); | 60 std::string ind = IndentFor(indent + 1); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 STLDeleteContainerPointers(contents_.begin(), contents_.end()); | 451 STLDeleteContainerPointers(contents_.begin(), contents_.end()); |
451 } | 452 } |
452 | 453 |
453 const ListNode* ListNode::AsList() const { | 454 const ListNode* ListNode::AsList() const { |
454 return this; | 455 return this; |
455 } | 456 } |
456 | 457 |
457 Value ListNode::Execute(Scope* scope, Err* err) const { | 458 Value ListNode::Execute(Scope* scope, Err* err) const { |
458 Value result_value(this, Value::LIST); | 459 Value result_value(this, Value::LIST); |
459 std::vector<Value>& results = result_value.list_value(); | 460 std::vector<Value>& results = result_value.list_value(); |
460 results.resize(contents_.size()); | 461 results.reserve(contents_.size()); |
461 | 462 |
462 for (size_t i = 0; i < contents_.size(); i++) { | 463 for (size_t i = 0; i < contents_.size(); i++) { |
463 const ParseNode* cur = contents_[i]; | 464 const ParseNode* cur = contents_[i]; |
464 results[i] = cur->Execute(scope, err); | 465 if (cur->AsBlockComment()) |
466 continue; | |
467 results.push_back(cur->Execute(scope, err)); | |
465 if (err->has_error()) | 468 if (err->has_error()) |
466 return Value(); | 469 return Value(); |
467 if (results[i].type() == Value::NONE) { | 470 if (results.back().type() == Value::NONE) { |
468 *err = cur->MakeErrorDescribing( | 471 *err = cur->MakeErrorDescribing( |
469 "This does not evaluate to a value.", | 472 "This does not evaluate to a value.", |
470 "I can't do something with nothing."); | 473 "I can't do something with nothing."); |
471 return Value(); | 474 return Value(); |
472 } | 475 } |
473 } | 476 } |
474 return result_value; | 477 return result_value; |
475 } | 478 } |
476 | 479 |
477 LocationRange ListNode::GetRange() const { | 480 LocationRange ListNode::GetRange() const { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 Err UnaryOpNode::MakeErrorDescribing(const std::string& msg, | 573 Err UnaryOpNode::MakeErrorDescribing(const std::string& msg, |
571 const std::string& help) const { | 574 const std::string& help) const { |
572 return Err(op_, msg, help); | 575 return Err(op_, msg, help); |
573 } | 576 } |
574 | 577 |
575 void UnaryOpNode::Print(std::ostream& out, int indent) const { | 578 void UnaryOpNode::Print(std::ostream& out, int indent) const { |
576 out << IndentFor(indent) << "UNARY(" << op_.value() << ")\n"; | 579 out << IndentFor(indent) << "UNARY(" << op_.value() << ")\n"; |
577 PrintComments(out, indent); | 580 PrintComments(out, indent); |
578 operand_->Print(out, indent + 1); | 581 operand_->Print(out, indent + 1); |
579 } | 582 } |
583 | |
584 // BlockCommentNode ------------------------------------------------------------ | |
585 | |
586 BlockCommentNode::BlockCommentNode() { | |
587 } | |
588 | |
589 BlockCommentNode::~BlockCommentNode() { | |
590 } | |
591 | |
592 const BlockCommentNode* BlockCommentNode::AsBlockComment() const { | |
593 return this; | |
594 } | |
595 | |
596 Value BlockCommentNode::Execute(Scope* scope, Err* err) const { | |
597 return Value(); | |
598 } | |
599 | |
600 LocationRange BlockCommentNode::GetRange() const { | |
601 return comment_.range(); | |
602 } | |
603 | |
604 Err BlockCommentNode::MakeErrorDescribing(const std::string& msg, | |
605 const std::string& help) const { | |
brettw
2014/09/25 22:11:32
indenting
scottmg
2014/09/25 23:03:11
Done.
| |
606 return Err(comment_, msg, help); | |
607 } | |
608 | |
609 void BlockCommentNode::Print(std::ostream& out, int indent) const { | |
610 out << IndentFor(indent) << "BLOCK_COMMENT(" << comment_.value() << ")\n"; | |
611 PrintComments(out, indent); | |
612 } | |
OLD | NEW |