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#include "clang/AST/ASTContext.h"
11
12using namespace clang;
13using namespace clang::interp;
14
15Record::Record(const RecordDecl *Decl, BaseList &&SrcBases,
16 FieldList &&SrcFields, VirtualBaseList &&SrcVirtualBases,
17 unsigned VirtualSize, unsigned BaseSize)
18 : Decl(Decl), Bases(std::move(SrcBases)), Fields(std::move(SrcFields)),
19 BaseSize(BaseSize), VirtualSize(VirtualSize) {
20 for (Base &V : SrcVirtualBases)
21 VirtualBases.push_back(Elt: { .Decl: V.Decl, .Offset: V.Offset + BaseSize, .Desc: V.Desc, .R: V.R });
22
23 for (Base &B : Bases)
24 BaseMap[B.Decl] = &B;
25 for (Field &F : Fields)
26 FieldMap[F.Decl] = &F;
27 for (Base &V : VirtualBases)
28 VirtualBaseMap[V.Decl] = &V;
29}
30
31const std::string Record::getName() const {
32 std::string Ret;
33 llvm::raw_string_ostream OS(Ret);
34 Decl->getNameForDiagnostic(OS, Policy: Decl->getASTContext().getPrintingPolicy(),
35 /*Qualified=*/true);
36 return Ret;
37}
38
39const Record::Field *Record::getField(const FieldDecl *FD) const {
40 auto It = FieldMap.find(Val: FD);
41 assert(It != FieldMap.end() && "Missing field");
42 return It->second;
43}
44
45const Record::Base *Record::getBase(const RecordDecl *FD) const {
46 auto It = BaseMap.find(Val: FD);
47 assert(It != BaseMap.end() && "Missing base");
48 return It->second;
49}
50
51const Record::Base *Record::getBase(QualType T) const {
52 if (!T->isRecordType())
53 return nullptr;
54
55 const RecordDecl *RD = T->getAs<RecordType>()->getDecl();
56 return BaseMap.lookup(Val: RD);
57}
58
59const Record::Base *Record::getVirtualBase(const RecordDecl *FD) const {
60 auto It = VirtualBaseMap.find(Val: FD);
61 assert(It != VirtualBaseMap.end() && "Missing virtual base");
62 return It->second;
63}
64

source code of clang/lib/AST/Interp/Record.cpp