@@ -129,6 +129,39 @@ namespace dependencies {
129
129
bool );
130
130
}
131
131
132
+ struct ImportStatementInfo {
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
+ ImportStatementInfo (std::string importIdentifier)
147
+ : importLocations(),
148
+ importIdentifier(importIdentifier) {}
149
+
150
+ ImportStatementInfo (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
+
132
165
// / Base class for the variant storage of ModuleDependencyInfo.
133
166
// /
134
167
// / This class is mostly an implementation detail for \c ModuleDependencyInfo.
@@ -142,8 +175,8 @@ class ModuleDependencyInfoStorageBase {
142
175
resolved (false ), finalized(false ) {}
143
176
144
177
ModuleDependencyInfoStorageBase (ModuleDependencyKind dependencyKind,
145
- const std::vector<std::string > &moduleImports,
146
- const std::vector<std::string > &optionalModuleImports,
178
+ const std::vector<ImportStatementInfo > &moduleImports,
179
+ const std::vector<ImportStatementInfo > &optionalModuleImports,
147
180
StringRef moduleCacheKey = " " )
148
181
: dependencyKind(dependencyKind), moduleImports(moduleImports),
149
182
optionalModuleImports(optionalModuleImports),
@@ -154,12 +187,12 @@ class ModuleDependencyInfoStorageBase {
154
187
virtual ~ModuleDependencyInfoStorageBase ();
155
188
156
189
// / The set of modules on which this module depends.
157
- std::vector<std::string > moduleImports;
190
+ std::vector<ImportStatementInfo > moduleImports;
158
191
159
192
// / The set of modules which constitute optional module
160
193
// / dependencies for this module, such as `@_implementationOnly`
161
194
// / or `internal` imports.
162
- std::vector<std::string > optionalModuleImports;
195
+ std::vector<ImportStatementInfo > optionalModuleImports;
163
196
164
197
// / The set of modules on which this module depends, resolved
165
198
// / to Module IDs, qualified by module kind: Swift, Clang, etc.
@@ -328,8 +361,8 @@ class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBas
328
361
SwiftBinaryModuleDependencyStorage (const std::string &compiledModulePath,
329
362
const std::string &moduleDocPath,
330
363
const std::string &sourceInfoPath,
331
- const std::vector<std::string > &moduleImports,
332
- const std::vector<std::string > &optionalModuleImports,
364
+ const std::vector<ImportStatementInfo > &moduleImports,
365
+ const std::vector<ImportStatementInfo > &optionalModuleImports,
333
366
const std::string &headerImport,
334
367
const bool isFramework,
335
368
const std::string &moduleCacheKey)
@@ -516,8 +549,8 @@ class ModuleDependencyInfo {
516
549
const std::string &compiledModulePath,
517
550
const std::string &moduleDocPath,
518
551
const std::string &sourceInfoPath,
519
- const std::vector<std::string > &moduleImports,
520
- const std::vector<std::string > &optionalModuleImports,
552
+ const std::vector<ImportStatementInfo > &moduleImports,
553
+ const std::vector<ImportStatementInfo > &optionalModuleImports,
521
554
const std::string &headerImport,
522
555
bool isFramework, const std::string &moduleCacheKey) {
523
556
return ModuleDependencyInfo (
@@ -567,12 +600,12 @@ class ModuleDependencyInfo {
567
600
}
568
601
569
602
// / Retrieve the module-level imports.
570
- ArrayRef<std::string > getModuleImports () const {
603
+ ArrayRef<ImportStatementInfo > getModuleImports () const {
571
604
return storage->moduleImports ;
572
605
}
573
606
574
607
// / Retrieve the module-level optional imports.
575
- ArrayRef<std::string > getOptionalModuleImports () const {
608
+ ArrayRef<ImportStatementInfo > getOptionalModuleImports () const {
576
609
return storage->optionalModuleImports ;
577
610
}
578
611
@@ -749,31 +782,24 @@ class ModuleDependencyInfo {
749
782
void addOptionalModuleImport (StringRef module ,
750
783
llvm::StringSet<> *alreadyAddedModules = nullptr );
751
784
785
+ // / Add all of the module imports in the given source
786
+ // / file to the set of module imports.
787
+ void addModuleImports (const SourceFile &sourceFile,
788
+ llvm::StringSet<> &alreadyAddedModules,
789
+ const SourceManager *sourceManager);
752
790
753
791
// / Add a dependency on the given module, if it was not already in the set.
754
- void addModuleImport (StringRef module ,
755
- llvm::StringSet<> *alreadyAddedModules = nullptr );
792
+ void addModuleImport (ImportPath::Module module ,
793
+ llvm::StringSet<> *alreadyAddedModules = nullptr ,
794
+ const SourceManager *sourceManager = nullptr ,
795
+ SourceLoc sourceLocation = SourceLoc());
756
796
757
797
// / Add a dependency on the given module, if it was not already in the set.
758
- void addModuleImport (ImportPath::Module module ,
759
- llvm::StringSet<> *alreadyAddedModules = nullptr ) {
760
- std::string ImportedModuleName = module .front ().Item .str ().str ();
761
- auto submodulePath = module .getSubmodulePath ();
762
- if (submodulePath.size () > 0 && !submodulePath[0 ].Item .empty ()) {
763
- auto submoduleComponent = submodulePath[0 ];
764
- // Special case: a submodule named "Foo.Private" can be moved to a top-level
765
- // module named "Foo_Private". ClangImporter has special support for this.
766
- if (submoduleComponent.Item .str () == " Private" )
767
- addOptionalModuleImport (ImportedModuleName + " _Private" , alreadyAddedModules);
768
- }
769
-
770
- addModuleImport (ImportedModuleName, alreadyAddedModules);
771
- }
798
+ void addModuleImport (StringRef module ,
799
+ llvm::StringSet<> *alreadyAddedModules = nullptr ,
800
+ const SourceManager *sourceManager = nullptr ,
801
+ SourceLoc sourceLocation = SourceLoc());
772
802
773
- // / Add all of the module imports in the given source
774
- // / file to the set of module imports.
775
- void addModuleImport (const SourceFile &sf,
776
- llvm::StringSet<> &alreadyAddedModules);
777
803
// / Add a kind-qualified module dependency ID to the set of
778
804
// / module dependencies.
779
805
void addModuleDependency (ModuleDependencyID dependencyID);
0 commit comments