blob: c319191bae6a30cb6da57f83f95913baddb860ab [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
29CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, Kind DK, DeclContext *DC,
30 SourceLocation L, IdentifierInfo *Id,
31 ScopedDecl *PrevDecl) {
32 void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
33 return new (Mem) CXXRecordDecl(DK, DC, L, Id, PrevDecl);
34}
35
36CXXMethodDecl *
37CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
38 SourceLocation L, IdentifierInfo *Id,
39 QualType T, bool isStatic, bool isInline,
40 ScopedDecl *PrevDecl) {
41 void *Mem = C.getAllocator().Allocate<CXXMethodDecl>();
42 return new (Mem) CXXMethodDecl(RD, L, Id, T, isStatic, isInline, PrevDecl);
43}
44
45QualType CXXMethodDecl::getThisType(ASTContext &C) const {
46 assert(isInstance() && "No 'this' for static methods!");
47 QualType ClassTy = C.getTagDeclType(cast<CXXRecordDecl>(getParent()));
48 QualType ThisTy = C.getPointerType(ClassTy);
49 ThisTy.addConst();
50 return ThisTy;
51}
52
53CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD,
54 SourceLocation L, IdentifierInfo *Id,
55 QualType T, ScopedDecl *PrevDecl) {
56 void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>();
57 return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl);
58}