@@ -1186,14 +1186,15 @@ printResult(CancellableResult<ResultType> Result,
1186
1186
}
1187
1187
}
1188
1188
1189
- static int printTypeContextInfo (
1190
- CancellableResult<TypeContextInfoResult> CancellableResult) {
1189
+ static int
1190
+ printTypeContextInfo (CancellableResult<TypeContextInfoResult> CancellableResult,
1191
+ const PrintOptions &PO) {
1191
1192
return printResult<TypeContextInfoResult>(
1192
- CancellableResult, [](const TypeContextInfoResult &Result) {
1193
+ CancellableResult, [& ](const TypeContextInfoResult &Result) {
1193
1194
llvm::outs () << " -----BEGIN TYPE CONTEXT INFO-----\n " ;
1194
1195
for (auto resultItem : Result.Results ) {
1195
1196
llvm::outs () << " - TypeName: " ;
1196
- resultItem.ExpectedTy .print (llvm::outs ());
1197
+ resultItem.ExpectedTy .print (llvm::outs (), PO );
1197
1198
llvm::outs () << " \n " ;
1198
1199
1199
1200
llvm::outs () << " TypeUSR: " ;
@@ -1224,11 +1225,10 @@ static int printTypeContextInfo(
1224
1225
});
1225
1226
}
1226
1227
1227
- static int doTypeContextInfo (const CompilerInvocation &InitInvok,
1228
- StringRef SourceFilename,
1229
- StringRef SecondSourceFileName,
1230
- StringRef CodeCompletionToken,
1231
- bool CodeCompletionDiagnostics) {
1228
+ static int
1229
+ doTypeContextInfo (const CompilerInvocation &InitInvok, StringRef SourceFilename,
1230
+ StringRef SecondSourceFileName, StringRef CodeCompletionToken,
1231
+ bool CodeCompletionDiagnostics, const PrintOptions &PO) {
1232
1232
return performWithCompletionLikeOperationParams (
1233
1233
InitInvok, SourceFilename, SecondSourceFileName, CodeCompletionToken,
1234
1234
CodeCompletionDiagnostics,
@@ -1241,24 +1241,25 @@ static int doTypeContextInfo(const CompilerInvocation &InitInvok,
1241
1241
Params.CompletionBuffer , Params.Offset , Params.DiagC ,
1242
1242
/* CancellationFlag=*/ nullptr ,
1243
1243
[&](CancellableResult<TypeContextInfoResult> Result) {
1244
- ExitCode = printTypeContextInfo (Result);
1244
+ ExitCode = printTypeContextInfo (Result, PO );
1245
1245
});
1246
1246
return ExitCode;
1247
1247
});
1248
1248
}
1249
1249
1250
1250
static int printConformingMethodList (
1251
- CancellableResult<ConformingMethodListResults> CancellableResult) {
1251
+ CancellableResult<ConformingMethodListResults> CancellableResult,
1252
+ const PrintOptions &PO) {
1252
1253
return printResult<ConformingMethodListResults>(
1253
- CancellableResult, [](const ConformingMethodListResults &Results) {
1254
+ CancellableResult, [& ](const ConformingMethodListResults &Results) {
1254
1255
auto Result = Results.Result ;
1255
1256
if (!Result) {
1256
1257
return 0 ;
1257
1258
}
1258
1259
llvm::outs () << " -----BEGIN CONFORMING METHOD LIST-----\n " ;
1259
1260
1260
1261
llvm::outs () << " - TypeName: " ;
1261
- Result->ExprType .print (llvm::outs ());
1262
+ Result->ExprType .print (llvm::outs (), PO );
1262
1263
llvm::outs () << " \n " ;
1263
1264
1264
1265
llvm::outs () << " - Members: " ;
@@ -1275,7 +1276,7 @@ static int printConformingMethodList(
1275
1276
llvm::outs () << " \n " ;
1276
1277
1277
1278
llvm::outs () << " TypeName: " ;
1278
- resultTy.print (llvm::outs ());
1279
+ resultTy.print (llvm::outs (), PO );
1279
1280
llvm::outs () << " \n " ;
1280
1281
1281
1282
StringRef BriefDoc = VD->getSemanticBriefComment ();
@@ -1291,12 +1292,11 @@ static int printConformingMethodList(
1291
1292
});
1292
1293
}
1293
1294
1294
- static int
1295
- doConformingMethodList (const CompilerInvocation &InitInvok,
1296
- StringRef SourceFilename, StringRef SecondSourceFileName,
1297
- StringRef CodeCompletionToken,
1298
- bool CodeCompletionDiagnostics,
1299
- const std::vector<std::string> expectedTypeNames) {
1295
+ static int doConformingMethodList (
1296
+ const CompilerInvocation &InitInvok, StringRef SourceFilename,
1297
+ StringRef SecondSourceFileName, StringRef CodeCompletionToken,
1298
+ bool CodeCompletionDiagnostics,
1299
+ const std::vector<std::string> expectedTypeNames, const PrintOptions &PO) {
1300
1300
SmallVector<const char *, 4 > typeNames;
1301
1301
for (auto &name : expectedTypeNames)
1302
1302
typeNames.push_back (name.c_str ());
@@ -1313,7 +1313,7 @@ doConformingMethodList(const CompilerInvocation &InitInvok,
1313
1313
Params.CompletionBuffer , Params.Offset , Params.DiagC , typeNames,
1314
1314
/* CancellationFlag=*/ nullptr ,
1315
1315
[&](CancellableResult<ConformingMethodListResults> Result) {
1316
- ExitCode = printConformingMethodList (Result);
1316
+ ExitCode = printConformingMethodList (Result, PO );
1317
1317
});
1318
1318
return ExitCode;
1319
1319
});
@@ -2754,7 +2754,8 @@ static int doPrintExpressionTypes(const CompilerInvocation &InitInvok,
2754
2754
}
2755
2755
2756
2756
static int doPrintLocalTypes (const CompilerInvocation &InitInvok,
2757
- const std::vector<std::string> ModulesToPrint) {
2757
+ const std::vector<std::string> ModulesToPrint,
2758
+ const PrintOptions &PO) {
2758
2759
using NodeKind = Demangle::Node::Kind;
2759
2760
2760
2761
CompilerInvocation Invocation (InitInvok);
@@ -2775,8 +2776,6 @@ static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
2775
2776
2776
2777
int ExitCode = 0 ;
2777
2778
2778
- PrintOptions Options = PrintOptions::printDeclarations ();
2779
-
2780
2779
for (StringRef ModuleName : ModulesToPrint) {
2781
2780
auto *M = getModuleByFullName (Context, ModuleName);
2782
2781
if (!M) {
@@ -2867,9 +2866,7 @@ static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
2867
2866
2868
2867
llvm::outs () << remangled << " \n " ;
2869
2868
2870
- auto Options = PrintOptions::printDeclarations ();
2871
- Options.PrintAccess = false ;
2872
- LTD->print (llvm::outs (), Options);
2869
+ LTD->print (llvm::outs (), PO);
2873
2870
llvm::outs () << " \n " ;
2874
2871
}
2875
2872
}
@@ -3410,8 +3407,7 @@ class ASTTypePrinter : public ASTWalker {
3410
3407
} // unnamed namespace
3411
3408
3412
3409
static int doPrintTypes (const CompilerInvocation &InitInvok,
3413
- StringRef SourceFilename,
3414
- bool FullyQualifiedTypes) {
3410
+ StringRef SourceFilename, const PrintOptions &PO) {
3415
3411
CompilerInvocation Invocation (InitInvok);
3416
3412
Invocation.getFrontendOptions ().InputsAndOutputs .addInputFile (SourceFilename);
3417
3413
@@ -3427,9 +3423,7 @@ static int doPrintTypes(const CompilerInvocation &InitInvok,
3427
3423
registerIDERequestFunctions (CI.getASTContext ().evaluator );
3428
3424
CI.performSema ();
3429
3425
3430
- PrintOptions Options = PrintOptions::printDeclarations ();
3431
- Options.FullyQualifiedTypes = FullyQualifiedTypes;
3432
- ASTTypePrinter Printer (CI.getSourceMgr (), Options);
3426
+ ASTTypePrinter Printer (CI.getSourceMgr (), PO);
3433
3427
3434
3428
CI.getMainModule ()->walk (Printer);
3435
3429
@@ -3971,10 +3965,12 @@ class TypeReconstructWalker : public SourceEntityWalker {
3971
3965
llvm::raw_ostream &Stream;
3972
3966
llvm::DenseSet<ValueDecl *> SeenDecls;
3973
3967
llvm::SmallVector<DeclContext *, 2 > NestedDCs;
3968
+ const PrintOptions &PO;
3974
3969
3975
3970
public:
3976
- TypeReconstructWalker (ASTContext &Ctx, llvm::raw_ostream &Stream)
3977
- : Ctx(Ctx), Stream(Stream) {}
3971
+ TypeReconstructWalker (ASTContext &Ctx, llvm::raw_ostream &Stream,
3972
+ const PrintOptions &PO)
3973
+ : Ctx(Ctx), Stream(Stream), PO(PO) {}
3978
3974
3979
3975
bool walkToDeclPre (Decl *D, CharSourceRange range) override {
3980
3976
if (auto *VD = dyn_cast<ValueDecl>(D)) {
@@ -4019,7 +4015,7 @@ class TypeReconstructWalker : public SourceEntityWalker {
4019
4015
Demangle::getTypeForMangling (Ctx, mangledName));
4020
4016
Stream << " type: " ;
4021
4017
if (ReconstructedType) {
4022
- ReconstructedType->print (Stream);
4018
+ ReconstructedType->print (Stream, PO );
4023
4019
} else {
4024
4020
Stream << " FAILURE" ;
4025
4021
}
@@ -4044,7 +4040,11 @@ class TypeReconstructWalker : public SourceEntityWalker {
4044
4040
}
4045
4041
4046
4042
if (TypeDecl *reDecl = Demangle::getTypeDeclForUSR (Ctx, USR)) {
4047
- PrintOptions POpts;
4043
+ PrintOptions POpts = PO.clone ();
4044
+ POpts.TypeDefinitions = false ;
4045
+ POpts.VarInitializers = false ;
4046
+ POpts.FunctionDefinitions = false ;
4047
+ POpts.PrintExprs = false ;
4048
4048
POpts.PreferTypeRepr = false ;
4049
4049
POpts.PrintParameterSpecifiers = true ;
4050
4050
reDecl->print (Stream, POpts);
@@ -4056,7 +4056,7 @@ class TypeReconstructWalker : public SourceEntityWalker {
4056
4056
};
4057
4057
4058
4058
static int doReconstructType (const CompilerInvocation &InitInvok,
4059
- StringRef SourceFilename) {
4059
+ StringRef SourceFilename, const PrintOptions &PO ) {
4060
4060
CompilerInvocation Invocation (InitInvok);
4061
4061
Invocation.getFrontendOptions ().InputsAndOutputs .addInputFile (SourceFilename);
4062
4062
Invocation.getLangOptions ().DisableAvailabilityChecking = false ;
@@ -4080,15 +4080,14 @@ static int doReconstructType(const CompilerInvocation &InitInvok,
4080
4080
break ;
4081
4081
}
4082
4082
assert (SF && " no source file?" );
4083
- TypeReconstructWalker Walker (SF->getASTContext (), llvm::outs ());
4083
+ TypeReconstructWalker Walker (SF->getASTContext (), llvm::outs (), PO );
4084
4084
Walker.walk (SF);
4085
4085
return 0 ;
4086
4086
}
4087
4087
4088
4088
static int doPrintRangeInfo (const CompilerInvocation &InitInvok,
4089
- StringRef SourceFileName,
4090
- StringRef StartPos,
4091
- StringRef EndPos) {
4089
+ StringRef SourceFileName, StringRef StartPos,
4090
+ StringRef EndPos, const PrintOptions &PO) {
4092
4091
auto StartOp = parseLineCol (StartPos);
4093
4092
auto EndOp = parseLineCol (EndPos);
4094
4093
if (!StartOp.has_value () || !EndOp.has_value ())
@@ -4127,7 +4126,7 @@ static int doPrintRangeInfo(const CompilerInvocation &InitInvok,
4127
4126
EndLineCol.second );
4128
4127
ResolvedRangeInfo Result = evaluateOrDefault (SF->getASTContext ().evaluator ,
4129
4128
RangeInfoRequest (RangeInfoOwner ({SF, StartLoc, EndLoc})), ResolvedRangeInfo ());
4130
- Result.print (llvm::outs ());
4129
+ Result.print (llvm::outs (), PO );
4131
4130
return 0 ;
4132
4131
}
4133
4132
@@ -4828,11 +4827,10 @@ int main(int argc, char *argv[]) {
4828
4827
llvm::errs () << " token name required\n " ;
4829
4828
return 1 ;
4830
4829
}
4831
- ExitCode = doTypeContextInfo (InitInvok,
4832
- options::SourceFilename,
4833
- options::SecondSourceFilename,
4834
- options::CodeCompletionToken,
4835
- options::CodeCompletionDiagnostics);
4830
+ ExitCode = doTypeContextInfo (InitInvok, options::SourceFilename,
4831
+ options::SecondSourceFilename,
4832
+ options::CodeCompletionToken,
4833
+ options::CodeCompletionDiagnostics, PrintOpts);
4836
4834
break ;
4837
4835
4838
4836
case ActionType::PrintExpressionTypes:
@@ -4846,12 +4844,10 @@ int main(int argc, char *argv[]) {
4846
4844
llvm::errs () << " token name required\n " ;
4847
4845
return 1 ;
4848
4846
}
4849
- ExitCode = doConformingMethodList (InitInvok,
4850
- options::SourceFilename,
4851
- options::SecondSourceFilename,
4852
- options::CodeCompletionToken,
4853
- options::CodeCompletionDiagnostics,
4854
- options::ConformingMethodListExpectedTypes);
4847
+ ExitCode = doConformingMethodList (
4848
+ InitInvok, options::SourceFilename, options::SecondSourceFilename,
4849
+ options::CodeCompletionToken, options::CodeCompletionDiagnostics,
4850
+ options::ConformingMethodListExpectedTypes, PrintOpts);
4855
4851
break ;
4856
4852
4857
4853
case ActionType::SyntaxColoring:
@@ -4892,7 +4888,7 @@ int main(int argc, char *argv[]) {
4892
4888
break ;
4893
4889
}
4894
4890
case ActionType::PrintLocalTypes:
4895
- ExitCode = doPrintLocalTypes (InitInvok, options::ModuleToPrint);
4891
+ ExitCode = doPrintLocalTypes (InitInvok, options::ModuleToPrint, PrintOpts );
4896
4892
break ;
4897
4893
4898
4894
case ActionType::PrintModuleGroups:
@@ -4943,8 +4939,7 @@ int main(int argc, char *argv[]) {
4943
4939
}
4944
4940
4945
4941
case ActionType::PrintTypes:
4946
- ExitCode = doPrintTypes (InitInvok, options::SourceFilename,
4947
- options::FullyQualifiedTypes);
4942
+ ExitCode = doPrintTypes (InitInvok, options::SourceFilename, PrintOpts);
4948
4943
break ;
4949
4944
4950
4945
case ActionType::PrintComments:
@@ -4979,12 +4974,12 @@ int main(int argc, char *argv[]) {
4979
4974
options::USR);
4980
4975
break ;
4981
4976
case ActionType::ReconstructType:
4982
- ExitCode = doReconstructType (InitInvok, options::SourceFilename);
4977
+ ExitCode = doReconstructType (InitInvok, options::SourceFilename, PrintOpts );
4983
4978
break ;
4984
4979
case ActionType::Range:
4985
4980
ExitCode = doPrintRangeInfo (InitInvok, options::SourceFilename,
4986
4981
options::LineColumnPair,
4987
- options::EndLineColumnPair);
4982
+ options::EndLineColumnPair, PrintOpts );
4988
4983
break ;
4989
4984
case ActionType::PrintIndexedSymbols:
4990
4985
if (options::ModuleToPrint.empty ()) {
0 commit comments