Skip to content

Commit

Permalink
Manually merged master:237625757a1 into amd-gfx:dc1257ed3f4
Browse files Browse the repository at this point in the history
Local branch amd-gfx dc1257e Manually merged master:1d104f75498 into amd-gfx:c625fb9f60f
Remote branch master 2376257 [SystemZ]  Bugfix for backchain with packed-stack

Change-Id: I079cf4e395ed6ab5e7bcb5a0bb9d2539f17c7513
  • Loading branch information
dstutt committed Mar 3, 2020
2 parents dc1257e + 2376257 commit 5662ccf
Show file tree
Hide file tree
Showing 307 changed files with 9,151 additions and 3,279 deletions.
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_clang_library(clangDaemon
ClangdServer.cpp
CodeComplete.cpp
CodeCompletionStrings.cpp
CollectMacros.cpp
CompileCommands.cpp
Compiler.cpp
Context.cpp
Expand Down
34 changes: 19 additions & 15 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Trace.h"
#include "URI.h"
#include "refactor/Tweak.h"
#include "clang/Basic/Version.h"
#include "clang/Tooling/Core/Replacement.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
Expand Down Expand Up @@ -546,7 +547,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
CodeAction::INFO_KIND}}};

llvm::json::Object Result{
{{"capabilities",
{{"serverInfo",
llvm::json::Object{{"name", "clangd"},
{"version", getClangToolFullVersion("clangd")}}},
{"capabilities",
llvm::json::Object{
{"textDocumentSync", (int)TextDocumentSyncKind::Incremental},
{"documentFormattingProvider", true},
Expand Down Expand Up @@ -600,6 +604,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
Reply(std::move(Result));
}

void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}

void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
Callback<std::nullptr_t> Reply) {
// Do essentially nothing, just say we're ready to exit.
Expand Down Expand Up @@ -808,7 +814,9 @@ void ClangdLSPServer::onDocumentDidClose(
// VSCode). Note that this cannot race with actual diagnostics responses
// because removeDocument() guarantees no diagnostic callbacks will be
// executed after it returns.
publishDiagnostics(URIForFile::canonicalize(File, /*TUPath=*/File), {});
PublishDiagnosticsParams Notification;
Notification.uri = URIForFile::canonicalize(File, /*TUPath=*/File);
publishDiagnostics(Notification);
}

void ClangdLSPServer::onDocumentOnTypeFormatting(
Expand Down Expand Up @@ -1145,18 +1153,13 @@ void ClangdLSPServer::applyConfiguration(
}

void ClangdLSPServer::publishSemanticHighlighting(
SemanticHighlightingParams Params) {
const SemanticHighlightingParams &Params) {
notify("textDocument/semanticHighlighting", Params);
}

void ClangdLSPServer::publishDiagnostics(
const URIForFile &File, std::vector<clangd::Diagnostic> Diagnostics) {
// Publish diagnostics.
notify("textDocument/publishDiagnostics",
llvm::json::Object{
{"uri", File},
{"diagnostics", std::move(Diagnostics)},
});
const PublishDiagnosticsParams &Params) {
notify("textDocument/publishDiagnostics", Params);
}

// FIXME: This function needs to be properly tested.
Expand Down Expand Up @@ -1243,6 +1246,7 @@ ClangdLSPServer::ClangdLSPServer(
NegotiatedOffsetEncoding(ForcedOffsetEncoding) {
// clang-format off
MsgHandler->bind("initialize", &ClangdLSPServer::onInitialize);
MsgHandler->bind("initialized", &ClangdLSPServer::onInitialized);
MsgHandler->bind("shutdown", &ClangdLSPServer::onShutdown);
MsgHandler->bind("sync", &ClangdLSPServer::onSync);
MsgHandler->bind("textDocument/rangeFormatting", &ClangdLSPServer::onDocumentRangeFormatting);
Expand Down Expand Up @@ -1361,15 +1365,15 @@ void ClangdLSPServer::onHighlightingsReady(

void ClangdLSPServer::onDiagnosticsReady(PathRef File,
std::vector<Diag> Diagnostics) {
auto URI = URIForFile::canonicalize(File, /*TUPath=*/File);
std::vector<Diagnostic> LSPDiagnostics;
PublishDiagnosticsParams Notification;
Notification.uri = URIForFile::canonicalize(File, /*TUPath=*/File);
DiagnosticToReplacementMap LocalFixIts; // Temporary storage
for (auto &Diag : Diagnostics) {
toLSPDiags(Diag, URI, DiagOpts,
toLSPDiags(Diag, Notification.uri, DiagOpts,
[&](clangd::Diagnostic Diag, llvm::ArrayRef<Fix> Fixes) {
auto &FixItsForDiagnostic = LocalFixIts[Diag];
llvm::copy(Fixes, std::back_inserter(FixItsForDiagnostic));
LSPDiagnostics.push_back(std::move(Diag));
Notification.diagnostics.push_back(std::move(Diag));
});
}

Expand All @@ -1380,7 +1384,7 @@ void ClangdLSPServer::onDiagnosticsReady(PathRef File,
}

// Send a notification to the LSP client.
publishDiagnostics(URI, std::move(LSPDiagnostics));
publishDiagnostics(Notification);
}

void ClangdLSPServer::onBackgroundIndexProgress(
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/ClangdLSPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
// LSP methods. Notifications have signature void(const Params&).
// Calls have signature void(const Params&, Callback<Response>).
void onInitialize(const InitializeParams &, Callback<llvm::json::Value>);
void onInitialized(const InitializedParams &);
void onShutdown(const ShutdownParams &, Callback<std::nullptr_t>);
void onSync(const NoParams &, Callback<std::nullptr_t>);
void onDocumentDidOpen(const DidOpenTextDocumentParams &);
Expand Down Expand Up @@ -132,11 +133,10 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
void applyConfiguration(const ConfigurationSettings &Settings);

/// Sends a "publishSemanticHighlighting" notification to the LSP client.
void publishSemanticHighlighting(SemanticHighlightingParams Params);
void publishSemanticHighlighting(const SemanticHighlightingParams &);

/// Sends a "publishDiagnostics" notification to the LSP client.
void publishDiagnostics(const URIForFile &File,
std::vector<clangd::Diagnostic> Diagnostics);
void publishDiagnostics(const PublishDiagnosticsParams &);

/// Since initialization of CDBs and ClangdServer is done lazily, the
/// following context captures the one used while creating ClangdLSPServer and
Expand Down
4 changes: 0 additions & 4 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,

void ClangdServer::removeDocument(PathRef File) { WorkScheduler.remove(File); }

llvm::StringRef ClangdServer::getDocument(PathRef File) const {
return WorkScheduler.getContents(File);
}

void ClangdServer::codeComplete(PathRef File, Position Pos,
const clangd::CodeCompleteOptions &Opts,
Callback<CodeCompleteResult> CB) {
Expand Down
3 changes: 0 additions & 3 deletions clang-tools-extra/clangd/ClangdServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ class ClangdServer {
WantDiagnostics WD = WantDiagnostics::Auto,
bool ForceRebuild = false);

/// Get the contents of \p File, which should have been added.
llvm::StringRef getDocument(PathRef File) const;

/// Remove \p File from list of tracked files, schedule a request to free
/// resources associated with it. Pending diagnostics for closed files may not
/// be delivered, even if requested with WantDiags::Auto or WantDiags::Yes.
Expand Down
34 changes: 34 additions & 0 deletions clang-tools-extra/clangd/CollectMacros.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===--- CollectMacros.cpp ---------------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "CollectMacros.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Lexer.h"

namespace clang {
namespace clangd {

void CollectMainFileMacros::add(const Token &MacroNameTok,
const MacroInfo *MI) {
if (!InMainFile)
return;
auto Loc = MacroNameTok.getLocation();
if (Loc.isInvalid() || Loc.isMacroID())
return;

auto Name = MacroNameTok.getIdentifierInfo()->getName();
Out.Names.insert(Name);
auto Range = halfOpenToRange(
SM, CharSourceRange::getCharRange(Loc, MacroNameTok.getEndLoc()));
if (auto SID = getSymbolID(Name, MI, SM))
Out.MacroRefs[*SID].push_back(Range);
else
Out.UnknownMacros.push_back(Range);
}
} // namespace clangd
} // namespace clang
24 changes: 3 additions & 21 deletions clang-tools-extra/clangd/CollectMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ struct MainFileMacros {
/// - collect macros after the preamble of the main file (in ParsedAST.cpp)
class CollectMainFileMacros : public PPCallbacks {
public:
explicit CollectMainFileMacros(const SourceManager &SM,
const LangOptions &LangOpts,
MainFileMacros &Out)
: SM(SM), LangOpts(LangOpts), Out(Out) {}
explicit CollectMainFileMacros(const SourceManager &SM, MainFileMacros &Out)
: SM(SM), Out(Out) {}

void FileChanged(SourceLocation Loc, FileChangeReason,
SrcMgr::CharacteristicKind, FileID) override {
Expand Down Expand Up @@ -89,24 +87,8 @@ class CollectMainFileMacros : public PPCallbacks {
}

private:
void add(const Token &MacroNameTok, const MacroInfo *MI) {
if (!InMainFile)
return;
auto Loc = MacroNameTok.getLocation();
if (Loc.isMacroID())
return;

if (auto Range = getTokenRange(SM, LangOpts, Loc)) {
auto Name = MacroNameTok.getIdentifierInfo()->getName();
Out.Names.insert(Name);
if (auto SID = getSymbolID(Name, MI, SM))
Out.MacroRefs[*SID].push_back(*Range);
else
Out.UnknownMacros.push_back(*Range);
}
}
void add(const Token &MacroNameTok, const MacroInfo *MI);
const SourceManager &SM;
const LangOptions &LangOpts;
bool InMainFile = true;
MainFileMacros &Out;
};
Expand Down
34 changes: 15 additions & 19 deletions clang-tools-extra/clangd/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/Type.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Index/IndexSymbol.h"
Expand Down Expand Up @@ -530,32 +531,33 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
llvm::consumeError(CurLoc.takeError());
return llvm::None;
}
auto TokensTouchingCursor =
syntax::spelledTokensTouching(*CurLoc, AST.getTokens());
const auto &TB = AST.getTokens();
auto TokensTouchingCursor = syntax::spelledTokensTouching(*CurLoc, TB);
// Early exit if there were no tokens around the cursor.
if (TokensTouchingCursor.empty())
return llvm::None;

// To be used as a backup for highlighting the selected token.
SourceLocation IdentLoc;
// To be used as a backup for highlighting the selected token, we use back as
// it aligns better with biases elsewhere (editors tend to send the position
// for the left of the hovered token).
CharSourceRange HighlightRange =
TokensTouchingCursor.back().range(SM).toCharRange(SM);
llvm::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().
for (const auto &Tok : TokensTouchingCursor) {
if (Tok.kind() == tok::identifier) {
IdentLoc = Tok.location();
// Prefer the identifier token as a fallback highlighting range.
HighlightRange = Tok.range(SM).toCharRange(SM);
if (auto M = locateMacroAt(Tok, AST.getPreprocessor())) {
HI = getHoverContents(*M, AST);
HI->SymRange = getTokenRange(AST.getSourceManager(), AST.getLangOpts(),
Tok.location());
break;
}
} else if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype) {
if (auto Deduced = getDeducedType(AST.getASTContext(), Tok.location())) {
HI = getHoverContents(*Deduced, AST.getASTContext(), Index);
HI->SymRange = getTokenRange(AST.getSourceManager(), AST.getLangOpts(),
Tok.location());
HighlightRange = Tok.range(SM).toCharRange(SM);
break;
}
}
Expand All @@ -566,10 +568,11 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
auto Offset = SM.getFileOffset(*CurLoc);
// Editors send the position on the left of the hovered character.
// So our selection tree should be biased right. (Tested with VSCode).
SelectionTree ST = SelectionTree::createRight(
AST.getASTContext(), AST.getTokens(), Offset, Offset);
SelectionTree ST =
SelectionTree::createRight(AST.getASTContext(), TB, Offset, Offset);
std::vector<const Decl *> Result;
if (const SelectionTree::Node *N = ST.commonAncestor()) {
// FIXME: Fill in HighlightRange with range coming from N->ASTNode.
auto Decls = explicitReferenceTargets(N->ASTNode, DeclRelation::Alias);
if (!Decls.empty()) {
HI = getHoverContents(Decls.front(), Index);
Expand All @@ -592,14 +595,7 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
if (auto Formatted =
tooling::applyAllReplacements(HI->Definition, Replacements))
HI->Definition = *Formatted;
// FIXME: We should rather fill this with info coming from SelectionTree node.
if (!HI->SymRange) {
SourceLocation ToHighlight = TokensTouchingCursor.front().location();
if (IdentLoc.isValid())
ToHighlight = IdentLoc;
HI->SymRange =
getTokenRange(AST.getSourceManager(), AST.getLangOpts(), ToHighlight);
}
HI->SymRange = halfOpenToRange(SM, HighlightRange);

return HI;
}
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/ParsedAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ ParsedAST::build(std::unique_ptr<clang::CompilerInvocation> CI,
Macros = Preamble->Macros;
Clang->getPreprocessor().addPPCallbacks(
std::make_unique<CollectMainFileMacros>(Clang->getSourceManager(),
Clang->getLangOpts(), Macros));
Macros));

// Copy over the includes from the preamble, then combine with the
// non-preamble includes below.
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/Preamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CppFilePreambleCallbacks : public PreambleCallbacks {

return std::make_unique<PPChainedCallbacks>(
collectIncludeStructureCallback(*SourceMgr, &Includes),
std::make_unique<CollectMainFileMacros>(*SourceMgr, *LangOpts, Macros));
std::make_unique<CollectMainFileMacros>(*SourceMgr, Macros));
}

CommentHandler *getCommentHandler() override {
Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/clangd/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ bool fromJSON(const llvm::json::Value &Params, Diagnostic &R) {
return true;
}

llvm::json::Value toJSON(const PublishDiagnosticsParams &PDP) {
return llvm::json::Object{
{"uri", PDP.uri},
{"diagnostics", PDP.diagnostics},
};
}

bool fromJSON(const llvm::json::Value &Params, CodeActionContext &R) {
llvm::json::ObjectMapper O(Params);
return O && O.map("diagnostics", R.diagnostics);
Expand Down
9 changes: 9 additions & 0 deletions clang-tools-extra/clangd/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ bool fromJSON(const llvm::json::Value &E, TraceLevel &Out);

struct NoParams {};
inline bool fromJSON(const llvm::json::Value &, NoParams &) { return true; }
using InitializedParams = NoParams;
using ShutdownParams = NoParams;
using ExitParams = NoParams;

Expand Down Expand Up @@ -791,6 +792,14 @@ struct LSPDiagnosticCompare {
bool fromJSON(const llvm::json::Value &, Diagnostic &);
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);

struct PublishDiagnosticsParams {
/// The URI for which diagnostic information is reported.
URIForFile uri;
/// An array of diagnostic information items.
std::vector<Diagnostic> diagnostics;
};
llvm::json::Value toJSON(const PublishDiagnosticsParams &);

struct CodeActionContext {
/// An array of diagnostics.
std::vector<Diagnostic> diagnostics;
Expand Down
Loading

0 comments on commit 5662ccf

Please sign in to comment.