2006-10-16 06:34:45 +08:00
|
|
|
//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-10-16 06:34:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-06-04 21:04:04 +08:00
|
|
|
// This file implements the Decl subclasses.
|
2006-10-16 06:34:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Decl.h"
|
2008-03-15 14:12:44 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2008-08-11 12:54:23 +08:00
|
|
|
#include "clang/AST/Stmt.h"
|
2008-12-18 07:39:55 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2008-08-11 12:54:23 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2008-05-20 08:43:19 +08:00
|
|
|
|
2006-10-25 13:11:20 +08:00
|
|
|
using namespace clang;
|
2006-10-16 06:34:45 +08:00
|
|
|
|
2008-03-15 14:12:44 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Decl Allocation/Deallocation Method Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-04-27 21:50:30 +08:00
|
|
|
|
2008-04-17 22:40:12 +08:00
|
|
|
TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
|
|
|
|
void *Mem = C.getAllocator().Allocate<TranslationUnitDecl>();
|
|
|
|
return new (Mem) TranslationUnitDecl();
|
|
|
|
}
|
|
|
|
|
2008-04-27 21:50:30 +08:00
|
|
|
NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L, IdentifierInfo *Id) {
|
|
|
|
void *Mem = C.getAllocator().Allocate<NamespaceDecl>();
|
|
|
|
return new (Mem) NamespaceDecl(DC, L, Id);
|
|
|
|
}
|
|
|
|
|
2008-05-20 12:49:55 +08:00
|
|
|
void NamespaceDecl::Destroy(ASTContext& C) {
|
|
|
|
// NamespaceDecl uses "NextDeclarator" to chain namespace declarations
|
|
|
|
// together. They are all top-level Decls.
|
|
|
|
|
2008-05-24 23:09:56 +08:00
|
|
|
this->~NamespaceDecl();
|
2008-05-20 12:49:55 +08:00
|
|
|
C.getAllocator().Deallocate((void *)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-18 02:05:57 +08:00
|
|
|
ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl) {
|
|
|
|
void *Mem = C.getAllocator().Allocate<ImplicitParamDecl>();
|
|
|
|
return new (Mem) ImplicitParamDecl(ImplicitParam, DC, L, Id, T, PrevDecl);
|
|
|
|
}
|
|
|
|
|
2008-04-23 02:39:57 +08:00
|
|
|
ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 14:12:32 +08:00
|
|
|
SourceLocation L, IdentifierInfo *Id,
|
|
|
|
QualType T, StorageClass S,
|
2008-04-08 12:40:51 +08:00
|
|
|
Expr *DefArg, ScopedDecl *PrevDecl) {
|
2008-03-16 05:10:16 +08:00
|
|
|
void *Mem = C.getAllocator().Allocate<ParmVarDecl>();
|
2008-12-21 07:29:59 +08:00
|
|
|
return new (Mem) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg, PrevDecl);
|
|
|
|
}
|
|
|
|
|
|
|
|
QualType ParmVarDecl::getOriginalType() const {
|
|
|
|
if (const ParmVarWithOriginalTypeDecl *PVD =
|
|
|
|
dyn_cast<ParmVarWithOriginalTypeDecl>(this))
|
|
|
|
return PVD->OriginalType;
|
|
|
|
return getType();
|
2008-03-16 05:10:16 +08:00
|
|
|
}
|
|
|
|
|
2008-12-21 04:56:12 +08:00
|
|
|
ParmVarWithOriginalTypeDecl *ParmVarWithOriginalTypeDecl::Create(
|
|
|
|
ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L, IdentifierInfo *Id,
|
|
|
|
QualType T, QualType OT, StorageClass S,
|
|
|
|
Expr *DefArg, ScopedDecl *PrevDecl) {
|
|
|
|
void *Mem = C.getAllocator().Allocate<ParmVarWithOriginalTypeDecl>();
|
|
|
|
return new (Mem) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S,
|
|
|
|
DefArg, PrevDecl);
|
|
|
|
}
|
|
|
|
|
2008-04-23 02:39:57 +08:00
|
|
|
FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 14:12:32 +08:00
|
|
|
SourceLocation L,
|
2008-11-18 06:58:34 +08:00
|
|
|
DeclarationName N, QualType T,
|
2008-03-16 05:24:04 +08:00
|
|
|
StorageClass S, bool isInline,
|
2008-10-03 08:02:03 +08:00
|
|
|
ScopedDecl *PrevDecl,
|
|
|
|
SourceLocation TypeSpecStartLoc) {
|
2008-03-16 05:24:04 +08:00
|
|
|
void *Mem = C.getAllocator().Allocate<FunctionDecl>();
|
2008-11-18 06:58:34 +08:00
|
|
|
return new (Mem) FunctionDecl(Function, DC, L, N, T, S, isInline, PrevDecl,
|
2008-10-03 08:02:03 +08:00
|
|
|
TypeSpecStartLoc);
|
2008-03-16 05:24:04 +08:00
|
|
|
}
|
|
|
|
|
2008-10-10 09:28:17 +08:00
|
|
|
BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
|
2008-10-09 01:01:13 +08:00
|
|
|
void *Mem = C.getAllocator().Allocate<BlockDecl>();
|
2008-10-10 09:28:17 +08:00
|
|
|
return new (Mem) BlockDecl(DC, L);
|
2008-10-09 01:01:13 +08:00
|
|
|
}
|
|
|
|
|
2008-12-12 00:49:14 +08:00
|
|
|
FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
|
|
|
|
IdentifierInfo *Id, QualType T, Expr *BW,
|
|
|
|
bool Mutable, ScopedDecl *PrevDecl) {
|
2008-03-16 08:16:02 +08:00
|
|
|
void *Mem = C.getAllocator().Allocate<FieldDecl>();
|
2008-12-12 00:49:14 +08:00
|
|
|
return new (Mem) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable, PrevDecl);
|
2008-03-16 08:16:02 +08:00
|
|
|
}
|
|
|
|
|
2008-03-16 05:24:04 +08:00
|
|
|
|
2008-04-04 14:12:32 +08:00
|
|
|
EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
|
|
|
|
SourceLocation L,
|
2008-03-16 05:32:50 +08:00
|
|
|
IdentifierInfo *Id, QualType T,
|
|
|
|
Expr *E, const llvm::APSInt &V,
|
|
|
|
ScopedDecl *PrevDecl){
|
2008-03-15 14:12:44 +08:00
|
|
|
void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
|
2008-04-04 14:12:32 +08:00
|
|
|
return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V, PrevDecl);
|
2008-03-15 14:12:44 +08:00
|
|
|
}
|
|
|
|
|
2008-05-20 12:49:55 +08:00
|
|
|
void EnumConstantDecl::Destroy(ASTContext& C) {
|
|
|
|
if (Init) Init->Destroy(C);
|
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2008-04-23 02:39:57 +08:00
|
|
|
TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 14:12:32 +08:00
|
|
|
SourceLocation L,
|
2008-03-16 05:32:50 +08:00
|
|
|
IdentifierInfo *Id, QualType T,
|
|
|
|
ScopedDecl *PD) {
|
2008-03-15 14:12:44 +08:00
|
|
|
void *Mem = C.getAllocator().Allocate<TypedefDecl>();
|
2008-04-23 02:39:57 +08:00
|
|
|
return new (Mem) TypedefDecl(DC, L, Id, T, PD);
|
2008-03-15 14:12:44 +08:00
|
|
|
}
|
|
|
|
|
2008-04-23 02:39:57 +08:00
|
|
|
EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
|
2008-04-04 14:12:32 +08:00
|
|
|
IdentifierInfo *Id,
|
2008-12-16 00:32:14 +08:00
|
|
|
EnumDecl *PrevDecl) {
|
2008-03-15 14:12:44 +08:00
|
|
|
void *Mem = C.getAllocator().Allocate<EnumDecl>();
|
2008-12-16 00:32:14 +08:00
|
|
|
EnumDecl *Enum = new (Mem) EnumDecl(DC, L, Id, 0);
|
|
|
|
C.getTypeDeclType(Enum, PrevDecl);
|
|
|
|
return Enum;
|
2008-03-15 14:12:44 +08:00
|
|
|
}
|
|
|
|
|
2008-09-03 04:13:32 +08:00
|
|
|
void EnumDecl::Destroy(ASTContext& C) {
|
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2008-12-12 00:49:14 +08:00
|
|
|
void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) {
|
|
|
|
assert(!isDefinition() && "Cannot redefine enums!");
|
|
|
|
setDefinition(true);
|
|
|
|
|
|
|
|
IntegerType = NewType;
|
|
|
|
|
|
|
|
// Let ASTContext know that this is the defining EnumDecl for this
|
|
|
|
// type.
|
|
|
|
C.setTagDefinition(this);
|
|
|
|
}
|
|
|
|
|
2008-04-04 14:12:32 +08:00
|
|
|
FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C,
|
|
|
|
SourceLocation L,
|
2008-03-16 08:16:02 +08:00
|
|
|
StringLiteral *Str) {
|
|
|
|
void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>();
|
|
|
|
return new (Mem) FileScopeAsmDecl(L, Str);
|
|
|
|
}
|
|
|
|
|
2008-03-31 08:36:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-10 07:41:00 +08:00
|
|
|
// ScopedDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void ScopedDecl::setLexicalDeclContext(DeclContext *DC) {
|
|
|
|
if (DC == getLexicalDeclContext())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isInSemaDC()) {
|
|
|
|
MultipleDC *MDC = new MultipleDC();
|
|
|
|
MDC->SemanticDC = getDeclContext();
|
|
|
|
MDC->LexicalDC = DC;
|
|
|
|
DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
|
|
|
|
} else {
|
|
|
|
getMultipleDC()->LexicalDC = DC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedDecl::~ScopedDecl() {
|
|
|
|
if (isOutOfSemaDC())
|
|
|
|
delete getMultipleDC();
|
|
|
|
}
|
|
|
|
|
2008-12-24 05:05:05 +08:00
|
|
|
bool ScopedDecl::declarationReplaces(NamedDecl *OldD) const {
|
|
|
|
assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");
|
|
|
|
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this))
|
|
|
|
// For function declarations, we keep track of redeclarations.
|
|
|
|
return FD->getPreviousDeclaration() == OldD;
|
|
|
|
|
|
|
|
// For non-function declarations, if the declarations are of the
|
|
|
|
// same kind then this must be a redeclaration, or semantic analysis
|
|
|
|
// would not have given us the new declaration.
|
|
|
|
return this->getKind() == OldD->getKind();
|
|
|
|
}
|
|
|
|
|
2008-12-18 07:39:55 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VarDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
IdentifierInfo *Id, QualType T,
|
|
|
|
StorageClass S, ScopedDecl *PrevDecl,
|
|
|
|
SourceLocation TypeSpecStartLoc) {
|
|
|
|
void *Mem = C.getAllocator().Allocate<VarDecl>();
|
|
|
|
return new (Mem) VarDecl(Var, DC, L, Id, T, S, PrevDecl, TypeSpecStartLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarDecl::Destroy(ASTContext& C) {
|
|
|
|
this->~VarDecl();
|
|
|
|
C.getAllocator().Deallocate((void *)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl::~VarDecl() {
|
|
|
|
delete getInit();
|
|
|
|
}
|
|
|
|
|
2008-11-10 07:41:00 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-03-31 08:36:02 +08:00
|
|
|
// FunctionDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-01-21 15:42:07 +08:00
|
|
|
FunctionDecl::~FunctionDecl() {
|
|
|
|
delete[] ParamInfo;
|
2008-04-21 10:02:58 +08:00
|
|
|
}
|
|
|
|
|
2008-05-20 08:43:19 +08:00
|
|
|
void FunctionDecl::Destroy(ASTContext& C) {
|
2008-05-20 11:56:00 +08:00
|
|
|
if (Body)
|
|
|
|
Body->Destroy(C);
|
|
|
|
|
|
|
|
for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
|
|
|
|
(*I)->Destroy(C);
|
|
|
|
|
2008-05-20 08:43:19 +08:00
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-21 10:02:58 +08:00
|
|
|
Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
|
|
|
|
for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
|
|
|
|
if (FD->Body) {
|
|
|
|
Definition = FD;
|
|
|
|
return FD->Body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-01-21 15:42:07 +08:00
|
|
|
}
|
|
|
|
|
2008-10-30 02:41:34 +08:00
|
|
|
// Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams()
|
|
|
|
static unsigned getNumTypeParams(QualType T) {
|
|
|
|
const FunctionType *FT = T->getAsFunctionType();
|
2008-04-07 07:09:52 +08:00
|
|
|
if (isa<FunctionTypeNoProto>(FT))
|
2008-03-15 13:43:15 +08:00
|
|
|
return 0;
|
2008-04-07 07:09:52 +08:00
|
|
|
return cast<FunctionTypeProto>(FT)->getNumArgs();
|
2007-01-21 15:42:07 +08:00
|
|
|
}
|
|
|
|
|
2008-10-30 02:41:34 +08:00
|
|
|
unsigned FunctionDecl::getNumParams() const {
|
|
|
|
// Can happen if a FunctionDecl is declared using typeof(some_other_func) bar;
|
|
|
|
if (!ParamInfo)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return getNumTypeParams(getType());
|
|
|
|
}
|
|
|
|
|
2007-06-14 04:44:40 +08:00
|
|
|
void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) {
|
2007-01-21 15:42:07 +08:00
|
|
|
assert(ParamInfo == 0 && "Already has param info!");
|
2008-10-30 02:41:34 +08:00
|
|
|
assert(NumParams == getNumTypeParams(getType()) &&
|
|
|
|
"Parameter count mismatch!");
|
2007-01-21 15:42:07 +08:00
|
|
|
|
2007-01-22 03:04:10 +08:00
|
|
|
// Zero params -> null pointer.
|
|
|
|
if (NumParams) {
|
2007-06-14 04:44:40 +08:00
|
|
|
ParamInfo = new ParmVarDecl*[NumParams];
|
|
|
|
memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
|
2007-01-22 03:04:10 +08:00
|
|
|
}
|
2007-01-21 15:42:07 +08:00
|
|
|
}
|
2007-01-25 12:52:46 +08:00
|
|
|
|
2008-04-10 10:22:51 +08:00
|
|
|
/// getMinRequiredArguments - Returns the minimum number of arguments
|
|
|
|
/// needed to call this function. This may be fewer than the number of
|
|
|
|
/// function parameters, if some of the parameters have default
|
2008-04-13 07:52:44 +08:00
|
|
|
/// arguments (in C++).
|
2008-04-10 10:22:51 +08:00
|
|
|
unsigned FunctionDecl::getMinRequiredArguments() const {
|
|
|
|
unsigned NumRequiredArgs = getNumParams();
|
|
|
|
while (NumRequiredArgs > 0
|
|
|
|
&& getParamDecl(NumRequiredArgs-1)->getDefaultArg())
|
|
|
|
--NumRequiredArgs;
|
|
|
|
|
|
|
|
return NumRequiredArgs;
|
|
|
|
}
|
|
|
|
|
2008-11-07 06:13:31 +08:00
|
|
|
/// getOverloadedOperator - Which C++ overloaded operator this
|
|
|
|
/// function represents, if any.
|
|
|
|
OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const {
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName)
|
|
|
|
return getDeclName().getCXXOverloadedOperator();
|
2008-11-07 06:13:31 +08:00
|
|
|
else
|
|
|
|
return OO_None;
|
|
|
|
}
|
|
|
|
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-06 01:16:31 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TagdDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
TagDecl* TagDecl::getDefinition(ASTContext& C) const {
|
|
|
|
QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this));
|
|
|
|
TagDecl* D = cast<TagDecl>(cast<TagType>(T)->getDecl());
|
|
|
|
return D->isDefinition() ? D : 0;
|
|
|
|
}
|
|
|
|
|
2008-03-31 08:36:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// RecordDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-01-25 12:52:46 +08:00
|
|
|
|
2008-10-15 08:42:39 +08:00
|
|
|
RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
|
2008-09-05 09:34:33 +08:00
|
|
|
IdentifierInfo *Id)
|
2008-12-12 00:49:14 +08:00
|
|
|
: TagDecl(DK, TK, DC, L, Id, 0), DeclContext(DK) {
|
2008-09-03 05:12:32 +08:00
|
|
|
|
|
|
|
HasFlexibleArrayMember = false;
|
|
|
|
assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-06 01:16:31 +08:00
|
|
|
SourceLocation L, IdentifierInfo *Id,
|
|
|
|
RecordDecl* PrevDecl) {
|
2008-09-05 09:34:33 +08:00
|
|
|
|
2008-09-03 05:12:32 +08:00
|
|
|
void *Mem = C.getAllocator().Allocate<RecordDecl>();
|
2008-10-15 08:42:39 +08:00
|
|
|
RecordDecl* R = new (Mem) RecordDecl(Record, TK, DC, L, Id);
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-06 01:16:31 +08:00
|
|
|
C.getTypeDeclType(R, PrevDecl);
|
|
|
|
return R;
|
2008-09-03 05:12:32 +08:00
|
|
|
}
|
|
|
|
|
2008-08-08 22:08:55 +08:00
|
|
|
RecordDecl::~RecordDecl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordDecl::Destroy(ASTContext& C) {
|
2008-12-12 00:49:14 +08:00
|
|
|
DeclContext::DestroyDecls(C);
|
2008-08-08 22:08:55 +08:00
|
|
|
TagDecl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2008-12-12 00:49:14 +08:00
|
|
|
/// completeDefinition - Notes that the definition of this type is now
|
|
|
|
/// complete.
|
|
|
|
void RecordDecl::completeDefinition(ASTContext& C) {
|
2007-01-25 12:52:46 +08:00
|
|
|
assert(!isDefinition() && "Cannot redefine record!");
|
2008-12-12 00:49:14 +08:00
|
|
|
|
2007-01-25 12:52:46 +08:00
|
|
|
setDefinition(true);
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-06 01:16:31 +08:00
|
|
|
|
2008-12-12 00:49:14 +08:00
|
|
|
// Let ASTContext know that this is the defining RecordDecl for this
|
|
|
|
// type.
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-06 01:16:31 +08:00
|
|
|
C.setTagDefinition(this);
|
2007-01-25 12:52:46 +08:00
|
|
|
}
|
2007-03-27 07:09:51 +08:00
|
|
|
|
2008-10-09 01:01:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BlockDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
BlockDecl::~BlockDecl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockDecl::Destroy(ASTContext& C) {
|
|
|
|
if (Body)
|
|
|
|
Body->Destroy(C);
|
|
|
|
|
|
|
|
for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
|
|
|
|
(*I)->Destroy(C);
|
|
|
|
|
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|