aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/adhoc-rule-regex-pattern.hxx
blob: eb75ea0cde7e370dd0ee024662740515ae70a08b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// file      : libbuild2/adhoc-rule-regex-pattern.hxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef LIBBUILD2_ADHOC_RULE_REGEX_PATTERN_HXX
#define LIBBUILD2_ADHOC_RULE_REGEX_PATTERN_HXX

#include <libbuild2/types.hxx>
#include <libbuild2/forward.hxx>
#include <libbuild2/utility.hxx>

#include <libbuild2/rule.hxx>

namespace build2
{
  // Ad hoc rule regex pattern.
  //
  // The name signature string is stored in match_extra::data while the regex
  // match_results object -- in the target auxiliary data storage. Both must
  // remain valid until after the apply_*() calls.
  //
  // Note: exported since may be accessed by ad hoc recipe implementation.
  //
  class LIBBUILD2_SYMEXPORT adhoc_rule_regex_pattern: public adhoc_rule_pattern
  {
  public:
    using name  = build2::name;
    using scope = build2::scope;

    adhoc_rule_regex_pattern (const scope&, string, const target_type&,
                              name&&, const location&,
                              names&&, const location&,
                              names&&, const location&);

    virtual bool
    match (action, const target&, const string&, match_extra&) const override;

    virtual void
    apply_adhoc_members (action, target&,
                         const scope&,
                         match_extra&) const override;

    virtual void
    apply_prerequisites (action, target&,
                         const scope&,
                         match_extra&) const override;

    virtual void
    dump (ostream&) const override;

  private:
    string text_;  // Pattern text.
    regex  regex_; // Pattern regex.

    struct element
    {
      build2::name       name;
      const target_type& type;
      bool               match_ext; // Match extension flag.
    };

    vector<element> targets_; // First is the primary target.
    vector<element> prereqs_;
  };
}

#endif // LIBBUILD2_ADHOC_RULE_REGEX_PATTERN_HXX