Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05: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 |
|
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 29 | CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
|
Ted Kremenek | df042e6 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 30 | SourceLocation L, IdentifierInfo *Id) {
|
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 31 | Kind DK;
|
| 32 | switch (TK) {
|
Ted Kremenek | 94cbb3e | 2008-06-16 23:46:27 +0000 | [diff] [blame] | 33 | default: assert(0 && "Invalid TagKind!");
|
| 34 | case TK_enum: assert(0 && "Enum TagKind passed for Record!");
|
| 35 | case TK_struct: DK = CXXStruct; break;
|
| 36 | case TK_union: DK = CXXUnion; break;
|
| 37 | case TK_class: DK = CXXClass; break;
|
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 38 | }
|
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 39 | void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
|
Ted Kremenek | df042e6 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 40 | return new (Mem) CXXRecordDecl(DK, DC, L, Id);
|
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 41 | }
|
| 42 |
|
| 43 | CXXMethodDecl *
|
| 44 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
|
| 45 | SourceLocation L, IdentifierInfo *Id,
|
| 46 | QualType T, bool isStatic, bool isInline,
|
| 47 | ScopedDecl *PrevDecl) {
|
| 48 | void *Mem = C.getAllocator().Allocate<CXXMethodDecl>();
|
| 49 | return new (Mem) CXXMethodDecl(RD, L, Id, T, isStatic, isInline, PrevDecl);
|
| 50 | }
|
| 51 |
|
| 52 | QualType CXXMethodDecl::getThisType(ASTContext &C) const {
|
| 53 | assert(isInstance() && "No 'this' for static methods!");
|
| 54 | QualType ClassTy = C.getTagDeclType(cast<CXXRecordDecl>(getParent()));
|
| 55 | QualType ThisTy = C.getPointerType(ClassTy);
|
| 56 | ThisTy.addConst();
|
| 57 | return ThisTy;
|
| 58 | }
|
| 59 |
|
| 60 | CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD,
|
| 61 | SourceLocation L, IdentifierInfo *Id,
|
| 62 | QualType T, ScopedDecl *PrevDecl) {
|
| 63 | void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>();
|
| 64 | return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl);
|
| 65 | }
|