Skip to content
Snippets Groups Projects
Commit 9af5a6e1 authored by Botond Ballo's avatar Botond Ballo
Browse files

Bug 1835694 - Factor out a helper function for handling heuristic results in...

Bug 1835694 - Factor out a helper function for handling heuristic results in MozsearchIndexer. r=asuth DONTBUILD

Differential Revision: https://phabricator.services.mozilla.com/D179401
parent 891bfc05
No related branches found
No related tags found
No related merge requests found
......@@ -1985,6 +1985,39 @@ public:
return true;
}
// Helper function for producing heuristic results for usages in dependent
// code. These should be distinguished from concrete results (obtained for
// dependent code using the AutoTemplateContext machinery) once bug 1833552 is
// fixed.
// We don't expect this method to be intentionally called multiple times for
// a given (Loc, NamedDecl) pair because our callers should be mutually
// exclusive AST node types. However, it's fine if this method is called
// multiple time for a given pair because we explicitly de-duplicate records
// with an identical string representation (which is a good reason to have
// this helper, as it ensures identical representations).
void visitHeuristicResult(SourceLocation Loc, const NamedDecl *ND) {
if (const TemplateDecl *TD = dyn_cast<TemplateDecl>(ND)) {
ND = TD->getTemplatedDecl();
}
QualType MaybeType;
const char *SyntaxKind = nullptr;
if (const FunctionDecl *F = dyn_cast<FunctionDecl>(ND)) {
MaybeType = F->getType();
SyntaxKind = "function";
} else if (const FieldDecl *F = dyn_cast<FieldDecl>(ND)) {
MaybeType = F->getType();
SyntaxKind = "field";
} else if (const EnumConstantDecl *E = dyn_cast<EnumConstantDecl>(ND)) {
MaybeType = E->getType();
SyntaxKind = "enum";
}
if (SyntaxKind) {
std::string Mangled = getMangledName(CurMangleContext, ND);
visitIdentifier("use", SyntaxKind, getQualifiedName(ND), Loc, Mangled,
MaybeType, getContext(Loc));
}
}
bool VisitOverloadExpr(OverloadExpr *E) {
SourceLocation Loc = E->getExprLoc();
normalizeLocation(&Loc);
......@@ -1993,14 +2026,7 @@ public:
}
for (auto *Candidate : E->decls()) {
if (TemplateDecl *TD = dyn_cast<TemplateDecl>(Candidate)) {
Candidate = TD->getTemplatedDecl();
}
if (FunctionDecl *F = dyn_cast<FunctionDecl>(Candidate)) {
std::string Mangled = getMangledName(CurMangleContext, F);
visitIdentifier("use", "function", getQualifiedName(F), Loc, Mangled,
F->getType(), getContext(Loc));
}
visitHeuristicResult(Loc, Candidate);
}
return true;
}
......@@ -2014,18 +2040,7 @@ public:
// If possible, provide a heuristic result without instantiation.
for (const NamedDecl *D : Resolver->resolveMemberExpr(E)) {
if (const TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) {
D = TD->getTemplatedDecl();
}
if (const FunctionDecl *F = dyn_cast<FunctionDecl>(D)) {
std::string Mangled = getMangledName(CurMangleContext, F);
visitIdentifier("use", "function", getQualifiedName(F), Loc, Mangled,
F->getType(), getContext(Loc));
} else if (const FieldDecl *F = dyn_cast<FieldDecl>(D)) {
std::string Mangled = getMangledName(CurMangleContext, F);
visitIdentifier("use", "field", getQualifiedName(F), Loc, Mangled,
F->getType(), getContext(Loc));
}
visitHeuristicResult(Loc, D);
}
// Also record this location so that if we have instantiations, we can
......@@ -2044,11 +2059,7 @@ public:
}
for (const NamedDecl *D : Resolver->resolveDeclRefExpr(E)) {
if (const EnumConstantDecl *E = dyn_cast<EnumConstantDecl>(D)) {
std::string Mangled = getMangledName(CurMangleContext, E);
visitIdentifier("use", "enum", getQualifiedName(E), Loc, Mangled,
E->getType(), getContext(Loc));
}
visitHeuristicResult(Loc, D);
}
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment