@@ -778,8 +778,7 @@ namespace {
778
778
class SourceFile ::Impl {
779
779
public:
780
780
// / Only intended for use by lookupOperatorDeclForName.
781
- static ArrayRef<std::pair<ModuleDecl::ImportedModule,
782
- std::pair<SourceFile::ImportOptions, StringRef>>>
781
+ static ArrayRef<SourceFile::ImportedModuleDesc>
783
782
getImportsForSourceFile (const SourceFile &SF) {
784
783
return SF.Imports ;
785
784
}
@@ -889,16 +888,16 @@ lookupOperatorDeclForName(const FileUnit &File, SourceLoc Loc, Identifier Name,
889
888
ImportedOperatorsMap<OP_DECL> importedOperators;
890
889
for (auto &imported : SourceFile::Impl::getImportsForSourceFile (SF)) {
891
890
// Protect against source files that contrive to import their own modules.
892
- if (imported.first .second == ownModule)
891
+ if (imported.module .second == ownModule)
893
892
continue ;
894
893
895
894
bool isExported =
896
- imported.second . first .contains (SourceFile::ImportFlags::Exported);
895
+ imported.importOptions .contains (SourceFile::ImportFlags::Exported);
897
896
if (!includePrivate && !isExported)
898
897
continue ;
899
898
900
- Optional<OP_DECL *> maybeOp
901
- = lookupOperatorDeclForName (imported.first .second , Loc, Name, OP_MAP);
899
+ Optional<OP_DECL *> maybeOp =
900
+ lookupOperatorDeclForName (imported.module .second , Loc, Name, OP_MAP);
902
901
if (!maybeOp)
903
902
return None;
904
903
@@ -990,21 +989,21 @@ void
990
989
SourceFile::getImportedModules (SmallVectorImpl<ModuleDecl::ImportedModule> &modules,
991
990
ModuleDecl::ImportFilter filter) const {
992
991
assert (ASTStage >= Parsed || Kind == SourceFileKind::SIL);
993
- for (auto importPair : Imports) {
992
+ for (auto desc : Imports) {
994
993
switch (filter) {
995
994
case ModuleDecl::ImportFilter::All:
996
995
break ;
997
996
case ModuleDecl::ImportFilter::Public:
998
- if (!importPair. second . first .contains (ImportFlags::Exported))
997
+ if (!desc. importOptions .contains (ImportFlags::Exported))
999
998
continue ;
1000
999
break ;
1001
1000
case ModuleDecl::ImportFilter::Private:
1002
- if (importPair. second . first .contains (ImportFlags::Exported))
1001
+ if (desc. importOptions .contains (ImportFlags::Exported))
1003
1002
continue ;
1004
1003
break ;
1005
1004
}
1006
1005
1007
- modules.push_back (importPair. first );
1006
+ modules.push_back (desc. module );
1008
1007
}
1009
1008
}
1010
1009
@@ -1374,17 +1373,12 @@ void SourceFile::print(ASTPrinter &Printer, const PrintOptions &PO) {
1374
1373
}
1375
1374
}
1376
1375
1377
- void SourceFile::addImports (
1378
- ArrayRef<std::pair<ModuleDecl::ImportedModule,
1379
- std::pair<ImportOptions, StringRef>>>
1380
- IM) {
1381
- using ImportPair = std::pair<ModuleDecl::ImportedModule,
1382
- std::pair<ImportOptions, StringRef>>;
1376
+ void SourceFile::addImports (ArrayRef<ImportedModuleDesc> IM) {
1383
1377
if (IM.empty ())
1384
1378
return ;
1385
1379
ASTContext &ctx = getASTContext ();
1386
1380
auto newBuf =
1387
- ctx.AllocateUninitialized <ImportPair >(Imports.size () + IM.size ());
1381
+ ctx.AllocateUninitialized <ImportedModuleDesc >(Imports.size () + IM.size ());
1388
1382
1389
1383
auto iter = newBuf.begin ();
1390
1384
iter = std::uninitialized_copy (Imports.begin (), Imports.end (), iter);
@@ -1395,20 +1389,16 @@ void SourceFile::addImports(
1395
1389
}
1396
1390
1397
1391
bool SourceFile::hasTestableImport (const swift::ModuleDecl *module ) const {
1398
- using ImportPair = std::pair<ModuleDecl::ImportedModule,
1399
- std::pair<ImportOptions, StringRef>>;
1400
1392
return std::any_of (
1401
- Imports.begin (), Imports.end (), [module ](ImportPair importPair) -> bool {
1402
- return importPair.first .second == module &&
1403
- importPair.second .first .contains (ImportFlags::Testable);
1393
+ Imports.begin (), Imports.end (),
1394
+ [module ](ImportedModuleDesc desc) -> bool {
1395
+ return desc.module .second == module &&
1396
+ desc.importOptions .contains (ImportFlags::Testable);
1404
1397
});
1405
1398
}
1406
1399
1407
1400
bool SourceFile::hasPrivateImport (AccessLevel accessLevel,
1408
1401
const swift::ValueDecl *ofDecl) const {
1409
- using ImportPair = std::pair<ModuleDecl::ImportedModule,
1410
- std::pair<ImportOptions, StringRef>>;
1411
-
1412
1402
auto *module = ofDecl->getModuleContext ();
1413
1403
switch (accessLevel) {
1414
1404
case AccessLevel::Internal:
@@ -1417,9 +1407,9 @@ bool SourceFile::hasPrivateImport(AccessLevel accessLevel,
1417
1407
// filename does not need to match (and we don't serialize it for such
1418
1408
// decls).
1419
1409
return std::any_of (Imports.begin (), Imports.end (),
1420
- [module ](ImportPair importPair ) -> bool {
1421
- return importPair. first .second == module &&
1422
- importPair. second . first .contains (
1410
+ [module ](ImportedModuleDesc desc ) -> bool {
1411
+ return desc. module .second == module &&
1412
+ desc. importOptions .contains (
1423
1413
ImportFlags::PrivateImport);
1424
1414
});
1425
1415
case AccessLevel::Open:
@@ -1447,11 +1437,11 @@ bool SourceFile::hasPrivateImport(AccessLevel accessLevel,
1447
1437
return false ;
1448
1438
1449
1439
return std::any_of (Imports.begin (), Imports.end (),
1450
- [module , filename](ImportPair importPair ) -> bool {
1451
- return importPair. first .second == module &&
1452
- importPair. second . first .contains (
1440
+ [module , filename](ImportedModuleDesc desc ) -> bool {
1441
+ return desc. module .second == module &&
1442
+ desc. importOptions .contains (
1453
1443
ImportFlags::PrivateImport) &&
1454
- importPair. second . second == filename;
1444
+ desc. filename == filename;
1455
1445
});
1456
1446
}
1457
1447
@@ -1500,9 +1490,8 @@ static void performAutoImport(
1500
1490
1501
1491
// FIXME: These will be the same for most source files, but we copy them
1502
1492
// over and over again.
1503
- auto Imports =
1504
- std::make_pair (ModuleDecl::ImportedModule ({}, M),
1505
- std::make_pair (SourceFile::ImportOptions (), StringRef ()));
1493
+ auto Imports = SourceFile::ImportedModuleDesc (
1494
+ ModuleDecl::ImportedModule ({}, M), SourceFile::ImportOptions ());
1506
1495
SF.addImports (Imports);
1507
1496
}
1508
1497
0 commit comments