Skip to content

Commit 3bc113f

Browse files
committed
Merge from 'master' to 'sycl-web' (intel#270)
2 parents 0d5465c + 891e25b commit 3bc113f

File tree

698 files changed

+28925
-7832
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

698 files changed

+28925
-7832
lines changed

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,17 +438,8 @@ targetDecl(const ast_type_traits::DynTypedNode &N, DeclRelationSet Mask) {
438438
return Result;
439439
}
440440

441-
namespace {
442-
/// Find declarations explicitly referenced in the source code defined by \p N.
443-
/// For templates, will prefer to return a template instantiation whenever
444-
/// possible. However, can also return a template pattern if the specialization
445-
/// cannot be picked, e.g. in dependent code or when there is no corresponding
446-
/// Decl for a template instantitation, e.g. for templated using decls:
447-
/// template <class T> using Ptr = T*;
448-
/// Ptr<int> x;
449-
/// ^~~ there is no Decl for 'Ptr<int>', so we return the template pattern.
450441
llvm::SmallVector<const NamedDecl *, 1>
451-
explicitReferenceTargets(DynTypedNode N, DeclRelationSet Mask = {}) {
442+
explicitReferenceTargets(DynTypedNode N, DeclRelationSet Mask) {
452443
assert(!(Mask & (DeclRelation::TemplatePattern |
453444
DeclRelation::TemplateInstantiation)) &&
454445
"explicitRefenceTargets handles templates on its own");
@@ -478,6 +469,7 @@ explicitReferenceTargets(DynTypedNode N, DeclRelationSet Mask = {}) {
478469
return Targets;
479470
}
480471

472+
namespace {
481473
llvm::SmallVector<ReferenceLoc, 2> refInDecl(const Decl *D) {
482474
struct Visitor : ConstDeclVisitor<Visitor> {
483475
llvm::SmallVector<ReferenceLoc, 2> Refs;

clang-tools-extra/clangd/FindTarget.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ inline DeclRelationSet operator&(DeclRelation L, DeclRelation R) {
182182
inline DeclRelationSet operator~(DeclRelation R) { return ~DeclRelationSet(R); }
183183
llvm::raw_ostream &operator<<(llvm::raw_ostream &, DeclRelationSet);
184184

185+
/// Find declarations explicitly referenced in the source code defined by \p N.
186+
/// For templates, will prefer to return a template instantiation whenever
187+
/// possible. However, can also return a template pattern if the specialization
188+
/// cannot be picked, e.g. in dependent code or when there is no corresponding
189+
/// Decl for a template instantitation, e.g. for templated using decls:
190+
/// template <class T> using Ptr = T*;
191+
/// Ptr<int> x;
192+
/// ^~~ there is no Decl for 'Ptr<int>', so we return the template pattern.
193+
/// \p Mask should not contain TemplatePattern or TemplateInstantiation.
194+
llvm::SmallVector<const NamedDecl *, 1>
195+
explicitReferenceTargets(ast_type_traits::DynTypedNode N,
196+
DeclRelationSet Mask = {});
185197
} // namespace clangd
186198
} // namespace clang
187199

clang-tools-extra/clangd/FormattedString.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,12 @@ std::string canonicalizeSpaces(std::string Input) {
104104
return "";
105105
// Go over each word and add it to the string.
106106
for (llvm::StringRef Word : Words) {
107+
if (WritePtr > Input.begin())
108+
*WritePtr++ = ' '; // Separate from previous block.
107109
llvm::for_each(Word, [&WritePtr](const char C) { *WritePtr++ = C; });
108-
// Separate from next block.
109-
*WritePtr++ = ' ';
110110
}
111-
// Get rid of extra spaces, -1 is for the trailing space introduced with last
112-
// word.
113-
Input.resize(WritePtr - Input.begin() - 1);
111+
// Get rid of extra spaces.
112+
Input.resize(WritePtr - Input.begin());
114113
return Input;
115114
}
116115

clang-tools-extra/clangd/Hover.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "clang/AST/PrettyPrinter.h"
2626
#include "clang/Index/IndexSymbol.h"
2727
#include "llvm/ADT/STLExtras.h"
28+
#include "llvm/ADT/iterator_range.h"
2829
#include "llvm/Support/Casting.h"
2930
#include "llvm/Support/raw_ostream.h"
3031

@@ -183,15 +184,29 @@ const FunctionDecl *getUnderlyingFunction(const Decl *D) {
183184
return D->getAsFunction();
184185
}
185186

187+
// Returns the decl that should be used for querying comments, either from index
188+
// or AST.
189+
const NamedDecl *getDeclForComment(const NamedDecl *D) {
190+
if (auto *CTSD = llvm::dyn_cast<ClassTemplateSpecializationDecl>(D))
191+
if (!CTSD->isExplicitInstantiationOrSpecialization())
192+
return CTSD->getTemplateInstantiationPattern();
193+
if (auto *VTSD = llvm::dyn_cast<VarTemplateSpecializationDecl>(D))
194+
if (!VTSD->isExplicitInstantiationOrSpecialization())
195+
return VTSD->getTemplateInstantiationPattern();
196+
if (auto *FD = D->getAsFunction())
197+
if (FD->isTemplateInstantiation())
198+
return FD->getTemplateSpecializationInfo()->getTemplate();
199+
return D;
200+
}
201+
186202
// Look up information about D from the index, and add it to Hover.
187-
void enhanceFromIndex(HoverInfo &Hover, const Decl *D,
203+
void enhanceFromIndex(HoverInfo &Hover, const NamedDecl &ND,
188204
const SymbolIndex *Index) {
189-
if (!Index || !llvm::isa<NamedDecl>(D))
190-
return;
191-
const NamedDecl &ND = *cast<NamedDecl>(D);
205+
assert(&ND == getDeclForComment(&ND));
192206
// We only add documentation, so don't bother if we already have some.
193-
if (!Hover.Documentation.empty())
207+
if (!Hover.Documentation.empty() || !Index)
194208
return;
209+
195210
// Skip querying for non-indexable symbols, there's no point.
196211
// We're searching for symbols that might be indexed outside this main file.
197212
if (!SymbolCollector::shouldCollectSymbol(ND, ND.getASTContext(),
@@ -307,8 +322,10 @@ HoverInfo getHoverContents(const Decl *D, const SymbolIndex *Index) {
307322

308323
PrintingPolicy Policy = printingPolicyForDecls(Ctx.getPrintingPolicy());
309324
if (const NamedDecl *ND = llvm::dyn_cast<NamedDecl>(D)) {
310-
HI.Documentation = getDeclComment(Ctx, *ND);
311325
HI.Name = printName(Ctx, *ND);
326+
ND = getDeclForComment(ND);
327+
HI.Documentation = getDeclComment(Ctx, *ND);
328+
enhanceFromIndex(HI, *ND, Index);
312329
}
313330

314331
HI.Kind = index::getSymbolInfo(D).Kind;
@@ -346,7 +363,6 @@ HoverInfo getHoverContents(const Decl *D, const SymbolIndex *Index) {
346363
}
347364

348365
HI.Definition = printDefinition(D);
349-
enhanceFromIndex(HI, D, Index);
350366
return HI;
351367
}
352368

@@ -358,10 +374,11 @@ HoverInfo getHoverContents(QualType T, ASTContext &ASTCtx,
358374
if (const auto *D = T->getAsTagDecl()) {
359375
HI.Name = printName(ASTCtx, *D);
360376
HI.Kind = index::getSymbolInfo(D).Kind;
361-
enhanceFromIndex(HI, D, Index);
362-
}
363377

364-
if (HI.Name.empty()) {
378+
const auto *CommentD = getDeclForComment(D);
379+
HI.Documentation = getDeclComment(ASTCtx, *CommentD);
380+
enhanceFromIndex(HI, *CommentD, Index);
381+
} else {
365382
// Builtin types
366383
llvm::raw_string_ostream OS(HI.Name);
367384
PrintingPolicy Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy());
@@ -397,7 +414,6 @@ HoverInfo getHoverContents(const DefinedMacro &Macro, ParsedAST &AST) {
397414
}
398415
return HI;
399416
}
400-
401417
} // namespace
402418

403419
llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
@@ -421,8 +437,7 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
421437
SelectionTree Selection(AST.getASTContext(), AST.getTokens(), *Offset);
422438
std::vector<const Decl *> Result;
423439
if (const SelectionTree::Node *N = Selection.commonAncestor()) {
424-
DeclRelationSet Rel = DeclRelation::TemplatePattern | DeclRelation::Alias;
425-
auto Decls = targetDecl(N->ASTNode, Rel);
440+
auto Decls = explicitReferenceTargets(N->ASTNode, DeclRelation::Alias);
426441
if (!Decls.empty()) {
427442
HI = getHoverContents(Decls.front(), Index);
428443
// Look for a close enclosing expression to show the value of.

0 commit comments

Comments
 (0)