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