46
46
#include " swift/Basic/Defer.h"
47
47
#include " swift/Basic/PrettyStackTrace.h"
48
48
#include " swift/Basic/SourceLoc.h"
49
+ #include " swift/Basic/SourceManager.h"
49
50
#include " swift/Basic/Statistic.h"
50
51
#include " swift/Basic/StringExtras.h"
51
52
#include " swift/Basic/Version.h"
@@ -8669,17 +8670,16 @@ bool importer::hasSameUnderlyingType(const clang::Type *a,
8669
8670
}
8670
8671
8671
8672
SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile (
8672
- ModuleDecl &module ,
8673
- StringRef attributeText,
8674
- bool cached
8675
- ) {
8673
+ Decl *MappedDecl, StringRef attributeText, bool cached) {
8674
+ auto *module = MappedDecl->getDeclContext ()->getParentModule ();
8675
+
8676
8676
::TinyPtrVector<SourceFile *> *sourceFiles = nullptr ;
8677
8677
if (cached) {
8678
8678
sourceFiles = &ClangSwiftAttrSourceFiles[attributeText];
8679
8679
8680
8680
// Check whether we've already created a source file.
8681
8681
for (auto sourceFile : *sourceFiles) {
8682
- if (sourceFile->getParentModule () == & module )
8682
+ if (sourceFile->getParentModule () == module )
8683
8683
return *sourceFile;
8684
8684
}
8685
8685
}
@@ -8689,20 +8689,17 @@ SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile(
8689
8689
auto &sourceMgr = SwiftContext.SourceMgr ;
8690
8690
auto bufferID = sourceMgr.addMemBufferCopy (attributeText);
8691
8691
8692
- // Note that this is for an attribute.
8693
- sourceMgr.setGeneratedSourceInfo (
8694
- bufferID,
8695
- {
8696
- GeneratedSourceInfo::AttributeFromClang,
8697
- CharSourceRange (),
8698
- sourceMgr.getRangeForBuffer (bufferID),
8699
- &module
8700
- }
8701
- );
8692
+ auto info = GeneratedSourceInfo{GeneratedSourceInfo::AttributeFromClang,
8693
+ CharSourceRange (),
8694
+ sourceMgr.getRangeForBuffer (bufferID)};
8695
+ info.astNode = static_cast <void *>(module );
8696
+ info.clangNode = MappedDecl->getClangNode ();
8697
+
8698
+ sourceMgr.setGeneratedSourceInfo (bufferID, info);
8702
8699
8703
8700
// Create the source file.
8704
- auto sourceFile = new (SwiftContext)
8705
- SourceFile (module , SourceFileKind::Library, bufferID);
8701
+ auto sourceFile =
8702
+ new (SwiftContext) SourceFile (* module , SourceFileKind::Library, bufferID);
8706
8703
8707
8704
if (cached)
8708
8705
sourceFiles->push_back (sourceFile);
@@ -8725,8 +8722,8 @@ void ClangImporter::Implementation::importNontrivialAttribute(
8725
8722
bool cached = true ;
8726
8723
while (true ) {
8727
8724
// Dig out a source file we can use for parsing.
8728
- auto &sourceFile = getClangSwiftAttrSourceFile (
8729
- *MappedDecl-> getDeclContext ()-> getParentModule () , AttrString, cached);
8725
+ auto &sourceFile =
8726
+ getClangSwiftAttrSourceFile (MappedDecl , AttrString, cached);
8730
8727
8731
8728
auto topLevelDecls = sourceFile.getTopLevelDecls ();
8732
8729
0 commit comments