LLVM 17.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/Support/Error.h"
19#include <optional>
20#include <vector>
21
22// This class represents a glob pattern. Supported metacharacters
23// are "*", "?", "\", "[<chars>]", "[^<chars>]", and "[!<chars>]".
24namespace llvm {
25
26template <typename T> class ArrayRef;
27class StringRef;
28
30public:
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
44private:
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 std::optional<StringRef> Exact;
52 std::optional<StringRef> Prefix;
53 std::optional<StringRef> Suffix;
54};
55}
56
57#endif // LLVM_SUPPORT_GLOBPATTERN_H
This file implements the BitVector class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Tagged union holding either a T or a Error.
Definition: Error.h:470
bool match(StringRef S) const
bool isTrivialMatchAll() const
Definition: GlobPattern.h:36
static Expected< GlobPattern > create(StringRef Pat)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ArrayRef(const T &OneElt) -> ArrayRef< T >