Merge commit 'a31edf53d0580efe47f4e9ef89dccc4429c056e8' into import-as-member

This commit is contained in:
Michael Ilseman
2016-03-23 13:05:57 -07:00
6536 changed files with 81412 additions and 56907 deletions

View File

@@ -69,8 +69,8 @@ private:
void printTypePost(const TypeLoc &TL) override {
return OtherPrinter.printTypePost(TL);
}
void printTypeRef(const TypeDecl *TD, Identifier Name) override {
return OtherPrinter.printTypeRef(TD, Name);
void printTypeRef(Type T, const TypeDecl *TD, Identifier Name) override {
return OtherPrinter.printTypeRef(T, TD, Name);
}
void printModuleRef(ModuleEntity Mod, Identifier Name) override {
return OtherPrinter.printModuleRef(Mod, Name);
@@ -85,6 +85,13 @@ private:
return OtherPrinter.printSynthesizedExtensionPost(ED, NTD);
}
void printStructurePre(PrintStructureKind Kind, const Decl *D) override {
return OtherPrinter.printStructurePre(Kind, D);
}
void printStructurePost(PrintStructureKind Kind, const Decl *D) override {
return OtherPrinter.printStructurePost(Kind, D);
}
void printNamePre(PrintNameContext Context) override {
return OtherPrinter.printNamePre(Context);
}
@@ -161,35 +168,6 @@ static void adjustPrintOptions(PrintOptions &AdjustedOptions) {
AdjustedOptions.PrintDefaultParameterPlaceholder = true;
}
void findExtensionsFromConformingProtocols(Decl *D,
llvm::SmallPtrSetImpl<ExtensionDecl*> &Results) {
NominalTypeDecl* NTD = dyn_cast<NominalTypeDecl>(D);
if (!NTD || NTD->getKind() == DeclKind::Protocol)
return;
std::vector<NominalTypeDecl*> Unhandled;
auto addTypeLocNominal = [&](TypeLoc TL){
if (TL.getType()) {
if (auto D = TL.getType()->getAnyNominal()) {
Unhandled.push_back(D);
}
}
};
for (auto TL : NTD->getInherited()) {
addTypeLocNominal(TL);
}
while(!Unhandled.empty()) {
NominalTypeDecl* Back = Unhandled.back();
Unhandled.pop_back();
for (ExtensionDecl *E : Back->getExtensions()) {
if(E->isConstrainedExtension())
Results.insert(E);
for (auto TL : Back->getInherited()) {
addTypeLocNominal(TL);
}
}
}
}
ArrayRef<StringRef>
swift::ide::collectModuleGroups(Module *M, std::vector<StringRef> &Scratch) {
for (auto File : M->getFiles()) {
@@ -305,7 +283,7 @@ void swift::ide::printSubmoduleInterface(
NoImportSubModules.insert(*It);
}
}
llvm::StringMap<std::vector<Decl*>> FileRangedDecls;
// Separate the declarations that we are going to print into different
// buckets.
for (Decl *D : Decls) {
@@ -383,8 +361,10 @@ void swift::ide::printSubmoduleInterface(
if (!GroupNames.empty()){
if (auto Target = D->getGroupName()) {
if (std::find(GroupNames.begin(), GroupNames.end(),
Target.getValue()) != GroupNames.end())
SwiftDecls.push_back(D);
Target.getValue()) != GroupNames.end()) {
FileRangedDecls.insert(std::make_pair(D->getSourceFileName().getValue(),
std::vector<Decl*>())).first->getValue().push_back(D);
}
}
continue;
}
@@ -392,6 +372,23 @@ void swift::ide::printSubmoduleInterface(
SwiftDecls.push_back(D);
}
}
if (!GroupNames.empty()) {
assert(SwiftDecls.empty());
for (auto &Entry : FileRangedDecls) {
auto &DeclsInFile = Entry.getValue();
std::sort(DeclsInFile.begin(), DeclsInFile.end(),
[](Decl* LHS, Decl *RHS) {
assert(LHS->getSourceOrder().hasValue());
assert(RHS->getSourceOrder().hasValue());
return LHS->getSourceOrder().getValue() <
RHS->getSourceOrder().getValue();
});
for (auto D : DeclsInFile) {
SwiftDecls.push_back(D);
}
}
}
// Create the missing import decls and add to the collector.
for (auto *SM : NoImportSubModules) {
@@ -501,19 +498,23 @@ void swift::ide::printSubmoduleInterface(
continue;
// Print synthesized extensions.
llvm::SmallPtrSet<ExtensionDecl *, 10> ExtensionsFromConformances;
findExtensionsFromConformingProtocols(D, ExtensionsFromConformances);
AdjustedOptions.initArchetypeTransformerForSynthesizedExtensions(NTD);
for (auto ET : ExtensionsFromConformances) {
if (!shouldPrint(ET, AdjustedOptions))
continue;
SynthesizedExtensionAnalyzer Analyzer(ET, NTD);
if (!Analyzer.isApplicable())
continue;
Printer << "\n";
ET->print(Printer, AdjustedOptions);
Printer << "\n";
}
SynthesizedExtensionAnalyzer Analyzer(NTD, AdjustedOptions);
AdjustedOptions.initArchetypeTransformerForSynthesizedExtensions(NTD,
&Analyzer);
Analyzer.forEachSynthesizedExtensionMergeGroup(
[&](ArrayRef<ExtensionDecl*> Decls){
for (auto ET : Decls) {
AdjustedOptions.TransformContext->shouldOpenExtension =
Decls.front() == ET;
AdjustedOptions.TransformContext->shouldCloseExtension =
Decls.back() == ET;
if (AdjustedOptions.TransformContext->shouldOpenExtension)
Printer << "\n";
ET->print(Printer, AdjustedOptions);
if (AdjustedOptions.TransformContext->shouldCloseExtension)
Printer << "\n";
}
});
AdjustedOptions.clearArchetypeTransformerForSynthesizedExtensions();
}
}