Skip to content

Commit f2d3fae

Browse files
committed
[ASTPrint] Refactor CustomAttr printing (NFC)
This is a pure refactor to enable using PrintAST in the next commit.
1 parent 8208b3a commit f2d3fae

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

include/swift/AST/Attr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,8 @@ class CustomAttr final : public DeclAttribute {
23442344

23452345
bool isEquivalent(const CustomAttr *other, Decl *attachedTo) const;
23462346

2347+
void printCustomAttr(ASTPrinter &Printer, const PrintOptions &Options) const;
2348+
23472349
private:
23482350
friend class CustomAttrNominalRequest;
23492351
void resetTypeInformation(TypeExpr *repr);

lib/AST/ASTPrinter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4843,6 +4843,16 @@ void PrintAST::visitMacroExpansionDecl(MacroExpansionDecl *decl) {
48434843
Printer << ')';
48444844
}
48454845

4846+
void CustomAttr::printCustomAttr(ASTPrinter &Printer, const PrintOptions &Options) const {
4847+
Printer.callPrintNamePre(PrintNameContext::Attribute);
4848+
Printer << "@";
4849+
if (auto type = getType())
4850+
type.print(Printer, Options);
4851+
else
4852+
getTypeRepr()->print(Printer, Options);
4853+
Printer.printNamePost(PrintNameContext::Attribute);
4854+
}
4855+
48464856
void PrintAST::visitIntegerLiteralExpr(IntegerLiteralExpr *expr) {
48474857
Printer << expr->getDigitsText();
48484858
}

lib/AST/Attr.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,14 +1453,8 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
14531453
}
14541454

14551455
case DeclAttrKind::Custom: {
1456-
Printer.callPrintNamePre(PrintNameContext::Attribute);
1457-
Printer << "@";
14581456
auto *attr = cast<CustomAttr>(this);
1459-
if (auto type = attr->getType())
1460-
type.print(Printer, Options);
1461-
else
1462-
attr->getTypeRepr()->print(Printer, Options);
1463-
Printer.printNamePost(PrintNameContext::Attribute);
1457+
attr->printCustomAttr(Printer, Options);
14641458
break;
14651459
}
14661460

0 commit comments

Comments
 (0)