DeclBase.h revision f8d49f64ef6ab7e632717a31631fc289aab69428
1//===-- DeclBase.h - Base Classes for representing declarations *- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the Decl and DeclContext interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLBASE_H
15#define LLVM_CLANG_AST_DECLBASE_H
16
17#include "clang/AST/Attr.h"
18#include "clang/AST/Type.h"
19#include "clang/Basic/SourceLocation.h"
20#include "llvm/ADT/PointerIntPair.h"
21#include <vector>
22
23namespace clang {
24class DeclContext;
25class TranslationUnitDecl;
26class NamespaceDecl;
27class NamedDecl;
28class ScopedDecl;
29class FunctionDecl;
30class CXXRecordDecl;
31class EnumDecl;
32class ObjCMethodDecl;
33class ObjCInterfaceDecl;
34class ObjCCategoryDecl;
35class ObjCProtocolDecl;
36class ObjCImplementationDecl;
37class ObjCCategoryImplDecl;
38class LinkageSpecDecl;
39class BlockDecl;
40class DeclarationName;
41
42/// Decl - This represents one declaration (or definition), e.g. a variable,
43/// typedef, function, struct, etc.
44///
45class Decl {
46public:
47  enum Kind {
48    // This lists the concrete classes of Decl in order of the inheritance
49    // hierarchy.  This allows us to do efficient classof tests based on the
50    // enums below.   The commented out names are abstract class names.
51    // [DeclContext] indicates that the class also inherits from DeclContext.
52
53    // Decl
54         TranslationUnit,  // [DeclContext]
55    //   NamedDecl
56           OverloadedFunction,
57    //     ScopedDecl
58             Field,
59               ObjCIvar,
60               ObjCAtDefsField,
61             Namespace,  // [DeclContext]
62    //       TypeDecl
63               Typedef,
64    //         TagDecl // [DeclContext]
65                 Enum,
66                 Record,
67                   CXXRecord,
68 	       TemplateTypeParm,
69    //       ValueDecl
70               EnumConstant,
71               Function,  // [DeclContext]
72                 CXXMethod,
73                   CXXConstructor,
74                   CXXDestructor,
75                   CXXConversion,
76               Var,
77                 ImplicitParam,
78                 CXXClassVar,
79                 ParmVar,
80                   OriginalParmVar,
81  	         NonTypeTemplateParm,
82             LinkageSpec, // [DeclContext]
83             ObjCMethod,  // [DeclContext]
84           ObjCContainer, // [DeclContext]
85             ObjCCategory,
86             ObjCProtocol,
87             ObjCInterface,
88             ObjCCategoryImpl,  // [DeclContext]
89             ObjCImplementation, // [DeclContext]
90             ObjCProperty,
91             ObjCCompatibleAlias,
92             ObjCClass,
93             ObjCForwardProtocol,
94             ObjCPropertyImpl,
95         FileScopeAsm,
96	     Block, // [DeclContext]
97
98    // For each non-leaf class, we now define a mapping to the first/last member
99    // of the class, to allow efficient classof.
100    NamedFirst    = OverloadedFunction, NamedLast   = NonTypeTemplateParm,
101    ObjCContainerFirst = ObjCContainer, ObjCContainerLast = ObjCInterface,
102    FieldFirst         = Field        , FieldLast     = ObjCAtDefsField,
103    ScopedFirst        = Field        , ScopedLast    = ObjCPropertyImpl,
104    TypeFirst          = Typedef      , TypeLast      = TemplateTypeParm,
105    TagFirst           = Enum         , TagLast       = CXXRecord,
106    RecordFirst        = Record       , RecordLast    = CXXRecord,
107    ValueFirst         = EnumConstant , ValueLast     = NonTypeTemplateParm,
108    FunctionFirst      = Function     , FunctionLast  = CXXConversion,
109    VarFirst           = Var          , VarLast       = NonTypeTemplateParm
110  };
111
112  /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces,
113  /// labels, tags, members and ordinary identifiers. These are meant
114  /// as bitmasks, so that searches in C++ can look into the "tag" namespace
115  /// during ordinary lookup.
116  enum IdentifierNamespace {
117    IDNS_Label = 0x1,
118    IDNS_Tag = 0x2,
119    IDNS_Member = 0x4,
120    IDNS_Ordinary = 0x8
121  };
122
123  /// ObjCDeclQualifier - Qualifier used on types in method declarations
124  /// for remote messaging. They are meant for the arguments though and
125  /// applied to the Decls (ObjCMethodDecl and ParmVarDecl).
126  enum ObjCDeclQualifier {
127    OBJC_TQ_None = 0x0,
128    OBJC_TQ_In = 0x1,
129    OBJC_TQ_Inout = 0x2,
130    OBJC_TQ_Out = 0x4,
131    OBJC_TQ_Bycopy = 0x8,
132    OBJC_TQ_Byref = 0x10,
133    OBJC_TQ_Oneway = 0x20
134  };
135
136private:
137  /// Loc - The location that this decl.
138  SourceLocation Loc;
139
140  /// DeclKind - This indicates which class this is.
141  Kind DeclKind   :  8;
142
143  /// InvalidDecl - This indicates a semantic error occurred.
144  unsigned int InvalidDecl :  1;
145
146  /// HasAttrs - This indicates whether the decl has attributes or not.
147  unsigned int HasAttrs : 1;
148
149  /// Implicit - Whether this declaration was implicitly generated by
150  /// the implementation rather than explicitly written by the user.
151  bool Implicit : 1;
152
153 protected:
154  /// Access - Used by C++ decls for the access specifier.
155  // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
156  unsigned Access : 2;
157  friend class CXXClassMemberWrapper;
158
159  Decl(Kind DK, SourceLocation L) : Loc(L), DeclKind(DK), InvalidDecl(0),
160    HasAttrs(false), Implicit(false) {
161    if (Decl::CollectingStats()) addDeclKind(DK);
162  }
163
164  virtual ~Decl();
165
166public:
167  SourceLocation getLocation() const { return Loc; }
168  void setLocation(SourceLocation L) { Loc = L; }
169
170  Kind getKind() const { return DeclKind; }
171  const char *getDeclKindName() const;
172
173  void addAttr(Attr *attr);
174  const Attr *getAttrs() const;
175  void swapAttrs(Decl *D);
176  void invalidateAttrs();
177
178  template<typename T> const T *getAttr() const {
179    for (const Attr *attr = getAttrs(); attr; attr = attr->getNext())
180      if (const T *V = dyn_cast<T>(attr))
181        return V;
182
183    return 0;
184  }
185
186  /// setInvalidDecl - Indicates the Decl had a semantic error. This
187  /// allows for graceful error recovery.
188  void setInvalidDecl() { InvalidDecl = 1; }
189  bool isInvalidDecl() const { return (bool) InvalidDecl; }
190
191  /// isImplicit - Indicates whether the declaration was implicitly
192  /// generated by the implementation. If false, this declaration
193  /// was written explicitly in the source code.
194  bool isImplicit() const { return Implicit; }
195  void setImplicit(bool I = true) { Implicit = I; }
196
197  IdentifierNamespace getIdentifierNamespace() const {
198    switch (DeclKind) {
199    default:
200      if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast)
201        return IDNS_Ordinary;
202      assert(0 && "Unknown decl kind!");
203    case ImplicitParam:
204    case Typedef:
205    case Var:
206    case ParmVar:
207    case OriginalParmVar:
208    case EnumConstant:
209    case NonTypeTemplateParm:
210    case ObjCInterface:
211    case ObjCCompatibleAlias:
212    case OverloadedFunction:
213    case CXXMethod:
214    case CXXConversion:
215    case CXXClassVar:
216      return IDNS_Ordinary;
217
218    case Field:
219    case ObjCAtDefsField:
220    case ObjCIvar:
221      return IDNS_Member;
222
223    case Record:
224    case CXXRecord:
225    case TemplateTypeParm:
226    case Enum:
227      return IDNS_Tag;
228    case Namespace:
229      return IdentifierNamespace(IDNS_Tag | IDNS_Ordinary);
230    }
231  }
232
233  bool isInIdentifierNamespace(unsigned NS) const {
234    return getIdentifierNamespace() & NS;
235  }
236
237  // getBody - If this Decl represents a declaration for a body of code,
238  //  such as a function or method definition, this method returns the top-level
239  //  Stmt* of that body.  Otherwise this method returns null.
240  virtual Stmt* getBody() const { return 0; }
241
242  // global temp stats (until we have a per-module visitor)
243  static void addDeclKind(Kind k);
244  static bool CollectingStats(bool Enable = false);
245  static void PrintStats();
246
247  /// isTemplateParameter - Determines whether this declartion is a
248  /// template parameter.
249  bool isTemplateParameter() const;
250
251  // Implement isa/cast/dyncast/etc.
252  static bool classof(const Decl *) { return true; }
253  static DeclContext *castToDeclContext(const Decl *);
254  static Decl *castFromDeclContext(const DeclContext *);
255
256  /// Emit - Serialize this Decl to Bitcode.
257  void Emit(llvm::Serializer& S) const;
258
259  /// Create - Deserialize a Decl from Bitcode.
260  static Decl* Create(llvm::Deserializer& D, ASTContext& C);
261
262  /// Destroy - Call destructors and release memory.
263  virtual void Destroy(ASTContext& C);
264
265protected:
266  /// EmitImpl - Provides the subclass-specific serialization logic for
267  ///   serializing out a decl.
268  virtual void EmitImpl(llvm::Serializer& S) const {
269    // FIXME: This will eventually be a pure virtual function.
270    assert (false && "Not implemented.");
271  }
272
273  void EmitInRec(llvm::Serializer& S) const;
274  void ReadInRec(llvm::Deserializer& D, ASTContext& C);
275};
276
277/// DeclContext - This is used only as base class of specific decl types that
278/// can act as declaration contexts. These decls are:
279///
280///   TranslationUnitDecl
281///   NamespaceDecl
282///   FunctionDecl
283///   RecordDecl/CXXRecordDecl
284///   EnumDecl
285///   ObjCMethodDecl
286///   ObjCInterfaceDecl
287///   LinkageSpecDecl
288///   BlockDecl
289class DeclContext {
290  /// DeclKind - This indicates which class this is.
291  Decl::Kind DeclKind   :  8;
292
293  /// LookupPtrKind - Describes what kind of pointer LookupPtr
294  /// actually is.
295  enum LookupPtrKind {
296    /// LookupIsMap - Indicates that LookupPtr is actually a map.
297    LookupIsMap = 7
298  };
299
300  /// LookupPtr - Pointer to a data structure used to lookup
301  /// declarations within this context. If the context contains fewer
302  /// than seven declarations, the number of declarations is provided
303  /// in the 3 lowest-order bits and the upper bits are treated as a
304  /// pointer to an array of ScopedDecl pointers. If the context
305  /// contains seven or more declarations, the upper bits are treated
306  /// as a pointer to a DenseMap<DeclarationName, std::vector<ScopedDecl>>.
307  /// FIXME: We need a better data structure for this.
308  llvm::PointerIntPair<void*, 3> LookupPtr;
309
310  /// Decls - Contains all of the declarations that are defined inside
311  /// this declaration context.
312  std::vector<ScopedDecl*> Decls;
313
314  // Used in the CastTo template to get the DeclKind
315  // from a Decl or a DeclContext. DeclContext doesn't have a getKind() method
316  // to avoid 'ambiguous access' compiler errors.
317  template<typename T> struct KindTrait {
318    static Decl::Kind getKind(const T *D) { return D->getKind(); }
319  };
320
321  // Used only by the ToDecl and FromDecl methods
322  template<typename To, typename From>
323  static To *CastTo(const From *D) {
324    Decl::Kind DK = KindTrait<From>::getKind(D);
325    switch(DK) {
326      case Decl::TranslationUnit:
327        return static_cast<TranslationUnitDecl*>(const_cast<From*>(D));
328      case Decl::Namespace:
329        return static_cast<NamespaceDecl*>(const_cast<From*>(D));
330      case Decl::Enum:
331        return static_cast<EnumDecl*>(const_cast<From*>(D));
332      case Decl::Record:
333        return static_cast<RecordDecl*>(const_cast<From*>(D));
334      case Decl::CXXRecord:
335        return static_cast<CXXRecordDecl*>(const_cast<From*>(D));
336      case Decl::ObjCMethod:
337        return static_cast<ObjCMethodDecl*>(const_cast<From*>(D));
338      case Decl::ObjCInterface:
339        return static_cast<ObjCInterfaceDecl*>(const_cast<From*>(D));
340      case Decl::ObjCCategory:
341        return static_cast<ObjCCategoryDecl*>(const_cast<From*>(D));
342      case Decl::ObjCProtocol:
343        return static_cast<ObjCProtocolDecl*>(const_cast<From*>(D));
344      case Decl::ObjCImplementation:
345        return static_cast<ObjCImplementationDecl*>(const_cast<From*>(D));
346      case Decl::ObjCCategoryImpl:
347        return static_cast<ObjCCategoryImplDecl*>(const_cast<From*>(D));
348      case Decl::LinkageSpec:
349        return static_cast<LinkageSpecDecl*>(const_cast<From*>(D));
350      case Decl::Block:
351        return static_cast<BlockDecl*>(const_cast<From*>(D));
352      default:
353        if (DK >= Decl::FunctionFirst && DK <= Decl::FunctionLast)
354          return static_cast<FunctionDecl*>(const_cast<From*>(D));
355
356        assert(false && "a decl that inherits DeclContext isn't handled");
357        return 0;
358    }
359  }
360
361  /// isLookupMap - Determine if the lookup structure is a
362  /// DenseMap. Othewise, it is an array.
363  bool isLookupMap() const { return LookupPtr.getInt() == LookupIsMap; }
364
365protected:
366  DeclContext(Decl::Kind K) : DeclKind(K), LookupPtr() {
367  }
368
369  void DestroyDecls(ASTContext &C);
370
371public:
372  ~DeclContext();
373
374  /// getParent - Returns the containing DeclContext if this is a ScopedDecl,
375  /// else returns NULL.
376  const DeclContext *getParent() const;
377  DeclContext *getParent() {
378    return const_cast<DeclContext*>(
379                             const_cast<const DeclContext*>(this)->getParent());
380  }
381
382  /// getLexicalParent - Returns the containing lexical DeclContext. May be
383  /// different from getParent, e.g.:
384  ///
385  ///   namespace A {
386  ///      struct S;
387  ///   }
388  ///   struct A::S {}; // getParent() == namespace 'A'
389  ///                   // getLexicalParent() == translation unit
390  ///
391  const DeclContext *getLexicalParent() const;
392  DeclContext *getLexicalParent() {
393    return const_cast<DeclContext*>(
394                      const_cast<const DeclContext*>(this)->getLexicalParent());
395  }
396
397  bool isFunctionOrMethod() const {
398    switch (DeclKind) {
399      case Decl::Block:
400      case Decl::ObjCMethod:
401        return true;
402
403      default:
404       if (DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast)
405         return true;
406        return false;
407    }
408  }
409
410  bool isFileContext() const {
411    return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace;
412  }
413
414  bool isRecord() const {
415    return DeclKind == Decl::Record || DeclKind == Decl::CXXRecord;
416  }
417
418  bool isNamespace() const {
419    return DeclKind == Decl::Namespace;
420  }
421
422  /// isTransparentContext - Determines whether this context is a
423  /// "transparent" context, meaning that the members declared in this
424  /// context are semantically declared in the nearest enclosing
425  /// non-transparent (opaque) context but are lexically declared in
426  /// this context. For example, consider the enumerators of an
427  /// enumeration type:
428  /// @code
429  /// enum E {
430  ///   Val1
431  /// };
432  /// @endcode
433  /// Here, E is a transparent context, so its enumerator (Val1) will
434  /// appear (semantically) that it is in the same context of E.
435  /// Examples of transparent contexts include: enumerations (except for
436  /// C++0x scoped enums), C++ linkage specifications, and C++0x
437  /// inline namespaces.
438  bool isTransparentContext() const;
439
440  bool Encloses(DeclContext *DC) const {
441    for (; DC; DC = DC->getParent())
442      if (DC == this)
443        return true;
444    return false;
445  }
446
447  /// getPrimaryContext - There may be many different
448  /// declarations of the same entity (including forward declarations
449  /// of classes, multiple definitions of namespaces, etc.), each with
450  /// a different set of declarations. This routine returns the
451  /// "primary" DeclContext structure, which will contain the
452  /// information needed to perform name lookup into this context.
453  DeclContext *getPrimaryContext();
454
455  /// getLookupContext - Retrieve the innermost non-transparent
456  /// context of this context, which corresponds to the innermost
457  /// location from which name lookup can find the entities in this
458  /// context.
459  DeclContext *getLookupContext() {
460    return const_cast<DeclContext *>(
461             const_cast<const DeclContext *>(this)->getLookupContext());
462  }
463  const DeclContext *getLookupContext() const;
464
465  /// getNextContext - If this is a DeclContext that may have other
466  /// DeclContexts that are semantically connected but syntactically
467  /// different, such as C++ namespaces, this routine retrieves the
468  /// next DeclContext in the link. Iteration through the chain of
469  /// DeclContexts should begin at the primary DeclContext and
470  /// continue until this function returns NULL. For example, given:
471  /// @code
472  /// namespace N {
473  ///   int x;
474  /// }
475  /// namespace N {
476  ///   int y;
477  /// }
478  /// @endcode
479  /// The first occurrence of namespace N will be the primary
480  /// DeclContext. Its getNextContext will return the second
481  /// occurrence of namespace N.
482  DeclContext *getNextContext();
483
484  /// decl_iterator - Iterates through the declarations stored
485  /// within this context.
486  typedef std::vector<ScopedDecl*>::const_iterator decl_iterator;
487
488  /// decls_begin/decls_end - Iterate over the declarations stored in
489  /// this context.
490  decl_iterator decls_begin() const { return Decls.begin(); }
491  decl_iterator decls_end()   const { return Decls.end(); }
492
493  /// specific_decl_iterator - Iterates over a subrange of
494  /// declarations stored in a DeclContext, providing only those that
495  /// are of type SpecificDecl (or a class derived from it) and,
496  /// optionally, that meet some additional run-time criteria. This
497  /// iterator is used, for example, to provide iteration over just
498  /// the fields within a RecordDecl (with SpecificDecl = FieldDecl)
499  /// or the instance methods within an Objective-C interface (with
500  /// SpecificDecl = ObjCMethodDecl and using
501  /// ObjCMethodDecl::isInstanceMethod as the run-time criteria).
502  template<typename SpecificDecl>
503  class specific_decl_iterator {
504    /// Current - The current, underlying declaration iterator, which
505    /// will either be the same as End or will point to a declaration of
506    /// type SpecificDecl.
507    DeclContext::decl_iterator Current;
508
509    /// End - One past the last declaration within the DeclContext.
510    DeclContext::decl_iterator End;
511
512    /// Acceptable - If non-NULL, points to a member function that
513    /// will determine if a particular declaration of type
514    /// SpecificDecl should be visited by the iteration.
515    bool (SpecificDecl::*Acceptable)() const;
516
517    /// SkipToNextDecl - Advances the current position up to the next
518    /// declaration of type SpecificDecl that also meets the criteria
519    /// required by Acceptable.
520    void SkipToNextDecl() {
521      while (Current != End &&
522             (!isa<SpecificDecl>(*Current) ||
523              (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)())))
524        ++Current;
525    }
526
527  public:
528    typedef SpecificDecl* value_type;
529    typedef SpecificDecl* reference;
530    typedef SpecificDecl* pointer;
531    typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
532      difference_type;
533    typedef std::forward_iterator_tag iterator_category;
534
535    specific_decl_iterator() : Current(), End(), Acceptable(0) { }
536
537    /// specific_decl_iterator - Construct a new iterator over a
538    /// subset of the declarations in [C, E). If A is non-NULL, it is
539    /// a pointer to a member function of SpecificDecl that should
540    /// return true for all of the SpecificDecl instances that will be
541    /// in the subset of iterators. For example, if you want
542    /// Objective-C instance methods, SpecificDecl will be
543    /// ObjCMethodDecl and A will be &ObjCMethodDecl::isInstanceMethod.
544    specific_decl_iterator(DeclContext::decl_iterator C,
545                           DeclContext::decl_iterator E,
546                           bool (SpecificDecl::*A)() const = 0)
547      : Current(C), End(E), Acceptable(A) {
548      SkipToNextDecl();
549    }
550
551    reference operator*() { return cast<SpecificDecl>(*Current); }
552    pointer operator->() { return cast<SpecificDecl>(*Current); }
553
554    specific_decl_iterator& operator++() {
555      ++Current;
556      SkipToNextDecl();
557      return *this;
558    }
559
560    specific_decl_iterator operator++(int) {
561      specific_decl_iterator tmp(*this);
562      ++(*this);
563      return tmp;
564    }
565
566    friend bool
567    operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) {
568      return x.Current == y.Current;
569    }
570
571    friend bool
572    operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) {
573      return x.Current != y.Current;
574    }
575  };
576
577  /// addDecl - Add the declaration D to this scope. Note that
578  /// declarations are added at the beginning of the declaration
579  /// chain, so reverseDeclChain() should be called after all
580  /// declarations have been added. If AllowLookup, also adds this
581  /// declaration into data structure for name lookup.
582  void addDecl(ASTContext &Context, ScopedDecl *D, bool AllowLookup = true);
583
584  void buildLookup(DeclContext *DCtx);
585
586  /// lookup_iterator - An iterator that provides access to the results
587  /// of looking up a name within this context.
588  typedef ScopedDecl **lookup_iterator;
589
590  /// lookup_const_iterator - An iterator that provides non-mutable
591  /// access to the results of lookup up a name within this context.
592  typedef ScopedDecl * const * lookup_const_iterator;
593
594  typedef std::pair<lookup_iterator, lookup_iterator> lookup_result;
595  typedef std::pair<lookup_const_iterator, lookup_const_iterator>
596    lookup_const_result;
597
598  /// lookup - Find the declarations (if any) with the given Name in
599  /// this context. Returns a range of iterators that contains all of
600  /// the declarations with this name (which may be 0, 1, or more
601  /// declarations). If two declarations are returned, the declaration
602  /// in the "ordinary" identifier namespace will precede the
603  /// declaration in the "tag" identifier namespace (e.g., values
604  /// before types). Note that this routine will not look into parent
605  /// contexts.
606  lookup_result lookup(DeclarationName Name);
607  lookup_const_result lookup(DeclarationName Name) const;
608
609  /// insert - Insert the declaration D into this context. Up to two
610  /// declarations with the same name can be inserted into a single
611  /// declaration context, one in the "tag" namespace (e.g., for
612  /// classes and enums) and one in the "ordinary" namespaces (e.g.,
613  /// for variables, functions, and other values). Note that, if there
614  /// is already a declaration with the same name and identifier
615  /// namespace, D will replace it. It is up to the caller to ensure
616  /// that this replacement is semantically correct, e.g., that
617  /// declarations are only replaced by later declarations of the same
618  /// entity and not a declaration of some other kind of entity.
619  void insert(ASTContext &Context, ScopedDecl *D);
620
621  static bool classof(const Decl *D) {
622    switch (D->getKind()) {
623      case Decl::TranslationUnit:
624      case Decl::Namespace:
625      case Decl::Enum:
626      case Decl::Record:
627      case Decl::CXXRecord:
628      case Decl::ObjCMethod:
629      case Decl::ObjCInterface:
630      case Decl::ObjCCategory:
631      case Decl::ObjCProtocol:
632      case Decl::ObjCImplementation:
633      case Decl::ObjCCategoryImpl:
634      case Decl::LinkageSpec:
635      case Decl::Block:
636        return true;
637      default:
638        if (D->getKind() >= Decl::FunctionFirst &&
639            D->getKind() <= Decl::FunctionLast)
640          return true;
641        return false;
642    }
643  }
644  static bool classof(const DeclContext *D) { return true; }
645  static bool classof(const TranslationUnitDecl *D) { return true; }
646  static bool classof(const NamespaceDecl *D) { return true; }
647  static bool classof(const FunctionDecl *D) { return true; }
648  static bool classof(const RecordDecl *D) { return true; }
649  static bool classof(const CXXRecordDecl *D) { return true; }
650  static bool classof(const EnumDecl *D) { return true; }
651  static bool classof(const ObjCMethodDecl *D) { return true; }
652  static bool classof(const ObjCInterfaceDecl *D) { return true; }
653  static bool classof(const ObjCCategoryDecl *D) { return true; }
654  static bool classof(const ObjCProtocolDecl *D) { return true; }
655  static bool classof(const ObjCImplementationDecl *D) { return true; }
656  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
657  static bool classof(const LinkageSpecDecl *D) { return true; }
658  static bool classof(const BlockDecl *D) { return true; }
659
660private:
661  void insertImpl(ScopedDecl *D);
662
663  void EmitOutRec(llvm::Serializer& S) const;
664  void ReadOutRec(llvm::Deserializer& D, ASTContext& C);
665
666  friend class Decl;
667};
668
669template<> struct DeclContext::KindTrait<DeclContext> {
670  static Decl::Kind getKind(const DeclContext *D) { return D->DeclKind; }
671};
672
673inline bool Decl::isTemplateParameter() const {
674  return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm;
675}
676
677} // end clang.
678
679namespace llvm {
680
681/// Implement a isa_impl_wrap specialization to check whether a DeclContext is
682/// a specific Decl.
683template<class ToTy>
684struct isa_impl_wrap<ToTy,
685                     const ::clang::DeclContext,const ::clang::DeclContext> {
686  static bool doit(const ::clang::DeclContext &Val) {
687    return ToTy::classof(::clang::Decl::castFromDeclContext(&Val));
688  }
689};
690template<class ToTy>
691struct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext>
692  : public isa_impl_wrap<ToTy,
693                      const ::clang::DeclContext,const ::clang::DeclContext> {};
694
695/// Implement cast_convert_val for Decl -> DeclContext conversions.
696template<class FromTy>
697struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> {
698  static ::clang::DeclContext &doit(const FromTy &Val) {
699    return *FromTy::castToDeclContext(&Val);
700  }
701};
702
703template<class FromTy>
704struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> {
705  static ::clang::DeclContext *doit(const FromTy *Val) {
706    return FromTy::castToDeclContext(Val);
707  }
708};
709
710template<class FromTy>
711struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> {
712  static const ::clang::DeclContext &doit(const FromTy &Val) {
713    return *FromTy::castToDeclContext(&Val);
714  }
715};
716
717template<class FromTy>
718struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> {
719  static const ::clang::DeclContext *doit(const FromTy *Val) {
720    return FromTy::castToDeclContext(Val);
721  }
722};
723
724/// Implement cast_convert_val for DeclContext -> Decl conversions.
725template<class ToTy>
726struct cast_convert_val<ToTy,
727                        const ::clang::DeclContext,const ::clang::DeclContext> {
728  static ToTy &doit(const ::clang::DeclContext &Val) {
729    return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val));
730  }
731};
732template<class ToTy>
733struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext>
734  : public cast_convert_val<ToTy,
735                      const ::clang::DeclContext,const ::clang::DeclContext> {};
736
737template<class ToTy>
738struct cast_convert_val<ToTy,
739                     const ::clang::DeclContext*, const ::clang::DeclContext*> {
740  static ToTy *doit(const ::clang::DeclContext *Val) {
741    return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val));
742  }
743};
744template<class ToTy>
745struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*>
746  : public cast_convert_val<ToTy,
747                    const ::clang::DeclContext*,const ::clang::DeclContext*> {};
748
749} // end namespace llvm
750
751#endif
752