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//===-----------------------------------------------------------------------===/
8
9#include "llvm/Support/MemoryBuffer.h"
10#include "llvm/TextAPI/InterfaceFile.h"
11#include <algorithm>
12#include <string>
13
14#ifndef TEXT_STUB_HELPERS_H
15#define TEXT_STUB_HELPERS_H
16
17namespace llvm {
18struct 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 = {};
25};
26
27using ExportedSymbolSeq = std::vector<ExportedSymbol>;
28using TargetToAttr = std::vector<std::pair<llvm::MachO::Target, std::string>>;
29using TBDFile = std::unique_ptr<MachO::InterfaceFile>;
30using TBDReexportFile = std::shared_ptr<MachO::InterfaceFile>;
31
32inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
33 return std::tie(args: LHS.Kind, args: LHS.Name) < std::tie(args: RHS.Kind, args: RHS.Name);
34}
35
36inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
37 return std::tie(args: LHS.Kind, args: LHS.Name, args: LHS.Weak, args: LHS.ThreadLocalValue) ==
38 std::tie(args: RHS.Kind, args: RHS.Name, args: RHS.Weak, args: RHS.ThreadLocalValue);
39}
40
41inline std::string stripWhitespace(std::string S) {
42 S.erase(first: std::remove_if(first: S.begin(), last: S.end(), pred: ::isspace), last: S.end());
43 return S;
44}
45
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.
49inline bool
50checkEqualityOnTransform(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;
62}
63
64} // namespace llvm
65#endif
66

source code of llvm/unittests/TextAPI/TextStubHelpers.h