| OLD | NEW |
| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 LocationRange GetRange() const override; | 220 LocationRange GetRange() const override; |
| 221 Err MakeErrorDescribing( | 221 Err MakeErrorDescribing( |
| 222 const std::string& msg, | 222 const std::string& msg, |
| 223 const std::string& help = std::string()) const override; | 223 const std::string& help = std::string()) const override; |
| 224 void Print(std::ostream& out, int indent) const override; | 224 void Print(std::ostream& out, int indent) const override; |
| 225 | 225 |
| 226 void set_begin_token(const Token& t) { begin_token_ = t; } | 226 void set_begin_token(const Token& t) { begin_token_ = t; } |
| 227 void set_end(std::unique_ptr<EndNode> e) { end_ = std::move(e); } | 227 void set_end(std::unique_ptr<EndNode> e) { end_ = std::move(e); } |
| 228 const EndNode* End() const { return end_.get(); } | 228 const EndNode* End() const { return end_.get(); } |
| 229 | 229 |
| 230 const std::vector<ParseNode*>& statements() const { return statements_; } | 230 const std::vector<std::unique_ptr<ParseNode>>& statements() const { |
| 231 return statements_; |
| 232 } |
| 231 void append_statement(std::unique_ptr<ParseNode> s) { | 233 void append_statement(std::unique_ptr<ParseNode> s) { |
| 232 statements_.push_back(s.release()); | 234 statements_.push_back(std::move(s)); |
| 233 } | 235 } |
| 234 | 236 |
| 235 private: | 237 private: |
| 236 // Tokens corresponding to { and }, if any (may be NULL). The end is stored | 238 // Tokens corresponding to { and }, if any (may be NULL). The end is stored |
| 237 // in a custom parse node so that it can have comments hung off of it. | 239 // in a custom parse node so that it can have comments hung off of it. |
| 238 Token begin_token_; | 240 Token begin_token_; |
| 239 std::unique_ptr<EndNode> end_; | 241 std::unique_ptr<EndNode> end_; |
| 240 | 242 |
| 241 // Owning pointers, use unique_ptr when we can use C++11. | 243 std::vector<std::unique_ptr<ParseNode>> statements_; |
| 242 std::vector<ParseNode*> statements_; | |
| 243 | 244 |
| 244 DISALLOW_COPY_AND_ASSIGN(BlockNode); | 245 DISALLOW_COPY_AND_ASSIGN(BlockNode); |
| 245 }; | 246 }; |
| 246 | 247 |
| 247 // ConditionNode --------------------------------------------------------------- | 248 // ConditionNode --------------------------------------------------------------- |
| 248 | 249 |
| 249 class ConditionNode : public ParseNode { | 250 class ConditionNode : public ParseNode { |
| 250 public: | 251 public: |
| 251 ConditionNode(); | 252 ConditionNode(); |
| 252 ~ConditionNode() override; | 253 ~ConditionNode() override; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 Err MakeErrorDescribing( | 358 Err MakeErrorDescribing( |
| 358 const std::string& msg, | 359 const std::string& msg, |
| 359 const std::string& help = std::string()) const override; | 360 const std::string& help = std::string()) const override; |
| 360 void Print(std::ostream& out, int indent) const override; | 361 void Print(std::ostream& out, int indent) const override; |
| 361 | 362 |
| 362 void set_begin_token(const Token& t) { begin_token_ = t; } | 363 void set_begin_token(const Token& t) { begin_token_ = t; } |
| 363 void set_end(std::unique_ptr<EndNode> e) { end_ = std::move(e); } | 364 void set_end(std::unique_ptr<EndNode> e) { end_ = std::move(e); } |
| 364 const EndNode* End() const { return end_.get(); } | 365 const EndNode* End() const { return end_.get(); } |
| 365 | 366 |
| 366 void append_item(std::unique_ptr<ParseNode> s) { | 367 void append_item(std::unique_ptr<ParseNode> s) { |
| 367 contents_.push_back(s.release()); | 368 contents_.push_back(std::move(s)); |
| 368 } | 369 } |
| 369 const std::vector<const ParseNode*>& contents() const { return contents_; } | 370 const std::vector<std::unique_ptr<const ParseNode>>& contents() const { |
| 371 return contents_; |
| 372 } |
| 370 | 373 |
| 371 void SortAsStringsList(); | 374 void SortAsStringsList(); |
| 372 void SortAsDepsList(); | 375 void SortAsDepsList(); |
| 373 | 376 |
| 374 // During formatting, do we want this list to always be multliline? This is | 377 // During formatting, do we want this list to always be multliline? This is |
| 375 // used to make assignments to deps, sources, etc. always be multiline lists, | 378 // used to make assignments to deps, sources, etc. always be multiline lists, |
| 376 // rather than collapsed to a single line when they're one element. | 379 // rather than collapsed to a single line when they're one element. |
| 377 bool prefer_multiline() const { return prefer_multiline_; } | 380 bool prefer_multiline() const { return prefer_multiline_; } |
| 378 void set_prefer_multiline(bool prefer_multiline) { | 381 void set_prefer_multiline(bool prefer_multiline) { |
| 379 prefer_multiline_ = prefer_multiline; | 382 prefer_multiline_ = prefer_multiline; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 390 private: | 393 private: |
| 391 template <typename Comparator> | 394 template <typename Comparator> |
| 392 void SortList(Comparator comparator); | 395 void SortList(Comparator comparator); |
| 393 | 396 |
| 394 // Tokens corresponding to the [ and ]. The end token is stored in inside an | 397 // Tokens corresponding to the [ and ]. The end token is stored in inside an |
| 395 // custom parse node so that it can have comments hung off of it. | 398 // custom parse node so that it can have comments hung off of it. |
| 396 Token begin_token_; | 399 Token begin_token_; |
| 397 std::unique_ptr<EndNode> end_; | 400 std::unique_ptr<EndNode> end_; |
| 398 bool prefer_multiline_; | 401 bool prefer_multiline_; |
| 399 | 402 |
| 400 // Owning pointers, use unique_ptr when we can use C++11. | 403 std::vector<std::unique_ptr<const ParseNode>> contents_; |
| 401 std::vector<const ParseNode*> contents_; | |
| 402 | 404 |
| 403 DISALLOW_COPY_AND_ASSIGN(ListNode); | 405 DISALLOW_COPY_AND_ASSIGN(ListNode); |
| 404 }; | 406 }; |
| 405 | 407 |
| 406 // LiteralNode ----------------------------------------------------------------- | 408 // LiteralNode ----------------------------------------------------------------- |
| 407 | 409 |
| 408 class LiteralNode : public ParseNode { | 410 class LiteralNode : public ParseNode { |
| 409 public: | 411 public: |
| 410 LiteralNode(); | 412 LiteralNode(); |
| 411 explicit LiteralNode(const Token& token); | 413 explicit LiteralNode(const Token& token); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 const Token& value() const { return value_; } | 513 const Token& value() const { return value_; } |
| 512 void set_value(const Token& t) { value_ = t; } | 514 void set_value(const Token& t) { value_ = t; } |
| 513 | 515 |
| 514 private: | 516 private: |
| 515 Token value_; | 517 Token value_; |
| 516 | 518 |
| 517 DISALLOW_COPY_AND_ASSIGN(EndNode); | 519 DISALLOW_COPY_AND_ASSIGN(EndNode); |
| 518 }; | 520 }; |
| 519 | 521 |
| 520 #endif // TOOLS_GN_PARSE_TREE_H_ | 522 #endif // TOOLS_GN_PARSE_TREE_H_ |
| OLD | NEW |