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 interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_DECL_H
15 #define LLVM_CLANG_AST_DECL_H
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Type.h"
19 #include "clang/Basic/SourceLocation.h"
20 #include "llvm/ADT/APSInt.h"
21 #include "llvm/Bitcode/SerializationFwd.h"
34 /// Decl - This represents one declaration (or definition), e.g. a variable,
35 /// typedef, function, struct, etc.
40 // This lists the concrete classes of Decl in order of the inheritance
41 // hierarchy. This allows us to do efficient classof tests based on the
42 // enums below. The commented out names are abstract class names.
77 // For each non-leaf class, we now define a mapping to the first/last member
78 // of the class, to allow efficient classof.
79 NamedFirst = Field, NamedLast = ParmVar,
80 FieldFirst = Field, FieldLast = ObjCIvar,
81 ScopedFirst = CompatibleAlias, ScopedLast = ParmVar,
82 TypeFirst = ObjCInterface, TypeLast = Class,
83 TagFirst = Enum , TagLast = Class,
84 RecordFirst = Struct , RecordLast = Class,
85 ValueFirst = EnumConstant , ValueLast = ParmVar,
86 VarFirst = BlockVar , VarLast = ParmVar
89 /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces,
90 /// labels, tags, members and ordinary identifiers.
91 enum IdentifierNamespace {
98 /// ObjCDeclQualifier - Qualifier used on types in method declarations
99 /// for remote messaging. They are meant for the arguments though and
100 /// applied to the Decls (ObjCMethodDecl and ParmVarDecl).
101 enum ObjCDeclQualifier {
106 OBJC_TQ_Bycopy = 0x8,
107 OBJC_TQ_Byref = 0x10,
108 OBJC_TQ_Oneway = 0x20
112 /// Loc - The location that this decl.
115 /// DeclKind - This indicates which class this is.
118 /// InvalidDecl - This indicates a semantic error occurred.
119 unsigned int InvalidDecl : 1;
121 /// HasAttrs - This indicates whether the decl has attributes or not.
122 unsigned int HasAttrs : 1;
124 Decl(Kind DK, SourceLocation L) : Loc(L), DeclKind(DK), InvalidDecl(0),
126 if (Decl::CollectingStats()) addDeclKind(DK);
132 SourceLocation getLocation() const { return Loc; }
133 void setLocation(SourceLocation L) { Loc = L; }
135 Kind getKind() const { return DeclKind; }
136 const char *getDeclKindName() const;
138 void addAttr(Attr *attr);
139 const Attr *getAttrs() const;
141 template<typename T> const T *getAttr() const {
142 for (const Attr *attr = getAttrs(); attr; attr = attr->getNext())
143 if (const T *V = dyn_cast<T>(attr))
149 /// setInvalidDecl - Indicates the Decl had a semantic error. This
150 /// allows for graceful error recovery.
151 void setInvalidDecl() { InvalidDecl = 1; }
152 bool isInvalidDecl() const { return (bool) InvalidDecl; }
154 IdentifierNamespace getIdentifierNamespace() const {
156 default: assert(0 && "Unknown decl kind!");
164 case CompatibleAlias:
165 return IDNS_Ordinary;
173 // global temp stats (until we have a per-module visitor)
174 static void addDeclKind(const Kind k);
175 static bool CollectingStats(bool enable=false);
176 static void PrintStats();
178 // Implement isa/cast/dyncast/etc.
179 static bool classof(const Decl *) { return true; }
181 /// Emit - Serialize this Decl to Bitcode.
182 void Emit(llvm::Serializer& S) const;
184 /// Create - Deserialize a Decl from Bitcode.
185 static Decl* Create(llvm::Deserializer& D);
188 /// EmitImpl - Provides the subclass-specific serialization logic for
189 /// serializing out a decl.
190 virtual void EmitImpl(llvm::Serializer& S) const {
191 // FIXME: This will eventually be a pure virtual function.
192 assert (false && "Not implemented.");
195 void EmitInRec(llvm::Serializer& S) const;
196 void ReadInRec(llvm::Deserializer& D);
199 /// NamedDecl - This represents a decl with an identifier for a name. Many
200 /// decls have names, but not ObjCMethodDecl, @class, etc.
201 class NamedDecl : public Decl {
202 /// Identifier - The identifier for this declaration (e.g. the name for the
203 /// variable, the tag for a struct).
204 IdentifierInfo *Identifier;
206 NamedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id)
207 : Decl(DK, L), Identifier(Id) {}
209 IdentifierInfo *getIdentifier() const { return Identifier; }
210 const char *getName() const;
212 static bool classof(const Decl *D) {
213 return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
215 static bool classof(const NamedDecl *D) { return true; }
218 void EmitInRec(llvm::Serializer& S) const;
219 void ReadInRec(llvm::Deserializer& D);
222 /// ScopedDecl - Represent lexically scoped names, used for all ValueDecl's
224 class ScopedDecl : public NamedDecl {
225 /// NextDeclarator - If this decl was part of a multi-declarator declaration,
226 /// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
227 ScopedDecl *NextDeclarator;
229 /// When this decl is in scope while parsing, the Next field contains a
230 /// pointer to the shadowed decl of the same name. When the scope is popped,
231 /// Decls are relinked onto a containing decl object.
236 ScopedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id,ScopedDecl *PrevDecl)
237 : NamedDecl(DK, L, Id), NextDeclarator(PrevDecl), Next(0) {}
240 ScopedDecl *getNext() const { return Next; }
241 void setNext(ScopedDecl *N) { Next = N; }
243 /// getNextDeclarator - If this decl was part of a multi-declarator
244 /// declaration, such as "int X, Y, *Z;" this returns the decl for the next
245 /// declarator. Otherwise it returns null.
246 ScopedDecl *getNextDeclarator() { return NextDeclarator; }
247 const ScopedDecl *getNextDeclarator() const { return NextDeclarator; }
248 void setNextDeclarator(ScopedDecl *N) { NextDeclarator = N; }
250 // Implement isa/cast/dyncast/etc.
251 static bool classof(const Decl *D) {
252 return D->getKind() >= ScopedFirst && D->getKind() <= ScopedLast;
254 static bool classof(const ScopedDecl *D) { return true; }
257 void EmitInRec(llvm::Serializer& S) const;
258 void ReadInRec(llvm::Deserializer& D);
260 void EmitOutRec(llvm::Serializer& S) const;
261 void ReadOutRec(llvm::Deserializer& D);
264 /// ValueDecl - Represent the declaration of a variable (in which case it is
265 /// an lvalue) a function (in which case it is a function designator) or
266 /// an enum constant.
267 class ValueDecl : public ScopedDecl {
271 ValueDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
272 ScopedDecl *PrevDecl)
273 : ScopedDecl(DK, L, Id, PrevDecl), DeclType(T) {}
275 QualType getType() const { return DeclType; }
276 void setType(QualType newType) { DeclType = newType; }
277 QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
279 // Implement isa/cast/dyncast/etc.
280 static bool classof(const Decl *D) {
281 return D->getKind() >= ValueFirst && D->getKind() <= ValueLast;
283 static bool classof(const ValueDecl *D) { return true; }
286 void EmitInRec(llvm::Serializer& S) const;
287 void ReadInRec(llvm::Deserializer& D);
290 /// VarDecl - An instance of this class is created to represent a variable
291 /// declaration or definition.
292 class VarDecl : public ValueDecl {
295 None, Extern, Static, Auto, Register, PrivateExtern
297 StorageClass getStorageClass() const { return (StorageClass)SClass; }
299 const Expr *getInit() const { return Init; }
300 Expr *getInit() { return Init; }
301 void setInit(Expr *I) { Init = I; }
303 /// hasAutoStorage - Returns true if either the implicit or explicit
304 /// storage class of a variable is "auto." In particular, variables
305 /// declared within a function that lack a storage keyword are
306 /// implicitly "auto", but are represented internally with a storage
308 bool hasAutoStorage() const {
309 return getStorageClass() == Auto ||
310 (getStorageClass() == None && getKind() != FileVar);
313 /// hasStaticStorage - Returns true if either the implicit or
314 /// explicit storage class of a variable is "static." In
315 /// particular, variables declared within a file (outside of a
316 /// function) that lack a storage keyword are implicitly "static,"
317 /// but are represented internally with a storage class of "None".
318 bool hasStaticStorage() const {
319 if (getStorageClass() == Static) return true;
320 return getKind() == FileVar;
323 /// hasLocalStorage - Returns true if a variable with function scope
324 /// is a non-static local variable.
325 bool hasLocalStorage() const {
326 return hasAutoStorage() || getStorageClass() == Register;
329 /// hasGlobalStorage - Returns true for all variables that do not
330 /// have local storage. This includs all global variables as well
331 /// as static variables declared within a function.
332 bool hasGlobalStorage() const { return !hasAutoStorage(); }
334 // Implement isa/cast/dyncast/etc.
335 static bool classof(const Decl *D) {
336 return D->getKind() >= VarFirst && D->getKind() <= VarLast;
338 static bool classof(const VarDecl *D) { return true; }
340 VarDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
341 StorageClass SC, ScopedDecl *PrevDecl)
342 : ValueDecl(DK, L, Id, T, PrevDecl), Init(0) { SClass = SC; }
345 // FIXME: This can be packed into the bitfields in Decl.
348 friend class StmtIteratorBase;
351 void EmitInRec(llvm::Serializer& S) const;
352 void ReadInRec(llvm::Deserializer& D);
354 void EmitOutRec(llvm::Serializer& S) const;
355 void ReadOutRec(llvm::Deserializer& D);
357 /// EmitImpl - Serialize this VarDecl. Called by Decl::Emit.
358 virtual void EmitImpl(llvm::Serializer& S) const;
360 /// ReadImpl - Deserialize this VarDecl. Called by subclasses.
361 virtual void ReadImpl(llvm::Deserializer& S);
364 /// BlockVarDecl - Represent a local variable declaration.
365 class BlockVarDecl : public VarDecl {
367 BlockVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
368 ScopedDecl *PrevDecl)
369 : VarDecl(BlockVar, L, Id, T, S, PrevDecl) {}
371 // Implement isa/cast/dyncast/etc.
372 static bool classof(const Decl *D) { return D->getKind() == BlockVar; }
373 static bool classof(const BlockVarDecl *D) { return true; }
376 /// CreateImpl - Deserialize a BlockVarDecl. Called by Decl::Create.
377 static BlockVarDecl* CreateImpl(llvm::Deserializer& D);
379 friend Decl* Decl::Create(llvm::Deserializer& D);
382 /// FileVarDecl - Represent a file scoped variable declaration. This
383 /// will allow us to reason about external variable declarations and tentative
384 /// definitions (C99 6.9.2p2) using our type system (without storing a
385 /// pointer to the decl's scope, which is transient).
386 class FileVarDecl : public VarDecl {
388 FileVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
389 ScopedDecl *PrevDecl)
390 : VarDecl(FileVar, L, Id, T, S, PrevDecl) {}
392 // Implement isa/cast/dyncast/etc.
393 static bool classof(const Decl *D) { return D->getKind() == FileVar; }
394 static bool classof(const FileVarDecl *D) { return true; }
397 /// CreateImpl - Deserialize a FileVarDecl. Called by Decl::Create.
398 static FileVarDecl* CreateImpl(llvm::Deserializer& D);
400 friend Decl* Decl::Create(llvm::Deserializer& D);
403 /// ParmVarDecl - Represent a parameter to a function.
404 class ParmVarDecl : public VarDecl {
406 ParmVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
407 ScopedDecl *PrevDecl)
408 : VarDecl(ParmVar, L, Id, T, S, PrevDecl),
409 objcDeclQualifier(OBJC_TQ_None) {}
411 ObjCDeclQualifier getObjCDeclQualifier() const {
412 return ObjCDeclQualifier(objcDeclQualifier);
414 void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
415 { objcDeclQualifier = QTVal; }
417 // Implement isa/cast/dyncast/etc.
418 static bool classof(const Decl *D) { return D->getKind() == ParmVar; }
419 static bool classof(const ParmVarDecl *D) { return true; }
422 // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
423 /// FIXME: Also can be paced into the bitfields in Decl.
425 unsigned objcDeclQualifier : 6;
428 /// EmitImpl - Serialize this ParmVarDecl. Called by Decl::Emit.
429 virtual void EmitImpl(llvm::Serializer& S) const;
431 /// CreateImpl - Deserialize a ParmVarDecl. Called by Decl::Create.
432 static ParmVarDecl* CreateImpl(llvm::Deserializer& D);
434 friend Decl* Decl::Create(llvm::Deserializer& D);
437 /// FunctionDecl - An instance of this class is created to represent a function
438 /// declaration or definition.
439 class FunctionDecl : public ValueDecl {
442 None, Extern, Static, PrivateExtern
444 FunctionDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
445 StorageClass S = None, bool isInline = false,
446 ScopedDecl *PrevDecl = 0)
447 : ValueDecl(Function, L, Id, T, PrevDecl),
448 ParamInfo(0), Body(0), DeclChain(0), SClass(S), IsInline(isInline) {}
449 virtual ~FunctionDecl();
451 Stmt *getBody() const { return Body; }
452 void setBody(Stmt *B) { Body = B; }
454 ScopedDecl *getDeclChain() const { return DeclChain; }
455 void setDeclChain(ScopedDecl *D) { DeclChain = D; }
457 // Iterator access to formal parameters.
458 unsigned param_size() const { return getNumParams(); }
459 typedef ParmVarDecl **param_iterator;
460 typedef ParmVarDecl * const *param_const_iterator;
461 param_iterator param_begin() { return ParamInfo; }
462 param_iterator param_end() { return ParamInfo+param_size(); }
463 param_const_iterator param_begin() const { return ParamInfo; }
464 param_const_iterator param_end() const { return ParamInfo+param_size(); }
466 unsigned getNumParams() const;
467 const ParmVarDecl *getParamDecl(unsigned i) const {
468 assert(i < getNumParams() && "Illegal param #");
471 ParmVarDecl *getParamDecl(unsigned i) {
472 assert(i < getNumParams() && "Illegal param #");
475 void setParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
477 QualType getResultType() const {
478 return cast<FunctionType>(getType())->getResultType();
480 StorageClass getStorageClass() const { return StorageClass(SClass); }
481 bool isInline() const { return IsInline; }
483 // Implement isa/cast/dyncast/etc.
484 static bool classof(const Decl *D) { return D->getKind() == Function; }
485 static bool classof(const FunctionDecl *D) { return true; }
488 /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
489 /// parameters of this function. This is null if a prototype or if there are
490 /// no formals. TODO: we could allocate this space immediately after the
491 /// FunctionDecl object to save an allocation like FunctionType does.
492 ParmVarDecl **ParamInfo;
494 Stmt *Body; // Null if a prototype.
496 /// DeclChain - Linked list of declarations that are defined inside this
498 ScopedDecl *DeclChain;
500 // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
505 /// EmitImpl - Serialize this FunctionDecl. Called by Decl::Emit.
506 virtual void EmitImpl(llvm::Serializer& S) const;
508 /// CreateImpl - Deserialize a FunctionDecl. Called by Decl::Create.
509 static FunctionDecl* CreateImpl(llvm::Deserializer& D);
511 friend Decl* Decl::Create(llvm::Deserializer& D);
515 /// FieldDecl - An instance of this class is created by Sema::ActOnField to
516 /// represent a member of a struct/union/class.
517 class FieldDecl : public NamedDecl {
521 FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
523 : NamedDecl(Field, L, Id), DeclType(T), BitWidth(BW) {}
524 FieldDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
526 : NamedDecl(DK, L, Id), DeclType(T), BitWidth(BW) {}
528 QualType getType() const { return DeclType; }
529 QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
531 bool isBitField() const { return BitWidth != NULL; }
532 Expr *getBitWidth() const { return BitWidth; }
533 // Implement isa/cast/dyncast/etc.
534 static bool classof(const Decl *D) {
535 return D->getKind() >= FieldFirst && D->getKind() <= FieldLast;
537 static bool classof(const FieldDecl *D) { return true; }
540 /// EmitImpl - Serialize this FieldDecl. Called by Decl::Emit.
541 virtual void EmitImpl(llvm::Serializer& S) const;
543 /// CreateImpl - Deserialize a FieldDecl. Called by Decl::Create.
544 static FieldDecl* CreateImpl(llvm::Deserializer& D);
546 friend Decl* Decl::Create(llvm::Deserializer& D);
549 /// EnumConstantDecl - An instance of this object exists for each enum constant
550 /// that is defined. For example, in "enum X {a,b}", each of a/b are
551 /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
552 /// TagType for the X EnumDecl.
553 class EnumConstantDecl : public ValueDecl {
554 Expr *Init; // an integer constant expression
555 llvm::APSInt Val; // The value.
557 EnumConstantDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E,
558 const llvm::APSInt &V, ScopedDecl *PrevDecl)
559 : ValueDecl(EnumConstant, L, Id, T, PrevDecl), Init(E), Val(V) {}
561 const Expr *getInitExpr() const { return Init; }
562 Expr *getInitExpr() { return Init; }
563 const llvm::APSInt &getInitVal() const { return Val; }
565 void setInitExpr(Expr *E) { Init = E; }
566 void setInitVal(const llvm::APSInt &V) { Val = V; }
568 // Implement isa/cast/dyncast/etc.
569 static bool classof(const Decl *D) { return D->getKind() == EnumConstant; }
570 static bool classof(const EnumConstantDecl *D) { return true; }
572 friend class StmtIteratorBase;
575 /// EmitImpl - Serialize this EnumConstantDecl. Called by Decl::Emit.
576 virtual void EmitImpl(llvm::Serializer& S) const;
578 /// CreateImpl - Deserialize a EnumConstantDecl. Called by Decl::Create.
579 static EnumConstantDecl* CreateImpl(llvm::Deserializer& D);
581 friend Decl* Decl::Create(llvm::Deserializer& D);
585 /// TypeDecl - Represents a declaration of a type.
587 class TypeDecl : public ScopedDecl {
588 /// TypeForDecl - This indicates the Type object that represents this
589 /// TypeDecl. It is a cache maintained by ASTContext::getTypedefType and
590 /// ASTContext::getTagDeclType.
592 friend class ASTContext;
594 TypeDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
595 : ScopedDecl(DK, L, Id, PrevDecl), TypeForDecl(0) {}
597 // Implement isa/cast/dyncast/etc.
598 static bool classof(const Decl *D) {
599 return D->getKind() >= TypeFirst && D->getKind() <= TypeLast;
601 static bool classof(const TypeDecl *D) { return true; }
605 class TypedefDecl : public TypeDecl {
606 /// UnderlyingType - This is the type the typedef is set to.
607 QualType UnderlyingType;
609 TypedefDecl(SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PD)
610 : TypeDecl(Typedef, L, Id, PD), UnderlyingType(T) {}
612 QualType getUnderlyingType() const { return UnderlyingType; }
613 void setUnderlyingType(QualType newType) { UnderlyingType = newType; }
615 // Implement isa/cast/dyncast/etc.
616 static bool classof(const Decl *D) { return D->getKind() == Typedef; }
617 static bool classof(const TypedefDecl *D) { return true; }
620 /// EmitImpl - Serialize this TypedefDecl. Called by Decl::Emit.
621 virtual void EmitImpl(llvm::Serializer& S) const;
623 /// CreateImpl - Deserialize a TypedefDecl. Called by Decl::Create.
624 static TypedefDecl* CreateImpl(llvm::Deserializer& D);
626 friend Decl* Decl::Create(llvm::Deserializer& D);
630 /// TagDecl - Represents the declaration of a struct/union/class/enum.
631 class TagDecl : public TypeDecl {
632 /// IsDefinition - True if this is a definition ("struct foo {};"), false if
633 /// it is a declaration ("struct foo;").
634 bool IsDefinition : 1;
636 TagDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
637 : TypeDecl(DK, L, Id, PrevDecl) {
638 IsDefinition = false;
642 /// isDefinition - Return true if this decl has its body specified.
643 bool isDefinition() const {
647 const char *getKindName() const {
649 default: assert(0 && "Unknown TagDecl!");
650 case Struct: return "struct";
651 case Union: return "union";
652 case Class: return "class";
653 case Enum: return "enum";
657 // Implement isa/cast/dyncast/etc.
658 static bool classof(const Decl *D) {
659 return D->getKind() >= TagFirst && D->getKind() <= TagLast;
661 static bool classof(const TagDecl *D) { return true; }
663 void setDefinition(bool V) { IsDefinition = V; }
666 /// EnumDecl - Represents an enum. As an extension, we allow forward-declared
668 class EnumDecl : public TagDecl {
669 /// ElementList - this is a linked list of EnumConstantDecl's which are linked
670 /// together through their getNextDeclarator pointers.
671 EnumConstantDecl *ElementList;
673 /// IntegerType - This represent the integer type that the enum corresponds
674 /// to for code generation purposes. Note that the enumerator constants may
675 /// have a different type than this does.
676 QualType IntegerType;
678 EnumDecl(SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
679 : TagDecl(Enum, L, Id, PrevDecl) {
681 IntegerType = QualType();
684 /// defineElements - When created, EnumDecl correspond to a forward declared
685 /// enum. This method is used to mark the decl as being defined, with the
686 /// specified list of enums.
687 void defineElements(EnumConstantDecl *ListHead, QualType NewType) {
688 assert(!isDefinition() && "Cannot redefine enums!");
689 ElementList = ListHead;
692 IntegerType = NewType;
695 /// getIntegerType - Return the integer type this enum decl corresponds to.
696 /// This returns a null qualtype for an enum forward definition.
697 QualType getIntegerType() const { return IntegerType; }
699 /// getEnumConstantList - Return the first EnumConstantDecl in the enum.
701 EnumConstantDecl *getEnumConstantList() { return ElementList; }
702 const EnumConstantDecl *getEnumConstantList() const { return ElementList; }
704 static bool classof(const Decl *D) { return D->getKind() == Enum; }
705 static bool classof(const EnumDecl *D) { return true; }
708 /// EmitImpl - Serialize this EnumDecl. Called by Decl::Emit.
709 virtual void EmitImpl(llvm::Serializer& S) const;
711 /// CreateImpl - Deserialize a EnumDecl. Called by Decl::Create.
712 static EnumDecl* CreateImpl(llvm::Deserializer& D);
714 friend Decl* Decl::Create(llvm::Deserializer& D);
718 /// RecordDecl - Represents a struct/union/class. For example:
719 /// struct X; // Forward declaration, no "body".
720 /// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
721 /// This decl will be marked invalid if *any* members are invalid.
723 class RecordDecl : public TagDecl {
724 /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
725 /// array member (e.g. int X[]) or if this union contains a struct that does.
726 /// If so, this cannot be contained in arrays or other structs as a member.
727 bool HasFlexibleArrayMember : 1;
729 /// Members/NumMembers - This is a new[]'d array of pointers to Decls.
730 FieldDecl **Members; // Null if not defined.
731 int NumMembers; // -1 if not defined.
733 RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl*PrevDecl)
734 : TagDecl(DK, L, Id, PrevDecl) {
735 HasFlexibleArrayMember = false;
736 assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
741 bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
742 void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
744 /// getNumMembers - Return the number of members, or -1 if this is a forward
746 int getNumMembers() const { return NumMembers; }
747 const FieldDecl *getMember(unsigned i) const { return Members[i]; }
748 FieldDecl *getMember(unsigned i) { return Members[i]; }
750 /// defineBody - When created, RecordDecl's correspond to a forward declared
751 /// record. This method is used to mark the decl as being defined, with the
752 /// specified contents.
753 void defineBody(FieldDecl **Members, unsigned numMembers);
755 /// getMember - If the member doesn't exist, or there are no members, this
756 /// function will return 0;
757 FieldDecl *getMember(IdentifierInfo *name);
759 static bool classof(const Decl *D) {
760 return D->getKind() >= RecordFirst && D->getKind() <= RecordLast;
762 static bool classof(const RecordDecl *D) { return true; }
765 /// EmitImpl - Serialize this RecordDecl. Called by Decl::Emit.
766 virtual void EmitImpl(llvm::Serializer& S) const;
768 /// CreateImpl - Deserialize a RecordDecl. Called by Decl::Create.
769 static RecordDecl* CreateImpl(Kind DK, llvm::Deserializer& D);
771 friend Decl* Decl::Create(llvm::Deserializer& D);
774 class FileScopeAsmDecl : public Decl {
775 StringLiteral *AsmString;
777 FileScopeAsmDecl(SourceLocation L, StringLiteral *asmstring)
778 : Decl(FileScopeAsm, L), AsmString(asmstring) {}
780 const StringLiteral *getAsmString() const { return AsmString; }
781 StringLiteral *getAsmString() { return AsmString; }
782 static bool classof(const Decl *D) {
783 return D->getKind() == FileScopeAsm;
785 static bool classof(const FileScopeAsmDecl *D) { return true; }
787 /// EmitImpl - Serialize this FileScopeAsmDecl. Called by Decl::Emit.
788 virtual void EmitImpl(llvm::Serializer& S) const;
790 /// CreateImpl - Deserialize a FileScopeAsmDecl. Called by Decl::Create.
791 static FileScopeAsmDecl* CreateImpl(llvm::Deserializer& D);
793 friend Decl* Decl::Create(llvm::Deserializer& D);
796 /// LinkageSpecDecl - This represents a linkage specification. For example:
797 /// extern "C" void foo();
799 class LinkageSpecDecl : public Decl {
801 /// LanguageIDs - Used to represent the language in a linkage
802 /// specification. The values are part of the serialization abi for
803 /// ASTs and cannot be changed without altering that abi. To help
804 /// ensure a stable abi for this, we choose the DW_LANG_ encodings
805 /// from the dwarf standard.
806 enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
807 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
809 /// Language - The language for this linkage specification.
810 LanguageIDs Language;
811 /// D - This is the Decl of the linkage specification.
814 LinkageSpecDecl(SourceLocation L, LanguageIDs lang, Decl *d)
815 : Decl(LinkageSpec, L), Language(lang), D(d) {}
817 LanguageIDs getLanguage() const { return Language; }
818 const Decl *getDecl() const { return D; }
819 Decl *getDecl() { return D; }
821 static bool classof(const Decl *D) {
822 return D->getKind() == LinkageSpec;
824 static bool classof(const LinkageSpecDecl *D) { return true; }
827 void EmitInRec(llvm::Serializer& S) const;
828 void ReadInRec(llvm::Deserializer& D);
831 } // end namespace clang