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

Side by Side Diff: tools/gn/parse_tree.h

Issue 588893006: gn: attach comments to parse tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: x64 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
« no previous file with comments | « tools/gn/location.cc ('k') | tools/gn/parse_tree.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 27
28 class Comments {
29 public:
30 Comments();
31 virtual ~Comments();
32
33 const std::vector<Token>& before() const { return before_; }
34 void append_before(Token c) {
35 before_.push_back(c);
36 }
37
38 const std::vector<Token>& suffix() const { return suffix_; }
39 void append_suffix(Token c) {
40 suffix_.push_back(c);
41 }
42
43 const std::vector<Token>& after() const { return after_; }
44 void append_after(Token c) {
45 after_.push_back(c);
46 }
47
48 private:
49 // Whole line comments before the expression.
50 std::vector<Token> before_;
51
52 // End-of-line comments after this expression.
53 std::vector<Token> suffix_;
54
55 // For top-level expressions only, after_ lists whole-line comments
56 // following the expression.
57 std::vector<Token> after_;
58
59 DISALLOW_COPY_AND_ASSIGN(Comments);
60 };
61
28 // ParseNode ------------------------------------------------------------------- 62 // ParseNode -------------------------------------------------------------------
29 63
30 // A node in the AST. 64 // A node in the AST.
31 class ParseNode { 65 class ParseNode {
32 public: 66 public:
33 ParseNode(); 67 ParseNode();
34 virtual ~ParseNode(); 68 virtual ~ParseNode();
35 69
36 virtual const AccessorNode* AsAccessor() const; 70 virtual const AccessorNode* AsAccessor() const;
37 virtual const BinaryOpNode* AsBinaryOp() const; 71 virtual const BinaryOpNode* AsBinaryOp() const;
(...skipping 12 matching lines...) Expand all
50 // Returns an error with the given messages and the range set to something 84 // Returns an error with the given messages and the range set to something
51 // that indicates this node. 85 // that indicates this node.
52 virtual Err MakeErrorDescribing( 86 virtual Err MakeErrorDescribing(
53 const std::string& msg, 87 const std::string& msg,
54 const std::string& help = std::string()) const = 0; 88 const std::string& help = std::string()) const = 0;
55 89
56 // Prints a representation of this node to the given string, indenting 90 // Prints a representation of this node to the given string, indenting
57 // by the given number of spaces. 91 // by the given number of spaces.
58 virtual void Print(std::ostream& out, int indent) const = 0; 92 virtual void Print(std::ostream& out, int indent) const = 0;
59 93
94 const Comments* comments() const { return comments_.get(); }
95 Comments* comments_mutable();
96 void PrintComments(std::ostream& out, int indent) const;
97
60 private: 98 private:
99 scoped_ptr<Comments> comments_;
100
61 DISALLOW_COPY_AND_ASSIGN(ParseNode); 101 DISALLOW_COPY_AND_ASSIGN(ParseNode);
62 }; 102 };
63 103
64 // AccessorNode ---------------------------------------------------------------- 104 // AccessorNode ----------------------------------------------------------------
65 105
66 // Access an array or scope element. 106 // Access an array or scope element.
67 // 107 //
68 // Currently, such values are only read-only. In that you can do: 108 // Currently, such values are only read-only. In that you can do:
69 // a = obj1.a 109 // a = obj1.a
70 // b = obj2[0] 110 // b = obj2[0]
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 428 }
389 429
390 private: 430 private:
391 Token op_; 431 Token op_;
392 scoped_ptr<ParseNode> operand_; 432 scoped_ptr<ParseNode> operand_;
393 433
394 DISALLOW_COPY_AND_ASSIGN(UnaryOpNode); 434 DISALLOW_COPY_AND_ASSIGN(UnaryOpNode);
395 }; 435 };
396 436
397 #endif // TOOLS_GN_PARSE_TREE_H_ 437 #endif // TOOLS_GN_PARSE_TREE_H_
OLDNEW
« no previous file with comments | « tools/gn/location.cc ('k') | tools/gn/parse_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698