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 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame^] | 29 | CXXBaseSpecifier *CXXBaseSpecifier::Create(ASTContext &C, SourceRange R, bool V, |
| 30 | bool BC, AccessSpecifier A, QualType T) |
| 31 | { |
| 32 | void *Mem = C.getAllocator().Allocate<CXXBaseSpecifier>(); |
| 33 | CXXBaseSpecifier* BS = new (Mem) CXXBaseSpecifier(R, V, BC, A, T); |
| 34 | return BS; |
| 35 | } |
| 36 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 37 | CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
| 38 | SourceLocation L, IdentifierInfo *Id, |
| 39 | CXXRecordDecl* PrevDecl) { |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 40 | void *Mem = C.getAllocator().Allocate<CXXRecordDecl>(); |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 41 | CXXRecordDecl* R = new (Mem) CXXRecordDecl(TK, DC, L, Id); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 42 | C.getTypeDeclType(R, PrevDecl); |
| 43 | return R; |
| 44 | } |
| 45 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame^] | 46 | CXXRecordDecl::~CXXRecordDecl() { |
| 47 | for (unsigned i = 0; i < NumBases; ++i) |
| 48 | delete Bases[i]; |
| 49 | delete [] Bases; |
| 50 | } |
| 51 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 52 | CXXMethodDecl * |
| 53 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
| 54 | SourceLocation L, IdentifierInfo *Id, |
| 55 | QualType T, bool isStatic, bool isInline, |
| 56 | ScopedDecl *PrevDecl) { |
| 57 | void *Mem = C.getAllocator().Allocate<CXXMethodDecl>(); |
| 58 | return new (Mem) CXXMethodDecl(RD, L, Id, T, isStatic, isInline, PrevDecl); |
| 59 | } |
| 60 | |
| 61 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
| 62 | assert(isInstance() && "No 'this' for static methods!"); |
Argyrios Kyrtzidis | d2595ec | 2008-10-12 18:40:01 +0000 | [diff] [blame] | 63 | QualType ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>( |
| 64 | cast<CXXRecordDecl>(getParent()))); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 65 | QualType ThisTy = C.getPointerType(ClassTy); |
| 66 | ThisTy.addConst(); |
| 67 | return ThisTy; |
| 68 | } |
| 69 | |
| 70 | CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
| 71 | SourceLocation L, IdentifierInfo *Id, |
| 72 | QualType T, ScopedDecl *PrevDecl) { |
| 73 | void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>(); |
| 74 | return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl); |
| 75 | } |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 76 | |
| 77 | OverloadedFunctionDecl * |
| 78 | OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, |
| 79 | IdentifierInfo *Id) { |
| 80 | void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>(); |
| 81 | return new (Mem) OverloadedFunctionDecl(DC, Id); |
| 82 | } |