clang
24.0.0git
lib
AST
ByteCode
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
#include "
clang/AST/ASTContext.h
"
11
12
using namespace
clang
;
13
using namespace
clang::interp
;
14
15
Record::Record(
const
RecordDecl
*
Decl
,
ArrayRef<Base>
Bases,
16
ArrayRef<Field>
Fields,
ArrayRef<Base>
VirtualBases,
17
unsigned
VirtualSize,
unsigned
BaseSize,
bool
HasPtrField)
18
:
Decl
(
Decl
), Bases(Bases), Fields(Fields), VirtualBases(VirtualBases),
19
BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(
Decl
->isUnion()),
20
IsAnonymousUnion(IsUnion &&
Decl
->isAnonymousStructOrUnion()),
21
HasPtrField(HasPtrField) {
22
for
(
const
Base
&B : this->Bases)
23
BaseMap[B.Decl] = &B;
24
}
25
26
std::string Record::getName()
const
{
27
std::string
Ret
;
28
llvm::raw_string_ostream OS(
Ret
);
29
Decl->getNameForDiagnostic(OS, Decl->getASTContext().getPrintingPolicy(),
30
/*Qualified=*/
true
);
31
return
Ret
;
32
}
33
34
bool
Record::hasTrivialDtor()
const
{
35
if
(
isAnonymousUnion
())
36
return
true
;
37
const
CXXDestructorDecl
*
Dtor
=
getDestructor
();
38
return
!
Dtor
||
Dtor
->isTrivial();
39
}
40
41
const
Record::Field *Record::findField(
unsigned
Offset)
const
{
42
if
(
auto
It = llvm::find_if(
43
Fields,
44
[=](
const
Record::Field &F) ->
bool
{
return
F.Offset == Offset; });
45
It != Fields.end())
46
return
&*It;
47
return
nullptr
;
48
}
49
50
const
Record::Base *Record::getBase(
const
RecordDecl
*RD)
const
{
51
auto
It = BaseMap.find(RD);
52
assert(It != BaseMap.end() &&
"Missing base"
);
53
return
It->second;
54
}
55
56
const
Record::Base *Record::getBaseOrNull(
const
RecordDecl
*RD)
const
{
57
return
BaseMap.lookup(RD);
58
}
59
60
const
Record::Base *Record::getBase(
QualType
T
)
const
{
61
if
(
auto
*RD =
T
->getAsCXXRecordDecl())
62
return
BaseMap.lookup(RD);
63
return
nullptr
;
64
}
65
66
const
Record::Base *Record::findBase(
unsigned
Offset)
const
{
67
if
(
auto
It = llvm::find_if(
68
Bases,
69
[=](
const
Record::Base &B) ->
bool
{
return
B.Offset == Offset; });
70
It != Bases.end())
71
return
&*It;
72
return
nullptr
;
73
}
74
75
const
Record::Base *Record::findVirtualBase(
const
RecordDecl
*FD)
const
{
76
if
(
auto
*It = llvm::find_if(
77
VirtualBases,
78
[=](
const
Record::Base &B) ->
bool
{
return
B.Decl == FD; });
79
It != Bases.end())
80
return
&*It;
81
return
nullptr
;
82
}
ASTContext.h
Defines the clang::ASTContext interface.
Record.h
Base
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition
DeclCXX.h:2907
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition
DeclBase.h:86
clang::QualType
A (possibly-)qualified type.
Definition
TypeBase.h:938
clang::RecordDecl
Represents a struct/union/class.
Definition
Decl.h:4460
clang::interp::Record::getDestructor
const CXXDestructorDecl * getDestructor() const
Returns the destructor of the record, if any.
Definition
Record.h:79
clang::interp::Record::isAnonymousUnion
bool isAnonymousUnion() const
Checks if the record is an anonymous union.
Definition
Record.h:73
llvm::ArrayRef
Definition
LLVM.h:31
clang::interp
Definition
ASTContext.h:164
clang::interp::Ret
PRESERVE_NONE bool Ret(InterpState &S)
Definition
Interp.h:283
clang::interp::EvaluationKind::Dtor
@ Dtor
Definition
InterpState.h:42
clang
Top level wrappers for InstallAPI frontend operations.
Definition
CalledOnceCheck.h:17
clang::T
const FunctionProtoType * T
Definition
RecursiveASTVisitor.h:1425
Generated on
for clang by
1.14.0