blob: b62ca58d72d3a93821fa287862fd3e2fbe0781b7 [file] [log] [blame]
Argiris Kirtzidis6df1fc02008-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
Argiris Kirtzidisc6cc7d52008-06-09 23:19:58 +000029CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
Argiris Kirtzidis6df1fc02008-06-09 21:05:31 +000030 SourceLocation L, IdentifierInfo *Id,
31 ScopedDecl *PrevDecl) {
Argiris Kirtzidisc6cc7d52008-06-09 23:19:58 +000032 Kind DK;
33 switch (TK) {
34 case TK_enum: assert(0 && "Enum TagKind passed for Record!");
35 case TK_struct: DK = Struct; break;
36 case TK_union: DK = Union; break;
37 case TK_class: DK = Class; break;
38 }
Argiris Kirtzidis6df1fc02008-06-09 21:05:31 +000039 void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
40 return new (Mem) CXXRecordDecl(DK, DC, L, Id, PrevDecl);
41}
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}