DeclGroup.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. //===--- 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. //
  10. // This file defines the DeclGroup and DeclGroupRef classes.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/AST/DeclGroup.h"
  14. #include "clang/AST/ASTContext.h"
  15. #include "clang/AST/Decl.h"
  16. #include "llvm/Support/Allocator.h"
  17. using namespace clang;
  18. DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
  19. static_assert(sizeof(DeclGroup) % llvm::AlignOf<void *>::Alignment == 0,
  20. "Trailing data is unaligned!");
  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);
  26. }
  27. DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
  28. assert(numdecls > 0);
  29. assert(decls);
  30. memcpy(this+1, decls, numdecls * sizeof(*decls));
  31. }