Eugene Zelenko | 8998f10 | 2017-11-10 00:59:22 +0000 | [diff] [blame] | 1 | //===- DeclGroup.cpp - Classes for representing groups of Decls -----------===// |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Douglas Gregor | 4feb36d | 2009-02-13 19:06:18 +0000 | [diff] [blame] | 9 | // This file defines the DeclGroup and DeclGroupRef classes. |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "clang/AST/DeclGroup.h" |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | 8998f10 | 2017-11-10 00:59:22 +0000 | [diff] [blame] | 15 | #include <cassert> |
| 16 | #include <memory> |
| 17 | |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
Chris Lattner | 5bbb3c8 | 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"); |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 22 | unsigned Size = totalSizeToAlloc<Decl *>(NumDecls); |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 23 | void *Mem = C.Allocate(Size, alignof(DeclGroup)); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 24 | new (Mem) DeclGroup(NumDecls, Decls); |
| 25 | return static_cast<DeclGroup*>(Mem); |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Ted Kremenek | 12183e2 | 2008-10-07 23:06:01 +0000 | [diff] [blame] | 28 | DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) { |
Chris Lattner | 23b88b7 | 2009-03-28 06:26:18 +0000 | [diff] [blame] | 29 | assert(numdecls > 0); |
| 30 | assert(decls); |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 31 | std::uninitialized_copy(decls, decls + numdecls, |
| 32 | getTrailingObjects<Decl *>()); |
Ted Kremenek | a5e23f6 | 2008-09-25 17:13:40 +0000 | [diff] [blame] | 33 | } |