blob: 0cce7db1d687c6b2575a1477651f93a951e5f2d8 [file] [log] [blame]
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05: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
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +000029CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
Ted Kremenekdf042e62008-09-05 01:34:33 +000030 SourceLocation L, IdentifierInfo *Id) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +000031 Kind DK;
32 switch (TK) {
Ted Kremenek94cbb3e2008-06-16 23:46:27 +000033 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 Kyrtzidis39ba4ae2008-06-09 23:19:58 +000038 }
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000039 void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
Ted Kremenekdf042e62008-09-05 01:34:33 +000040 return new (Mem) CXXRecordDecl(DK, DC, L, Id);
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000041}
42
43CXXMethodDecl *
44CXXMethodDecl::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
52QualType 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
60CXXClassVarDecl *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}