clang  10.0.0svn
Record.h
Go to the documentation of this file.
1 //===--- Record.h - 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 // A record is part of a program to describe the layout and methods of a struct.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_AST_INTERP_RECORD_H
14 #define LLVM_CLANG_AST_INTERP_RECORD_H
15 
16 #include "Pointer.h"
17 
18 namespace clang {
19 namespace interp {
20 class Program;
21 
22 /// Structure/Class descriptor.
23 class Record {
24 public:
25  /// Describes a record field.
26  struct Field {
27  const FieldDecl *Decl;
28  unsigned Offset;
30  };
31 
32  /// Describes a base class.
33  struct Base {
34  const RecordDecl *Decl;
35  unsigned Offset;
38  };
39 
40  /// Mapping from identifiers to field descriptors.
42  /// Mapping from identifiers to base classes.
44  /// List of virtual base classes.
46 
47 public:
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; }
56  /// Returns a field.
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;
62 
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());
66  }
67 
68  unsigned getNumFields() { return Fields.size(); }
69  Field *getField(unsigned I) { return &Fields[I]; }
70 
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());
74  }
75 
76  unsigned getNumBases() { return Bases.size(); }
77  Base *getBase(unsigned I) { return &Bases[I]; }
78 
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());
82  }
83 
84  unsigned getNumVirtualBases() { return VirtualBases.size(); }
85  Base *getVirtualBase(unsigned I) { return &VirtualBases[I]; }
86 
87 private:
88  /// Constructor used by Program to create record descriptors.
89  Record(const RecordDecl *, BaseList &&Bases, FieldList &&Fields,
90  VirtualBaseList &&VirtualBases, unsigned VirtualSize,
91  unsigned BaseSize);
92 
93 private:
94  friend class Program;
95 
96  /// Original declaration.
97  const RecordDecl *Decl;
98  /// List of all base classes.
99  BaseList Bases;
100  /// List of all the fields in the record.
101  FieldList Fields;
102  /// List o fall virtual bases.
103  VirtualBaseList VirtualBases;
104 
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;
111  /// Mapping from
112  /// Size of the structure.
113  unsigned BaseSize;
114  /// Size of all virtual bases.
115  unsigned VirtualSize;
116 };
117 
118 } // namespace interp
119 } // namespace clang
120 
121 #endif
const RecordDecl * Decl
Definition: Record.h:34
const Base * getBase(const RecordDecl *FD) const
Returns a base descriptor.
Definition: Record.cpp:36
llvm::iterator_range< const_virtual_iter > virtual_bases() const
Definition: Record.h:80
Represents a struct/union/class.
Definition: Decl.h:3662
FieldList::const_iterator const_field_iter
Definition: Record.h:63
Represents a member of a struct/union/class.
Definition: Decl.h:2643
const RecordDecl * getDecl() const
Returns the underlying declaration.
Definition: Record.h:49
Base * getBase(unsigned I)
Definition: Record.h:77
Structure/Class descriptor.
Definition: Record.h:23
unsigned getNumVirtualBases()
Definition: Record.h:84
Base * getVirtualBase(unsigned I)
Definition: Record.h:85
Field * getField(unsigned I)
Definition: Record.h:69
Describes a memory block created by an allocation site.
Definition: Descriptor.h:51
bool isUnion() const
Checks if the record is a union.
Definition: Record.h:51
unsigned getNumBases()
Definition: Record.h:76
BaseList::const_iterator const_base_iter
Definition: Record.h:71
unsigned getNumFields()
Definition: Record.h:68
The program contains and links the bytecode for all functions.
Definition: Program.h:43
VirtualBaseList::const_iterator const_virtual_iter
Definition: Record.h:79
unsigned getFullSize() const
Returns the full size of the record, including records.
Definition: Record.h:55
Dataflow Directional Tag Classes.
llvm::iterator_range< const_field_iter > fields() const
Definition: Record.h:64
Describes a record field.
Definition: Record.h:26
const FieldDecl * Decl
Definition: Record.h:27
llvm::iterator_range< const_base_iter > bases() const
Definition: Record.h:72
bool isUnion() const
Definition: Decl.h:3321
const Field * getField(const FieldDecl *FD) const
Returns a field.
Definition: Record.cpp:30
const Base * getVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
Definition: Record.cpp:42
Describes a base class.
Definition: Record.h:33
unsigned getSize() const
Returns the size of the record.
Definition: Record.h:53