LLVM 22.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
12using namespace llvm;
13using namespace llvm::objcopy;
14
17 function_ref<Error(Error)> ErrorCallback) {
18 switch (MS) {
20 return NameOrPattern(Pattern);
22 bool IsPositiveMatch = !Pattern.consume_front("!");
24
25 // If we couldn't create it as a glob, report the error, but try again
26 // with a literal if the error reporting is non-fatal.
27 if (!GlobOrErr) {
28 if (Error E = ErrorCallback(GlobOrErr.takeError()))
29 return std::move(E);
30 return create(Pattern, MatchStyle::Literal, ErrorCallback);
31 }
32
33 return NameOrPattern(std::make_shared<GlobPattern>(*GlobOrErr),
34 IsPositiveMatch);
35 }
36 case MatchStyle::Regex: {
37 Regex RegEx(Pattern);
38 std::string Err;
39 if (!RegEx.isValid(Err))
41 "cannot compile regular expression \'" +
42 Pattern + "\': " + Err);
44 return NameOrPattern(std::make_shared<Regex>(
45 ("^" + Pattern.ltrim('^').rtrim('$') + "$").toStringRef(Data)));
46 }
47 }
48 llvm_unreachable("Unhandled llvm.objcopy.MatchStyle enum");
49}
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
static LLVM_ABI Expected< GlobPattern > create(StringRef Pat, std::optional< size_t > MaxSubPatterns={})
LLVM_ABI 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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
An efficient, type-erasing, non-owning reference to a callable.
static LLVM_ABI 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.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
@ invalid_argument
Definition Errc.h:56
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189