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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 void set_begin_token(const Token& t) { begin_token_ = t; } | 365 void set_begin_token(const Token& t) { begin_token_ = t; } |
366 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); } | 366 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); } |
367 const EndNode* End() const { return end_.get(); } | 367 const EndNode* End() const { return end_.get(); } |
368 | 368 |
369 void append_item(scoped_ptr<ParseNode> s) { | 369 void append_item(scoped_ptr<ParseNode> s) { |
370 contents_.push_back(s.release()); | 370 contents_.push_back(s.release()); |
371 } | 371 } |
372 const std::vector<const ParseNode*>& contents() const { return contents_; } | 372 const std::vector<const ParseNode*>& contents() const { return contents_; } |
373 | 373 |
374 void SortAsStringsList(); | 374 void SortAsStringsList(); |
| 375 void SortAsDepsList(); |
375 | 376 |
376 // 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 |
377 // 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, |
378 // 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. |
379 bool prefer_multiline() const { return prefer_multiline_; } | 380 bool prefer_multiline() const { return prefer_multiline_; } |
380 void set_prefer_multiline(bool prefer_multiline) { | 381 void set_prefer_multiline(bool prefer_multiline) { |
381 prefer_multiline_ = prefer_multiline; | 382 prefer_multiline_ = prefer_multiline; |
382 } | 383 } |
383 | 384 |
384 struct SortRange { | 385 struct SortRange { |
385 size_t begin; | 386 size_t begin; |
386 size_t end; | 387 size_t end; |
387 SortRange(size_t begin, size_t end) : begin(begin), end(end) {} | 388 SortRange(size_t begin, size_t end) : begin(begin), end(end) {} |
388 }; | 389 }; |
389 // Only public for testing. | 390 // Only public for testing. |
390 std::vector<SortRange> GetSortRanges() const; | 391 std::vector<SortRange> GetSortRanges() const; |
391 | 392 |
392 private: | 393 private: |
| 394 template <typename Comparator> |
| 395 void SortList(Comparator comparator); |
| 396 |
393 // 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 |
394 // 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. |
395 Token begin_token_; | 399 Token begin_token_; |
396 scoped_ptr<EndNode> end_; | 400 scoped_ptr<EndNode> end_; |
397 bool prefer_multiline_; | 401 bool prefer_multiline_; |
398 | 402 |
399 // Owning pointers, use unique_ptr when we can use C++11. | 403 // Owning pointers, use unique_ptr when we can use C++11. |
400 std::vector<const ParseNode*> contents_; | 404 std::vector<const ParseNode*> contents_; |
401 | 405 |
402 DISALLOW_COPY_AND_ASSIGN(ListNode); | 406 DISALLOW_COPY_AND_ASSIGN(ListNode); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 const Token& value() const { return value_; } | 514 const Token& value() const { return value_; } |
511 void set_value(const Token& t) { value_ = t; } | 515 void set_value(const Token& t) { value_ = t; } |
512 | 516 |
513 private: | 517 private: |
514 Token value_; | 518 Token value_; |
515 | 519 |
516 DISALLOW_COPY_AND_ASSIGN(EndNode); | 520 DISALLOW_COPY_AND_ASSIGN(EndNode); |
517 }; | 521 }; |
518 | 522 |
519 #endif // TOOLS_GN_PARSE_TREE_H_ | 523 #endif // TOOLS_GN_PARSE_TREE_H_ |
OLD | NEW |