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 #include "clang/Basic/Specifiers.h"
20 #include "llvm/Support/PrettyStackTrace.h"
21 #include "llvm/ADT/PointerUnion.h"
25 class TranslationUnitDecl;
27 class UsingDirectiveDecl;
33 class ObjCContainerDecl;
34 class ObjCInterfaceDecl;
35 class ObjCCategoryDecl;
36 class ObjCProtocolDecl;
37 class ObjCImplementationDecl;
38 class ObjCCategoryImplDecl;
40 class LinkageSpecDecl;
42 class DeclarationName;
45 class DependentDiagnostic;
46 class ASTMutationListener;
50 // DeclContext* is only 4-byte aligned on 32-bit systems.
52 class PointerLikeTypeTraits<clang::DeclContext*> {
53 typedef clang::DeclContext* PT;
55 static inline void *getAsVoidPointer(PT P) { return P; }
56 static inline PT getFromVoidPointer(void *P) {
57 return static_cast<PT>(P);
59 enum { NumLowBitsAvailable = 2 };
65 /// \brief Captures the result of checking the availability of a
67 enum AvailabilityResult {
74 /// Decl - This represents one declaration (or definition), e.g. a variable,
75 /// typedef, function, struct, etc.
79 /// \brief Lists the kind of concrete classes of Decl.
81 #define DECL(DERIVED, BASE) DERIVED,
82 #define ABSTRACT_DECL(DECL)
83 #define DECL_RANGE(BASE, START, END) \
84 first##BASE = START, last##BASE = END,
85 #define LAST_DECL_RANGE(BASE, START, END) \
86 first##BASE = START, last##BASE = END
87 #include "clang/AST/DeclNodes.inc"
90 /// \brief A placeholder type used to construct an empty shell of a
91 /// decl-derived type that will be filled in later (e.g., by some
92 /// deserialization method).
93 struct EmptyShell { };
95 /// IdentifierNamespace - The different namespaces in which
96 /// declarations may appear. According to C99 6.2.3, there are
97 /// four namespaces, labels, tags, members and ordinary
98 /// identifiers. C++ describes lookup completely differently:
99 /// certain lookups merely "ignore" certain kinds of declarations,
100 /// usually based on whether the declaration is of a type, etc.
102 /// These are meant as bitmasks, so that searches in
103 /// C++ can look into the "tag" namespace during ordinary lookup.
105 /// Decl currently provides 15 bits of IDNS bits.
106 enum IdentifierNamespace {
107 /// Labels, declared with 'x:' and referenced with 'goto x'.
110 /// Tags, declared with 'struct foo;' and referenced with
111 /// 'struct foo'. All tags are also types. This is what
112 /// elaborated-type-specifiers look for in C.
115 /// Types, declared with 'struct foo', typedefs, etc.
116 /// This is what elaborated-type-specifiers look for in C++,
117 /// but note that it's ill-formed to find a non-tag.
120 /// Members, declared with object declarations within tag
121 /// definitions. In C, these can only be found by "qualified"
122 /// lookup in member expressions. In C++, they're found by
124 IDNS_Member = 0x0008,
126 /// Namespaces, declared with 'namespace foo {}'.
127 /// Lookup for nested-name-specifiers find these.
128 IDNS_Namespace = 0x0010,
130 /// Ordinary names. In C, everything that's not a label, tag,
131 /// or member ends up here.
132 IDNS_Ordinary = 0x0020,
134 /// Objective C @protocol.
135 IDNS_ObjCProtocol = 0x0040,
137 /// This declaration is a friend function. A friend function
138 /// declaration is always in this namespace but may also be in
139 /// IDNS_Ordinary if it was previously declared.
140 IDNS_OrdinaryFriend = 0x0080,
142 /// This declaration is a friend class. A friend class
143 /// declaration is always in this namespace but may also be in
144 /// IDNS_Tag|IDNS_Type if it was previously declared.
145 IDNS_TagFriend = 0x0100,
147 /// This declaration is a using declaration. A using declaration
148 /// *introduces* a number of other declarations into the current
149 /// scope, and those declarations use the IDNS of their targets,
150 /// but the actual using declarations go in this namespace.
153 /// This declaration is a C++ operator declared in a non-class
154 /// context. All such operators are also in IDNS_Ordinary.
155 /// C++ lexical operator lookup looks for these.
156 IDNS_NonMemberOperator = 0x0400
159 /// ObjCDeclQualifier - 'Qualifiers' written next to the return and
160 /// parameter types in method declarations. Other than remembering
161 /// them and mangling them into the method's signature string, these
162 /// are ignored by the compiler; they are consumed by certain
163 /// remote-messaging frameworks.
165 /// in, inout, and out are mutually exclusive and apply only to
166 /// method parameters. bycopy and byref are mutually exclusive and
167 /// apply only to method parameters (?). oneway applies only to
168 /// results. All of these expect their corresponding parameter to
169 /// have a particular type. None of this is currently enforced by
172 /// This should be kept in sync with ObjCDeclSpec::ObjCDeclQualifier.
173 enum ObjCDeclQualifier {
178 OBJC_TQ_Bycopy = 0x8,
179 OBJC_TQ_Byref = 0x10,
180 OBJC_TQ_Oneway = 0x20
184 /// NextDeclInContext - The next declaration within the same lexical
185 /// DeclContext. These pointers form the linked list that is
186 /// traversed via DeclContext's decls_begin()/decls_end().
187 Decl *NextDeclInContext;
189 friend class DeclContext;
192 DeclContext *SemanticDC;
193 DeclContext *LexicalDC;
197 /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
198 /// For declarations that don't contain C++ scope specifiers, it contains
199 /// the DeclContext where the Decl was declared.
200 /// For declarations with C++ scope specifiers, it contains a MultipleDC*
201 /// with the context where it semantically belongs (SemanticDC) and the
202 /// context where it was lexically declared (LexicalDC).
206 /// void f(); // SemanticDC == LexicalDC == 'namespace A'
208 /// void A::f(); // SemanticDC == namespace 'A'
209 /// // LexicalDC == global namespace
210 llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
212 inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
213 inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
214 inline MultipleDC *getMultipleDC() const {
215 return DeclCtx.get<MultipleDC*>();
217 inline DeclContext *getSemanticDC() const {
218 return DeclCtx.get<DeclContext*>();
221 /// Loc - The location of this decl.
224 /// DeclKind - This indicates which class this is.
225 unsigned DeclKind : 8;
227 /// InvalidDecl - This indicates a semantic error occurred.
228 unsigned InvalidDecl : 1;
230 /// HasAttrs - This indicates whether the decl has attributes or not.
231 unsigned HasAttrs : 1;
233 /// Implicit - Whether this declaration was implicitly generated by
234 /// the implementation rather than explicitly written by the user.
235 unsigned Implicit : 1;
237 /// \brief Whether this declaration was "used", meaning that a definition is
241 /// \brief Whether this declaration was "referenced".
242 /// The difference with 'Used' is whether the reference appears in a
243 /// evaluated context or not, e.g. functions used in uninstantiated templates
244 /// are regarded as "referenced" but not "used".
245 unsigned Referenced : 1;
248 /// Access - Used by C++ decls for the access specifier.
249 // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
251 friend class CXXClassMemberWrapper;
253 /// \brief Whether this declaration was loaded from an AST file.
254 unsigned FromASTFile : 1;
256 /// ChangedAfterLoad - if this declaration has changed since being loaded
257 unsigned ChangedAfterLoad : 1;
259 /// \brief Whether this declaration is private to the module in which it was
261 unsigned ModulePrivate : 1;
263 /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
264 unsigned IdentifierNamespace : 12;
266 /// \brief Whether the \c CachedLinkage field is active.
268 /// This field is only valid for NamedDecls subclasses.
269 mutable unsigned HasCachedLinkage : 1;
271 /// \brief If \c HasCachedLinkage, the linkage of this declaration.
273 /// This field is only valid for NamedDecls subclasses.
274 mutable unsigned CachedLinkage : 2;
276 friend class ASTDeclWriter;
277 friend class ASTDeclReader;
280 void CheckAccessDeclContext() const;
284 Decl(Kind DK, DeclContext *DC, SourceLocation L)
285 : NextDeclInContext(0), DeclCtx(DC),
286 Loc(L), DeclKind(DK), InvalidDecl(0),
287 HasAttrs(false), Implicit(false), Used(false), Referenced(false),
288 Access(AS_none), FromASTFile(0), ChangedAfterLoad(false),
290 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
293 if (Decl::CollectingStats()) add(DK);
296 Decl(Kind DK, EmptyShell Empty)
297 : NextDeclInContext(0), DeclKind(DK), InvalidDecl(0),
298 HasAttrs(false), Implicit(false), Used(false), Referenced(false),
299 Access(AS_none), FromASTFile(0), ChangedAfterLoad(false),
301 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
304 if (Decl::CollectingStats()) add(DK);
311 /// \brief Source range that this declaration covers.
312 virtual SourceRange getSourceRange() const {
313 return SourceRange(getLocation(), getLocation());
315 SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
316 SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
318 SourceLocation getLocation() const { return Loc; }
319 void setLocation(SourceLocation L) { Loc = L; }
321 Kind getKind() const { return static_cast<Kind>(DeclKind); }
322 const char *getDeclKindName() const;
324 Decl *getNextDeclInContext() { return NextDeclInContext; }
325 const Decl *getNextDeclInContext() const { return NextDeclInContext; }
327 DeclContext *getDeclContext() {
329 return getSemanticDC();
330 return getMultipleDC()->SemanticDC;
332 const DeclContext *getDeclContext() const {
333 return const_cast<Decl*>(this)->getDeclContext();
336 /// Finds the innermost non-closure context of this declaration.
337 /// That is, walk out the DeclContext chain, skipping any blocks.
338 DeclContext *getNonClosureContext();
339 const DeclContext *getNonClosureContext() const {
340 return const_cast<Decl*>(this)->getNonClosureContext();
343 TranslationUnitDecl *getTranslationUnitDecl();
344 const TranslationUnitDecl *getTranslationUnitDecl() const {
345 return const_cast<Decl*>(this)->getTranslationUnitDecl();
348 bool isInAnonymousNamespace() const;
350 ASTContext &getASTContext() const;
352 void setAccess(AccessSpecifier AS) {
355 CheckAccessDeclContext();
359 AccessSpecifier getAccess() const {
361 CheckAccessDeclContext();
363 return AccessSpecifier(Access);
366 bool hasAttrs() const { return HasAttrs; }
367 void setAttrs(const AttrVec& Attrs);
368 AttrVec &getAttrs() {
369 return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs());
371 const AttrVec &getAttrs() const;
372 void swapAttrs(Decl *D);
375 void addAttr(Attr *A) {
377 getAttrs().push_back(A);
379 setAttrs(AttrVec(1, A));
382 typedef AttrVec::const_iterator attr_iterator;
384 // FIXME: Do not rely on iterators having comparable singular values.
385 // Note that this should error out if they do not.
386 attr_iterator attr_begin() const {
387 return hasAttrs() ? getAttrs().begin() : 0;
389 attr_iterator attr_end() const {
390 return hasAttrs() ? getAttrs().end() : 0;
393 template <typename T>
395 if (!HasAttrs) return;
397 AttrVec &Attrs = getAttrs();
398 for (unsigned i = 0, e = Attrs.size(); i != e; /* in loop */) {
399 if (isa<T>(Attrs[i])) {
400 Attrs.erase(Attrs.begin() + i);
410 template <typename T>
411 specific_attr_iterator<T> specific_attr_begin() const {
412 return specific_attr_iterator<T>(attr_begin());
414 template <typename T>
415 specific_attr_iterator<T> specific_attr_end() const {
416 return specific_attr_iterator<T>(attr_end());
419 template<typename T> T *getAttr() const {
420 return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : 0;
422 template<typename T> bool hasAttr() const {
423 return hasAttrs() && hasSpecificAttr<T>(getAttrs());
426 /// getMaxAlignment - return the maximum alignment specified by attributes
427 /// on this decl, 0 if there are none.
428 unsigned getMaxAlignment() const {
429 return hasAttrs() ? getMaxAttrAlignment(getAttrs(), getASTContext()) : 0;
432 /// setInvalidDecl - Indicates the Decl had a semantic error. This
433 /// allows for graceful error recovery.
434 void setInvalidDecl(bool Invalid = true);
435 bool isInvalidDecl() const { return (bool) InvalidDecl; }
437 /// isImplicit - Indicates whether the declaration was implicitly
438 /// generated by the implementation. If false, this declaration
439 /// was written explicitly in the source code.
440 bool isImplicit() const { return Implicit; }
441 void setImplicit(bool I = true) { Implicit = I; }
443 /// \brief Whether this declaration was used, meaning that a definition
446 /// \param CheckUsedAttr When true, also consider the "used" attribute
447 /// (in addition to the "used" bit set by \c setUsed()) when determining
448 /// whether the function is used.
449 bool isUsed(bool CheckUsedAttr = true) const;
451 void setUsed(bool U = true) { Used = U; }
453 /// \brief Whether this declaration was referenced.
454 bool isReferenced() const;
456 void setReferenced(bool R = true) { Referenced = R; }
458 /// \brief Determine the availability of the given declaration.
460 /// This routine will determine the most restrictive availability of
461 /// the given declaration (e.g., preferring 'unavailable' to
464 /// \param Message If non-NULL and the result is not \c
465 /// AR_Available, will be set to a (possibly empty) message
466 /// describing why the declaration has not been introduced, is
467 /// deprecated, or is unavailable.
468 AvailabilityResult getAvailability(std::string *Message = 0) const;
470 /// \brief Determine whether this declaration is marked 'deprecated'.
472 /// \param Message If non-NULL and the declaration is deprecated,
473 /// this will be set to the message describing why the declaration
474 /// was deprecated (which may be empty).
475 bool isDeprecated(std::string *Message = 0) const {
476 return getAvailability(Message) == AR_Deprecated;
479 /// \brief Determine whether this declaration is marked 'unavailable'.
481 /// \param Message If non-NULL and the declaration is unavailable,
482 /// this will be set to the message describing why the declaration
483 /// was made unavailable (which may be empty).
484 bool isUnavailable(std::string *Message = 0) const {
485 return getAvailability(Message) == AR_Unavailable;
488 /// \brief Determine whether this is a weak-imported symbol.
490 /// Weak-imported symbols are typically marked with the
491 /// 'weak_import' attribute, but may also be marked with an
492 /// 'availability' attribute where we're targing a platform prior to
493 /// the introduction of this feature.
494 bool isWeakImported() const;
496 /// \brief Determines whether this symbol can be weak-imported,
497 /// e.g., whether it would be well-formed to add the weak_import
500 /// \param IsDefinition Set to \c true to indicate that this
501 /// declaration cannot be weak-imported because it has a definition.
502 bool canBeWeakImported(bool &IsDefinition) const;
504 /// \brief Determine whether this declaration came from an AST file (such as
505 /// a precompiled header or module) rather than having been parsed.
506 bool isFromASTFile() const { return FromASTFile; }
508 /// \brief Query whether this declaration was changed in a significant way
509 /// since being loaded from an AST file.
511 /// In an epic violation of layering, what is "significant" is entirely
512 /// up to the serialization system, but implemented in AST and Sema.
513 bool isChangedSinceDeserialization() const { return ChangedAfterLoad; }
515 /// \brief Mark this declaration as having changed since deserialization, or
517 void setChangedSinceDeserialization(bool Changed) {
518 ChangedAfterLoad = Changed;
521 unsigned getIdentifierNamespace() const {
522 return IdentifierNamespace;
524 bool isInIdentifierNamespace(unsigned NS) const {
525 return getIdentifierNamespace() & NS;
527 static unsigned getIdentifierNamespaceForKind(Kind DK);
529 bool hasTagIdentifierNamespace() const {
530 return isTagIdentifierNamespace(getIdentifierNamespace());
532 static bool isTagIdentifierNamespace(unsigned NS) {
533 // TagDecls have Tag and Type set and may also have TagFriend.
534 return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type);
537 /// getLexicalDeclContext - The declaration context where this Decl was
538 /// lexically declared (LexicalDC). May be different from
539 /// getDeclContext() (SemanticDC).
543 /// void f(); // SemanticDC == LexicalDC == 'namespace A'
545 /// void A::f(); // SemanticDC == namespace 'A'
546 /// // LexicalDC == global namespace
547 DeclContext *getLexicalDeclContext() {
549 return getSemanticDC();
550 return getMultipleDC()->LexicalDC;
552 const DeclContext *getLexicalDeclContext() const {
553 return const_cast<Decl*>(this)->getLexicalDeclContext();
556 virtual bool isOutOfLine() const {
557 return getLexicalDeclContext() != getDeclContext();
560 /// setDeclContext - Set both the semantic and lexical DeclContext
562 void setDeclContext(DeclContext *DC);
564 void setLexicalDeclContext(DeclContext *DC);
566 /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this
567 /// scoped decl is defined outside the current function or method. This is
568 /// roughly global variables and functions, but also handles enums (which
569 /// could be defined inside or outside a function etc).
570 bool isDefinedOutsideFunctionOrMethod() const {
571 return getParentFunctionOrMethod() == 0;
574 /// \brief If this decl is defined inside a function/method/block it returns
575 /// the corresponding DeclContext, otherwise it returns null.
576 const DeclContext *getParentFunctionOrMethod() const;
577 DeclContext *getParentFunctionOrMethod() {
578 return const_cast<DeclContext*>(
579 const_cast<const Decl*>(this)->getParentFunctionOrMethod());
582 /// \brief Retrieves the "canonical" declaration of the given declaration.
583 virtual Decl *getCanonicalDecl() { return this; }
584 const Decl *getCanonicalDecl() const {
585 return const_cast<Decl*>(this)->getCanonicalDecl();
588 /// \brief Whether this particular Decl is a canonical one.
589 bool isCanonicalDecl() const { return getCanonicalDecl() == this; }
592 /// \brief Returns the next redeclaration or itself if this is the only decl.
594 /// Decl subclasses that can be redeclared should override this method so that
595 /// Decl::redecl_iterator can iterate over them.
596 virtual Decl *getNextRedeclaration() { return this; }
599 /// \brief Iterates through all the redeclarations of the same decl.
600 class redecl_iterator {
601 /// Current - The current declaration.
606 typedef Decl* value_type;
607 typedef Decl* reference;
608 typedef Decl* pointer;
609 typedef std::forward_iterator_tag iterator_category;
610 typedef std::ptrdiff_t difference_type;
612 redecl_iterator() : Current(0) { }
613 explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { }
615 reference operator*() const { return Current; }
616 pointer operator->() const { return Current; }
618 redecl_iterator& operator++() {
619 assert(Current && "Advancing while iterator has reached end");
620 // Get either previous decl or latest decl.
621 Decl *Next = Current->getNextRedeclaration();
622 assert(Next && "Should return next redeclaration or itself, never null!");
623 Current = (Next != Starter ? Next : 0);
627 redecl_iterator operator++(int) {
628 redecl_iterator tmp(*this);
633 friend bool operator==(redecl_iterator x, redecl_iterator y) {
634 return x.Current == y.Current;
636 friend bool operator!=(redecl_iterator x, redecl_iterator y) {
637 return x.Current != y.Current;
641 /// \brief Returns iterator for all the redeclarations of the same decl.
642 /// It will iterate at least once (when this decl is the only one).
643 redecl_iterator redecls_begin() const {
644 return redecl_iterator(const_cast<Decl*>(this));
646 redecl_iterator redecls_end() const { return redecl_iterator(); }
648 /// getBody - If this Decl represents a declaration for a body of code,
649 /// such as a function or method definition, this method returns the
650 /// top-level Stmt* of that body. Otherwise this method returns null.
651 virtual Stmt* getBody() const { return 0; }
653 /// \brief Returns true if this Decl represents a declaration for a body of
654 /// code, such as a function or method definition.
655 virtual bool hasBody() const { return getBody() != 0; }
657 /// getBodyRBrace - Gets the right brace of the body, if a body exists.
658 /// This works whether the body is a CompoundStmt or a CXXTryStmt.
659 SourceLocation getBodyRBrace() const;
661 // global temp stats (until we have a per-module visitor)
662 static void add(Kind k);
663 static bool CollectingStats(bool Enable = false);
664 static void PrintStats();
666 /// isTemplateParameter - Determines whether this declaration is a
667 /// template parameter.
668 bool isTemplateParameter() const;
670 /// isTemplateParameter - Determines whether this declaration is a
671 /// template parameter pack.
672 bool isTemplateParameterPack() const;
674 /// \brief Whether this declaration is a parameter pack.
675 bool isParameterPack() const;
677 /// \brief returns true if this declaration is a template
678 bool isTemplateDecl() const;
680 /// \brief Whether this declaration is a function or function template.
681 bool isFunctionOrFunctionTemplate() const;
683 /// \brief Changes the namespace of this declaration to reflect that it's
684 /// the object of a friend declaration.
686 /// These declarations appear in the lexical context of the friending
687 /// class, but in the semantic context of the actual entity. This property
688 /// applies only to a specific decl object; other redeclarations of the
689 /// same entity may not (and probably don't) share this property.
690 void setObjectOfFriendDecl(bool PreviouslyDeclared) {
691 unsigned OldNS = IdentifierNamespace;
692 assert((OldNS & (IDNS_Tag | IDNS_Ordinary |
693 IDNS_TagFriend | IDNS_OrdinaryFriend)) &&
694 "namespace includes neither ordinary nor tag");
695 assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type |
696 IDNS_TagFriend | IDNS_OrdinaryFriend)) &&
697 "namespace includes other than ordinary or tag");
699 IdentifierNamespace = 0;
700 if (OldNS & (IDNS_Tag | IDNS_TagFriend)) {
701 IdentifierNamespace |= IDNS_TagFriend;
702 if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Tag | IDNS_Type;
705 if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend)) {
706 IdentifierNamespace |= IDNS_OrdinaryFriend;
707 if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Ordinary;
711 enum FriendObjectKind {
712 FOK_None, // not a friend object
713 FOK_Declared, // a friend of a previously-declared entity
714 FOK_Undeclared // a friend of a previously-undeclared entity
717 /// \brief Determines whether this declaration is the object of a
718 /// friend declaration and, if so, what kind.
720 /// There is currently no direct way to find the associated FriendDecl.
721 FriendObjectKind getFriendObjectKind() const {
723 = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend));
724 if (!mask) return FOK_None;
725 return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ?
726 FOK_Declared : FOK_Undeclared);
729 /// Specifies that this declaration is a C++ overloaded non-member.
730 void setNonMemberOperator() {
731 assert(getKind() == Function || getKind() == FunctionTemplate);
732 assert((IdentifierNamespace & IDNS_Ordinary) &&
733 "visible non-member operators should be in ordinary namespace");
734 IdentifierNamespace |= IDNS_NonMemberOperator;
737 // Implement isa/cast/dyncast/etc.
738 static bool classof(const Decl *) { return true; }
739 static bool classofKind(Kind K) { return true; }
740 static DeclContext *castToDeclContext(const Decl *);
741 static Decl *castFromDeclContext(const DeclContext *);
743 void print(raw_ostream &Out, unsigned Indentation = 0,
744 bool PrintInstantiation = false) const;
745 void print(raw_ostream &Out, const PrintingPolicy &Policy,
746 unsigned Indentation = 0, bool PrintInstantiation = false) const;
747 static void printGroup(Decl** Begin, unsigned NumDecls,
748 raw_ostream &Out, const PrintingPolicy &Policy,
749 unsigned Indentation = 0);
751 void dumpXML() const;
752 void dumpXML(raw_ostream &OS) const;
755 const Attr *getAttrsImpl() const;
758 ASTMutationListener *getASTMutationListener() const;
761 /// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when
762 /// doing something to a specific decl.
763 class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry {
769 PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L,
770 SourceManager &sm, const char *Msg)
771 : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {}
773 virtual void print(raw_ostream &OS) const;
776 class DeclContextLookupResult
777 : public std::pair<NamedDecl**,NamedDecl**> {
779 DeclContextLookupResult(NamedDecl **I, NamedDecl **E)
780 : std::pair<NamedDecl**,NamedDecl**>(I, E) {}
781 DeclContextLookupResult()
782 : std::pair<NamedDecl**,NamedDecl**>() {}
784 using std::pair<NamedDecl**,NamedDecl**>::operator=;
787 class DeclContextLookupConstResult
788 : public std::pair<NamedDecl*const*, NamedDecl*const*> {
790 DeclContextLookupConstResult(std::pair<NamedDecl**,NamedDecl**> R)
791 : std::pair<NamedDecl*const*, NamedDecl*const*>(R) {}
792 DeclContextLookupConstResult(NamedDecl * const *I, NamedDecl * const *E)
793 : std::pair<NamedDecl*const*, NamedDecl*const*>(I, E) {}
794 DeclContextLookupConstResult()
795 : std::pair<NamedDecl*const*, NamedDecl*const*>() {}
797 using std::pair<NamedDecl*const*,NamedDecl*const*>::operator=;
800 /// DeclContext - This is used only as base class of specific decl types that
801 /// can act as declaration contexts. These decls are (only the top classes
802 /// that directly derive from DeclContext are mentioned, not their subclasses):
804 /// TranslationUnitDecl
809 /// ObjCContainerDecl
814 /// DeclKind - This indicates which class this is.
815 unsigned DeclKind : 8;
817 /// \brief Whether this declaration context also has some external
818 /// storage that contains additional declarations that are lexically
819 /// part of this context.
820 mutable unsigned ExternalLexicalStorage : 1;
822 /// \brief Whether this declaration context also has some external
823 /// storage that contains additional declarations that are visible
825 mutable unsigned ExternalVisibleStorage : 1;
827 /// \brief Pointer to the data structure used to lookup declarations
828 /// within this context (or a DependentStoredDeclsMap if this is a
829 /// dependent context).
830 mutable StoredDeclsMap *LookupPtr;
833 /// FirstDecl - The first declaration stored within this declaration
835 mutable Decl *FirstDecl;
837 /// LastDecl - The last declaration stored within this declaration
838 /// context. FIXME: We could probably cache this value somewhere
839 /// outside of the DeclContext, to reduce the size of DeclContext by
841 mutable Decl *LastDecl;
843 friend class ExternalASTSource;
845 /// \brief Build up a chain of declarations.
847 /// \returns the first/last pair of declarations.
848 static std::pair<Decl *, Decl *>
849 BuildDeclChain(const SmallVectorImpl<Decl*> &Decls, bool FieldsAlreadyLoaded);
851 DeclContext(Decl::Kind K)
852 : DeclKind(K), ExternalLexicalStorage(false),
853 ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0),
859 Decl::Kind getDeclKind() const {
860 return static_cast<Decl::Kind>(DeclKind);
862 const char *getDeclKindName() const;
864 /// getParent - Returns the containing DeclContext.
865 DeclContext *getParent() {
866 return cast<Decl>(this)->getDeclContext();
868 const DeclContext *getParent() const {
869 return const_cast<DeclContext*>(this)->getParent();
872 /// getLexicalParent - Returns the containing lexical DeclContext. May be
873 /// different from getParent, e.g.:
878 /// struct A::S {}; // getParent() == namespace 'A'
879 /// // getLexicalParent() == translation unit
881 DeclContext *getLexicalParent() {
882 return cast<Decl>(this)->getLexicalDeclContext();
884 const DeclContext *getLexicalParent() const {
885 return const_cast<DeclContext*>(this)->getLexicalParent();
888 DeclContext *getLookupParent();
890 const DeclContext *getLookupParent() const {
891 return const_cast<DeclContext*>(this)->getLookupParent();
894 ASTContext &getParentASTContext() const {
895 return cast<Decl>(this)->getASTContext();
898 bool isClosure() const {
899 return DeclKind == Decl::Block;
902 bool isObjCContainer() const {
904 case Decl::ObjCCategory:
905 case Decl::ObjCCategoryImpl:
906 case Decl::ObjCImplementation:
907 case Decl::ObjCInterface:
908 case Decl::ObjCProtocol:
914 bool isFunctionOrMethod() const {
917 case Decl::ObjCMethod:
920 return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction;
924 bool isFileContext() const {
925 return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace;
928 bool isTranslationUnit() const {
929 return DeclKind == Decl::TranslationUnit;
932 bool isRecord() const {
933 return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord;
936 bool isNamespace() const {
937 return DeclKind == Decl::Namespace;
940 bool isInlineNamespace() const;
942 /// \brief Determines whether this context is dependent on a
943 /// template parameter.
944 bool isDependentContext() const;
946 /// isTransparentContext - Determines whether this context is a
947 /// "transparent" context, meaning that the members declared in this
948 /// context are semantically declared in the nearest enclosing
949 /// non-transparent (opaque) context but are lexically declared in
950 /// this context. For example, consider the enumerators of an
951 /// enumeration type:
957 /// Here, E is a transparent context, so its enumerator (Val1) will
958 /// appear (semantically) that it is in the same context of E.
959 /// Examples of transparent contexts include: enumerations (except for
960 /// C++0x scoped enums), and C++ linkage specifications.
961 bool isTransparentContext() const;
963 /// \brief Determines whether this context is, or is nested within,
964 /// a C++ extern "C" linkage spec.
965 bool isExternCContext() const;
967 /// \brief Determine whether this declaration context is equivalent
968 /// to the declaration context DC.
969 bool Equals(const DeclContext *DC) const {
970 return DC && this->getPrimaryContext() == DC->getPrimaryContext();
973 /// \brief Determine whether this declaration context encloses the
974 /// declaration context DC.
975 bool Encloses(const DeclContext *DC) const;
977 /// getPrimaryContext - There may be many different
978 /// declarations of the same entity (including forward declarations
979 /// of classes, multiple definitions of namespaces, etc.), each with
980 /// a different set of declarations. This routine returns the
981 /// "primary" DeclContext structure, which will contain the
982 /// information needed to perform name lookup into this context.
983 DeclContext *getPrimaryContext();
984 const DeclContext *getPrimaryContext() const {
985 return const_cast<DeclContext*>(this)->getPrimaryContext();
988 /// getRedeclContext - Retrieve the context in which an entity conflicts with
989 /// other entities of the same name, or where it is a redeclaration if the
990 /// two entities are compatible. This skips through transparent contexts.
991 DeclContext *getRedeclContext();
992 const DeclContext *getRedeclContext() const {
993 return const_cast<DeclContext *>(this)->getRedeclContext();
996 /// \brief Retrieve the nearest enclosing namespace context.
997 DeclContext *getEnclosingNamespaceContext();
998 const DeclContext *getEnclosingNamespaceContext() const {
999 return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext();
1002 /// \brief Test if this context is part of the enclosing namespace set of
1003 /// the context NS, as defined in C++0x [namespace.def]p9. If either context
1004 /// isn't a namespace, this is equivalent to Equals().
1006 /// The enclosing namespace set of a namespace is the namespace and, if it is
1007 /// inline, its enclosing namespace, recursively.
1008 bool InEnclosingNamespaceSetOf(const DeclContext *NS) const;
1010 /// getNextContext - If this is a DeclContext that may have other
1011 /// DeclContexts that are semantically connected but syntactically
1012 /// different, such as C++ namespaces, this routine retrieves the
1013 /// next DeclContext in the link. Iteration through the chain of
1014 /// DeclContexts should begin at the primary DeclContext and
1015 /// continue until this function returns NULL. For example, given:
1024 /// The first occurrence of namespace N will be the primary
1025 /// DeclContext. Its getNextContext will return the second
1026 /// occurrence of namespace N.
1027 DeclContext *getNextContext();
1029 /// decl_iterator - Iterates through the declarations stored
1030 /// within this context.
1031 class decl_iterator {
1032 /// Current - The current declaration.
1036 typedef Decl* value_type;
1037 typedef Decl* reference;
1038 typedef Decl* pointer;
1039 typedef std::forward_iterator_tag iterator_category;
1040 typedef std::ptrdiff_t difference_type;
1042 decl_iterator() : Current(0) { }
1043 explicit decl_iterator(Decl *C) : Current(C) { }
1045 reference operator*() const { return Current; }
1046 pointer operator->() const { return Current; }
1048 decl_iterator& operator++() {
1049 Current = Current->getNextDeclInContext();
1053 decl_iterator operator++(int) {
1054 decl_iterator tmp(*this);
1059 friend bool operator==(decl_iterator x, decl_iterator y) {
1060 return x.Current == y.Current;
1062 friend bool operator!=(decl_iterator x, decl_iterator y) {
1063 return x.Current != y.Current;
1067 /// decls_begin/decls_end - Iterate over the declarations stored in
1069 decl_iterator decls_begin() const;
1070 decl_iterator decls_end() const;
1071 bool decls_empty() const;
1073 /// noload_decls_begin/end - Iterate over the declarations stored in this
1074 /// context that are currently loaded; don't attempt to retrieve anything
1075 /// from an external source.
1076 decl_iterator noload_decls_begin() const;
1077 decl_iterator noload_decls_end() const;
1079 /// specific_decl_iterator - Iterates over a subrange of
1080 /// declarations stored in a DeclContext, providing only those that
1081 /// are of type SpecificDecl (or a class derived from it). This
1082 /// iterator is used, for example, to provide iteration over just
1083 /// the fields within a RecordDecl (with SpecificDecl = FieldDecl).
1084 template<typename SpecificDecl>
1085 class specific_decl_iterator {
1086 /// Current - The current, underlying declaration iterator, which
1087 /// will either be NULL or will point to a declaration of
1088 /// type SpecificDecl.
1089 DeclContext::decl_iterator Current;
1091 /// SkipToNextDecl - Advances the current position up to the next
1092 /// declaration of type SpecificDecl that also meets the criteria
1093 /// required by Acceptable.
1094 void SkipToNextDecl() {
1095 while (*Current && !isa<SpecificDecl>(*Current))
1100 typedef SpecificDecl* value_type;
1101 typedef SpecificDecl* reference;
1102 typedef SpecificDecl* pointer;
1103 typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
1105 typedef std::forward_iterator_tag iterator_category;
1107 specific_decl_iterator() : Current() { }
1109 /// specific_decl_iterator - Construct a new iterator over a
1110 /// subset of the declarations the range [C,
1111 /// end-of-declarations). If A is non-NULL, it is a pointer to a
1112 /// member function of SpecificDecl that should return true for
1113 /// all of the SpecificDecl instances that will be in the subset
1114 /// of iterators. For example, if you want Objective-C instance
1115 /// methods, SpecificDecl will be ObjCMethodDecl and A will be
1116 /// &ObjCMethodDecl::isInstanceMethod.
1117 explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) {
1121 reference operator*() const { return cast<SpecificDecl>(*Current); }
1122 pointer operator->() const { return cast<SpecificDecl>(*Current); }
1124 specific_decl_iterator& operator++() {
1130 specific_decl_iterator operator++(int) {
1131 specific_decl_iterator tmp(*this);
1137 operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) {
1138 return x.Current == y.Current;
1142 operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) {
1143 return x.Current != y.Current;
1147 /// \brief Iterates over a filtered subrange of declarations stored
1148 /// in a DeclContext.
1150 /// This iterator visits only those declarations that are of type
1151 /// SpecificDecl (or a class derived from it) and that meet some
1152 /// additional run-time criteria. This iterator is used, for
1153 /// example, to provide access to the instance methods within an
1154 /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and
1155 /// Acceptable = ObjCMethodDecl::isInstanceMethod).
1156 template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const>
1157 class filtered_decl_iterator {
1158 /// Current - The current, underlying declaration iterator, which
1159 /// will either be NULL or will point to a declaration of
1160 /// type SpecificDecl.
1161 DeclContext::decl_iterator Current;
1163 /// SkipToNextDecl - Advances the current position up to the next
1164 /// declaration of type SpecificDecl that also meets the criteria
1165 /// required by Acceptable.
1166 void SkipToNextDecl() {
1168 (!isa<SpecificDecl>(*Current) ||
1169 (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)())))
1174 typedef SpecificDecl* value_type;
1175 typedef SpecificDecl* reference;
1176 typedef SpecificDecl* pointer;
1177 typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
1179 typedef std::forward_iterator_tag iterator_category;
1181 filtered_decl_iterator() : Current() { }
1183 /// specific_decl_iterator - Construct a new iterator over a
1184 /// subset of the declarations the range [C,
1185 /// end-of-declarations). If A is non-NULL, it is a pointer to a
1186 /// member function of SpecificDecl that should return true for
1187 /// all of the SpecificDecl instances that will be in the subset
1188 /// of iterators. For example, if you want Objective-C instance
1189 /// methods, SpecificDecl will be ObjCMethodDecl and A will be
1190 /// &ObjCMethodDecl::isInstanceMethod.
1191 explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) {
1195 reference operator*() const { return cast<SpecificDecl>(*Current); }
1196 pointer operator->() const { return cast<SpecificDecl>(*Current); }
1198 filtered_decl_iterator& operator++() {
1204 filtered_decl_iterator operator++(int) {
1205 filtered_decl_iterator tmp(*this);
1211 operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) {
1212 return x.Current == y.Current;
1216 operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) {
1217 return x.Current != y.Current;
1221 /// @brief Add the declaration D into this context.
1223 /// This routine should be invoked when the declaration D has first
1224 /// been declared, to place D into the context where it was
1225 /// (lexically) defined. Every declaration must be added to one
1226 /// (and only one!) context, where it can be visited via
1227 /// [decls_begin(), decls_end()). Once a declaration has been added
1228 /// to its lexical context, the corresponding DeclContext owns the
1231 /// If D is also a NamedDecl, it will be made visible within its
1232 /// semantic context via makeDeclVisibleInContext.
1233 void addDecl(Decl *D);
1235 /// @brief Add the declaration D to this context without modifying
1236 /// any lookup tables.
1238 /// This is useful for some operations in dependent contexts where
1239 /// the semantic context might not be dependent; this basically
1240 /// only happens with friends.
1241 void addHiddenDecl(Decl *D);
1243 /// @brief Removes a declaration from this context.
1244 void removeDecl(Decl *D);
1246 /// lookup_iterator - An iterator that provides access to the results
1247 /// of looking up a name within this context.
1248 typedef NamedDecl **lookup_iterator;
1250 /// lookup_const_iterator - An iterator that provides non-mutable
1251 /// access to the results of lookup up a name within this context.
1252 typedef NamedDecl * const * lookup_const_iterator;
1254 typedef DeclContextLookupResult lookup_result;
1255 typedef DeclContextLookupConstResult lookup_const_result;
1257 /// lookup - Find the declarations (if any) with the given Name in
1258 /// this context. Returns a range of iterators that contains all of
1259 /// the declarations with this name, with object, function, member,
1260 /// and enumerator names preceding any tag name. Note that this
1261 /// routine will not look into parent contexts.
1262 lookup_result lookup(DeclarationName Name);
1263 lookup_const_result lookup(DeclarationName Name) const;
1265 /// \brief A simplistic name lookup mechanism that performs name lookup
1266 /// into this declaration context without consulting the external source.
1268 /// This function should almost never be used, because it subverts the
1269 /// usual relationship between a DeclContext and the external source.
1270 /// See the ASTImporter for the (few, but important) use cases.
1271 void localUncachedLookup(DeclarationName Name,
1272 llvm::SmallVectorImpl<NamedDecl *> &Results);
1274 /// @brief Makes a declaration visible within this context.
1276 /// This routine makes the declaration D visible to name lookup
1277 /// within this context and, if this is a transparent context,
1278 /// within its parent contexts up to the first enclosing
1279 /// non-transparent context. Making a declaration visible within a
1280 /// context does not transfer ownership of a declaration, and a
1281 /// declaration can be visible in many contexts that aren't its
1282 /// lexical context.
1284 /// If D is a redeclaration of an existing declaration that is
1285 /// visible from this context, as determined by
1286 /// NamedDecl::declarationReplaces, the previous declaration will be
1287 /// replaced with D.
1289 /// @param Recoverable true if it's okay to not add this decl to
1290 /// the lookup tables because it can be easily recovered by walking
1291 /// the declaration chains.
1292 void makeDeclVisibleInContext(NamedDecl *D, bool Recoverable = true);
1294 /// udir_iterator - Iterates through the using-directives stored
1295 /// within this context.
1296 typedef UsingDirectiveDecl * const * udir_iterator;
1298 typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range;
1300 udir_iterator_range getUsingDirectives() const;
1302 udir_iterator using_directives_begin() const {
1303 return getUsingDirectives().first;
1306 udir_iterator using_directives_end() const {
1307 return getUsingDirectives().second;
1310 // These are all defined in DependentDiagnostic.h.
1311 class ddiag_iterator;
1312 inline ddiag_iterator ddiag_begin() const;
1313 inline ddiag_iterator ddiag_end() const;
1315 // Low-level accessors
1317 /// \brief Retrieve the internal representation of the lookup structure.
1318 StoredDeclsMap* getLookupPtr() const { return LookupPtr; }
1320 /// \brief Whether this DeclContext has external storage containing
1321 /// additional declarations that are lexically in this context.
1322 bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; }
1324 /// \brief State whether this DeclContext has external storage for
1325 /// declarations lexically in this context.
1326 void setHasExternalLexicalStorage(bool ES = true) {
1327 ExternalLexicalStorage = ES;
1330 /// \brief Whether this DeclContext has external storage containing
1331 /// additional declarations that are visible in this context.
1332 bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; }
1334 /// \brief State whether this DeclContext has external storage for
1335 /// declarations visible in this context.
1336 void setHasExternalVisibleStorage(bool ES = true) {
1337 ExternalVisibleStorage = ES;
1340 /// \brief Determine whether the given declaration is stored in the list of
1341 /// declarations lexically within this context.
1342 bool isDeclInLexicalTraversal(const Decl *D) const {
1343 return D && (D->NextDeclInContext || D == FirstDecl || D == LastDecl);
1346 static bool classof(const Decl *D);
1347 static bool classof(const DeclContext *D) { return true; }
1348 #define DECL(NAME, BASE)
1349 #define DECL_CONTEXT(NAME) \
1350 static bool classof(const NAME##Decl *D) { return true; }
1351 #include "clang/AST/DeclNodes.inc"
1353 void dumpDeclContext() const;
1356 void LoadLexicalDeclsFromExternalStorage() const;
1358 friend class DependentDiagnostic;
1359 StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const;
1361 void buildLookup(DeclContext *DCtx);
1362 void makeDeclVisibleInContextImpl(NamedDecl *D);
1365 inline bool Decl::isTemplateParameter() const {
1366 return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm ||
1367 getKind() == TemplateTemplateParm;
1370 // Specialization selected when ToTy is not a known subclass of DeclContext.
1371 template <class ToTy,
1372 bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value>
1373 struct cast_convert_decl_context {
1374 static const ToTy *doit(const DeclContext *Val) {
1375 return static_cast<const ToTy*>(Decl::castFromDeclContext(Val));
1378 static ToTy *doit(DeclContext *Val) {
1379 return static_cast<ToTy*>(Decl::castFromDeclContext(Val));
1383 // Specialization selected when ToTy is a known subclass of DeclContext.
1384 template <class ToTy>
1385 struct cast_convert_decl_context<ToTy, true> {
1386 static const ToTy *doit(const DeclContext *Val) {
1387 return static_cast<const ToTy*>(Val);
1390 static ToTy *doit(DeclContext *Val) {
1391 return static_cast<ToTy*>(Val);
1400 /// isa<T>(DeclContext*)
1401 template <typename To>
1402 struct isa_impl<To, ::clang::DeclContext> {
1403 static bool doit(const ::clang::DeclContext &Val) {
1404 return To::classofKind(Val.getDeclKind());
1408 /// cast<T>(DeclContext*)
1409 template<class ToTy>
1410 struct cast_convert_val<ToTy,
1411 const ::clang::DeclContext,const ::clang::DeclContext> {
1412 static const ToTy &doit(const ::clang::DeclContext &Val) {
1413 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
1416 template<class ToTy>
1417 struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> {
1418 static ToTy &doit(::clang::DeclContext &Val) {
1419 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
1422 template<class ToTy>
1423 struct cast_convert_val<ToTy,
1424 const ::clang::DeclContext*, const ::clang::DeclContext*> {
1425 static const ToTy *doit(const ::clang::DeclContext *Val) {
1426 return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
1429 template<class ToTy>
1430 struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> {
1431 static ToTy *doit(::clang::DeclContext *Val) {
1432 return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
1436 /// Implement cast_convert_val for Decl -> DeclContext conversions.
1437 template<class FromTy>
1438 struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> {
1439 static ::clang::DeclContext &doit(const FromTy &Val) {
1440 return *FromTy::castToDeclContext(&Val);
1444 template<class FromTy>
1445 struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> {
1446 static ::clang::DeclContext *doit(const FromTy *Val) {
1447 return FromTy::castToDeclContext(Val);
1451 template<class FromTy>
1452 struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> {
1453 static const ::clang::DeclContext &doit(const FromTy &Val) {
1454 return *FromTy::castToDeclContext(&Val);
1458 template<class FromTy>
1459 struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> {
1460 static const ::clang::DeclContext *doit(const FromTy *Val) {
1461 return FromTy::castToDeclContext(Val);
1465 } // end namespace llvm