Add LookupHelper::findAnyFunction

This commit is contained in:
Philippe Canal 2013-11-01 18:40:29 -05:00 committed by sftnight
parent abdb935f70
commit 6f87119b4b
2 changed files with 69 additions and 1 deletions

View File

@ -74,6 +74,20 @@ namespace cling {
const clang::ClassTemplateDecl* findClassTemplate(llvm::StringRef Name) const;
///\brief Lookup a function based on its Decl(Context), name (return any
///function that matches the name (and constness if requested).
///
///\param [in] scopeDecl - the scope (namespace or tag) that is searched for
/// the function.
///\param [in] funcName - the name of the function to find.
///\param [in] objectIsConst - if true search fo function that can
/// be called on a const object ; default to false.
///\returns The function found or null.
const clang::FunctionDecl* findAnyFunction(const clang::Decl* scopeDecl,
llvm::StringRef funcName,
bool objectIsConst = false
) const;
///\brief Lookup a function based on its Decl(Context), name and parameters.
///
///\param [in] scopeDecl - the scope (namespace or tag) that is searched for

View File

@ -586,7 +586,7 @@ namespace cling {
Context,P,S);
if (TheDecl) {
if ( IsOverload( Context, FuncTemplateArgs, GivenArgs, TheDecl) ) {
if ( IsOverload(Context, FuncTemplateArgs, GivenArgs, TheDecl) ) {
return 0;
} else {
// Double check const-ness.
@ -915,6 +915,60 @@ namespace cling {
return true;
}
static
const FunctionDecl* findAnyFunctionSelector(DeclContext* ,
bool /* objectIsConst */,
const llvm::SmallVector<Expr*, 4> &,
LookupResult &Result,
DeclarationNameInfo &,
const TemplateArgumentListInfo* ,
ASTContext&, Parser &, Sema &) {
//
// Check for lookup failure.
//
if (Result.empty())
return 0;
if (Result.isSingleResult())
return dyn_cast<FunctionDecl>(Result.getFoundDecl());
else
return dyn_cast<FunctionDecl>(*(Result.begin()));
}
const FunctionDecl* LookupHelper::findAnyFunction(const clang::Decl* scopeDecl,
llvm::StringRef funcName,
bool objectIsConst
) const{
//FIXME: remove code duplication with findFunctionArgs() and friends.
assert(scopeDecl && "Decl cannot be null");
//
// Some utilities.
//
Parser& P = *m_Parser;
Sema& S = P.getActions();
ASTContext& Context = S.getASTContext();
//
// Convert the passed decl into a nested name specifier,
// a scope spec, and a decl context.
//
// Do this 'early' to save on the expansive parser setup,
// in case of failure.
//
CXXScopeSpec SS;
DeclContext* foundDC = getContextAndSpec(SS,scopeDecl,Context,S);
if (!foundDC) return 0;
ParserStateRAII ResetParserState(P);
llvm::SmallVector<Expr*, 4> GivenArgs;
Interpreter::PushTransactionRAII pushedT(m_Interpreter);
return findFunction(foundDC, SS,
funcName, GivenArgs, objectIsConst,
Context, P, S, findAnyFunctionSelector);
}
const FunctionDecl* LookupHelper::findFunctionProto(const Decl* scopeDecl,
llvm::StringRef funcName,
const llvm::SmallVector<QualType, 4>& funcProto,