@@ -116,14 +116,34 @@ bool ModuleDependencyInfo::isTestableImport(StringRef moduleName) const {
116
116
}
117
117
118
118
void ModuleDependencyInfo::addOptionalModuleImport (
119
- StringRef module , bool isExported, llvm::StringSet<> *alreadyAddedModules) {
120
- if (!alreadyAddedModules || alreadyAddedModules->insert (module ).second )
121
- storage->optionalModuleImports .push_back ({module .str (), isExported});
119
+ StringRef module , bool isExported, AccessLevel accessLevel,
120
+ llvm::StringSet<> *alreadyAddedModules) {
121
+
122
+ if (alreadyAddedModules && alreadyAddedModules->contains (module )) {
123
+ // Find a prior import of this module and add import location
124
+ // and adjust whether or not this module is ever imported as exported
125
+ // as well as the access level
126
+ for (auto &existingImport : storage->optionalModuleImports ) {
127
+ if (existingImport.importIdentifier == module ) {
128
+ existingImport.isExported |= isExported;
129
+ existingImport.accessLevel = std::max (existingImport.accessLevel ,
130
+ accessLevel);
131
+ break ;
132
+ }
133
+ }
134
+ } else {
135
+ if (alreadyAddedModules)
136
+ alreadyAddedModules->insert (module );
137
+
138
+ storage->optionalModuleImports .push_back (
139
+ {module .str (), isExported, accessLevel});
140
+ }
122
141
}
123
142
124
143
void ModuleDependencyInfo::addModuleImport (
125
- StringRef module , bool isExported, llvm::StringSet<> *alreadyAddedModules,
126
- const SourceManager *sourceManager, SourceLoc sourceLocation) {
144
+ StringRef module , bool isExported, AccessLevel accessLevel,
145
+ llvm::StringSet<> *alreadyAddedModules, const SourceManager *sourceManager,
146
+ SourceLoc sourceLocation) {
127
147
auto scannerImportLocToDiagnosticLocInfo =
128
148
[&sourceManager](SourceLoc sourceLocation) {
129
149
auto lineAndColumnNumbers =
@@ -138,13 +158,16 @@ void ModuleDependencyInfo::addModuleImport(
138
158
if (alreadyAddedModules && alreadyAddedModules->contains (module )) {
139
159
// Find a prior import of this module and add import location
140
160
// and adjust whether or not this module is ever imported as exported
161
+ // as well as the access level
141
162
for (auto &existingImport : storage->moduleImports ) {
142
163
if (existingImport.importIdentifier == module ) {
143
164
if (validSourceLocation) {
144
165
existingImport.addImportLocation (
145
- scannerImportLocToDiagnosticLocInfo (sourceLocation));
166
+ scannerImportLocToDiagnosticLocInfo (sourceLocation));
146
167
}
147
168
existingImport.isExported |= isExported;
169
+ existingImport.accessLevel = std::max (existingImport.accessLevel ,
170
+ accessLevel);
148
171
break ;
149
172
}
150
173
}
@@ -154,16 +177,18 @@ void ModuleDependencyInfo::addModuleImport(
154
177
155
178
if (validSourceLocation)
156
179
storage->moduleImports .push_back (ScannerImportStatementInfo (
157
- module .str (), isExported, scannerImportLocToDiagnosticLocInfo (sourceLocation)));
180
+ module .str (), isExported, accessLevel,
181
+ scannerImportLocToDiagnosticLocInfo (sourceLocation)));
158
182
else
159
183
storage->moduleImports .push_back (
160
- ScannerImportStatementInfo (module .str (), isExported));
184
+ ScannerImportStatementInfo (module .str (), isExported, accessLevel ));
161
185
}
162
186
}
163
187
164
188
void ModuleDependencyInfo::addModuleImport (
165
- ImportPath::Module module , bool isExported, llvm::StringSet<> *alreadyAddedModules,
166
- const SourceManager *sourceManager, SourceLoc sourceLocation) {
189
+ ImportPath::Module module , bool isExported, AccessLevel accessLevel,
190
+ llvm::StringSet<> *alreadyAddedModules, const SourceManager *sourceManager,
191
+ SourceLoc sourceLocation) {
167
192
std::string ImportedModuleName = module .front ().Item .str ().str ();
168
193
auto submodulePath = module .getSubmodulePath ();
169
194
if (submodulePath.size () > 0 && !submodulePath[0 ].Item .empty ()) {
@@ -172,11 +197,12 @@ void ModuleDependencyInfo::addModuleImport(
172
197
// module named "Foo_Private". ClangImporter has special support for this.
173
198
if (submoduleComponent.Item .str () == " Private" )
174
199
addOptionalModuleImport (ImportedModuleName + " _Private" ,
200
+ isExported, accessLevel,
175
201
alreadyAddedModules);
176
202
}
177
203
178
- addModuleImport (ImportedModuleName, isExported, alreadyAddedModules ,
179
- sourceManager, sourceLocation);
204
+ addModuleImport (ImportedModuleName, isExported, accessLevel ,
205
+ alreadyAddedModules, sourceManager, sourceLocation);
180
206
}
181
207
182
208
void ModuleDependencyInfo::addModuleImports (
@@ -205,6 +231,7 @@ void ModuleDependencyInfo::addModuleImports(
205
231
continue ;
206
232
207
233
addModuleImport (realPath, importDecl->isExported (),
234
+ importDecl->getAccessLevel (),
208
235
&alreadyAddedModules, sourceManager,
209
236
importDecl->getLoc ());
210
237
0 commit comments