Skip to content

Commit 81c19b5

Browse files
committed
[ASTPrinter] Move up the logic printing the module disambiguation
1 parent a380799 commit 81c19b5

File tree

6 files changed

+17
-21
lines changed

6 files changed

+17
-21
lines changed

include/swift/AST/ASTPrinter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ class ASTPrinter {
166166
PrintNameContext NameContext = PrintNameContext::Normal);
167167

168168
/// Called when printing the referenced name of a module.
169-
virtual void printModuleRef(ModuleEntity Mod, Identifier Name,
170-
const PrintOptions &Options);
169+
virtual void printModuleRef(ModuleEntity Mod, Identifier Name);
171170

172171
/// Called before printing a synthesized extension.
173172
virtual void printSynthesizedExtensionPre(const ExtensionDecl *ED,

lib/AST/ASTPrinter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,7 @@ void ASTPrinter::printTypeRef(Type T, const TypeDecl *RefTo, Identifier Name,
367367
printName(Name, Context);
368368
}
369369

370-
void ASTPrinter::printModuleRef(ModuleEntity Mod, Identifier Name,
371-
const PrintOptions &Options) {
372-
if (Options.AliasModuleNames)
373-
printTextImpl(MODULE_DISAMBIGUATING_PREFIX);
374-
370+
void ASTPrinter::printModuleRef(ModuleEntity Mod, Identifier Name) {
375371
printName(Name);
376372
}
377373

@@ -2509,7 +2505,7 @@ void PrintAST::visitImportDecl(ImportDecl *decl) {
25092505
Name = Declaring->getRealName();
25102506
}
25112507
}
2512-
Printer.printModuleRef(Mods.front(), Name, Options);
2508+
Printer.printModuleRef(Mods.front(), Name);
25132509
Mods = Mods.slice(1);
25142510
} else {
25152511
Printer << Elem.Item.str();
@@ -5397,7 +5393,12 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
53975393
}
53985394
}
53995395

5400-
Printer.printModuleRef(Mod, Name, Options);
5396+
if (Options.AliasModuleNames) {
5397+
auto nameTwine = MODULE_DISAMBIGUATING_PREFIX + Name.str();
5398+
Name = Mod->getASTContext().getIdentifier(nameTwine.str());
5399+
}
5400+
5401+
Printer.printModuleRef(Mod, Name);
54015402
Printer << ".";
54025403
}
54035404

@@ -5748,8 +5749,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
57485749
Printer << "module<";
57495750
// Should print the module real name in case module aliasing is
57505751
// used (see -module-alias), since that's the actual binary name.
5751-
Printer.printModuleRef(T->getModule(), T->getModule()->getRealName(),
5752-
Options);
5752+
Printer.printModuleRef(T->getModule(), T->getModule()->getRealName());
57535753
Printer << ">";
57545754
}
57555755

lib/AST/TypeRepr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void ComponentIdentTypeRepr::printImpl(ASTPrinter &Printer,
269269
const PrintOptions &Opts) const {
270270
if (auto *TD = dyn_cast_or_null<TypeDecl>(getBoundDecl())) {
271271
if (auto MD = dyn_cast<ModuleDecl>(TD))
272-
Printer.printModuleRef(MD, getNameRef().getBaseIdentifier(), Opts);
272+
Printer.printModuleRef(MD, getNameRef().getBaseIdentifier());
273273
else
274274
Printer.printTypeRef(Type(), TD, getNameRef().getBaseIdentifier());
275275
} else {

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ class ClangCommentPrinter : public ASTPrinter {
8080
PrintNameContext NameContext) override {
8181
return OtherPrinter.printTypeRef(T, TD, Name, NameContext);
8282
}
83-
void printModuleRef(ModuleEntity Mod, Identifier Name,
84-
const PrintOptions &Options) override {
85-
return OtherPrinter.printModuleRef(Mod, Name, Options);
83+
void printModuleRef(ModuleEntity Mod, Identifier Name) override {
84+
return OtherPrinter.printModuleRef(Mod, Name);
8685
}
8786
void printSynthesizedExtensionPre(const ExtensionDecl *ED,
8887
TypeOrExtensionDecl Target,

tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,10 @@ class AnnotatingPrinter : public StreamPrinter {
185185
StreamPrinter::printTypeRef(T, TD, Name, NameContext);
186186
}
187187

188-
void printModuleRef(ModuleEntity Mod, Identifier Name,
189-
const PrintOptions &Options) override {
188+
void printModuleRef(ModuleEntity Mod, Identifier Name) override {
190189
unsigned StartOffset = OS.tell();
191190
Info.References.emplace_back(Mod, StartOffset, Name.str().size());
192-
StreamPrinter::printModuleRef(Mod, Name, Options);
191+
StreamPrinter::printModuleRef(Mod, Name);
193192
}
194193
};
195194

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,10 +2841,9 @@ class AnnotatingPrinter : public StreamPrinter {
28412841
StreamPrinter::printTypeRef(T, TD, Name, NameContext);
28422842
OS << "</ref>";
28432843
}
2844-
void printModuleRef(ModuleEntity Mod, Identifier Name,
2845-
const PrintOptions &Options) override {
2844+
void printModuleRef(ModuleEntity Mod, Identifier Name) override {
28462845
OS << "<ref:module>";
2847-
StreamPrinter::printModuleRef(Mod, Name, Options);
2846+
StreamPrinter::printModuleRef(Mod, Name);
28482847
OS << "</ref>";
28492848
}
28502849
};

0 commit comments

Comments
 (0)