Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / unittests / TextAPI / TextStubHelpers.h
blobbaefe8fa9bbf907251746d1aa76ac38d07c89cda
1 //===-- TextStubHelpers.cpp -------------------------------------*- 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 //===-----------------------------------------------------------------------===/
9 #include "llvm/Support/MemoryBuffer.h"
10 #include "llvm/TextAPI/InterfaceFile.h"
11 #include <algorithm>
12 #include <string>
14 #ifndef TEXT_STUB_HELPERS_H
15 #define TEXT_STUB_HELPERS_H
17 namespace llvm {
18 struct ExportedSymbol {
19 MachO::EncodeKind Kind = MachO::EncodeKind::GlobalSymbol;
20 std::string Name = {};
21 bool Weak = false;
22 bool ThreadLocalValue = false;
23 bool isData = false;
24 MachO::TargetList Targets = {};
27 using ExportedSymbolSeq = std::vector<ExportedSymbol>;
28 using TargetToAttr = std::vector<std::pair<llvm::MachO::Target, std::string>>;
29 using TBDFile = std::unique_ptr<MachO::InterfaceFile>;
30 using TBDReexportFile = std::shared_ptr<MachO::InterfaceFile>;
32 inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
33 return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
36 inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
37 return std::tie(LHS.Kind, LHS.Name, LHS.Weak, LHS.ThreadLocalValue) ==
38 std::tie(RHS.Kind, RHS.Name, RHS.Weak, RHS.ThreadLocalValue);
41 inline std::string stripWhitespace(std::string S) {
42 S.erase(std::remove_if(S.begin(), S.end(), ::isspace), S.end());
43 return S;
46 // This will transform a single InterfaceFile then compare against the other
47 // InterfaceFile then transform the second InterfaceFile in the same way to
48 // regain equality.
49 inline bool
50 checkEqualityOnTransform(MachO::InterfaceFile &FileA,
51 MachO::InterfaceFile &FileB,
52 void (*Transform)(MachO::InterfaceFile *)) {
53 Transform(&FileA);
54 // Files should not be equal.
55 if (FileA == FileB)
56 return false;
57 Transform(&FileB);
58 // Files should be equal.
59 if (FileA != FileB)
60 return false;
61 return true;
64 } // namespace llvm
65 #endif