36
36
#include " swift/Basic/StringExtras.h"
37
37
#include " swift/Config.h"
38
38
#include " swift/Parse/Lexer.h"
39
- #include " swift/Sema/IDETypeChecking.h"
40
39
#include " swift/Strings.h"
41
40
#include " clang/AST/ASTContext.h"
42
41
#include " clang/AST/Decl.h"
52
51
53
52
using namespace swift ;
54
53
55
- PrintOptions PrintOptions::printTypeInterface (Type T) {
56
- PrintOptions result = printInterface ();
57
- result.PrintExtensionFromConformingProtocols = true ;
58
- result.TransformContext = TypeTransformContext (T);
59
- result.printExtensionContentAsMembers = [T](const ExtensionDecl *ED) {
60
- return isExtensionApplied (*T->getNominalOrBoundGenericNominal ()->
61
- getDeclContext (), T, ED);
62
- };
63
- return result;
64
- }
65
-
66
54
void PrintOptions::setBaseType (Type T) {
67
55
TransformContext = TypeTransformContext (T);
68
56
}
@@ -830,17 +818,17 @@ static const unsigned ErrorDepth = ~0U;
830
818
// / A helper function to return the depth of a type.
831
819
static unsigned getDepthOfType (Type ty) {
832
820
unsigned depth = ErrorDepth;
833
-
821
+
834
822
auto combineDepth = [&depth](unsigned newDepth) -> bool {
835
823
// If there is no current depth (depth == ErrorDepth), then assign to
836
824
// newDepth; otherwise, choose the deeper of the current and new depth.
837
-
825
+
838
826
// Since ErrorDepth == ~0U, ErrorDepth + 1 == 0, which is smaller than any
839
827
// valid depth + 1.
840
828
depth = std::max (depth+1U , newDepth+1U ) - 1U ;
841
829
return false ;
842
830
};
843
-
831
+
844
832
ty.findIf ([combineDepth](Type t) -> bool {
845
833
if (auto paramTy = t->getAs <GenericTypeParamType>())
846
834
return combineDepth (paramTy->getDepth ());
@@ -856,7 +844,7 @@ static unsigned getDepthOfType(Type ty) {
856
844
857
845
return false ;
858
846
});
859
-
847
+
860
848
return depth;
861
849
}
862
850
@@ -1222,16 +1210,8 @@ void PrintAST::printRequirement(const Requirement &req) {
1222
1210
printType (req.getSecondType ());
1223
1211
}
1224
1212
1225
- bool swift::shouldPrintPattern (const Pattern *P, PrintOptions &Options) {
1226
- bool ShouldPrint = false ;
1227
- P->forEachVariable ([&](VarDecl *VD) {
1228
- ShouldPrint |= shouldPrint (VD, Options);
1229
- });
1230
- return ShouldPrint;
1231
- }
1232
-
1233
1213
bool PrintAST::shouldPrintPattern (const Pattern *P) {
1234
- return swift::shouldPrintPattern (P, Options );
1214
+ return Options. shouldPrint (P );
1235
1215
}
1236
1216
1237
1217
void PrintAST::printPatternType (const Pattern *P) {
@@ -1241,24 +1221,15 @@ void PrintAST::printPatternType(const Pattern *P) {
1241
1221
}
1242
1222
}
1243
1223
1244
- static bool shouldPrintAsFavorable (const Decl *D, PrintOptions &Options) {
1245
- if (!Options.TransformContext || !D->getDeclContext ()->isExtensionContext () ||
1246
- !Options.TransformContext ->isPrintingSynthesizedExtension ())
1247
- return true ;
1248
- NominalTypeDecl *Target = Options.TransformContext ->getNominal ();
1249
- Type BaseTy = Target->getDeclaredTypeInContext ();
1250
- const auto *FD = dyn_cast<FuncDecl>(D);
1251
- if (!FD)
1252
- return true ;
1253
- ResolvedMemberResult Result = resolveValueMember (*Target->getDeclContext (),
1254
- BaseTy,
1255
- FD->getEffectiveFullName ());
1256
- return !(Result.hasBestOverload () && Result.getBestOverload () != D);
1224
+ bool ShouldPrintChecker::shouldPrint (const Pattern *P, PrintOptions &Options) {
1225
+ bool ShouldPrint = false ;
1226
+ P->forEachVariable ([&](const VarDecl *VD) {
1227
+ ShouldPrint |= shouldPrint (VD, Options);
1228
+ });
1229
+ return ShouldPrint;
1257
1230
}
1258
1231
1259
- bool swift::shouldPrint (const Decl *D, PrintOptions &Options) {
1260
- if (!shouldPrintAsFavorable (D, Options))
1261
- return false ;
1232
+ bool ShouldPrintChecker::shouldPrint (const Decl *D, PrintOptions &Options) {
1262
1233
if (auto *ED= dyn_cast<ExtensionDecl>(D)) {
1263
1234
if (Options.printExtensionContentAsMembers (ED))
1264
1235
return false ;
@@ -1358,7 +1329,7 @@ bool swift::shouldPrint(const Decl *D, PrintOptions &Options) {
1358
1329
if (auto *PD = dyn_cast<PatternBindingDecl>(D)) {
1359
1330
auto ShouldPrint = false ;
1360
1331
for (auto entry : PD->getPatternList ()) {
1361
- ShouldPrint |= shouldPrintPattern (entry.getPattern (), Options);
1332
+ ShouldPrint |= shouldPrint (entry.getPattern (), Options);
1362
1333
if (ShouldPrint)
1363
1334
return true ;
1364
1335
}
@@ -1368,7 +1339,7 @@ bool swift::shouldPrint(const Decl *D, PrintOptions &Options) {
1368
1339
}
1369
1340
1370
1341
bool PrintAST::shouldPrint (const Decl *D, bool Notify) {
1371
- auto Result = swift:: shouldPrint (D, Options );
1342
+ auto Result = Options. shouldPrint (D);
1372
1343
if (!Result && Notify)
1373
1344
Printer.callAvoidPrintDeclPost (D);
1374
1345
return Result;
@@ -3600,7 +3571,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3600
3571
};
3601
3572
3602
3573
printFunctionExtInfo (T->getExtInfo ());
3603
-
3574
+
3604
3575
// If we're stripping argument labels from types, do it when printing.
3605
3576
Type inputType = T->getInput ();
3606
3577
if (auto tupleTy = dyn_cast<TupleType>(inputType.getPointer ())) {
@@ -3614,15 +3585,15 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3614
3585
bool needsParens =
3615
3586
!isa<ParenType>(inputType.getPointer ()) &&
3616
3587
!inputType->is <TupleType>();
3617
-
3588
+
3618
3589
if (needsParens)
3619
3590
Printer << " (" ;
3620
3591
3621
3592
visit (inputType);
3622
-
3593
+
3623
3594
if (needsParens)
3624
3595
Printer << " )" ;
3625
-
3596
+
3626
3597
if (T->throws ())
3627
3598
Printer << " " << tok::kw_throws;
3628
3599
@@ -3653,7 +3624,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3653
3624
bool needsParens =
3654
3625
!isa<ParenType>(T->getInput ().getPointer ()) &&
3655
3626
!T->getInput ()->is <TupleType>();
3656
-
3627
+
3657
3628
if (needsParens)
3658
3629
Printer << " (" ;
3659
3630
@@ -3742,7 +3713,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3742
3713
PrintOptions subOptions = Options;
3743
3714
subOptions.GenericEnv = nullptr ;
3744
3715
TypePrinter sub (Printer, subOptions);
3745
-
3716
+
3746
3717
// Capture list used here to ensure we don't print anything using `this`
3747
3718
// printer, but only the sub-Printer.
3748
3719
[&sub, T]{
@@ -3764,7 +3735,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3764
3735
sub.Printer << " }" ;
3765
3736
}();
3766
3737
}
3767
-
3738
+
3768
3739
// The arguments to the layout, if any, do come from the outer environment.
3769
3740
if (!T->getGenericArgs ().empty ()) {
3770
3741
Printer << " <" ;
0 commit comments