LLVM 18.0.0git
CommonConfig.cpp
Go to the documentation of this file.
1//===- CommonConfig.cpp ---------------------------------------------------===//
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
10
11namespace llvm {
12namespace objcopy {
13
14Expected<NameOrPattern>
16 function_ref<Error(Error)> ErrorCallback) {
17 switch (MS) {
19 return NameOrPattern(Pattern);
22 bool IsPositiveMatch = true;
23 if (Pattern[0] == '!') {
24 IsPositiveMatch = false;
25 Pattern = Pattern.drop_front();
26 }
28
29 // If we couldn't create it as a glob, report the error, but try again
30 // with a literal if the error reporting is non-fatal.
31 if (!GlobOrErr) {
32 if (Error E = ErrorCallback(GlobOrErr.takeError()))
33 return std::move(E);
34 return create(Pattern, MatchStyle::Literal, ErrorCallback);
35 }
36
37 return NameOrPattern(std::make_shared<GlobPattern>(*GlobOrErr),
38 IsPositiveMatch);
39 }
40 case MatchStyle::Regex: {
42 return NameOrPattern(std::make_shared<Regex>(
43 ("^" + Pattern.ltrim('^').rtrim('$') + "$").toStringRef(Data)));
44 }
45 }
46 llvm_unreachable("Unhandled llvm.objcopy.MatchStyle enum");
47}
48
49} // end namespace objcopy
50} // end namespace llvm
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:474
Error takeError()
Take ownership of the stored error.
Definition: Error.h:601
static Expected< GlobPattern > create(StringRef Pat, std::optional< size_t > MaxSubPatterns={})
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
An efficient, type-erasing, non-owning reference to a callable.
static Expected< NameOrPattern > create(StringRef Pattern, MatchStyle MS, llvm::function_ref< Error(Error)> ErrorCallback)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18