clang 19.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 for (Base &V : SrcVirtualBases)
21 VirtualBases.push_back({ V.Decl, V.Offset + BaseSize, V.Desc, 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, 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(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(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(RD);
57}
58
59const Record::Base *Record::getVirtualBase(const RecordDecl *FD) const {
60 auto It = VirtualBaseMap.find(FD);
61 assert(It != VirtualBaseMap.end() && "Missing virtual base");
62 return It->second;
63}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3298
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:700
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:523
Represents a member of a struct/union/class.
Definition: Decl.h:3059
A (possibly-)qualified type.
Definition: Type.h:940
Represents a struct/union/class.
Definition: Decl.h:4170
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5565
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8143
bool isRecordType() const
Definition: Type.h:7719
const RecordDecl * getDecl() const
Returns the underlying declaration.
Definition: Record.h:52
bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.h:224
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
Definition: Format.h:5433