1 //===--- LayoutOverrideSource.h --Override Record Layouts -------*- 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 #ifndef LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H
10 #define LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H
12 #include "clang/AST/ExternalASTSource.h"
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/ADT/StringRef.h"
18 /// An external AST source that overrides the layout of
19 /// a specified set of record types.
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.
24 class LayoutOverrideSource : public ExternalASTSource {
25 /// The layout of a given record.
27 /// The size of the record.
30 /// The alignment of the record.
33 /// The offsets of the fields, in source order.
34 SmallVector<uint64_t, 8> FieldOffsets;
37 /// The set of layouts that will be overridden.
38 llvm::StringMap<Layout> Layouts;
41 /// Create a new AST source that overrides the layout of some
42 /// set of record types.
44 /// The file is the result of passing -fdump-record-layouts to a file.
45 explicit LayoutOverrideSource(StringRef Filename);
47 /// If this particular record type has an overridden layout,
48 /// return that layout.
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;
57 /// Dump the overridden layouts.