LLVM  16.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 <optional>
21 #include <vector>
22 
23 // This class represents a glob pattern. Supported metacharacters
24 // are "*", "?", "\", "[<chars>]", "[^<chars>]", and "[!<chars>]".
25 namespace llvm {
26 
27 template <typename T> class ArrayRef;
28 class StringRef;
29 
30 class GlobPattern {
31 public:
33  bool match(StringRef S) const;
34 
35  // Returns true for glob pattern "*". Can be used to avoid expensive
36  // preparation/acquisition of the input for match().
37  bool isTrivialMatchAll() const {
38  if (Prefix && Prefix->empty()) {
39  assert(!Suffix);
40  return true;
41  }
42  return false;
43  }
44 
45 private:
46  bool matchOne(ArrayRef<BitVector> Pat, StringRef S) const;
47 
48  // Parsed glob pattern.
49  std::vector<BitVector> Tokens;
50 
51  // The following members are for optimization.
52  std::optional<StringRef> Exact;
53  std::optional<StringRef> Prefix;
54  std::optional<StringRef> Suffix;
55 };
56 }
57 
58 #endif // LLVM_SUPPORT_GLOBPATTERN_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Optional.h
Error.h
llvm::GlobPattern
Definition: GlobPattern.h:30
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::GlobPattern::isTrivialMatchAll
bool isTrivialMatchAll() const
Definition: GlobPattern.h:37
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:50
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