Ted Kremenek | a5e23f6 | 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 | 4feb36d | 2009-02-13 19:06:18 +0000 | [diff] [blame] | 10 | // This file defines the DeclGroup and DeclGroupRef classes. |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclGroup.h" |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 19 | DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) { |
| 20 | assert(NumDecls > 1 && "Invalid DeclGroup"); |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 21 | unsigned Size = totalSizeToAlloc<Decl *>(NumDecls); |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 22 | void *Mem = C.Allocate(Size, alignof(DeclGroup)); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 23 | new (Mem) DeclGroup(NumDecls, Decls); |
| 24 | return static_cast<DeclGroup*>(Mem); |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Ted Kremenek | 12183e2 | 2008-10-07 23:06:01 +0000 | [diff] [blame] | 27 | DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) { |
Chris Lattner | 23b88b7 | 2009-03-28 06:26:18 +0000 | [diff] [blame] | 28 | assert(numdecls > 0); |
| 29 | assert(decls); |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 30 | std::uninitialized_copy(decls, decls + numdecls, |
| 31 | getTrailingObjects<Decl *>()); |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 32 | } |