DeclCXX.cpp revision 4b7c98378ae0c1a3635f0b7756848b4a9923f8bc
1//===--- 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) {
32  Kind DK;
33  switch (TK) {
34    default: assert(0 && "Invalid TagKind!");
35    case TK_enum:   assert(0 && "Enum TagKind passed for Record!");
36    case TK_struct: DK = CXXStruct; break;
37    case TK_union:  DK = CXXUnion;  break;
38    case TK_class:  DK = CXXClass;  break;
39  }
40  void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
41  CXXRecordDecl* R = new (Mem) CXXRecordDecl(DK, DC, L, Id);
42  C.getTypeDeclType(R, PrevDecl);
43  return R;
44}
45
46CXXMethodDecl *
47CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
48                      SourceLocation L, IdentifierInfo *Id,
49                      QualType T, bool isStatic, bool isInline,
50                      ScopedDecl *PrevDecl) {
51  void *Mem = C.getAllocator().Allocate<CXXMethodDecl>();
52  return new (Mem) CXXMethodDecl(RD, L, Id, T, isStatic, isInline, PrevDecl);
53}
54
55QualType CXXMethodDecl::getThisType(ASTContext &C) const {
56  assert(isInstance() && "No 'this' for static methods!");
57  QualType ClassTy = C.getTagDeclType(cast<CXXRecordDecl>(getParent()));
58  QualType ThisTy = C.getPointerType(ClassTy);
59  ThisTy.addConst();
60  return ThisTy;
61}
62
63CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD,
64                                   SourceLocation L, IdentifierInfo *Id,
65                                   QualType T, ScopedDecl *PrevDecl) {
66  void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>();
67  return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl);
68}
69