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" |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 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) { |
Pirama Arumuga Nainar | 58878f8 | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 21 | static_assert(sizeof(DeclGroup) % llvm::AlignOf<void *>::Alignment == 0, |
| 22 | "Trailing data is unaligned!"); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 23 | assert(NumDecls > 1 && "Invalid DeclGroup"); |
| 24 | unsigned Size = sizeof(DeclGroup) + sizeof(Decl*) * NumDecls; |
| 25 | void* Mem = C.Allocate(Size, llvm::AlignOf<DeclGroup>::Alignment); |
| 26 | new (Mem) DeclGroup(NumDecls, Decls); |
| 27 | return static_cast<DeclGroup*>(Mem); |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Ted Kremenek | 401adfa | 2008-10-07 23:06:01 +0000 | [diff] [blame] | 30 | DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) { |
Chris Lattner | fe95dea | 2009-03-28 06:26:18 +0000 | [diff] [blame] | 31 | assert(numdecls > 0); |
| 32 | assert(decls); |
Ted Kremenek | d17062c | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 33 | memcpy(this+1, decls, numdecls * sizeof(*decls)); |
| 34 | } |