1 //===--- Record.h - struct and class metadata for the VM --------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // A record is part of a program to describe the layout and methods of a struct.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_AST_INTERP_RECORD_H
14 #define LLVM_CLANG_AST_INTERP_RECORD_H
22 /// Structure/Class descriptor.
25 /// Describes a record field.
27 const FieldDecl *Decl;
32 /// Describes a base class.
34 const RecordDecl *Decl;
40 /// Mapping from identifiers to field descriptors.
41 using FieldList = llvm::SmallVector<Field, 8>;
42 /// Mapping from identifiers to base classes.
43 using BaseList = llvm::SmallVector<Base, 8>;
44 /// List of virtual base classes.
45 using VirtualBaseList = llvm::SmallVector<Base, 2>;
48 /// Returns the underlying declaration.
49 const RecordDecl *getDecl() const { return Decl; }
50 /// Checks if the record is a union.
51 bool isUnion() const { return getDecl()->isUnion(); }
52 /// Returns the size of the record.
53 unsigned getSize() const { return BaseSize; }
54 /// Returns the full size of the record, including records.
55 unsigned getFullSize() const { return BaseSize + VirtualSize; }
57 const Field *getField(const FieldDecl *FD) const;
58 /// Returns a base descriptor.
59 const Base *getBase(const RecordDecl *FD) const;
60 /// Returns a virtual base descriptor.
61 const Base *getVirtualBase(const RecordDecl *RD) const;
63 using const_field_iter = FieldList::const_iterator;
64 llvm::iterator_range<const_field_iter> fields() const {
65 return llvm::make_range(Fields.begin(), Fields.end());
68 unsigned getNumFields() { return Fields.size(); }
69 Field *getField(unsigned I) { return &Fields[I]; }
71 using const_base_iter = BaseList::const_iterator;
72 llvm::iterator_range<const_base_iter> bases() const {
73 return llvm::make_range(Bases.begin(), Bases.end());
76 unsigned getNumBases() { return Bases.size(); }
77 Base *getBase(unsigned I) { return &Bases[I]; }
79 using const_virtual_iter = VirtualBaseList::const_iterator;
80 llvm::iterator_range<const_virtual_iter> virtual_bases() const {
81 return llvm::make_range(VirtualBases.begin(), VirtualBases.end());
84 unsigned getNumVirtualBases() { return VirtualBases.size(); }
85 Base *getVirtualBase(unsigned I) { return &VirtualBases[I]; }
88 /// Constructor used by Program to create record descriptors.
89 Record(const RecordDecl *, BaseList &&Bases, FieldList &&Fields,
90 VirtualBaseList &&VirtualBases, unsigned VirtualSize,
96 /// Original declaration.
97 const RecordDecl *Decl;
98 /// List of all base classes.
100 /// List of all the fields in the record.
102 /// List o fall virtual bases.
103 VirtualBaseList VirtualBases;
105 /// Mapping from declarations to bases.
106 llvm::DenseMap<const RecordDecl *, Base *> BaseMap;
107 /// Mapping from field identifiers to descriptors.
108 llvm::DenseMap<const FieldDecl *, Field *> FieldMap;
109 /// Mapping from declarations to virtual bases.
110 llvm::DenseMap<const RecordDecl *, Base *> VirtualBaseMap;
112 /// Size of the structure.
114 /// Size of all virtual bases.
115 unsigned VirtualSize;
118 } // namespace interp