DeclGroup.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. //===- DeclGroup.cpp - Classes for representing groups of Decls -----------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the DeclGroup and DeclGroupRef classes.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/AST/DeclGroup.h"
  13. #include "clang/AST/ASTContext.h"
  14. #include <cassert>
  15. #include <memory>
  16. using namespace clang;
  17. DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
  18. assert(NumDecls > 1 && "Invalid DeclGroup");
  19. unsigned Size = totalSizeToAlloc<Decl *>(NumDecls);
  20. void *Mem = C.Allocate(Size, alignof(DeclGroup));
  21. new (Mem) DeclGroup(NumDecls, Decls);
  22. return static_cast<DeclGroup*>(Mem);
  23. }
  24. DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
  25. assert(numdecls > 0);
  26. assert(decls);
  27. std::uninitialized_copy(decls, decls + numdecls,
  28. getTrailingObjects<Decl *>());
  29. }