blob: 86db8532c8f38fa1746a680fdca697156048a158 [file] [log] [blame]
Ted Kremenek4b7c9832008-09-05 17:16:31 +00001//===--- 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"
16using namespace clang;
17
18//===----------------------------------------------------------------------===//
19// Decl Allocation/Deallocation Method Implementations
20//===----------------------------------------------------------------------===//
21
22CXXFieldDecl *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 Gregorf8268ae2008-10-22 17:49:05 +000029CXXBaseSpecifier *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 Kremenek4b7c9832008-09-05 17:16:31 +000037CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
38 SourceLocation L, IdentifierInfo *Id,
39 CXXRecordDecl* PrevDecl) {
Ted Kremenek4b7c9832008-09-05 17:16:31 +000040 void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +000041 CXXRecordDecl* R = new (Mem) CXXRecordDecl(TK, DC, L, Id);
Ted Kremenek4b7c9832008-09-05 17:16:31 +000042 C.getTypeDeclType(R, PrevDecl);
43 return R;
44}
45
Douglas Gregorf8268ae2008-10-22 17:49:05 +000046CXXRecordDecl::~CXXRecordDecl() {
47 for (unsigned i = 0; i < NumBases; ++i)
48 delete Bases[i];
49 delete [] Bases;
50}
51
Ted Kremenek4b7c9832008-09-05 17:16:31 +000052CXXMethodDecl *
53CXXMethodDecl::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
61QualType CXXMethodDecl::getThisType(ASTContext &C) const {
62 assert(isInstance() && "No 'this' for static methods!");
Argyrios Kyrtzidisd2595ec2008-10-12 18:40:01 +000063 QualType ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>(
64 cast<CXXRecordDecl>(getParent())));
Ted Kremenek4b7c9832008-09-05 17:16:31 +000065 QualType ThisTy = C.getPointerType(ClassTy);
66 ThisTy.addConst();
67 return ThisTy;
68}
69
70CXXClassVarDecl *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 Gregor8e9bebd2008-10-21 16:13:35 +000076
77OverloadedFunctionDecl *
78OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC,
79 IdentifierInfo *Id) {
80 void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>();
81 return new (Mem) OverloadedFunctionDecl(DC, Id);
82}