File: label_pattern.h

package info (click to toggle)
qtwebengine-opensource-src 5.11.3%2Bdfsg-2%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,551,988 kB
  • sloc: cpp: 10,064,061; ansic: 3,832,841; asm: 590,489; python: 455,759; xml: 261,729; sh: 90,157; objc: 77,089; perl: 71,296; makefile: 27,041; cs: 23,492; yacc: 14,360; tcl: 12,756; php: 4,714; lex: 4,028; pascal: 3,741; ml: 3,543; ruby: 1,497; lisp: 1,490; awk: 183; csh: 117; sed: 54
file content (76 lines) | stat: -rw-r--r-- 2,460 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
72
73
74
75
76
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TOOLS_GN_LABEL_PATTERN_H_
#define TOOLS_GN_LABEL_PATTERN_H_

#include "base/strings/string_piece.h"
#include "tools/gn/label.h"
#include "tools/gn/source_dir.h"

class Err;
class Value;

extern const char kLabelPattern_Help[];

// A label pattern is a simple pattern that matches labels. It is used for
// specifying visibility and other times when multiple targets need to be
// referenced.
class LabelPattern {
 public:
  enum Type {
    MATCH = 1,  // Exact match for a given target.
    DIRECTORY,  // Only targets in the file in the given directory.
    RECURSIVE_DIRECTORY  // The given directory and any subdir.
                         // (also indicates "public" when dir is empty).
  };

  LabelPattern();
  LabelPattern(Type type,
               const SourceDir& dir,
               const base::StringPiece& name,
               const Label& toolchain_label);
  LabelPattern(const LabelPattern& other);
  ~LabelPattern();

  // Converts the given input string to a pattern. This does special stuff
  // to treat the pattern as a label. Sets the error on failure.
  static LabelPattern GetPattern(const SourceDir& current_dir,
                                 const Value& value,
                                 Err* err);

  // Returns true if the given input string might match more than one thing.
  static bool HasWildcard(const std::string& str);

  // Returns true if this pattern matches the given label.
  bool Matches(const Label& label) const;

  // Returns a string representation of this pattern.
  std::string Describe() const;

  Type type() const { return type_; }

  const SourceDir& dir() const { return dir_; }
  const std::string& name() const { return name_; }

  const Label& toolchain() const { return toolchain_; }
  void set_toolchain(const Label& tc) { toolchain_ = tc; }

 private:
  // If nonempty, specifies the toolchain to use. If empty, this will match
  // all toolchains. This is independent of the match type.
  Label toolchain_;

  Type type_;

  // Used when type_ == PRIVATE and PRIVATE_RECURSIVE. This specifies the
  // directory that to which the pattern is private to.
  SourceDir dir_;

  // Empty name means match everything. Otherwise the name must match
  // exactly.
  std::string name_;
};

#endif  // TOOLS_GN_LABEL_PATTERN_H_