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 "llvm/ADT/StringMap.h"
00015 #include "llvm/ADT/StringRef.h"
00016 
00017 namespace clang {
00018   /// \brief An external AST source that overrides the layout of
00019   /// a specified set of record types.
00020   ///
00021   /// This class is used only for testing the ability of external AST sources
00022   /// to override the layout of record types. Its input is the output format
00023   /// of the command-line argument -fdump-record-layouts.
00024   class LayoutOverrideSource : public ExternalASTSource {
00025     /// \brief The layout of a given record.
00026     struct Layout {
00027       /// \brief The size of the record.
00028       uint64_t Size;
00029       
00030       /// \brief The alignment of the record.
00031       uint64_t Align;
00032       
00033       /// \brief The offsets of the fields, in source order.
00034       llvm::SmallVector<uint64_t, 8> FieldOffsets;
00035     };
00036     
00037     /// \brief The set of layouts that will be overridden.
00038     llvm::StringMap<Layout> Layouts;
00039     
00040   public:
00041     /// \brief Create a new AST source that overrides the layout of some
00042     /// set of record types.
00043     ///
00044     /// The file is the result of passing -fdump-record-layouts to a file.
00045     explicit LayoutOverrideSource(llvm::StringRef Filename);
00046     
00047     /// \brief If this particular record type has an overridden layout,
00048     /// return that layout.
00049     virtual bool 
00050     layoutRecordType(const RecordDecl *Record,
00051        uint64_t &Size, uint64_t &Alignment,
00052        llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
00053        llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
00054        llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
00055     
00056     /// \brief Dump the overridden layouts.
00057     void dump();
00058   };
00059 }
00060 
00061 #endif