blob: 27dbdaab6f30db673c422d826aeaffc24966336f [file] [log] [blame]
Eugene Zelenko8998f102017-11-10 00:59:22 +00001//===- DeclGroup.cpp - Classes for representing groups of Decls -----------===//
Ted Kremeneka5e23f62008-09-25 17:13:40 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Kremeneka5e23f62008-09-25 17:13:40 +00006//
7//===----------------------------------------------------------------------===//
8//
Douglas Gregor4feb36d2009-02-13 19:06:18 +00009// This file defines the DeclGroup and DeclGroupRef classes.
Ted Kremeneka5e23f62008-09-25 17:13:40 +000010//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/DeclGroup.h"
Ted Kremeneka5e23f62008-09-25 17:13:40 +000014#include "clang/AST/ASTContext.h"
Eugene Zelenko8998f102017-11-10 00:59:22 +000015#include <cassert>
16#include <memory>
17
Ted Kremeneka5e23f62008-09-25 17:13:40 +000018using namespace clang;
19
Chris Lattner5bbb3c82009-03-29 16:50:03 +000020DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
21 assert(NumDecls > 1 && "Invalid DeclGroup");
James Y Knight967eb202015-12-29 22:13:13 +000022 unsigned Size = totalSizeToAlloc<Decl *>(NumDecls);
Benjamin Kramerc3f89252016-10-20 14:27:22 +000023 void *Mem = C.Allocate(Size, alignof(DeclGroup));
Chris Lattner5bbb3c82009-03-29 16:50:03 +000024 new (Mem) DeclGroup(NumDecls, Decls);
25 return static_cast<DeclGroup*>(Mem);
Ted Kremeneka5e23f62008-09-25 17:13:40 +000026}
27
Ted Kremenek12183e22008-10-07 23:06:01 +000028DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
Chris Lattner23b88b72009-03-28 06:26:18 +000029 assert(numdecls > 0);
30 assert(decls);
James Y Knight967eb202015-12-29 22:13:13 +000031 std::uninitialized_copy(decls, decls + numdecls,
32 getTrailingObjects<Decl *>());
Ted Kremeneka5e23f62008-09-25 17:13:40 +000033}