clang 24.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, bool HasPtrField)
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 HasPtrField(HasPtrField) {
22 for (Base &V : SrcVirtualBases)
23 VirtualBases.emplace_back(V.Decl, V.Desc, V.R, V.Offset + BaseSize);
24
25 for (Base &B : Bases) {
26 BaseMap[B.Decl] = &B;
27 if (!this->HasPtrField)
28 this->HasPtrField |= B.R->hasPtrField();
29 }
30 for (Base &V : VirtualBases) {
31 if (!this->HasPtrField)
32 this->HasPtrField |= V.R->hasPtrField();
33 }
34}
35
36std::string Record::getName() const {
37 std::string Ret;
38 llvm::raw_string_ostream OS(Ret);
39 Decl->getNameForDiagnostic(OS, Decl->getASTContext().getPrintingPolicy(),
40 /*Qualified=*/true);
41 return Ret;
42}
43
44bool Record::hasTrivialDtor() const {
45 if (isAnonymousUnion())
46 return true;
48 return !Dtor || Dtor->isTrivial();
49}
50
51const Record::Field *Record::findField(unsigned Offset) const {
52 if (auto It = llvm::find_if(
53 Fields,
54 [=](const Record::Field &F) -> bool { return F.Offset == Offset; });
55 It != Fields.end())
56 return &*It;
57 return nullptr;
58}
59
60const Record::Base *Record::getBase(const RecordDecl *RD) const {
61 auto It = BaseMap.find(RD);
62 assert(It != BaseMap.end() && "Missing base");
63 return It->second;
64}
65
66const Record::Base *Record::getBaseOrNull(const RecordDecl *RD) const {
67 return BaseMap.lookup(RD);
68}
69
70const Record::Base *Record::getBase(QualType T) const {
71 if (auto *RD = T->getAsCXXRecordDecl())
72 return BaseMap.lookup(RD);
73 return nullptr;
74}
75
76const Record::Base *Record::findBase(unsigned Offset) const {
77 if (auto It = llvm::find_if(
78 Bases,
79 [=](const Record::Base &B) -> bool { return B.Offset == Offset; });
80 It != Bases.end())
81 return &*It;
82 return nullptr;
83}
84
85const Record::Base *Record::findVirtualBase(const RecordDecl *FD) const {
86 if (auto *It = llvm::find_if(
87 VirtualBases,
88 [=](const Record::Base &B) -> bool { return B.Decl == FD; });
89 It != Bases.end())
90 return &*It;
91 return nullptr;
92}
Defines the clang::ASTContext interface.
#define V(N, I)
Represents a C++ destructor within a class.
Definition DeclCXX.h:2906
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
A (possibly-)qualified type.
Definition TypeBase.h:938
Represents a struct/union/class.
Definition Decl.h:4460
const CXXDestructorDecl * getDestructor() const
Returns the destructor of the record, if any.
Definition Record.h:77
bool isAnonymousUnion() const
Checks if the record is an anonymous union.
Definition Record.h:71
PRESERVE_NONE bool Ret(InterpState &S)
Definition Interp.h:288
Top level wrappers for InstallAPI frontend operations.
const FunctionProtoType * T
for(const auto &A :T->param_types())