mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge remote-tracking branch 'origin/main' into rebranch
This commit is contained in:
@@ -585,6 +585,11 @@ PreferTypeRepr("prefer-type-repr",
|
||||
llvm::cl::cat(Category),
|
||||
llvm::cl::init(true));
|
||||
|
||||
static llvm::cl::opt<bool> PrintForDebugging(
|
||||
"debug-print",
|
||||
llvm::cl::desc("Print using the debug representation for types"),
|
||||
llvm::cl::cat(Category), llvm::cl::init(true));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
FullyQualifiedTypes("fully-qualified-types",
|
||||
llvm::cl::desc("Print fully qualified types"),
|
||||
@@ -1186,14 +1191,15 @@ printResult(CancellableResult<ResultType> Result,
|
||||
}
|
||||
}
|
||||
|
||||
static int printTypeContextInfo(
|
||||
CancellableResult<TypeContextInfoResult> CancellableResult) {
|
||||
static int
|
||||
printTypeContextInfo(CancellableResult<TypeContextInfoResult> CancellableResult,
|
||||
const PrintOptions &PO) {
|
||||
return printResult<TypeContextInfoResult>(
|
||||
CancellableResult, [](const TypeContextInfoResult &Result) {
|
||||
CancellableResult, [&](const TypeContextInfoResult &Result) {
|
||||
llvm::outs() << "-----BEGIN TYPE CONTEXT INFO-----\n";
|
||||
for (auto resultItem : Result.Results) {
|
||||
llvm::outs() << "- TypeName: ";
|
||||
resultItem.ExpectedTy.print(llvm::outs());
|
||||
resultItem.ExpectedTy.print(llvm::outs(), PO);
|
||||
llvm::outs() << "\n";
|
||||
|
||||
llvm::outs() << " TypeUSR: ";
|
||||
@@ -1224,11 +1230,10 @@ static int printTypeContextInfo(
|
||||
});
|
||||
}
|
||||
|
||||
static int doTypeContextInfo(const CompilerInvocation &InitInvok,
|
||||
StringRef SourceFilename,
|
||||
StringRef SecondSourceFileName,
|
||||
StringRef CodeCompletionToken,
|
||||
bool CodeCompletionDiagnostics) {
|
||||
static int
|
||||
doTypeContextInfo(const CompilerInvocation &InitInvok, StringRef SourceFilename,
|
||||
StringRef SecondSourceFileName, StringRef CodeCompletionToken,
|
||||
bool CodeCompletionDiagnostics, const PrintOptions &PO) {
|
||||
return performWithCompletionLikeOperationParams(
|
||||
InitInvok, SourceFilename, SecondSourceFileName, CodeCompletionToken,
|
||||
CodeCompletionDiagnostics,
|
||||
@@ -1241,16 +1246,17 @@ static int doTypeContextInfo(const CompilerInvocation &InitInvok,
|
||||
Params.CompletionBuffer, Params.Offset, Params.DiagC,
|
||||
/*CancellationFlag=*/nullptr,
|
||||
[&](CancellableResult<TypeContextInfoResult> Result) {
|
||||
ExitCode = printTypeContextInfo(Result);
|
||||
ExitCode = printTypeContextInfo(Result, PO);
|
||||
});
|
||||
return ExitCode;
|
||||
});
|
||||
}
|
||||
|
||||
static int printConformingMethodList(
|
||||
CancellableResult<ConformingMethodListResults> CancellableResult) {
|
||||
CancellableResult<ConformingMethodListResults> CancellableResult,
|
||||
const PrintOptions &PO) {
|
||||
return printResult<ConformingMethodListResults>(
|
||||
CancellableResult, [](const ConformingMethodListResults &Results) {
|
||||
CancellableResult, [&](const ConformingMethodListResults &Results) {
|
||||
auto Result = Results.Result;
|
||||
if (!Result) {
|
||||
return 0;
|
||||
@@ -1258,7 +1264,7 @@ static int printConformingMethodList(
|
||||
llvm::outs() << "-----BEGIN CONFORMING METHOD LIST-----\n";
|
||||
|
||||
llvm::outs() << "- TypeName: ";
|
||||
Result->ExprType.print(llvm::outs());
|
||||
Result->ExprType.print(llvm::outs(), PO);
|
||||
llvm::outs() << "\n";
|
||||
|
||||
llvm::outs() << "- Members: ";
|
||||
@@ -1275,7 +1281,7 @@ static int printConformingMethodList(
|
||||
llvm::outs() << "\n";
|
||||
|
||||
llvm::outs() << " TypeName: ";
|
||||
resultTy.print(llvm::outs());
|
||||
resultTy.print(llvm::outs(), PO);
|
||||
llvm::outs() << "\n";
|
||||
|
||||
StringRef BriefDoc = VD->getSemanticBriefComment();
|
||||
@@ -1291,12 +1297,11 @@ static int printConformingMethodList(
|
||||
});
|
||||
}
|
||||
|
||||
static int
|
||||
doConformingMethodList(const CompilerInvocation &InitInvok,
|
||||
StringRef SourceFilename, StringRef SecondSourceFileName,
|
||||
StringRef CodeCompletionToken,
|
||||
bool CodeCompletionDiagnostics,
|
||||
const std::vector<std::string> expectedTypeNames) {
|
||||
static int doConformingMethodList(
|
||||
const CompilerInvocation &InitInvok, StringRef SourceFilename,
|
||||
StringRef SecondSourceFileName, StringRef CodeCompletionToken,
|
||||
bool CodeCompletionDiagnostics,
|
||||
const std::vector<std::string> expectedTypeNames, const PrintOptions &PO) {
|
||||
SmallVector<const char *, 4> typeNames;
|
||||
for (auto &name : expectedTypeNames)
|
||||
typeNames.push_back(name.c_str());
|
||||
@@ -1313,7 +1318,7 @@ doConformingMethodList(const CompilerInvocation &InitInvok,
|
||||
Params.CompletionBuffer, Params.Offset, Params.DiagC, typeNames,
|
||||
/*CancellationFlag=*/nullptr,
|
||||
[&](CancellableResult<ConformingMethodListResults> Result) {
|
||||
ExitCode = printConformingMethodList(Result);
|
||||
ExitCode = printConformingMethodList(Result, PO);
|
||||
});
|
||||
return ExitCode;
|
||||
});
|
||||
@@ -2754,7 +2759,8 @@ static int doPrintExpressionTypes(const CompilerInvocation &InitInvok,
|
||||
}
|
||||
|
||||
static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
|
||||
const std::vector<std::string> ModulesToPrint) {
|
||||
const std::vector<std::string> ModulesToPrint,
|
||||
const PrintOptions &PO) {
|
||||
using NodeKind = Demangle::Node::Kind;
|
||||
|
||||
CompilerInvocation Invocation(InitInvok);
|
||||
@@ -2775,8 +2781,6 @@ static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
|
||||
|
||||
int ExitCode = 0;
|
||||
|
||||
PrintOptions Options = PrintOptions::printDeclarations();
|
||||
|
||||
for (StringRef ModuleName : ModulesToPrint) {
|
||||
auto *M = getModuleByFullName(Context, ModuleName);
|
||||
if (!M) {
|
||||
@@ -2867,9 +2871,7 @@ static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
|
||||
|
||||
llvm::outs() << remangled << "\n";
|
||||
|
||||
auto Options = PrintOptions::printDeclarations();
|
||||
Options.PrintAccess = false;
|
||||
LTD->print(llvm::outs(), Options);
|
||||
LTD->print(llvm::outs(), PO);
|
||||
llvm::outs() << "\n";
|
||||
}
|
||||
}
|
||||
@@ -3410,8 +3412,7 @@ public:
|
||||
} // unnamed namespace
|
||||
|
||||
static int doPrintTypes(const CompilerInvocation &InitInvok,
|
||||
StringRef SourceFilename,
|
||||
bool FullyQualifiedTypes) {
|
||||
StringRef SourceFilename, const PrintOptions &PO) {
|
||||
CompilerInvocation Invocation(InitInvok);
|
||||
Invocation.getFrontendOptions().InputsAndOutputs.addInputFile(SourceFilename);
|
||||
|
||||
@@ -3427,9 +3428,7 @@ static int doPrintTypes(const CompilerInvocation &InitInvok,
|
||||
registerIDERequestFunctions(CI.getASTContext().evaluator);
|
||||
CI.performSema();
|
||||
|
||||
PrintOptions Options = PrintOptions::printDeclarations();
|
||||
Options.FullyQualifiedTypes = FullyQualifiedTypes;
|
||||
ASTTypePrinter Printer(CI.getSourceMgr(), Options);
|
||||
ASTTypePrinter Printer(CI.getSourceMgr(), PO);
|
||||
|
||||
CI.getMainModule()->walk(Printer);
|
||||
|
||||
@@ -3971,10 +3970,12 @@ class TypeReconstructWalker : public SourceEntityWalker {
|
||||
llvm::raw_ostream &Stream;
|
||||
llvm::DenseSet<ValueDecl *> SeenDecls;
|
||||
llvm::SmallVector<DeclContext *, 2> NestedDCs;
|
||||
const PrintOptions &PO;
|
||||
|
||||
public:
|
||||
TypeReconstructWalker(ASTContext &Ctx, llvm::raw_ostream &Stream)
|
||||
: Ctx(Ctx), Stream(Stream) {}
|
||||
TypeReconstructWalker(ASTContext &Ctx, llvm::raw_ostream &Stream,
|
||||
const PrintOptions &PO)
|
||||
: Ctx(Ctx), Stream(Stream), PO(PO) {}
|
||||
|
||||
bool walkToDeclPre(Decl *D, CharSourceRange range) override {
|
||||
if (auto *VD = dyn_cast<ValueDecl>(D)) {
|
||||
@@ -4019,7 +4020,7 @@ private:
|
||||
Demangle::getTypeForMangling(Ctx, mangledName));
|
||||
Stream << "type: ";
|
||||
if (ReconstructedType) {
|
||||
ReconstructedType->print(Stream);
|
||||
ReconstructedType->print(Stream, PO);
|
||||
} else {
|
||||
Stream << "FAILURE";
|
||||
}
|
||||
@@ -4044,7 +4045,11 @@ private:
|
||||
}
|
||||
|
||||
if (TypeDecl *reDecl = Demangle::getTypeDeclForUSR(Ctx, USR)) {
|
||||
PrintOptions POpts;
|
||||
PrintOptions POpts = PO.clone();
|
||||
POpts.TypeDefinitions = false;
|
||||
POpts.VarInitializers = false;
|
||||
POpts.FunctionDefinitions = false;
|
||||
POpts.PrintExprs = false;
|
||||
POpts.PreferTypeRepr = false;
|
||||
POpts.PrintParameterSpecifiers = true;
|
||||
reDecl->print(Stream, POpts);
|
||||
@@ -4056,7 +4061,7 @@ private:
|
||||
};
|
||||
|
||||
static int doReconstructType(const CompilerInvocation &InitInvok,
|
||||
StringRef SourceFilename) {
|
||||
StringRef SourceFilename, const PrintOptions &PO) {
|
||||
CompilerInvocation Invocation(InitInvok);
|
||||
Invocation.getFrontendOptions().InputsAndOutputs.addInputFile(SourceFilename);
|
||||
Invocation.getLangOptions().DisableAvailabilityChecking = false;
|
||||
@@ -4080,15 +4085,14 @@ static int doReconstructType(const CompilerInvocation &InitInvok,
|
||||
break;
|
||||
}
|
||||
assert(SF && "no source file?");
|
||||
TypeReconstructWalker Walker(SF->getASTContext(), llvm::outs());
|
||||
TypeReconstructWalker Walker(SF->getASTContext(), llvm::outs(), PO);
|
||||
Walker.walk(SF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int doPrintRangeInfo(const CompilerInvocation &InitInvok,
|
||||
StringRef SourceFileName,
|
||||
StringRef StartPos,
|
||||
StringRef EndPos) {
|
||||
StringRef SourceFileName, StringRef StartPos,
|
||||
StringRef EndPos, const PrintOptions &PO) {
|
||||
auto StartOp = parseLineCol(StartPos);
|
||||
auto EndOp = parseLineCol(EndPos);
|
||||
if (!StartOp.has_value() || !EndOp.has_value())
|
||||
@@ -4127,7 +4131,7 @@ static int doPrintRangeInfo(const CompilerInvocation &InitInvok,
|
||||
EndLineCol.second);
|
||||
ResolvedRangeInfo Result = evaluateOrDefault(SF->getASTContext().evaluator,
|
||||
RangeInfoRequest(RangeInfoOwner({SF, StartLoc, EndLoc})), ResolvedRangeInfo());
|
||||
Result.print(llvm::outs());
|
||||
Result.print(llvm::outs(), PO);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4736,6 +4740,7 @@ int main(int argc, char *argv[]) {
|
||||
return PrintOptions::printDocInterface();
|
||||
} else {
|
||||
auto PrintOpts = PrintOptions::printEverything();
|
||||
PrintOpts.PrintTypesForDebugging = options::PrintForDebugging;
|
||||
PrintOpts.FullyQualifiedTypes = options::FullyQualifiedTypes;
|
||||
PrintOpts.FullyQualifiedTypesIfAmbiguous =
|
||||
options::FullyQualifiedTypesIfAmbiguous;
|
||||
@@ -4828,11 +4833,10 @@ int main(int argc, char *argv[]) {
|
||||
llvm::errs() << "token name required\n";
|
||||
return 1;
|
||||
}
|
||||
ExitCode = doTypeContextInfo(InitInvok,
|
||||
options::SourceFilename,
|
||||
options::SecondSourceFilename,
|
||||
options::CodeCompletionToken,
|
||||
options::CodeCompletionDiagnostics);
|
||||
ExitCode = doTypeContextInfo(InitInvok, options::SourceFilename,
|
||||
options::SecondSourceFilename,
|
||||
options::CodeCompletionToken,
|
||||
options::CodeCompletionDiagnostics, PrintOpts);
|
||||
break;
|
||||
|
||||
case ActionType::PrintExpressionTypes:
|
||||
@@ -4846,12 +4850,10 @@ int main(int argc, char *argv[]) {
|
||||
llvm::errs() << "token name required\n";
|
||||
return 1;
|
||||
}
|
||||
ExitCode = doConformingMethodList(InitInvok,
|
||||
options::SourceFilename,
|
||||
options::SecondSourceFilename,
|
||||
options::CodeCompletionToken,
|
||||
options::CodeCompletionDiagnostics,
|
||||
options::ConformingMethodListExpectedTypes);
|
||||
ExitCode = doConformingMethodList(
|
||||
InitInvok, options::SourceFilename, options::SecondSourceFilename,
|
||||
options::CodeCompletionToken, options::CodeCompletionDiagnostics,
|
||||
options::ConformingMethodListExpectedTypes, PrintOpts);
|
||||
break;
|
||||
|
||||
case ActionType::SyntaxColoring:
|
||||
@@ -4892,7 +4894,7 @@ int main(int argc, char *argv[]) {
|
||||
break;
|
||||
}
|
||||
case ActionType::PrintLocalTypes:
|
||||
ExitCode = doPrintLocalTypes(InitInvok, options::ModuleToPrint);
|
||||
ExitCode = doPrintLocalTypes(InitInvok, options::ModuleToPrint, PrintOpts);
|
||||
break;
|
||||
|
||||
case ActionType::PrintModuleGroups:
|
||||
@@ -4943,8 +4945,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
case ActionType::PrintTypes:
|
||||
ExitCode = doPrintTypes(InitInvok, options::SourceFilename,
|
||||
options::FullyQualifiedTypes);
|
||||
ExitCode = doPrintTypes(InitInvok, options::SourceFilename, PrintOpts);
|
||||
break;
|
||||
|
||||
case ActionType::PrintComments:
|
||||
@@ -4979,12 +4980,12 @@ int main(int argc, char *argv[]) {
|
||||
options::USR);
|
||||
break;
|
||||
case ActionType::ReconstructType:
|
||||
ExitCode = doReconstructType(InitInvok, options::SourceFilename);
|
||||
ExitCode = doReconstructType(InitInvok, options::SourceFilename, PrintOpts);
|
||||
break;
|
||||
case ActionType::Range:
|
||||
ExitCode = doPrintRangeInfo(InitInvok, options::SourceFilename,
|
||||
options::LineColumnPair,
|
||||
options::EndLineColumnPair);
|
||||
options::EndLineColumnPair, PrintOpts);
|
||||
break;
|
||||
case ActionType::PrintIndexedSymbols:
|
||||
if (options::ModuleToPrint.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user