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

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

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
« no previous file with comments | « tools/gn/format_test_data/017.golden ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 class BlockCommentNode;
28 class EndNode;
brettw 2014/09/26 21:37:34 Can you sort this list?
scottmg 2014/09/26 21:47:32 Done.
28 29
29 class Comments { 30 class Comments {
30 public: 31 public:
31 Comments(); 32 Comments();
32 virtual ~Comments(); 33 virtual ~Comments();
33 34
34 const std::vector<Token>& before() const { return before_; } 35 const std::vector<Token>& before() const { return before_; }
35 void append_before(Token c) { 36 void append_before(Token c) {
36 before_.push_back(c); 37 before_.push_back(c);
37 } 38 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 virtual const AccessorNode* AsAccessor() const; 76 virtual const AccessorNode* AsAccessor() const;
76 virtual const BinaryOpNode* AsBinaryOp() const; 77 virtual const BinaryOpNode* AsBinaryOp() const;
77 virtual const BlockNode* AsBlock() const; 78 virtual const BlockNode* AsBlock() const;
78 virtual const ConditionNode* AsConditionNode() const; 79 virtual const ConditionNode* AsConditionNode() const;
79 virtual const FunctionCallNode* AsFunctionCall() const; 80 virtual const FunctionCallNode* AsFunctionCall() const;
80 virtual const IdentifierNode* AsIdentifier() const; 81 virtual const IdentifierNode* AsIdentifier() const;
81 virtual const ListNode* AsList() const; 82 virtual const ListNode* AsList() const;
82 virtual const LiteralNode* AsLiteral() const; 83 virtual const LiteralNode* AsLiteral() const;
83 virtual const UnaryOpNode* AsUnaryOp() const; 84 virtual const UnaryOpNode* AsUnaryOp() const;
84 virtual const BlockCommentNode* AsBlockComment() const; 85 virtual const BlockCommentNode* AsBlockComment() const;
86 virtual const EndNode* AsEnd() const;
85 87
86 virtual Value Execute(Scope* scope, Err* err) const = 0; 88 virtual Value Execute(Scope* scope, Err* err) const = 0;
87 89
88 virtual LocationRange GetRange() const = 0; 90 virtual LocationRange GetRange() const = 0;
89 91
90 // Returns an error with the given messages and the range set to something 92 // Returns an error with the given messages and the range set to something
91 // that indicates this node. 93 // that indicates this node.
92 virtual Err MakeErrorDescribing( 94 virtual Err MakeErrorDescribing(
93 const std::string& msg, 95 const std::string& msg,
94 const std::string& help = std::string()) const = 0; 96 const std::string& help = std::string()) const = 0;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 221
220 virtual const BlockNode* AsBlock() const OVERRIDE; 222 virtual const BlockNode* AsBlock() const OVERRIDE;
221 virtual Value Execute(Scope* scope, Err* err) const OVERRIDE; 223 virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
222 virtual LocationRange GetRange() const OVERRIDE; 224 virtual LocationRange GetRange() const OVERRIDE;
223 virtual Err MakeErrorDescribing( 225 virtual Err MakeErrorDescribing(
224 const std::string& msg, 226 const std::string& msg,
225 const std::string& help = std::string()) const OVERRIDE; 227 const std::string& help = std::string()) const OVERRIDE;
226 virtual void Print(std::ostream& out, int indent) const OVERRIDE; 228 virtual void Print(std::ostream& out, int indent) const OVERRIDE;
227 229
228 void set_begin_token(const Token& t) { begin_token_ = t; } 230 void set_begin_token(const Token& t) { begin_token_ = t; }
229 void set_end_token(const Token& t) { end_token_ = t; } 231 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); }
232 const EndNode* End() const { return end_.get(); }
230 233
231 const std::vector<ParseNode*>& statements() const { return statements_; } 234 const std::vector<ParseNode*>& statements() const { return statements_; }
232 void append_statement(scoped_ptr<ParseNode> s) { 235 void append_statement(scoped_ptr<ParseNode> s) {
233 statements_.push_back(s.release()); 236 statements_.push_back(s.release());
234 } 237 }
235 238
236 // Doesn't create a nested scope. 239 // Doesn't create a nested scope.
237 Value ExecuteBlockInScope(Scope* our_scope, Err* err) const; 240 Value ExecuteBlockInScope(Scope* our_scope, Err* err) const;
238 241
239 private: 242 private:
240 bool has_scope_; 243 bool has_scope_;
241 244
242 // Tokens corresponding to { and }, if any (may be NULL). 245 // Tokens corresponding to { and }, if any (may be NULL). The end is stored
246 // in a custom parse node so that it can have comments hung off of it.
243 Token begin_token_; 247 Token begin_token_;
244 Token end_token_; 248 scoped_ptr<EndNode> end_;
245 249
246 // Owning pointers, use unique_ptr when we can use C++11. 250 // Owning pointers, use unique_ptr when we can use C++11.
247 std::vector<ParseNode*> statements_; 251 std::vector<ParseNode*> statements_;
248 252
249 DISALLOW_COPY_AND_ASSIGN(BlockNode); 253 DISALLOW_COPY_AND_ASSIGN(BlockNode);
250 }; 254 };
251 255
252 // ConditionNode --------------------------------------------------------------- 256 // ConditionNode ---------------------------------------------------------------
253 257
254 class ConditionNode : public ParseNode { 258 class ConditionNode : public ParseNode {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 364
361 virtual const ListNode* AsList() const OVERRIDE; 365 virtual const ListNode* AsList() const OVERRIDE;
362 virtual Value Execute(Scope* scope, Err* err) const OVERRIDE; 366 virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
363 virtual LocationRange GetRange() const OVERRIDE; 367 virtual LocationRange GetRange() const OVERRIDE;
364 virtual Err MakeErrorDescribing( 368 virtual Err MakeErrorDescribing(
365 const std::string& msg, 369 const std::string& msg,
366 const std::string& help = std::string()) const OVERRIDE; 370 const std::string& help = std::string()) const OVERRIDE;
367 virtual void Print(std::ostream& out, int indent) const OVERRIDE; 371 virtual void Print(std::ostream& out, int indent) const OVERRIDE;
368 372
369 void set_begin_token(const Token& t) { begin_token_ = t; } 373 void set_begin_token(const Token& t) { begin_token_ = t; }
370 void set_end_token(const Token& t) { end_token_ = t; } 374 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); }
375 const EndNode* End() const { return end_.get(); }
371 376
372 void append_item(scoped_ptr<ParseNode> s) { 377 void append_item(scoped_ptr<ParseNode> s) {
373 contents_.push_back(s.release()); 378 contents_.push_back(s.release());
374 } 379 }
375 const std::vector<const ParseNode*>& contents() const { return contents_; } 380 const std::vector<const ParseNode*>& contents() const { return contents_; }
376 381
377 private: 382 private:
378 // Tokens corresponding to the [ and ]. 383 // Tokens corresponding to the [ and ]. The end token is stored in inside an
384 // custom parse node so that it can have comments hung off of it.
379 Token begin_token_; 385 Token begin_token_;
380 Token end_token_; 386 scoped_ptr<EndNode> end_;
381 387
382 // Owning pointers, use unique_ptr when we can use C++11. 388 // Owning pointers, use unique_ptr when we can use C++11.
383 std::vector<const ParseNode*> contents_; 389 std::vector<const ParseNode*> contents_;
384 390
385 DISALLOW_COPY_AND_ASSIGN(ListNode); 391 DISALLOW_COPY_AND_ASSIGN(ListNode);
386 }; 392 };
387 393
388 // LiteralNode ----------------------------------------------------------------- 394 // LiteralNode -----------------------------------------------------------------
389 395
390 class LiteralNode : public ParseNode { 396 class LiteralNode : public ParseNode {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 468
463 const Token& comment() const { return comment_; } 469 const Token& comment() const { return comment_; }
464 void set_comment(const Token& t) { comment_ = t; } 470 void set_comment(const Token& t) { comment_ = t; }
465 471
466 private: 472 private:
467 Token comment_; 473 Token comment_;
468 474
469 DISALLOW_COPY_AND_ASSIGN(BlockCommentNode); 475 DISALLOW_COPY_AND_ASSIGN(BlockCommentNode);
470 }; 476 };
471 477
478 // EndNode ---------------------------------------------------------------------
479
480 class EndNode : public IdentifierNode {
brettw 2014/09/26 21:37:34 Can you document here what this is for? It's not s
scottmg 2014/09/26 21:47:32 Done.
481 public:
482 EndNode();
483 EndNode(const Token& token);
484 virtual ~EndNode();
485
486 virtual const IdentifierNode* AsIdentifier() const OVERRIDE;
487 virtual const EndNode* AsEnd() const OVERRIDE;
488 virtual void Print(std::ostream& out, int indent) const OVERRIDE;
489 };
490
472 #endif // TOOLS_GN_PARSE_TREE_H_ 491 #endif // TOOLS_GN_PARSE_TREE_H_
OLDNEW
« no previous file with comments | « tools/gn/format_test_data/017.golden ('k') | tools/gn/parse_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698