Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 6c37c01

Browse files
committed
Merge pull request #11 from milseman/apinotes
[Import as member] Module attribute swift_infer_import_as_member
2 parents c80a4d6 + 262574a commit 6c37c01

File tree

17 files changed

+97
-5
lines changed

17 files changed

+97
-5
lines changed

include/clang/APINotes/APINotesManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class APINotesManager {
111111

112112
/// Find the API notes reader that corresponds to the given source location.
113113
APINotesReader *findAPINotes(SourceLocation Loc);
114+
115+
APINotesReader *getCurrentModuleReader() {
116+
return CurrentModuleReader.get();
117+
}
114118
};
115119

116120
} // end namespace api_notes

include/clang/APINotes/APINotesReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class APINotesReader {
5050
/// notes.
5151
StringRef getModuleName() const;
5252

53+
/// Retrieve the module options
54+
ModuleOptions getModuleOptions() const;
55+
5356
/// Look for information regarding the given Objective-C class.
5457
///
5558
/// \param name The name of the class we're looking for.

include/clang/APINotes/APINotesWriter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class APINotesWriter {
107107
/// \param name The name of this typedef.
108108
/// \param info Information about this typedef.
109109
void addTypedef(StringRef name, const TypedefInfo &info);
110+
111+
/// Add module options
112+
void addModuleOptions(ModuleOptions opts);
110113
};
111114

112115
} // end namespace api_notes

include/clang/APINotes/Types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ class TypedefInfo : public CommonTypeInfo {
474474
TypedefInfo() : CommonTypeInfo() { }
475475
};
476476

477+
/// Descripts a series of options for a module
478+
struct ModuleOptions {
479+
bool SwiftInferImportAsMember;
480+
};
481+
477482
} // end namespace api_notes
478483
} // end namespace clang
479484

include/clang/Basic/Module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ class Module {
183183
/// \brief Whether this is an inferred submodule (module * { ... }).
184184
unsigned IsInferred : 1;
185185

186+
/// \brief Whether this is a module who has its swift_names inferred.
187+
unsigned IsSwiftInferImportAsMember : 1;
188+
186189
/// \brief Whether we should infer submodules for this module based on
187190
/// the headers.
188191
///

include/clang/Lex/ModuleMap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class ModuleMap {
176176

177177
/// \brief Whether this is an exhaustive set of configuration macros.
178178
unsigned IsExhaustive : 1;
179+
180+
/// \brief Whether this is a module who has its swift_names inferred.
181+
unsigned IsSwiftInferImportAsMember : 1;
179182
};
180183

181184
/// \brief A directory for which framework modules can be inferred.

lib/APINotes/APINotesFormat.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const uint16_t VERSION_MAJOR = 0;
3535
/// API notes file minor version number.
3636
///
3737
/// When the format changes IN ANY WAY, this number should be incremented.
38-
const uint16_t VERSION_MINOR = 10; // enum constants
38+
const uint16_t VERSION_MINOR = 11; // SwiftInferImportAsMember
3939

4040
using IdentifierID = Fixnum<31>;
4141
using IdentifierIDField = BCVBR<16>;
@@ -104,7 +104,8 @@ namespace control_block {
104104
// VERSION_MAJOR.
105105
enum {
106106
METADATA = 1,
107-
MODULE_NAME = 2
107+
MODULE_NAME = 2,
108+
MODULE_OPTIONS = 3
108109
};
109110

110111
using MetadataLayout = BCRecordLayout<
@@ -117,6 +118,11 @@ namespace control_block {
117118
MODULE_NAME,
118119
BCBlob // Module name
119120
>;
121+
122+
using ModuleOptionsLayout = BCRecordLayout<
123+
MODULE_OPTIONS,
124+
BCFixed<1> // SwiftInferImportAsMember
125+
>;
120126
}
121127

122128
namespace identifier_block {

lib/APINotes/APINotesReader.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ class APINotesReader::Implementation {
562562
/// The name of the module that we read from the control block.
563563
std::string ModuleName;
564564

565+
/// Various options and attributes for the module
566+
ModuleOptions ModuleOpts;
567+
565568
using SerializedIdentifierTable =
566569
llvm::OnDiskIterableChainedHashTable<IdentifierTableInfo>;
567570

@@ -735,6 +738,10 @@ bool APINotesReader::Implementation::readControlBlock(
735738
ModuleName = blobData.str();
736739
break;
737740

741+
case control_block::MODULE_OPTIONS:
742+
ModuleOpts.SwiftInferImportAsMember = (scratch.front() & 1) != 0;
743+
break;
744+
738745
default:
739746
// Unknown metadata record, possibly for use by a future version of the
740747
// module format.
@@ -1440,6 +1447,10 @@ StringRef APINotesReader::getModuleName() const {
14401447
return Impl.ModuleName;
14411448
}
14421449

1450+
ModuleOptions APINotesReader::getModuleOptions() const {
1451+
return Impl.ModuleOpts;
1452+
}
1453+
14431454
auto APINotesReader::lookupObjCClass(StringRef name)
14441455
-> Optional<std::pair<ContextID, ObjCContextInfo>> {
14451456
if (!Impl.ObjCContextTable)

lib/APINotes/APINotesWriter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class APINotesWriter::Implementation {
4343
/// The name of the module
4444
std::string ModuleName;
4545

46+
bool SwiftInferImportAsMember = false;
47+
4648
/// Information about Objective-C contexts (classes or protocols).
4749
///
4850
/// Indexed by the identifier ID and a bit indication whether we're looking
@@ -214,6 +216,11 @@ void APINotesWriter::Implementation::writeControlBlock(
214216

215217
control_block::ModuleNameLayout moduleName(writer);
216218
moduleName.emit(ScratchRecord, ModuleName);
219+
220+
if (SwiftInferImportAsMember) {
221+
control_block::ModuleOptionsLayout moduleOptions(writer);
222+
moduleOptions.emit(ScratchRecord, SwiftInferImportAsMember);
223+
}
217224
}
218225

219226
namespace {
@@ -1091,3 +1098,8 @@ void APINotesWriter::addTypedef(llvm::StringRef name, const TypedefInfo &info) {
10911098
assert(!Impl.Typedefs.count(typedefID));
10921099
Impl.Typedefs[typedefID] = info;
10931100
}
1101+
1102+
void APINotesWriter::addModuleOptions(ModuleOptions opts) {
1103+
Impl.SwiftInferImportAsMember = opts.SwiftInferImportAsMember;
1104+
}
1105+

lib/APINotes/APINotesYAMLCompiler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ namespace {
250250
TagsSeq Tags;
251251
TypedefsSeq Typedefs;
252252

253+
llvm::Optional<bool> SwiftInferImportAsMember;
254+
253255
LLVM_ATTRIBUTE_DEPRECATED(
254256
void dump() LLVM_ATTRIBUTE_USED,
255257
"only for use within the debugger");
@@ -416,6 +418,7 @@ namespace llvm {
416418
io.mapRequired("Name", m.Name);
417419
io.mapOptional("Availability", m.Availability.Mode);
418420
io.mapOptional("AvailabilityMsg", m.Availability.Msg);
421+
io.mapOptional("SwiftInferImportAsMember", m.SwiftInferImportAsMember);
419422
io.mapOptional("Classes", m.Classes);
420423
io.mapOptional("Protocols", m.Protocols);
421424
io.mapOptional("Functions", m.Functions);
@@ -771,6 +774,9 @@ namespace {
771774
Writer->addTypedef(t.Name, typedefInfo);
772775
}
773776

777+
if (TheModule.SwiftInferImportAsMember)
778+
Writer->addModuleOptions({true});
779+
774780
if (!ErrorOccured)
775781
Writer->writeToStream(OS);
776782

@@ -1032,6 +1038,11 @@ bool api_notes::decompileAPINotes(std::unique_ptr<llvm::MemoryBuffer> input,
10321038
// Set module name.
10331039
module.Name = reader->getModuleName();
10341040

1041+
// Set module options
1042+
auto opts = reader->getModuleOptions();
1043+
if (opts.SwiftInferImportAsMember)
1044+
module.SwiftInferImportAsMember = true;
1045+
10351046
// Sort classes.
10361047
std::sort(module.Classes.begin(), module.Classes.end(),
10371048
[](const Class &lhs, const Class &rhs) -> bool {

0 commit comments

Comments
 (0)