| 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_SUBSTITUTION_PATTERN_H_ | 5 #ifndef TOOLS_GN_SUBSTITUTION_PATTERN_H_ |
| 6 #define TOOLS_GN_SUBSTITUTION_PATTERN_H_ | 6 #define TOOLS_GN_SUBSTITUTION_PATTERN_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "tools/gn/substitution_type.h" | 11 #include "tools/gn/substitution_type.h" |
| 12 | 12 |
| 13 class BuildSettings; |
| 13 class Err; | 14 class Err; |
| 14 class ParseNode; | 15 class ParseNode; |
| 15 class Value; | 16 class Value; |
| 16 | 17 |
| 17 // Represents a string with {{substitution_patterns}} in them. | 18 // Represents a string with {{substitution_patterns}} in them. |
| 18 class SubstitutionPattern { | 19 class SubstitutionPattern { |
| 19 public: | 20 public: |
| 20 struct Subrange { | 21 struct Subrange { |
| 21 Subrange(); | 22 Subrange(); |
| 22 Subrange(SubstitutionType t, const std::string& l = std::string()); | 23 Subrange(SubstitutionType t, const std::string& l = std::string()); |
| 23 ~Subrange(); | 24 ~Subrange(); |
| 24 | 25 |
| 26 inline bool operator==(const Subrange& other) const { |
| 27 return type == other.type && literal == other.literal; |
| 28 } |
| 29 |
| 25 SubstitutionType type; | 30 SubstitutionType type; |
| 26 | 31 |
| 27 // When type_ == LITERAL, this specifies the literal. | 32 // When type_ == LITERAL, this specifies the literal. |
| 28 std::string literal; | 33 std::string literal; |
| 29 }; | 34 }; |
| 30 | 35 |
| 31 SubstitutionPattern(); | 36 SubstitutionPattern(); |
| 32 ~SubstitutionPattern(); | 37 ~SubstitutionPattern(); |
| 33 | 38 |
| 34 // Parses the given string and fills in the pattern. The pattern must only | 39 // Parses the given string and fills in the pattern. The pattern must only |
| 35 // be initialized once. On failure, returns false and sets the error. | 40 // be initialized once. On failure, returns false and sets the error. |
| 36 bool Parse(const Value& value, Err* err); | 41 bool Parse(const Value& value, Err* err); |
| 37 bool Parse(const std::string& str, const ParseNode* origin, Err* err); | 42 bool Parse(const std::string& str, const ParseNode* origin, Err* err); |
| 38 | 43 |
| 39 // Returns the pattern as a string with substitutions in them. | 44 // Returns the pattern as a string with substitutions in them. |
| 40 std::string AsString() const; | 45 std::string AsString() const; |
| 41 | 46 |
| 42 // Sets the bits in the given vector corresponding to the substitutions used | 47 // Sets the bits in the given vector corresponding to the substitutions used |
| 43 // by this pattern. SUBSTITUTION_LITERAL is ignored. | 48 // by this pattern. SUBSTITUTION_LITERAL is ignored. |
| 44 void FillRequiredTypes(bool required_types[SUBSTITUTION_NUM_TYPES]) const; | 49 void FillRequiredTypes(SubstitutionBits* bits) const; |
| 50 |
| 51 // Checks whether this pattern resolves to something in the output directory |
| 52 // for the given build settings. If not, returns false and fills in the given |
| 53 // error. |
| 54 bool IsInOutputDir(const BuildSettings* build_settings, |
| 55 Err* err) const; |
| 45 | 56 |
| 46 // Returns a vector listing the substitutions used by this pattern, not | 57 // Returns a vector listing the substitutions used by this pattern, not |
| 47 // counting SUBSTITUTION_LITERAL. | 58 // counting SUBSTITUTION_LITERAL. |
| 48 const std::vector<SubstitutionType>& required_types() const { | 59 const std::vector<SubstitutionType>& required_types() const { |
| 49 return required_types_; | 60 return required_types_; |
| 50 } | 61 } |
| 51 | 62 |
| 52 const std::vector<Subrange>& ranges() const { return ranges_; } | 63 const std::vector<Subrange>& ranges() const { return ranges_; } |
| 53 bool empty() const { return ranges_.empty(); } | 64 bool empty() const { return ranges_.empty(); } |
| 54 | 65 |
| 55 private: | 66 private: |
| 56 std::vector<Subrange> ranges_; | 67 std::vector<Subrange> ranges_; |
| 68 const ParseNode* origin_; |
| 57 | 69 |
| 58 std::vector<SubstitutionType> required_types_; | 70 std::vector<SubstitutionType> required_types_; |
| 59 }; | 71 }; |
| 60 | 72 |
| 61 #endif // TOOLS_GN_SUBSTITUTION_PATTERN_H_ | 73 #endif // TOOLS_GN_SUBSTITUTION_PATTERN_H_ |
| OLD | NEW |