Record.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //===--- Record.cpp - struct and class metadata for the VM ------*- C++ -*-===//
  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. #include "Record.h"
  9. using namespace clang;
  10. using namespace clang::interp;
  11. Record::Record(const RecordDecl *Decl, BaseList &&SrcBases,
  12. FieldList &&SrcFields, VirtualBaseList &&SrcVirtualBases,
  13. unsigned VirtualSize, unsigned BaseSize)
  14. : Decl(Decl), Bases(std::move(SrcBases)), Fields(std::move(SrcFields)),
  15. BaseSize(BaseSize), VirtualSize(VirtualSize) {
  16. for (Base &V : SrcVirtualBases)
  17. VirtualBases.push_back({ V.Decl, V.Offset + BaseSize, V.Desc, V.R });
  18. for (Base &B : Bases)
  19. BaseMap[B.Decl] = &B;
  20. for (Field &F : Fields)
  21. FieldMap[F.Decl] = &F;
  22. for (Base &V : VirtualBases)
  23. VirtualBaseMap[V.Decl] = &V;
  24. }
  25. const Record::Field *Record::getField(const FieldDecl *FD) const {
  26. auto It = FieldMap.find(FD);
  27. assert(It != FieldMap.end() && "Missing field");
  28. return It->second;
  29. }
  30. const Record::Base *Record::getBase(const RecordDecl *FD) const {
  31. auto It = BaseMap.find(FD);
  32. assert(It != BaseMap.end() && "Missing base");
  33. return It->second;
  34. }
  35. const Record::Base *Record::getVirtualBase(const RecordDecl *FD) const {
  36. auto It = VirtualBaseMap.find(FD);
  37. assert(It != VirtualBaseMap.end() && "Missing virtual base");
  38. return It->second;
  39. }