diff options
Diffstat (limited to 'lib/Sema/Lookup.h')
-rw-r--r-- | lib/Sema/Lookup.h | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/lib/Sema/Lookup.h b/lib/Sema/Lookup.h index 78f79ea..c5eecda 100644 --- a/lib/Sema/Lookup.h +++ b/lib/Sema/Lookup.h @@ -121,6 +121,8 @@ public: typedef llvm::SmallVector<NamedDecl*, 4> DeclsTy; typedef DeclsTy::const_iterator iterator; + typedef bool (*ResultFilter)(NamedDecl*, unsigned IDNS); + LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc, Sema::LookupNameKind LookupKind, Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration) @@ -130,11 +132,14 @@ public: Name(Name), NameLoc(NameLoc), LookupKind(LookupKind), + IsAcceptableFn(0), IDNS(0), Redecl(Redecl != Sema::NotForRedeclaration), HideTags(true), Diagnose(Redecl == Sema::NotForRedeclaration) - {} + { + configure(); + } /// Creates a temporary lookup result, initializing its core data /// using the information from another result. Diagnostics are always @@ -146,6 +151,7 @@ public: Name(Other.Name), NameLoc(Other.NameLoc), LookupKind(Other.LookupKind), + IsAcceptableFn(Other.IsAcceptableFn), IDNS(Other.IDNS), Redecl(Other.Redecl), HideTags(Other.HideTags), @@ -162,6 +168,11 @@ public: return Name; } + /// \brief Sets the name to look up. + void setLookupName(DeclarationName Name) { + this->Name = Name; + } + /// Gets the kind of lookup to perform. Sema::LookupNameKind getLookupKind() const { return LookupKind; @@ -178,17 +189,6 @@ public: HideTags = Hide; } - /// The identifier namespace of this lookup. This information is - /// private to the lookup routines. - unsigned getIdentifierNamespace() const { - assert(IDNS); - return IDNS; - } - - void setIdentifierNamespace(unsigned NS) { - IDNS = NS; - } - bool isAmbiguous() const { return getResultKind() == Ambiguous; } @@ -231,7 +231,19 @@ public: return Paths; } - /// \brief Add a declaration to these results. + /// \brief Tests whether the given declaration is acceptable. + bool isAcceptableDecl(NamedDecl *D) const { + assert(IsAcceptableFn); + return IsAcceptableFn(D, IDNS); + } + + /// \brief Returns the identifier namespace mask for this lookup. + unsigned getIdentifierNamespace() const { + return IDNS; + } + + /// \brief Add a declaration to these results. Does not test the + /// acceptance criteria. void addDecl(NamedDecl *D) { Decls.push_back(D); ResultKind = Found; @@ -334,6 +346,7 @@ public: void clear(Sema::LookupNameKind Kind) { clear(); LookupKind = Kind; + configure(); } void print(llvm::raw_ostream &); @@ -362,6 +375,10 @@ public: return NameLoc; } + /// \brief Get the Sema object that this lookup result is searching + /// with. + Sema &getSema() const { return SemaRef; } + /// A class for iterating through a result set and possibly /// filtering out results. The results returned are possibly /// sugared. @@ -438,6 +455,7 @@ private: } void addDeclsFromBasePaths(const CXXBasePaths &P); + void configure(); // Sanity checks. void sanity() const { @@ -476,7 +494,9 @@ private: SourceLocation NameLoc; SourceRange NameContextRange; Sema::LookupNameKind LookupKind; - unsigned IDNS; // ill-defined until set by lookup + ResultFilter IsAcceptableFn; // set by configure() + unsigned IDNS; // set by configure() + bool Redecl; /// \brief True if tag declarations should be hidden if non-tags @@ -486,6 +506,26 @@ private: bool Diagnose; }; + /// \brief Consumes visible declarations found when searching for + /// all visible names within a given scope or context. + /// + /// This abstract class is meant to be subclassed by clients of \c + /// Sema::LookupVisibleDecls(), each of which should override the \c + /// FoundDecl() function to process declarations as they are found. + class VisibleDeclConsumer { + public: + /// \brief Destroys the visible declaration consumer. + virtual ~VisibleDeclConsumer(); + + /// \brief Invoked each time \p Sema::LookupVisibleDecls() finds a + /// declaration visible from the current scope or context. + /// + /// \param ND the declaration found. + /// + /// \param Hiding a declaration that hides the declaration \p ND, + /// or NULL if no such declaration exists. + virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding) = 0; + }; } #endif |