Fix DisownOpener and related tests.
[chromium-blink-merge.git] / tools / gn / substitution_pattern.h
blob7e6c662519ad4518b25961480f1d298418e036ae
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
3 // found in the LICENSE file.
5 #ifndef TOOLS_GN_SUBSTITUTION_PATTERN_H_
6 #define TOOLS_GN_SUBSTITUTION_PATTERN_H_
8 #include <string>
9 #include <vector>
11 #include "tools/gn/substitution_type.h"
13 class BuildSettings;
14 class Err;
15 class ParseNode;
16 class Value;
18 // Represents a string with {{substitution_patterns}} in them.
19 class SubstitutionPattern {
20 public:
21 struct Subrange {
22 Subrange();
23 Subrange(SubstitutionType t, const std::string& l = std::string());
24 ~Subrange();
26 inline bool operator==(const Subrange& other) const {
27 return type == other.type && literal == other.literal;
30 SubstitutionType type;
32 // When type_ == LITERAL, this specifies the literal.
33 std::string literal;
36 SubstitutionPattern();
37 ~SubstitutionPattern();
39 // Parses the given string and fills in the pattern. The pattern must only
40 // be initialized once. On failure, returns false and sets the error.
41 bool Parse(const Value& value, Err* err);
42 bool Parse(const std::string& str, const ParseNode* origin, Err* err);
44 // Returns the pattern as a string with substitutions in them.
45 std::string AsString() const;
47 // Sets the bits in the given vector corresponding to the substitutions used
48 // by this pattern. SUBSTITUTION_LITERAL is ignored.
49 void FillRequiredTypes(SubstitutionBits* bits) const;
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;
57 // Returns a vector listing the substitutions used by this pattern, not
58 // counting SUBSTITUTION_LITERAL.
59 const std::vector<SubstitutionType>& required_types() const {
60 return required_types_;
63 const std::vector<Subrange>& ranges() const { return ranges_; }
64 bool empty() const { return ranges_.empty(); }
66 private:
67 std::vector<Subrange> ranges_;
68 const ParseNode* origin_;
70 std::vector<SubstitutionType> required_types_;
73 #endif // TOOLS_GN_SUBSTITUTION_PATTERN_H_