1 //===-- DeclBase.h - Base Classes for representing declarations -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Decl and DeclContext interfaces.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_DECLBASE_H
15 #define LLVM_CLANG_AST_DECLBASE_H
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Type.h"
19 // FIXME: Layering violation
20 #include "clang/Parse/AccessSpecifier.h"
21 #include "llvm/Support/PrettyStackTrace.h"
22 #include "llvm/ADT/PointerUnion.h"
26 class TranslationUnitDecl;
28 class UsingDirectiveDecl;
34 class ObjCContainerDecl;
35 class ObjCInterfaceDecl;
36 class ObjCCategoryDecl;
37 class ObjCProtocolDecl;
38 class ObjCImplementationDecl;
39 class ObjCCategoryImplDecl;
40 class LinkageSpecDecl;
42 class DeclarationName;
47 // DeclContext* is only 4-byte aligned on 32-bit systems.
49 class PointerLikeTypeTraits<clang::DeclContext*> {
50 typedef clang::DeclContext* PT;
52 static inline void *getAsVoidPointer(PT P) { return P; }
53 static inline PT getFromVoidPointer(void *P) {
54 return static_cast<PT>(P);
56 enum { NumLowBitsAvailable = 2 };
62 /// Decl - This represents one declaration (or definition), e.g. a variable,
63 /// typedef, function, struct, etc.
67 /// \brief Lists the kind of concrete classes of Decl.
69 #define DECL(Derived, Base) Derived,
70 #define DECL_RANGE(CommonBase, Start, End) \
71 CommonBase##First = Start, CommonBase##Last = End,
72 #define LAST_DECL_RANGE(CommonBase, Start, End) \
73 CommonBase##First = Start, CommonBase##Last = End
74 #include "clang/AST/DeclNodes.def"
77 /// IdentifierNamespace - According to C99 6.2.3, there are four
78 /// namespaces, labels, tags, members and ordinary
79 /// identifiers. These are meant as bitmasks, so that searches in
80 /// C++ can look into the "tag" namespace during ordinary lookup. We
81 /// use additional namespaces for Objective-C entities.
82 enum IdentifierNamespace {
87 IDNS_ObjCProtocol = 0x10,
88 IDNS_ObjCImplementation = 0x20,
89 IDNS_ObjCCategoryImpl = 0x40
92 /// ObjCDeclQualifier - Qualifier used on types in method declarations
93 /// for remote messaging. They are meant for the arguments though and
94 /// applied to the Decls (ObjCMethodDecl and ParmVarDecl).
95 enum ObjCDeclQualifier {
100 OBJC_TQ_Bycopy = 0x8,
101 OBJC_TQ_Byref = 0x10,
102 OBJC_TQ_Oneway = 0x20
106 /// NextDeclInContext - The next declaration within the same lexical
107 /// DeclContext. These pointers form the linked list that is
108 /// traversed via DeclContext's decls_begin()/decls_end().
109 Decl *NextDeclInContext;
111 friend class DeclContext;
114 DeclContext *SemanticDC;
115 DeclContext *LexicalDC;
119 /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
120 /// For declarations that don't contain C++ scope specifiers, it contains
121 /// the DeclContext where the Decl was declared.
122 /// For declarations with C++ scope specifiers, it contains a MultipleDC*
123 /// with the context where it semantically belongs (SemanticDC) and the
124 /// context where it was lexically declared (LexicalDC).
128 /// void f(); // SemanticDC == LexicalDC == 'namespace A'
130 /// void A::f(); // SemanticDC == namespace 'A'
131 /// // LexicalDC == global namespace
132 llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
134 inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
135 inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
136 inline MultipleDC *getMultipleDC() const {
137 return DeclCtx.get<MultipleDC*>();
139 inline DeclContext *getSemanticDC() const {
140 return DeclCtx.get<DeclContext*>();
143 /// Loc - The location that this decl.
146 /// DeclKind - This indicates which class this is.
149 /// InvalidDecl - This indicates a semantic error occurred.
150 unsigned int InvalidDecl : 1;
152 /// HasAttrs - This indicates whether the decl has attributes or not.
153 unsigned int HasAttrs : 1;
155 /// Implicit - Whether this declaration was implicitly generated by
156 /// the implementation rather than explicitly written by the user.
159 /// \brief Whether this declaration was "used", meaning that a definition is
164 /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
165 unsigned IdentifierNamespace : 8;
169 void CheckAccessDeclContext() const;
171 void CheckAccessDeclContext() const { }
175 /// Access - Used by C++ decls for the access specifier.
176 // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
178 friend class CXXClassMemberWrapper;
180 Decl(Kind DK, DeclContext *DC, SourceLocation L)
181 : NextDeclInContext(0), DeclCtx(DC),
182 Loc(L), DeclKind(DK), InvalidDecl(0),
183 HasAttrs(false), Implicit(false), Used(false),
184 IdentifierNamespace(getIdentifierNamespaceForKind(DK)), Access(AS_none) {
185 if (Decl::CollectingStats()) addDeclKind(DK);
192 /// \brief Source range that this declaration covers.
193 virtual SourceRange getSourceRange() const {
194 return SourceRange(getLocation(), getLocation());
196 SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
197 SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
199 SourceLocation getLocation() const { return Loc; }
200 void setLocation(SourceLocation L) { Loc = L; }
202 Kind getKind() const { return DeclKind; }
203 const char *getDeclKindName() const;
205 Decl *getNextDeclInContext() { return NextDeclInContext; }
206 const Decl *getNextDeclInContext() const { return NextDeclInContext; }
208 DeclContext *getDeclContext() {
210 return getSemanticDC();
211 return getMultipleDC()->SemanticDC;
213 const DeclContext *getDeclContext() const {
214 return const_cast<Decl*>(this)->getDeclContext();
217 TranslationUnitDecl *getTranslationUnitDecl();
218 const TranslationUnitDecl *getTranslationUnitDecl() const {
219 return const_cast<Decl*>(this)->getTranslationUnitDecl();
222 ASTContext &getASTContext() const;
224 void setAccess(AccessSpecifier AS) {
226 CheckAccessDeclContext();
229 AccessSpecifier getAccess() const {
230 CheckAccessDeclContext();
231 return AccessSpecifier(Access);
234 bool hasAttrs() const { return HasAttrs; }
235 void addAttr(Attr *attr);
236 const Attr *getAttrs() const {
237 if (!HasAttrs) return 0; // common case, no attributes.
238 return getAttrsImpl(); // Uncommon case, out of line hash lookup.
240 void swapAttrs(Decl *D);
241 void invalidateAttrs();
243 template<typename T> const T *getAttr() const {
244 for (const Attr *attr = getAttrs(); attr; attr = attr->getNext())
245 if (const T *V = dyn_cast<T>(attr))
250 template<typename T> bool hasAttr() const {
251 return getAttr<T>() != 0;
254 /// setInvalidDecl - Indicates the Decl had a semantic error. This
255 /// allows for graceful error recovery.
256 void setInvalidDecl(bool Invalid = true) { InvalidDecl = Invalid; }
257 bool isInvalidDecl() const { return (bool) InvalidDecl; }
259 /// isImplicit - Indicates whether the declaration was implicitly
260 /// generated by the implementation. If false, this declaration
261 /// was written explicitly in the source code.
262 bool isImplicit() const { return Implicit; }
263 void setImplicit(bool I = true) { Implicit = I; }
265 /// \brief Whether this declaration was used, meaning that a definition
267 bool isUsed() const { return Used; }
268 void setUsed(bool U = true) { Used = U; }
270 unsigned getIdentifierNamespace() const {
271 return IdentifierNamespace;
273 bool isInIdentifierNamespace(unsigned NS) const {
274 return getIdentifierNamespace() & NS;
276 static unsigned getIdentifierNamespaceForKind(Kind DK);
279 /// getLexicalDeclContext - The declaration context where this Decl was
280 /// lexically declared (LexicalDC). May be different from
281 /// getDeclContext() (SemanticDC).
285 /// void f(); // SemanticDC == LexicalDC == 'namespace A'
287 /// void A::f(); // SemanticDC == namespace 'A'
288 /// // LexicalDC == global namespace
289 DeclContext *getLexicalDeclContext() {
291 return getSemanticDC();
292 return getMultipleDC()->LexicalDC;
294 const DeclContext *getLexicalDeclContext() const {
295 return const_cast<Decl*>(this)->getLexicalDeclContext();
298 bool isOutOfLine() const {
299 return getLexicalDeclContext() != getDeclContext();
302 /// setDeclContext - Set both the semantic and lexical DeclContext
304 void setDeclContext(DeclContext *DC);
306 void setLexicalDeclContext(DeclContext *DC);
308 // isDefinedOutsideFunctionOrMethod - This predicate returns true if this
309 // scoped decl is defined outside the current function or method. This is
310 // roughly global variables and functions, but also handles enums (which could
311 // be defined inside or outside a function etc).
312 bool isDefinedOutsideFunctionOrMethod() const;
314 /// getBody - If this Decl represents a declaration for a body of code,
315 /// such as a function or method definition, this method returns the
316 /// top-level Stmt* of that body. Otherwise this method returns null.
317 virtual Stmt* getBody() const { return 0; }
319 /// getCompoundBody - Returns getBody(), dyn_casted to a CompoundStmt.
320 CompoundStmt* getCompoundBody() const;
322 /// getBodyRBrace - Gets the right brace of the body, if a body exists.
323 /// This works whether the body is a CompoundStmt or a CXXTryStmt.
324 SourceLocation getBodyRBrace() const;
326 // global temp stats (until we have a per-module visitor)
327 static void addDeclKind(Kind k);
328 static bool CollectingStats(bool Enable = false);
329 static void PrintStats();
331 /// isTemplateParameter - Determines whether this declaration is a
332 /// template parameter.
333 bool isTemplateParameter() const;
335 /// isTemplateParameter - Determines whether this declaration is a
336 /// template parameter pack.
337 bool isTemplateParameterPack() const;
339 /// \brief Whether this declaration is a function or function template.
340 bool isFunctionOrFunctionTemplate() const;
342 // Implement isa/cast/dyncast/etc.
343 static bool classof(const Decl *) { return true; }
344 static DeclContext *castToDeclContext(const Decl *);
345 static Decl *castFromDeclContext(const DeclContext *);
347 /// Destroy - Call destructors and release memory.
348 virtual void Destroy(ASTContext& C);
350 void print(llvm::raw_ostream &Out, unsigned Indentation = 0);
351 void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy,
352 unsigned Indentation = 0);
353 static void printGroup(Decl** Begin, unsigned NumDecls,
354 llvm::raw_ostream &Out, const PrintingPolicy &Policy,
355 unsigned Indentation = 0);
359 const Attr *getAttrsImpl() const;
363 /// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when
364 /// doing something to a specific decl.
365 class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry {
371 PrettyStackTraceDecl(Decl *theDecl, SourceLocation L,
372 SourceManager &sm, const char *Msg)
373 : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {}
375 virtual void print(llvm::raw_ostream &OS) const;
379 /// DeclContext - This is used only as base class of specific decl types that
380 /// can act as declaration contexts. These decls are (only the top classes
381 /// that directly derive from DeclContext are mentioned, not their subclasses):
383 /// TranslationUnitDecl
388 /// ObjCContainerDecl
389 /// ObjCCategoryImplDecl
390 /// ObjCImplementationDecl
395 /// DeclKind - This indicates which class this is.
396 Decl::Kind DeclKind : 8;
398 /// \brief Whether this declaration context also has some external
399 /// storage that contains additional declarations that are lexically
400 /// part of this context.
401 mutable bool ExternalLexicalStorage : 1;
403 /// \brief Whether this declaration context also has some external
404 /// storage that contains additional declarations that are visible
406 mutable bool ExternalVisibleStorage : 1;
408 /// \brief Pointer to the data structure used to lookup declarations
409 /// within this context, which is a DenseMap<DeclarationName,
410 /// StoredDeclsList>.
411 mutable void* LookupPtr;
413 /// FirstDecl - The first declaration stored within this declaration
415 mutable Decl *FirstDecl;
417 /// LastDecl - The last declaration stored within this declaration
418 /// context. FIXME: We could probably cache this value somewhere
419 /// outside of the DeclContext, to reduce the size of DeclContext by
421 mutable Decl *LastDecl;
424 DeclContext(Decl::Kind K)
425 : DeclKind(K), ExternalLexicalStorage(false),
426 ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0),
429 void DestroyDecls(ASTContext &C);
434 Decl::Kind getDeclKind() const {
437 const char *getDeclKindName() const;
439 /// getParent - Returns the containing DeclContext.
440 DeclContext *getParent() {
441 return cast<Decl>(this)->getDeclContext();
443 const DeclContext *getParent() const {
444 return const_cast<DeclContext*>(this)->getParent();
447 /// getLexicalParent - Returns the containing lexical DeclContext. May be
448 /// different from getParent, e.g.:
453 /// struct A::S {}; // getParent() == namespace 'A'
454 /// // getLexicalParent() == translation unit
456 DeclContext *getLexicalParent() {
457 return cast<Decl>(this)->getLexicalDeclContext();
459 const DeclContext *getLexicalParent() const {
460 return const_cast<DeclContext*>(this)->getLexicalParent();
463 ASTContext &getParentASTContext() const {
464 return cast<Decl>(this)->getASTContext();
467 bool isFunctionOrMethod() const {
470 case Decl::ObjCMethod:
473 return DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast;
477 bool isFileContext() const {
478 return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace;
481 bool isTranslationUnit() const {
482 return DeclKind == Decl::TranslationUnit;
485 bool isRecord() const {
486 return DeclKind >= Decl::RecordFirst && DeclKind <= Decl::RecordLast;
489 bool isNamespace() const {
490 return DeclKind == Decl::Namespace;
493 /// \brief Determines whether this context is dependent on a
494 /// template parameter.
495 bool isDependentContext() const;
497 /// isTransparentContext - Determines whether this context is a
498 /// "transparent" context, meaning that the members declared in this
499 /// context are semantically declared in the nearest enclosing
500 /// non-transparent (opaque) context but are lexically declared in
501 /// this context. For example, consider the enumerators of an
502 /// enumeration type:
508 /// Here, E is a transparent context, so its enumerator (Val1) will
509 /// appear (semantically) that it is in the same context of E.
510 /// Examples of transparent contexts include: enumerations (except for
511 /// C++0x scoped enums), C++ linkage specifications, and C++0x
512 /// inline namespaces.
513 bool isTransparentContext() const;
515 bool Encloses(DeclContext *DC) const {
516 for (; DC; DC = DC->getParent())
522 /// getPrimaryContext - There may be many different
523 /// declarations of the same entity (including forward declarations
524 /// of classes, multiple definitions of namespaces, etc.), each with
525 /// a different set of declarations. This routine returns the
526 /// "primary" DeclContext structure, which will contain the
527 /// information needed to perform name lookup into this context.
528 DeclContext *getPrimaryContext();
530 /// getLookupContext - Retrieve the innermost non-transparent
531 /// context of this context, which corresponds to the innermost
532 /// location from which name lookup can find the entities in this
534 DeclContext *getLookupContext();
535 const DeclContext *getLookupContext() const {
536 return const_cast<DeclContext *>(this)->getLookupContext();
539 /// \brief Retrieve the nearest enclosing namespace context.
540 DeclContext *getEnclosingNamespaceContext();
541 const DeclContext *getEnclosingNamespaceContext() const {
542 return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext();
545 /// getNextContext - If this is a DeclContext that may have other
546 /// DeclContexts that are semantically connected but syntactically
547 /// different, such as C++ namespaces, this routine retrieves the
548 /// next DeclContext in the link. Iteration through the chain of
549 /// DeclContexts should begin at the primary DeclContext and
550 /// continue until this function returns NULL. For example, given:
559 /// The first occurrence of namespace N will be the primary
560 /// DeclContext. Its getNextContext will return the second
561 /// occurrence of namespace N.
562 DeclContext *getNextContext();
564 /// decl_iterator - Iterates through the declarations stored
565 /// within this context.
566 class decl_iterator {
567 /// Current - The current declaration.
571 typedef Decl* value_type;
572 typedef Decl* reference;
573 typedef Decl* pointer;
574 typedef std::forward_iterator_tag iterator_category;
575 typedef std::ptrdiff_t difference_type;
577 decl_iterator() : Current(0) { }
578 explicit decl_iterator(Decl *C) : Current(C) { }
580 reference operator*() const { return Current; }
581 pointer operator->() const { return Current; }
583 decl_iterator& operator++() {
584 Current = Current->getNextDeclInContext();
588 decl_iterator operator++(int) {
589 decl_iterator tmp(*this);
594 friend bool operator==(decl_iterator x, decl_iterator y) {
595 return x.Current == y.Current;
597 friend bool operator!=(decl_iterator x, decl_iterator y) {
598 return x.Current != y.Current;
602 /// decls_begin/decls_end - Iterate over the declarations stored in
604 decl_iterator decls_begin() const;
605 decl_iterator decls_end() const;
606 bool decls_empty() const;
608 /// specific_decl_iterator - Iterates over a subrange of
609 /// declarations stored in a DeclContext, providing only those that
610 /// are of type SpecificDecl (or a class derived from it). This
611 /// iterator is used, for example, to provide iteration over just
612 /// the fields within a RecordDecl (with SpecificDecl = FieldDecl).
613 template<typename SpecificDecl>
614 class specific_decl_iterator {
615 /// Current - The current, underlying declaration iterator, which
616 /// will either be NULL or will point to a declaration of
617 /// type SpecificDecl.
618 DeclContext::decl_iterator Current;
620 /// SkipToNextDecl - Advances the current position up to the next
621 /// declaration of type SpecificDecl that also meets the criteria
622 /// required by Acceptable.
623 void SkipToNextDecl() {
624 while (*Current && !isa<SpecificDecl>(*Current))
629 typedef SpecificDecl* value_type;
630 typedef SpecificDecl* reference;
631 typedef SpecificDecl* pointer;
632 typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
634 typedef std::forward_iterator_tag iterator_category;
636 specific_decl_iterator() : Current() { }
638 /// specific_decl_iterator - Construct a new iterator over a
639 /// subset of the declarations the range [C,
640 /// end-of-declarations). If A is non-NULL, it is a pointer to a
641 /// member function of SpecificDecl that should return true for
642 /// all of the SpecificDecl instances that will be in the subset
643 /// of iterators. For example, if you want Objective-C instance
644 /// methods, SpecificDecl will be ObjCMethodDecl and A will be
645 /// &ObjCMethodDecl::isInstanceMethod.
646 explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) {
650 reference operator*() const { return cast<SpecificDecl>(*Current); }
651 pointer operator->() const { return cast<SpecificDecl>(*Current); }
653 specific_decl_iterator& operator++() {
659 specific_decl_iterator operator++(int) {
660 specific_decl_iterator tmp(*this);
666 operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) {
667 return x.Current == y.Current;
671 operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) {
672 return x.Current != y.Current;
676 /// \brief Iterates over a filtered subrange of declarations stored
677 /// in a DeclContext.
679 /// This iterator visits only those declarations that are of type
680 /// SpecificDecl (or a class derived from it) and that meet some
681 /// additional run-time criteria. This iterator is used, for
682 /// example, to provide access to the instance methods within an
683 /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and
684 /// Acceptable = ObjCMethodDecl::isInstanceMethod).
685 template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const>
686 class filtered_decl_iterator {
687 /// Current - The current, underlying declaration iterator, which
688 /// will either be NULL or will point to a declaration of
689 /// type SpecificDecl.
690 DeclContext::decl_iterator Current;
692 /// SkipToNextDecl - Advances the current position up to the next
693 /// declaration of type SpecificDecl that also meets the criteria
694 /// required by Acceptable.
695 void SkipToNextDecl() {
697 (!isa<SpecificDecl>(*Current) ||
698 (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)())))
703 typedef SpecificDecl* value_type;
704 typedef SpecificDecl* reference;
705 typedef SpecificDecl* pointer;
706 typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
708 typedef std::forward_iterator_tag iterator_category;
710 filtered_decl_iterator() : Current() { }
712 /// specific_decl_iterator - Construct a new iterator over a
713 /// subset of the declarations the range [C,
714 /// end-of-declarations). If A is non-NULL, it is a pointer to a
715 /// member function of SpecificDecl that should return true for
716 /// all of the SpecificDecl instances that will be in the subset
717 /// of iterators. For example, if you want Objective-C instance
718 /// methods, SpecificDecl will be ObjCMethodDecl and A will be
719 /// &ObjCMethodDecl::isInstanceMethod.
720 explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) {
724 reference operator*() const { return cast<SpecificDecl>(*Current); }
725 pointer operator->() const { return cast<SpecificDecl>(*Current); }
727 filtered_decl_iterator& operator++() {
733 filtered_decl_iterator operator++(int) {
734 filtered_decl_iterator tmp(*this);
740 operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) {
741 return x.Current == y.Current;
745 operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) {
746 return x.Current != y.Current;
750 /// @brief Add the declaration D into this context.
752 /// This routine should be invoked when the declaration D has first
753 /// been declared, to place D into the context where it was
754 /// (lexically) defined. Every declaration must be added to one
755 /// (and only one!) context, where it can be visited via
756 /// [decls_begin(), decls_end()). Once a declaration has been added
757 /// to its lexical context, the corresponding DeclContext owns the
760 /// If D is also a NamedDecl, it will be made visible within its
761 /// semantic context via makeDeclVisibleInContext.
762 void addDecl(Decl *D);
764 /// lookup_iterator - An iterator that provides access to the results
765 /// of looking up a name within this context.
766 typedef NamedDecl **lookup_iterator;
768 /// lookup_const_iterator - An iterator that provides non-mutable
769 /// access to the results of lookup up a name within this context.
770 typedef NamedDecl * const * lookup_const_iterator;
772 typedef std::pair<lookup_iterator, lookup_iterator> lookup_result;
773 typedef std::pair<lookup_const_iterator, lookup_const_iterator>
776 /// lookup - Find the declarations (if any) with the given Name in
777 /// this context. Returns a range of iterators that contains all of
778 /// the declarations with this name, with object, function, member,
779 /// and enumerator names preceding any tag name. Note that this
780 /// routine will not look into parent contexts.
781 lookup_result lookup(DeclarationName Name);
782 lookup_const_result lookup(DeclarationName Name) const;
784 /// @brief Makes a declaration visible within this context.
786 /// This routine makes the declaration D visible to name lookup
787 /// within this context and, if this is a transparent context,
788 /// within its parent contexts up to the first enclosing
789 /// non-transparent context. Making a declaration visible within a
790 /// context does not transfer ownership of a declaration, and a
791 /// declaration can be visible in many contexts that aren't its
794 /// If D is a redeclaration of an existing declaration that is
795 /// visible from this context, as determined by
796 /// NamedDecl::declarationReplaces, the previous declaration will be
798 void makeDeclVisibleInContext(NamedDecl *D);
800 /// udir_iterator - Iterates through the using-directives stored
801 /// within this context.
802 typedef UsingDirectiveDecl * const * udir_iterator;
804 typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range;
806 udir_iterator_range getUsingDirectives() const;
808 udir_iterator using_directives_begin() const {
809 return getUsingDirectives().first;
812 udir_iterator using_directives_end() const {
813 return getUsingDirectives().second;
816 // Low-level accessors
818 /// \brief Retrieve the internal representation of the lookup structure.
819 void* getLookupPtr() const { return LookupPtr; }
821 /// \brief Whether this DeclContext has external storage containing
822 /// additional declarations that are lexically in this context.
823 bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; }
825 /// \brief State whether this DeclContext has external storage for
826 /// declarations lexically in this context.
827 void setHasExternalLexicalStorage(bool ES = true) {
828 ExternalLexicalStorage = ES;
831 /// \brief Whether this DeclContext has external storage containing
832 /// additional declarations that are visible in this context.
833 bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; }
835 /// \brief State whether this DeclContext has external storage for
836 /// declarations visible in this context.
837 void setHasExternalVisibleStorage(bool ES = true) {
838 ExternalVisibleStorage = ES;
841 static bool classof(const Decl *D);
842 static bool classof(const DeclContext *D) { return true; }
843 #define DECL_CONTEXT(Name) \
844 static bool classof(const Name##Decl *D) { return true; }
845 #include "clang/AST/DeclNodes.def"
848 void LoadLexicalDeclsFromExternalStorage() const;
849 void LoadVisibleDeclsFromExternalStorage() const;
851 void buildLookup(DeclContext *DCtx);
852 void makeDeclVisibleInContextImpl(NamedDecl *D);
855 inline bool Decl::isTemplateParameter() const {
856 return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm;
859 inline bool Decl::isDefinedOutsideFunctionOrMethod() const {
860 if (getDeclContext())
861 return !getDeclContext()->getLookupContext()->isFunctionOrMethod();
869 /// Implement a isa_impl_wrap specialization to check whether a DeclContext is
872 struct isa_impl_wrap<ToTy,
873 const ::clang::DeclContext,const ::clang::DeclContext> {
874 static bool doit(const ::clang::DeclContext &Val) {
875 return ToTy::classof(::clang::Decl::castFromDeclContext(&Val));
879 struct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext>
880 : public isa_impl_wrap<ToTy,
881 const ::clang::DeclContext,const ::clang::DeclContext> {};
883 /// Implement cast_convert_val for Decl -> DeclContext conversions.
884 template<class FromTy>
885 struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> {
886 static ::clang::DeclContext &doit(const FromTy &Val) {
887 return *FromTy::castToDeclContext(&Val);
891 template<class FromTy>
892 struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> {
893 static ::clang::DeclContext *doit(const FromTy *Val) {
894 return FromTy::castToDeclContext(Val);
898 template<class FromTy>
899 struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> {
900 static const ::clang::DeclContext &doit(const FromTy &Val) {
901 return *FromTy::castToDeclContext(&Val);
905 template<class FromTy>
906 struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> {
907 static const ::clang::DeclContext *doit(const FromTy *Val) {
908 return FromTy::castToDeclContext(Val);
912 /// Implement cast_convert_val for DeclContext -> Decl conversions.
914 struct cast_convert_val<ToTy,
915 const ::clang::DeclContext,const ::clang::DeclContext> {
916 static ToTy &doit(const ::clang::DeclContext &Val) {
917 return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val));
921 struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext>
922 : public cast_convert_val<ToTy,
923 const ::clang::DeclContext,const ::clang::DeclContext> {};
926 struct cast_convert_val<ToTy,
927 const ::clang::DeclContext*, const ::clang::DeclContext*> {
928 static ToTy *doit(const ::clang::DeclContext *Val) {
929 return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val));
933 struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*>
934 : public cast_convert_val<ToTy,
935 const ::clang::DeclContext*,const ::clang::DeclContext*> {};
937 } // end namespace llvm