diff --git a/include/cling/Utils/AST.h b/include/cling/Utils/AST.h index 90b53074..a85d2d81 100644 --- a/include/cling/Utils/AST.h +++ b/include/cling/Utils/AST.h @@ -13,6 +13,7 @@ namespace clang { class ASTContext; class Expr; class DeclContext; + class DeclarationName; class NamedDecl; class NamespaceDecl; class QualType; @@ -64,13 +65,47 @@ namespace utils { /// class Lookup { public: + + ///\brief Quick lookup for a single namespace declaration in a given + /// declaration context. + /// + ///\param[in] S - Semantic Analysis object doing the lookup. + ///\param[in] Name - The name we are looking up. + ///\param[in] Within - The context within the lookup is done. If 0 the + /// TranslationUnitDecl is used. + ///\returns the found result (if single) or 0. + /// static clang::NamespaceDecl* Namespace(clang::Sema* S, const char* Name, clang::DeclContext* Within = 0); + + ///\brief Quick lookup for a single named declaration in a given + /// declaration context. + /// + ///\param[in] S - Semantic Analysis object doing the lookup. + ///\param[in] Name - The name we are looking up. + ///\param[in] Within - The context within the lookup is done. If 0 the + /// TranslationUnitDecl is used. + ///\returns the found result (if single) or 0. + /// static clang::NamedDecl* Named(clang::Sema* S, const char* Name, clang::DeclContext* Within = 0); + ///\brief Quick lookup for a single namespace declaration in a given + /// declaration context. + /// + ///\param[in] S - Semantic Analysis object doing the lookup. + ///\param[in] Name - The name we are looking up. The & avoids inclusion of + /// DeclarationName.h (faster at runtime). + ///\param[in] Within - The context within the lookup is done. If 0 the + /// TranslationUnitDecl is used. + ///\returns the found result (if single) or 0. + /// + static clang::NamedDecl* Named(clang::Sema* S, + const clang::DeclarationName& Name, + clang::DeclContext* Within = 0); + }; } // end namespace utils } // end namespace cling diff --git a/lib/Utils/AST.cpp b/lib/Utils/AST.cpp index b1a7ac58..e170ffe5 100644 --- a/lib/Utils/AST.cpp +++ b/lib/Utils/AST.cpp @@ -389,8 +389,12 @@ namespace utils { NamedDecl* Lookup::Named(Sema* S, const char* Name, DeclContext* Within) { DeclarationName DName = &S->Context.Idents.get(Name); + return Lookup::Named(S, DName, Within); + } - LookupResult R(*S, DName, SourceLocation(), Sema::LookupOrdinaryName, + NamedDecl* Lookup::Named(Sema* S, const DeclarationName& Name, + DeclContext* Within) { + LookupResult R(*S, Name, SourceLocation(), Sema::LookupOrdinaryName, Sema::ForRedeclaration); if (!Within) S->LookupName(R, S->TUScope);