Skip to content

Commit a748d8e

Browse files
committed
[NFC] Fixup RequirementRepr Printing To Use Only the Repr
If a semantic representation of the RequirementRepr is needed, then it should be resolved to a Requirement and printed.
1 parent 8be08b1 commit a748d8e

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,16 +1044,16 @@ class RequirementRepr {
10441044
StringRef AsWrittenString;
10451045

10461046
RequirementRepr(SourceLoc SeparatorLoc, RequirementReprKind Kind,
1047-
TypeLoc FirstType, TypeLoc SecondType)
1047+
TypeRepr *FirstType, TypeRepr *SecondType)
10481048
: SeparatorLoc(SeparatorLoc), Kind(Kind), Invalid(false),
10491049
FirstType(FirstType), SecondType(SecondType) { }
10501050

10511051
RequirementRepr(SourceLoc SeparatorLoc, RequirementReprKind Kind,
1052-
TypeLoc FirstType, LayoutConstraintLoc SecondLayout)
1052+
TypeRepr *FirstType, LayoutConstraintLoc SecondLayout)
10531053
: SeparatorLoc(SeparatorLoc), Kind(Kind), Invalid(false),
10541054
FirstType(FirstType), SecondLayout(SecondLayout) { }
10551055

1056-
void printImpl(ASTPrinter &OS, bool AsWritten) const;
1056+
void printImpl(ASTPrinter &OS) const;
10571057

10581058
public:
10591059
/// Construct a new type-constraint requirement.

lib/AST/ASTDumper.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,47 +121,49 @@ void RequirementRepr::dump() const {
121121
llvm::errs() << "\n";
122122
}
123123

124-
void RequirementRepr::printImpl(ASTPrinter &out, bool AsWritten) const {
125-
auto printTy = [&](const TypeLoc &TyLoc) {
126-
if (AsWritten && TyLoc.getTypeRepr()) {
127-
TyLoc.getTypeRepr()->print(out, PrintOptions());
128-
} else {
129-
TyLoc.getType().print(out, PrintOptions());
130-
}
131-
};
132-
124+
void RequirementRepr::printImpl(ASTPrinter &out) const {
133125
auto printLayoutConstraint =
134126
[&](const LayoutConstraintLoc &LayoutConstraintLoc) {
135127
LayoutConstraintLoc.getLayoutConstraint()->print(out, PrintOptions());
136128
};
137129

138130
switch (getKind()) {
139131
case RequirementReprKind::LayoutConstraint:
140-
printTy(getSubjectLoc());
132+
if (auto *repr = getSubjectRepr()) {
133+
repr->print(out, PrintOptions());
134+
}
141135
out << " : ";
142136
printLayoutConstraint(getLayoutConstraintLoc());
143137
break;
144138

145139
case RequirementReprKind::TypeConstraint:
146-
printTy(getSubjectLoc());
140+
if (auto *repr = getSubjectRepr()) {
141+
repr->print(out, PrintOptions());
142+
}
147143
out << " : ";
148-
printTy(getConstraintLoc());
144+
if (auto *repr = getConstraintRepr()) {
145+
repr->print(out, PrintOptions());
146+
}
149147
break;
150148

151149
case RequirementReprKind::SameType:
152-
printTy(getFirstTypeLoc());
150+
if (auto *repr = getFirstTypeRepr()) {
151+
repr->print(out, PrintOptions());
152+
}
153153
out << " == ";
154-
printTy(getSecondTypeLoc());
154+
if (auto *repr = getSecondTypeRepr()) {
155+
repr->print(out, PrintOptions());
156+
}
155157
break;
156158
}
157159
}
158160

159161
void RequirementRepr::print(raw_ostream &out) const {
160162
StreamPrinter printer(out);
161-
printImpl(printer, /*AsWritten=*/true);
163+
printImpl(printer);
162164
}
163165
void RequirementRepr::print(ASTPrinter &out) const {
164-
printImpl(out, /*AsWritten=*/true);
166+
printImpl(out);
165167
}
166168

167169
static void printTrailingRequirements(ASTPrinter &Printer,

0 commit comments

Comments
 (0)