Skip to content

Commit 90cb347

Browse files
authored
Merge pull request #32466 from martinboehme/pass-print-options-by-const-ref
Pass PrintOptions by const reference instead of by value.
2 parents dff221d + 0f7eb02 commit 90cb347

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

include/swift/AST/ASTPrinter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ class ASTPrinter {
204204
return *this << StringRef(&c, 1);
205205
}
206206

207-
void printKeyword(StringRef name, PrintOptions Opts, StringRef Suffix = "") {
207+
void printKeyword(StringRef name,
208+
const PrintOptions &Opts,
209+
StringRef Suffix = "") {
208210
if (Opts.SkipUnderscoredKeywords && name.startswith("_"))
209211
return;
210212
assert(!name.empty() && "Tried to print empty keyword");

include/swift/AST/GenericSignature.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ class GenericSignature {
136136
return hash_value(sig.getPointer());
137137
}
138138

139-
void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const;
140-
void print(ASTPrinter &Printer, PrintOptions Opts = PrintOptions()) const;
139+
void print(raw_ostream &OS,
140+
const PrintOptions &Options = PrintOptions()) const;
141+
void print(ASTPrinter &Printer,
142+
const PrintOptions &Opts = PrintOptions()) const;
141143
SWIFT_DEBUG_DUMP;
142144
std::string getAsString() const;
143145

lib/AST/ASTPrinter.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void StreamPrinter::printText(StringRef Text) {
475475
/// Whether we will be printing a TypeLoc by using the TypeRepr printer
476476
static bool willUseTypeReprPrinting(TypeLoc tyLoc,
477477
Type currentType,
478-
PrintOptions options) {
478+
const PrintOptions &options) {
479479
// Special case for when transforming archetypes
480480
if (currentType && tyLoc.getType())
481481
return false;
@@ -686,7 +686,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
686686
}
687687
}
688688

689-
void printTypeWithOptions(Type T, PrintOptions options) {
689+
void printTypeWithOptions(Type T, const PrintOptions &options) {
690690
if (options.TransformContext) {
691691
// FIXME: it's not clear exactly what we want to keep from the existing
692692
// options, and what we want to discard.
@@ -736,7 +736,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
736736
printTransformedTypeWithOptions(T, Options);
737737
}
738738

739-
void printTypeLocWithOptions(const TypeLoc &TL, PrintOptions options) {
739+
void printTypeLocWithOptions(const TypeLoc &TL, const PrintOptions &options) {
740740
if (CurrentType && TL.getType()) {
741741
printTransformedTypeWithOptions(TL.getType(), options);
742742
return;
@@ -1081,7 +1081,7 @@ void PrintAST::printTypedPattern(const TypedPattern *TP) {
10811081

10821082
/// Determines if we are required to print the name of a property declaration,
10831083
/// or if we can elide it by printing a '_' instead.
1084-
static bool mustPrintPropertyName(VarDecl *decl, PrintOptions opts) {
1084+
static bool mustPrintPropertyName(VarDecl *decl, const PrintOptions &opts) {
10851085
// If we're not allowed to omit the name, we must print it.
10861086
if (!opts.OmitNameOfInaccessibleProperties) return true;
10871087

@@ -2636,8 +2636,10 @@ static bool isEscaping(Type type) {
26362636
return false;
26372637
}
26382638

2639-
static void printParameterFlags(ASTPrinter &printer, PrintOptions options,
2640-
ParameterTypeFlags flags, bool escaping) {
2639+
static void printParameterFlags(ASTPrinter &printer,
2640+
const PrintOptions &options,
2641+
ParameterTypeFlags flags,
2642+
bool escaping) {
26412643
if (!options.excludeAttrKind(TAK_autoclosure) && flags.isAutoClosure())
26422644
printer.printAttrName("@autoclosure ");
26432645
if (!options.excludeAttrKind(TAK_noDerivative) && flags.isNoDerivative())
@@ -4680,12 +4682,13 @@ void GenericSignatureImpl::print(ASTPrinter &Printer, PrintOptions PO) const {
46804682
GenericSignature(const_cast<GenericSignatureImpl *>(this)).print(Printer, PO);
46814683
}
46824684

4683-
void GenericSignature::print(raw_ostream &OS, PrintOptions Opts) const {
4685+
void GenericSignature::print(raw_ostream &OS, const PrintOptions &Opts) const {
46844686
StreamPrinter Printer(OS);
46854687
print(Printer, Opts);
46864688
}
46874689

4688-
void GenericSignature::print(ASTPrinter &Printer, PrintOptions Opts) const {
4690+
void GenericSignature::print(ASTPrinter &Printer,
4691+
const PrintOptions &Opts) const {
46894692
if (isNull()) {
46904693
Printer << "<null>";
46914694
return;

lib/AST/Attr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ static std::string getDifferentiationParametersClauseString(
528528
/// - If `omitWrtClause` is true, omit printing the `wrt:` differentiation
529529
/// parameters clause.
530530
static void printDifferentiableAttrArguments(
531-
const DifferentiableAttr *attr, ASTPrinter &printer, PrintOptions Options,
532-
const Decl *D, bool omitWrtClause = false) {
531+
const DifferentiableAttr *attr, ASTPrinter &printer,
532+
const PrintOptions &Options, const Decl *D, bool omitWrtClause = false) {
533533
assert(D);
534534
// Create a temporary string for the attribute argument text.
535535
std::string attrArgText;

0 commit comments

Comments
 (0)