HeuristicResolverImpl {
29HeuristicResolverImpl(ASTContext &Ctx) : Ctx(Ctx) {}
33std::vector<const NamedDecl *>
34resolveMemberExpr(
constCXXDependentScopeMemberExpr *ME);
35std::vector<const NamedDecl *>
36resolveDeclRefExpr(
constDependentScopeDeclRefExpr *RE);
37std::vector<const NamedDecl *> resolveTypeOfCallExpr(
constCallExpr *CE);
38std::vector<const NamedDecl *> resolveCalleeOfCallExpr(
constCallExpr *CE);
39std::vector<const NamedDecl *>
40resolveUsingValueDecl(
constUnresolvedUsingValueDecl *UUVD);
41std::vector<const NamedDecl *>
42resolveDependentNameType(
constDependentNameType *DNT);
43std::vector<const NamedDecl *> resolveTemplateSpecializationType(
44 constDependentTemplateSpecializationType *DTST);
45QualType resolveNestedNameSpecifierToType(
constNestedNameSpecifier *NNS);
52llvm::SmallSet<const DependentNameType *, 4> SeenDependentNameTypes;
63std::vector<const NamedDecl *>
64resolveDependentMember(QualType
T, DeclarationName Name,
65llvm::function_ref<
bool(
constNamedDecl *ND)> Filter);
69QualType resolveExprToType(
constExpr *
E);
70std::vector<const NamedDecl *> resolveExprToDecls(
constExpr *
E);
75TagDecl *resolveTypeToTagDecl(
constType *
T);
84QualType simplifyType(QualType Type,
constExpr *
E,
boolUnwrapPointer);
93std::vector<const NamedDecl *>
94lookupDependentName(CXXRecordDecl *RD, DeclarationName Name,
95llvm::function_ref<
bool(
constNamedDecl *ND)> Filter);
98DeclarationName Name);
103const autoNoFilter = [](
constNamedDecl *
D) {
return true; };
104const autoNonStaticFilter = [](
constNamedDecl *
D) {
105 return D->isCXXInstanceMember();
107const autoStaticFilter = [](
constNamedDecl *
D) {
108 return!
D->isCXXInstanceMember();
110const autoValueFilter = [](
constNamedDecl *
D) {
returnisa<ValueDecl>(
D); };
111const autoTypeFilter = [](
constNamedDecl *
D) {
returnisa<TypeDecl>(
D); };
112const autoTemplateFilter = [](
constNamedDecl *
D) {
113 returnisa<TemplateDecl>(
D);
116QualType resolveDeclsToType(
conststd::vector<const NamedDecl *> &Decls,
118 if(Decls.size() != 1)
120 if(
const auto*TD = dyn_cast<TypeDecl>(Decls[0])) {
123 if(
const auto*VD = dyn_cast<ValueDecl>(Decls[0])) {
124 returnVD->getType();
129TemplateName getReferencedTemplateName(
constType *
T) {
130 if(
const auto*TST =
T->
getAs<TemplateSpecializationType>()) {
131 returnTST->getTemplateName();
133 if(
const auto*DTST =
T->
getAs<DeducedTemplateSpecializationType>()) {
134 returnDTST->getTemplateName();
136 returnTemplateName();
142TagDecl *HeuristicResolverImpl::resolveTypeToTagDecl(
constType *
T) {
148 if(
const auto*DNT =
T->
getAs<DependentNameType>()) {
149 T= resolveDeclsToType(resolveDependentNameType(DNT), Ctx)
156 if(
auto*TT =
T->
getAs<TagType>()) {
157 returnTT->getDecl();
160 if(
const auto*ICNT =
T->
getAs<InjectedClassNameType>())
161 T= ICNT->getInjectedSpecializationType().getTypePtrOrNull();
165TemplateName TN = getReferencedTemplateName(
T);
169 constClassTemplateDecl *TD =
170dyn_cast_or_null<ClassTemplateDecl>(TN.getAsTemplateDecl());
174 returnTD->getTemplatedDecl();
177QualType HeuristicResolverImpl::getPointeeType(QualType
T) {
188 autoArrowOps = resolveDependentMember(
190 if(ArrowOps.empty())
199 auto*TST =
T->
getAs<TemplateSpecializationType>();
202 if(TST->template_arguments().size() == 0)
204 constTemplateArgument &FirstArg = TST->template_arguments()[0];
207 returnFirstArg.getAsType();
210QualType HeuristicResolverImpl::simplifyType(QualType Type,
constExpr *
E,
211 boolUnwrapPointer) {
212 boolDidUnwrapPointer =
false;
213 autoSimplifyOneStep = [&](QualType
T) {
216DidUnwrapPointer =
true;
220 if(
const auto*RT =
T->
getAs<ReferenceType>()) {
222 returnRT->getPointeeType();
224 if(
const auto*BT =
T->
getAs<BuiltinType>()) {
228 if(
E&& BT->getKind() == BuiltinType::Dependent) {
229 returnresolveExprToType(
E);
239 if(
E&& AT->isUndeducedAutoType()) {
240 if(
const auto*DRE = dyn_cast<DeclRefExpr>(
E)) {
241 if(
const auto*VD = dyn_cast<VarDecl>(DRE->getDecl())) {
243 returnresolveExprToType(VD->getInit());
250 while(!
Type.isNull()) {
251QualType New = SimplifyOneStep(Type);
256 if(UnwrapPointer && !DidUnwrapPointer)
261std::vector<const NamedDecl *> HeuristicResolverImpl::resolveMemberExpr(
262 constCXXDependentScopeMemberExpr *ME) {
274 if(NestedNameSpecifier *NNS = ME->getQualifier()) {
275 if(QualType QualifierType = resolveNestedNameSpecifierToType(NNS);
276!QualifierType.isNull()) {
278resolveDependentMember(QualifierType, ME->getMember(), NoFilter);
291Expr *
Base= ME->isImplicitAccess() ? nullptr : ME->getBase();
292QualType BaseType = ME->getBaseType();
293BaseType = simplifyType(BaseType,
Base, ME->isArrow());
294 returnresolveDependentMember(BaseType, ME->getMember(), NoFilter);
297std::vector<const NamedDecl *>
298HeuristicResolverImpl::resolveDeclRefExpr(
constDependentScopeDeclRefExpr *RE) {
299 returnresolveDependentMember(
300resolveNestedNameSpecifierToType(RE->getQualifier()), RE->getDeclName(),
304std::vector<const NamedDecl *>
305HeuristicResolverImpl::resolveTypeOfCallExpr(
constCallExpr *CE) {
306QualType CalleeType = resolveExprToType(CE->getCallee());
307 if(CalleeType.isNull())
309 if(
const auto*FnTypePtr = CalleeType->getAs<PointerType>())
310CalleeType = FnTypePtr->getPointeeType();
311 if(
constFunctionType *FnType = CalleeType->getAs<FunctionType>()) {
312 if(
const auto*
D=
313resolveTypeToTagDecl(FnType->getReturnType().getTypePtr())) {
320std::vector<const NamedDecl *>
321HeuristicResolverImpl::resolveCalleeOfCallExpr(
constCallExpr *CE) {
322 if(
const auto*ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) {
326 returnresolveExprToDecls(CE->getCallee());
329std::vector<const NamedDecl *> HeuristicResolverImpl::resolveUsingValueDecl(
330 constUnresolvedUsingValueDecl *UUVD) {
331 returnresolveDependentMember(QualType(UUVD->getQualifier()->getAsType(), 0),
332UUVD->getNameInfo().getName(), ValueFilter);
335std::vector<const NamedDecl *>
336HeuristicResolverImpl::resolveDependentNameType(
constDependentNameType *DNT) {
337 if(
auto[_, inserted] = SeenDependentNameTypes.insert(DNT); !inserted)
339 returnresolveDependentMember(
340resolveNestedNameSpecifierToType(DNT->getQualifier()),
341DNT->getIdentifier(), TypeFilter);
344std::vector<const NamedDecl *>
345HeuristicResolverImpl::resolveTemplateSpecializationType(
346 constDependentTemplateSpecializationType *DTST) {
347 returnresolveDependentMember(
348resolveNestedNameSpecifierToType(DTST->getQualifier()),
349DTST->getIdentifier(), TemplateFilter);
352std::vector<const NamedDecl *>
353HeuristicResolverImpl::resolveExprToDecls(
constExpr *
E) {
354 if(
const auto*ME = dyn_cast<CXXDependentScopeMemberExpr>(
E)) {
355 returnresolveMemberExpr(ME);
357 if(
const auto*RE = dyn_cast<DependentScopeDeclRefExpr>(
E)) {
358 returnresolveDeclRefExpr(RE);
360 if(
const auto*OE = dyn_cast<OverloadExpr>(
E)) {
361 return{OE->decls_begin(), OE->decls_end()};
363 if(
const auto*CE = dyn_cast<CallExpr>(
E)) {
364 returnresolveTypeOfCallExpr(CE);
366 if(
const auto*ME = dyn_cast<MemberExpr>(
E))
367 return{ME->getMemberDecl()};
372QualType HeuristicResolverImpl::resolveExprToType(
constExpr *
E) {
373std::vector<const NamedDecl *> Decls = resolveExprToDecls(
E);
375 returnresolveDeclsToType(Decls, Ctx);
380QualType HeuristicResolverImpl::resolveNestedNameSpecifierToType(
381 constNestedNameSpecifier *NNS) {
389 switch(NNS->getKind()) {
392 returnQualType(NNS->getAsType(), 0);
394 returnresolveDeclsToType(
395resolveDependentMember(
396resolveNestedNameSpecifierToType(NNS->getPrefix()),
397NNS->getAsIdentifier(), TypeFilter),
412DeclarationName Name) {
413 Path.Decls = RD->lookup(Name).begin();
421boolHeuristicResolverImpl::findOrdinaryMemberInDependentClasses(
423DeclarationName Name) {
424TagDecl *TD = resolveTypeToTagDecl(
Specifier->getType().getTypePtr());
425 if(
const auto*RD = dyn_cast_if_present<CXXRecordDecl>(TD)) {
431std::vector<const NamedDecl *> HeuristicResolverImpl::lookupDependentName(
432CXXRecordDecl *RD, DeclarationName Name,
433llvm::function_ref<
bool(
constNamedDecl *ND)> Filter) {
434std::vector<const NamedDecl *> Results;
437 boolAnyOrdinaryMembers =
false;
438 for(
constNamedDecl *ND : RD->lookup(Name)) {
440AnyOrdinaryMembers =
true;
442Results.push_back(ND);
444 if(AnyOrdinaryMembers)
450 if(!RD->lookupInBases(
451[&](
constCXXBaseSpecifier *
Specifier, CXXBasePath &
Path) {
452return findOrdinaryMemberInDependentClasses(Specifier, Path, Name);
459Results.push_back(*I);
464std::vector<const NamedDecl *> HeuristicResolverImpl::resolveDependentMember(
465QualType QT, DeclarationName Name,
466llvm::function_ref<
bool(
constNamedDecl *ND)> Filter) {
467 const Type*
T= QT.getTypePtrOrNull();
470TagDecl *TD = resolveTypeToTagDecl(
T);
473 if(
auto*ED = dyn_cast<EnumDecl>(TD)) {
474 auto Result= ED->lookup(Name);
477 if(
auto*RD = dyn_cast<CXXRecordDecl>(TD)) {
478 if(!RD->hasDefinition())
480RD = RD->getDefinition();
481 returnlookupDependentName(RD, Name, [&](
constNamedDecl *ND) {
484 if(
const auto*MD = dyn_cast<CXXMethodDecl>(ND)) {
485 return!MD->isInstance() ||
486MD->getMethodQualifiers().compatiblyIncludes(QT.getQualifiers(),
498 returnHeuristicResolverImpl(Ctx).resolveMemberExpr(ME);
502 returnHeuristicResolverImpl(Ctx).resolveDeclRefExpr(RE);
504std::vector<const NamedDecl *>
506 returnHeuristicResolverImpl(Ctx).resolveTypeOfCallExpr(CE);
508std::vector<const NamedDecl *>
510 returnHeuristicResolverImpl(Ctx).resolveCalleeOfCallExpr(CE);
514 returnHeuristicResolverImpl(Ctx).resolveUsingValueDecl(UUVD);
518 returnHeuristicResolverImpl(Ctx).resolveDependentNameType(DNT);
520std::vector<const NamedDecl *>
523 returnHeuristicResolverImpl(Ctx).resolveTemplateSpecializationType(DTST);
527 returnHeuristicResolverImpl(Ctx).resolveNestedNameSpecifierToType(NNS);
530 returnHeuristicResolverImpl(Ctx).getPointeeType(
T);
Defines the clang::ASTContext interface.
static bool findOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, DeclarationName Name)
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.
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
const NestedNameSpecifier * Specifier
DeclarationNameTable DeclarationNames
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Represents a C++ member access expression where the actual member referenced could not be resolved be...
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
lookup_result::iterator lookup_iterator
@ IDNS_Ordinary
Ordinary names.
@ IDNS_Member
Members, declared with object declarations within tag definitions.
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Represents a qualified type name for which the type name is dependent.
A qualified reference to a name whose declaration cannot yet be resolved.
Represents a template specialization type whose template cannot be resolved, e.g.
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
std::vector< const NamedDecl * > resolveDependentNameType(const DependentNameType *DNT) const
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Identifier
An identifier, stored as an IdentifierInfo*.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
@ Type
The template argument is a type.
bool isPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
QualType getCanonicalTypeInternal() const
const T * getAs() const
Member-template getAs<specific type>'.
Represents a dependent using declaration which was not marked with typename.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4