xref: /minix3/external/bsd/llvm/dist/clang/lib/AST/DeclGroup.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc //===--- DeclGroup.cpp - Classes for representing groups of Decls -*- C++ -*-==//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc //
10*f4a2713aSLionel Sambuc //  This file defines the DeclGroup and DeclGroupRef classes.
11*f4a2713aSLionel Sambuc //
12*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc #include "clang/AST/DeclGroup.h"
15*f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h"
16*f4a2713aSLionel Sambuc #include "clang/AST/Decl.h"
17*f4a2713aSLionel Sambuc #include "llvm/Support/Allocator.h"
18*f4a2713aSLionel Sambuc using namespace clang;
19*f4a2713aSLionel Sambuc 
Create(ASTContext & C,Decl ** Decls,unsigned NumDecls)20*f4a2713aSLionel Sambuc DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
21*f4a2713aSLionel Sambuc   assert(NumDecls > 1 && "Invalid DeclGroup");
22*f4a2713aSLionel Sambuc   unsigned Size = sizeof(DeclGroup) + sizeof(Decl*) * NumDecls;
23*f4a2713aSLionel Sambuc   void* Mem = C.Allocate(Size, llvm::AlignOf<DeclGroup>::Alignment);
24*f4a2713aSLionel Sambuc   new (Mem) DeclGroup(NumDecls, Decls);
25*f4a2713aSLionel Sambuc   return static_cast<DeclGroup*>(Mem);
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
DeclGroup(unsigned numdecls,Decl ** decls)28*f4a2713aSLionel Sambuc DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
29*f4a2713aSLionel Sambuc   assert(numdecls > 0);
30*f4a2713aSLionel Sambuc   assert(decls);
31*f4a2713aSLionel Sambuc   memcpy(this+1, decls, numdecls * sizeof(*decls));
32*f4a2713aSLionel Sambuc }
33