@@ -129,6 +129,39 @@ namespace dependencies {
129129 bool );
130130}
131131
132+ struct ScannerImportStatementInfo {
133+ struct ImportDiagnosticLocationInfo {
134+ ImportDiagnosticLocationInfo () = delete ;
135+ ImportDiagnosticLocationInfo (std::string bufferIdentifier,
136+ uint32_t lineNumber,
137+ uint32_t columnNumber)
138+ : bufferIdentifier(bufferIdentifier),
139+ lineNumber (lineNumber),
140+ columnNumber(columnNumber) {}
141+ std::string bufferIdentifier;
142+ uint32_t lineNumber;
143+ uint32_t columnNumber;
144+ };
145+
146+ ScannerImportStatementInfo (std::string importIdentifier)
147+ : importLocations(),
148+ importIdentifier(importIdentifier) {}
149+
150+ ScannerImportStatementInfo (std::string importIdentifier,
151+ ImportDiagnosticLocationInfo location)
152+ : importLocations({location}),
153+ importIdentifier(importIdentifier) {}
154+
155+ void addImportLocation (ImportDiagnosticLocationInfo location) {
156+ importLocations.push_back (location);
157+ }
158+
159+ // Buffer, line & column number of the import statement
160+ SmallVector<ImportDiagnosticLocationInfo, 4 > importLocations;
161+ // Imported module string. e.g. "Foo.Bar" in 'import Foo.Bar'
162+ std::string importIdentifier;
163+ };
164+
132165// / Base class for the variant storage of ModuleDependencyInfo.
133166// /
134167// / This class is mostly an implementation detail for \c ModuleDependencyInfo.
@@ -141,25 +174,27 @@ class ModuleDependencyInfoStorageBase {
141174 : dependencyKind(dependencyKind), moduleCacheKey(moduleCacheKey.str()),
142175 resolved (false ), finalized(false ) {}
143176
144- ModuleDependencyInfoStorageBase (ModuleDependencyKind dependencyKind,
145- const std::vector<std::string> &moduleImports,
146- const std::vector<std::string> &optionalModuleImports,
147- StringRef moduleCacheKey = " " )
177+ ModuleDependencyInfoStorageBase (
178+ ModuleDependencyKind dependencyKind,
179+ const std::vector<ScannerImportStatementInfo> &moduleImports,
180+ const std::vector<ScannerImportStatementInfo> &optionalModuleImports,
181+ StringRef moduleCacheKey = " " )
148182 : dependencyKind(dependencyKind), moduleImports(moduleImports),
149183 optionalModuleImports(optionalModuleImports),
150- moduleCacheKey(moduleCacheKey.str()), resolved(false ), finalized(false ) {}
184+ moduleCacheKey(moduleCacheKey.str()), resolved(false ),
185+ finalized(false ) {}
151186
152187 virtual ModuleDependencyInfoStorageBase *clone () const = 0;
153188
154189 virtual ~ModuleDependencyInfoStorageBase ();
155190
156191 // / The set of modules on which this module depends.
157- std::vector<std::string > moduleImports;
192+ std::vector<ScannerImportStatementInfo > moduleImports;
158193
159194 // / The set of modules which constitute optional module
160195 // / dependencies for this module, such as `@_implementationOnly`
161196 // / or `internal` imports.
162- std::vector<std::string > optionalModuleImports;
197+ std::vector<ScannerImportStatementInfo > optionalModuleImports;
163198
164199 // / The set of modules on which this module depends, resolved
165200 // / to Module IDs, qualified by module kind: Swift, Clang, etc.
@@ -320,21 +355,23 @@ class SwiftSourceModuleDependenciesStorage :
320355 }
321356};
322357
323- // / Describes the dependencies of a pre-built Swift module (with no .swiftinterface).
358+ // / Describes the dependencies of a pre-built Swift module (with no
359+ // / .swiftinterface).
324360// /
325361// / This class is mostly an implementation detail for \c ModuleDependencyInfo.
326- class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
362+ class SwiftBinaryModuleDependencyStorage
363+ : public ModuleDependencyInfoStorageBase {
327364public:
328- SwiftBinaryModuleDependencyStorage (const std::string &compiledModulePath,
329- const std::string &moduleDocPath,
330- const std::string &sourceInfoPath,
331- const std::vector<std::string> &moduleImports,
332- const std::vector<std::string> &optionalModuleImports,
333- const std::string &headerImport,
334- const bool isFramework,
335- const std::string &moduleCacheKey)
365+ SwiftBinaryModuleDependencyStorage (
366+ const std::string &compiledModulePath, const std::string &moduleDocPath,
367+ const std::string &sourceInfoPath,
368+ const std::vector<ScannerImportStatementInfo> &moduleImports,
369+ const std::vector<ScannerImportStatementInfo> &optionalModuleImports,
370+ const std::string &headerImport, const bool isFramework,
371+ const std::string &moduleCacheKey)
336372 : ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftBinary,
337- moduleImports, optionalModuleImports, moduleCacheKey),
373+ moduleImports, optionalModuleImports,
374+ moduleCacheKey),
338375 compiledModulePath (compiledModulePath), moduleDocPath(moduleDocPath),
339376 sourceInfoPath(sourceInfoPath), headerImport(headerImport),
340377 isFramework(isFramework) {}
@@ -520,8 +557,8 @@ class ModuleDependencyInfo {
520557 const std::string &compiledModulePath,
521558 const std::string &moduleDocPath,
522559 const std::string &sourceInfoPath,
523- const std::vector<std::string > &moduleImports,
524- const std::vector<std::string > &optionalModuleImports,
560+ const std::vector<ScannerImportStatementInfo > &moduleImports,
561+ const std::vector<ScannerImportStatementInfo > &optionalModuleImports,
525562 const std::string &headerImport,
526563 bool isFramework, const std::string &moduleCacheKey) {
527564 return ModuleDependencyInfo (
@@ -572,12 +609,12 @@ class ModuleDependencyInfo {
572609 }
573610
574611 // / Retrieve the module-level imports.
575- ArrayRef<std::string > getModuleImports () const {
612+ ArrayRef<ScannerImportStatementInfo > getModuleImports () const {
576613 return storage->moduleImports ;
577614 }
578615
579616 // / Retrieve the module-level optional imports.
580- ArrayRef<std::string > getOptionalModuleImports () const {
617+ ArrayRef<ScannerImportStatementInfo > getOptionalModuleImports () const {
581618 return storage->optionalModuleImports ;
582619 }
583620
@@ -754,31 +791,24 @@ class ModuleDependencyInfo {
754791 void addOptionalModuleImport (StringRef module ,
755792 llvm::StringSet<> *alreadyAddedModules = nullptr );
756793
794+ // / Add all of the module imports in the given source
795+ // / file to the set of module imports.
796+ void addModuleImports (const SourceFile &sourceFile,
797+ llvm::StringSet<> &alreadyAddedModules,
798+ const SourceManager *sourceManager);
757799
758800 // / Add a dependency on the given module, if it was not already in the set.
759- void addModuleImport (StringRef module ,
760- llvm::StringSet<> *alreadyAddedModules = nullptr );
801+ void addModuleImport (ImportPath::Module module ,
802+ llvm::StringSet<> *alreadyAddedModules = nullptr ,
803+ const SourceManager *sourceManager = nullptr ,
804+ SourceLoc sourceLocation = SourceLoc());
761805
762806 // / Add a dependency on the given module, if it was not already in the set.
763- void addModuleImport (ImportPath::Module module ,
764- llvm::StringSet<> *alreadyAddedModules = nullptr ) {
765- std::string ImportedModuleName = module .front ().Item .str ().str ();
766- auto submodulePath = module .getSubmodulePath ();
767- if (submodulePath.size () > 0 && !submodulePath[0 ].Item .empty ()) {
768- auto submoduleComponent = submodulePath[0 ];
769- // Special case: a submodule named "Foo.Private" can be moved to a top-level
770- // module named "Foo_Private". ClangImporter has special support for this.
771- if (submoduleComponent.Item .str () == " Private" )
772- addOptionalModuleImport (ImportedModuleName + " _Private" , alreadyAddedModules);
773- }
774-
775- addModuleImport (ImportedModuleName, alreadyAddedModules);
776- }
807+ void addModuleImport (StringRef module ,
808+ llvm::StringSet<> *alreadyAddedModules = nullptr ,
809+ const SourceManager *sourceManager = nullptr ,
810+ SourceLoc sourceLocation = SourceLoc());
777811
778- // / Add all of the module imports in the given source
779- // / file to the set of module imports.
780- void addModuleImport (const SourceFile &sf,
781- llvm::StringSet<> &alreadyAddedModules);
782812 // / Add a kind-qualified module dependency ID to the set of
783813 // / module dependencies.
784814 void addModuleDependency (ModuleDependencyID dependencyID);
0 commit comments