clang-tools 10.0.0

XRefs.h
Go to the documentation of this file.
1 //===--- XRefs.h -------------------------------------------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Features that traverse references between symbols.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
14 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
15
16 #include "FormattedString.h"
17 #include "Path.h"
18 #include "Protocol.h"
19 #include "index/Index.h"
20 #include "index/SymbolLocation.h"
21 #include "clang/AST/Type.h"
22 #include "clang/Format/Format.h"
23 #include "clang/Index/IndexSymbol.h"
24 #include "llvm/ADT/Optional.h"
25 #include "llvm/Support/raw_ostream.h"
26 #include <vector>
27
28 namespace clang {
29 namespace clangd {
30 class ParsedAST;
31
32 // Describes where a symbol is declared and defined (as far as clangd knows).
33 // There are three cases:
34 // - a declaration only, no definition is known (e.g. only header seen)
35 // - a declaration and a distinct definition (e.g. function declared in header)
36 // - a declaration and an equal definition (e.g. inline function, or class)
37 // For some types of symbol, e.g. macros, definition == declaration always.
38 struct LocatedSymbol {
39 // The (unqualified) name of the symbol.
40 std::string Name;
41 // The canonical or best declaration: where most users find its interface.
42 Location PreferredDeclaration;
43 // Where the symbol is defined, if known. May equal PreferredDeclaration.
44 llvm::Optional<Location> Definition;
45 };
46 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const LocatedSymbol &);
47 /// Get definition of symbol at a specified \p Pos.
48 /// Multiple locations may be returned, corresponding to distinct symbols.
49 std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
50 const SymbolIndex *Index = nullptr);
51
52 /// Get all document links
53 std::vector<DocumentLink> getDocumentLinks(ParsedAST &AST);
54
55 /// Returns highlights for all usages of a symbol at \p Pos.
56 std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
57 Position Pos);
58
59 struct ReferencesResult {
60 std::vector<Location> References;
61 bool HasMore = false;
62 };
63 /// Returns references of the symbol at a specified \p Pos.
64 /// \p Limit limits the number of results returned (0 means no limit).
65 ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
66 const SymbolIndex *Index = nullptr);
67
68 /// Get info about symbols at \p Pos.
69 std::vector<SymbolDetails> getSymbolInfo(ParsedAST &AST, Position Pos);
70
71 /// Find the record type references at \p Pos.
72 const CXXRecordDecl *findRecordTypeAt(ParsedAST &AST, Position Pos);
73
74 /// Given a record type declaration, find its base (parent) types.
75 std::vector<const CXXRecordDecl *> typeParents(const CXXRecordDecl *CXXRD);
76
77 /// Get type hierarchy information at \p Pos.
78 llvm::Optional<TypeHierarchyItem> getTypeHierarchy(
79 ParsedAST &AST, Position Pos, int Resolve, TypeHierarchyDirection Direction,
80 const SymbolIndex *Index = nullptr, PathRef TUPath = PathRef{});
81
82 void resolveTypeHierarchy(TypeHierarchyItem &Item, int ResolveLevels,
83 TypeHierarchyDirection Direction,
84 const SymbolIndex *Index);
85
86 /// Returns all decls that are referenced in the \p FD except local symbols.
87 llvm::DenseSet<const Decl *> getNonLocalDeclRefs(ParsedAST &AST,
88 const FunctionDecl *FD);
89 } // namespace clangd
90 } // namespace clang
91
92 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
Limit
int Limit
Definition: FindSymbolsTests.cpp:71
FormattedString.h
Index.h
clang::clangd::getDocumentLinks
std::vector< DocumentLink > getDocumentLinks(ParsedAST &AST)
Get all document links.
Definition: XRefs.cpp:170
clang::clangd::resolveTypeHierarchy
void resolveTypeHierarchy(TypeHierarchyItem &Item, int ResolveLevels, TypeHierarchyDirection Direction, const SymbolIndex *Index)
Definition: XRefs.cpp:807
clang::clangd::SymbolIndex
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:85
Protocol.h
clang::clangd::LocatedSymbol::Definition
llvm::Optional< Location > Definition
Definition: XRefs.h:44
clang::clangd::Position
Definition: Protocol.h:127
clang::clangd::PathRef
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition: Path.h:23
clang::clangd::findReferences
ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit, const SymbolIndex *Index)
Returns references of the symbol at a specified Pos.
Definition: XRefs.cpp:423
clang::clangd::ReferencesResult
Definition: XRefs.h:59
clang::clangd::getSymbolInfo
std::vector< SymbolDetails > getSymbolInfo(ParsedAST &AST, Position Pos)
Get info about symbols at Pos.
Definition: XRefs.cpp:519
clang::clangd::LocatedSymbol::Name
std::string Name
Definition: XRefs.h:40
clang::clangd::SymbolOrigin::AST
clang::clangd::LocatedSymbol::PreferredDeclaration
Location PreferredDeclaration
Definition: XRefs.h:42
Pos
Position Pos
Definition: SourceCode.cpp:772
clang::clangd::findDocumentHighlights
std::vector< DocumentHighlight > findDocumentHighlights(ParsedAST &AST, Position Pos)
Returns highlights for all usages of a symbol at Pos.
Definition: XRefs.cpp:390
clang::clangd::ParsedAST
Stores and provides access to parsed AST.
Definition: ParsedAST.h:46
clang::clangd::LocatedSymbol
Definition: XRefs.h:38
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::findRecordTypeAt
const CXXRecordDecl * findRecordTypeAt(ParsedAST &AST, Position Pos)
Find the record type references at Pos.
Definition: XRefs.cpp:692
Path.h
clang::clangd::getTypeHierarchy
llvm::Optional< TypeHierarchyItem > getTypeHierarchy(ParsedAST &AST, Position Pos, int ResolveLevels, TypeHierarchyDirection Direction, const SymbolIndex *Index, PathRef TUPath)
Get type hierarchy information at Pos.
Definition: XRefs.cpp:768
clang::clangd::locateSymbolAt
std::vector< LocatedSymbol > locateSymbolAt(ParsedAST &AST, Position Pos, const SymbolIndex *Index)
Get definition of symbol at a specified Pos.
Definition: XRefs.cpp:190
clang::clangd::operator<<
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
Definition: CodeComplete.cpp:1850
clang::clangd::Location
Definition: Protocol.h:182
clang::clangd::ReferencesResult::References
std::vector< Location > References
Definition: XRefs.h:60
clang::clangd::TypeHierarchyDirection
TypeHierarchyDirection
Definition: Protocol.h:1121
clang::clangd::typeParents
std::vector< const CXXRecordDecl * > typeParents(const CXXRecordDecl *CXXRD)
Given a record type declaration, find its base (parent) types.
Definition: XRefs.cpp:730
clang::clangd::getNonLocalDeclRefs
llvm::DenseSet< const Decl * > getNonLocalDeclRefs(ParsedAST &AST, const FunctionDecl *FD)
Returns all decls that are referenced in the FD except local symbols.
Definition: XRefs.cpp:826
SymbolLocation.h
Index
const SymbolIndex * Index
Definition: Dexp.cpp:84
clang::clangd::TypeHierarchyItem
Definition: Protocol.h:1136