Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 1 | //===--- DeclGroup.cpp - Classes for representing groups of Decls -*- C++ -*-==// |
| 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 | // |
Douglas Gregor | 9653db7 | 2009-02-13 19:06:18 +0000 | [diff] [blame] | 10 | // This file defines the DeclGroup and DeclGroupRef classes. |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclGroup.h" |
| 15 | #include "clang/AST/Decl.h" |
| 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "llvm/Support/Allocator.h" |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 20 | DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) { |
| 21 | assert(NumDecls > 1 && "Invalid DeclGroup"); |
| 22 | unsigned Size = sizeof(DeclGroup) + sizeof(Decl*) * NumDecls; |
| 23 | void* Mem = C.Allocate(Size, llvm::AlignOf<DeclGroup>::Alignment); |
| 24 | new (Mem) DeclGroup(NumDecls, Decls); |
| 25 | return static_cast<DeclGroup*>(Mem); |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Ted Kremenek | 401adfa | 2008-10-07 23:06:01 +0000 | [diff] [blame] | 28 | DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) { |
Chris Lattner | fe95dea | 2009-03-28 06:26:18 +0000 | [diff] [blame] | 29 | assert(numdecls > 0); |
| 30 | assert(decls); |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 31 | memcpy(this+1, decls, numdecls * sizeof(*decls)); |
| 32 | } |
| 33 | |
| 34 | void DeclGroup::Destroy(ASTContext& C) { |
Ted Kremenek | e7809d4 | 2009-12-23 08:56:00 +0000 | [diff] [blame] | 35 | // Decls are destroyed by the DeclContext. |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 36 | this->~DeclGroup(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 37 | C.Deallocate((void*) this); |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 38 | } |