clang 20.0.0git
HeuristicResolver.h
Go to the documentation of this file.
1//===--- HeuristicResolver.h - Resolution of dependent names -----*- 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#ifndef LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
10#define LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
11
12#include "clang/AST/Decl.h"
13#include <vector>
14
15namespace clang {
16
17class ASTContext;
18class CallExpr;
19class CXXBasePath;
20class CXXDependentScopeMemberExpr;
21class DeclarationName;
22class DependentScopeDeclRefExpr;
23class NamedDecl;
24class Type;
25class UnresolvedUsingValueDecl;
26
27// This class handles heuristic resolution of declarations and types in template
28// code.
29//
30// As a compiler, clang only needs to perform certain types of processing on
31// template code (such as resolving dependent names to declarations, or
32// resolving the type of a dependent expression) after instantiation. Indeed,
33// C++ language features such as template specialization mean such resolution
34// cannot be done accurately before instantiation.
35//
36// However, template code is written and read in uninstantiated form, and clangd
37// would like to provide editor features like go-to-definition in template code
38// where possible. To this end, clangd attempts to resolve declarations and
39// types in uninstantiated code by using heuristics, understanding that the
40// results may not be fully accurate but that this is better than nothing.
41//
42// At this time, the heuristic used is a simple but effective one: assume that
43// template instantiations are based on the primary template definition and not
44// not a specialization. More advanced heuristics may be added in the future.
46public:
47 HeuristicResolver(ASTContext &Ctx) : Ctx(Ctx) {}
48
49 // Try to heuristically resolve certain types of expressions, declarations, or
50 // types to one or more likely-referenced declarations.
51 std::vector<const NamedDecl *>
53 std::vector<const NamedDecl *>
55 std::vector<const NamedDecl *>
56 resolveTypeOfCallExpr(const CallExpr *CE) const;
57 std::vector<const NamedDecl *>
58 resolveCalleeOfCallExpr(const CallExpr *CE) const;
59 std::vector<const NamedDecl *>
61 std::vector<const NamedDecl *>
63 std::vector<const NamedDecl *> resolveTemplateSpecializationType(
64 const DependentTemplateSpecializationType *DTST) const;
65
66 // Try to heuristically resolve a dependent nested name specifier
67 // to the type it likely denotes. Note that *dependent* name specifiers always
68 // denote types, not namespaces.
71
72 // Given the type T of a dependent expression that appears of the LHS of a
73 // "->", heuristically find a corresponding pointee type in whose scope we
74 // could look up the name appearing on the RHS.
75 const QualType getPointeeType(QualType T) const;
76
77private:
78 ASTContext &Ctx;
79};
80
81} // namespace clang
82
83#endif
MatchType Type
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3683
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2874
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:7029
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:7081
std::vector< const NamedDecl * > resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) const
const QualType getPointeeType(QualType T) const
std::vector< const NamedDecl * > resolveMemberExpr(const CXXDependentScopeMemberExpr *ME) const
QualType resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS) const
std::vector< const NamedDecl * > resolveCalleeOfCallExpr(const CallExpr *CE) const
std::vector< const NamedDecl * > resolveTypeOfCallExpr(const CallExpr *CE) const
std::vector< const NamedDecl * > resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD) const
std::vector< const NamedDecl * > resolveTemplateSpecializationType(const DependentTemplateSpecializationType *DTST) const
HeuristicResolver(ASTContext &Ctx)
std::vector< const NamedDecl * > resolveDependentNameType(const DependentNameType *DNT) const
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
A (possibly-)qualified type.
Definition: Type.h:929
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3885
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T