Debian Codegraph @

clang/lib/AST/ByteCode/Record.cpp

raw
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, 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
32 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
40 bool Record::hasTrivialDtor() const {
41 if (isAnonymousUnion())
42 return true;
43 const CXXDestructorDecl *Dtor = getDestructor();
44 return !Dtor || Dtor->isTrivial();
45 }
46
47 const Record::Field *Record::getField(const FieldDecl *FD) const {
48 auto It = FieldMap.find(FD->getFirstDecl());
49 assert(It != FieldMap.end() && "Missing field");
50 return It->second;
51 }
52
53 const Record::Base *Record::getBase(const RecordDecl *FD) const {
54 auto It = BaseMap.find(FD);
55 assert(It != BaseMap.end() && "Missing base");
56 return It->second;
57 }
58
59 const Record::Base *Record::getBase(QualType T) const {
60 if (auto *RD = T->getAsCXXRecordDecl())
61 return BaseMap.lookup(RD);
62 return nullptr;
63 }
64
65 const Record::Base *Record::getVirtualBase(const RecordDecl *FD) const {
66 auto It = VirtualBaseMap.find(FD);
67 assert(It != VirtualBaseMap.end() && "Missing virtual base");
68 return It->second;
69 }