blob: 434bf00d354e346aa56beb16d037c69927222840 [file] [log] [blame]
Ted Kremenekd17062c2008-09-25 17:13:40 +00001//===--- 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 Gregor9653db72009-02-13 19:06:18 +000010// This file defines the DeclGroup and DeclGroupRef classes.
Ted Kremenekd17062c2008-09-25 17:13:40 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/DeclGroup.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/ASTContext.h"
17#include "llvm/Support/Allocator.h"
Ted Kremenekd17062c2008-09-25 17:13:40 +000018using namespace clang;
19
Chris Lattner682bf922009-03-29 16:50:03 +000020DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
21 assert(NumDecls > 1 && "Invalid DeclGroup");
22 unsigned Size = sizeof(DeclGroup) + sizeof(Decl*) * NumDecls;
23 void* Mem = C.Allocate(Size, llvm::AlignOf<DeclGroup>::Alignment);
24 new (Mem) DeclGroup(NumDecls, Decls);
25 return static_cast<DeclGroup*>(Mem);
Ted Kremenekd17062c2008-09-25 17:13:40 +000026}
27
Ted Kremenek401adfa2008-10-07 23:06:01 +000028DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
Chris Lattnerfe95dea2009-03-28 06:26:18 +000029 assert(numdecls > 0);
30 assert(decls);
Ted Kremenekd17062c2008-09-25 17:13:40 +000031 memcpy(this+1, decls, numdecls * sizeof(*decls));
32}
33
34void DeclGroup::Destroy(ASTContext& C) {
Ted Kremeneke7809d42009-12-23 08:56:00 +000035 // Decls are destroyed by the DeclContext.
Ted Kremenekd17062c2008-09-25 17:13:40 +000036 this->~DeclGroup();
Steve Naroff3e970492009-01-27 21:25:57 +000037 C.Deallocate((void*) this);
Ted Kremenekd17062c2008-09-25 17:13:40 +000038}