Skip to content

Commit a38b7a4

Browse files
authored
[InstallAPI] Break up headers and add common header for TextAPI types (#84960)
Before it gets too unwieldy, add a common header for all MachO types that are used across InstallAPI. Also, break up the types in `InstallAPI/Frontend`. This both avoids circular dependencies and is logically easier to maintain as more functionality gets added.
1 parent 4521970 commit a38b7a4

File tree

8 files changed

+159
-110
lines changed

8 files changed

+159
-110
lines changed

clang/include/clang/InstallAPI/Context.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "clang/Basic/Diagnostic.h"
1313
#include "clang/Basic/FileManager.h"
1414
#include "clang/InstallAPI/HeaderFile.h"
15+
#include "clang/InstallAPI/MachO.h"
1516
#include "llvm/ADT/DenseMap.h"
16-
#include "llvm/TextAPI/InterfaceFile.h"
1717

1818
namespace clang {
1919
namespace installapi {
@@ -25,7 +25,7 @@ class FrontendRecordsSlice;
2525
struct InstallAPIContext {
2626

2727
/// Library attributes that are typically passed as linker inputs.
28-
llvm::MachO::RecordsSlice::BinaryAttrs BA;
28+
BinaryAttrs BA;
2929

3030
/// All headers that represent a library.
3131
HeaderSeq InputHeaders;
@@ -49,7 +49,7 @@ struct InstallAPIContext {
4949
llvm::StringRef OutputLoc{};
5050

5151
/// What encoding to write output as.
52-
llvm::MachO::FileType FT = llvm::MachO::FileType::TBD_V5;
52+
FileType FT = FileType::TBD_V5;
5353

5454
/// Populate entries of headers that should be included for TextAPI
5555
/// generation.

clang/include/clang/InstallAPI/Frontend.h

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -25,100 +25,6 @@
2525
namespace clang {
2626
namespace installapi {
2727

28-
using SymbolFlags = llvm::MachO::SymbolFlags;
29-
using RecordLinkage = llvm::MachO::RecordLinkage;
30-
using GlobalRecord = llvm::MachO::GlobalRecord;
31-
using ObjCContainerRecord = llvm::MachO::ObjCContainerRecord;
32-
using ObjCInterfaceRecord = llvm::MachO::ObjCInterfaceRecord;
33-
using ObjCCategoryRecord = llvm::MachO::ObjCCategoryRecord;
34-
using ObjCIVarRecord = llvm::MachO::ObjCIVarRecord;
35-
36-
// Represents a collection of frontend records for a library that are tied to a
37-
// darwin target triple.
38-
class FrontendRecordsSlice : public llvm::MachO::RecordsSlice {
39-
public:
40-
FrontendRecordsSlice(const llvm::Triple &T)
41-
: llvm::MachO::RecordsSlice({T}) {}
42-
43-
/// Add non-ObjC global record with attributes from AST.
44-
///
45-
/// \param Name The name of symbol.
46-
/// \param Linkage The linkage of symbol.
47-
/// \param GV The kind of global.
48-
/// \param Avail The availability information tied to the active target
49-
/// triple.
50-
/// \param D The pointer to the declaration from traversing AST.
51-
/// \param Access The intended access level of symbol.
52-
/// \param Flags The flags that describe attributes of the symbol.
53-
/// \param Inlined Whether declaration is inlined, only applicable to
54-
/// functions.
55-
/// \return The non-owning pointer to added record in slice.
56-
GlobalRecord *addGlobal(StringRef Name, RecordLinkage Linkage,
57-
GlobalRecord::Kind GV,
58-
const clang::AvailabilityInfo Avail, const Decl *D,
59-
const HeaderType Access,
60-
SymbolFlags Flags = SymbolFlags::None,
61-
bool Inlined = false);
62-
63-
/// Add ObjC Class record with attributes from AST.
64-
///
65-
/// \param Name The name of class, not symbol.
66-
/// \param Linkage The linkage of symbol.
67-
/// \param Avail The availability information tied to the active target
68-
/// triple.
69-
/// \param D The pointer to the declaration from traversing AST.
70-
/// \param Access The intended access level of symbol.
71-
/// \param IsEHType Whether declaration has an exception attribute.
72-
/// \return The non-owning pointer to added record in slice.
73-
ObjCInterfaceRecord *addObjCInterface(StringRef Name, RecordLinkage Linkage,
74-
const clang::AvailabilityInfo Avail,
75-
const Decl *D, HeaderType Access,
76-
bool IsEHType);
77-
78-
/// Add ObjC Category record with attributes from AST.
79-
///
80-
/// \param ClassToExtend The name of class that is extended by category, not
81-
/// symbol.
82-
/// \param CategoryName The name of category, not symbol.
83-
/// \param Avail The availability information tied
84-
/// to the active target triple.
85-
/// \param D The pointer to the declaration from traversing AST.
86-
/// \param Access The intended access level of symbol.
87-
/// \return The non-owning pointer to added record in slice.
88-
ObjCCategoryRecord *addObjCCategory(StringRef ClassToExtend,
89-
StringRef CategoryName,
90-
const clang::AvailabilityInfo Avail,
91-
const Decl *D, HeaderType Access);
92-
93-
/// Add ObjC IVar record with attributes from AST.
94-
///
95-
/// \param Container The owning pointer for instance variable.
96-
/// \param Name The name of ivar, not symbol.
97-
/// \param Linkage The linkage of symbol.
98-
/// \param Avail The availability information tied to the active target
99-
/// triple.
100-
/// \param D The pointer to the declaration from traversing AST.
101-
/// \param Access The intended access level of symbol.
102-
/// \param AC The access control tied to the ivar declaration.
103-
/// \return The non-owning pointer to added record in slice.
104-
ObjCIVarRecord *addObjCIVar(ObjCContainerRecord *Container,
105-
StringRef IvarName, RecordLinkage Linkage,
106-
const clang::AvailabilityInfo Avail,
107-
const Decl *D, HeaderType Access,
108-
const clang::ObjCIvarDecl::AccessControl AC);
109-
110-
private:
111-
/// Frontend information captured about records.
112-
struct FrontendAttrs {
113-
const AvailabilityInfo Avail;
114-
const Decl *D;
115-
const HeaderType Access;
116-
};
117-
118-
/// Mapping of records stored in slice to their frontend attributes.
119-
llvm::DenseMap<llvm::MachO::Record *, FrontendAttrs> FrontendRecords;
120-
};
121-
12228
/// Create a buffer that contains all headers to scan
12329
/// for global symbols with.
12430
std::unique_ptr<llvm::MemoryBuffer> createInputBuffer(InstallAPIContext &Ctx);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//===- InstallAPI/FrontendRecords.h ------------------------------*- 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+
#ifndef LLVM_CLANG_INSTALLAPI_FRONTENDRECORDS_H
10+
#define LLVM_CLANG_INSTALLAPI_FRONTENDRECORDS_H
11+
12+
#include "clang/AST/Availability.h"
13+
#include "clang/AST/DeclObjC.h"
14+
#include "clang/InstallAPI/MachO.h"
15+
16+
namespace clang {
17+
namespace installapi {
18+
19+
/// Frontend information captured about records.
20+
struct FrontendAttrs {
21+
const AvailabilityInfo Avail;
22+
const Decl *D;
23+
const HeaderType Access;
24+
};
25+
26+
// Represents a collection of frontend records for a library that are tied to a
27+
// darwin target triple.
28+
class FrontendRecordsSlice : public llvm::MachO::RecordsSlice {
29+
public:
30+
FrontendRecordsSlice(const llvm::Triple &T)
31+
: llvm::MachO::RecordsSlice({T}) {}
32+
33+
/// Add non-ObjC global record with attributes from AST.
34+
///
35+
/// \param Name The name of symbol.
36+
/// \param Linkage The linkage of symbol.
37+
/// \param GV The kind of global.
38+
/// \param Avail The availability information tied to the active target
39+
/// triple.
40+
/// \param D The pointer to the declaration from traversing AST.
41+
/// \param Access The intended access level of symbol.
42+
/// \param Flags The flags that describe attributes of the symbol.
43+
/// \param Inlined Whether declaration is inlined, only applicable to
44+
/// functions.
45+
/// \return The non-owning pointer to added record in slice.
46+
GlobalRecord *addGlobal(StringRef Name, RecordLinkage Linkage,
47+
GlobalRecord::Kind GV,
48+
const clang::AvailabilityInfo Avail, const Decl *D,
49+
const HeaderType Access,
50+
SymbolFlags Flags = SymbolFlags::None,
51+
bool Inlined = false);
52+
53+
/// Add ObjC Class record with attributes from AST.
54+
///
55+
/// \param Name The name of class, not symbol.
56+
/// \param Linkage The linkage of symbol.
57+
/// \param Avail The availability information tied to the active target
58+
/// triple.
59+
/// \param D The pointer to the declaration from traversing AST.
60+
/// \param Access The intended access level of symbol.
61+
/// \param IsEHType Whether declaration has an exception attribute.
62+
/// \return The non-owning pointer to added record in slice.
63+
ObjCInterfaceRecord *addObjCInterface(StringRef Name, RecordLinkage Linkage,
64+
const clang::AvailabilityInfo Avail,
65+
const Decl *D, HeaderType Access,
66+
bool IsEHType);
67+
68+
/// Add ObjC Category record with attributes from AST.
69+
///
70+
/// \param ClassToExtend The name of class that is extended by category, not
71+
/// symbol.
72+
/// \param CategoryName The name of category, not symbol.
73+
/// \param Avail The availability information tied
74+
/// to the active target triple.
75+
/// \param D The pointer to the declaration from traversing AST.
76+
/// \param Access The intended access level of symbol.
77+
/// \return The non-owning pointer to added record in slice.
78+
ObjCCategoryRecord *addObjCCategory(StringRef ClassToExtend,
79+
StringRef CategoryName,
80+
const clang::AvailabilityInfo Avail,
81+
const Decl *D, HeaderType Access);
82+
83+
/// Add ObjC IVar record with attributes from AST.
84+
///
85+
/// \param Container The owning pointer for instance variable.
86+
/// \param Name The name of ivar, not symbol.
87+
/// \param Linkage The linkage of symbol.
88+
/// \param Avail The availability information tied to the active target
89+
/// triple.
90+
/// \param D The pointer to the declaration from traversing AST.
91+
/// \param Access The intended access level of symbol.
92+
/// \param AC The access control tied to the ivar declaration.
93+
/// \return The non-owning pointer to added record in slice.
94+
ObjCIVarRecord *addObjCIVar(ObjCContainerRecord *Container,
95+
StringRef IvarName, RecordLinkage Linkage,
96+
const clang::AvailabilityInfo Avail,
97+
const Decl *D, HeaderType Access,
98+
const clang::ObjCIvarDecl::AccessControl AC);
99+
100+
private:
101+
/// Mapping of records stored in slice to their frontend attributes.
102+
llvm::DenseMap<Record *, FrontendAttrs> FrontendRecords;
103+
};
104+
105+
} // namespace installapi
106+
} // namespace clang
107+
108+
#endif // LLVM_CLANG_INSTALLAPI_FRONTENDRECORDS_H
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===- InstallAPI/MachO.h ---------------------------------------*- 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+
// Imports and forward declarations for llvm::MachO types.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_CLANG_INSTALLAPI_MACHO_H
14+
#define LLVM_CLANG_INSTALLAPI_MACHO_H
15+
16+
#include "llvm/TextAPI/Architecture.h"
17+
#include "llvm/TextAPI/InterfaceFile.h"
18+
#include "llvm/TextAPI/PackedVersion.h"
19+
#include "llvm/TextAPI/Platform.h"
20+
#include "llvm/TextAPI/RecordVisitor.h"
21+
#include "llvm/TextAPI/Target.h"
22+
#include "llvm/TextAPI/TextAPIWriter.h"
23+
#include "llvm/TextAPI/Utils.h"
24+
25+
using SymbolFlags = llvm::MachO::SymbolFlags;
26+
using RecordLinkage = llvm::MachO::RecordLinkage;
27+
using Record = llvm::MachO::Record;
28+
using GlobalRecord = llvm::MachO::GlobalRecord;
29+
using ObjCContainerRecord = llvm::MachO::ObjCContainerRecord;
30+
using ObjCInterfaceRecord = llvm::MachO::ObjCInterfaceRecord;
31+
using ObjCCategoryRecord = llvm::MachO::ObjCCategoryRecord;
32+
using ObjCIVarRecord = llvm::MachO::ObjCIVarRecord;
33+
using Records = llvm::MachO::Records;
34+
using BinaryAttrs = llvm::MachO::RecordsSlice::BinaryAttrs;
35+
using SymbolSet = llvm::MachO::SymbolSet;
36+
using FileType = llvm::MachO::FileType;
37+
using PackedVersion = llvm::MachO::PackedVersion;
38+
using Target = llvm::MachO::Target;
39+
40+
#endif // LLVM_CLANG_INSTALLAPI_MACHO_H

clang/lib/InstallAPI/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "clang/InstallAPI/Frontend.h"
1010
#include "clang/AST/Availability.h"
11+
#include "clang/InstallAPI/FrontendRecords.h"
1112
#include "llvm/ADT/SmallString.h"
1213
#include "llvm/ADT/StringRef.h"
1314

clang/lib/InstallAPI/Visitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "clang/AST/ParentMapContext.h"
1212
#include "clang/AST/VTableBuilder.h"
1313
#include "clang/Basic/Linkage.h"
14-
#include "clang/InstallAPI/Frontend.h"
14+
#include "clang/InstallAPI/FrontendRecords.h"
1515
#include "llvm/ADT/SmallString.h"
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/IR/DataLayout.h"

clang/tools/clang-installapi/ClangInstallAPI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "clang/Driver/Tool.h"
2020
#include "clang/Frontend/TextDiagnosticPrinter.h"
2121
#include "clang/InstallAPI/Frontend.h"
22+
#include "clang/InstallAPI/FrontendRecords.h"
23+
#include "clang/InstallAPI/MachO.h"
2224
#include "clang/Tooling/Tooling.h"
2325
#include "llvm/ADT/ArrayRef.h"
2426
#include "llvm/Option/Option.h"
@@ -29,8 +31,6 @@
2931
#include "llvm/Support/Process.h"
3032
#include "llvm/Support/Signals.h"
3133
#include "llvm/TargetParser/Host.h"
32-
#include "llvm/TextAPI/RecordVisitor.h"
33-
#include "llvm/TextAPI/TextAPIWriter.h"
3434
#include <memory>
3535

3636
using namespace clang;
@@ -125,7 +125,7 @@ static bool run(ArrayRef<const char *> Args, const char *ProgName) {
125125
// Execute and gather AST results.
126126
// An invocation is ran for each unique target triple and for each header
127127
// access level.
128-
llvm::MachO::Records FrontendResults;
128+
Records FrontendResults;
129129
for (const auto &[Targ, Trip] : Opts.DriverOpts.Targets) {
130130
for (const HeaderType Type :
131131
{HeaderType::Public, HeaderType::Private, HeaderType::Project}) {

clang/tools/clang-installapi/Options.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,17 @@
1313
#include "clang/Basic/FileManager.h"
1414
#include "clang/Frontend/FrontendOptions.h"
1515
#include "clang/InstallAPI/Context.h"
16+
#include "clang/InstallAPI/MachO.h"
1617
#include "llvm/Option/ArgList.h"
1718
#include "llvm/Option/Option.h"
1819
#include "llvm/Support/Program.h"
1920
#include "llvm/TargetParser/Triple.h"
20-
#include "llvm/TextAPI/Architecture.h"
21-
#include "llvm/TextAPI/InterfaceFile.h"
22-
#include "llvm/TextAPI/PackedVersion.h"
23-
#include "llvm/TextAPI/Platform.h"
24-
#include "llvm/TextAPI/Target.h"
25-
#include "llvm/TextAPI/Utils.h"
2621
#include <set>
2722
#include <string>
2823
#include <vector>
2924

3025
namespace clang {
3126
namespace installapi {
32-
using Macro = std::pair<std::string, bool /*isUndef*/>;
3327

3428
struct DriverOptions {
3529
/// \brief Path to input file lists (JSON).
@@ -42,7 +36,7 @@ struct DriverOptions {
4236
std::string OutputPath;
4337

4438
/// \brief File encoding to print.
45-
llvm::MachO::FileType OutFT = llvm::MachO::FileType::TBD_V5;
39+
FileType OutFT = FileType::TBD_V5;
4640

4741
/// \brief Print verbose output.
4842
bool Verbose = false;
@@ -53,7 +47,7 @@ struct LinkerOptions {
5347
std::string InstallName;
5448

5549
/// \brief The current version to use for the dynamic library.
56-
llvm::MachO::PackedVersion CurrentVersion;
50+
PackedVersion CurrentVersion;
5751

5852
/// \brief Is application extension safe.
5953
bool AppExtensionSafe = false;

0 commit comments

Comments
 (0)