mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SourceKit] Mark functions on CancellableResult const
This commit is contained in:
@@ -118,25 +118,25 @@ public:
|
||||
|
||||
/// Return the result kind this \c CancellableResult represents: success,
|
||||
/// failure or cancelled.
|
||||
CancellableResultKind getKind() { return Kind; }
|
||||
CancellableResultKind getKind() const { return Kind; }
|
||||
|
||||
/// Assuming that the result represents success, return the underlying result
|
||||
/// value.
|
||||
ResultType &getResult() {
|
||||
const ResultType &getResult() const {
|
||||
assert(getKind() == CancellableResultKind::Success);
|
||||
return Result;
|
||||
}
|
||||
|
||||
/// Assuming that the result represents success, retrieve members of the
|
||||
/// underlying result value.
|
||||
ResultType *operator->() { return &getResult(); }
|
||||
const ResultType *operator->() { return &getResult(); }
|
||||
|
||||
/// Assuming that the result represents success, return the underlying result
|
||||
/// value.
|
||||
ResultType &operator*() { return getResult(); }
|
||||
const ResultType &operator*() { return getResult(); }
|
||||
|
||||
/// Assuming that the result represents a failure, return the error message.
|
||||
std::string getError() {
|
||||
std::string getError() const {
|
||||
assert(getKind() == CancellableResultKind::Failure);
|
||||
return Error;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public:
|
||||
template <typename NewResultType>
|
||||
void
|
||||
mapAsync(llvm::function_ref<
|
||||
void(ResultType &,
|
||||
void(const ResultType &,
|
||||
llvm::function_ref<void(CancellableResult<NewResultType>)>)>
|
||||
Transform,
|
||||
llvm::function_ref<void(CancellableResult<NewResultType>)> Handle) {
|
||||
@@ -170,6 +170,24 @@ public:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// If the result represents success, invoke \p Transform to create a success
|
||||
/// result containing new backing data.
|
||||
///
|
||||
/// If the result represents error or cancelled, propagate that kind without
|
||||
/// modification.
|
||||
template <typename NewResultType>
|
||||
CancellableResult<NewResultType>
|
||||
map(llvm::function_ref<NewResultType(const ResultType &)> Transform) {
|
||||
switch (getKind()) {
|
||||
case CancellableResultKind::Success:
|
||||
return CancellableResult<NewResultType>::success(Transform(getResult()));
|
||||
case CancellableResultKind::Failure:
|
||||
return CancellableResult<NewResultType>::failure(getError());
|
||||
case CancellableResultKind::Cancelled:
|
||||
return CancellableResult<NewResultType>::cancelled();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ide
|
||||
|
||||
@@ -1147,8 +1147,9 @@ static bool performWithCompletionLikeOperationParams(
|
||||
}
|
||||
|
||||
template <typename ResultType>
|
||||
static int printResult(CancellableResult<ResultType> Result,
|
||||
llvm::function_ref<int(ResultType &)> PrintSuccess) {
|
||||
static int
|
||||
printResult(CancellableResult<ResultType> Result,
|
||||
llvm::function_ref<int(const ResultType &)> PrintSuccess) {
|
||||
switch (Result.getKind()) {
|
||||
case CancellableResultKind::Success: {
|
||||
return PrintSuccess(Result.getResult());
|
||||
@@ -1166,7 +1167,7 @@ static int printResult(CancellableResult<ResultType> Result,
|
||||
static int printTypeContextInfo(
|
||||
CancellableResult<TypeContextInfoResult> CancellableResult) {
|
||||
return printResult<TypeContextInfoResult>(
|
||||
CancellableResult, [](TypeContextInfoResult &Result) {
|
||||
CancellableResult, [](const TypeContextInfoResult &Result) {
|
||||
llvm::outs() << "-----BEGIN TYPE CONTEXT INFO-----\n";
|
||||
for (auto resultItem : Result.Results) {
|
||||
llvm::outs() << "- TypeName: ";
|
||||
@@ -1227,7 +1228,7 @@ static int doTypeContextInfo(const CompilerInvocation &InitInvok,
|
||||
static int printConformingMethodList(
|
||||
CancellableResult<ConformingMethodListResults> CancellableResult) {
|
||||
return printResult<ConformingMethodListResults>(
|
||||
CancellableResult, [](ConformingMethodListResults &Results) {
|
||||
CancellableResult, [](const ConformingMethodListResults &Results) {
|
||||
auto Result = Results.Result;
|
||||
if (!Result) {
|
||||
return 0;
|
||||
@@ -1396,7 +1397,7 @@ static int printCodeCompletionResults(
|
||||
bool PrintAnnotatedDescription) {
|
||||
llvm::raw_fd_ostream &OS = llvm::outs();
|
||||
return printResult<CodeCompleteResult>(
|
||||
CancellableResult, [&](CodeCompleteResult &Result) {
|
||||
CancellableResult, [&](const CodeCompleteResult &Result) {
|
||||
printCodeCompletionResultsImpl(
|
||||
Result.ResultSink.Results, OS, IncludeKeywords, IncludeComments,
|
||||
IncludeSourceText, PrintAnnotatedDescription,
|
||||
|
||||
Reference in New Issue
Block a user