cling/lib/Interpreter/ValuePrinterInfo.cpp
Axel Naumann 17884114d5 Add value printing of namespace- or static member functions (i.e. not CXXMethods):
root [0] TIterCategory<TList>::End
(class TIterCategory<class TList> (void)) Function @0x1086ff040: 
static TIterCategory<TList> End() {
    return TIterCategory<TList>(static_cast<TIterator *>(0));
}


root [1] printf
(int (const char *, ...)) Function @0x7fff946a6650: 
int printf(const char *, ...) __attribute__((format("printf", 1, 2)))
root [2] TCollection::GetCurrentCollection
(class TCollection *(void)) Function @0x100b4cf90: 
static TCollection *GetCurrentCollection()
root [3] TMath::Sin
(Double_t (Double_t)) Function @0x10ca2d9f0:
inline Double_t Sin(Double_t x) {
    return sin(x);
}

Dump the decl (its definition, if available), which we cannot get from the type, instead put the Expr back into the ValuePrinterInfo and use its DeclRefExpr.
If we don't have one, then just dump the function type which is much less informative.


git-svn-id: http://root.cern.ch/svn/root/trunk@47775 27541ba8-7e3a-0410-8455-c3a389f83636
2012-12-02 16:47:34 +00:00

54 lines
1.7 KiB
C++

//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
// version: $Id$
// author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch>
//------------------------------------------------------------------------------
#include "cling/Interpreter/ValuePrinterInfo.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Type.h"
using namespace clang;
namespace cling {
ValuePrinterInfo::ValuePrinterInfo(Expr* E, ASTContext* Ctx)
: m_Type(), m_Expr(E), m_Context(Ctx), m_Flags(0) {
Init(E->getType());
}
ValuePrinterInfo::ValuePrinterInfo(QualType Ty, ASTContext* Ctx)
: m_Type(), m_Expr(0), m_Context(Ctx), m_Flags(0) {
Init(Ty);
}
void ValuePrinterInfo::Init(clang::QualType Ty) {
assert(!Ty.isNull() && "Type must be valid!");
assert(m_Context && "ASTContext cannot be null!");
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 (Ty->isPointerType()) {
// treat arrary-to-pointer decay as array:
QualType PQT = Ty->getPointeeType();
const Type* PTT = PQT.getTypePtr();
if (!PTT || !PTT->isArrayType()) {
m_Flags |= VPI_Ptr;
if (const RecordType* RT = dyn_cast<RecordType>(Ty.getTypePtr()))
if (RecordDecl* RD = RT->getDecl()) {
CXXRecordDecl* CRD = dyn_cast<CXXRecordDecl>(RD);
if (CRD && CRD->isPolymorphic())
m_Flags |= VPI_Polymorphic;
}
}
}
}
} // end namespace cling