Don't #include Type.h in ValuePrinterInfo.h - this will be needed at runtime, too.

Instead just allocate enough data member space to store a QualType (asserting that it really is enough), and cast to and from as needed.
Ugly but it works, and it's sufficiently internal.


git-svn-id: http://root.cern.ch/svn/root/trunk@47191 27541ba8-7e3a-0410-8455-c3a389f83636
This commit is contained in:
Axel Naumann
2012-11-12 14:58:49 +00:00
parent 45adbab8dc
commit d94e4aae9c
2 changed files with 19 additions and 16 deletions

View File

@ -7,22 +7,21 @@
#ifndef CLING_VALUE_PRINTER_INFO_H
#define CLING_VALUE_PRINTER_INFO_H
#include "clang/AST/Type.h"
namespace clang {
class ASTContext;
class Expr;
class QualType;
}
namespace cling {
class ValuePrinterInfo {
private:
clang::QualType m_Type;
void* /* clang::QualType */ m_Type; // QualType buffer to prevent #include
clang::ASTContext* m_Context;
unsigned m_Flags;
void Init();
void Init(clang::QualType Ty);
public:
enum ValuePrinterFlags {
@ -33,7 +32,8 @@ namespace cling {
ValuePrinterInfo(clang::Expr* Expr, clang::ASTContext* Ctx);
ValuePrinterInfo(clang::QualType Ty, clang::ASTContext* Ctx);
const clang::QualType getType() const { return m_Type; }
const clang::QualType& getType() const {
return *reinterpret_cast<const clang::QualType*>(&m_Type); }
clang::ASTContext* getASTContext() const { return m_Context; }
unsigned getFlags() { return m_Flags; }
};

View File

@ -14,31 +14,34 @@ using namespace clang;
namespace cling {
ValuePrinterInfo::ValuePrinterInfo(Expr* E, ASTContext* Ctx)
: m_Type(E->getType()), m_Context(Ctx), m_Flags(0) {
Init();
: m_Type(), m_Context(Ctx), m_Flags(0) {
Init(E->getType());
}
ValuePrinterInfo::ValuePrinterInfo(QualType Ty, ASTContext* Ctx)
: m_Type(Ty), m_Context(Ctx), m_Flags(0) {
Init();
: m_Type(), m_Context(Ctx), m_Flags(0) {
Init(Ty);
}
void ValuePrinterInfo::Init() {
assert(!m_Type.isNull() && "Type must be valid!");
void ValuePrinterInfo::Init(clang::QualType Ty) {
assert(!Ty.isNull() && "Type must be valid!");
assert(m_Context && "ASTContext cannot be null!");
// 1. Get the flags
if (m_Type.isLocalConstQualified() || m_Type.isConstant(*m_Context)){
assert(sizeof(m_Type) >= sizeof(clang::QualType) && "m_Type too small!");
m_Type = *reinterpret_cast<void**>(&Ty);
// 1. Get the flags
if (Ty.isLocalConstQualified() || Ty.isConstant(*m_Context)){
m_Flags |= VPI_Const;
}
if (m_Type->isPointerType()) {
if (Ty->isPointerType()) {
// treat arrary-to-pointer decay as array:
QualType PQT = m_Type->getPointeeType();
QualType PQT = Ty->getPointeeType();
const Type* PTT = PQT.getTypePtr();
if (!PTT || !PTT->isArrayType()) {
m_Flags |= VPI_Ptr;
if (const RecordType* RT = dyn_cast<RecordType>(m_Type.getTypePtr()))
if (const RecordType* RT = dyn_cast<RecordType>(Ty.getTypePtr()))
if (RecordDecl* RD = RT->getDecl()) {
CXXRecordDecl* CRD = dyn_cast<CXXRecordDecl>(RD);
if (CRD && CRD->isPolymorphic())