Skip to content

Fix a couple references to nullptr #63666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,11 +1269,10 @@ static bool performAction(CompilerInstance &Instance,
int &ReturnValue,
FrontendObserver *observer) {
const auto &opts = Instance.getInvocation().getFrontendOptions();
auto &Context = Instance.getASTContext();
switch (Instance.getInvocation().getFrontendOptions().RequestedAction) {
// MARK: Trivial Actions
case FrontendOptions::ActionType::NoneAction:
return Context.hadError();
return Instance.getASTContext().hadError();
case FrontendOptions::ActionType::PrintVersion:
return printSwiftVersion(Instance.getInvocation());
case FrontendOptions::ActionType::PrintFeature:
Expand Down Expand Up @@ -1332,7 +1331,7 @@ static bool performAction(CompilerInstance &Instance,
}, /*runDespiteErrors=*/true);
case FrontendOptions::ActionType::DumpInterfaceHash:
getPrimaryOrMainSourceFile(Instance).dumpInterfaceHash(llvm::errs());
return Context.hadError();
return Instance.getASTContext().hadError();
case FrontendOptions::ActionType::EmitImportedModules:
return emitImportedModules(Instance.getMainModule(), opts);

Expand Down Expand Up @@ -1372,7 +1371,7 @@ static bool performAction(CompilerInstance &Instance,
}

assert(false && "Unhandled case in performCompile!");
return Context.hadError();
return Instance.getASTContext().hadError();
}

/// Performs the compile requested by the user.
Expand Down
58 changes: 30 additions & 28 deletions tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ doConformingMethodList(const CompilerInvocation &InitInvok,
static void printCodeCompletionResultsImpl(
ArrayRef<CodeCompletionResult *> Results, llvm::raw_ostream &OS,
bool IncludeKeywords, bool IncludeComments, bool IncludeSourceText,
bool PrintAnnotatedDescription, const ASTContext &Ctx) {
bool PrintAnnotatedDescription, const ASTContext *Ctx) {
unsigned NumResults = 0;
for (auto Result : Results) {
if (!IncludeKeywords &&
Expand Down Expand Up @@ -1134,30 +1134,33 @@ static void printCodeCompletionResultsImpl(
OS << "; comment=" << comment;
}

SmallString<256> Scratch;
auto DiagSeverityAndMessage =
Result->getDiagnosticSeverityAndMessage(Scratch, Ctx);
if (DiagSeverityAndMessage.first !=
CodeCompletionDiagnosticSeverity::None) {
OS << "; diagnostics=" << comment;
switch (DiagSeverityAndMessage.first) {
case CodeCompletionDiagnosticSeverity::Error:
OS << "error";
break;
case CodeCompletionDiagnosticSeverity::Warning:
OS << "warning";
break;
case CodeCompletionDiagnosticSeverity::Remark:
OS << "remark";
break;
case CodeCompletionDiagnosticSeverity::Note:
OS << "note";
break;
case CodeCompletionDiagnosticSeverity::None:
llvm_unreachable("none");
}
if (Ctx) {
// Only print diagnostics if we have an ASTContext
SmallString<256> Scratch;
OS << ":" << DiagSeverityAndMessage.second;
auto DiagSeverityAndMessage =
Result->getDiagnosticSeverityAndMessage(Scratch, *Ctx);
if (DiagSeverityAndMessage.first !=
CodeCompletionDiagnosticSeverity::None) {
OS << "; diagnostics=" << comment;
switch (DiagSeverityAndMessage.first) {
case CodeCompletionDiagnosticSeverity::Error:
OS << "error";
break;
case CodeCompletionDiagnosticSeverity::Warning:
OS << "warning";
break;
case CodeCompletionDiagnosticSeverity::Remark:
OS << "remark";
break;
case CodeCompletionDiagnosticSeverity::Note:
OS << "note";
break;
case CodeCompletionDiagnosticSeverity::None:
llvm_unreachable("none");
}
SmallString<256> Scratch;
OS << ":" << DiagSeverityAndMessage.second;
}
}

OS << "\n";
Expand Down Expand Up @@ -1188,7 +1191,7 @@ static int printCodeCompletionResults(
printCodeCompletionResultsImpl(
Result.ResultSink.Results, OS, IncludeKeywords, IncludeComments,
IncludeSourceText, PrintAnnotatedDescription,
Result.Info.compilerInstance->getASTContext());
&Result.Info.compilerInstance->getASTContext());
printCodeCompletionLookedupTypeNames(
Result.Info.completionContext->LookedupNominalTypeNames, OS);
return 0;
Expand Down Expand Up @@ -1570,7 +1573,7 @@ static int doBatchCodeCompletion(const CompilerInvocation &InitInvok,
Result->ResultSink.Results, OS, IncludeKeywords,
IncludeComments, IncludeSourceText,
CodeCompletionAnnotateResults,
Result->Info.compilerInstance->getASTContext());
&Result->Info.compilerInstance->getASTContext());
printCodeCompletionLookedupTypeNames(
Result->Info.completionContext->LookedupNominalTypeNames, OS);
break;
Expand Down Expand Up @@ -4249,12 +4252,11 @@ int main(int argc, char *argv[]) {
ContextualNotRecommendedReason::None);
contextualResults.push_back(contextualResult);
}
auto CompInstance = std::make_unique<CompilerInstance>();
printCodeCompletionResultsImpl(
contextualResults, llvm::outs(), options::CodeCompletionKeywords,
options::CodeCompletionComments, options::CodeCompletionSourceText,
options::CodeCompletionAnnotateResults,
CompInstance->getASTContext());
/*Ctx=*/nullptr);
}

return 0;
Expand Down