clang  14.0.0git
LayoutOverrideSource.h
Go to the documentation of this file.
1 //===--- LayoutOverrideSource.h --Override Record Layouts -------*- 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 #ifndef LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H
10 #define LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H
11 
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/ADT/StringRef.h"
16 
17 namespace clang {
18  /// An external AST source that overrides the layout of
19  /// a specified set of record types.
20  ///
21  /// This class is used only for testing the ability of external AST sources
22  /// to override the layout of record types. Its input is the output format
23  /// of the command-line argument -fdump-record-layouts.
25  /// The layout of a given record.
26  struct Layout {
27  /// The size of the record.
28  uint64_t Size;
29 
30  /// The alignment of the record.
31  uint64_t Align;
32 
33  /// The offsets of the fields, in source order.
34  SmallVector<uint64_t, 8> FieldOffsets;
35  };
36 
37  /// The set of layouts that will be overridden.
38  llvm::StringMap<Layout> Layouts;
39 
40  public:
41  /// Create a new AST source that overrides the layout of some
42  /// set of record types.
43  ///
44  /// The file is the result of passing -fdump-record-layouts to a file.
45  explicit LayoutOverrideSource(StringRef Filename);
46 
47  /// If this particular record type has an overridden layout,
48  /// return that layout.
49  bool
50  layoutRecordType(const RecordDecl *Record,
51  uint64_t &Size, uint64_t &Alignment,
52  llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
53  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
54  llvm::DenseMap<const CXXRecordDecl *,
55  CharUnits> &VirtualBaseOffsets) override;
56 
57  /// Dump the overridden layouts.
58  void dump();
59  };
60 }
61 
62 #endif
llvm::SmallVector< uint64_t, 8 >
Filename
StringRef Filename
Definition: Format.cpp:2333
clang::LayoutOverrideSource::dump
void dump()
Dump the overridden layouts.
Definition: LayoutOverrideSource.cpp:190
clang::LayoutOverrideSource
An external AST source that overrides the layout of a specified set of record types.
Definition: LayoutOverrideSource.h:24
clang::LayoutOverrideSource::layoutRecordType
bool layoutRecordType(const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap< const FieldDecl *, uint64_t > &FieldOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &BaseOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &VirtualBaseOffsets) override
If this particular record type has an overridden layout, return that layout.
Definition: LayoutOverrideSource.cpp:155
ExternalASTSource.h
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
LLVM.h
clang
Definition: CalledOnceCheck.h:17
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::ExternalASTSource
Abstract interface for external sources of AST nodes.
Definition: ExternalASTSource.h:60
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3859
clang::LayoutOverrideSource::LayoutOverrideSource
LayoutOverrideSource(StringRef Filename)
Create a new AST source that overrides the layout of some set of record types.
Definition: LayoutOverrideSource.cpp:29