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"
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  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 
31 const 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 
39 const 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 
45 const 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 
52  if (!T->isRecordType())
53  return nullptr;
54 
55  const RecordDecl *RD = T->getAs<RecordType>()->getDecl();
56  return BaseMap.lookup(RD);
57 }
58 
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:3299
static std::string getName(const CallEvent &Call)
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:501
Represents a member of a struct/union/class.
Definition: Decl.h:3060
A (possibly-)qualified type.
Definition: Type.h:940
Represents a struct/union/class.
Definition: Decl.h:4171
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5561
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8160
bool isRecordType() const
Definition: Type.h:7718
const RecordDecl * getDecl() const
Returns the underlying declaration.
Definition: Record.h:52
const Field * getField(const FieldDecl *FD) const
Returns a field.
Definition: Record.cpp:39
const Base * getVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
Definition: Record.cpp:59
const Base * getBase(const RecordDecl *FD) const
Returns a base descriptor.
Definition: Record.cpp:45
bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.h:218
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
Definition: Format.h:5433