clang 22.0.0git
HeuristicResolver.cpp
Go to the documentation of this file.
1//===--- HeuristicResolver.cpp ---------------------------*- 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
13#include "clang/AST/ExprCXX.h"
15#include "clang/AST/Type.h"
16
17namespace clang {
18
19namespace {
20
21// Helper class for implementing HeuristicResolver.
22// Unlike HeuristicResolver which is a long-lived class,
23// a new instance of this class is created for every external
24// call into a HeuristicResolver operation. That allows this
25// class to store state that's local to such a top-level call,
26// particularly "recursion protection sets" that keep track of
27// nodes that have already been seen to avoid infinite recursion.
28class HeuristicResolverImpl {
29public:
30 HeuristicResolverImpl(ASTContext &Ctx) : Ctx(Ctx) {}
31
32 // These functions match the public interface of HeuristicResolver
33 // (but aren't const since they may modify the recursion protection sets).
34 std::vector<const NamedDecl *>
35 resolveMemberExpr(const CXXDependentScopeMemberExpr *ME);
36 std::vector<const NamedDecl *>
37 resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE);
38 std::vector<const NamedDecl *> resolveTypeOfCallExpr(const CallExpr *CE);
39 std::vector<const NamedDecl *> resolveCalleeOfCallExpr(const CallExpr *CE);
40 std::vector<const NamedDecl *>
41 resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD);
42 std::vector<const NamedDecl *>
43 resolveDependentNameType(const DependentNameType *DNT);
44 std::vector<const NamedDecl *>
45 resolveTemplateSpecializationType(const TemplateSpecializationType *TST);
46 QualType resolveNestedNameSpecifierToType(NestedNameSpecifier NNS);
47 QualType getPointeeType(QualType T);
48 std::vector<const NamedDecl *>
49 lookupDependentName(CXXRecordDecl *RD, DeclarationName Name,
50 llvm::function_ref<bool(const NamedDecl *ND)> Filter);
51 TagDecl *resolveTypeToTagDecl(QualType T);
52 QualType simplifyType(QualType Type, const Expr *E, bool UnwrapPointer);
53 FunctionProtoTypeLoc getFunctionProtoTypeLoc(const Expr *Fn);
54
55private:
56 ASTContext &Ctx;
57
58 // Recursion protection sets
59 llvm::SmallPtrSet<const DependentNameType *, 4> SeenDependentNameTypes;
60
61 // Given a tag-decl type and a member name, heuristically resolve the
62 // name to one or more declarations.
63 // The current heuristic is simply to look up the name in the primary
64 // template. This is a heuristic because the template could potentially
65 // have specializations that declare different members.
66 // Multiple declarations could be returned if the name is overloaded
67 // (e.g. an overloaded method in the primary template).
68 // This heuristic will give the desired answer in many cases, e.g.
69 // for a call to vector<T>::size().
70 std::vector<const NamedDecl *>
71 resolveDependentMember(QualType T, DeclarationName Name,
72 llvm::function_ref<bool(const NamedDecl *ND)> Filter);
73
74 // Try to heuristically resolve the type of a possibly-dependent expression
75 // `E`.
76 QualType resolveExprToType(const Expr *E);
77 std::vector<const NamedDecl *> resolveExprToDecls(const Expr *E);
78
79 bool findOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
80 CXXBasePath &Path,
81 DeclarationName Name);
82};
83
84// Convenience lambdas for use as the 'Filter' parameter of
85// HeuristicResolver::resolveDependentMember().
86const auto NoFilter = [](const NamedDecl *D) { return true; };
87const auto NonStaticFilter = [](const NamedDecl *D) {
88 return D->isCXXInstanceMember();
89};
90const auto StaticFilter = [](const NamedDecl *D) {
91 return !D->isCXXInstanceMember();
92};
93const auto ValueFilter = [](const NamedDecl *D) { return isa<ValueDecl>(D); };
94const auto TypeFilter = [](const NamedDecl *D) { return isa<TypeDecl>(D); };
95const auto TemplateFilter = [](const NamedDecl *D) {
96 return isa<TemplateDecl>(D);
97};
98
99QualType resolveDeclsToType(const std::vector<const NamedDecl *> &Decls,
100 ASTContext &Ctx) {
101 if (Decls.size() != 1) // Names an overload set -- just bail.
102 return QualType();
103 if (const auto *TD = dyn_cast<TypeDecl>(Decls[0]))
104 return Ctx.getCanonicalTypeDeclType(TD);
105 if (const auto *VD = dyn_cast<ValueDecl>(Decls[0])) {
106 return VD->getType();
107 }
108 return QualType();
109}
110
111TemplateName getReferencedTemplateName(const Type *T) {
112 if (const auto *TST = T->getAs<TemplateSpecializationType>()) {
113 return TST->getTemplateName();
114 }
115 if (const auto *DTST = T->getAs<DeducedTemplateSpecializationType>()) {
116 return DTST->getTemplateName();
117 }
118 return TemplateName();
119}
120
121// Helper function for HeuristicResolver::resolveDependentMember()
122// which takes a possibly-dependent type `T` and heuristically
123// resolves it to a CXXRecordDecl in which we can try name lookup.
124TagDecl *HeuristicResolverImpl::resolveTypeToTagDecl(QualType QT) {
125 const Type *T = QT.getTypePtrOrNull();
126 if (!T)
127 return nullptr;
128
129 // Unwrap type sugar such as type aliases.
131
132 if (const auto *DNT = T->getAs<DependentNameType>()) {
133 T = resolveDeclsToType(resolveDependentNameType(DNT), Ctx)
134 .getTypePtrOrNull();
135 if (!T)
136 return nullptr;
138 }
139
140 if (auto *TD = T->getAsTagDecl()) {
141 // Template might not be instantiated yet, fall back to primary template
142 // in such cases.
143 if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(TD)) {
144 if (CTSD->getTemplateSpecializationKind() == TSK_Undeclared) {
145 return CTSD->getSpecializedTemplate()->getTemplatedDecl();
146 }
147 }
148 return TD;
149 }
150
151 TemplateName TN = getReferencedTemplateName(T);
152 if (TN.isNull())
153 return nullptr;
154
155 const ClassTemplateDecl *TD =
156 dyn_cast_or_null<ClassTemplateDecl>(TN.getAsTemplateDecl());
157 if (!TD)
158 return nullptr;
159
160 return TD->getTemplatedDecl();
161}
162
163QualType HeuristicResolverImpl::getPointeeType(QualType T) {
164 if (T.isNull())
165 return QualType();
166
167 if (T->isPointerType())
168 return T->castAs<PointerType>()->getPointeeType();
169
170 // Try to handle smart pointer types.
171
172 // Look up operator-> in the primary template. If we find one, it's probably a
173 // smart pointer type.
174 auto ArrowOps = resolveDependentMember(
175 T, Ctx.DeclarationNames.getCXXOperatorName(OO_Arrow), NonStaticFilter);
176 if (ArrowOps.empty())
177 return QualType();
178
179 // Getting the return type of the found operator-> method decl isn't useful,
180 // because we discarded template arguments to perform lookup in the primary
181 // template scope, so the return type would just have the form U* where U is a
182 // template parameter type.
183 // Instead, just handle the common case where the smart pointer type has the
184 // form of SmartPtr<X, ...>, and assume X is the pointee type.
185 auto *TST = T->getAs<TemplateSpecializationType>();
186 if (!TST)
187 return QualType();
188 if (TST->template_arguments().size() == 0)
189 return QualType();
190 const TemplateArgument &FirstArg = TST->template_arguments()[0];
191 if (FirstArg.getKind() != TemplateArgument::Type)
192 return QualType();
193 return FirstArg.getAsType();
194}
195
196QualType HeuristicResolverImpl::simplifyType(QualType Type, const Expr *E,
197 bool UnwrapPointer) {
198 bool DidUnwrapPointer = false;
199 // A type, together with an optional expression whose type it represents
200 // which may have additional information about the expression's type
201 // not stored in the QualType itself.
202 struct TypeExprPair {
203 QualType Type;
204 const Expr *E = nullptr;
205 };
206 TypeExprPair Current{Type, E};
207 auto SimplifyOneStep = [UnwrapPointer, &DidUnwrapPointer,
208 this](TypeExprPair T) -> TypeExprPair {
209 if (UnwrapPointer) {
210 if (QualType Pointee = getPointeeType(T.Type); !Pointee.isNull()) {
211 DidUnwrapPointer = true;
212 return {Pointee};
213 }
214 }
215 if (const auto *RT = T.Type->getAs<ReferenceType>()) {
216 // Does not count as "unwrap pointer".
217 return {RT->getPointeeType()};
218 }
219 if (const auto *BT = T.Type->getAs<BuiltinType>()) {
220 // If BaseType is the type of a dependent expression, it's just
221 // represented as BuiltinType::Dependent which gives us no information. We
222 // can get further by analyzing the dependent expression.
223 if (T.E && BT->getKind() == BuiltinType::Dependent) {
224 return {resolveExprToType(T.E), T.E};
225 }
226 }
227 if (const auto *AT = T.Type->getContainedAutoType()) {
228 // If T contains a dependent `auto` type, deduction will not have
229 // been performed on it yet. In simple cases (e.g. `auto` variable with
230 // initializer), get the approximate type that would result from
231 // deduction.
232 // FIXME: A more accurate implementation would propagate things like the
233 // `const` in `const auto`.
234 if (T.E && AT->isUndeducedAutoType()) {
235 if (const auto *DRE = dyn_cast<DeclRefExpr>(T.E)) {
236 if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
237 if (auto *Init = VD->getInit())
238 return {resolveExprToType(Init), Init};
239 }
240 }
241 }
242 }
243 if (const auto *TTPT = dyn_cast_if_present<TemplateTypeParmType>(T.Type)) {
244 // We can't do much useful with a template parameter (e.g. we cannot look
245 // up member names inside it). However, if the template parameter has a
246 // default argument, as a heuristic we can replace T with the default
247 // argument type.
248 if (const auto *TTPD = TTPT->getDecl()) {
249 if (TTPD->hasDefaultArgument()) {
250 const auto &DefaultArg = TTPD->getDefaultArgument().getArgument();
251 if (DefaultArg.getKind() == TemplateArgument::Type) {
252 return {DefaultArg.getAsType()};
253 }
254 }
255 }
256 }
257 // Check if the expression refers to an explicit object parameter of
258 // templated type. If so, heuristically treat it as having the type of the
259 // enclosing class.
260 if (!T.Type.isNull() &&
261 (T.Type->isUndeducedAutoType() || T.Type->isTemplateTypeParmType())) {
262 if (auto *DRE = dyn_cast_if_present<DeclRefExpr>(T.E)) {
263 auto *PrDecl = dyn_cast<ParmVarDecl>(DRE->getDecl());
264 if (PrDecl && PrDecl->isExplicitObjectParameter()) {
265 const auto *Parent =
266 dyn_cast<TagDecl>(PrDecl->getDeclContext()->getParent());
267 return {Ctx.getCanonicalTagType(Parent)};
268 }
269 }
270 }
271
272 return T;
273 };
274 // As an additional protection against infinite loops, bound the number of
275 // simplification steps.
276 size_t StepCount = 0;
277 const size_t MaxSteps = 64;
278 while (!Current.Type.isNull() && StepCount++ < MaxSteps) {
279 TypeExprPair New = SimplifyOneStep(Current);
280 if (New.Type == Current.Type)
281 break;
282 Current = New;
283 }
284 if (UnwrapPointer && !DidUnwrapPointer)
285 return QualType();
286 return Current.Type;
287}
288
289std::vector<const NamedDecl *> HeuristicResolverImpl::resolveMemberExpr(
290 const CXXDependentScopeMemberExpr *ME) {
291 // If the expression has a qualifier, try resolving the member inside the
292 // qualifier's type.
293 // Note that we cannot use a NonStaticFilter in either case, for a couple
294 // of reasons:
295 // 1. It's valid to access a static member using instance member syntax,
296 // e.g. `instance.static_member`.
297 // 2. We can sometimes get a CXXDependentScopeMemberExpr for static
298 // member syntax too, e.g. if `X::static_member` occurs inside
299 // an instance method, it's represented as a CXXDependentScopeMemberExpr
300 // with `this` as the base expression as `X` as the qualifier
301 // (which could be valid if `X` names a base class after instantiation).
302 if (NestedNameSpecifier NNS = ME->getQualifier()) {
303 if (QualType QualifierType = resolveNestedNameSpecifierToType(NNS);
304 !QualifierType.isNull()) {
305 auto Decls =
306 resolveDependentMember(QualifierType, ME->getMember(), NoFilter);
307 if (!Decls.empty())
308 return Decls;
309 }
310
311 // Do not proceed to try resolving the member in the expression's base type
312 // without regard to the qualifier, as that could produce incorrect results.
313 // For example, `void foo() { this->Base::foo(); }` shouldn't resolve to
314 // foo() itself!
315 return {};
316 }
317
318 // Try resolving the member inside the expression's base type.
319 Expr *Base = ME->isImplicitAccess() ? nullptr : ME->getBase();
320 QualType BaseType = ME->getBaseType();
321 BaseType = simplifyType(BaseType, Base, ME->isArrow());
322 return resolveDependentMember(BaseType, ME->getMember(), NoFilter);
323}
324
325std::vector<const NamedDecl *>
326HeuristicResolverImpl::resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) {
327 QualType Qualifier = resolveNestedNameSpecifierToType(RE->getQualifier());
328 Qualifier = simplifyType(Qualifier, nullptr, /*UnwrapPointer=*/false);
329 return resolveDependentMember(Qualifier, RE->getDeclName(), StaticFilter);
330}
331
332std::vector<const NamedDecl *>
333HeuristicResolverImpl::resolveTypeOfCallExpr(const CallExpr *CE) {
334 QualType CalleeType = resolveExprToType(CE->getCallee());
335 if (CalleeType.isNull())
336 return {};
337 if (const auto *FnTypePtr = CalleeType->getAs<PointerType>())
338 CalleeType = FnTypePtr->getPointeeType();
339 if (const FunctionType *FnType = CalleeType->getAs<FunctionType>()) {
340 if (const auto *D = resolveTypeToTagDecl(FnType->getReturnType())) {
341 return {D};
342 }
343 }
344 return {};
345}
346
347std::vector<const NamedDecl *>
348HeuristicResolverImpl::resolveCalleeOfCallExpr(const CallExpr *CE) {
349 if (const auto *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) {
350 return {ND};
351 }
352
353 return resolveExprToDecls(CE->getCallee());
354}
355
356std::vector<const NamedDecl *> HeuristicResolverImpl::resolveUsingValueDecl(
357 const UnresolvedUsingValueDecl *UUVD) {
358 NestedNameSpecifier Qualifier = UUVD->getQualifier();
359 if (Qualifier.getKind() != NestedNameSpecifier::Kind::Type)
360 return {};
361 return resolveDependentMember(QualType(Qualifier.getAsType(), 0),
362 UUVD->getNameInfo().getName(), ValueFilter);
363}
364
365std::vector<const NamedDecl *>
366HeuristicResolverImpl::resolveDependentNameType(const DependentNameType *DNT) {
367 if (auto [_, inserted] = SeenDependentNameTypes.insert(DNT); !inserted)
368 return {};
369 return resolveDependentMember(
370 resolveNestedNameSpecifierToType(DNT->getQualifier()),
371 DNT->getIdentifier(), TypeFilter);
372}
373
374std::vector<const NamedDecl *>
375HeuristicResolverImpl::resolveTemplateSpecializationType(
376 const TemplateSpecializationType *TST) {
377 const DependentTemplateStorage &DTN =
378 *TST->getTemplateName().getAsDependentTemplateName();
379 return resolveDependentMember(
380 resolveNestedNameSpecifierToType(DTN.getQualifier()),
381 DTN.getName().getIdentifier(), TemplateFilter);
382}
383
384std::vector<const NamedDecl *>
385HeuristicResolverImpl::resolveExprToDecls(const Expr *E) {
386 if (const auto *ME = dyn_cast<CXXDependentScopeMemberExpr>(E)) {
387 return resolveMemberExpr(ME);
388 }
389 if (const auto *RE = dyn_cast<DependentScopeDeclRefExpr>(E)) {
390 return resolveDeclRefExpr(RE);
391 }
392 if (const auto *OE = dyn_cast<OverloadExpr>(E)) {
393 return {OE->decls_begin(), OE->decls_end()};
394 }
395 if (const auto *CE = dyn_cast<CallExpr>(E)) {
396 return resolveTypeOfCallExpr(CE);
397 }
398 if (const auto *ME = dyn_cast<MemberExpr>(E))
399 return {ME->getMemberDecl()};
400
401 return {};
402}
403
404QualType HeuristicResolverImpl::resolveExprToType(const Expr *E) {
405 std::vector<const NamedDecl *> Decls = resolveExprToDecls(E);
406 if (!Decls.empty())
407 return resolveDeclsToType(Decls, Ctx);
408
409 return E->getType();
410}
411
412QualType HeuristicResolverImpl::resolveNestedNameSpecifierToType(
413 NestedNameSpecifier NNS) {
414 // The purpose of this function is to handle the dependent (Kind ==
415 // Identifier) case, but we need to recurse on the prefix because
416 // that may be dependent as well, so for convenience handle
417 // the TypeSpec cases too.
418 switch (NNS.getKind()) {
419 case NestedNameSpecifier::Kind::Type: {
420 const auto *T = NNS.getAsType();
421 // FIXME: Should this handle the DependentTemplateSpecializationType as
422 // well?
423 if (const auto *DTN = dyn_cast<DependentNameType>(T))
424 return resolveDeclsToType(
425 resolveDependentMember(
426 resolveNestedNameSpecifierToType(DTN->getQualifier()),
427 DTN->getIdentifier(), TypeFilter),
428 Ctx);
429 return QualType(T, 0);
430 }
431 default:
432 break;
433 }
434 return QualType();
435}
436
437bool isOrdinaryMember(const NamedDecl *ND) {
438 return ND->isInIdentifierNamespace(Decl::IDNS_Ordinary | Decl::IDNS_Tag |
440}
441
442bool findOrdinaryMember(const CXXRecordDecl *RD, CXXBasePath &Path,
443 DeclarationName Name) {
444 Path.Decls = RD->lookup(Name).begin();
445 for (DeclContext::lookup_iterator I = Path.Decls, E = I.end(); I != E; ++I)
446 if (isOrdinaryMember(*I))
447 return true;
448
449 return false;
450}
451
452bool HeuristicResolverImpl::findOrdinaryMemberInDependentClasses(
453 const CXXBaseSpecifier *Specifier, CXXBasePath &Path,
454 DeclarationName Name) {
455 TagDecl *TD = resolveTypeToTagDecl(Specifier->getType());
456 if (const auto *RD = dyn_cast_if_present<CXXRecordDecl>(TD)) {
457 return findOrdinaryMember(RD, Path, Name);
458 }
459 return false;
460}
461
462std::vector<const NamedDecl *> HeuristicResolverImpl::lookupDependentName(
463 CXXRecordDecl *RD, DeclarationName Name,
464 llvm::function_ref<bool(const NamedDecl *ND)> Filter) {
465 std::vector<const NamedDecl *> Results;
466
467 // Lookup in the class.
468 bool AnyOrdinaryMembers = false;
469 for (const NamedDecl *ND : RD->lookup(Name)) {
470 if (isOrdinaryMember(ND))
471 AnyOrdinaryMembers = true;
472 if (Filter(ND))
473 Results.push_back(ND);
474 }
475 if (AnyOrdinaryMembers)
476 return Results;
477
478 // Perform lookup into our base classes.
479 CXXBasePaths Paths;
480 Paths.setOrigin(RD);
481 if (!RD->lookupInBases(
482 [&](const CXXBaseSpecifier *Specifier, CXXBasePath &Path) {
483 return findOrdinaryMemberInDependentClasses(Specifier, Path, Name);
484 },
485 Paths, /*LookupInDependent=*/true))
486 return Results;
487 for (DeclContext::lookup_iterator I = Paths.front().Decls, E = I.end();
488 I != E; ++I) {
489 if (isOrdinaryMember(*I) && Filter(*I))
490 Results.push_back(*I);
491 }
492 return Results;
493}
494
495std::vector<const NamedDecl *> HeuristicResolverImpl::resolveDependentMember(
496 QualType QT, DeclarationName Name,
497 llvm::function_ref<bool(const NamedDecl *ND)> Filter) {
498 TagDecl *TD = resolveTypeToTagDecl(QT);
499 if (!TD)
500 return {};
501 if (auto *ED = dyn_cast<EnumDecl>(TD)) {
502 auto Result = ED->lookup(Name);
503 return {Result.begin(), Result.end()};
504 }
505 if (auto *RD = dyn_cast<CXXRecordDecl>(TD)) {
506 if (!RD->hasDefinition())
507 return {};
508 RD = RD->getDefinition();
509 return lookupDependentName(RD, Name, [&](const NamedDecl *ND) {
510 if (!Filter(ND))
511 return false;
512 if (const auto *MD = dyn_cast<CXXMethodDecl>(ND)) {
513 return !MD->isInstance() ||
514 MD->getMethodQualifiers().compatiblyIncludes(QT.getQualifiers(),
515 Ctx);
516 }
517 return true;
518 });
519 }
520 return {};
521}
522
523FunctionProtoTypeLoc
524HeuristicResolverImpl::getFunctionProtoTypeLoc(const Expr *Fn) {
525 TypeLoc Target;
526 const Expr *NakedFn = Fn->IgnoreParenCasts();
527 if (const auto *T = NakedFn->getType().getTypePtr()->getAs<TypedefType>()) {
528 Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
529 } else if (const auto *DR = dyn_cast<DeclRefExpr>(NakedFn)) {
530 const auto *D = DR->getDecl();
531 if (const auto *const VD = dyn_cast<VarDecl>(D)) {
532 Target = VD->getTypeSourceInfo()->getTypeLoc();
533 }
534 } else if (const auto *ME = dyn_cast<MemberExpr>(NakedFn)) {
535 const auto *MD = ME->getMemberDecl();
536 if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
537 Target = FD->getTypeSourceInfo()->getTypeLoc();
538 }
539 }
540
541 if (!Target)
542 return {};
543
544 // Unwrap types that may be wrapping the function type
545 while (true) {
546 if (auto P = Target.getAs<PointerTypeLoc>()) {
547 Target = P.getPointeeLoc();
548 continue;
549 }
550 if (auto A = Target.getAs<AttributedTypeLoc>()) {
551 Target = A.getModifiedLoc();
552 continue;
553 }
554 if (auto P = Target.getAs<ParenTypeLoc>()) {
555 Target = P.getInnerLoc();
556 continue;
557 }
558 break;
559 }
560
561 if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
562 // In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
563 // which has null parameters. Avoid these as they don't contain useful
564 // information.
565 if (!llvm::is_contained(F.getParams(), nullptr))
566 return F;
567 }
568
569 return {};
570}
571
572} // namespace
573
574std::vector<const NamedDecl *> HeuristicResolver::resolveMemberExpr(
575 const CXXDependentScopeMemberExpr *ME) const {
576 return HeuristicResolverImpl(Ctx).resolveMemberExpr(ME);
577}
578std::vector<const NamedDecl *> HeuristicResolver::resolveDeclRefExpr(
579 const DependentScopeDeclRefExpr *RE) const {
580 return HeuristicResolverImpl(Ctx).resolveDeclRefExpr(RE);
581}
582std::vector<const NamedDecl *>
584 return HeuristicResolverImpl(Ctx).resolveTypeOfCallExpr(CE);
585}
586std::vector<const NamedDecl *>
588 return HeuristicResolverImpl(Ctx).resolveCalleeOfCallExpr(CE);
589}
590std::vector<const NamedDecl *> HeuristicResolver::resolveUsingValueDecl(
591 const UnresolvedUsingValueDecl *UUVD) const {
592 return HeuristicResolverImpl(Ctx).resolveUsingValueDecl(UUVD);
593}
594std::vector<const NamedDecl *> HeuristicResolver::resolveDependentNameType(
595 const DependentNameType *DNT) const {
596 return HeuristicResolverImpl(Ctx).resolveDependentNameType(DNT);
597}
598std::vector<const NamedDecl *>
600 const TemplateSpecializationType *TST) const {
601 return HeuristicResolverImpl(Ctx).resolveTemplateSpecializationType(TST);
602}
604 NestedNameSpecifier NNS) const {
605 return HeuristicResolverImpl(Ctx).resolveNestedNameSpecifierToType(NNS);
606}
607std::vector<const NamedDecl *> HeuristicResolver::lookupDependentName(
609 llvm::function_ref<bool(const NamedDecl *ND)> Filter) {
610 return HeuristicResolverImpl(Ctx).lookupDependentName(RD, Name, Filter);
611}
613 return HeuristicResolverImpl(Ctx).getPointeeType(T);
614}
616 return HeuristicResolverImpl(Ctx).resolveTypeToTagDecl(T);
617}
619 bool UnwrapPointer) {
620 return HeuristicResolverImpl(Ctx).simplifyType(Type, E, UnwrapPointer);
621}
622
625 return HeuristicResolverImpl(Ctx).getFunctionProtoTypeLoc(Fn);
626}
627
628} // namespace clang
Defines the clang::ASTContext interface.
static bool isOrdinaryMember(const NamedDecl *ND)
static bool findOrdinaryMember(const CXXRecordDecl *RD, CXXBasePath &Path, DeclarationName Name)
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
llvm::MachO::Target Target
Definition MachO.h:51
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
DeclarationNameTable DeclarationNames
Definition ASTContext.h:741
CanQualType getCanonicalTypeDeclType(const TypeDecl *TD) const
CanQualType getCanonicalTagType(const TagDecl *TD) const
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:3864
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2879
lookup_result::iterator lookup_iterator
Definition DeclBase.h:2578
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_Member
Members, declared with object declarations within tag definitions.
Definition DeclBase.h:136
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
The name of a declaration.
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3504
This represents one expression.
Definition Expr.h:112
std::vector< const NamedDecl * > resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) const
const QualType getPointeeType(QualType T) const
QualType simplifyType(QualType Type, const Expr *E, bool UnwrapPointer)
std::vector< const NamedDecl * > resolveMemberExpr(const CXXDependentScopeMemberExpr *ME) const
FunctionProtoTypeLoc getFunctionProtoTypeLoc(const Expr *Fn) const
QualType resolveNestedNameSpecifierToType(NestedNameSpecifier NNS) const
std::vector< const NamedDecl * > resolveCalleeOfCallExpr(const CallExpr *CE) const
std::vector< const NamedDecl * > resolveTemplateSpecializationType(const TemplateSpecializationType *TST) const
TagDecl * resolveTypeToTagDecl(QualType T) const
std::vector< const NamedDecl * > resolveTypeOfCallExpr(const CallExpr *CE) const
std::vector< const NamedDecl * > resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD) const
std::vector< const NamedDecl * > resolveDependentNameType(const DependentNameType *DNT) const
std::vector< const NamedDecl * > lookupDependentName(CXXRecordDecl *RD, DeclarationName Name, llvm::function_ref< bool(const NamedDecl *ND)> Filter)
This represents a decl that may have a name.
Definition Decl.h:273
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
A (possibly-)qualified type.
Definition TypeBase.h:937
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8285
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3714
Represents a C++ template name within the type system.
The base class of the type hierarchy.
Definition TypeBase.h:1833
bool isUndeducedAutoType() const
Definition TypeBase.h:8708
bool isPointerType() const
Definition TypeBase.h:8522
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9168
Type(TypeClass tc, QualType canon, TypeDependence Dependence)
Definition TypeBase.h:2349
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition Type.h:65
QualType getCanonicalTypeInternal() const
Definition TypeBase.h:3119
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9101
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3934
bool Init(InterpState &S, CodePtr OpPC)
Definition Interp.h:2098
llvm::cl::opt< std::string > Filter
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
nullptr
This class represents a compute construct, representing a 'Kind' of β€˜parallel’, 'serial',...
@ Result
The result type of a method or function.
Definition TypeBase.h:905
const FunctionProtoType * T
@ Type
The name was classified as a type.
Definition Sema.h:562