Skip to content

Commit

Permalink
JSON: llvm::Optional => std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Dec 16, 2022
1 parent f13d0c1 commit 1da3a79
Show file tree
Hide file tree
Showing 45 changed files with 220 additions and 212 deletions.
20 changes: 10 additions & 10 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Expand Up @@ -57,10 +57,10 @@ constexpr trace::Metric LSPLatency("lsp_latency", trace::Metric::Distribution,

// LSP defines file versions as numbers that increase.
// ClangdServer treats them as opaque and therefore uses strings instead.
std::string encodeVersion(llvm::Optional<int64_t> LSPVersion) {
std::string encodeVersion(std::optional<int64_t> LSPVersion) {
return LSPVersion ? llvm::to_string(*LSPVersion) : "";
}
llvm::Optional<int64_t> decodeVersion(llvm::StringRef Encoded) {
std::optional<int64_t> decodeVersion(llvm::StringRef Encoded) {
int64_t Result;
if (llvm::to_integer(Encoded, Result, 10))
return Result;
Expand Down Expand Up @@ -805,7 +805,7 @@ void ClangdLSPServer::onWorkspaceSymbol(
}

void ClangdLSPServer::onPrepareRename(const TextDocumentPositionParams &Params,
Callback<llvm::Optional<Range>> Reply) {
Callback<std::optional<Range>> Reply) {
Server->prepareRename(
Params.textDocument.uri.file(), Params.position, /*NewName*/ std::nullopt,
Opts.Rename,
Expand Down Expand Up @@ -1143,7 +1143,7 @@ void ClangdLSPServer::onGoToDeclaration(

void ClangdLSPServer::onSwitchSourceHeader(
const TextDocumentIdentifier &Params,
Callback<llvm::Optional<URIForFile>> Reply) {
Callback<std::optional<URIForFile>> Reply) {
Server->switchSourceHeader(
Params.uri.file(),
[Reply = std::move(Reply),
Expand All @@ -1164,10 +1164,10 @@ void ClangdLSPServer::onDocumentHighlight(
}

void ClangdLSPServer::onHover(const TextDocumentPositionParams &Params,
Callback<llvm::Optional<Hover>> Reply) {
Callback<std::optional<Hover>> Reply) {
Server->findHover(Params.textDocument.uri.file(), Params.position,
[Reply = std::move(Reply), this](
llvm::Expected<llvm::Optional<HoverInfo>> H) mutable {
[Reply = std::move(Reply),
this](llvm::Expected<std::optional<HoverInfo>> H) mutable {
if (!H)
return Reply(H.takeError());
if (!*H)
Expand Down Expand Up @@ -1244,7 +1244,7 @@ void ClangdLSPServer::onResolveTypeHierarchy(
Callback<llvm::json::Value> Reply) {
auto Serialize =
[Reply = std::move(Reply)](
llvm::Expected<llvm::Optional<TypeHierarchyItem>> Resp) mutable {
llvm::Expected<std::optional<TypeHierarchyItem>> Resp) mutable {
if (!Resp) {
Reply(Resp.takeError());
return;
Expand All @@ -1268,7 +1268,7 @@ void ClangdLSPServer::onPrepareTypeHierarchy(

void ClangdLSPServer::onSuperTypes(
const ResolveTypeHierarchyItemParams &Params,
Callback<llvm::Optional<std::vector<TypeHierarchyItem>>> Reply) {
Callback<std::optional<std::vector<TypeHierarchyItem>>> Reply) {
Server->superTypes(Params.item, std::move(Reply));
}

Expand Down Expand Up @@ -1545,7 +1545,7 @@ void ClangdLSPServer::onMemoryUsage(const NoParams &,
}

void ClangdLSPServer::onAST(const ASTParams &Params,
Callback<llvm::Optional<ASTNode>> CB) {
Callback<std::optional<ASTNode>> CB) {
Server->getAST(Params.textDocument.uri.file(), Params.range, std::move(CB));
}

Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clangd/ClangdLSPServer.h
Expand Up @@ -94,7 +94,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
void onDocumentDidChange(const DidChangeTextDocumentParams &);
void onDocumentDidClose(const DidCloseTextDocumentParams &);
void onDocumentDidSave(const DidSaveTextDocumentParams &);
void onAST(const ASTParams &, Callback<llvm::Optional<ASTNode>>);
void onAST(const ASTParams &, Callback<std::optional<ASTNode>>);
void onDocumentOnTypeFormatting(const DocumentOnTypeFormattingParams &,
Callback<std::vector<TextEdit>>);
void onDocumentRangeFormatting(const DocumentRangeFormattingParams &,
Expand Down Expand Up @@ -122,21 +122,21 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
Callback<std::vector<Location>>);
void onReference(const ReferenceParams &, Callback<std::vector<Location>>);
void onSwitchSourceHeader(const TextDocumentIdentifier &,
Callback<llvm::Optional<URIForFile>>);
Callback<std::optional<URIForFile>>);
void onDocumentHighlight(const TextDocumentPositionParams &,
Callback<std::vector<DocumentHighlight>>);
void onFileEvent(const DidChangeWatchedFilesParams &);
void onWorkspaceSymbol(const WorkspaceSymbolParams &,
Callback<std::vector<SymbolInformation>>);
void onPrepareRename(const TextDocumentPositionParams &,
Callback<llvm::Optional<Range>>);
Callback<std::optional<Range>>);
void onRename(const RenameParams &, Callback<WorkspaceEdit>);
void onHover(const TextDocumentPositionParams &,
Callback<llvm::Optional<Hover>>);
Callback<std::optional<Hover>>);
void onPrepareTypeHierarchy(const TypeHierarchyPrepareParams &,
Callback<std::vector<TypeHierarchyItem>>);
void onSuperTypes(const ResolveTypeHierarchyItemParams &,
Callback<llvm::Optional<std::vector<TypeHierarchyItem>>>);
Callback<std::optional<std::vector<TypeHierarchyItem>>>);
void onSubTypes(const ResolveTypeHierarchyItemParams &,
Callback<std::vector<TypeHierarchyItem>>);
void onTypeHierarchy(const TypeHierarchyPrepareParams &,
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clangd/ClangdServer.cpp
Expand Up @@ -737,7 +737,7 @@ void ClangdServer::findDocumentHighlights(
}

void ClangdServer::findHover(PathRef File, Position Pos,
Callback<llvm::Optional<HoverInfo>> CB) {
Callback<std::optional<HoverInfo>> CB) {
auto Action = [File = File.str(), Pos, CB = std::move(CB),
this](llvm::Expected<InputsAndAST> InpAST) mutable {
if (!InpAST)
Expand Down Expand Up @@ -766,7 +766,7 @@ void ClangdServer::typeHierarchy(PathRef File, Position Pos, int Resolve,

void ClangdServer::superTypes(
const TypeHierarchyItem &Item,
Callback<llvm::Optional<std::vector<TypeHierarchyItem>>> CB) {
Callback<std::optional<std::vector<TypeHierarchyItem>>> CB) {
WorkScheduler->run("typeHierarchy/superTypes", /*Path=*/"",
[=, CB = std::move(CB)]() mutable {
CB(clangd::superTypes(Item, Index));
Expand All @@ -782,7 +782,7 @@ void ClangdServer::subTypes(const TypeHierarchyItem &Item,

void ClangdServer::resolveTypeHierarchy(
TypeHierarchyItem Item, int Resolve, TypeHierarchyDirection Direction,
Callback<llvm::Optional<TypeHierarchyItem>> CB) {
Callback<std::optional<TypeHierarchyItem>> CB) {
WorkScheduler->run(
"Resolve Type Hierarchy", "", [=, CB = std::move(CB)]() mutable {
clangd::resolveTypeHierarchy(Item, Resolve, Direction, Index);
Expand Down Expand Up @@ -810,7 +810,7 @@ void ClangdServer::incomingCalls(
});
}

void ClangdServer::inlayHints(PathRef File, llvm::Optional<Range> RestrictRange,
void ClangdServer::inlayHints(PathRef File, std::optional<Range> RestrictRange,
Callback<std::vector<InlayHint>> CB) {
auto Action = [RestrictRange(std::move(RestrictRange)),
CB = std::move(CB)](Expected<InputsAndAST> InpAST) mutable {
Expand Down Expand Up @@ -955,8 +955,8 @@ void ClangdServer::semanticHighlights(
Transient);
}

void ClangdServer::getAST(PathRef File, llvm::Optional<Range> R,
Callback<llvm::Optional<ASTNode>> CB) {
void ClangdServer::getAST(PathRef File, std::optional<Range> R,
Callback<std::optional<ASTNode>> CB) {
auto Action =
[R, CB(std::move(CB))](llvm::Expected<InputsAndAST> Inputs) mutable {
if (!Inputs)
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clangd/ClangdServer.h
Expand Up @@ -248,23 +248,23 @@ class ClangdServer {

/// Get code hover for a given position.
void findHover(PathRef File, Position Pos,
Callback<llvm::Optional<HoverInfo>> CB);
Callback<std::optional<HoverInfo>> CB);

/// Get information about type hierarchy for a given position.
void typeHierarchy(PathRef File, Position Pos, int Resolve,
TypeHierarchyDirection Direction,
Callback<std::vector<TypeHierarchyItem>> CB);
/// Get direct parents of a type hierarchy item.
void superTypes(const TypeHierarchyItem &Item,
Callback<llvm::Optional<std::vector<TypeHierarchyItem>>> CB);
Callback<std::optional<std::vector<TypeHierarchyItem>>> CB);
/// Get direct children of a type hierarchy item.
void subTypes(const TypeHierarchyItem &Item,
Callback<std::vector<TypeHierarchyItem>> CB);

/// Resolve type hierarchy item in the given direction.
void resolveTypeHierarchy(TypeHierarchyItem Item, int Resolve,
TypeHierarchyDirection Direction,
Callback<llvm::Optional<TypeHierarchyItem>> CB);
Callback<std::optional<TypeHierarchyItem>> CB);

/// Get information about call hierarchy for a given position.
void prepareCallHierarchy(PathRef File, Position Pos,
Expand All @@ -275,7 +275,7 @@ class ClangdServer {
Callback<std::vector<CallHierarchyIncomingCall>>);

/// Resolve inlay hints for a given document.
void inlayHints(PathRef File, llvm::Optional<Range> RestrictRange,
void inlayHints(PathRef File, std::optional<Range> RestrictRange,
Callback<std::vector<InlayHint>>);

/// Retrieve the top symbols from the workspace matching a query.
Expand Down Expand Up @@ -361,8 +361,8 @@ class ClangdServer {
Callback<std::vector<HighlightingToken>>);

/// Describe the AST subtree for a piece of code.
void getAST(PathRef File, llvm::Optional<Range> R,
Callback<llvm::Optional<ASTNode>> CB);
void getAST(PathRef File, std::optional<Range> R,
Callback<std::optional<ASTNode>> CB);

/// Runs an arbitrary action that has access to the AST of the specified file.
/// The action will execute on one of ClangdServer's internal threads.
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/Config.h
Expand Up @@ -56,7 +56,7 @@ struct Config {
struct CDBSearchSpec {
enum { Ancestors, FixedDir, NoCDBSearch } Policy = Ancestors;
// Absolute, native slashes, no trailing slash.
llvm::Optional<std::string> FixedCDBPath;
std::optional<std::string> FixedCDBPath;
};

/// Controls how the compile command for the current file is determined.
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/ConfigCompile.cpp
Expand Up @@ -115,9 +115,9 @@ struct FragmentCompiler {
return Result;
}

llvm::Optional<std::string> makeAbsolute(Located<std::string> Path,
llvm::StringLiteral Description,
llvm::sys::path::Style Style) {
std::optional<std::string> makeAbsolute(Located<std::string> Path,
llvm::StringLiteral Description,
llvm::sys::path::Style Style) {
if (llvm::sys::path::is_absolute(*Path))
return *Path;
if (FragmentDirectory.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/GlobalCompilationDatabase.h
Expand Up @@ -106,7 +106,7 @@ class DirectoryBasedGlobalCompilationDatabase
std::function<Context(llvm::StringRef)> ContextProvider;
// Only look for a compilation database in this one fixed directory.
// FIXME: fold this into config/context mechanism.
llvm::Optional<Path> CompileCommandsDir;
std::optional<Path> CompileCommandsDir;
};

DirectoryBasedGlobalCompilationDatabase(const Options &Opts);
Expand Down
24 changes: 12 additions & 12 deletions clang-tools-extra/clangd/Hover.cpp
Expand Up @@ -642,7 +642,7 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
}

/// The standard defines __func__ as a "predefined variable".
llvm::Optional<HoverInfo>
std::optional<HoverInfo>
getPredefinedExprHoverContents(const PredefinedExpr &PE, ASTContext &Ctx,
const PrintingPolicy &PP) {
HoverInfo HI;
Expand Down Expand Up @@ -733,9 +733,9 @@ std::string typeAsDefinition(const HoverInfo::PrintedType &PType) {
return Result;
}

llvm::Optional<HoverInfo> getThisExprHoverContents(const CXXThisExpr *CTE,
ASTContext &ASTCtx,
const PrintingPolicy &PP) {
std::optional<HoverInfo> getThisExprHoverContents(const CXXThisExpr *CTE,
ASTContext &ASTCtx,
const PrintingPolicy &PP) {
QualType OriginThisType = CTE->getType()->getPointeeType();
QualType ClassType = declaredType(OriginThisType->getAsTagDecl());
// For partial specialization class, origin `this` pointee type will be
Expand Down Expand Up @@ -811,9 +811,9 @@ llvm::StringLiteral getNameForExpr(const Expr *E) {

// Generates hover info for `this` and evaluatable expressions.
// FIXME: Support hover for literals (esp user-defined)
llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
const PrintingPolicy &PP,
const SymbolIndex *Index) {
std::optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
const PrintingPolicy &PP,
const SymbolIndex *Index) {
// There's not much value in hovering over "42" and getting a hover card
// saying "42 is an int", similar for other literals.
if (isLiteral(E))
Expand All @@ -840,7 +840,7 @@ llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
}

// Generates hover info for attributes.
llvm::Optional<HoverInfo> getHoverContents(const Attr *A, ParsedAST &AST) {
std::optional<HoverInfo> getHoverContents(const Attr *A, ParsedAST &AST) {
HoverInfo HI;
HI.Name = A->getSpelling();
if (A->hasScope())
Expand Down Expand Up @@ -1052,9 +1052,9 @@ const NamedDecl *pickDeclToUse(llvm::ArrayRef<const NamedDecl *> Candidates) {

} // namespace

llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
const format::FormatStyle &Style,
const SymbolIndex *Index) {
std::optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
const format::FormatStyle &Style,
const SymbolIndex *Index) {
PrintingPolicy PP =
getPrintingPolicy(AST.getASTContext().getPrintingPolicy());
const SourceManager &SM = AST.getSourceManager();
Expand Down Expand Up @@ -1087,7 +1087,7 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
// for the left of the hovered token).
CharSourceRange HighlightRange =
TokensTouchingCursor.back().range(SM).toCharRange(SM);
llvm::Optional<HoverInfo> HI;
std::optional<HoverInfo> HI;
// Macros and deducedtype only works on identifiers and auto/decltype keywords
// respectively. Therefore they are only trggered on whichever works for them,
// similar to SelectionTree::create().
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/Hover.h
Expand Up @@ -136,9 +136,9 @@ inline bool operator==(const HoverInfo::Param &LHS,
}

/// Get the hover information when hovering at \p Pos.
llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
const format::FormatStyle &Style,
const SymbolIndex *Index);
std::optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
const format::FormatStyle &Style,
const SymbolIndex *Index);

} // namespace clangd
} // namespace clang
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/InlayHints.cpp
Expand Up @@ -192,7 +192,7 @@ getDesignators(const InitListExpr *Syn) {
class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
public:
InlayHintVisitor(std::vector<InlayHint> &Results, ParsedAST &AST,
const Config &Cfg, llvm::Optional<Range> RestrictRange)
const Config &Cfg, std::optional<Range> RestrictRange)
: Results(Results), AST(AST.getASTContext()), Tokens(AST.getTokens()),
Cfg(Cfg), RestrictRange(std::move(RestrictRange)),
MainFileID(AST.getSourceManager().getMainFileID()),
Expand Down Expand Up @@ -679,7 +679,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
ASTContext &AST;
const syntax::TokenBuffer &Tokens;
const Config &Cfg;
llvm::Optional<Range> RestrictRange;
std::optional<Range> RestrictRange;
FileID MainFileID;
StringRef MainFileBuf;
const HeuristicResolver *Resolver;
Expand All @@ -698,7 +698,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
} // namespace

std::vector<InlayHint> inlayHints(ParsedAST &AST,
llvm::Optional<Range> RestrictRange) {
std::optional<Range> RestrictRange) {
std::vector<InlayHint> Results;
const auto &Cfg = Config::current();
if (!Cfg.InlayHints.Enabled)
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/InlayHints.h
Expand Up @@ -25,7 +25,7 @@ class ParsedAST;
/// Compute and return inlay hints for a file.
/// If RestrictRange is set, return only hints whose location is in that range.
std::vector<InlayHint> inlayHints(ParsedAST &AST,
llvm::Optional<Range> RestrictRange);
std::optional<Range> RestrictRange);

} // namespace clangd
} // namespace clang
Expand Down

0 comments on commit 1da3a79

Please sign in to comment.