@@ -129,6 +129,39 @@ namespace dependencies {
129
129
bool );
130
130
}
131
131
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
+
132
165
// / Base class for the variant storage of ModuleDependencyInfo.
133
166
// /
134
167
// / This class is mostly an implementation detail for \c ModuleDependencyInfo.
@@ -141,25 +174,27 @@ class ModuleDependencyInfoStorageBase {
141
174
: dependencyKind(dependencyKind), moduleCacheKey(moduleCacheKey.str()),
142
175
resolved (false ), finalized(false ) {}
143
176
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 = " " )
148
182
: dependencyKind(dependencyKind), moduleImports(moduleImports),
149
183
optionalModuleImports(optionalModuleImports),
150
- moduleCacheKey(moduleCacheKey.str()), resolved(false ), finalized(false ) {}
184
+ moduleCacheKey(moduleCacheKey.str()), resolved(false ),
185
+ finalized(false ) {}
151
186
152
187
virtual ModuleDependencyInfoStorageBase *clone () const = 0;
153
188
154
189
virtual ~ModuleDependencyInfoStorageBase ();
155
190
156
191
// / The set of modules on which this module depends.
157
- std::vector<std::string > moduleImports;
192
+ std::vector<ScannerImportStatementInfo > moduleImports;
158
193
159
194
// / The set of modules which constitute optional module
160
195
// / dependencies for this module, such as `@_implementationOnly`
161
196
// / or `internal` imports.
162
- std::vector<std::string > optionalModuleImports;
197
+ std::vector<ScannerImportStatementInfo > optionalModuleImports;
163
198
164
199
// / The set of modules on which this module depends, resolved
165
200
// / to Module IDs, qualified by module kind: Swift, Clang, etc.
@@ -320,21 +355,23 @@ class SwiftSourceModuleDependenciesStorage :
320
355
}
321
356
};
322
357
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).
324
360
// /
325
361
// / This class is mostly an implementation detail for \c ModuleDependencyInfo.
326
- class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
362
+ class SwiftBinaryModuleDependencyStorage
363
+ : public ModuleDependencyInfoStorageBase {
327
364
public:
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)
336
372
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftBinary,
337
- moduleImports, optionalModuleImports, moduleCacheKey),
373
+ moduleImports, optionalModuleImports,
374
+ moduleCacheKey),
338
375
compiledModulePath (compiledModulePath), moduleDocPath(moduleDocPath),
339
376
sourceInfoPath(sourceInfoPath), headerImport(headerImport),
340
377
isFramework(isFramework) {}
@@ -516,8 +553,8 @@ class ModuleDependencyInfo {
516
553
const std::string &compiledModulePath,
517
554
const std::string &moduleDocPath,
518
555
const std::string &sourceInfoPath,
519
- const std::vector<std::string > &moduleImports,
520
- const std::vector<std::string > &optionalModuleImports,
556
+ const std::vector<ScannerImportStatementInfo > &moduleImports,
557
+ const std::vector<ScannerImportStatementInfo > &optionalModuleImports,
521
558
const std::string &headerImport,
522
559
bool isFramework, const std::string &moduleCacheKey) {
523
560
return ModuleDependencyInfo (
@@ -567,12 +604,12 @@ class ModuleDependencyInfo {
567
604
}
568
605
569
606
// / Retrieve the module-level imports.
570
- ArrayRef<std::string > getModuleImports () const {
607
+ ArrayRef<ScannerImportStatementInfo > getModuleImports () const {
571
608
return storage->moduleImports ;
572
609
}
573
610
574
611
// / Retrieve the module-level optional imports.
575
- ArrayRef<std::string > getOptionalModuleImports () const {
612
+ ArrayRef<ScannerImportStatementInfo > getOptionalModuleImports () const {
576
613
return storage->optionalModuleImports ;
577
614
}
578
615
@@ -749,31 +786,24 @@ class ModuleDependencyInfo {
749
786
void addOptionalModuleImport (StringRef module ,
750
787
llvm::StringSet<> *alreadyAddedModules = nullptr );
751
788
789
+ // / Add all of the module imports in the given source
790
+ // / file to the set of module imports.
791
+ void addModuleImports (const SourceFile &sourceFile,
792
+ llvm::StringSet<> &alreadyAddedModules,
793
+ const SourceManager *sourceManager);
752
794
753
795
// / 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 );
796
+ void addModuleImport (ImportPath::Module module ,
797
+ llvm::StringSet<> *alreadyAddedModules = nullptr ,
798
+ const SourceManager *sourceManager = nullptr ,
799
+ SourceLoc sourceLocation = SourceLoc());
756
800
757
801
// / 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
- }
802
+ void addModuleImport (StringRef module ,
803
+ llvm::StringSet<> *alreadyAddedModules = nullptr ,
804
+ const SourceManager *sourceManager = nullptr ,
805
+ SourceLoc sourceLocation = SourceLoc());
772
806
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
807
// / Add a kind-qualified module dependency ID to the set of
778
808
// / module dependencies.
779
809
void addModuleDependency (ModuleDependencyID dependencyID);
0 commit comments