1*0b57cec5SDimitry Andric //===- DeclGroup.cpp - Classes for representing groups of Decls -----------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // This file defines the DeclGroup and DeclGroupRef classes.
10*0b57cec5SDimitry Andric //
11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
12*0b57cec5SDimitry Andric
13*0b57cec5SDimitry Andric #include "clang/AST/DeclGroup.h"
14*0b57cec5SDimitry Andric #include "clang/AST/ASTContext.h"
15*0b57cec5SDimitry Andric #include <cassert>
16*0b57cec5SDimitry Andric #include <memory>
17*0b57cec5SDimitry Andric
18*0b57cec5SDimitry Andric using namespace clang;
19*0b57cec5SDimitry Andric
Create(ASTContext & C,Decl ** Decls,unsigned NumDecls)20*0b57cec5SDimitry Andric DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
21*0b57cec5SDimitry Andric assert(NumDecls > 1 && "Invalid DeclGroup");
22*0b57cec5SDimitry Andric unsigned Size = totalSizeToAlloc<Decl *>(NumDecls);
23*0b57cec5SDimitry Andric void *Mem = C.Allocate(Size, alignof(DeclGroup));
24*0b57cec5SDimitry Andric new (Mem) DeclGroup(NumDecls, Decls);
25*0b57cec5SDimitry Andric return static_cast<DeclGroup*>(Mem);
26*0b57cec5SDimitry Andric }
27*0b57cec5SDimitry Andric
DeclGroup(unsigned numdecls,Decl ** decls)28*0b57cec5SDimitry Andric DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
29*0b57cec5SDimitry Andric assert(numdecls > 0);
30*0b57cec5SDimitry Andric assert(decls);
31*0b57cec5SDimitry Andric std::uninitialized_copy(decls, decls + numdecls,
32*0b57cec5SDimitry Andric getTrailingObjects<Decl *>());
33*0b57cec5SDimitry Andric }
34