Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1 | //===--- DeclCXX.cpp - C++ Declaration AST Node Implementation ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the C++ related Decl classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclCXX.h" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | using namespace clang; |
| 17 | |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | // Decl Allocation/Deallocation Method Implementations |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | CXXFieldDecl *CXXFieldDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
| 23 | SourceLocation L, IdentifierInfo *Id, |
| 24 | QualType T, Expr *BW) { |
| 25 | void *Mem = C.getAllocator().Allocate<CXXFieldDecl>(); |
| 26 | return new (Mem) CXXFieldDecl(RD, L, Id, T, BW); |
| 27 | } |
| 28 | |
| 29 | CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
| 30 | SourceLocation L, IdentifierInfo *Id, |
| 31 | CXXRecordDecl* PrevDecl) { |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 32 | void *Mem = C.getAllocator().Allocate<CXXRecordDecl>(); |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 33 | CXXRecordDecl* R = new (Mem) CXXRecordDecl(TK, DC, L, Id); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 34 | C.getTypeDeclType(R, PrevDecl); |
| 35 | return R; |
| 36 | } |
| 37 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 38 | CXXRecordDecl::~CXXRecordDecl() { |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 39 | delete [] Bases; |
| 40 | } |
| 41 | |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 42 | void |
| 43 | CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, |
| 44 | unsigned NumBases) { |
| 45 | if (this->Bases) |
| 46 | delete [] this->Bases; |
| 47 | |
| 48 | this->Bases = new CXXBaseSpecifier[NumBases]; |
| 49 | this->NumBases = NumBases; |
| 50 | for (unsigned i = 0; i < NumBases; ++i) |
| 51 | this->Bases[i] = *Bases[i]; |
| 52 | } |
| 53 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 54 | CXXMethodDecl * |
| 55 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
| 56 | SourceLocation L, IdentifierInfo *Id, |
| 57 | QualType T, bool isStatic, bool isInline, |
| 58 | ScopedDecl *PrevDecl) { |
| 59 | void *Mem = C.getAllocator().Allocate<CXXMethodDecl>(); |
| 60 | return new (Mem) CXXMethodDecl(RD, L, Id, T, isStatic, isInline, PrevDecl); |
| 61 | } |
| 62 | |
| 63 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
| 64 | assert(isInstance() && "No 'this' for static methods!"); |
Argyrios Kyrtzidis | d2595ec | 2008-10-12 18:40:01 +0000 | [diff] [blame] | 65 | QualType ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>( |
| 66 | cast<CXXRecordDecl>(getParent()))); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame^] | 67 | ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers()); |
| 68 | return C.getPointerType(ClassTy).withConst(); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
| 72 | SourceLocation L, IdentifierInfo *Id, |
| 73 | QualType T, ScopedDecl *PrevDecl) { |
| 74 | void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>(); |
| 75 | return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl); |
| 76 | } |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 77 | |
| 78 | OverloadedFunctionDecl * |
| 79 | OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, |
| 80 | IdentifierInfo *Id) { |
| 81 | void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>(); |
| 82 | return new (Mem) OverloadedFunctionDecl(DC, Id); |
| 83 | } |