clang API Documentation

LayoutOverrideSource.h
Go to the documentation of this file.
00001 //===--- LayoutOverrideSource.h --Override Record Layouts -----------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H
00011 #define LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H
00012 
00013 #include "clang/AST/ExternalASTSource.h"
00014 #include "clang/Basic/LLVM.h"
00015 #include "llvm/ADT/StringMap.h"
00016 #include "llvm/ADT/StringRef.h"
00017 
00018 namespace clang {
00019   /// \brief An external AST source that overrides the layout of
00020   /// a specified set of record types.
00021   ///
00022   /// This class is used only for testing the ability of external AST sources
00023   /// to override the layout of record types. Its input is the output format
00024   /// of the command-line argument -fdump-record-layouts.
00025   class LayoutOverrideSource : public ExternalASTSource {
00026     /// \brief The layout of a given record.
00027     struct Layout {
00028       /// \brief The size of the record.
00029       uint64_t Size;
00030       
00031       /// \brief The alignment of the record.
00032       uint64_t Align;
00033       
00034       /// \brief The offsets of the fields, in source order.
00035       SmallVector<uint64_t, 8> FieldOffsets;
00036     };
00037     
00038     /// \brief The set of layouts that will be overridden.
00039     llvm::StringMap<Layout> Layouts;
00040     
00041   public:
00042     /// \brief Create a new AST source that overrides the layout of some
00043     /// set of record types.
00044     ///
00045     /// The file is the result of passing -fdump-record-layouts to a file.
00046     explicit LayoutOverrideSource(StringRef Filename);
00047     
00048     /// \brief If this particular record type has an overridden layout,
00049     /// return that layout.
00050     bool
00051     layoutRecordType(const RecordDecl *Record,
00052        uint64_t &Size, uint64_t &Alignment,
00053        llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
00054        llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
00055        llvm::DenseMap<const CXXRecordDecl *,
00056                       CharUnits> &VirtualBaseOffsets) override;
00057     
00058     /// \brief Dump the overridden layouts.
00059     void dump();
00060   };
00061 }
00062 
00063 #endif