Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:00

0001 //===--- HeuristicResolver.h - Resolution of dependent names -----*- C++-*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
0010 #define LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
0011 
0012 #include "clang/AST/Decl.h"
0013 #include <vector>
0014 
0015 namespace clang {
0016 
0017 class ASTContext;
0018 class CallExpr;
0019 class CXXBasePath;
0020 class CXXDependentScopeMemberExpr;
0021 class DeclarationName;
0022 class DependentScopeDeclRefExpr;
0023 class NamedDecl;
0024 class Type;
0025 class UnresolvedUsingValueDecl;
0026 
0027 // This class handles heuristic resolution of declarations and types in template
0028 // code.
0029 //
0030 // As a compiler, clang only needs to perform certain types of processing on
0031 // template code (such as resolving dependent names to declarations, or
0032 // resolving the type of a dependent expression) after instantiation. Indeed,
0033 // C++ language features such as template specialization mean such resolution
0034 // cannot be done accurately before instantiation.
0035 //
0036 // However, template code is written and read in uninstantiated form, and clangd
0037 // would like to provide editor features like go-to-definition in template code
0038 // where possible. To this end, clangd attempts to resolve declarations and
0039 // types in uninstantiated code by using heuristics, understanding that the
0040 // results may not be fully accurate but that this is better than nothing.
0041 //
0042 // At this time, the heuristic used is a simple but effective one: assume that
0043 // template instantiations are based on the primary template definition and not
0044 // not a specialization. More advanced heuristics may be added in the future.
0045 class HeuristicResolver {
0046 public:
0047   HeuristicResolver(ASTContext &Ctx) : Ctx(Ctx) {}
0048 
0049   // Try to heuristically resolve certain types of expressions, declarations, or
0050   // types to one or more likely-referenced declarations.
0051   std::vector<const NamedDecl *>
0052   resolveMemberExpr(const CXXDependentScopeMemberExpr *ME) const;
0053   std::vector<const NamedDecl *>
0054   resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) const;
0055   std::vector<const NamedDecl *>
0056   resolveTypeOfCallExpr(const CallExpr *CE) const;
0057   std::vector<const NamedDecl *>
0058   resolveCalleeOfCallExpr(const CallExpr *CE) const;
0059   std::vector<const NamedDecl *>
0060   resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD) const;
0061   std::vector<const NamedDecl *>
0062   resolveDependentNameType(const DependentNameType *DNT) const;
0063   std::vector<const NamedDecl *> resolveTemplateSpecializationType(
0064       const DependentTemplateSpecializationType *DTST) const;
0065 
0066   // Try to heuristically resolve a dependent nested name specifier
0067   // to the type it likely denotes. Note that *dependent* name specifiers always
0068   // denote types, not namespaces.
0069   QualType
0070   resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS) const;
0071 
0072   // Given the type T of a dependent expression that appears of the LHS of a
0073   // "->", heuristically find a corresponding pointee type in whose scope we
0074   // could look up the name appearing on the RHS.
0075   const QualType getPointeeType(QualType T) const;
0076 
0077 private:
0078   ASTContext &Ctx;
0079 };
0080 
0081 } // namespace clang
0082 
0083 #endif