blob: 9fd7ff974e91f41c773b886ebf9817888e0d9b48 [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
29CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
30 SourceLocation L, IdentifierInfo *Id,
31 CXXRecordDecl* PrevDecl) {
Ted Kremenek4b7c9832008-09-05 17:16:31 +000032 void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +000033 CXXRecordDecl* R = new (Mem) CXXRecordDecl(TK, DC, L, Id);
Ted Kremenek4b7c9832008-09-05 17:16:31 +000034 C.getTypeDeclType(R, PrevDecl);
35 return R;
36}
37
38CXXMethodDecl *
39CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
40 SourceLocation L, IdentifierInfo *Id,
41 QualType T, bool isStatic, bool isInline,
42 ScopedDecl *PrevDecl) {
43 void *Mem = C.getAllocator().Allocate<CXXMethodDecl>();
44 return new (Mem) CXXMethodDecl(RD, L, Id, T, isStatic, isInline, PrevDecl);
45}
46
47QualType CXXMethodDecl::getThisType(ASTContext &C) const {
48 assert(isInstance() && "No 'this' for static methods!");
Argyrios Kyrtzidisd2595ec2008-10-12 18:40:01 +000049 QualType ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>(
50 cast<CXXRecordDecl>(getParent())));
Ted Kremenek4b7c9832008-09-05 17:16:31 +000051 QualType ThisTy = C.getPointerType(ClassTy);
52 ThisTy.addConst();
53 return ThisTy;
54}
55
56CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD,
57 SourceLocation L, IdentifierInfo *Id,
58 QualType T, ScopedDecl *PrevDecl) {
59 void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>();
60 return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl);
61}
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000062
63OverloadedFunctionDecl *
64OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC,
65 IdentifierInfo *Id) {
66 void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>();
67 return new (Mem) OverloadedFunctionDecl(DC, Id);
68}