LLVM  13.0.0git
GlobPattern.h
Go to the documentation of this file.
1 //===-- GlobPattern.h - glob pattern matcher implementation -*- C++ -*-----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a glob pattern matcher. The glob pattern is the
10 // rule used by the shell.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_GLOBPATTERN_H
15 #define LLVM_SUPPORT_GLOBPATTERN_H
16 
17 #include "llvm/ADT/BitVector.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/Support/Error.h"
20 #include <vector>
21 
22 // This class represents a glob pattern. Supported metacharacters
23 // are "*", "?", "\", "[<chars>]", "[^<chars>]", and "[!<chars>]".
24 namespace llvm {
25 
26 template <typename T> class ArrayRef;
27 class StringRef;
28 
29 class GlobPattern {
30 public:
32  bool match(StringRef S) const;
33 
34  // Returns true for glob pattern "*". Can be used to avoid expensive
35  // preparation/acquisition of the input for match().
36  bool isTrivialMatchAll() const {
37  if (Prefix && Prefix->empty()) {
38  assert(!Suffix);
39  return true;
40  }
41  return false;
42  }
43 
44 private:
45  bool matchOne(ArrayRef<BitVector> Pat, StringRef S) const;
46 
47  // Parsed glob pattern.
48  std::vector<BitVector> Tokens;
49 
50  // The following members are for optimization.
51  Optional<StringRef> Exact;
52  Optional<StringRef> Prefix;
53  Optional<StringRef> Suffix;
54 };
55 }
56 
57 #endif // LLVM_SUPPORT_GLOBPATTERN_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Optional.h
Error.h
llvm::Optional
Definition: APInt.h:33
llvm::GlobPattern
Definition: GlobPattern.h:29
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::GlobPattern::isTrivialMatchAll
bool isTrivialMatchAll() const
Definition: GlobPattern.h:36
BitVector.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::GlobPattern::create
static Expected< GlobPattern > create(StringRef Pat)
Definition: GlobPattern.cpp:108
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::GlobPattern::match
bool match(StringRef S) const
Definition: GlobPattern.cpp:143