Chromium Code Reviews| Index: tools/gn/parse_tree.cc |
| diff --git a/tools/gn/parse_tree.cc b/tools/gn/parse_tree.cc |
| index c4f78b7ce0768f9f7e7d025d112e1e25c7c31930..fedb00433e9a658599ebb080703dced501f5015a 100644 |
| --- a/tools/gn/parse_tree.cc |
| +++ b/tools/gn/parse_tree.cc |
| @@ -16,14 +16,17 @@ |
| namespace { |
| std::string IndentFor(int value) { |
| - std::string ret; |
| - for (int i = 0; i < value; i++) |
| - ret.append(" "); |
| - return ret; |
| + return std::string(value, ' '); |
| } |
| } // namespace |
| +Comments::Comments() { |
| +} |
| + |
| +Comments::~Comments() { |
| +} |
| + |
| ParseNode::ParseNode() { |
| } |
| @@ -40,6 +43,24 @@ const ListNode* ParseNode::AsList() const { return NULL; } |
| const LiteralNode* ParseNode::AsLiteral() const { return NULL; } |
| const UnaryOpNode* ParseNode::AsUnaryOp() const { return NULL; } |
| +Comments* ParseNode::comments_mutable() { |
| + if (!comments_) |
| + comments_.reset(new Comments); |
| + return comments_.get(); |
| +} |
| + |
| +void ParseNode::PrintComments(std::ostream& out, int indent) const { |
| + if (comments_) { |
| + std::string ind = IndentFor(indent + 1); |
| + for (const auto& i : comments_->before()) |
|
brettw
2014/09/23 21:33:15
This is technically on the list of stuff "to be di
scottmg
2014/09/23 22:15:37
Done.
|
| + out << ind << "+BEFORE_COMMENT(\"" << i.value() << "\")\n"; |
| + for (const auto& i : comments_->suffix()) |
| + out << ind << "+SUFFIX_COMMENT(\"" << i.value() << "\")\n"; |
| + for (const auto& i : comments_->after()) |
| + out << ind << "+AFTER_COMMENT(\"" << i.value() << "\")\n"; |
| + } |
| +} |
| + |
| // AccessorNode --------------------------------------------------------------- |
| AccessorNode::AccessorNode() { |
| @@ -77,6 +98,7 @@ Err AccessorNode::MakeErrorDescribing(const std::string& msg, |
| void AccessorNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "ACCESSOR\n"; |
| + PrintComments(out, indent); |
| out << IndentFor(indent + 1) << base_.value() << "\n"; |
| if (index_) |
| index_->Print(out, indent + 1); |
| @@ -192,6 +214,7 @@ Err BinaryOpNode::MakeErrorDescribing(const std::string& msg, |
| void BinaryOpNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "BINARY(" << op_.value() << ")\n"; |
| + PrintComments(out, indent); |
| left_->Print(out, indent + 1); |
| right_->Print(out, indent + 1); |
| } |
| @@ -241,6 +264,7 @@ Err BlockNode::MakeErrorDescribing(const std::string& msg, |
| void BlockNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "BLOCK\n"; |
| + PrintComments(out, indent); |
| for (size_t i = 0; i < statements_.size(); i++) |
| statements_[i]->Print(out, indent + 1); |
| } |
| @@ -317,6 +341,7 @@ Err ConditionNode::MakeErrorDescribing(const std::string& msg, |
| void ConditionNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "CONDITION\n"; |
| + PrintComments(out, indent); |
| condition_->Print(out, indent + 1); |
| if_true_->Print(out, indent + 1); |
| if (if_false_) |
| @@ -354,6 +379,7 @@ Err FunctionCallNode::MakeErrorDescribing(const std::string& msg, |
| void FunctionCallNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "FUNCTION(" << function_.value() << ")\n"; |
| + PrintComments(out, indent); |
| args_->Print(out, indent + 1); |
| if (block_) |
| block_->Print(out, indent + 1); |
| @@ -398,6 +424,7 @@ Err IdentifierNode::MakeErrorDescribing(const std::string& msg, |
| void IdentifierNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "IDENTIFIER(" << value_.value() << ")\n"; |
| + PrintComments(out, indent); |
| } |
| // ListNode ------------------------------------------------------------------- |
| @@ -444,6 +471,7 @@ Err ListNode::MakeErrorDescribing(const std::string& msg, |
| void ListNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "LIST\n"; |
| + PrintComments(out, indent); |
| for (size_t i = 0; i < contents_.size(); i++) |
| contents_[i]->Print(out, indent + 1); |
| } |
| @@ -499,6 +527,7 @@ Err LiteralNode::MakeErrorDescribing(const std::string& msg, |
| void LiteralNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "LITERAL(" << value_.value() << ")\n"; |
| + PrintComments(out, indent); |
| } |
| // UnaryOpNode ---------------------------------------------------------------- |
| @@ -531,5 +560,6 @@ Err UnaryOpNode::MakeErrorDescribing(const std::string& msg, |
| void UnaryOpNode::Print(std::ostream& out, int indent) const { |
| out << IndentFor(indent) << "UNARY(" << op_.value() << ")\n"; |
| + PrintComments(out, indent); |
| operand_->Print(out, indent + 1); |
| } |