Skip to content

Commit 7a630f4

Browse files
committed
ClangImporter: Track raw types of imported struct and enum wrappers
These will be used shortly to avoid name lookups into the imported type.
1 parent 95843e3 commit 7a630f4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,15 +1499,19 @@ static void makeStructRawValued(
14991499
createValueConstructor(Impl, structDecl, var,
15001500
/*wantCtorParamNames=*/false,
15011501
/*wantBody=*/!Impl.hasFinishedTypeChecking()));
1502-
structDecl->addMember(
1502+
1503+
auto *initRawValue =
15031504
createValueConstructor(Impl, structDecl, var,
15041505
/*wantCtorParamNames=*/true,
1505-
/*wantBody=*/!Impl.hasFinishedTypeChecking()));
1506+
/*wantBody=*/!Impl.hasFinishedTypeChecking());
1507+
structDecl->addMember(initRawValue);
15061508
structDecl->addMember(patternBinding);
15071509
structDecl->addMember(var);
15081510
structDecl->addMember(varGetter);
15091511

15101512
addSynthesizedTypealias(structDecl, ctx.Id_RawValue, underlyingType);
1513+
Impl.RawTypes[structDecl] = underlyingType;
1514+
Impl.RawInits[structDecl] = initRawValue;
15111515
}
15121516

15131517
/// Create a rawValue-ed constructor that bridges to its underlying storage.
@@ -1650,6 +1654,8 @@ static void makeStructRawValuedWithBridge(
16501654
structDecl->addMember(computedVarGetter);
16511655

16521656
addSynthesizedTypealias(structDecl, ctx.Id_RawValue, bridgedType);
1657+
Impl.RawTypes[structDecl] = bridgedType;
1658+
Impl.RawInits[structDecl] = init;
16531659
}
16541660

16551661
/// Build a declaration for an Objective-C subscript getter.
@@ -2852,6 +2858,8 @@ namespace {
28522858
enumDecl->addMember(rawValueBinding);
28532859

28542860
addSynthesizedTypealias(enumDecl, C.Id_RawValue, underlyingType);
2861+
Impl.RawTypes[enumDecl] = underlyingType;
2862+
Impl.RawInits[enumDecl] = rawValueConstructor;
28552863

28562864
// If we have an error wrapper, finish it up now that its
28572865
// nested enum has been constructed.

lib/ClangImporter/ImporterImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,12 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
451451
llvm::DenseMap<std::pair<ObjCSelector, char>, unsigned>
452452
ActiveSelectors;
453453

454+
// Mapping from imported types to their raw value types.
455+
llvm::DenseMap<const NominalTypeDecl *, Type> RawTypes;
456+
457+
// Mapping from imported types to their init(rawValue:) initializers.
458+
llvm::DenseMap<const NominalTypeDecl *, ConstructorDecl *> RawInits;
459+
454460
clang::CompilerInstance *getClangInstance() {
455461
return Instance.get();
456462
}

0 commit comments

Comments
 (0)