clang 20.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"
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), IsUnion(Decl->isUnion()),
20 IsAnonymousUnion(IsUnion && Decl->isAnonymousStructOrUnion()) {
21 for (Base &V : SrcVirtualBases)
22 VirtualBases.push_back({V.Decl, V.Offset + BaseSize, V.Desc, V.R});
23
24 for (Base &B : Bases)
25 BaseMap[B.Decl] = &B;
26 for (Field &F : Fields)
27 FieldMap[F.Decl] = &F;
28 for (Base &V : VirtualBases)
29 VirtualBaseMap[V.Decl] = &V;
30}
31
32const std::string Record::getName() const {
33 std::string Ret;
34 llvm::raw_string_ostream OS(Ret);
35 Decl->getNameForDiagnostic(OS, Decl->getASTContext().getPrintingPolicy(),
36 /*Qualified=*/true);
37 return Ret;
38}
39
40const Record::Field *Record::getField(const FieldDecl *FD) const {
41 auto It = FieldMap.find(FD->getFirstDecl());
42 assert(It != FieldMap.end() && "Missing field");
43 return It->second;
44}
45
46const Record::Base *Record::getBase(const RecordDecl *FD) const {
47 auto It = BaseMap.find(FD);
48 assert(It != BaseMap.end() && "Missing base");
49 return It->second;
50}
51
52const Record::Base *Record::getBase(QualType T) const {
53 if (auto *RT = T->getAs<RecordType>()) {
54 const RecordDecl *RD = RT->getDecl();
55 return BaseMap.lookup(RD);
56 }
57 return nullptr;
58}
59
60const Record::Base *Record::getVirtualBase(const RecordDecl *FD) const {
61 auto It = VirtualBaseMap.find(FD);
62 assert(It != VirtualBaseMap.end() && "Missing virtual base");
63 return It->second;
64}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3443
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:733
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:520
Represents a member of a struct/union/class.
Definition: Decl.h:3033
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:319
A (possibly-)qualified type.
Definition: Type.h:929
Represents a struct/union/class.
Definition: Decl.h:4148
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6072
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
bool Ret(InterpState &S, CodePtr &PC)
Definition: Interp.h:318
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T