1 //===--- Decl.h - 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 subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_DECL_H
15 #define LLVM_CLANG_AST_DECL_H
17 #include "clang/AST/APValue.h"
18 #include "clang/AST/DeclBase.h"
19 #include "clang/AST/DeclarationName.h"
20 #include "clang/AST/ExternalASTSource.h"
24 class FunctionTemplateDecl;
29 /// TranslationUnitDecl - The top declaration context.
30 class TranslationUnitDecl : public Decl, public DeclContext {
32 : Decl(TranslationUnit, 0, SourceLocation()),
33 DeclContext(TranslationUnit) {}
35 static TranslationUnitDecl *Create(ASTContext &C);
36 // Implement isa/cast/dyncast/etc.
37 static bool classof(const Decl *D) { return D->getKind() == TranslationUnit; }
38 static bool classof(const TranslationUnitDecl *D) { return true; }
39 static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
40 return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
42 static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
43 return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
47 /// NamedDecl - This represents a decl with a name. Many decls have names such
48 /// as ObjCMethodDecl, but not @class, etc.
49 class NamedDecl : public Decl {
50 /// Name - The name of this declaration, which is typically a normal
51 /// identifier but may also be a special kind of name (C++
52 /// constructor, Objective-C selector, etc.)
56 NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
57 : Decl(DK, DC, L), Name(N) { }
60 /// getIdentifier - Get the identifier that names this declaration,
61 /// if there is one. This will return NULL if this declaration has
62 /// no name (e.g., for an unnamed class) or if the name is a special
63 /// name (C++ constructor, Objective-C selector, etc.).
64 IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
66 /// getNameAsCString - Get the name of identifier for this declaration as a
67 /// C string (const char*). This requires that the declaration have a name
68 /// and that it be a simple identifier.
69 const char *getNameAsCString() const {
70 assert(getIdentifier() && "Name is not a simple identifier");
71 return getIdentifier()->getName();
74 /// getDeclName - Get the actual, stored name of the declaration,
75 /// which may be a special name.
76 DeclarationName getDeclName() const { return Name; }
78 /// \brief Set the name of this declaration.
79 void setDeclName(DeclarationName N) { Name = N; }
81 /// getNameAsString - Get a human-readable name for the declaration, even if
82 /// it is one of the special kinds of names (C++ constructor, Objective-C
83 /// selector, etc). Creating this name requires expensive string
84 /// manipulation, so it should be called only when performance doesn't matter.
85 /// For simple declarations, getNameAsCString() should suffice.
86 std::string getNameAsString() const { return Name.getAsString(); }
88 /// getQualifiedNameAsString - Returns human-readable qualified name for
89 /// declaration, like A::B::i, for i being member of namespace A::B.
90 /// If declaration is not member of context which can be named (record,
91 /// namespace), it will return same result as getNameAsString().
92 /// Creating this name is expensive, so it should be called only when
93 /// performance doesn't matter.
94 std::string getQualifiedNameAsString() const;
96 /// declarationReplaces - Determine whether this declaration, if
97 /// known to be well-formed within its context, will replace the
98 /// declaration OldD if introduced into scope. A declaration will
99 /// replace another declaration if, for example, it is a
100 /// redeclaration of the same variable or function, but not if it is
101 /// a declaration of a different kind (function vs. class) or an
102 /// overloaded function.
103 bool declarationReplaces(NamedDecl *OldD) const;
105 /// \brief Determine whether this declaration has linkage.
106 bool hasLinkage() const;
108 static bool classof(const Decl *D) {
109 return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
111 static bool classof(const NamedDecl *D) { return true; }
114 /// NamespaceDecl - Represent a C++ namespace.
115 class NamespaceDecl : public NamedDecl, public DeclContext {
116 SourceLocation LBracLoc, RBracLoc;
118 // For extended namespace definitions:
120 // namespace A { int x; }
121 // namespace A { int y; }
123 // there will be one NamespaceDecl for each declaration.
124 // NextNamespace points to the next extended declaration.
125 // OrigNamespace points to the original namespace declaration.
126 // OrigNamespace of the first namespace decl points to itself.
127 NamespaceDecl *OrigNamespace, *NextNamespace;
129 NamespaceDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
130 : NamedDecl(Namespace, DC, L, Id), DeclContext(Namespace) {
131 OrigNamespace = this;
135 static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
136 SourceLocation L, IdentifierInfo *Id);
138 virtual void Destroy(ASTContext& C);
140 NamespaceDecl *getNextNamespace() { return NextNamespace; }
141 const NamespaceDecl *getNextNamespace() const { return NextNamespace; }
142 void setNextNamespace(NamespaceDecl *ND) { NextNamespace = ND; }
144 NamespaceDecl *getOriginalNamespace() const {
145 return OrigNamespace;
147 void setOriginalNamespace(NamespaceDecl *ND) { OrigNamespace = ND; }
149 SourceRange getSourceRange() const {
150 return SourceRange(LBracLoc, RBracLoc);
153 SourceLocation getLBracLoc() const { return LBracLoc; }
154 SourceLocation getRBracLoc() const { return RBracLoc; }
155 void setLBracLoc(SourceLocation LBrace) { LBracLoc = LBrace; }
156 void setRBracLoc(SourceLocation RBrace) { RBracLoc = RBrace; }
158 // Implement isa/cast/dyncast/etc.
159 static bool classof(const Decl *D) { return D->getKind() == Namespace; }
160 static bool classof(const NamespaceDecl *D) { return true; }
161 static DeclContext *castToDeclContext(const NamespaceDecl *D) {
162 return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
164 static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
165 return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
169 /// ValueDecl - Represent the declaration of a variable (in which case it is
170 /// an lvalue) a function (in which case it is a function designator) or
171 /// an enum constant.
172 class ValueDecl : public NamedDecl {
176 ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
177 DeclarationName N, QualType T)
178 : NamedDecl(DK, DC, L, N), DeclType(T) {}
180 QualType getType() const { return DeclType; }
181 void setType(QualType newType) { DeclType = newType; }
183 // Implement isa/cast/dyncast/etc.
184 static bool classof(const Decl *D) {
185 return D->getKind() >= ValueFirst && D->getKind() <= ValueLast;
187 static bool classof(const ValueDecl *D) { return true; }
190 /// \brief Structure used to store a statement, the constant value to
191 /// which it was evaluated (if any), and whether or not the statement
192 /// is an integral constant expression (if known).
193 struct EvaluatedStmt {
194 EvaluatedStmt() : WasEvaluated(false), CheckedICE(false), IsICE(false) { }
196 /// \brief Whether this statement was already evaluated.
197 bool WasEvaluated : 1;
199 /// \brief Whether we already checked whether this statement was an
200 /// integral constant expression.
203 /// \brief Whether this statement is an integral constant
204 /// expression. Only valid if CheckedICE is true.
211 /// VarDecl - An instance of this class is created to represent a variable
212 /// declaration or definition.
213 class VarDecl : public ValueDecl {
216 None, Auto, Register, Extern, Static, PrivateExtern
219 /// getStorageClassSpecifierString - Return the string used to
220 /// specify the storage class \arg SC.
222 /// It is illegal to call this function with SC == None.
223 static const char *getStorageClassSpecifierString(StorageClass SC);
226 mutable llvm::PointerUnion<Stmt *, EvaluatedStmt *> Init;
227 // FIXME: This can be packed into the bitfields in Decl.
229 bool ThreadSpecified : 1;
230 bool HasCXXDirectInit : 1;
232 /// DeclaredInCondition - Whether this variable was declared in a
233 /// condition, e.g., if (int x = foo()) { ... }.
234 bool DeclaredInCondition : 1;
236 /// \brief The previous declaration of this variable.
237 VarDecl *PreviousDeclaration;
239 // Move to DeclGroup when it is implemented.
240 SourceLocation TypeSpecStartLoc;
241 friend class StmtIteratorBase;
243 VarDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
244 QualType T, StorageClass SC, SourceLocation TSSL = SourceLocation())
245 : ValueDecl(DK, DC, L, Id, T), Init(),
246 ThreadSpecified(false), HasCXXDirectInit(false),
247 DeclaredInCondition(false), PreviousDeclaration(0),
248 TypeSpecStartLoc(TSSL) {
252 static VarDecl *Create(ASTContext &C, DeclContext *DC,
253 SourceLocation L, IdentifierInfo *Id,
254 QualType T, StorageClass S,
255 SourceLocation TypeSpecStartLoc = SourceLocation());
258 virtual void Destroy(ASTContext& C);
260 StorageClass getStorageClass() const { return (StorageClass)SClass; }
261 void setStorageClass(StorageClass SC) { SClass = SC; }
263 SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
264 void setTypeSpecStartLoc(SourceLocation SL) {
265 TypeSpecStartLoc = SL;
268 const Expr *getInit() const {
272 const Stmt *S = Init.dyn_cast<Stmt *>();
274 S = Init.get<EvaluatedStmt *>()->Value;
276 return (const Expr*) S;
282 Stmt *S = Init.dyn_cast<Stmt *>();
284 S = Init.get<EvaluatedStmt *>()->Value;
289 /// \brief Retrieve the address of the initializer expression.
290 Stmt **getInitAddress() {
291 if (Init.is<Stmt *>())
292 return reinterpret_cast<Stmt **>(&Init); // FIXME: ugly hack
293 return &Init.get<EvaluatedStmt *>()->Value;
296 void setInit(ASTContext &C, Expr *I);
298 /// \brief Note that constant evaluation has computed the given
299 /// value for this variable's initializer.
300 void setEvaluatedValue(ASTContext &C, const APValue &Value) const {
301 EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>();
303 Stmt *S = Init.get<Stmt *>();
304 Eval = new (C) EvaluatedStmt;
309 Eval->WasEvaluated = true;
310 Eval->Evaluated = Value;
313 /// \brief Return the already-evaluated value of this variable's
314 /// initializer, or NULL if the value is not yet known.
315 APValue *getEvaluatedValue() const {
316 if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
317 if (Eval->WasEvaluated)
318 return &Eval->Evaluated;
323 /// \brief Determines whether it is already known whether the
324 /// initializer is an integral constant expression or not.
325 bool isInitKnownICE() const {
326 if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
327 return Eval->CheckedICE;
332 /// \brief Determines whether the initializer is an integral
333 /// constant expression.
335 /// \pre isInitKnownICE()
336 bool isInitICE() const {
337 assert(isInitKnownICE() &&
338 "Check whether we already know that the initializer is an ICE");
339 return Init.get<EvaluatedStmt *>()->IsICE;
342 /// \brief Note that we now know whether the initializer is an
343 /// integral constant expression.
344 void setInitKnownICE(ASTContext &C, bool IsICE) const {
345 EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>();
347 Stmt *S = Init.get<Stmt *>();
348 Eval = new (C) EvaluatedStmt;
353 Eval->CheckedICE = true;
357 /// \brief Retrieve the definition of this variable, which may come
358 /// from a previous declaration. Def will be set to the VarDecl that
359 /// contains the initializer, and the result will be that
361 const Expr *getDefinition(const VarDecl *&Def) const;
363 void setThreadSpecified(bool T) { ThreadSpecified = T; }
364 bool isThreadSpecified() const {
365 return ThreadSpecified;
368 void setCXXDirectInitializer(bool T) { HasCXXDirectInit = T; }
370 /// hasCXXDirectInitializer - If true, the initializer was a direct
371 /// initializer, e.g: "int x(1);". The Init expression will be the expression
372 /// inside the parens or a "ClassType(a,b,c)" class constructor expression for
373 /// class types. Clients can distinguish between "int x(1);" and "int x=1;"
374 /// by checking hasCXXDirectInitializer.
376 bool hasCXXDirectInitializer() const {
377 return HasCXXDirectInit;
380 /// isDeclaredInCondition - Whether this variable was declared as
381 /// part of a condition in an if/switch/while statement, e.g.,
383 /// if (int x = foo()) { ... }
385 bool isDeclaredInCondition() const {
386 return DeclaredInCondition;
388 void setDeclaredInCondition(bool InCondition) {
389 DeclaredInCondition = InCondition;
392 /// getPreviousDeclaration - Return the previous declaration of this
394 const VarDecl *getPreviousDeclaration() const { return PreviousDeclaration; }
396 void setPreviousDeclaration(VarDecl *PrevDecl) {
397 PreviousDeclaration = PrevDecl;
400 /// hasLocalStorage - Returns true if a variable with function scope
401 /// is a non-static local variable.
402 bool hasLocalStorage() const {
403 if (getStorageClass() == None)
404 return !isFileVarDecl();
406 // Return true for: Auto, Register.
407 // Return false for: Extern, Static, PrivateExtern.
409 return getStorageClass() <= Register;
412 /// hasExternStorage - Returns true if a variable has extern or
413 /// __private_extern__ storage.
414 bool hasExternalStorage() const {
415 return getStorageClass() == Extern || getStorageClass() == PrivateExtern;
418 /// hasGlobalStorage - Returns true for all variables that do not
419 /// have local storage. This includs all global variables as well
420 /// as static variables declared within a function.
421 bool hasGlobalStorage() const { return !hasLocalStorage(); }
423 /// isBlockVarDecl - Returns true for local variable declarations. Note that
424 /// this includes static variables inside of functions.
426 /// void foo() { int x; static int y; extern int z; }
428 bool isBlockVarDecl() const {
429 if (getKind() != Decl::Var)
431 if (const DeclContext *DC = getDeclContext())
432 return DC->getLookupContext()->isFunctionOrMethod();
436 /// \brief Determines whether this is a static data member.
438 /// This will only be true in C++, and applies to, e.g., the
445 bool isStaticDataMember() const {
446 return getDeclContext()->isRecord();
449 /// isFileVarDecl - Returns true for file scoped variable declaration.
450 bool isFileVarDecl() const {
451 if (getKind() != Decl::Var)
453 if (const DeclContext *Ctx = getDeclContext()) {
454 Ctx = Ctx->getLookupContext();
455 if (isa<TranslationUnitDecl>(Ctx) || isa<NamespaceDecl>(Ctx) )
461 /// \brief Determine whether this is a tentative definition of a
463 bool isTentativeDefinition(ASTContext &Context) const;
465 /// \brief Determines whether this variable is a variable with
466 /// external, C linkage.
467 bool isExternC(ASTContext &Context) const;
469 // Implement isa/cast/dyncast/etc.
470 static bool classof(const Decl *D) {
471 return D->getKind() >= VarFirst && D->getKind() <= VarLast;
473 static bool classof(const VarDecl *D) { return true; }
476 class ImplicitParamDecl : public VarDecl {
478 ImplicitParamDecl(Kind DK, DeclContext *DC, SourceLocation L,
479 IdentifierInfo *Id, QualType Tw)
480 : VarDecl(DK, DC, L, Id, Tw, VarDecl::None) {}
482 static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
483 SourceLocation L, IdentifierInfo *Id,
485 // Implement isa/cast/dyncast/etc.
486 static bool classof(const ImplicitParamDecl *D) { return true; }
487 static bool classof(const Decl *D) { return D->getKind() == ImplicitParam; }
490 /// ParmVarDecl - Represent a parameter to a function.
491 class ParmVarDecl : public VarDecl {
492 // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
493 /// FIXME: Also can be paced into the bitfields in Decl.
495 unsigned objcDeclQualifier : 6;
497 /// Default argument, if any. [C++ Only]
500 ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation L,
501 IdentifierInfo *Id, QualType T, StorageClass S,
503 : VarDecl(DK, DC, L, Id, T, S),
504 objcDeclQualifier(OBJC_TQ_None), DefaultArg(DefArg) {}
507 static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
508 SourceLocation L,IdentifierInfo *Id,
509 QualType T, StorageClass S, Expr *DefArg);
511 ObjCDeclQualifier getObjCDeclQualifier() const {
512 return ObjCDeclQualifier(objcDeclQualifier);
514 void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
515 objcDeclQualifier = QTVal;
518 const Expr *getDefaultArg() const { return DefaultArg; }
519 Expr *getDefaultArg() { return DefaultArg; }
520 void setDefaultArg(Expr *defarg) { DefaultArg = defarg; }
522 /// hasUnparsedDefaultArg - Determines whether this parameter has a
523 /// default argument that has not yet been parsed. This will occur
524 /// during the processing of a C++ class whose member functions have
525 /// default arguments, e.g.,
529 /// void f(int x = 17); // x has an unparsed default argument now
530 /// }; // x has a regular default argument now
532 bool hasUnparsedDefaultArg() const {
533 return DefaultArg == reinterpret_cast<Expr *>(-1);
536 /// setUnparsedDefaultArg - Specify that this parameter has an
537 /// unparsed default argument. The argument will be replaced with a
538 /// real default argument via setDefaultArg when the class
539 /// definition enclosing the function declaration that owns this
540 /// default argument is completed.
541 void setUnparsedDefaultArg() { DefaultArg = reinterpret_cast<Expr *>(-1); }
543 QualType getOriginalType() const;
545 /// setOwningFunction - Sets the function declaration that owns this
546 /// ParmVarDecl. Since ParmVarDecls are often created before the
547 /// FunctionDecls that own them, this routine is required to update
548 /// the DeclContext appropriately.
549 void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
551 // Implement isa/cast/dyncast/etc.
552 static bool classof(const Decl *D) {
553 return (D->getKind() == ParmVar ||
554 D->getKind() == OriginalParmVar);
556 static bool classof(const ParmVarDecl *D) { return true; }
559 /// OriginalParmVarDecl - Represent a parameter to a function, when
560 /// the type of the parameter has been promoted. This node represents the
561 /// parameter to the function with its original type.
563 class OriginalParmVarDecl : public ParmVarDecl {
564 friend class ParmVarDecl;
566 QualType OriginalType;
568 OriginalParmVarDecl(DeclContext *DC, SourceLocation L,
569 IdentifierInfo *Id, QualType T,
570 QualType OT, StorageClass S,
572 : ParmVarDecl(OriginalParmVar, DC, L, Id, T, S, DefArg), OriginalType(OT) {}
574 static OriginalParmVarDecl *Create(ASTContext &C, DeclContext *DC,
575 SourceLocation L,IdentifierInfo *Id,
576 QualType T, QualType OT,
577 StorageClass S, Expr *DefArg);
579 void setOriginalType(QualType T) { OriginalType = T; }
581 // Implement isa/cast/dyncast/etc.
582 static bool classof(const Decl *D) { return D->getKind() == OriginalParmVar; }
583 static bool classof(const OriginalParmVarDecl *D) { return true; }
586 /// FunctionDecl - An instance of this class is created to represent a
587 /// function declaration or definition.
589 /// Since a given function can be declared several times in a program,
590 /// there may be several FunctionDecls that correspond to that
591 /// function. Only one of those FunctionDecls will be found when
592 /// traversing the list of declarations in the context of the
593 /// FunctionDecl (e.g., the translation unit); this FunctionDecl
594 /// contains all of the information known about the function. Other,
595 /// previous declarations of the function are available via the
596 /// getPreviousDeclaration() chain.
597 class FunctionDecl : public ValueDecl, public DeclContext {
600 None, Extern, Static, PrivateExtern
603 /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
604 /// parameters of this function. This is null if a prototype or if there are
605 /// no formals. TODO: we could allocate this space immediately after the
606 /// FunctionDecl object to save an allocation like FunctionType does.
607 ParmVarDecl **ParamInfo;
609 LazyDeclStmtPtr Body;
611 /// PreviousDeclaration - A link to the previous declaration of this
612 /// same function, NULL if this is the first declaration. For
613 /// example, in the following code, the PreviousDeclaration can be
614 /// traversed several times to see all three declarations of the
615 /// function "f", the last of which is also a definition.
617 /// int f(int x, int y = 1);
618 /// int f(int x = 0, int y);
619 /// int f(int x, int y) { return x + y; }
620 FunctionDecl *PreviousDeclaration;
622 // FIXME: This can be packed into the bitfields in Decl.
623 // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
626 bool C99InlineDefinition : 1;
627 bool IsVirtualAsWritten : 1;
629 bool HasInheritedPrototype : 1;
630 bool HasWrittenPrototype : 1;
633 // Move to DeclGroup when it is implemented.
634 SourceLocation TypeSpecStartLoc;
636 /// \brief The template or declaration that this declaration
637 /// describes or was instantiated from, respectively.
639 /// For non-templates, this value will be NULL. For function
640 /// declarations that describe a function template, this will be a
641 /// pointer to a FunctionTemplateDecl. For member functions
642 /// of class template specializations, this will be the
643 /// FunctionDecl from which the member function was instantiated.
644 llvm::PointerUnion<FunctionTemplateDecl*, FunctionDecl*>
645 TemplateOrInstantiation;
648 FunctionDecl(Kind DK, DeclContext *DC, SourceLocation L,
649 DeclarationName N, QualType T,
650 StorageClass S, bool isInline,
651 SourceLocation TSSL = SourceLocation())
652 : ValueDecl(DK, DC, L, N, T),
654 ParamInfo(0), Body(), PreviousDeclaration(0),
655 SClass(S), IsInline(isInline), C99InlineDefinition(false),
656 IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false),
657 HasWrittenPrototype(true), IsDeleted(false), TypeSpecStartLoc(TSSL),
658 TemplateOrInstantiation() {}
660 virtual ~FunctionDecl() {}
661 virtual void Destroy(ASTContext& C);
664 static FunctionDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
665 DeclarationName N, QualType T,
666 StorageClass S = None, bool isInline = false,
667 bool hasWrittenPrototype = true,
668 SourceLocation TSStartLoc = SourceLocation());
670 SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
671 void setTypeSpecStartLoc(SourceLocation TS) { TypeSpecStartLoc = TS; }
673 /// getBody - Retrieve the body (definition) of the function. The
674 /// function body might be in any of the (re-)declarations of this
675 /// function. The variant that accepts a FunctionDecl pointer will
676 /// set that function declaration to the actual declaration
677 /// containing the body (if there is one).
678 Stmt *getBody(ASTContext &Context, const FunctionDecl *&Definition) const;
680 virtual Stmt *getBody(ASTContext &Context) const {
681 const FunctionDecl* Definition;
682 return getBody(Context, Definition);
685 /// \brief If the function has a body that is immediately available,
687 Stmt *getBodyIfAvailable() const;
689 /// isThisDeclarationADefinition - Returns whether this specific
690 /// declaration of the function is also a definition. This does not
691 /// determine whether the function has been defined (e.g., in a
692 /// previous definition); for that information, use getBody.
693 /// FIXME: Should return true if function is deleted or defaulted. However,
694 /// CodeGenModule.cpp uses it, and I don't know if this would break it.
695 bool isThisDeclarationADefinition() const { return Body; }
697 void setBody(Stmt *B) { Body = B; }
698 void setLazyBody(uint64_t Offset) { Body = Offset; }
700 /// Whether this function is marked as virtual explicitly.
701 bool isVirtualAsWritten() const { return IsVirtualAsWritten; }
702 void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; }
704 /// Whether this virtual function is pure, i.e. makes the containing class
706 bool isPure() const { return IsPure; }
707 void setPure(bool P = true) { IsPure = P; }
709 /// \brief Whether this function has a prototype, either because one
710 /// was explicitly written or because it was "inherited" by merging
711 /// a declaration without a prototype with a declaration that has a
713 bool hasPrototype() const {
714 return HasWrittenPrototype || HasInheritedPrototype;
717 bool hasWrittenPrototype() const { return HasWrittenPrototype; }
718 void setHasWrittenPrototype(bool P) { HasWrittenPrototype = P; }
720 /// \brief Whether this function inherited its prototype from a
721 /// previous declaration.
722 bool hasInheritedPrototype() const { return HasInheritedPrototype; }
723 void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; }
725 /// \brief Whether this function has been deleted.
727 /// A function that is "deleted" (via the C++0x "= delete" syntax)
728 /// acts like a normal function, except that it cannot actually be
729 /// called or have its address taken. Deleted functions are
730 /// typically used in C++ overload resolution to attract arguments
731 /// whose type or lvalue/rvalue-ness would permit the use of a
732 /// different overload that would behave incorrectly. For example,
733 /// one might use deleted functions to ban implicit conversion from
734 /// a floating-point number to an Integer type:
738 /// Integer(long); // construct from a long
739 /// Integer(double) = delete; // no construction from float or double
740 /// Integer(long double) = delete; // no construction from long double
743 bool isDeleted() const { return IsDeleted; }
744 void setDeleted(bool D = true) { IsDeleted = D; }
746 /// \brief Determines whether this is a function "main", which is
747 /// the entry point into an executable program.
750 /// \brief Determines whether this function is a function with
751 /// external, C linkage.
752 bool isExternC(ASTContext &Context) const;
754 /// \brief Determines whether this is a global function.
755 bool isGlobal() const;
757 /// getPreviousDeclaration - Return the previous declaration of this
759 const FunctionDecl *getPreviousDeclaration() const {
760 return PreviousDeclaration;
763 void setPreviousDeclaration(FunctionDecl * PrevDecl) {
764 PreviousDeclaration = PrevDecl;
767 unsigned getBuiltinID(ASTContext &Context) const;
769 unsigned getNumParmVarDeclsFromType() const;
771 // Iterator access to formal parameters.
772 unsigned param_size() const { return getNumParams(); }
773 typedef ParmVarDecl **param_iterator;
774 typedef ParmVarDecl * const *param_const_iterator;
776 param_iterator param_begin() { return ParamInfo; }
777 param_iterator param_end() { return ParamInfo+param_size(); }
779 param_const_iterator param_begin() const { return ParamInfo; }
780 param_const_iterator param_end() const { return ParamInfo+param_size(); }
782 /// getNumParams - Return the number of parameters this function must have
783 /// based on its functiontype. This is the length of the PararmInfo array
784 /// after it has been created.
785 unsigned getNumParams() const;
787 const ParmVarDecl *getParamDecl(unsigned i) const {
788 assert(i < getNumParams() && "Illegal param #");
791 ParmVarDecl *getParamDecl(unsigned i) {
792 assert(i < getNumParams() && "Illegal param #");
795 void setParams(ASTContext& C, ParmVarDecl **NewParamInfo, unsigned NumParams);
797 /// getMinRequiredArguments - Returns the minimum number of arguments
798 /// needed to call this function. This may be fewer than the number of
799 /// function parameters, if some of the parameters have default
800 /// arguments (in C++).
801 unsigned getMinRequiredArguments() const;
803 QualType getResultType() const {
804 return getType()->getAsFunctionType()->getResultType();
806 StorageClass getStorageClass() const { return StorageClass(SClass); }
807 void setStorageClass(StorageClass SC) { SClass = SC; }
809 bool isInline() const { return IsInline; }
810 void setInline(bool I) { IsInline = I; }
812 /// \brief Whether this function is an "inline definition" as
814 bool isC99InlineDefinition() const { return C99InlineDefinition; }
815 void setC99InlineDefinition(bool I) { C99InlineDefinition = I; }
817 /// \brief Determines whether this function has a gnu_inline
818 /// attribute that affects its semantics.
820 /// The gnu_inline attribute only introduces GNU inline semantics
821 /// when all of the inline declarations of the function are marked
823 bool hasActiveGNUInlineAttribute() const;
825 /// \brief Determines whether this function is a GNU "extern
826 /// inline", which is roughly the opposite of a C99 "extern inline"
828 bool isExternGNUInline() const;
830 /// isOverloadedOperator - Whether this function declaration
831 /// represents an C++ overloaded operator, e.g., "operator+".
832 bool isOverloadedOperator() const {
833 return getOverloadedOperator() != OO_None;
836 OverloadedOperatorKind getOverloadedOperator() const;
838 /// \brief If this function is an instantiation of a member function
839 /// of a class template specialization, retrieves the function from
840 /// which it was instantiated.
842 /// This routine will return non-NULL for (non-templated) member
843 /// functions of class templates and for instantiations of function
844 /// templates. For example, given:
847 /// template<typename T>
853 /// The declaration for X<int>::f is a (non-templated) FunctionDecl
854 /// whose parent is the class template specialization X<int>. For
855 /// this declaration, getInstantiatedFromFunction() will return
856 /// the FunctionDecl X<T>::A. When a complete definition of
857 /// X<int>::A is required, it will be instantiated from the
858 /// declaration returned by getInstantiatedFromMemberFunction().
859 FunctionDecl *getInstantiatedFromMemberFunction() const {
860 return TemplateOrInstantiation.dyn_cast<FunctionDecl*>();
863 /// \brief Specify that this record is an instantiation of the
864 /// member function RD.
865 void setInstantiationOfMemberFunction(FunctionDecl *RD) {
866 TemplateOrInstantiation = RD;
869 /// \brief Retrieves the function template that is described by this
870 /// function declaration.
872 /// Every function template is represented as a FunctionTemplateDecl
873 /// and a FunctionDecl (or something derived from FunctionDecl). The
874 /// former contains template properties (such as the template
875 /// parameter lists) while the latter contains the actual
876 /// description of the template's
877 /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
878 /// FunctionDecl that describes the function template,
879 /// getDescribedFunctionTemplate() retrieves the
880 /// FunctionTemplateDecl from a FunctionDecl.
881 FunctionTemplateDecl *getDescribedFunctionTemplate() const {
882 return TemplateOrInstantiation.dyn_cast<FunctionTemplateDecl*>();
885 void setDescribedFunctionTemplate(FunctionTemplateDecl *Template) {
886 TemplateOrInstantiation = Template;
889 // Implement isa/cast/dyncast/etc.
890 static bool classof(const Decl *D) {
891 return D->getKind() >= FunctionFirst && D->getKind() <= FunctionLast;
893 static bool classof(const FunctionDecl *D) { return true; }
894 static DeclContext *castToDeclContext(const FunctionDecl *D) {
895 return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
897 static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
898 return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
903 /// FieldDecl - An instance of this class is created by Sema::ActOnField to
904 /// represent a member of a struct/union/class.
905 class FieldDecl : public ValueDecl {
906 // FIXME: This can be packed into the bitfields in Decl.
910 FieldDecl(Kind DK, DeclContext *DC, SourceLocation L,
911 IdentifierInfo *Id, QualType T, Expr *BW, bool Mutable)
912 : ValueDecl(DK, DC, L, Id, T), Mutable(Mutable), BitWidth(BW)
916 static FieldDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
917 IdentifierInfo *Id, QualType T, Expr *BW,
920 /// isMutable - Determines whether this field is mutable (C++ only).
921 bool isMutable() const { return Mutable; }
923 /// \brief Set whether this field is mutable (C++ only).
924 void setMutable(bool M) { Mutable = M; }
926 /// isBitfield - Determines whether this field is a bitfield.
927 bool isBitField() const { return BitWidth != NULL; }
929 /// @brief Determines whether this is an unnamed bitfield.
930 bool isUnnamedBitfield() const { return BitWidth != NULL && !getDeclName(); }
932 /// isAnonymousStructOrUnion - Determines whether this field is a
933 /// representative for an anonymous struct or union. Such fields are
934 /// unnamed and are implicitly generated by the implementation to
935 /// store the data for the anonymous union or struct.
936 bool isAnonymousStructOrUnion() const;
938 Expr *getBitWidth() const { return BitWidth; }
939 void setBitWidth(Expr *BW) { BitWidth = BW; }
941 // Implement isa/cast/dyncast/etc.
942 static bool classof(const Decl *D) {
943 return D->getKind() >= FieldFirst && D->getKind() <= FieldLast;
945 static bool classof(const FieldDecl *D) { return true; }
948 /// EnumConstantDecl - An instance of this object exists for each enum constant
949 /// that is defined. For example, in "enum X {a,b}", each of a/b are
950 /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
951 /// TagType for the X EnumDecl.
952 class EnumConstantDecl : public ValueDecl {
953 Stmt *Init; // an integer constant expression
954 llvm::APSInt Val; // The value.
956 EnumConstantDecl(DeclContext *DC, SourceLocation L,
957 IdentifierInfo *Id, QualType T, Expr *E,
958 const llvm::APSInt &V)
959 : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
961 virtual ~EnumConstantDecl() {}
964 static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
965 SourceLocation L, IdentifierInfo *Id,
967 const llvm::APSInt &V);
969 virtual void Destroy(ASTContext& C);
971 const Expr *getInitExpr() const { return (const Expr*) Init; }
972 Expr *getInitExpr() { return (Expr*) Init; }
973 const llvm::APSInt &getInitVal() const { return Val; }
975 void setInitExpr(Expr *E) { Init = (Stmt*) E; }
976 void setInitVal(const llvm::APSInt &V) { Val = V; }
978 // Implement isa/cast/dyncast/etc.
979 static bool classof(const Decl *D) { return D->getKind() == EnumConstant; }
980 static bool classof(const EnumConstantDecl *D) { return true; }
982 friend class StmtIteratorBase;
986 /// TypeDecl - Represents a declaration of a type.
988 class TypeDecl : public NamedDecl {
989 /// TypeForDecl - This indicates the Type object that represents
990 /// this TypeDecl. It is a cache maintained by
991 /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
992 /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
993 mutable Type *TypeForDecl;
994 friend class ASTContext;
995 friend class DeclContext;
996 friend class TagDecl;
997 friend class TemplateTypeParmDecl;
998 friend class ClassTemplateSpecializationDecl;
999 friend class TagType;
1002 TypeDecl(Kind DK, DeclContext *DC, SourceLocation L,
1004 : NamedDecl(DK, DC, L, Id), TypeForDecl(0) {}
1007 // Low-level accessor
1008 Type *getTypeForDecl() const { return TypeForDecl; }
1009 void setTypeForDecl(Type *TD) { TypeForDecl = TD; }
1011 // Implement isa/cast/dyncast/etc.
1012 static bool classof(const Decl *D) {
1013 return D->getKind() >= TypeFirst && D->getKind() <= TypeLast;
1015 static bool classof(const TypeDecl *D) { return true; }
1019 class TypedefDecl : public TypeDecl {
1020 /// UnderlyingType - This is the type the typedef is set to.
1021 QualType UnderlyingType;
1022 TypedefDecl(DeclContext *DC, SourceLocation L,
1023 IdentifierInfo *Id, QualType T)
1024 : TypeDecl(Typedef, DC, L, Id), UnderlyingType(T) {}
1026 virtual ~TypedefDecl() {}
1029 static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
1030 SourceLocation L,IdentifierInfo *Id,
1033 QualType getUnderlyingType() const { return UnderlyingType; }
1034 void setUnderlyingType(QualType newType) { UnderlyingType = newType; }
1036 // Implement isa/cast/dyncast/etc.
1037 static bool classof(const Decl *D) { return D->getKind() == Typedef; }
1038 static bool classof(const TypedefDecl *D) { return true; }
1043 /// TagDecl - Represents the declaration of a struct/union/class/enum.
1044 class TagDecl : public TypeDecl, public DeclContext {
1054 // FIXME: This can be packed into the bitfields in Decl.
1055 /// TagDeclKind - The TagKind enum.
1056 unsigned TagDeclKind : 2;
1058 /// IsDefinition - True if this is a definition ("struct foo {};"), false if
1059 /// it is a declaration ("struct foo;").
1060 bool IsDefinition : 1;
1062 /// TypedefForAnonDecl - If a TagDecl is anonymous and part of a typedef,
1063 /// this points to the TypedefDecl. Used for mangling.
1064 TypedefDecl *TypedefForAnonDecl;
1067 TagDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
1069 : TypeDecl(DK, DC, L, Id), DeclContext(DK), TypedefForAnonDecl(0) {
1070 assert((DK != Enum || TK == TK_enum) &&"EnumDecl not matched with TK_enum");
1072 IsDefinition = false;
1076 /// isDefinition - Return true if this decl has its body specified.
1077 bool isDefinition() const {
1078 return IsDefinition;
1081 /// \brief Whether this declaration declares a type that is
1082 /// dependent, i.e., a type that somehow depends on template
1084 bool isDependentType() const { return isDependentContext(); }
1086 /// @brief Starts the definition of this tag declaration.
1088 /// This method should be invoked at the beginning of the definition
1089 /// of this tag declaration. It will set the tag type into a state
1090 /// where it is in the process of being defined.
1091 void startDefinition();
1093 /// @brief Completes the definition of this tag declaration.
1094 void completeDefinition();
1096 /// getDefinition - Returns the TagDecl that actually defines this
1097 /// struct/union/class/enum. When determining whether or not a
1098 /// struct/union/class/enum is completely defined, one should use this method
1099 /// as opposed to 'isDefinition'. 'isDefinition' indicates whether or not a
1100 /// specific TagDecl is defining declaration, not whether or not the
1101 /// struct/union/class/enum type is defined. This method returns NULL if
1102 /// there is no TagDecl that defines the struct/union/class/enum.
1103 TagDecl* getDefinition(ASTContext& C) const;
1105 const char *getKindName() const {
1106 switch (getTagKind()) {
1107 default: assert(0 && "Unknown TagKind!");
1108 case TK_struct: return "struct";
1109 case TK_union: return "union";
1110 case TK_class: return "class";
1111 case TK_enum: return "enum";
1115 TagKind getTagKind() const {
1116 return TagKind(TagDeclKind);
1119 void setTagKind(TagKind TK) { TagDeclKind = TK; }
1121 bool isStruct() const { return getTagKind() == TK_struct; }
1122 bool isClass() const { return getTagKind() == TK_class; }
1123 bool isUnion() const { return getTagKind() == TK_union; }
1124 bool isEnum() const { return getTagKind() == TK_enum; }
1126 TypedefDecl *getTypedefForAnonDecl() const { return TypedefForAnonDecl; }
1127 void setTypedefForAnonDecl(TypedefDecl *TDD) { TypedefForAnonDecl = TDD; }
1129 // Implement isa/cast/dyncast/etc.
1130 static bool classof(const Decl *D) {
1131 return D->getKind() >= TagFirst && D->getKind() <= TagLast;
1133 static bool classof(const TagDecl *D) { return true; }
1135 static DeclContext *castToDeclContext(const TagDecl *D) {
1136 return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
1138 static TagDecl *castFromDeclContext(const DeclContext *DC) {
1139 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
1142 void setDefinition(bool V) { IsDefinition = V; }
1145 /// EnumDecl - Represents an enum. As an extension, we allow forward-declared
1147 class EnumDecl : public TagDecl {
1148 /// IntegerType - This represent the integer type that the enum corresponds
1149 /// to for code generation purposes. Note that the enumerator constants may
1150 /// have a different type than this does.
1151 QualType IntegerType;
1153 /// \brief If the enumeration was instantiated from an enumeration
1154 /// within a class or function template, this pointer refers to the
1155 /// enumeration declared within the template.
1156 EnumDecl *InstantiatedFrom;
1158 EnumDecl(DeclContext *DC, SourceLocation L,
1160 : TagDecl(Enum, TK_enum, DC, L, Id), InstantiatedFrom(0) {
1161 IntegerType = QualType();
1164 static EnumDecl *Create(ASTContext &C, DeclContext *DC,
1165 SourceLocation L, IdentifierInfo *Id,
1166 EnumDecl *PrevDecl);
1168 virtual void Destroy(ASTContext& C);
1170 /// completeDefinition - When created, the EnumDecl corresponds to a
1171 /// forward-declared enum. This method is used to mark the
1172 /// declaration as being defined; it's enumerators have already been
1173 /// added (via DeclContext::addDecl). NewType is the new underlying
1174 /// type of the enumeration type.
1175 void completeDefinition(ASTContext &C, QualType NewType);
1177 // enumerator_iterator - Iterates through the enumerators of this
1179 typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator;
1181 enumerator_iterator enumerator_begin(ASTContext &Context) const {
1182 return enumerator_iterator(this->decls_begin(Context));
1185 enumerator_iterator enumerator_end(ASTContext &Context) const {
1186 return enumerator_iterator(this->decls_end(Context));
1189 /// getIntegerType - Return the integer type this enum decl corresponds to.
1190 /// This returns a null qualtype for an enum forward definition.
1191 QualType getIntegerType() const { return IntegerType; }
1193 /// \brief Set the underlying integer type.
1194 void setIntegerType(QualType T) { IntegerType = T; }
1196 /// \brief Returns the enumeration (declared within the template)
1197 /// from which this enumeration type was instantiated, or NULL if
1198 /// this enumeration was not instantiated from any template.
1199 EnumDecl *getInstantiatedFromMemberEnum() const {
1200 return InstantiatedFrom;
1203 void setInstantiationOfMemberEnum(EnumDecl *IF) { InstantiatedFrom = IF; }
1205 static bool classof(const Decl *D) { return D->getKind() == Enum; }
1206 static bool classof(const EnumDecl *D) { return true; }
1210 /// RecordDecl - Represents a struct/union/class. For example:
1211 /// struct X; // Forward declaration, no "body".
1212 /// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
1213 /// This decl will be marked invalid if *any* members are invalid.
1215 class RecordDecl : public TagDecl {
1216 // FIXME: This can be packed into the bitfields in Decl.
1217 /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
1218 /// array member (e.g. int X[]) or if this union contains a struct that does.
1219 /// If so, this cannot be contained in arrays or other structs as a member.
1220 bool HasFlexibleArrayMember : 1;
1222 /// AnonymousStructOrUnion - Whether this is the type of an
1223 /// anonymous struct or union.
1224 bool AnonymousStructOrUnion : 1;
1227 RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
1228 SourceLocation L, IdentifierInfo *Id);
1229 virtual ~RecordDecl();
1232 static RecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
1233 SourceLocation L, IdentifierInfo *Id,
1234 RecordDecl* PrevDecl = 0);
1236 virtual void Destroy(ASTContext& C);
1238 bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
1239 void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
1241 /// isAnonymousStructOrUnion - Whether this is an anonymous struct
1242 /// or union. To be an anonymous struct or union, it must have been
1243 /// declared without a name and there must be no objects of this
1244 /// type declared, e.g.,
1246 /// union { int i; float f; };
1248 /// is an anonymous union but neither of the following are:
1250 /// union X { int i; float f; };
1251 /// union { int i; float f; } obj;
1253 bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; }
1254 void setAnonymousStructOrUnion(bool Anon) {
1255 AnonymousStructOrUnion = Anon;
1258 /// \brief Determines whether this declaration represents the
1259 /// injected class name.
1261 /// The injected class name in C++ is the name of the class that
1262 /// appears inside the class itself. For example:
1266 /// // C is implicitly declared here as a synonym for the class name.
1269 /// C::C c; // same as "C c;"
1271 bool isInjectedClassName() const;
1273 /// getDefinition - Returns the RecordDecl that actually defines this
1274 /// struct/union/class. When determining whether or not a struct/union/class
1275 /// is completely defined, one should use this method as opposed to
1276 /// 'isDefinition'. 'isDefinition' indicates whether or not a specific
1277 /// RecordDecl is defining declaration, not whether or not the record
1278 /// type is defined. This method returns NULL if there is no RecordDecl
1279 /// that defines the struct/union/tag.
1280 RecordDecl* getDefinition(ASTContext& C) const {
1281 return cast_or_null<RecordDecl>(TagDecl::getDefinition(C));
1284 // Iterator access to field members. The field iterator only visits
1285 // the non-static data members of this class, ignoring any static
1286 // data members, functions, constructors, destructors, etc.
1287 typedef specific_decl_iterator<FieldDecl> field_iterator;
1289 field_iterator field_begin(ASTContext &Context) const {
1290 return field_iterator(decls_begin(Context));
1292 field_iterator field_end(ASTContext &Context) const {
1293 return field_iterator(decls_end(Context));
1296 // field_empty - Whether there are any fields (non-static data
1297 // members) in this record.
1298 bool field_empty(ASTContext &Context) const {
1299 return field_begin(Context) == field_end(Context);
1302 /// completeDefinition - Notes that the definition of this type is
1304 void completeDefinition(ASTContext& C);
1306 static bool classof(const Decl *D) {
1307 return D->getKind() >= RecordFirst && D->getKind() <= RecordLast;
1309 static bool classof(const RecordDecl *D) { return true; }
1312 class FileScopeAsmDecl : public Decl {
1313 StringLiteral *AsmString;
1314 FileScopeAsmDecl(DeclContext *DC, SourceLocation L, StringLiteral *asmstring)
1315 : Decl(FileScopeAsm, DC, L), AsmString(asmstring) {}
1317 static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
1318 SourceLocation L, StringLiteral *Str);
1320 const StringLiteral *getAsmString() const { return AsmString; }
1321 StringLiteral *getAsmString() { return AsmString; }
1322 void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
1324 static bool classof(const Decl *D) {
1325 return D->getKind() == FileScopeAsm;
1327 static bool classof(const FileScopeAsmDecl *D) { return true; }
1330 /// BlockDecl - This represents a block literal declaration, which is like an
1331 /// unnamed FunctionDecl. For example:
1332 /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
1334 class BlockDecl : public Decl, public DeclContext {
1335 // FIXME: This can be packed into the bitfields in Decl.
1336 bool isVariadic : 1;
1337 /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal
1338 /// parameters of this function. This is null if a prototype or if there are
1340 ParmVarDecl **ParamInfo;
1346 BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
1347 : Decl(Block, DC, CaretLoc), DeclContext(Block),
1348 isVariadic(false), ParamInfo(0), NumParams(0), Body(0) {}
1350 virtual ~BlockDecl();
1351 virtual void Destroy(ASTContext& C);
1354 static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
1356 SourceLocation getCaretLocation() const { return getLocation(); }
1358 bool IsVariadic() const { return isVariadic; }
1359 void setIsVariadic(bool value) { isVariadic = value; }
1361 CompoundStmt *getBody() const { return (CompoundStmt*) Body; }
1362 Stmt *getBody(ASTContext &C) const { return (Stmt*) Body; }
1363 void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
1365 // Iterator access to formal parameters.
1366 unsigned param_size() const { return getNumParams(); }
1367 typedef ParmVarDecl **param_iterator;
1368 typedef ParmVarDecl * const *param_const_iterator;
1370 bool param_empty() const { return NumParams == 0; }
1371 param_iterator param_begin() { return ParamInfo; }
1372 param_iterator param_end() { return ParamInfo+param_size(); }
1374 param_const_iterator param_begin() const { return ParamInfo; }
1375 param_const_iterator param_end() const { return ParamInfo+param_size(); }
1377 unsigned getNumParams() const;
1378 const ParmVarDecl *getParamDecl(unsigned i) const {
1379 assert(i < getNumParams() && "Illegal param #");
1380 return ParamInfo[i];
1382 ParmVarDecl *getParamDecl(unsigned i) {
1383 assert(i < getNumParams() && "Illegal param #");
1384 return ParamInfo[i];
1386 void setParams(ASTContext& C, ParmVarDecl **NewParamInfo, unsigned NumParams);
1388 // Implement isa/cast/dyncast/etc.
1389 static bool classof(const Decl *D) { return D->getKind() == Block; }
1390 static bool classof(const BlockDecl *D) { return true; }
1391 static DeclContext *castToDeclContext(const BlockDecl *D) {
1392 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
1394 static BlockDecl *castFromDeclContext(const DeclContext *DC) {
1395 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
1399 /// Insertion operator for diagnostics. This allows sending NamedDecl's
1400 /// into a diagnostic with <<.
1401 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1403 DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), Diagnostic::ak_nameddecl);
1407 } // end namespace clang