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 #ifndef TOOLS_GN_PARSE_TREE_H_ | 5 #ifndef TOOLS_GN_PARSE_TREE_H_ |
6 #define TOOLS_GN_PARSE_TREE_H_ | 6 #define TOOLS_GN_PARSE_TREE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "tools/gn/err.h" | 13 #include "tools/gn/err.h" |
14 #include "tools/gn/token.h" | 14 #include "tools/gn/token.h" |
15 #include "tools/gn/value.h" | 15 #include "tools/gn/value.h" |
16 | 16 |
17 class AccessorNode; | 17 class AccessorNode; |
18 class BinaryOpNode; | 18 class BinaryOpNode; |
19 class BlockNode; | 19 class BlockNode; |
20 class ConditionNode; | 20 class ConditionNode; |
21 class FunctionCallNode; | 21 class FunctionCallNode; |
22 class IdentifierNode; | 22 class IdentifierNode; |
23 class ListNode; | 23 class ListNode; |
24 class LiteralNode; | 24 class LiteralNode; |
25 class Scope; | 25 class Scope; |
26 class UnaryOpNode; | 26 class UnaryOpNode; |
| 27 class BlockCommentNode; |
27 | 28 |
28 class Comments { | 29 class Comments { |
29 public: | 30 public: |
30 Comments(); | 31 Comments(); |
31 virtual ~Comments(); | 32 virtual ~Comments(); |
32 | 33 |
33 const std::vector<Token>& before() const { return before_; } | 34 const std::vector<Token>& before() const { return before_; } |
34 void append_before(Token c) { | 35 void append_before(Token c) { |
35 before_.push_back(c); | 36 before_.push_back(c); |
36 } | 37 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 74 |
74 virtual const AccessorNode* AsAccessor() const; | 75 virtual const AccessorNode* AsAccessor() const; |
75 virtual const BinaryOpNode* AsBinaryOp() const; | 76 virtual const BinaryOpNode* AsBinaryOp() const; |
76 virtual const BlockNode* AsBlock() const; | 77 virtual const BlockNode* AsBlock() const; |
77 virtual const ConditionNode* AsConditionNode() const; | 78 virtual const ConditionNode* AsConditionNode() const; |
78 virtual const FunctionCallNode* AsFunctionCall() const; | 79 virtual const FunctionCallNode* AsFunctionCall() const; |
79 virtual const IdentifierNode* AsIdentifier() const; | 80 virtual const IdentifierNode* AsIdentifier() const; |
80 virtual const ListNode* AsList() const; | 81 virtual const ListNode* AsList() const; |
81 virtual const LiteralNode* AsLiteral() const; | 82 virtual const LiteralNode* AsLiteral() const; |
82 virtual const UnaryOpNode* AsUnaryOp() const; | 83 virtual const UnaryOpNode* AsUnaryOp() const; |
| 84 virtual const BlockCommentNode* AsBlockComment() const; |
83 | 85 |
84 virtual Value Execute(Scope* scope, Err* err) const = 0; | 86 virtual Value Execute(Scope* scope, Err* err) const = 0; |
85 | 87 |
86 virtual LocationRange GetRange() const = 0; | 88 virtual LocationRange GetRange() const = 0; |
87 | 89 |
88 // Returns an error with the given messages and the range set to something | 90 // Returns an error with the given messages and the range set to something |
89 // that indicates this node. | 91 // that indicates this node. |
90 virtual Err MakeErrorDescribing( | 92 virtual Err MakeErrorDescribing( |
91 const std::string& msg, | 93 const std::string& msg, |
92 const std::string& help = std::string()) const = 0; | 94 const std::string& help = std::string()) const = 0; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 operand_ = operand.Pass(); | 433 operand_ = operand.Pass(); |
432 } | 434 } |
433 | 435 |
434 private: | 436 private: |
435 Token op_; | 437 Token op_; |
436 scoped_ptr<ParseNode> operand_; | 438 scoped_ptr<ParseNode> operand_; |
437 | 439 |
438 DISALLOW_COPY_AND_ASSIGN(UnaryOpNode); | 440 DISALLOW_COPY_AND_ASSIGN(UnaryOpNode); |
439 }; | 441 }; |
440 | 442 |
| 443 // BlockCommentNode ------------------------------------------------------------ |
| 444 |
| 445 // This node type is only used for standalone comments (that is, those not |
| 446 // specifically attached to another syntax element. The most common of these |
| 447 // is a copyright header block. This node contains only the last line of such |
| 448 // a comment block as the anchor, and other lines of the block comment are |
| 449 // hung off of it as Before comments, similar to other syntax elements. |
| 450 class BlockCommentNode : public ParseNode { |
| 451 public: |
| 452 BlockCommentNode(); |
| 453 virtual ~BlockCommentNode(); |
| 454 |
| 455 virtual const BlockCommentNode* AsBlockComment() const OVERRIDE; |
| 456 virtual Value Execute(Scope* scope, Err* err) const OVERRIDE; |
| 457 virtual LocationRange GetRange() const OVERRIDE; |
| 458 virtual Err MakeErrorDescribing( |
| 459 const std::string& msg, |
| 460 const std::string& help = std::string()) const OVERRIDE; |
| 461 virtual void Print(std::ostream& out, int indent) const OVERRIDE; |
| 462 |
| 463 const Token& comment() const { return comment_; } |
| 464 void set_comment(const Token& t) { comment_ = t; } |
| 465 |
| 466 private: |
| 467 Token comment_; |
| 468 |
| 469 DISALLOW_COPY_AND_ASSIGN(BlockCommentNode); |
| 470 }; |
| 471 |
441 #endif // TOOLS_GN_PARSE_TREE_H_ | 472 #endif // TOOLS_GN_PARSE_TREE_H_ |
OLD | NEW |