LLVM 20.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#include "llvm/Support/Errc.h"
11
12namespace llvm {
13namespace objcopy {
14
15Expected<NameOrPattern>
17 function_ref<Error(Error)> ErrorCallback) {
18 switch (MS) {
20 return NameOrPattern(Pattern);
23 bool IsPositiveMatch = !Pattern.consume_front("!");
25
26 // If we couldn't create it as a glob, report the error, but try again
27 // with a literal if the error reporting is non-fatal.
28 if (!GlobOrErr) {
29 if (Error E = ErrorCallback(GlobOrErr.takeError()))
30 return std::move(E);
31 return create(Pattern, MatchStyle::Literal, ErrorCallback);
32 }
33
34 return NameOrPattern(std::make_shared<GlobPattern>(*GlobOrErr),
35 IsPositiveMatch);
36 }
37 case MatchStyle::Regex: {
38 Regex RegEx(Pattern);
39 std::string Err;
40 if (!RegEx.isValid(Err))
42 "cannot compile regular expression \'" +
43 Pattern + "\': " + Err);
45 return NameOrPattern(std::make_shared<Regex>(
46 ("^" + Pattern.ltrim('^').rtrim('$') + "$").toStringRef(Data)));
47 }
48 }
49 llvm_unreachable("Unhandled llvm.objcopy.MatchStyle enum");
50}
51
52} // end namespace objcopy
53} // 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:481
Error takeError()
Take ownership of the stored error.
Definition: Error.h:608
static Expected< GlobPattern > create(StringRef Pat, std::optional< size_t > MaxSubPatterns={})
bool isValid(std::string &Error) const
isValid - returns the error encountered during regex compilation, if any.
Definition: Regex.cpp:69
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
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
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1286