[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / lib / ObjCopy / CommonConfig.cpp
blobe85715d0c44cb39d9042eab4fc4204779989d528
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ObjCopy/CommonConfig.h"
11 namespace llvm {
12 namespace objcopy {
14 Expected<NameOrPattern>
15 NameOrPattern::create(StringRef Pattern, MatchStyle MS,
16 function_ref<Error(Error)> ErrorCallback) {
17 switch (MS) {
18 case MatchStyle::Literal:
19 return NameOrPattern(Pattern);
20 case MatchStyle::Wildcard: {
21 SmallVector<char, 32> Data;
22 bool IsPositiveMatch = true;
23 if (Pattern[0] == '!') {
24 IsPositiveMatch = false;
25 Pattern = Pattern.drop_front();
27 Expected<GlobPattern> GlobOrErr = GlobPattern::create(Pattern);
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);
37 return NameOrPattern(std::make_shared<GlobPattern>(*GlobOrErr),
38 IsPositiveMatch);
40 case MatchStyle::Regex: {
41 SmallVector<char, 32> Data;
42 return NameOrPattern(std::make_shared<Regex>(
43 ("^" + Pattern.ltrim('^').rtrim('$') + "$").toStringRef(Data)));
46 llvm_unreachable("Unhandled llvm.objcopy.MatchStyle enum");
49 } // end namespace objcopy
50 } // end namespace llvm