clang 17.0.0git
Record.cpp
Go to the documentation of this file.
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
43 if (!T->isRecordType())
44 return nullptr;
45
46 const RecordDecl *RD = T->getAs<RecordType>()->getDecl();
47 return BaseMap.lookup(RD);
48}
49
51 auto It = VirtualBaseMap.find(FD);
52 assert(It != VirtualBaseMap.end() && "Missing virtual base");
53 return It->second;
54}
#define V(N, I)
Definition: ASTContext.h:3230
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
Represents a member of a struct/union/class.
Definition: Decl.h:2960
A (possibly-)qualified type.
Definition: Type.h:736
Represents a struct/union/class.
Definition: Decl.h:4027
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4850
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7430
bool isRecordType() const
Definition: Type.h:7006
const RecordDecl * getDecl() const
Returns the underlying declaration.
Definition: Record.h:51
const Field * getField(const FieldDecl *FD) const
Returns a field.
Definition: Record.cpp:30
const Base * getVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
Definition: Record.cpp:50
const Base * getBase(const RecordDecl *FD) const
Returns a base descriptor.
Definition: Record.cpp:36
Definition: Format.h:4761
Describes a base class.
Definition: Record.h:35
Describes a record field.
Definition: Record.h:28