Decl.h revision 777f07b6cd595bb0922e05768e5703fbc92b5695
1//===--- Decl.h - 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 subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECL_H
15#define LLVM_CLANG_AST_DECL_H
16
17#include "clang/Basic/IdentifierTable.h"
18#include "clang/Basic/OperatorKinds.h"
19#include "clang/AST/DeclarationName.h"
20#include "clang/AST/DeclBase.h"
21#include "clang/Parse/AccessSpecifier.h"
22#include "llvm/ADT/SmallVector.h"
23
24namespace clang {
25class Expr;
26class Stmt;
27class CompoundStmt;
28class StringLiteral;
29
30/// TranslationUnitDecl - The top declaration context.
31/// FIXME: The TranslationUnit class should probably be modified to serve as
32/// the top decl context. It would have ownership of the top decls so that the
33/// AST is self-contained and easily de/serializable.
34class TranslationUnitDecl : public Decl, public DeclContext {
35  TranslationUnitDecl()
36    : Decl(TranslationUnit, SourceLocation()),
37      DeclContext(TranslationUnit) {}
38public:
39  static TranslationUnitDecl *Create(ASTContext &C);
40  // Implement isa/cast/dyncast/etc.
41  static bool classof(const Decl *D) { return D->getKind() == TranslationUnit; }
42  static bool classof(const TranslationUnitDecl *D) { return true; }
43  static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
44    return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
45  }
46  static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
47    return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
48  }
49
50protected:
51  /// EmitImpl - Serialize this TranslationUnitDecl. Called by Decl::Emit.
52  virtual void EmitImpl(llvm::Serializer& S) const;
53
54  /// CreateImpl - Deserialize a TranslationUnitDecl.  Called by Decl::Create.
55  static TranslationUnitDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
56
57  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
58};
59
60/// NamedDecl - This represents a decl with a name.  Many decls have names such
61/// as ObjCMethodDecl, but not @class, etc.
62class NamedDecl : public Decl {
63  /// Name - The name of this declaration, which is typically a normal
64  /// identifier but may also be a special kind of name (C++
65  /// constructor, Objective-C selector, etc.)
66  DeclarationName Name;
67
68protected:
69  NamedDecl(Kind DK, SourceLocation L, DeclarationName N)
70    : Decl(DK, L), Name(N) {}
71
72public:
73  NamedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id)
74    : Decl(DK, L), Name(Id) {}
75
76  /// getIdentifier - Get the identifier that names this declaration,
77  /// if there is one. This will return NULL if this declaration has
78  /// no name (e.g., for an unnamed class) or if the name is a special
79  /// name (C++ constructor, Objective-C selector, etc.).
80  IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
81
82  /// getNameAsCString - Get the name of identifier for this declaration as a
83  /// C string (const char*).  This requires that the declaration have a name
84  /// and that it be a simple identifier.
85  const char *getNameAsCString() const {
86    assert(getIdentifier() && "Name is not a simple identifier");
87    return getIdentifier()->getName();
88  }
89
90  /// getDeclName - Get the actual, stored name of the declaration,
91  /// which may be a special name.
92  DeclarationName getDeclName() const { return Name; }
93
94  /// getNameAsString - Get a human-readable name for the declaration, even if
95  /// it is one of the special kinds of names (C++ constructor, Objective-C
96  /// selector, etc).  Creating this name requires expensive string
97  /// manipulation, so it should be called only when performance doesn't matter.
98  /// For simple declarations, getNameAsCString() should suffice.
99  std::string getNameAsString() const { return Name.getAsString(); }
100
101  static bool classof(const Decl *D) {
102    return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
103  }
104  static bool classof(const NamedDecl *D) { return true; }
105
106protected:
107  void EmitInRec(llvm::Serializer& S) const;
108  void ReadInRec(llvm::Deserializer& D, ASTContext& C);
109};
110
111/// ScopedDecl - Represent lexically scoped names, used for all ValueDecl's
112/// and TypeDecl's.
113class ScopedDecl : public NamedDecl {
114  /// NextDeclarator - If this decl was part of a multi-declarator declaration,
115  /// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
116  ScopedDecl *NextDeclarator;
117
118  /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
119  /// For declarations that don't contain C++ scope specifiers, it contains
120  /// the DeclContext where the ScopedDecl was declared.
121  /// For declarations with C++ scope specifiers, it contains a MultipleDC*
122  /// with the context where it semantically belongs (SemanticDC) and the
123  /// context where it was lexically declared (LexicalDC).
124  /// e.g.:
125  ///
126  ///   namespace A {
127  ///      void f(); // SemanticDC == LexicalDC == 'namespace A'
128  ///   }
129  ///   void A::f(); // SemanticDC == namespace 'A'
130  ///                // LexicalDC == global namespace
131  uintptr_t DeclCtx;
132
133  struct MultipleDC {
134    DeclContext *SemanticDC;
135    DeclContext *LexicalDC;
136  };
137
138  inline bool isInSemaDC() const { return (DeclCtx & 0x1) == 0; }
139  inline bool isOutOfSemaDC() const { return (DeclCtx & 0x1) != 0; }
140  inline MultipleDC *getMultipleDC() const {
141    return reinterpret_cast<MultipleDC*>(DeclCtx & ~0x1);
142  }
143
144protected:
145  ScopedDecl(Kind DK, DeclContext *DC, SourceLocation L,
146             DeclarationName N, ScopedDecl *PrevDecl)
147    : NamedDecl(DK, L, N), NextDeclarator(PrevDecl),
148      DeclCtx(reinterpret_cast<uintptr_t>(DC)) {}
149
150  virtual ~ScopedDecl();
151
152public:
153  const DeclContext *getDeclContext() const {
154    if (isInSemaDC())
155      return reinterpret_cast<DeclContext*>(DeclCtx);
156    return getMultipleDC()->SemanticDC;
157  }
158  DeclContext *getDeclContext() {
159    return const_cast<DeclContext*>(
160                         const_cast<const ScopedDecl*>(this)->getDeclContext());
161  }
162
163  /// getLexicalDeclContext - The declaration context where this ScopedDecl was
164  /// lexically declared (LexicalDC). May be different from
165  /// getDeclContext() (SemanticDC).
166  /// e.g.:
167  ///
168  ///   namespace A {
169  ///      void f(); // SemanticDC == LexicalDC == 'namespace A'
170  ///   }
171  ///   void A::f(); // SemanticDC == namespace 'A'
172  ///                // LexicalDC == global namespace
173  const DeclContext *getLexicalDeclContext() const {
174    if (isInSemaDC())
175      return reinterpret_cast<DeclContext*>(DeclCtx);
176    return getMultipleDC()->LexicalDC;
177  }
178  DeclContext *getLexicalDeclContext() {
179    return const_cast<DeclContext*>(
180                  const_cast<const ScopedDecl*>(this)->getLexicalDeclContext());
181  }
182
183  void setLexicalDeclContext(DeclContext *DC);
184
185  /// getNextDeclarator - If this decl was part of a multi-declarator
186  /// declaration, such as "int X, Y, *Z;" this returns the decl for the next
187  /// declarator.  Otherwise it returns null.
188  ScopedDecl *getNextDeclarator() { return NextDeclarator; }
189  const ScopedDecl *getNextDeclarator() const { return NextDeclarator; }
190  void setNextDeclarator(ScopedDecl *N) { NextDeclarator = N; }
191
192  // isDefinedOutsideFunctionOrMethod - This predicate returns true if this
193  // scoped decl is defined outside the current function or method.  This is
194  // roughly global variables and functions, but also handles enums (which could
195  // be defined inside or outside a function etc).
196  bool isDefinedOutsideFunctionOrMethod() const {
197    if (getDeclContext())
198      return !getDeclContext()->isFunctionOrMethod();
199    else
200      return true;
201  }
202
203  // Implement isa/cast/dyncast/etc.
204  static bool classof(const Decl *D) {
205    return D->getKind() >= ScopedFirst && D->getKind() <= ScopedLast;
206  }
207  static bool classof(const ScopedDecl *D) { return true; }
208
209protected:
210  void EmitInRec(llvm::Serializer& S) const;
211  void ReadInRec(llvm::Deserializer& D, ASTContext& C);
212
213  void EmitOutRec(llvm::Serializer& S) const;
214  void ReadOutRec(llvm::Deserializer& D, ASTContext& C);
215
216  friend void Decl::Destroy(ASTContext& C);
217};
218
219/// NamespaceDecl - Represent a C++ namespace.
220class NamespaceDecl : public ScopedDecl, public DeclContext {
221  SourceLocation LBracLoc, RBracLoc;
222
223  // For extended namespace definitions:
224  //
225  // namespace A { int x; }
226  // namespace A { int y; }
227  //
228  // there will be one NamespaceDecl for each declaration.
229  // NextDeclarator points to the next extended declaration.
230  // OrigNamespace points to the original namespace declaration.
231  // OrigNamespace of the first namespace decl points to itself.
232
233  NamespaceDecl *OrigNamespace;
234
235  NamespaceDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
236    : ScopedDecl(Namespace, DC, L, Id, 0), DeclContext(Namespace) {
237      OrigNamespace = this;
238  }
239public:
240  static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
241                               SourceLocation L, IdentifierInfo *Id);
242
243  virtual void Destroy(ASTContext& C);
244
245  NamespaceDecl *getNextNamespace() {
246    return cast_or_null<NamespaceDecl>(getNextDeclarator());
247  }
248  const NamespaceDecl *getNextNamespace() const {
249    return cast_or_null<NamespaceDecl>(getNextDeclarator());
250  }
251  void setNextNamespace(NamespaceDecl *ND) { setNextDeclarator(ND); }
252
253  NamespaceDecl *getOriginalNamespace() const {
254    return OrigNamespace;
255  }
256  void setOriginalNamespace(NamespaceDecl *ND) { OrigNamespace = ND; }
257
258  SourceRange getSourceRange() const {
259    return SourceRange(LBracLoc, RBracLoc);
260  }
261
262  SourceLocation getLBracLoc() const { return LBracLoc; }
263  SourceLocation getRBracLoc() const { return RBracLoc; }
264  void setLBracLoc(SourceLocation LBrace) { LBracLoc = LBrace; }
265  void setRBracLoc(SourceLocation RBrace) { RBracLoc = RBrace; }
266
267  // Implement isa/cast/dyncast/etc.
268  static bool classof(const Decl *D) { return D->getKind() == Namespace; }
269  static bool classof(const NamespaceDecl *D) { return true; }
270  static DeclContext *castToDeclContext(const NamespaceDecl *D) {
271    return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
272  }
273  static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
274    return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
275  }
276
277protected:
278  /// EmitImpl - Serialize this NamespaceDecl. Called by Decl::Emit.
279  virtual void EmitImpl(llvm::Serializer& S) const;
280
281  /// CreateImpl - Deserialize a NamespaceDecl.  Called by Decl::Create.
282  static NamespaceDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
283
284  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
285};
286
287/// ValueDecl - Represent the declaration of a variable (in which case it is
288/// an lvalue) a function (in which case it is a function designator) or
289/// an enum constant.
290class ValueDecl : public ScopedDecl {
291  QualType DeclType;
292
293protected:
294  ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
295            DeclarationName N, QualType T, ScopedDecl *PrevDecl)
296    : ScopedDecl(DK, DC, L, N, PrevDecl), DeclType(T) {}
297public:
298  QualType getType() const { return DeclType; }
299  void setType(QualType newType) { DeclType = newType; }
300
301  // Implement isa/cast/dyncast/etc.
302  static bool classof(const Decl *D) {
303    return D->getKind() >= ValueFirst && D->getKind() <= ValueLast;
304  }
305  static bool classof(const ValueDecl *D) { return true; }
306
307protected:
308  void EmitInRec(llvm::Serializer& S) const;
309  void ReadInRec(llvm::Deserializer& D, ASTContext& C);
310};
311
312/// VarDecl - An instance of this class is created to represent a variable
313/// declaration or definition.
314class VarDecl : public ValueDecl {
315public:
316  enum StorageClass {
317    None, Auto, Register, Extern, Static, PrivateExtern
318  };
319private:
320  Stmt *Init;
321  // FIXME: This can be packed into the bitfields in Decl.
322  unsigned SClass : 3;
323  bool ThreadSpecified : 1;
324  bool HasCXXDirectInit : 1;
325
326  /// DeclaredInCondition - Whether this variable was declared in a
327  /// condition, e.g., if (int x = foo()) { ... }.
328  bool DeclaredInCondition : 1;
329
330  // Move to DeclGroup when it is implemented.
331  SourceLocation TypeSpecStartLoc;
332  friend class StmtIteratorBase;
333protected:
334  VarDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
335          QualType T, StorageClass SC, ScopedDecl *PrevDecl,
336          SourceLocation TSSL = SourceLocation())
337    : ValueDecl(DK, DC, L, Id, T, PrevDecl), Init(0),
338          ThreadSpecified(false), HasCXXDirectInit(false),
339          DeclaredInCondition(false), TypeSpecStartLoc(TSSL) {
340    SClass = SC;
341  }
342public:
343  static VarDecl *Create(ASTContext &C, DeclContext *DC,
344                         SourceLocation L, IdentifierInfo *Id,
345                         QualType T, StorageClass S, ScopedDecl *PrevDecl,
346                         SourceLocation TypeSpecStartLoc = SourceLocation());
347
348  StorageClass getStorageClass() const { return (StorageClass)SClass; }
349
350  SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
351
352  const Expr *getInit() const { return (const Expr*) Init; }
353  Expr *getInit() { return (Expr*) Init; }
354  void setInit(Expr *I) { Init = (Stmt*) I; }
355
356  void setThreadSpecified(bool T) { ThreadSpecified = T; }
357  bool isThreadSpecified() const {
358    return ThreadSpecified;
359  }
360
361  void setCXXDirectInitializer(bool T) { HasCXXDirectInit = T; }
362
363  /// hasCXXDirectInitializer - If true, the initializer was a direct
364  /// initializer, e.g: "int x(1);". The Init expression will be the expression
365  /// inside the parens or a "ClassType(a,b,c)" class constructor expression for
366  /// class types. Clients can distinguish between "int x(1);" and "int x=1;"
367  /// by checking hasCXXDirectInitializer.
368  ///
369  bool hasCXXDirectInitializer() const {
370    return HasCXXDirectInit;
371  }
372
373  /// isDeclaredInCondition - Whether this variable was declared as
374  /// part of a condition in an if/switch/while statement, e.g.,
375  /// @code
376  /// if (int x = foo()) { ... }
377  /// @endcode
378  bool isDeclaredInCondition() const {
379    return DeclaredInCondition;
380  }
381  void setDeclaredInCondition(bool InCondition) {
382    DeclaredInCondition = InCondition;
383  }
384
385  /// hasLocalStorage - Returns true if a variable with function scope
386  ///  is a non-static local variable.
387  bool hasLocalStorage() const {
388    if (getStorageClass() == None)
389      return !isFileVarDecl();
390
391    // Return true for:  Auto, Register.
392    // Return false for: Extern, Static, PrivateExtern.
393
394    return getStorageClass() <= Register;
395  }
396
397  /// hasGlobalStorage - Returns true for all variables that do not
398  ///  have local storage.  This includs all global variables as well
399  ///  as static variables declared within a function.
400  bool hasGlobalStorage() const { return !hasLocalStorage(); }
401
402  /// isBlockVarDecl - Returns true for local variable declarations.  Note that
403  /// this includes static variables inside of functions.
404  ///
405  ///   void foo() { int x; static int y; extern int z; }
406  ///
407  bool isBlockVarDecl() const {
408    if (getKind() != Decl::Var)
409      return false;
410    if (const DeclContext *DC = getDeclContext())
411      return DC->isFunctionOrMethod();
412    return false;
413  }
414
415  /// isFileVarDecl - Returns true for file scoped variable declaration.
416  bool isFileVarDecl() const {
417    if (getKind() != Decl::Var)
418      return false;
419    if (isa<TranslationUnitDecl>(getDeclContext()) ||
420        isa<NamespaceDecl>(getDeclContext()) )
421      return true;
422    return false;
423  }
424
425  // Implement isa/cast/dyncast/etc.
426  static bool classof(const Decl *D) {
427    return D->getKind() >= VarFirst && D->getKind() <= VarLast;
428  }
429  static bool classof(const VarDecl *D) { return true; }
430
431protected:
432  void EmitInRec(llvm::Serializer& S) const;
433  void ReadInRec(llvm::Deserializer& D, ASTContext& C);
434
435  void EmitOutRec(llvm::Serializer& S) const;
436  void ReadOutRec(llvm::Deserializer& D, ASTContext& C);
437
438  /// EmitImpl - Serialize this VarDecl. Called by Decl::Emit.
439  virtual void EmitImpl(llvm::Serializer& S) const;
440
441  /// ReadImpl - Deserialize this VarDecl. Called by subclasses.
442  virtual void ReadImpl(llvm::Deserializer& D, ASTContext& C);
443
444  /// CreateImpl - Deserialize a VarDecl.  Called by Decl::Create.
445  static VarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
446};
447
448class ImplicitParamDecl : public VarDecl {
449protected:
450  ImplicitParamDecl(Kind DK, DeclContext *DC, SourceLocation L,
451            IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl)
452    : VarDecl(DK, DC, L, Id, T, VarDecl::None, PrevDecl) {}
453public:
454  static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
455                         SourceLocation L, IdentifierInfo *Id,
456                         QualType T, ScopedDecl *PrevDecl);
457  // Implement isa/cast/dyncast/etc.
458  static bool classof(const ImplicitParamDecl *D) { return true; }
459  static bool classof(const Decl *D) { return D->getKind() == ImplicitParam; }
460};
461
462/// ParmVarDecl - Represent a parameter to a function.
463class ParmVarDecl : public VarDecl {
464  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
465  /// FIXME: Also can be paced into the bitfields in Decl.
466  /// in, inout, etc.
467  unsigned objcDeclQualifier : 6;
468
469  /// Default argument, if any.  [C++ Only]
470  Expr *DefaultArg;
471
472  ParmVarDecl(DeclContext *DC, SourceLocation L,
473              IdentifierInfo *Id, QualType T, StorageClass S,
474              Expr *DefArg, ScopedDecl *PrevDecl)
475    : VarDecl(ParmVar, DC, L, Id, T, S, PrevDecl),
476      objcDeclQualifier(OBJC_TQ_None), DefaultArg(DefArg) {}
477
478public:
479  static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
480                             SourceLocation L,IdentifierInfo *Id,
481                             QualType T, StorageClass S, Expr *DefArg,
482                             ScopedDecl *PrevDecl);
483
484  ObjCDeclQualifier getObjCDeclQualifier() const {
485    return ObjCDeclQualifier(objcDeclQualifier);
486  }
487  void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
488    objcDeclQualifier = QTVal;
489  }
490
491  const Expr *getDefaultArg() const { return DefaultArg; }
492  Expr *getDefaultArg() { return DefaultArg; }
493  void setDefaultArg(Expr *defarg) { DefaultArg = defarg; }
494
495  // Implement isa/cast/dyncast/etc.
496  static bool classof(const Decl *D) { return D->getKind() == ParmVar; }
497  static bool classof(const ParmVarDecl *D) { return true; }
498
499protected:
500  /// EmitImpl - Serialize this ParmVarDecl. Called by Decl::Emit.
501  virtual void EmitImpl(llvm::Serializer& S) const;
502
503  /// CreateImpl - Deserialize a ParmVarDecl.  Called by Decl::Create.
504  static ParmVarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
505
506  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
507};
508
509/// FunctionDecl - An instance of this class is created to represent a
510/// function declaration or definition.
511///
512/// Since a given function can be declared several times in a program,
513/// there may be several FunctionDecls that correspond to that
514/// function. Only one of those FunctionDecls will be found when
515/// traversing the list of declarations in the context of the
516/// FunctionDecl (e.g., the translation unit); this FunctionDecl
517/// contains all of the information known about the function. Other,
518/// previous declarations of the function are available via the
519/// getPreviousDeclaration() chain.
520class FunctionDecl : public ValueDecl, public DeclContext {
521public:
522  enum StorageClass {
523    None, Extern, Static, PrivateExtern
524  };
525private:
526  /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
527  /// parameters of this function.  This is null if a prototype or if there are
528  /// no formals.  TODO: we could allocate this space immediately after the
529  /// FunctionDecl object to save an allocation like FunctionType does.
530  ParmVarDecl **ParamInfo;
531
532  Stmt *Body;  // Null if a prototype.
533
534  /// PreviousDeclaration - A link to the previous declaration of this
535  /// same function, NULL if this is the first declaration. For
536  /// example, in the following code, the PreviousDeclaration can be
537  /// traversed several times to see all three declarations of the
538  /// function "f", the last of which is also a definition.
539  ///
540  ///   int f(int x, int y = 1);
541  ///   int f(int x = 0, int y);
542  ///   int f(int x, int y) { return x + y; }
543  FunctionDecl *PreviousDeclaration;
544
545  // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
546  unsigned SClass : 2;
547  bool IsInline : 1;
548  bool IsImplicit : 1;
549
550  // Move to DeclGroup when it is implemented.
551  SourceLocation TypeSpecStartLoc;
552protected:
553  FunctionDecl(Kind DK, DeclContext *DC, SourceLocation L,
554               DeclarationName N, QualType T,
555               StorageClass S, bool isInline, ScopedDecl *PrevDecl,
556               SourceLocation TSSL = SourceLocation())
557    : ValueDecl(DK, DC, L, N, T, PrevDecl),
558      DeclContext(DK),
559      ParamInfo(0), Body(0), PreviousDeclaration(0),
560      SClass(S), IsInline(isInline), IsImplicit(0), TypeSpecStartLoc(TSSL) {}
561
562  virtual ~FunctionDecl();
563  virtual void Destroy(ASTContext& C);
564
565public:
566  static FunctionDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
567                              DeclarationName N, QualType T,
568                              StorageClass S = None, bool isInline = false,
569                              ScopedDecl *PrevDecl = 0,
570                              SourceLocation TSStartLoc = SourceLocation());
571
572  SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
573
574  /// getBody - Retrieve the body (definition) of the function. The
575  /// function body might be in any of the (re-)declarations of this
576  /// function. The variant that accepts a FunctionDecl pointer will
577  /// set that function declaration to the actual declaration
578  /// containing the body (if there is one).
579  Stmt *getBody(const FunctionDecl *&Definition) const;
580
581  virtual Stmt *getBody() const {
582    const FunctionDecl* Definition;
583    return getBody(Definition);
584  }
585
586  /// isThisDeclarationADefinition - Returns whether this specific
587  /// declaration of the function is also a definition. This does not
588  /// determine whether the function has been defined (e.g., in a
589  /// previous definition); for that information, use getBody.
590  bool isThisDeclarationADefinition() const { return Body != 0; }
591
592  void setBody(Stmt *B) { Body = B; }
593
594  bool isImplicit() { return IsImplicit; }
595  void setImplicit() { IsImplicit = true; }
596
597  /// getPreviousDeclaration - Return the previous declaration of this
598  /// function.
599  const FunctionDecl *getPreviousDeclaration() const {
600    return PreviousDeclaration;
601  }
602
603  void setPreviousDeclaration(FunctionDecl * PrevDecl) {
604    PreviousDeclaration = PrevDecl;
605  }
606
607  // Iterator access to formal parameters.
608  unsigned param_size() const { return getNumParams(); }
609  typedef ParmVarDecl **param_iterator;
610  typedef ParmVarDecl * const *param_const_iterator;
611
612  param_iterator param_begin() { return ParamInfo; }
613  param_iterator param_end()   { return ParamInfo+param_size(); }
614
615  param_const_iterator param_begin() const { return ParamInfo; }
616  param_const_iterator param_end() const   { return ParamInfo+param_size(); }
617
618  unsigned getNumParams() const;
619  const ParmVarDecl *getParamDecl(unsigned i) const {
620    assert(i < getNumParams() && "Illegal param #");
621    return ParamInfo[i];
622  }
623  ParmVarDecl *getParamDecl(unsigned i) {
624    assert(i < getNumParams() && "Illegal param #");
625    return ParamInfo[i];
626  }
627  void setParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
628
629  /// getMinRequiredArguments - Returns the minimum number of arguments
630  /// needed to call this function. This may be fewer than the number of
631  /// function parameters, if some of the parameters have default
632  /// arguments (in C++).
633  unsigned getMinRequiredArguments() const;
634
635  QualType getResultType() const {
636    return getType()->getAsFunctionType()->getResultType();
637  }
638  StorageClass getStorageClass() const { return StorageClass(SClass); }
639  bool isInline() const { return IsInline; }
640
641  /// isOverloadedOperator - Whether this function declaration
642  /// represents an C++ overloaded operator, e.g., "operator+".
643  bool isOverloadedOperator() const {
644    return getOverloadedOperator() != OO_None;
645  };
646
647  OverloadedOperatorKind getOverloadedOperator() const;
648
649  // Implement isa/cast/dyncast/etc.
650  static bool classof(const Decl *D) {
651    return D->getKind() >= FunctionFirst && D->getKind() <= FunctionLast;
652  }
653  static bool classof(const FunctionDecl *D) { return true; }
654  static DeclContext *castToDeclContext(const FunctionDecl *D) {
655    return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
656  }
657  static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
658    return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
659  }
660
661protected:
662  /// EmitImpl - Serialize this FunctionDecl.  Called by Decl::Emit.
663  virtual void EmitImpl(llvm::Serializer& S) const;
664
665  /// CreateImpl - Deserialize a FunctionDecl.  Called by Decl::Create.
666  static FunctionDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
667
668  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
669  friend class CXXRecordDecl;
670};
671
672
673/// FieldDecl - An instance of this class is created by Sema::ActOnField to
674/// represent a member of a struct/union/class.
675class FieldDecl : public ScopedDecl {
676  bool Mutable : 1;
677  QualType DeclType;
678  Expr *BitWidth;
679protected:
680  FieldDecl(Kind DK, DeclContext *DC, SourceLocation L,
681            IdentifierInfo *Id, QualType T, Expr *BW, bool Mutable,
682            ScopedDecl *PrevDecl)
683    : ScopedDecl(DK, DC, L, Id, PrevDecl), Mutable(Mutable), DeclType(T),
684      BitWidth(BW)
685      { }
686
687public:
688  static FieldDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
689                           IdentifierInfo *Id, QualType T, Expr *BW,
690                           bool Mutable, ScopedDecl *PrevDecl);
691
692  QualType getType() const { return DeclType; }
693
694  /// isMutable - Determines whether this field is mutable (C++ only).
695  bool isMutable() const { return Mutable; }
696
697  /// isBitfield - Determines whether this field is a bitfield.
698  bool isBitField() const { return BitWidth != NULL; }
699
700  Expr *getBitWidth() const { return BitWidth; }
701  // Implement isa/cast/dyncast/etc.
702  static bool classof(const Decl *D) {
703    return D->getKind() >= FieldFirst && D->getKind() <= FieldLast;
704  }
705  static bool classof(const FieldDecl *D) { return true; }
706
707protected:
708  /// EmitImpl - Serialize this FieldDecl.  Called by Decl::Emit.
709  virtual void EmitImpl(llvm::Serializer& S) const;
710
711  /// CreateImpl - Deserialize a FieldDecl.  Called by Decl::Create.
712  static FieldDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
713
714  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
715};
716
717/// EnumConstantDecl - An instance of this object exists for each enum constant
718/// that is defined.  For example, in "enum X {a,b}", each of a/b are
719/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
720/// TagType for the X EnumDecl.
721class EnumConstantDecl : public ValueDecl {
722  Stmt *Init; // an integer constant expression
723  llvm::APSInt Val; // The value.
724protected:
725  EnumConstantDecl(DeclContext *DC, SourceLocation L,
726                   IdentifierInfo *Id, QualType T, Expr *E,
727                   const llvm::APSInt &V, ScopedDecl *PrevDecl)
728    : ValueDecl(EnumConstant, DC, L, Id, T, PrevDecl), Init((Stmt*)E), Val(V) {}
729
730  virtual ~EnumConstantDecl() {}
731public:
732
733  static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
734                                  SourceLocation L, IdentifierInfo *Id,
735                                  QualType T, Expr *E,
736                                  const llvm::APSInt &V, ScopedDecl *PrevDecl);
737
738  virtual void Destroy(ASTContext& C);
739
740  const Expr *getInitExpr() const { return (const Expr*) Init; }
741  Expr *getInitExpr() { return (Expr*) Init; }
742  const llvm::APSInt &getInitVal() const { return Val; }
743
744  void setInitExpr(Expr *E) { Init = (Stmt*) E; }
745  void setInitVal(const llvm::APSInt &V) { Val = V; }
746
747  // Implement isa/cast/dyncast/etc.
748  static bool classof(const Decl *D) { return D->getKind() == EnumConstant; }
749  static bool classof(const EnumConstantDecl *D) { return true; }
750
751  friend class StmtIteratorBase;
752
753protected:
754  /// EmitImpl - Serialize this EnumConstantDecl.  Called by Decl::Emit.
755  virtual void EmitImpl(llvm::Serializer& S) const;
756
757  /// CreateImpl - Deserialize a EnumConstantDecl.  Called by Decl::Create.
758  static EnumConstantDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
759
760  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
761};
762
763
764/// TypeDecl - Represents a declaration of a type.
765///
766class TypeDecl : public ScopedDecl {
767  /// TypeForDecl - This indicates the Type object that represents this
768  /// TypeDecl.  It is a cache maintained by ASTContext::getTypedefType,
769  /// ASTContext::getTagDeclType, and ASTContext::getTemplateTypeParmType.
770  Type *TypeForDecl;
771  friend class ASTContext;
772protected:
773  TypeDecl(Kind DK, DeclContext *DC, SourceLocation L,
774           IdentifierInfo *Id, ScopedDecl *PrevDecl)
775    : ScopedDecl(DK, DC, L, Id, PrevDecl), TypeForDecl(0) {}
776public:
777  void setAccess(AccessSpecifier AS) { Access = AS; }
778  AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
779
780  // Implement isa/cast/dyncast/etc.
781  static bool classof(const Decl *D) {
782    return D->getKind() >= TypeFirst && D->getKind() <= TypeLast;
783  }
784  static bool classof(const TypeDecl *D) { return true; }
785};
786
787
788class TypedefDecl : public TypeDecl {
789  /// UnderlyingType - This is the type the typedef is set to.
790  QualType UnderlyingType;
791  TypedefDecl(DeclContext *DC, SourceLocation L,
792              IdentifierInfo *Id, QualType T, ScopedDecl *PD)
793    : TypeDecl(Typedef, DC, L, Id, PD), UnderlyingType(T) {}
794
795  virtual ~TypedefDecl() {}
796public:
797
798  static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
799                             SourceLocation L,IdentifierInfo *Id,
800                             QualType T, ScopedDecl *PD);
801
802  QualType getUnderlyingType() const { return UnderlyingType; }
803  void setUnderlyingType(QualType newType) { UnderlyingType = newType; }
804
805  // Implement isa/cast/dyncast/etc.
806  static bool classof(const Decl *D) { return D->getKind() == Typedef; }
807  static bool classof(const TypedefDecl *D) { return true; }
808
809protected:
810  /// EmitImpl - Serialize this TypedefDecl.  Called by Decl::Emit.
811  virtual void EmitImpl(llvm::Serializer& S) const;
812
813  /// CreateImpl - Deserialize a TypedefDecl.  Called by Decl::Create.
814  static TypedefDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
815
816  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
817};
818
819
820/// TagDecl - Represents the declaration of a struct/union/class/enum.
821class TagDecl : public TypeDecl {
822public:
823  enum TagKind {
824    TK_struct,
825    TK_union,
826    TK_class,
827    TK_enum
828  };
829
830private:
831  /// TagDeclKind - The TagKind enum.
832  unsigned TagDeclKind : 2;
833
834  /// IsDefinition - True if this is a definition ("struct foo {};"), false if
835  /// it is a declaration ("struct foo;").
836  bool IsDefinition : 1;
837protected:
838  TagDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
839          IdentifierInfo *Id, ScopedDecl *PrevDecl)
840    : TypeDecl(DK, DC, L, Id, PrevDecl) {
841    assert((DK != Enum || TK == TK_enum) &&"EnumDecl not matched with TK_enum");
842    TagDeclKind = TK;
843    IsDefinition = false;
844  }
845public:
846
847  /// isDefinition - Return true if this decl has its body specified.
848  bool isDefinition() const {
849    return IsDefinition;
850  }
851
852  /// getDefinition - Returns the TagDecl that actually defines this
853  ///  struct/union/class/enum.  When determining whether or not a
854  ///  struct/union/class/enum is completely defined, one should use this method
855  ///  as opposed to 'isDefinition'.  'isDefinition' indicates whether or not a
856  ///  specific TagDecl is defining declaration, not whether or not the
857  ///  struct/union/class/enum type is defined.  This method returns NULL if
858  ///  there is no TagDecl that defines the struct/union/class/enum.
859  TagDecl* getDefinition(ASTContext& C) const;
860
861  const char *getKindName() const {
862    switch (getTagKind()) {
863    default: assert(0 && "Unknown TagKind!");
864    case TK_struct: return "struct";
865    case TK_union:  return "union";
866    case TK_class:  return "class";
867    case TK_enum:   return "enum";
868    }
869  }
870
871  TagKind getTagKind() const {
872    return TagKind(TagDeclKind);
873  }
874
875  bool isStruct() const { return getTagKind() == TK_struct; }
876  bool isClass()  const { return getTagKind() == TK_class; }
877  bool isUnion()  const { return getTagKind() == TK_union; }
878  bool isEnum()   const { return getTagKind() == TK_enum; }
879
880  // Implement isa/cast/dyncast/etc.
881  static bool classof(const Decl *D) {
882    return D->getKind() >= TagFirst && D->getKind() <= TagLast;
883  }
884  static bool classof(const TagDecl *D) { return true; }
885protected:
886  void setDefinition(bool V) { IsDefinition = V; }
887};
888
889/// EnumDecl - Represents an enum.  As an extension, we allow forward-declared
890/// enums.
891class EnumDecl : public TagDecl, public DeclContext {
892  /// IntegerType - This represent the integer type that the enum corresponds
893  /// to for code generation purposes.  Note that the enumerator constants may
894  /// have a different type than this does.
895  QualType IntegerType;
896
897  EnumDecl(DeclContext *DC, SourceLocation L,
898           IdentifierInfo *Id, ScopedDecl *PrevDecl)
899    : TagDecl(Enum, TK_enum, DC, L, Id, PrevDecl), DeclContext(Enum) {
900      IntegerType = QualType();
901    }
902public:
903  static EnumDecl *Create(ASTContext &C, DeclContext *DC,
904                          SourceLocation L, IdentifierInfo *Id,
905                          EnumDecl *PrevDecl);
906
907  virtual void Destroy(ASTContext& C);
908
909  /// completeDefinition - When created, the EnumDecl corresponds to a
910  /// forward-declared enum. This method is used to mark the
911  /// declaration as being defined; it's enumerators have already been
912  /// added (via DeclContext::addDecl). NewType is the new underlying
913  /// type of the enumeration type.
914  void completeDefinition(ASTContext &C, QualType NewType);
915
916  // enumerator_iterator - Iterates through the enumerators of this
917  // enumeration.
918  struct enumerator_iterator : public DeclContext::decl_iterator {
919    typedef EnumConstantDecl* value_type;
920    typedef EnumConstantDecl* reference;
921    typedef EnumConstantDecl* pointer;
922
923    enumerator_iterator() : DeclContext::decl_iterator() { }
924
925    explicit enumerator_iterator(DeclContext::decl_iterator Pos)
926      : DeclContext::decl_iterator(Pos) { }
927
928    reference operator*() const {
929      return cast<EnumConstantDecl>(DeclContext::decl_iterator::operator*());
930    }
931
932    pointer operator->() const {
933      return cast<EnumConstantDecl>(DeclContext::decl_iterator::operator*());
934    }
935  };
936
937  enumerator_iterator enumerator_begin() const {
938    return enumerator_iterator(this->decls_begin());
939  }
940
941  enumerator_iterator enumerator_end() const {
942    return enumerator_iterator(this->decls_end());
943  }
944
945  /// getIntegerType - Return the integer type this enum decl corresponds to.
946  /// This returns a null qualtype for an enum forward definition.
947  QualType getIntegerType() const { return IntegerType; }
948
949  static bool classof(const Decl *D) { return D->getKind() == Enum; }
950  static bool classof(const EnumDecl *D) { return true; }
951  static DeclContext *castToDeclContext(const EnumDecl *D) {
952    return static_cast<DeclContext *>(const_cast<EnumDecl*>(D));
953  }
954  static EnumDecl *castFromDeclContext(const DeclContext *DC) {
955    return static_cast<EnumDecl *>(const_cast<DeclContext*>(DC));
956  }
957
958protected:
959  /// EmitImpl - Serialize this EnumDecl.  Called by Decl::Emit.
960  virtual void EmitImpl(llvm::Serializer& S) const;
961
962  /// CreateImpl - Deserialize a EnumDecl.  Called by Decl::Create.
963  static EnumDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
964
965  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
966};
967
968
969/// RecordDecl - Represents a struct/union/class.  For example:
970///   struct X;                  // Forward declaration, no "body".
971///   union Y { int A, B; };     // Has body with members A and B (FieldDecls).
972/// This decl will be marked invalid if *any* members are invalid.
973///
974class RecordDecl : public TagDecl, public DeclContext {
975  /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
976  /// array member (e.g. int X[]) or if this union contains a struct that does.
977  /// If so, this cannot be contained in arrays or other structs as a member.
978  bool HasFlexibleArrayMember : 1;
979
980protected:
981  RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
982             SourceLocation L, IdentifierInfo *Id);
983  virtual ~RecordDecl();
984
985public:
986  static RecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
987                            SourceLocation L, IdentifierInfo *Id,
988                            RecordDecl* PrevDecl = 0);
989
990  virtual void Destroy(ASTContext& C);
991
992  bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
993  void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
994
995  /// getDefinition - Returns the RecordDecl that actually defines this
996  ///  struct/union/class.  When determining whether or not a struct/union/class
997  ///  is completely defined, one should use this method as opposed to
998  ///  'isDefinition'.  'isDefinition' indicates whether or not a specific
999  ///  RecordDecl is defining declaration, not whether or not the record
1000  ///  type is defined.  This method returns NULL if there is no RecordDecl
1001  ///  that defines the struct/union/tag.
1002  RecordDecl* getDefinition(ASTContext& C) const {
1003    return cast_or_null<RecordDecl>(TagDecl::getDefinition(C));
1004  }
1005
1006  // Iterator access to field members. The field iterator only visits
1007  // the non-static data members of this class, ignoring any static
1008  // data members, functions, constructors, destructors, etc.
1009  class field_const_iterator {
1010  protected:
1011    /// Current - Current position within the sequence of declarations
1012    /// in this record.
1013    DeclContext::decl_iterator Current;
1014
1015    /// End - Last position in the sequence of declarations in this
1016    /// record.
1017    DeclContext::decl_iterator End;
1018
1019    /// SkipToNextField - Advances the current position up to the next
1020    /// FieldDecl.
1021    void SkipToNextField() {
1022      while (Current != End && !isa<FieldDecl>(*Current))
1023        ++Current;
1024    }
1025
1026  public:
1027    typedef FieldDecl const *         value_type;
1028    typedef FieldDecl const *         reference;
1029    typedef FieldDecl const *         pointer;
1030    typedef std::ptrdiff_t            difference_type;
1031    typedef std::forward_iterator_tag iterator_category;
1032
1033    field_const_iterator() : Current(), End() { }
1034
1035    field_const_iterator(DeclContext::decl_iterator C,
1036                         DeclContext::decl_iterator E)
1037      : Current(C), End(E) {
1038      SkipToNextField();
1039    }
1040
1041    reference operator*() const { return cast<FieldDecl>(*Current); }
1042
1043    pointer operator->() const { return cast<FieldDecl>(*Current); }
1044
1045    field_const_iterator& operator++() {
1046      ++Current;
1047      SkipToNextField();
1048      return *this;
1049    }
1050
1051    field_const_iterator operator++(int) {
1052      field_const_iterator tmp(*this);
1053      ++(*this);
1054      return tmp;
1055    }
1056
1057    friend bool
1058    operator==(const field_const_iterator& x, const field_const_iterator& y) {
1059      return x.Current == y.Current;
1060    }
1061
1062    friend bool
1063    operator!=(const field_const_iterator& x, const field_const_iterator& y) {
1064      return x.Current != y.Current;
1065    }
1066  };
1067
1068  class field_iterator : public field_const_iterator {
1069  public:
1070    typedef FieldDecl*           value_type;
1071    typedef FieldDecl*           reference;
1072    typedef FieldDecl*           pointer;
1073
1074    field_iterator() : field_const_iterator() { }
1075
1076    field_iterator(DeclContext::decl_iterator C, DeclContext::decl_iterator E)
1077      : field_const_iterator(C, E) { }
1078
1079    reference operator*() const { return cast<FieldDecl>(*Current); }
1080
1081    pointer operator->() const { return cast<FieldDecl>(*Current); }
1082
1083    field_iterator& operator++() {
1084      ++Current;
1085      SkipToNextField();
1086      return *this;
1087    }
1088
1089    field_iterator operator++(int) {
1090      field_iterator tmp(*this);
1091      ++(*this);
1092      return tmp;
1093    }
1094  };
1095
1096  field_iterator field_begin() {
1097    return field_iterator(decls_begin(), decls_end());
1098  }
1099  field_iterator field_end() {
1100    return field_iterator(decls_end(), decls_end());
1101  }
1102
1103  field_const_iterator field_begin() const {
1104    return field_const_iterator(decls_begin(), decls_end());
1105  }
1106  field_const_iterator field_end() const {
1107    return field_const_iterator(decls_end(), decls_end());
1108  }
1109
1110  // field_empty - Whether there are any fields (non-static data
1111  // members) in this record.
1112  bool field_empty() const { return field_begin() == field_end(); }
1113
1114  /// completeDefinition - Notes that the definition of this type is
1115  /// now complete.
1116  void completeDefinition(ASTContext& C);
1117
1118  static bool classof(const Decl *D) {
1119    return D->getKind() >= RecordFirst && D->getKind() <= RecordLast;
1120  }
1121  static bool classof(const RecordDecl *D) { return true; }
1122
1123protected:
1124  /// EmitImpl - Serialize this RecordDecl.  Called by Decl::Emit.
1125  virtual void EmitImpl(llvm::Serializer& S) const;
1126
1127  /// CreateImpl - Deserialize a RecordDecl.  Called by Decl::Create.
1128  static RecordDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1129
1130  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
1131};
1132
1133class FileScopeAsmDecl : public Decl {
1134  StringLiteral *AsmString;
1135  FileScopeAsmDecl(SourceLocation L, StringLiteral *asmstring)
1136    : Decl(FileScopeAsm, L), AsmString(asmstring) {}
1137public:
1138  static FileScopeAsmDecl *Create(ASTContext &C, SourceLocation L,
1139                                  StringLiteral *Str);
1140
1141  const StringLiteral *getAsmString() const { return AsmString; }
1142  StringLiteral *getAsmString() { return AsmString; }
1143  static bool classof(const Decl *D) {
1144    return D->getKind() == FileScopeAsm;
1145  }
1146  static bool classof(const FileScopeAsmDecl *D) { return true; }
1147protected:
1148  /// EmitImpl - Serialize this FileScopeAsmDecl. Called by Decl::Emit.
1149  virtual void EmitImpl(llvm::Serializer& S) const;
1150
1151  /// CreateImpl - Deserialize a FileScopeAsmDecl.  Called by Decl::Create.
1152  static FileScopeAsmDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1153
1154  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
1155};
1156
1157/// BlockDecl - This represents a block literal declaration, which is like an
1158/// unnamed FunctionDecl.  For example:
1159/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
1160///
1161class BlockDecl : public Decl, public DeclContext {
1162  llvm::SmallVector<ParmVarDecl*, 8> Args;
1163  Stmt *Body;
1164
1165  // Since BlockDecl's aren't named/scoped, we need to store the context.
1166  DeclContext *ParentContext;
1167protected:
1168  BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
1169    : Decl(Block, CaretLoc), DeclContext(Block), Body(0), ParentContext(DC) {}
1170
1171  virtual ~BlockDecl();
1172  virtual void Destroy(ASTContext& C);
1173
1174public:
1175  static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
1176
1177  SourceLocation getCaretLocation() const { return getLocation(); }
1178
1179  Stmt *getBody() const { return Body; }
1180  void setBody(Stmt *B) { Body = B; }
1181
1182  void setArgs(ParmVarDecl **args, unsigned numargs) {
1183    Args.clear();
1184    Args.insert(Args.begin(), args, args+numargs);
1185  }
1186  const DeclContext *getParentContext() const { return ParentContext; }
1187  DeclContext *getParentContext() { return ParentContext; }
1188
1189  /// arg_iterator - Iterate over the ParmVarDecl's for this block.
1190  typedef llvm::SmallVector<ParmVarDecl*, 8>::const_iterator param_iterator;
1191  bool param_empty() const { return Args.empty(); }
1192  param_iterator param_begin() const { return Args.begin(); }
1193  param_iterator param_end() const { return Args.end(); }
1194
1195  // Implement isa/cast/dyncast/etc.
1196  static bool classof(const Decl *D) { return D->getKind() == Block; }
1197  static bool classof(const BlockDecl *D) { return true; }
1198  static DeclContext *castToDeclContext(const BlockDecl *D) {
1199    return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
1200  }
1201  static BlockDecl *castFromDeclContext(const DeclContext *DC) {
1202    return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
1203  }
1204
1205protected:
1206  /// EmitImpl - Serialize this BlockDecl. Called by Decl::Emit.
1207  virtual void EmitImpl(llvm::Serializer& S) const;
1208
1209  /// CreateImpl - Deserialize a BlockDecl.  Called by Decl::Create.
1210  static BlockDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1211
1212  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
1213};
1214
1215}  // end namespace clang
1216
1217#endif
1218