diff --git a/cintex/inc/Cintex/Cintex.h b/cintex/inc/Cintex/Cintex.h index 897ce0a864dbb737bf7117c9cb1e947871045a29..bdcaa3aa707be22282f11816172f6c7052e08e76 100644 --- a/cintex/inc/Cintex/Cintex.h +++ b/cintex/inc/Cintex/Cintex.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: Cintex.h,v 1.4 2006/04/28 06:40:18 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: Cintex.h,v 1.5 2006/06/21 18:39:30 brun Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -24,7 +24,8 @@ class TClass; namespace ROOT { namespace Cintex { - struct Callback : public ROOT::Reflex::ICallback { + class Callback : public ROOT::Reflex::ICallback { + public: virtual void operator () ( const ROOT::Reflex::Type& t ); virtual void operator () ( const ROOT::Reflex::Member& m ); }; diff --git a/cintex/src/CINTClassBuilder.cxx b/cintex/src/CINTClassBuilder.cxx index b836c3f93454863ac1a68c119b18bf08945895d7..27d138eb2b5cf7c26f2770fd555961fdecd2da7b 100644 --- a/cintex/src/CINTClassBuilder.cxx +++ b/cintex/src/CINTClassBuilder.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTClassBuilder.cxx,v 1.14 2006/05/30 12:29:24 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTClassBuilder.cxx,v 1.15 2006/06/21 18:39:30 brun Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -31,294 +31,303 @@ using namespace std; namespace ROOT { namespace Cintex { - void* CINTClassBuilder::sFakeObject = 0; - void* CINTClassBuilder::sFakeAddress = &CINTClassBuilder::sFakeObject; - - struct PendingBase { - Type basetype; - int tagnum; - size_t offset; - PendingBase( const Type& t, int n, size_t o) : basetype(t), tagnum(n), offset(o) {} - }; - - -// static list<PendingBase>& pendingBases() { -// static list<PendingBase> s_pendingBases; -// return s_pendingBases; -// } - - CINTClassBuilder& CINTClassBuilder::Get(const Type& cl) { - CINTClassBuilders& builders = CINTClassBuilders::Instance(); - CINTClassBuilders::iterator it = builders.find(cl); - if( it != builders.end() ) return *(*it).second; - CINTClassBuilder* builder = new CINTClassBuilder(cl); - builders[cl] = builder; - return *builder; - } - - CINTClassBuilder::CINTClassBuilder(const Type& cl) - : fClass(cl), fName(CintName(cl)), fPending(true), - fSetup_memvar(0), fSetup_memfunc(0), fBases(0) - { - fTaginfo = new G__linked_taginfo; - fTaginfo->tagnum = -1; // >> need to be pre-initialized to be understood by CINT - fTaginfo->tagtype = 'c'; - fTaginfo->tagname = fName.c_str(); - fTaginfo->tagnum = G__defined_tagname(fTaginfo->tagname, 2); - - if ( fTaginfo->tagnum < 0 ) { - Setup_tagtable(); - } - else { - G__ClassInfo info(fTaginfo->tagnum); - // if the scope is a class and was used before it might happen that - // it was assumed to be a namespace, reset to class if this was the case - if (!(info.Property() & (G__BIT_ISSTRUCT | G__BIT_ISCLASS))) { - // update from 'n' or 'a' - G__search_tagname(fTaginfo->tagname, cl.IsClass() ? 'c' : 's'); - Setup_tagtable(); + void* CINTClassBuilder::fgFakeObject = 0; + void* CINTClassBuilder::fgFakeAddress = &CINTClassBuilder::fgFakeObject; + + struct PendingBase_t { + Type fBasetype; + int fTagnum; + size_t fOffset; + PendingBase_t( const Type& t, int n, size_t o) : fBasetype(t), fTagnum(n), fOffset(o) {} + }; + + + // static list<PendingBase>& pendingBases() { + // static list<PendingBase> s_pendingBases; + // return s_pendingBases; + // } + + CINTClassBuilder& CINTClassBuilder::Get(const Type& cl) { + // run all builders + CINTClassBuilders& builders = CINTClassBuilders::Instance(); + CINTClassBuilders::iterator it = builders.find(cl); + if( it != builders.end() ) return *(*it).second; + CINTClassBuilder* builder = new CINTClassBuilder(cl); + builders[cl] = builder; + return *builder; + } + + CINTClassBuilder::CINTClassBuilder(const Type& cl) + : fClass(cl), fName(CintName(cl)), fPending(true), + fSetup_memvar(0), fSetup_memfunc(0), fBases(0) + { + // CINTClassBuilder constructor + fTaginfo = new G__linked_taginfo; + fTaginfo->tagnum = -1; // >> need to be pre-initialized to be understood by CINT + fTaginfo->tagtype = 'c'; + fTaginfo->tagname = fName.c_str(); + fTaginfo->tagnum = G__defined_tagname(fTaginfo->tagname, 2); + + if ( fTaginfo->tagnum < 0 ) { + Setup_tagtable(); } - else if ( !info.IsLoaded() ) { - Setup_tagtable(); + else { + G__ClassInfo info(fTaginfo->tagnum); + // if the scope is a class and was used before it might happen that + // it was assumed to be a namespace, reset to class if this was the case + if (!(info.Property() & (G__BIT_ISSTRUCT | G__BIT_ISCLASS))) { + // update from 'n' or 'a' + G__search_tagname(fTaginfo->tagname, cl.IsClass() ? 'c' : 's'); + Setup_tagtable(); + } + else if ( !info.IsLoaded() ) { + Setup_tagtable(); + } + else { + fPending = false; + if( Cintex::Debug() > 1 ) std::cout << "Precompiled class:" << fName << std::endl; + } } - else { - fPending = false; - if( Cintex::Debug() > 1 ) std::cout << "Precompiled class:" << fName << std::endl; + } + + CINTClassBuilder::~CINTClassBuilder() { + // CINTClassBuilder destructor + delete fTaginfo; + Free_function((void*)fSetup_memfunc); + Free_function((void*)fSetup_memvar); + } + + void CINTClassBuilder::Setup() { + // setup a Cint class + if ( fPending ) { + if ( Cintex::Debug() ) std::cout << "Building class " << fName << std::endl; + fPending = false; + + // Setup_memfunc(); // It is delayed + // Setup_memvar(); // It is delayed + Setup_inheritance(); + Setup_typetable(); } - } - } - - CINTClassBuilder::~CINTClassBuilder() { - delete fTaginfo; - Free_function((void*)fSetup_memfunc); - Free_function((void*)fSetup_memvar); - } - - void CINTClassBuilder::Setup() { - if ( fPending ) { - if ( Cintex::Debug() ) std::cout << "Building class " << fName << std::endl; - fPending = false; - - // Setup_memfunc(); // It is delayed - // Setup_memvar(); // It is delayed - Setup_inheritance(); - Setup_typetable(); - } - return; - } - - void CINTClassBuilder::Setup_tagtable() { - - // Setup scope - Scope scope = fClass.DeclaringScope(); - if ( scope ) CINTScopeBuilder::Setup(scope); - else { - scope = Scope::ByName(Tools::GetScopeName(fClass.Name(SCOPED))); - if( scope.Id() ) CINTScopeBuilder::Setup(scope); - } - - // Setup tag number - fTaginfo->tagnum = G__get_linked_tagnum(fTaginfo); - std::string comment = fClass.Properties().HasKey("comment") ? - fClass.Properties().PropertyAsString("comment").c_str() : - ""; - // Assume some minimal class functionality; see below for explanation - int rootFlag = 0; - rootFlag += 0x00020000; // No operator >> () - //if ( 0 != streamer() ) { // If a customized streamer exists - // if ( !(isIntrinsic() || getFlag(ISSTRING)) ) { - // rootFlag += 0x00010000; // Bit 1 Set - // } // - //} // - //else { // Automatic schema evolution - // rootFlag += 0x00040000; // - //} // - if ( fClass.IsAbstract() ) { - rootFlag += G__BIT_ISABSTRACT; // Abstract class - } // - // rootFlag += 0x00000100; // Class has Empty Constructor - // rootFlag += 0x00000400; // Class has destructor - //if ( 0 != fCopyConstructor ) { // - // rootFlag += 0x00000200; // Class has copy Constructor - //} // - if ( fClass.HasBase(Type::ByName("TObject"))) { - rootFlag += 0x00007000; // Class has inherits from TObject - } // - if ( fClass.TypeInfo() == typeid(std::string) ) { - rootFlag = 0x48F00; - } - - fSetup_memvar = Allocate_void_function(this, Setup_memvar_with_context ); - fSetup_memfunc = Allocate_void_function(this, Setup_memfunc_with_context ); - - G__tagtable_setup( fTaginfo->tagnum, // tag number - fClass.SizeOf(), // size - G__CPPLINK, // cpplink - rootFlag, // isabstract - comment.empty() ? 0 : comment.c_str(), // comment - fSetup_memvar, // G__setup_memvarMyClass - fSetup_memfunc); // G__setup_memfuncMyClass - } - - void CINTClassBuilder::Setup_memfunc_with_context(void* ctx) { - int autoload = G__set_class_autoloading(0); // To avoid recursive loads - ((CINTClassBuilder*)ctx)->Setup_memfunc(); - G__set_class_autoloading(autoload); - } - void CINTClassBuilder::Setup_memvar_with_context(void* ctx) { - int autoload = G__set_class_autoloading(0); // To avoid recursive loads - ((CINTClassBuilder*)ctx)->Setup_memvar(); - G__set_class_autoloading(autoload); - } - - void CINTClassBuilder::Setup_memfunc() { - - for ( size_t i = 0; i < fClass.FunctionMemberSize(); i++ ) - CINTScopeBuilder::Setup(fClass.FunctionMemberAt(i).TypeOf()); - - G__tag_memfunc_setup(fTaginfo->tagnum); - for ( size_t i = 0; i < fClass.FunctionMemberSize(); i++ ) { - Member method = fClass.FunctionMemberAt(i); - std::string n = method.Name(); - CINTFunctionBuilder::Setup(method); - } - ::G__tag_memfunc_reset(); - - } - - void CINTClassBuilder::Setup_memvar() { - - for ( size_t i = 0; i < fClass.DataMemberSize(); i++ ) - CINTScopeBuilder::Setup(fClass.DataMemberAt(i).TypeOf()); - - G__tag_memvar_setup(fTaginfo->tagnum); - - // Set placeholder for virtual function table if the class is virtual - if ( fClass.IsVirtual() ) { - G__memvar_setup((void*)0,'l',0,0,-1,-1,-1,4,"G__virtualinfo=",0,0); - } - - if ( ! IsSTL(fClass.Name(SCOPED)) ) { - for ( size_t i = 0; i < fClass.DataMemberSize(); i++ ) { - - Member dm = fClass.DataMemberAt(i); - CINTVariableBuilder::Setup(dm); + return; + } + + void CINTClassBuilder::Setup_tagtable() { + + // Setup scope + Scope scope = fClass.DeclaringScope(); + if ( scope ) CINTScopeBuilder::Setup(scope); + else { + scope = Scope::ByName(Tools::GetScopeName(fClass.Name(SCOPED))); + if( scope.Id() ) CINTScopeBuilder::Setup(scope); } - } - G__tag_memvar_reset(); - - } - - CINTClassBuilder::Bases* CINTClassBuilder::GetBases() { - if ( fBases ) return fBases; - Member getbases = fClass.MemberByName("__getBasesTable"); - if ( !getbases ) getbases = fClass.MemberByName("getBasesTable"); - if( getbases ) { - fBases = (Bases*)( getbases.Invoke().Address() ); - } - else { - static Bases s_bases; - fBases = &s_bases; - } - return fBases; - } - - void CINTClassBuilder::Setup_inheritance() { - if ( 0 == ::G__getnumbaseclass(fTaginfo->tagnum) ) { - bool IsVirtual = false; - for ( Bases::iterator it = GetBases()->begin(); it != GetBases()->end(); it++ ) - if( (*it).first.IsVirtual() ) IsVirtual = true; - - if ( IsVirtual ) { - if ( !fClass.IsAbstract() ) { - Member ctor, dtor; - for ( size_t i = 0; i < fClass.FunctionMemberSize(); i++ ) { - Member method = fClass.FunctionMemberAt(i); - if( method.IsConstructor() && method.FunctionParameterSize() == 0 ) ctor = method; - else if ( method.IsDestructor() ) dtor = method; - } - if ( ctor ) { - Object obj = fClass.Construct(); - Setup_inheritance(obj); - if ( dtor ) fClass.Destruct(obj.Address()); - } - // There is no default constructor. So, it is not a I/O class - else { - Object obj(fClass, 0); - Setup_inheritance(obj); - } - } - // Special case of "pure abstract". The offsets will be Set to 0. - // All that is necessary because ROOT does not handle virtual inheritance correctly. - // ROOT always wants to Get a real offset between base classes ans this is not - // possible without having an Instance of the object. In case of pure abstract classes - // we can not do it. So, in case the abstract class has no data members then we assume - // offsets to base class to be 0. - else if ( fClass.IsAbstract() && fClass.DataMemberSize() == 0) { - Object obj(fClass, 0); - Setup_inheritance(obj); - } - // The above fails for Gaudi Algorithms (virutal inheritance, abstract and with - // data members. Do not know What to do. - else { - Object obj(fClass, 0); - Setup_inheritance(obj); - } + + // Setup tag number + fTaginfo->tagnum = G__get_linked_tagnum(fTaginfo); + std::string comment = fClass.Properties().HasKey("comment") ? + fClass.Properties().PropertyAsString("comment").c_str() : + ""; + // Assume some minimal class functionality; see below for explanation + int rootFlag = 0; + rootFlag += 0x00020000; // No operator >> () + //if ( 0 != streamer() ) { // If a customized streamer exists + // if ( !(isIntrinsic() || getFlag(ISSTRING)) ) { + // rootFlag += 0x00010000; // Bit 1 Set + // } // + //} // + //else { // Automatic schema evolution + // rootFlag += 0x00040000; // + //} // + if ( fClass.IsAbstract() ) { + rootFlag += G__BIT_ISABSTRACT; // Abstract class + } // + // rootFlag += 0x00000100; // Class has Empty Constructor + // rootFlag += 0x00000400; // Class has destructor + //if ( 0 != fCopyConstructor ) { // + // rootFlag += 0x00000200; // Class has copy Constructor + //} // + if ( fClass.HasBase(Type::ByName("TObject"))) { + rootFlag += 0x00007000; // Class has inherits from TObject + } // + if ( fClass.TypeInfo() == typeid(std::string) ) { + rootFlag = 0x48F00; } - else { - Object obj(fClass, sFakeAddress); - Setup_inheritance(obj); + + fSetup_memvar = Allocate_void_function(this, Setup_memvar_with_context ); + fSetup_memfunc = Allocate_void_function(this, Setup_memfunc_with_context ); + + G__tagtable_setup( fTaginfo->tagnum, // tag number + fClass.SizeOf(), // size + G__CPPLINK, // cpplink + rootFlag, // isabstract + comment.empty() ? 0 : comment.c_str(), // comment + fSetup_memvar, // G__setup_memvarMyClass + fSetup_memfunc); // G__setup_memfuncMyClass + } + + void CINTClassBuilder::Setup_memfunc_with_context(void* ctx) { + // setup a CINT member function + int autoload = G__set_class_autoloading(0); // To avoid recursive loads + ((CINTClassBuilder*)ctx)->Setup_memfunc(); + G__set_class_autoloading(autoload); + } + void CINTClassBuilder::Setup_memvar_with_context(void* ctx) { + // setup a CINT data member + int autoload = G__set_class_autoloading(0); // To avoid recursive loads + ((CINTClassBuilder*)ctx)->Setup_memvar(); + G__set_class_autoloading(autoload); + } + + void CINTClassBuilder::Setup_memfunc() { + // setup a CINT member function + for ( size_t i = 0; i < fClass.FunctionMemberSize(); i++ ) + CINTScopeBuilder::Setup(fClass.FunctionMemberAt(i).TypeOf()); + + G__tag_memfunc_setup(fTaginfo->tagnum); + for ( size_t i = 0; i < fClass.FunctionMemberSize(); i++ ) { + Member method = fClass.FunctionMemberAt(i); + std::string n = method.Name(); + CINTFunctionBuilder::Setup(method); } - } - } - void CINTClassBuilder::Setup_inheritance(Object& obj) { - if ( ! IsSTL(fClass.Name(SCOPED)) ) { - if ( 0 == ::G__getnumbaseclass(fTaginfo->tagnum) ) { - for ( Bases::iterator it = GetBases()->begin(); it != GetBases()->end(); it++ ) { - Base base = it->first; - int level = it->second; - Type btype = base.ToType(); - CINTScopeBuilder::Setup(btype); - std::string b_nam = CintName(btype); - int b_tagnum = CintTag(b_nam); - // Get the Offset. Treat differently virtual and non-virtual inheritance - size_t offset; - long type = (level == 0) ? G__ISDIRECTINHERIT : 0; - if ( base.IsVirtual() ) { - if (obj.Address()) { - offset = ( * base.OffsetFP())(obj.Address()); - } - else { - offset = (size_t)base.OffsetFP(); - type = type | G__ISVIRTUALBASE; - } - } - else { - offset = base.Offset(sFakeAddress); - } - if( Cintex::Debug() > 1 ) { - std::cout << fClass.Name(SCOPED) << " Base:" << btype.Name(SCOPED) << " Offset:" << offset << std::endl; - } - int mod = base.IsPublic() ? G__PUBLIC : ( base.IsPrivate() ? G__PRIVATE : G__PROTECTED ); - ::G__inheritance_setup(fTaginfo->tagnum, b_tagnum, offset, mod, type ); - Object bobj(btype,(char*)obj.Address() + offset); - } + ::G__tag_memfunc_reset(); + + } + + void CINTClassBuilder::Setup_memvar() { + // setup a CINT data member + for ( size_t i = 0; i < fClass.DataMemberSize(); i++ ) + CINTScopeBuilder::Setup(fClass.DataMemberAt(i).TypeOf()); + + G__tag_memvar_setup(fTaginfo->tagnum); + + // Set placeholder for virtual function table if the class is virtual + if ( fClass.IsVirtual() ) { + G__memvar_setup((void*)0,'l',0,0,-1,-1,-1,4,"G__virtualinfo=",0,0); + } + + if ( ! IsSTL(fClass.Name(SCOPED)) ) { + for ( size_t i = 0; i < fClass.DataMemberSize(); i++ ) { + + Member dm = fClass.DataMemberAt(i); + CINTVariableBuilder::Setup(dm); + } } - } - } + G__tag_memvar_reset(); - void CINTClassBuilder::Setup_typetable() { + } - for (Type_Iterator ti = fClass.SubType_Begin(); ti != fClass.SubType_End(); ++ti) { - if (Cintex::PropagateClassTypedefs() && ti->IsTypedef() ) { - CINTTypedefBuilder::Setup(*ti); - CINTScopeBuilder::Setup(ti->ToType()); + CINTClassBuilder::Bases* CINTClassBuilder::GetBases() { + // get base classes + if ( fBases ) return fBases; + Member getbases = fClass.MemberByName("__getBasesTable"); + if ( !getbases ) getbases = fClass.MemberByName("getBasesTable"); + if( getbases ) { + fBases = (Bases*)( getbases.Invoke().Address() ); + } + else { + static Bases s_bases; + fBases = &s_bases; } - else if (Cintex::PropagateClassEnums() && ti->IsEnum() ) { - CINTEnumBuilder::Setup(*ti); + return fBases; + } + + void CINTClassBuilder::Setup_inheritance() { + // setup inheritance info + if ( 0 == ::G__getnumbaseclass(fTaginfo->tagnum) ) { + bool isVirtual = false; + for ( Bases::iterator it = GetBases()->begin(); it != GetBases()->end(); it++ ) + if( (*it).first.IsVirtual() ) isVirtual = true; + + if ( isVirtual ) { + if ( !fClass.IsAbstract() ) { + Member ctor, dtor; + for ( size_t i = 0; i < fClass.FunctionMemberSize(); i++ ) { + Member method = fClass.FunctionMemberAt(i); + if( method.IsConstructor() && method.FunctionParameterSize() == 0 ) ctor = method; + else if ( method.IsDestructor() ) dtor = method; + } + if ( ctor ) { + Object obj = fClass.Construct(); + Setup_inheritance(obj); + if ( dtor ) fClass.Destruct(obj.Address()); + } + // There is no default constructor. So, it is not a I/O class + else { + Object obj(fClass, 0); + Setup_inheritance(obj); + } + } + // Special case of "pure abstract". The offsets will be Set to 0. + // All that is necessary because ROOT does not handle virtual inheritance correctly. + // ROOT always wants to Get a real offset between base classes ans this is not + // possible without having an Instance of the object. In case of pure abstract classes + // we can not do it. So, in case the abstract class has no data members then we assume + // offsets to base class to be 0. + else if ( fClass.IsAbstract() && fClass.DataMemberSize() == 0) { + Object obj(fClass, 0); + Setup_inheritance(obj); + } + // The above fails for Gaudi Algorithms (virutal inheritance, abstract and with + // data members. Do not know What to do. + else { + Object obj(fClass, 0); + Setup_inheritance(obj); + } + } + else { + Object obj(fClass, fgFakeAddress); + Setup_inheritance(obj); + } + } + } + void CINTClassBuilder::Setup_inheritance(Object& obj) { + // setup inheritance info + if ( ! IsSTL(fClass.Name(SCOPED)) ) { + if ( 0 == ::G__getnumbaseclass(fTaginfo->tagnum) ) { + for ( Bases::iterator it = GetBases()->begin(); it != GetBases()->end(); it++ ) { + Base base = it->first; + int level = it->second; + Type btype = base.ToType(); + CINTScopeBuilder::Setup(btype); + std::string b_nam = CintName(btype); + int b_tagnum = CintTag(b_nam); + // Get the Offset. Treat differently virtual and non-virtual inheritance + size_t offset; + long int type = (level == 0) ? G__ISDIRECTINHERIT : 0; + if ( base.IsVirtual() ) { + if (obj.Address()) { + offset = ( * base.OffsetFP())(obj.Address()); + } + else { + offset = (size_t)base.OffsetFP(); + type = type | G__ISVIRTUALBASE; + } + } + else { + offset = base.Offset(fgFakeAddress); + } + if( Cintex::Debug() > 1 ) { + std::cout << fClass.Name(SCOPED) << " Base:" << btype.Name(SCOPED) << " Offset:" << offset << std::endl; + } + int mod = base.IsPublic() ? G__PUBLIC : ( base.IsPrivate() ? G__PRIVATE : G__PROTECTED ); + ::G__inheritance_setup(fTaginfo->tagnum, b_tagnum, offset, mod, type ); + Object bobj(btype,(char*)obj.Address() + offset); + } + } + } + } + + void CINTClassBuilder::Setup_typetable() { + // setup types + for (Type_Iterator ti = fClass.SubType_Begin(); ti != fClass.SubType_End(); ++ti) { + if (Cintex::PropagateClassTypedefs() && ti->IsTypedef() ) { + CINTTypedefBuilder::Setup(*ti); + CINTScopeBuilder::Setup(ti->ToType()); + } + else if (Cintex::PropagateClassEnums() && ti->IsEnum() ) { + CINTEnumBuilder::Setup(*ti); + } } - } - } + } }} diff --git a/cintex/src/CINTClassBuilder.h b/cintex/src/CINTClassBuilder.h index 2c397f30849556f16c16642cf38d389c89ecf3b8..23153aca1acf62d47471625b5842f7098052207d 100644 --- a/cintex/src/CINTClassBuilder.h +++ b/cintex/src/CINTClassBuilder.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTClassBuilder.h,v 1.3 2005/11/17 14:12:33 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTClassBuilder.h,v 1.4 2006/04/13 14:42:48 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -45,14 +45,14 @@ namespace ROOT { static void Setup_memfunc_with_context(void*); static void Setup_memvar_with_context(void*); private: - static void* sFakeObject; - static void* sFakeAddress; + static void* fgFakeObject; + static void* fgFakeAddress; ROOT::Reflex::Type fClass; G__linked_taginfo* fTaginfo; std::string fName; bool fPending; - FuncVoidPtr fSetup_memvar; - FuncVoidPtr fSetup_memfunc; + FuncVoidPtr_t fSetup_memvar; + FuncVoidPtr_t fSetup_memfunc; Bases* fBases; class CINTClassBuilders : public std::map<ROOT::Reflex::Type, CINTClassBuilder*> { diff --git a/cintex/src/CINTEnumBuilder.cxx b/cintex/src/CINTEnumBuilder.cxx index 14888befbf1f3f0cfe03cd0ee65d41e81cb6a9f5..2b95aeea6ff50e81303bb2a79127a4a2734ad466 100644 --- a/cintex/src/CINTEnumBuilder.cxx +++ b/cintex/src/CINTEnumBuilder.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTEnumBuilder.cxx,v 1.7 2006/01/20 17:21:18 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTEnumBuilder.cxx,v 1.8 2006/06/13 08:19:01 brun Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -25,64 +25,65 @@ using namespace std; namespace ROOT { namespace Cintex { - void CINTEnumBuilder::Setup(const Type& e) { - if ( e.IsEnum() ) { - string name = CintName(e.Name(SCOPED)); - int tagnum = ::G__defined_tagname(name.c_str(), 2); - if( -1 != tagnum ) return; + void CINTEnumBuilder::Setup(const Type& e) { + // setup enum info + if ( e.IsEnum() ) { + string name = CintName(e.Name(SCOPED)); + int tagnum = ::G__defined_tagname(name.c_str(), 2); + if( -1 != tagnum ) return; - if ( Cintex::Debug() ) { - cout << "Building enum " << name << endl; - } + if ( Cintex::Debug() ) { + cout << "Building enum " << name << endl; + } - Scope scope = e.DeclaringScope(); - CINTScopeBuilder::Setup( scope ); - bool isCPPMacroEnum = name == "$CPP_MACROS"; + Scope scope = e.DeclaringScope(); + CINTScopeBuilder::Setup( scope ); + bool isCPPMacroEnum = name == "$CPP_MACROS"; - if (!isCPPMacroEnum) { - G__linked_taginfo taginfo; - taginfo.tagnum = -1; - taginfo.tagtype = 'e'; - taginfo.tagname = name.c_str(); - G__get_linked_tagnum(&taginfo); - tagnum = taginfo.tagnum; - ::G__tagtable_setup( tagnum, sizeof(int), -1, 0,(char*)NULL, NULL, NULL); - } + if (!isCPPMacroEnum) { + G__linked_taginfo taginfo; + taginfo.tagnum = -1; + taginfo.tagtype = 'e'; + taginfo.tagname = name.c_str(); + G__get_linked_tagnum(&taginfo); + tagnum = taginfo.tagnum; + ::G__tagtable_setup( tagnum, sizeof(int), -1, 0,(char*)NULL, NULL, NULL); + } - //--- setup enum values ------- - int isstatic; - if ( scope.IsTopScope() ) { - isstatic = -1; - /* Setting up global variables */ - ::G__resetplocal(); - } - else { - string sname = CintName(scope.Name(SCOPED)); - int stagnum = ::G__defined_tagname(sname.c_str(), 2); - isstatic = -2; - if( -1 == stagnum ) return; - ::G__tag_memvar_setup(stagnum); - } - for ( size_t i = 0; i < e.DataMemberSize(); i++ ) { - stringstream s; - s << e.DataMemberAt(i).Name() << "="; - if ( isCPPMacroEnum ) s << (const char*)e.DataMemberAt(i).Offset(); - else s << (int)e.DataMemberAt(i).Offset(); + //--- setup enum values ------- + int isstatic; + if ( scope.IsTopScope() ) { + isstatic = -1; + /* Setting up global variables */ + ::G__resetplocal(); + } + else { + string sname = CintName(scope.Name(SCOPED)); + int stagnum = ::G__defined_tagname(sname.c_str(), 2); + isstatic = -2; + if( -1 == stagnum ) return; + ::G__tag_memvar_setup(stagnum); + } + for ( size_t i = 0; i < e.DataMemberSize(); i++ ) { + stringstream s; + s << e.DataMemberAt(i).Name() << "="; + if ( isCPPMacroEnum ) s << (const char*)e.DataMemberAt(i).Offset(); + else s << (int)e.DataMemberAt(i).Offset(); - string item = s.str(); - if ( Cintex::Debug() ) cout << " item " << i << " " << item <<endl; - if ( isCPPMacroEnum ) - ::G__memvar_setup((void*)G__PVOID, 'p', 0, 0, -1, -1, -1, 1, item.c_str(), 1, (char*)NULL); - else - ::G__memvar_setup((void*)G__PVOID, 'i', 0, 1, tagnum, -1, isstatic, 1, item.c_str(), 0, (char*)NULL); - } - if ( scope.IsTopScope() ) { - ::G__resetglobalenv(); - } - else { - ::G__tag_memvar_reset(); - } + string item = s.str(); + if ( Cintex::Debug() ) cout << " item " << i << " " << item <<endl; + if ( isCPPMacroEnum ) + ::G__memvar_setup((void*)G__PVOID, 'p', 0, 0, -1, -1, -1, 1, item.c_str(), 1, (char*)NULL); + else + ::G__memvar_setup((void*)G__PVOID, 'i', 0, 1, tagnum, -1, isstatic, 1, item.c_str(), 0, (char*)NULL); + } + if ( scope.IsTopScope() ) { + ::G__resetglobalenv(); + } + else { + ::G__tag_memvar_reset(); + } - } - } + } + } }} diff --git a/cintex/src/CINTEnumBuilder.h b/cintex/src/CINTEnumBuilder.h index 2d893f6819b82d5cfaefc67a4b4737389c4930f5..0318cf3c3b60801d7587135683c446f6e5f6bbb7 100644 --- a/cintex/src/CINTEnumBuilder.h +++ b/cintex/src/CINTEnumBuilder.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name:$:$Id:$ +// @(#)root/cintex:$Name: $:$Id: CINTEnumBuilder.h,v 1.3 2005/11/17 14:12:33 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -19,13 +19,13 @@ */ namespace ROOT { namespace Cintex { - /* @class CINTEnumBuilder CINTEnumBuilder.h - */ - class CINTEnumBuilder { - public: - // Declare typedef to CINT - static void Setup(const ROOT::Reflex::Type& t); - }; -}} + /* @class CINTEnumBuilder CINTEnumBuilder.h + */ + class CINTEnumBuilder { + public: + // Declare typedef to CINT + static void Setup(const ROOT::Reflex::Type& t); + }; + }} #endif // ROOT_Cintex_CINTEnumBuilder diff --git a/cintex/src/CINTFunctionBuilder.cxx b/cintex/src/CINTFunctionBuilder.cxx index 6848b605e4d7a9572244504dc91f53d5805ba19b..d3ac592518e5c16021148d90a95d756d04277af9 100644 --- a/cintex/src/CINTFunctionBuilder.cxx +++ b/cintex/src/CINTFunctionBuilder.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTFunctionBuilder.cxx,v 1.8 2006/05/30 08:14:13 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTFunctionBuilder.cxx,v 1.9 2006/06/14 18:15:30 pcanal Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -23,127 +23,131 @@ using namespace std; namespace ROOT { namespace Cintex { - CINTFunctionBuilder::CINTFunctionBuilder(const ROOT::Reflex::Member& m) - : fFunction(m) { } - - CINTFunctionBuilder::~CINTFunctionBuilder() { - } - - void CINTFunctionBuilder::Setup() { - - Scope scope = fFunction.DeclaringScope(); - bool global = scope.IsTopScope(); - - if ( global ) { - G__lastifuncposition(); - } - else { - CINTScopeBuilder::Setup(scope); - string sname = scope.Name(SCOPED); - int ns_tag = G__search_tagname(sname.c_str(),'n'); - G__tag_memfunc_setup(ns_tag); - } - - Setup(fFunction); - - if ( global ) { - G__resetifuncposition(); - } - else { - G__tag_memfunc_reset(); - } + CINTFunctionBuilder::CINTFunctionBuilder(const ROOT::Reflex::Member& m) + : fFunction(m) { + // CINTFunctionBuilder constructor + } + + CINTFunctionBuilder::~CINTFunctionBuilder() { + // CINTFunctionBuilder destructor + } + + void CINTFunctionBuilder::Setup() { + // setup a CINT function + Scope scope = fFunction.DeclaringScope(); + bool global = scope.IsTopScope(); + + if ( global ) { + G__lastifuncposition(); + } + else { + CINTScopeBuilder::Setup(scope); + string sname = scope.Name(SCOPED); + int ns_tag = G__search_tagname(sname.c_str(),'n'); + G__tag_memfunc_setup(ns_tag); + } + + Setup(fFunction); + + if ( global ) { + G__resetifuncposition(); + } + else { + G__tag_memfunc_reset(); + } - return; - } - - void CINTFunctionBuilder::Setup(const Member& function) { - Type cl = Type::ByName(function.DeclaringScope().Name(SCOPED)); - int access = G__PUBLIC; - int const_ness = 0; - int virtuality = 0; - int reference = 0; - int memory_type = 1; // G__LOCAL; // G__AUTO=-1 - int tagnum = CintTag(function.DeclaringScope().Name(SCOPED)); - - //---Alocate a context - StubContext* stub_context = new StubContext(function, cl); - - //---Function Name and hash value - string funcname = function.Name(); - int hash, tmp; - - //---Return type ---------------- - Type rt = function.TypeOf().ReturnType(); - reference = rt.IsReference() ? 1 : 0; - int ret_typedeft = -1; - if ( rt.IsTypedef()) { - ret_typedeft = CINTTypedefBuilder::Setup(rt); - rt = rt.ToType(FINAL); - } - //CINTScopeBuilder::Setup( rt ); - CintTypeDesc ret_desc = CintType( rt ); - char ret_type = rt.IsPointer() ? (ret_desc.first - ('a'-'A')) : ret_desc.first; - int ret_tag = CintTag( ret_desc.second ); - - if( function.IsOperator() ) { - // remove space between "operator" keywork and the actual operator - if ( funcname[8] == ' ' && ! isalpha( funcname[9] ) ) - funcname = "operator" + funcname.substr(9); - } - G__InterfaceMethod stub; - if( function.IsConstructor() ) { - //stub = Constructor_stub; - stub = Allocate_stub_function(stub_context, & Constructor_stub_with_context); - funcname = G__ClassInfo(tagnum).Name(); - ret_tag = tagnum; - } - else if ( function.IsDestructor() ) { - //stub = Destructor_stub; - stub = Allocate_stub_function(stub_context, & Destructor_stub_with_context); - funcname = "~"; - funcname += G__ClassInfo(tagnum).Name(); - } - else { - //stub = Method_stub; - stub = Allocate_stub_function(stub_context, & Method_stub_with_context); - } - if ( function.IsPrivate() ) - access = G__PRIVATE; - else if ( function.IsProtected() ) - access = G__PROTECTED; - else if ( function.IsPublic() ) - access = G__PUBLIC; - - if ( function.TypeOf().IsConst() ) - const_ness = G__CONSTFUNC; - if ( function.IsVirtual() ) - virtuality = 1; - if ( function.IsStatic() ) - memory_type += G__CLASSSCOPE; - - string signature = CintSignature(function); - int nparam = function.TypeOf().FunctionParameterSize(); - //---Cint function hash - G__hash(funcname, hash, tmp); - - G__usermemfunc_setup( const_cast<char*>(funcname.c_str()), // function Name - hash, // function Name hash value - (int (*)(void))stub, // method stub function - ret_type, // return type (void) - ret_tag, // return TypeNth tag number - ret_typedeft, // typedef number - reference, // reftype - nparam, // number of paramerters - memory_type, // memory type - access, // access type - const_ness, // CV qualifiers - const_cast<char*>(signature.c_str()), // signature - (char*)NULL, // comment line - (void*)NULL, // true2pf - virtuality, // virtuality - stub_context // user ParameterNth - ); - - } + return; + } + + void CINTFunctionBuilder::Setup(const Member& function) { + // setup a CINT function + Type cl = Type::ByName(function.DeclaringScope().Name(SCOPED)); + int access = G__PUBLIC; + int const_ness = 0; + int virtuality = 0; + int reference = 0; + int memory_type = 1; // G__LOCAL; // G__AUTO=-1 + int tagnum = CintTag(function.DeclaringScope().Name(SCOPED)); + + //---Alocate a context + StubContext_t* stub_context = new StubContext_t(function, cl); + + //---Function Name and hash value + string funcname = function.Name(); + int hash, tmp; + + //---Return type ---------------- + Type rt = function.TypeOf().ReturnType(); + reference = rt.IsReference() ? 1 : 0; + int ret_typedeft = -1; + if ( rt.IsTypedef()) { + ret_typedeft = CINTTypedefBuilder::Setup(rt); + rt = rt.ToType(FINAL); + } + //CINTScopeBuilder::Setup( rt ); + CintTypeDesc ret_desc = CintType( rt ); + char ret_type = rt.IsPointer() ? (ret_desc.first - ('a'-'A')) : ret_desc.first; + int ret_tag = CintTag( ret_desc.second ); + + if( function.IsOperator() ) { + // remove space between "operator" keywork and the actual operator + if ( funcname[8] == ' ' && ! isalpha( funcname[9] ) ) + funcname = "operator" + funcname.substr(9); + } + G__InterfaceMethod stub; + if( function.IsConstructor() ) { + //stub = Constructor_stub; + stub = Allocate_stub_function(stub_context, & Constructor_stub_with_context); + funcname = G__ClassInfo(tagnum).Name(); + ret_tag = tagnum; + } + else if ( function.IsDestructor() ) { + //stub = Destructor_stub; + stub = Allocate_stub_function(stub_context, & Destructor_stub_with_context); + funcname = "~"; + funcname += G__ClassInfo(tagnum).Name(); + } + else { + //stub = Method_stub; + stub = Allocate_stub_function(stub_context, & Method_stub_with_context); + } + if ( function.IsPrivate() ) + access = G__PRIVATE; + else if ( function.IsProtected() ) + access = G__PROTECTED; + else if ( function.IsPublic() ) + access = G__PUBLIC; + + if ( function.TypeOf().IsConst() ) + const_ness = G__CONSTFUNC; + if ( function.IsVirtual() ) + virtuality = 1; + if ( function.IsStatic() ) + memory_type += G__CLASSSCOPE; + + string signature = CintSignature(function); + int nparam = function.TypeOf().FunctionParameterSize(); + //---Cint function hash + G__hash(funcname, hash, tmp); + + G__usermemfunc_setup( const_cast<char*>(funcname.c_str()), // function Name + hash, // function Name hash value + (int (*)(void))stub, // method stub function + ret_type, // return type (void) + ret_tag, // return TypeNth tag number + ret_typedeft, // typedef number + reference, // reftype + nparam, // number of paramerters + memory_type, // memory type + access, // access type + const_ness, // CV qualifiers + const_cast<char*>(signature.c_str()), // signature + (char*)NULL, // comment line + (void*)NULL, // true2pf + virtuality, // virtuality + stub_context // user ParameterNth + ); + + } }} diff --git a/cintex/src/CINTFunctionBuilder.h b/cintex/src/CINTFunctionBuilder.h index 690eb24927bd6843d76ef10320d24d7d91758a7c..b1d6fe1de17438ef5c3ae5a0bf03c36c0dd0f195 100644 --- a/cintex/src/CINTFunctionBuilder.h +++ b/cintex/src/CINTFunctionBuilder.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTFunctionBuilder.h,v 1.3 2005/11/17 14:12:33 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTFunctionBuilder.h,v 1.4 2005/12/12 09:12:27 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -16,19 +16,19 @@ #include "CINTdefs.h" namespace ROOT { - namespace Cintex { + namespace Cintex { - class CINTFunctionBuilder { - public: - CINTFunctionBuilder(const ROOT::Reflex::Member& m); - ~CINTFunctionBuilder(); - void Setup(void); - static void Setup(const ROOT::Reflex::Member&); - private: - const ROOT::Reflex::Member& fFunction; - }; + class CINTFunctionBuilder { + public: + CINTFunctionBuilder(const ROOT::Reflex::Member& m); + ~CINTFunctionBuilder(); + void Setup(void); + static void Setup(const ROOT::Reflex::Member&); + private: + const ROOT::Reflex::Member& fFunction; + }; - } + } } #endif // ROOT_Cintex_CINTFunctionBuilder diff --git a/cintex/src/CINTFunctional.cxx b/cintex/src/CINTFunctional.cxx index b0e0f14b700d912d61a1fe518530b31650b49a1d..9212bbfc0a441affed82da4bcd506fcaa3167ffd 100644 --- a/cintex/src/CINTFunctional.cxx +++ b/cintex/src/CINTFunctional.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTFunctional.cxx,v 1.14 2006/02/09 20:36:54 pcanal Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTFunctional.cxx,v 1.15 2006/02/23 18:29:26 brun Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -16,7 +16,7 @@ #include "CINTFunctional.h" #ifdef __linux - #include <sys/mman.h> +#include <sys/mman.h> #endif using namespace ROOT::Reflex; @@ -24,376 +24,388 @@ using namespace std; namespace ROOT { namespace Cintex { -class StubContexts : public vector<StubContext*> { - public: - static StubContexts& Instance() { - static StubContexts s_cont; - return s_cont; - } - private: - StubContexts() {} - ~StubContexts() { - for( vector<StubContext*>::iterator j = begin(); j != end(); ++j) - delete (*j); - clear(); - } - }; - -StubContext::StubContext(const Member& mem, const Type& cl ) - : fMethodCode(0), fMember(mem), fClass(cl), fNewdelfuncs(0), fInitialized(false) -{ - StubContexts::Instance().push_back(this); -} + class StubContexts : public vector<StubContext_t*> { + public: + static StubContexts& Instance() { + static StubContexts s_cont; + return s_cont; + } + private: + StubContexts() {} + ~StubContexts() { + for( vector<StubContext_t*>::iterator j = begin(); j != end(); ++j) + delete (*j); + clear(); + } + }; -StubContext::~StubContext() { - if ( fMethodCode ) Free_function( (void*)fMethodCode ); -} + StubContext_t::StubContext_t(const Member& mem, const Type& cl ) + : fMethodCode(0), fMember(mem), fClass(cl), fNewdelfuncs(0), fInitialized(false) + { + // push back a context + StubContexts::Instance().push_back(this); + } -void StubContext::Initialize() { - fFunction = fMember.TypeOf(); - fNpar = fFunction.FunctionParameterSize(); - fStub = fMember.Stubfunction(); - fStubctx = fMember.Stubcontext(); - fParam.resize(fNpar); - fParcnv.resize(fNpar); - fTreat.resize(fNpar); - // pre-process paramters and remember the treatment that is needed to be done - for (int i = 0; i < fNpar; i++ ) { - Type pt = fFunction.FunctionParameterAt(i); - while ( pt.IsTypedef() ) pt = pt.ToType(); - if ( pt.IsFundamental() || pt.IsEnum() ) - if ( pt.TypeInfo() == typeid(float) ) fTreat[i] = 'f'; - else if ( pt.TypeInfo() == typeid(double) ) fTreat[i] = 'd'; - else if ( pt.TypeInfo() == typeid(long double) ) fTreat[i] = 'q'; - else if ( pt.TypeInfo() == typeid(long long) ) fTreat[i] = 'n'; - else if ( pt.TypeInfo() == typeid(unsigned long long) ) fTreat[i] = 'm'; - else fTreat[i] = 'i'; - else if ( pt.IsReference() ) - if( pt.IsPointer() ) fTreat[i] = '*'; - else fTreat[i] = '&'; - //fTreat[i] = '&'; - else fTreat[i] = 'u'; - } + StubContext_t::~StubContext_t() { + // destructor + if ( fMethodCode ) Free_function( (void*)fMethodCode ); + } - // pre-process result block - Type rt = fFunction.ReturnType(); - fRet_byref = rt.IsReference(); - while ( rt.IsTypedef() ) rt = rt.ToType(); - fRet_desc = CintType( rt ); - fRet_tag = CintTag( fRet_desc.second ); - fRet_byvalue = !fRet_byref && !rt.IsFundamental() && !rt.IsPointer() && - !rt.IsArray() && !rt.IsEnum(); - if ( rt.IsPointer() ) fRet_desc.first = (fRet_desc.first - ('a'-'A')); + void StubContext_t::Initialize() { + // initialise a context + fFunction = fMember.TypeOf(); + fNpar = fFunction.FunctionParameterSize(); + fStub = fMember.Stubfunction(); + fStubctx = fMember.Stubcontext(); + fParam.resize(fNpar); + fParcnv.resize(fNpar); + fTreat.resize(fNpar); + // pre-process paramters and remember the treatment that is needed to be done + for (int i = 0; i < fNpar; i++ ) { + Type pt = fFunction.FunctionParameterAt(i); + while ( pt.IsTypedef() ) pt = pt.ToType(); + if ( pt.IsFundamental() || pt.IsEnum() ) + if ( pt.TypeInfo() == typeid(float) ) fTreat[i] = 'f'; + else if ( pt.TypeInfo() == typeid(double) ) fTreat[i] = 'd'; + else if ( pt.TypeInfo() == typeid(long double) ) fTreat[i] = 'q'; + else if ( pt.TypeInfo() == typeid(long long) ) fTreat[i] = 'n'; + else if ( pt.TypeInfo() == typeid(unsigned long long) ) fTreat[i] = 'm'; + else fTreat[i] = 'i'; + else if ( pt.IsReference() ) + if( pt.IsPointer() ) fTreat[i] = '*'; + else fTreat[i] = '&'; + //fTreat[i] = '&'; + else fTreat[i] = 'u'; + } - // for constructor the result block is the class itself - if( fClass) fClass_tag = CintTag( CintType(fClass).second ); - else fClass_tag = 0; - // for constructor or destructor locate newdelfunctions pointers - if ( fMember.IsConstructor() || fMember.IsDestructor() ) { - Member getnewdelfuncs = fClass.MemberByName("__getNewDelFunctions"); - if( getnewdelfuncs ) { - fNewdelfuncs = (NewDelFunctions*)( getnewdelfuncs.Invoke().Address() ); - } - } - // Set initialized flag - fInitialized = true; -} + // pre-process result block + Type rt = fFunction.ReturnType(); + fRet_byref = rt.IsReference(); + while ( rt.IsTypedef() ) rt = rt.ToType(); + fRet_desc = CintType( rt ); + fRet_tag = CintTag( fRet_desc.second ); + fRet_byvalue = !fRet_byref && !rt.IsFundamental() && !rt.IsPointer() && + !rt.IsArray() && !rt.IsEnum(); + if ( rt.IsPointer() ) fRet_desc.first = (fRet_desc.first - ('a'-'A')); -void StubContext::ProcessParam(G__param* libp) { - fParam.resize(libp->paran); - for (int i = 0; i < libp->paran; i++ ) { - switch(fTreat[i]) { - case 'd': fParcnv[i].obj.d = G__double(libp->para[i]);fParam[i] = &fParcnv[i].obj.d; break; - case 'f': fParcnv[i].obj.fl = (float)G__double(libp->para[i]);fParam[i] = &fParcnv[i].obj.fl; break; - case 'n': fParcnv[i].obj.ll = G__Longlong(libp->para[i]);fParam[i] = &fParcnv[i].obj.ll; break; - case 'm': fParcnv[i].obj.ull= G__ULonglong(libp->para[i]);fParam[i] = &fParcnv[i].obj.ull; break; - case 'q': fParcnv[i].obj.ld = G__Longdouble(libp->para[i]);fParam[i] = &fParcnv[i].obj.ld; break; - case 'i': fParcnv[i].obj.i = G__int(libp->para[i]); fParam[i] = &fParcnv[i].obj.i; break; - case '*': fParam[i] = libp->para[i].ref ? (void*)libp->para[i].ref : &libp->para[i].obj.i; break; - case '&': fParam[i] = (void*)libp->para[i].ref; break; - case 'u': fParam[i] = (void*)libp->para[i].obj.i; break; - } - } -} + // for constructor the result block is the class itself + if( fClass) fClass_tag = CintTag( CintType(fClass).second ); + else fClass_tag = 0; + // for constructor or destructor locate newdelfunctions pointers + if ( fMember.IsConstructor() || fMember.IsDestructor() ) { + Member getnewdelfuncs = fClass.MemberByName("__getNewDelFunctions"); + if( getnewdelfuncs ) { + fNewdelfuncs = (NewDelFunctions_t*)( getnewdelfuncs.Invoke().Address() ); + } + } + // Set initialized flag + fInitialized = true; + } -void StubContext::ProcessResult(G__value* result, void* obj) { - char t = fRet_desc.first; - result->type = t; - switch( t ) { - case 'y': G__setnull(result); break; - case 'Y': Converter<long>::toCint (result, obj); break; - case 'g': Converter<bool>::toCint (result, obj); break; - case 'G': Converter<int>::toCint (result, obj); break; - case 'c': Converter<char>::toCint (result, obj); break; - case 'C': Converter<int>::toCint (result, obj); break; - case 'b': Converter<unsigned char>::toCint (result, obj); break; - case 'B': Converter<int>::toCint (result, obj); break; - case 's': Converter<short>::toCint (result, obj); break; - case 'S': Converter<int>::toCint (result, obj); break; - case 'r': Converter<unsigned short>::toCint(result, obj); break; - case 'R': Converter<int>::toCint (result, obj); break; - case 'i': Converter<int>::toCint (result, obj); break; - case 'I': Converter<int>::toCint (result, obj); break; - case 'h': Converter<unsigned int>::toCint (result, obj); break; - case 'H': Converter<int>::toCint (result, obj); break; - case 'l': Converter<long>::toCint (result, obj); break; - case 'L': Converter<int>::toCint (result, obj); break; - case 'k': Converter<unsigned long>::toCint (result, obj); break; - case 'K': Converter<int>::toCint (result, obj); break; - case 'n': Converter<long long>::toCint (result, obj); break; - case 'N': Converter<int>::toCint (result, obj); break; - case 'm': Converter<unsigned long long>::toCint (result, obj); break; - case 'M': Converter<int>::toCint (result, obj); break; - case 'f': Converter<float>::toCint (result, obj); break; - case 'F': Converter<int>::toCint (result, obj); break; - case 'd': Converter<double>::toCint (result, obj); break; - case 'D': Converter<int>::toCint (result, obj); break; - case 'q': Converter<long double>::toCint (result, obj); break; - case 'Q': Converter<int>::toCint (result, obj); break; - case 'u': Converter<long>::toCint (result, obj); - result->ref = (long)obj; - result->tagnum = fRet_tag; - break; - case 'U': - if ( fRet_byref) { - Converter<long>::toCint(result, *(void**)obj); - result->ref = (long)obj; + void StubContext_t::ProcessParam(G__param* libp) { + // process param type + fParam.resize(libp->paran); + for (int i = 0; i < libp->paran; i++ ) { + switch(fTreat[i]) { + case 'd': fParcnv[i].obj.d = G__double(libp->para[i]);fParam[i] = &fParcnv[i].obj.d; break; + case 'f': fParcnv[i].obj.fl = (float)G__double(libp->para[i]);fParam[i] = &fParcnv[i].obj.fl; break; + case 'n': fParcnv[i].obj.ll = G__Longlong(libp->para[i]);fParam[i] = &fParcnv[i].obj.ll; break; + case 'm': fParcnv[i].obj.ull= G__ULonglong(libp->para[i]);fParam[i] = &fParcnv[i].obj.ull; break; + case 'q': fParcnv[i].obj.ld = G__Longdouble(libp->para[i]);fParam[i] = &fParcnv[i].obj.ld; break; + case 'i': fParcnv[i].obj.i = G__int(libp->para[i]); fParam[i] = &fParcnv[i].obj.i; break; + case '*': fParam[i] = libp->para[i].ref ? (void*)libp->para[i].ref : &libp->para[i].obj.i; break; + case '&': fParam[i] = (void*)libp->para[i].ref; break; + case 'u': fParam[i] = (void*)libp->para[i].obj.i; break; + } } - else { - Converter<long>::toCint(result, obj); - result->ref = 0; + } + + void StubContext_t::ProcessResult(G__value* result, void* obj) { + // process ctx result + char t = fRet_desc.first; + result->type = t; + switch( t ) { + case 'y': G__setnull(result); break; + case 'Y': Converter<long>::toCint (result, obj); break; + case 'g': Converter<bool>::toCint (result, obj); break; + case 'G': Converter<int>::toCint (result, obj); break; + case 'c': Converter<char>::toCint (result, obj); break; + case 'C': Converter<int>::toCint (result, obj); break; + case 'b': Converter<unsigned char>::toCint (result, obj); break; + case 'B': Converter<int>::toCint (result, obj); break; + case 's': Converter<short>::toCint (result, obj); break; + case 'S': Converter<int>::toCint (result, obj); break; + case 'r': Converter<unsigned short>::toCint(result, obj); break; + case 'R': Converter<int>::toCint (result, obj); break; + case 'i': Converter<int>::toCint (result, obj); break; + case 'I': Converter<int>::toCint (result, obj); break; + case 'h': Converter<unsigned int>::toCint (result, obj); break; + case 'H': Converter<int>::toCint (result, obj); break; + case 'l': Converter<long>::toCint (result, obj); break; + case 'L': Converter<int>::toCint (result, obj); break; + case 'k': Converter<unsigned long>::toCint (result, obj); break; + case 'K': Converter<int>::toCint (result, obj); break; + case 'n': Converter<long long>::toCint (result, obj); break; + case 'N': Converter<int>::toCint (result, obj); break; + case 'm': Converter<unsigned long long>::toCint (result, obj); break; + case 'M': Converter<int>::toCint (result, obj); break; + case 'f': Converter<float>::toCint (result, obj); break; + case 'F': Converter<int>::toCint (result, obj); break; + case 'd': Converter<double>::toCint (result, obj); break; + case 'D': Converter<int>::toCint (result, obj); break; + case 'q': Converter<long double>::toCint (result, obj); break; + case 'Q': Converter<int>::toCint (result, obj); break; + case 'u': Converter<long>::toCint (result, obj); + result->ref = (long)obj; + result->tagnum = fRet_tag; + break; + case 'U': + if ( fRet_byref) { + Converter<long>::toCint(result, *(void**)obj); + result->ref = (long)obj; + } + else { + Converter<long>::toCint(result, obj); + result->ref = 0; + } + result->tagnum = fRet_tag; + break; } - result->tagnum = fRet_tag; - break; - } -} + } -//------------------Stub adpater functions-------------------------------------------------------- -int Method_stub_with_context(StubContext* context, - G__value* result, - G__CONST char* /*funcname*/, - G__param* libp, - int /*hash*/ ) -{ - if ( !context->fInitialized ) context->Initialize(); - context->ProcessParam(libp); + //------------------Stub adpater functions-------------------------------------------------------- + int Method_stub_with_context(StubContext_t* context, + G__value* result, + G__CONST char* /*funcname*/, + G__param* libp, + int /*hash*/ ) + { + // process method, catch exceptions + if ( !context->fInitialized ) context->Initialize(); + context->ProcessParam(libp); - // Catch here everything since going through the adaptor in the data section - // does not transmit the exception - try { - void* r = (*context->fStub)((void*)G__getstructoffset(), context->fParam, context->fStubctx); - context->ProcessResult(result, r); - if ( context->fRet_byvalue ) G__store_tempobject(*result); - } - catch ( std::exception& e ) { - string errtxt("Exception: "); - errtxt += e.what(); - errtxt += " (C++ exception)"; - G__genericerror(errtxt.c_str()); - G__setnull(result); - } - catch (...) { - G__genericerror("Exception: Unknown C++ exception"); - G__setnull(result); - } - return(1); -} + // Catch here everything since going through the adaptor in the data section + // does not transmit the exception + try { + void* r = (*context->fStub)((void*)G__getstructoffset(), context->fParam, context->fStubctx); + context->ProcessResult(result, r); + if ( context->fRet_byvalue ) G__store_tempobject(*result); + } + catch ( std::exception& e ) { + string errtxt("Exception: "); + errtxt += e.what(); + errtxt += " (C++ exception)"; + G__genericerror(errtxt.c_str()); + G__setnull(result); + } + catch (...) { + G__genericerror("Exception: Unknown C++ exception"); + G__setnull(result); + } + return(1); + } -//------------------------------------------------------------------------------------- -int Constructor_stub_with_context(StubContext* context, - G__value* result, - G__CONST char* /*funcname*/, - G__param *libp, - int /*indx*/ ) -{ - if ( !context->fInitialized ) context->Initialize(); - context->ProcessParam(libp); + //------------------------------------------------------------------------------------- + int Constructor_stub_with_context(StubContext_t* context, + G__value* result, + G__CONST char* /*funcname*/, + G__param *libp, + int /*indx*/ ) + { + // process constructor, catch exceptions + if ( !context->fInitialized ) context->Initialize(); + context->ProcessParam(libp); - void* obj=0; + void* obj=0; - // Catch here everything since going through the adaptor in the data section - // does not transmit the exception - try { - long nary = G__getaryconstruct(); - size_t size = context->fClass.SizeOf(); - if ( nary ) { - if( context->fNewdelfuncs ) { - obj = context->fNewdelfuncs->NewArray(nary, 0); + // Catch here everything since going through the adaptor in the data section + // does not transmit the exception + try { + long nary = G__getaryconstruct(); + size_t size = context->fClass.SizeOf(); + if ( nary ) { + if( context->fNewdelfuncs ) { + obj = context->fNewdelfuncs->fNewArray(nary, 0); + } + else { + obj = ::operator new( nary * size); + long p = (long)obj; + for( long i = 0; i < nary; ++i, p += size ) + (*context->fStub)((void*)p, context->fParam, 0); + } + } + else { + obj = ::operator new( size ); + (*context->fStub)(obj, context->fParam, 0); + } } - else { - obj = ::operator new( nary * size); - long p = (long)obj; - for( long i = 0; i < nary; ++i, p += size ) - (*context->fStub)((void*)p, context->fParam, 0); + catch ( std::exception& e ) { + string errtxt("Exception: "); + errtxt += e.what(); + errtxt += " (C++ exception)"; + G__genericerror(errtxt.c_str()); + ::operator delete (obj); + obj = 0; + } + catch (...) { + G__genericerror("Exception: Unknown C++ exception"); + ::operator delete (obj); + obj = 0; } - } - else { - obj = ::operator new( size ); - (*context->fStub)(obj, context->fParam, 0); - } - } - catch ( std::exception& e ) { - string errtxt("Exception: "); - errtxt += e.what(); - errtxt += " (C++ exception)"; - G__genericerror(errtxt.c_str()); - ::operator delete (obj); - obj = 0; - } - catch (...) { - G__genericerror("Exception: Unknown C++ exception"); - ::operator delete (obj); - obj = 0; - } - result->obj.i = (long)obj; - result->ref = (long)obj; - result->type = 'u'; - result->tagnum = context->fClass_tag; - return(1); -} + result->obj.i = (long)obj; + result->ref = (long)obj; + result->type = 'u'; + result->tagnum = context->fClass_tag; + return(1); + } -//------------------------------------------------------------------------------------------------- -int Destructor_stub_with_context( StubContext* context, - G__value* result, - G__CONST char* /*funcname*/, - G__param* /*libp*/, - int /*indx*/ ) -{ - void* obj = (void*)G__getstructoffset(); - if( 0 == obj ) return 1; - if ( !context->fInitialized ) context->Initialize(); + //------------------------------------------------------------------------------------------------- + int Destructor_stub_with_context( StubContext_t* context, + G__value* result, + G__CONST char* /*funcname*/, + G__param* /*libp*/, + int /*indx*/ ) + { + // process destructor + void* obj = (void*)G__getstructoffset(); + if( 0 == obj ) return 1; + if ( !context->fInitialized ) context->Initialize(); - if( G__getaryconstruct() ) { - if( G__PVOID == G__getgvp() ) { // delete[] (TYPE*)(G__getstructoffset()); - if( context->fNewdelfuncs ) context->fNewdelfuncs->DeleteArray(obj); - } - else { - size_t size = context->fClass.SizeOf(); - for(int i = G__getaryconstruct()-1; i>=0 ; i--) - (*context->fStub)((char*)obj + size*i, context->fParam, 0); - ::operator delete (obj); - } - } - else { - long G__Xtmp = G__getgvp(); - G__setgvp(G__PVOID); - (*context->fStub)(obj, context->fParam, 0); - G__setgvp(G__Xtmp); - if( !(long(obj) == G__getgvp() && G__PVOID != G__getgvp()) ) { - ::operator delete (obj); //G__operator_delete(obj); - } - } - G__setnull(result); - return 1; -} + if( G__getaryconstruct() ) { + if( G__PVOID == G__getgvp() ) { // delete[] (TYPE*)(G__getstructoffset()); + if( context->fNewdelfuncs ) context->fNewdelfuncs->fDeleteArray(obj); + } + else { + size_t size = context->fClass.SizeOf(); + for(int i = G__getaryconstruct()-1; i>=0 ; i--) + (*context->fStub)((char*)obj + size*i, context->fParam, 0); + ::operator delete (obj); + } + } + else { + long g__Xtmp = G__getgvp(); + G__setgvp(G__PVOID); + (*context->fStub)(obj, context->fParam, 0); + G__setgvp(g__Xtmp); + if( !(long(obj) == G__getgvp() && G__PVOID != G__getgvp()) ) { + ::operator delete (obj); //G__operator_delete(obj); + } + } + G__setnull(result); + return 1; + } -//------ Support for functions a state ------------------------------------------------------- + //------ Support for functions a state ------------------------------------------------------- -char* Allocate_code(const void* src, size_t len) { - char* code = new char[len+1]; - if ( !code ) return 0; - ::memcpy(code, src, len); - //---The following lines take care of unprotecting for execution the allocated data - // The usage of mprotect taken from ffcall package (http://directory.fsf.org/libs/c/ffcall.html) + char* Allocate_code(const void* src, size_t len) { + char* code = new char[len+1]; + if ( !code ) return 0; + ::memcpy(code, src, len); + //---The following lines take care of unprotecting for execution the allocated data + // The usage of mprotect taken from ffcall package (http://directory.fsf.org/libs/c/ffcall.html) #if defined(__linux) && ! defined(DATA_EXECUTABLE) - { - static long pagesize = 0; - if ( !pagesize ) pagesize = getpagesize(); - unsigned long start_addr = (unsigned long) code; - unsigned long end_addr = (unsigned long) (code + len); - start_addr = start_addr & -pagesize; - end_addr = (end_addr + pagesize-1) & -pagesize; - unsigned long len = end_addr - start_addr; - if ( mprotect( (void*)start_addr, len, PROT_READ|PROT_WRITE|PROT_EXEC) < 0 ) { - return 0; - } - } + { + static long pagesize = 0; + if ( !pagesize ) pagesize = getpagesize(); + unsigned long start_addr = (unsigned long) code; + unsigned long end_addr = (unsigned long) (code + len); + start_addr = start_addr & -pagesize; + end_addr = (end_addr + pagesize-1) & -pagesize; + unsigned long len = end_addr - start_addr; + if ( mprotect( (void*)start_addr, len, PROT_READ|PROT_WRITE|PROT_EXEC) < 0 ) { + return 0; + } + } #endif - return code; -} + return code; + } -//------ Function models------------------------------------------------------------------- + //------ Function models------------------------------------------------------------------- #if INT_MAX < LONG_MAX - #define FUNCPATTERN 0xFAFAFAFAFAFAFAFAL - #define DATAPATTERN 0xDADADADADADADADAL +#define FUNCPATTERN 0xFAFAFAFAFAFAFAFAL +#define DATAPATTERN 0xDADADADADADADADAL #else - #define FUNCPATTERN 0xFAFAFAFAL - #define DATAPATTERN 0xDADADADAL +#define FUNCPATTERN 0xFAFAFAFAL +#define DATAPATTERN 0xDADADADAL #endif -static void f0a() { - typedef void (*f_t)(void*); - ((f_t)FUNCPATTERN)((void*)DATAPATTERN); -} -static void f1a(void* a0) { - typedef void (*f_t)(void*,void*); - ((f_t)FUNCPATTERN)((void*)DATAPATTERN, a0); -} -static void f4a(void* a0, void* a1, void* a2, void* a3) { - typedef void (*f_t)(void*,void*,void*,void*,void*); - ((f_t)FUNCPATTERN)((void*)DATAPATTERN, a0, a1, a2, a3); -} + static void f0a() { + typedef void (*f_t)(void*); + ((f_t)FUNCPATTERN)((void*)DATAPATTERN); + } + static void f1a(void* a0) { + typedef void (*f_t)(void*,void*); + ((f_t)FUNCPATTERN)((void*)DATAPATTERN, a0); + } + static void f4a(void* a0, void* a1, void* a2, void* a3) { + typedef void (*f_t)(void*,void*,void*,void*,void*); + ((f_t)FUNCPATTERN)((void*)DATAPATTERN, a0, a1, a2, a3); + } -struct FunctionCode { - FunctionCode(int narg) : f_offset(0), a_offset(0), size(0) { - if (narg == 0) code = (char*)f0a; - else if (narg == 1) code = (char*)f1a; - else if (narg == 4) code = (char*)f4a; - char* b = code; - for ( size_t o = 0; o < 1000; o++, b++) { - if ( *(size_t*)b == DATAPATTERN ) a_offset = o; - if ( *(size_t*)b == FUNCPATTERN ) f_offset = o; - if ( f_offset && a_offset ) { - size = (o + 32) & ~0xF; - break; + struct FunctionCode_t { + FunctionCode_t(int narg) : f_offset(0), fa_offset(0), fSize(0) { + if (narg == 0) fCode = (char*)f0a; + else if (narg == 1) fCode = (char*)f1a; + else if (narg == 4) fCode = (char*)f4a; + char* b = fCode; + for ( size_t o = 0; o < 1000; o++, b++) { + if ( *(size_t*)b == DATAPATTERN ) fa_offset = o; + if ( *(size_t*)b == FUNCPATTERN ) f_offset = o; + if ( f_offset && fa_offset ) { + fSize = (o + 32) & ~0xF; + break; + } } } - } - size_t f_offset; - size_t a_offset; - size_t size; - char* code; -}; + size_t f_offset; + size_t fa_offset; + size_t fSize; + char* fCode; + }; #undef DATAPATTERN #undef FUNCPATTERN -G__InterfaceMethod Allocate_stub_function( StubContext* obj, - int (*fun)(StubContext*, G__value*, G__CONST char*, G__param*, int ) ) -{ - static FunctionCode s_func4arg(4); - char* code = Allocate_code(s_func4arg.code, s_func4arg.size ); - *(void**)&code[s_func4arg.a_offset] = (void*)obj; - *(void**)&code[s_func4arg.f_offset] = (void*)fun; - obj->fMethodCode = (G__InterfaceMethod)code; - return obj->fMethodCode; -} + G__InterfaceMethod Allocate_stub_function( StubContext_t* obj, + int (*fun)(StubContext_t*, G__value*, G__CONST char*, G__param*, int ) ) + { + // allocate a stub function + static FunctionCode_t s_func4arg(4); + char* code = Allocate_code(s_func4arg.fCode, s_func4arg.fSize ); + *(void**)&code[s_func4arg.fa_offset] = (void*)obj; + *(void**)&code[s_func4arg.f_offset] = (void*)fun; + obj->fMethodCode = (G__InterfaceMethod)code; + return obj->fMethodCode; + } -FuncVoidPtr Allocate_void_function( void* obj, void (*fun)(void*) ) -{ - static FunctionCode s_func0arg(0); - char* code = Allocate_code(s_func0arg.code, s_func0arg.size); - *(void**)&code[s_func0arg.a_offset] = (void*)obj; - *(void**)&code[s_func0arg.f_offset] = (void*)fun; - return (FuncVoidPtr)code; -} + FuncVoidPtr_t Allocate_void_function( void* obj, void (*fun)(void*) ) + { + // allocate a stub function + static FunctionCode_t s_func0arg(0); + char* code = Allocate_code(s_func0arg.fCode, s_func0arg.fSize); + *(void**)&code[s_func0arg.fa_offset] = (void*)obj; + *(void**)&code[s_func0arg.f_offset] = (void*)fun; + return (FuncVoidPtr_t)code; + } -FuncArg1Ptr Allocate_1arg_function( void* obj, void* (*fun)(void*, void*) ) -{ - static FunctionCode s_func1arg(1); - char* code = Allocate_code(s_func1arg.code, s_func1arg.size); - *(void**)&code[s_func1arg.a_offset] = (void*)obj; - *(void**)&code[s_func1arg.a_offset] = (void*)fun; - return (FuncArg1Ptr)code; -} + FuncArg1Ptr_t Allocate_1arg_function( void* obj, void* (*fun)(void*, void*) ) + { + // allocate a stub function + static FunctionCode_t s_func1arg(1); + char* code = Allocate_code(s_func1arg.fCode, s_func1arg.fSize); + *(void**)&code[s_func1arg.fa_offset] = (void*)obj; + *(void**)&code[s_func1arg.fa_offset] = (void*)fun; + return (FuncArg1Ptr_t)code; + } -void Free_function( void* code ) -{ - char* scode = (char*)code; - delete [] scode; -} + void Free_function( void* code ) + { + // free a function code + char* scode = (char*)code; + delete [] scode; + } } } // seal and cintex namepaces diff --git a/cintex/src/CINTFunctional.h b/cintex/src/CINTFunctional.h index ffe0853d9011c0ff524cf37a6a9bd3d5c8585db7..56947deb28581b71cc42f4e815bd279a2f99a5cf 100644 --- a/cintex/src/CINTFunctional.h +++ b/cintex/src/CINTFunctional.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTFunctional.h,v 1.3 2005/11/17 14:12:33 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTFunctional.h,v 1.4 2006/02/09 20:36:54 pcanal Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -18,71 +18,71 @@ #include <vector> namespace ROOT { - namespace Cintex { + namespace Cintex { - typedef void(*FuncVoidPtr)(void); - typedef void*(*FuncArg1Ptr)(void*); + typedef void(*FuncVoidPtr_t)(void); + typedef void*(*FuncArg1Ptr_t)(void*); - typedef void* (*NewFunc_t)( void* ); - typedef void* (*NewArrFunc_t)( long size, void *arena ); - typedef void (*DelFunc_t)( void* ); - typedef void (*DelArrFunc_t)( void* ); - typedef void (*DesFunc_t)( void* ); + typedef void* (*NewFunc_t)( void* ); + typedef void* (*NewArrFunc_t)( long size, void *arena ); + typedef void (*DelFunc_t)( void* ); + typedef void (*DelArrFunc_t)( void* ); + typedef void (*DesFunc_t)( void* ); - struct NewDelFunctions { - NewFunc_t New; //pointer to a function newing one object. - NewArrFunc_t NewArray; //pointer to a function newing an array of objects. - DelFunc_t Delete; //pointer to a function deleting one object. - DelArrFunc_t DeleteArray; //pointer to a function deleting an array of objects. - DesFunc_t Destructor; //pointer to a function call an object's destructor. - }; + struct NewDelFunctions_t { + NewFunc_t fNew; //pointer to a function newing one object. + NewArrFunc_t fNewArray; //pointer to a function newing an array of objects. + DelFunc_t fDelete; //pointer to a function deleting one object. + DelArrFunc_t fDeleteArray; //pointer to a function deleting an array of objects. + DesFunc_t fDestructor; //pointer to a function call an object's destructor. + }; - struct StubContext { - /// Constructor. It prepares the necessary information such that the run-time processing is optimal - StubContext(const ROOT::Reflex::Member& mem, const ROOT::Reflex::Type& cl ); - /// Destructor - virtual ~StubContext(); + struct StubContext_t { + /// Constructor. It prepares the necessary information such that the run-time processing is optimal + StubContext_t(const ROOT::Reflex::Member& mem, const ROOT::Reflex::Type& cl ); + /// Destructor + virtual ~StubContext_t(); - /// Initialization - void Initialize(); - /// Process the function parameters to adapt from CINT to Reflex interfaces - void ProcessParam(G__param* libp); - /// Process the return value to adapt from Reflex to CINT - void ProcessResult(G__value* result, void * obj); + /// Initialization + void Initialize(); + /// Process the function parameters to adapt from CINT to Reflex interfaces + void ProcessParam(G__param* libp); + /// Process the return value to adapt from Reflex to CINT + void ProcessResult(G__value* result, void * obj); - G__InterfaceMethod fMethodCode; ///< method allocated code - std::vector<void*> fParam; ///< Reflex ParameterNth vector - std::vector<G__value> fParcnv; ///< CINT ParameterNth conversions vector - std::vector<char> fTreat; ///< Coded treatment of parameters - CintTypeDesc fRet_desc; ///< Coded treatment of parameters - int fRet_tag; ///< Return TypeNth tag number - bool fRet_byvalue; ///< Return by value flag - bool fRet_byref; ///< Return by reference flag - int fClass_tag; ///< Class TypeNth tag number - ROOT::Reflex::Member fMember; ///< Reflex FunctionMember - ROOT::Reflex::Type fClass; ///< Declaring Reflex class - ROOT::Reflex::Type fFunction; ///< Reflex Function TypeNth - int fNpar; ///< number of function parameters - ROOT::Reflex::StubFunction fStub; ///< pointer to the stub function - void* fStubctx; ///< stub function context - NewDelFunctions* fNewdelfuncs; ///< Pointer to the NewDelFunctions structure - bool fInitialized; ///< Initialized flag - }; + G__InterfaceMethod fMethodCode; ///< method allocated code + std::vector<void*> fParam; ///< Reflex ParameterNth vector + std::vector<G__value> fParcnv; ///< CINT ParameterNth conversions vector + std::vector<char> fTreat; ///< Coded treatment of parameters + CintTypeDesc fRet_desc; ///< Coded treatment of parameters + int fRet_tag; ///< Return TypeNth tag number + bool fRet_byvalue; ///< Return by value flag + bool fRet_byref; ///< Return by reference flag + int fClass_tag; ///< Class TypeNth tag number + ROOT::Reflex::Member fMember; ///< Reflex FunctionMember + ROOT::Reflex::Type fClass; ///< Declaring Reflex class + ROOT::Reflex::Type fFunction; ///< Reflex Function TypeNth + int fNpar; ///< number of function parameters + ROOT::Reflex::StubFunction fStub; ///< pointer to the stub function + void* fStubctx; ///< stub function context + NewDelFunctions_t* fNewdelfuncs; ///< Pointer to the NewDelFunctions structure + bool fInitialized; ///< Initialized flag + }; - int Constructor_stub(G__value*, G__CONST char*, G__param*, int ); - int Destructor_stub(G__value*, G__CONST char*, G__param*, int ); - int Method_stub(G__value*, G__CONST char*, G__param*, int ); - int Constructor_stub_with_context(StubContext*, G__value*, G__CONST char*, G__param*, int ); - int Destructor_stub_with_context(StubContext*, G__value*, G__CONST char*, G__param*, int ); - int Method_stub_with_context(StubContext*, G__value*, G__CONST char*, G__param*, int ); - char* Allocate_code(const void* src, size_t len); - G__InterfaceMethod Allocate_stub_function( StubContext* obj, - int (*fun)(StubContext*, G__value*, G__CONST char*, G__param*, int ) ); - FuncVoidPtr Allocate_void_function( void* obj, void (*fun)(void*) ); - FuncArg1Ptr Allocate_1arg_function( void* obj, void* (*fun)(void*, void*) ); - void Free_function( void* ); - } + int Constructor_stub(G__value*, G__CONST char*, G__param*, int ); + int Destructor_stub(G__value*, G__CONST char*, G__param*, int ); + int Method_stub(G__value*, G__CONST char*, G__param*, int ); + int Constructor_stub_with_context(StubContext_t*, G__value*, G__CONST char*, G__param*, int ); + int Destructor_stub_with_context(StubContext_t*, G__value*, G__CONST char*, G__param*, int ); + int Method_stub_with_context(StubContext_t*, G__value*, G__CONST char*, G__param*, int ); + char* Allocate_code(const void* src, size_t len); + G__InterfaceMethod Allocate_stub_function( StubContext_t* obj, + int (*fun)(StubContext_t*, G__value*, G__CONST char*, G__param*, int ) ); + FuncVoidPtr_t Allocate_void_function( void* obj, void (*fun)(void*) ); + FuncArg1Ptr_t Allocate_1arg_function( void* obj, void* (*fun)(void*, void*) ); + void Free_function( void* ); + } } #endif // ROOT_Cintex_CINTFunctional diff --git a/cintex/src/CINTScopeBuilder.cxx b/cintex/src/CINTScopeBuilder.cxx index d178e132e0644d1a7a90dd86b99732ca01441ebe..48e0a5eaf8a9c47be6931b40848089c43599b3e9 100644 --- a/cintex/src/CINTScopeBuilder.cxx +++ b/cintex/src/CINTScopeBuilder.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTScopeBuilder.cxx,v 1.6 2006/02/16 05:58:56 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTScopeBuilder.cxx,v 1.7 2006/06/13 08:19:01 brun Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -26,69 +26,69 @@ using namespace std; namespace ROOT { namespace Cintex { - void CINTScopeBuilder::Setup(const Scope& scope) { - if ( scope ) { - if (scope.IsTopScope() ) return; - Setup( scope.DeclaringScope() ); - } - else { - if ( scope.Name() == "" ) return; - Scope dcl_scope = Scope::ByName(Tools::GetScopeName(scope.Name(SCOPED))); - if( dcl_scope.Id() ) Setup(dcl_scope); - } - string sname = CintName(scope.Name(SCOPED)); - G__linked_taginfo taginfo; - taginfo.tagnum = -1; // >> need to be pre-initialized to be understood by CINT - if (scope.IsNamespace() ) taginfo.tagtype = 'n'; - else if (scope.IsClass() ) taginfo.tagtype = 'c'; - else taginfo.tagtype = 'n'; // Undefined. Assume namespace - taginfo.tagname = sname.c_str(); - int tagnum = G__defined_tagname(taginfo.tagname, 2); - G__ClassInfo info(tagnum); - if ( !info.IsLoaded() ) { - G__get_linked_tagnum(&taginfo); - //--Setup the namespace--- - if ( scope.IsClass() ) { //--Setup the class scope - CINTClassBuilder::Get(Type::ByName(sname)); + void CINTScopeBuilder::Setup(const Scope& scope) { + if ( scope ) { + if (scope.IsTopScope() ) return; + Setup( scope.DeclaringScope() ); } else { - G__tagtable_setup( taginfo.tagnum, // tag number - 0, // size - G__CPPLINK, // cpplink - 9600, // isabstract - 0, // comment - 0, // Variable Setup func - 0); // Function Setup func - //-- Create a TClass Instance to please PyROOT adnd ROOT that also wats to have - // TClass for namespaces - if (scope) ROOTClassEnhancer::CreateClassForNamespace(sname); + if ( scope.Name() == "" ) return; + Scope dcl_scope = Scope::ByName(Tools::GetScopeName(scope.Name(SCOPED))); + if( dcl_scope.Id() ) Setup(dcl_scope); } - } - return; - } + string sname = CintName(scope.Name(SCOPED)); + G__linked_taginfo taginfo; + taginfo.tagnum = -1; // >> need to be pre-initialized to be understood by CINT + if (scope.IsNamespace() ) taginfo.tagtype = 'n'; + else if (scope.IsClass() ) taginfo.tagtype = 'c'; + else taginfo.tagtype = 'n'; // Undefined. Assume namespace + taginfo.tagname = sname.c_str(); + int tagnum = G__defined_tagname(taginfo.tagname, 2); + G__ClassInfo info(tagnum); + if ( !info.IsLoaded() ) { + G__get_linked_tagnum(&taginfo); + //--Setup the namespace--- + if ( scope.IsClass() ) { //--Setup the class scope + CINTClassBuilder::Get(Type::ByName(sname)); + } + else { + G__tagtable_setup( taginfo.tagnum, // tag number + 0, // size + G__CPPLINK, // cpplink + 9600, // isabstract + 0, // comment + 0, // Variable Setup func + 0); // Function Setup func + //-- Create a TClass Instance to please PyROOT adnd ROOT that also wats to have + // TClass for namespaces + if (scope) ROOTClassEnhancer::CreateClassForNamespace(sname); + } + } + return; + } - void CINTScopeBuilder::Setup(const Type& type) { - if ( type.IsFunction() ) { - Setup(type.ReturnType()); - for ( size_t i = 0; i < type.FunctionParameterSize(); i++ ) Setup(type.FunctionParameterAt(i)); - } - else if ( type.IsTypedef() ) { - CINTTypedefBuilder::Setup(type); - Setup(type.ToType()); - } - else if ( type.IsEnum() ) { - CINTEnumBuilder::Setup(type); - Setup(type.DeclaringScope()); - } - else { - Scope scope = type.DeclaringScope(); - if ( scope ) Setup(scope); + void CINTScopeBuilder::Setup(const Type& type) { + if ( type.IsFunction() ) { + Setup(type.ReturnType()); + for ( size_t i = 0; i < type.FunctionParameterSize(); i++ ) Setup(type.FunctionParameterAt(i)); + } + else if ( type.IsTypedef() ) { + CINTTypedefBuilder::Setup(type); + Setup(type.ToType()); + } + else if ( type.IsEnum() ) { + CINTEnumBuilder::Setup(type); + Setup(type.DeclaringScope()); + } else { - // Type not yet defined. Get the ScopeNth anyway... - scope = Scope::ByName(Tools::GetScopeName(type.Name(SCOPED))); - if( scope.Id() ) Setup(scope); + Scope scope = type.DeclaringScope(); + if ( scope ) Setup(scope); + else { + // Type not yet defined. Get the ScopeNth anyway... + scope = Scope::ByName(Tools::GetScopeName(type.Name(SCOPED))); + if( scope.Id() ) Setup(scope); + } } - } - } + } }} diff --git a/cintex/src/CINTScopeBuilder.h b/cintex/src/CINTScopeBuilder.h index 9731d223feab3e8e3bd1a62ef047a23840e0cef6..7c17576510b8c7a0c8990f0fcad6cc62616825f3 100644 --- a/cintex/src/CINTScopeBuilder.h +++ b/cintex/src/CINTScopeBuilder.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name:$:$Id:$ +// @(#)root/cintex:$Name: $:$Id: CINTScopeBuilder.h,v 1.3 2005/11/17 14:12:33 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -16,13 +16,13 @@ #include "CINTdefs.h" namespace ROOT { - namespace Cintex { + namespace Cintex { - namespace CINTScopeBuilder { - void Setup(const ROOT::Reflex::Scope&); - void Setup(const ROOT::Reflex::Type&); - } - } + namespace CINTScopeBuilder { + void Setup(const ROOT::Reflex::Scope&); + void Setup(const ROOT::Reflex::Type&); + } + } } #endif // ROOT_Cintex_CINTScopeBuilder diff --git a/cintex/src/CINTTypedefBuilder.cxx b/cintex/src/CINTTypedefBuilder.cxx index 193b938aedad770dcc210f3690d5738ee560444a..01d4e18cb0f03b300a25da229cc428f780370599 100644 --- a/cintex/src/CINTTypedefBuilder.cxx +++ b/cintex/src/CINTTypedefBuilder.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTTypedefBuilder.cxx,v 1.10 2006/06/15 12:07:18 brun Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTTypedefBuilder.cxx,v 1.11 2006/06/28 08:21:31 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -24,48 +24,49 @@ using namespace std; namespace ROOT { - namespace Cintex { + namespace Cintex { - int CINTTypedefBuilder::Setup(const Type& t) { - if ( t.IsTypedef() ) { + int CINTTypedefBuilder::Setup(const Type& t) { + // setup typedef info + if ( t.IsTypedef() ) { - std::string nam = CintName(t.Name(SCOPED)); + std::string nam = CintName(t.Name(SCOPED)); - Type rt(t); - Scope scope = rt.DeclaringScope(); - CINTScopeBuilder::Setup( scope ); - while ( rt.IsTypedef() ) rt = rt.ToType(); + Type rt(t); + Scope scope = rt.DeclaringScope(); + CINTScopeBuilder::Setup( scope ); + while ( rt.IsTypedef() ) rt = rt.ToType(); - Indirection indir = IndirectionGet(rt); - Scope rscope = indir.second.DeclaringScope(); + Indirection indir = IndirectionGet(rt); + Scope rscope = indir.second.DeclaringScope(); - if ( scope != rscope ) { - if ( rscope ) CINTScopeBuilder::Setup(rscope); - else { - rscope = Scope::ByName(Tools::GetScopeName(indir.second.Name(SCOPED))); - CINTScopeBuilder::Setup(rscope); - } - } + if ( scope != rscope ) { + if ( rscope ) CINTScopeBuilder::Setup(rscope); + else { + rscope = Scope::ByName(Tools::GetScopeName(indir.second.Name(SCOPED))); + CINTScopeBuilder::Setup(rscope); + } + } - if( -1 != G__defined_typename(nam.c_str()) ) return -1; + if( -1 != G__defined_typename(nam.c_str()) ) return -1; - if ( Cintex::Debug() ) { - std::cout << "Building typedef " << nam << std::endl; - } + if ( Cintex::Debug() ) { + std::cout << "Building typedef " << nam << std::endl; + } - int rtypenum; - int rtagnum; - CintType(rt, rtypenum, rtagnum ); + int rtypenum; + int rtagnum; + CintType(rt, rtypenum, rtagnum ); - int stagnum = -1; - if ( !scope.IsTopScope() ) stagnum = ::G__defined_tagname(CintName(scope.Name(SCOPED)).c_str(), 1); + int stagnum = -1; + if ( !scope.IsTopScope() ) stagnum = ::G__defined_tagname(CintName(scope.Name(SCOPED)).c_str(), 1); - int r = ::G__search_typename2( t.Name().c_str(), rtypenum, rtagnum, 0, stagnum); - ::G__setnewtype(-1,NULL,0); + int r = ::G__search_typename2( t.Name().c_str(), rtypenum, rtagnum, 0, stagnum); + ::G__setnewtype(-1,NULL,0); - return r; + return r; + } + return -1; } - return -1; - } - } + } } diff --git a/cintex/src/CINTTypedefBuilder.h b/cintex/src/CINTTypedefBuilder.h index d20540e0adf6d7b6a1866a6ed59824250e7a6e39..b6459b0503e8d96423ce5b1246f6ffe13a3ca3ae 100644 --- a/cintex/src/CINTTypedefBuilder.h +++ b/cintex/src/CINTTypedefBuilder.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTTypedefBuilder.h,v 1.3 2005/11/17 14:12:33 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTTypedefBuilder.h,v 1.4 2006/05/04 19:31:31 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -19,17 +19,17 @@ */ namespace ROOT { namespace Cintex { - /* @class CINTTypedefBuilder CINTTypedefBuilder.h - * - * @author M.Frank - * @version 1.0 - * @date 10/04/2005 - */ - class CINTTypedefBuilder { - public: - // Declare typedef to CINT - static int Setup(const ROOT::Reflex::Type& t); - }; -}} + /* @class CINTTypedefBuilder CINTTypedefBuilder.h + * + * @author M.Frank + * @version 1.0 + * @date 10/04/2005 + */ + class CINTTypedefBuilder { + public: + // Declare typedef to CINT + static int Setup(const ROOT::Reflex::Type& t); + }; + }} #endif // ROOT_Cintex_CINTTypdefBuilder diff --git a/cintex/src/CINTUtils.cxx b/cintex/src/CINTUtils.cxx index a0eb4451275aae2d5df4000b754bf6fd66bdc2bf..d0e2a22bfba37b55a63c1cc07035fac738f6059d 100644 --- a/cintex/src/CINTUtils.cxx +++ b/cintex/src/CINTUtils.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTUtils.cxx,v 1.7 2006/05/04 16:53:11 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTUtils.cxx,v 1.8 2006/06/13 08:19:01 brun Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -18,322 +18,322 @@ using namespace std; namespace ROOT { namespace Cintex { - Indirection IndirectionGet(const Type& typ) { - Type t(typ); - int indir = 0; - for ( ; t.IsTypedef(); t = t.ToType()) ; - for ( ; t.IsPointer(); t = t.ToType()) indir++; - return Indirection(indir, t); - } + Indirection IndirectionGet(const Type& typ) { + Type t(typ); + int indir = 0; + for ( ; t.IsTypedef(); t = t.ToType()) ; + for ( ; t.IsPointer(); t = t.ToType()) indir++; + return Indirection(indir, t); + } - void CintType( const Type& typ, int& typenum, int& tagnum ) { - Type t(typ); - int indir = 0; - while( t.IsTypedef()) t = t.ToType(); - for ( ; t.IsPointer(); t = t.ToType()) indir++; + void CintType( const Type& typ, int& typenum, int& tagnum ) { + Type t(typ); + int indir = 0; + while( t.IsTypedef()) t = t.ToType(); + for ( ; t.IsPointer(); t = t.ToType()) indir++; - CintTypeDesc dsc = CintType( t ); + CintTypeDesc dsc = CintType( t ); - typenum = dsc.first + (indir > 0 ? 'A'-'a' : 0); - tagnum = -1; - if ( dsc.first == 'u' ) { - tagnum = ::G__defined_tagname(dsc.second.c_str(), 2); - if ( tagnum == -1 ) { - G__linked_taginfo taginfo; - taginfo.tagnum = -1; - if ( t.IsClass() || t.IsStruct() ) taginfo.tagtype = 'c'; - else taginfo.tagtype = 'a'; - taginfo.tagname = dsc.second.c_str(); - G__get_linked_tagnum(&taginfo); - tagnum = taginfo.tagnum; + typenum = dsc.first + (indir > 0 ? 'A'-'a' : 0); + tagnum = -1; + if ( dsc.first == 'u' ) { + tagnum = ::G__defined_tagname(dsc.second.c_str(), 2); + if ( tagnum == -1 ) { + G__linked_taginfo taginfo; + taginfo.tagnum = -1; + if ( t.IsClass() || t.IsStruct() ) taginfo.tagtype = 'c'; + else taginfo.tagtype = 'a'; + taginfo.tagname = dsc.second.c_str(); + G__get_linked_tagnum(&taginfo); + tagnum = taginfo.tagnum; + } } - } - } + } - CintTypeDesc CintType(const ROOT::Reflex::Type& typ) { - Type t(CleanType(typ)); - string nam = t.Name(SCOPED); + CintTypeDesc CintType(const ROOT::Reflex::Type& typ) { + Type t(CleanType(typ)); + string nam = t.Name(SCOPED); - if ( nam == "void" ) - return CintTypeDesc('y', "-"); - else if ( nam == "bool" ) - return CintTypeDesc('g', "-"); - else if ( nam == "char" ) - return CintTypeDesc('c', "-"); - else if ( nam == "signed char" ) - return CintTypeDesc('c', "-"); - else if ( nam == "unsigned char" ) - return CintTypeDesc('b', "-"); - else if ( nam == "short" ) - return CintTypeDesc('s', "-"); - else if ( nam == "short int" ) - return CintTypeDesc('s', "-"); - else if ( nam == "signed short" ) - return CintTypeDesc('s', "-"); - else if ( nam == "signed short int" ) - return CintTypeDesc('s', "-"); - else if ( nam == "unsigned short" ) - return CintTypeDesc('r', "-"); - else if ( nam == "short unsigned" ) - return CintTypeDesc('r', "-"); - else if ( nam == "unsigned short int" ) - return CintTypeDesc('r', "-"); - else if ( nam == "short unsigned int" ) - return CintTypeDesc('r', "-"); - else if ( nam == "int" ) - return CintTypeDesc('i', "-"); - else if ( nam == "signed" ) - return CintTypeDesc('i', "-"); - else if ( nam == "signed int" ) - return CintTypeDesc('i', "-"); - else if ( nam == "unsigned int" ) - return CintTypeDesc('h', "-"); - else if ( nam == "unsigned" ) - return CintTypeDesc('h', "-"); - else if ( nam == "long" ) - return CintTypeDesc('l', "-"); - else if ( nam == "long int" ) - return CintTypeDesc('l', "-"); - else if ( nam == "signed long" ) - return CintTypeDesc('l', "-"); - else if ( nam == "signed long int" ) - return CintTypeDesc('l', "-"); - else if ( nam == "long signed" ) - return CintTypeDesc('l', "-"); - else if ( nam == "long signed int" ) - return CintTypeDesc('l', "-"); - else if ( nam == "unsigned long" ) - return CintTypeDesc('k', "-"); - else if ( nam == "unsigned long int" ) - return CintTypeDesc('k', "-"); - else if ( nam == "long unsigned int" ) - return CintTypeDesc('k', "-"); - else if ( nam == "longlong" ) - return CintTypeDesc('n', "-"); - else if ( nam == "long long" ) - return CintTypeDesc('n', "-"); - else if ( nam == "long long int" ) - return CintTypeDesc('n', "-"); - else if ( nam == "long long signed int" ) - return CintTypeDesc('n', "-"); - else if ( nam == "long long signed" ) - return CintTypeDesc('n', "-"); - else if ( nam == "signed long long int" ) - return CintTypeDesc('n', "-"); - else if ( nam == "ulonglong" ) - return CintTypeDesc('m', "-"); - else if ( nam == "unsigned long long" ) - return CintTypeDesc('m', "-"); - else if ( nam == "long long unsigned" ) - return CintTypeDesc('m', "-"); - else if ( nam == "long long unsigned int" ) - return CintTypeDesc('m', "-"); - else if ( nam == "unsigned long long int" ) - return CintTypeDesc('m', "-"); - else if ( nam == "long double" ) - return CintTypeDesc('q', "-"); - else if ( nam == "double" ) - return CintTypeDesc('d', "-"); - else if ( nam == "double32" ) - return CintTypeDesc('d', "-"); - else if ( nam == "float" ) - return CintTypeDesc('f', "-"); - else if ( t.IsEnum() ) - return CintTypeDesc('i', "-"); - else if ( t.IsFunction() ) - return CintTypeDesc('y', "-"); - else if ( !t.IsFundamental() ) - return CintTypeDesc('u', CintName(t)); - else - return CintTypeDesc('-', CintName(t)); - } + if ( nam == "void" ) + return CintTypeDesc('y', "-"); + else if ( nam == "bool" ) + return CintTypeDesc('g', "-"); + else if ( nam == "char" ) + return CintTypeDesc('c', "-"); + else if ( nam == "signed char" ) + return CintTypeDesc('c', "-"); + else if ( nam == "unsigned char" ) + return CintTypeDesc('b', "-"); + else if ( nam == "short" ) + return CintTypeDesc('s', "-"); + else if ( nam == "short int" ) + return CintTypeDesc('s', "-"); + else if ( nam == "signed short" ) + return CintTypeDesc('s', "-"); + else if ( nam == "signed short int" ) + return CintTypeDesc('s', "-"); + else if ( nam == "unsigned short" ) + return CintTypeDesc('r', "-"); + else if ( nam == "short unsigned" ) + return CintTypeDesc('r', "-"); + else if ( nam == "unsigned short int" ) + return CintTypeDesc('r', "-"); + else if ( nam == "short unsigned int" ) + return CintTypeDesc('r', "-"); + else if ( nam == "int" ) + return CintTypeDesc('i', "-"); + else if ( nam == "signed" ) + return CintTypeDesc('i', "-"); + else if ( nam == "signed int" ) + return CintTypeDesc('i', "-"); + else if ( nam == "unsigned int" ) + return CintTypeDesc('h', "-"); + else if ( nam == "unsigned" ) + return CintTypeDesc('h', "-"); + else if ( nam == "long" ) + return CintTypeDesc('l', "-"); + else if ( nam == "long int" ) + return CintTypeDesc('l', "-"); + else if ( nam == "signed long" ) + return CintTypeDesc('l', "-"); + else if ( nam == "signed long int" ) + return CintTypeDesc('l', "-"); + else if ( nam == "long signed" ) + return CintTypeDesc('l', "-"); + else if ( nam == "long signed int" ) + return CintTypeDesc('l', "-"); + else if ( nam == "unsigned long" ) + return CintTypeDesc('k', "-"); + else if ( nam == "unsigned long int" ) + return CintTypeDesc('k', "-"); + else if ( nam == "long unsigned int" ) + return CintTypeDesc('k', "-"); + else if ( nam == "longlong" ) + return CintTypeDesc('n', "-"); + else if ( nam == "long long" ) + return CintTypeDesc('n', "-"); + else if ( nam == "long long int" ) + return CintTypeDesc('n', "-"); + else if ( nam == "long long signed int" ) + return CintTypeDesc('n', "-"); + else if ( nam == "long long signed" ) + return CintTypeDesc('n', "-"); + else if ( nam == "signed long long int" ) + return CintTypeDesc('n', "-"); + else if ( nam == "ulonglong" ) + return CintTypeDesc('m', "-"); + else if ( nam == "unsigned long long" ) + return CintTypeDesc('m', "-"); + else if ( nam == "long long unsigned" ) + return CintTypeDesc('m', "-"); + else if ( nam == "long long unsigned int" ) + return CintTypeDesc('m', "-"); + else if ( nam == "unsigned long long int" ) + return CintTypeDesc('m', "-"); + else if ( nam == "long double" ) + return CintTypeDesc('q', "-"); + else if ( nam == "double" ) + return CintTypeDesc('d', "-"); + else if ( nam == "double32" ) + return CintTypeDesc('d', "-"); + else if ( nam == "float" ) + return CintTypeDesc('f', "-"); + else if ( t.IsEnum() ) + return CintTypeDesc('i', "-"); + else if ( t.IsFunction() ) + return CintTypeDesc('y', "-"); + else if ( !t.IsFundamental() ) + return CintTypeDesc('u', CintName(t)); + else + return CintTypeDesc('-', CintName(t)); + } - Type CleanType(const Type& typ) { - if ( typ ) { - Type t( typ ); - while ( t.IsTypedef() ) t = CleanType(t.ToType()); - while ( t.IsPointer() ) t = CleanType(t.ToType()); - while ( t.IsArray() ) t = CleanType(t.ToType()); - return t; - } - return typ; - } + Type CleanType(const Type& typ) { + if ( typ ) { + Type t( typ ); + while ( t.IsTypedef() ) t = CleanType(t.ToType()); + while ( t.IsPointer() ) t = CleanType(t.ToType()); + while ( t.IsArray() ) t = CleanType(t.ToType()); + return t; + } + return typ; + } - bool IsTypeOf(Type& typ, const std::string& base_name) { - Type ref_typ = Type::ByName(base_name); - if ( ref_typ ) { - if ( typ == ref_typ || typ.HasBase(ref_typ) ) { - return true; + bool IsTypeOf(Type& typ, const std::string& base_name) { + Type ref_typ = Type::ByName(base_name); + if ( ref_typ ) { + if ( typ == ref_typ || typ.HasBase(ref_typ) ) { + return true; + } + return false; } return false; - } - return false; - //throw std::runtime_error("Fatal error: Failed to retrieved dictionary for "+base_name); - } - - bool IsSTLinternal(const std::string& nam) { - std::string sub = nam.substr(0,8); - std::string sub6 = nam.substr(0,6); - std::string sub9 = nam.substr(0,9); - if ( nam.empty() || sub6 =="std::_" || sub9 =="stdext::_" || nam.substr(0,12)=="__gnu_cxx::_") { - return true; - } - return false; - } + //throw std::runtime_error("Fatal error: Failed to retrieved dictionary for "+base_name); + } - bool IsSTL(const std::string& nam) { - if ( ! IsSTLinternal(nam) ) { + bool IsSTLinternal(const std::string& nam) { std::string sub = nam.substr(0,8); - bool stl = nam.substr(0,17)=="std::basic_string" || - sub=="std::str" || sub=="std::vec" || sub=="std::lis" || - sub=="std::set" || sub=="std::deq" || sub=="std::map" || - sub=="std::mul" || sub=="stdext::" || sub=="__gnu_cx"; - return stl; - } - return true; - } - bool IsSTLext(const std::string& nam) { - std::string sub = nam.substr(0,8); - return sub=="stdext::" || sub=="__gnu_cx"; - } + std::string sub6 = nam.substr(0,6); + std::string sub9 = nam.substr(0,9); + if ( nam.empty() || sub6 =="std::_" || sub9 =="stdext::_" || nam.substr(0,12)=="__gnu_cxx::_") { + return true; + } + return false; + } - /// one-at-time hash function - static unsigned long hash32(const char* key) { - unsigned long hash; - const char* k; - for (hash = 0, k = key; *k; k++) { - hash += *k; hash += (hash << 10); hash ^= (hash >> 6); - } - hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); - return hash; - } + bool IsSTL(const std::string& nam) { + if ( ! IsSTLinternal(nam) ) { + std::string sub = nam.substr(0,8); + bool stl = nam.substr(0,17)=="std::basic_string" || + sub=="std::str" || sub=="std::vec" || sub=="std::lis" || + sub=="std::set" || sub=="std::deq" || sub=="std::map" || + sub=="std::mul" || sub=="stdext::" || sub=="__gnu_cx"; + return stl; + } + return true; + } + bool IsSTLext(const std::string& nam) { + std::string sub = nam.substr(0,8); + return sub=="stdext::" || sub=="__gnu_cx"; + } - // Conversion table: Note: order is important! - static const char* s_normalize[][2] = { - {" ", " " } - ,{", ", "," } - ,{" signed ", " " } - ,{",signed ", "," } - ,{"<signed ", "<" } - ,{"(signed ", "(" } - ,{"ulonglong", "unsigned long long" } - ,{"longlong", "long long" } - ,{"long unsigned", "unsigned long" } - ,{"short unsigned", "unsigned short" } - ,{"short int", "short" } - ,{"long int", "long" } - ,{"basic_string<char> ", "string"} - ,{"basic_string<char>", "string"} - ,{"basic_string<char,allocator<char> > ","string"} - ,{"basic_string<char,allocator<char> >","string"} - ,{"basic_string<char,char_traits<char>,allocator<char> > ","string"} - ,{"basic_string<char,char_traits<char>,allocator<char> >","string"} - }; + /// one-at-time hash function + static unsigned long hash32(const char* key) { + unsigned long hash; + const char* k; + for (hash = 0, k = key; *k; k++) { + hash += *k; hash += (hash << 10); hash ^= (hash >> 6); + } + hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); + return hash; + } - std::string CintName(const Type& typ) { - Type t(CleanType(typ)); - return CintName(t.Name(SCOPED)); - } - std::string CintName(const std::string& full_nam) { - if ( full_nam.length() > 255 ) { - char txt[256]; - sprintf(txt,"objecttype_%08lX", hash32(full_nam.c_str())); - return txt; - } - else { - size_t occ; - std::string nam = full_nam; //(full) ? full_nam : cl->Name(); - std::string s = (nam.substr(0,2) == "::") ? nam.substr(2) : nam; + // Conversion table: Note: order is important! + static const char* s_normalize[][2] = { + {" ", " " } + ,{", ", "," } + ,{" signed ", " " } + ,{",signed ", "," } + ,{"<signed ", "<" } + ,{"(signed ", "(" } + ,{"ulonglong", "unsigned long long" } + ,{"longlong", "long long" } + ,{"long unsigned", "unsigned long" } + ,{"short unsigned", "unsigned short" } + ,{"short int", "short" } + ,{"long int", "long" } + ,{"basic_string<char> ", "string"} + ,{"basic_string<char>", "string"} + ,{"basic_string<char,allocator<char> > ","string"} + ,{"basic_string<char,allocator<char> >","string"} + ,{"basic_string<char,char_traits<char>,allocator<char> > ","string"} + ,{"basic_string<char,char_traits<char>,allocator<char> >","string"} + }; - /// Completely ignore namespace std - while ( (occ=s.find("std::")) != std::string::npos ) { - s.replace(occ, 5, ""); - } - /// Completely ignore namespace std - while ( (occ=s.find(", ")) != std::string::npos ) { - s.replace(occ, 2, ","); + std::string CintName(const Type& typ) { + Type t(CleanType(typ)); + return CintName(t.Name(SCOPED)); + } + std::string CintName(const std::string& full_nam) { + if ( full_nam.length() > 255 ) { + char txt[256]; + sprintf(txt,"objecttype_%08lX", hash32(full_nam.c_str())); + return txt; } + else { + size_t occ; + std::string nam = full_nam; //(full) ? full_nam : cl->Name(); + std::string s = (nam.substr(0,2) == "::") ? nam.substr(2) : nam; - // - // Perform naming normalization for primitives - // since GCC-XML, this pile of shit just generates - // anything. - // - // Let's hope this will not kick us back sometimes. - // - for(size_t i=0; i<sizeof(s_normalize)/sizeof(s_normalize[0]); ++i) { - /// Normalize names - while ( (occ=s.find(s_normalize[i][0])) != std::string::npos ) { - s.replace(occ, strlen(s_normalize[i][0]), s_normalize[i][1]); - } - } - if ( s.find('[') != std::string::npos ) { - s = s.substr(0, s.find('[')); + /// Completely ignore namespace std + while ( (occ=s.find("std::")) != std::string::npos ) { + s.replace(occ, 5, ""); + } + /// Completely ignore namespace std + while ( (occ=s.find(", ")) != std::string::npos ) { + s.replace(occ, 2, ","); + } + + // + // Perform naming normalization for primitives + // since GCC-XML, this pile of shit just generates + // anything. + // + // Let's hope this will not kick us back sometimes. + // + for(size_t i=0; i<sizeof(s_normalize)/sizeof(s_normalize[0]); ++i) { + /// Normalize names + while ( (occ=s.find(s_normalize[i][0])) != std::string::npos ) { + s.replace(occ, strlen(s_normalize[i][0]), s_normalize[i][1]); + } + } + if ( s.find('[') != std::string::npos ) { + s = s.substr(0, s.find('[')); + } + return s; } - return s; - } - } + } - int CintTag(const std::string& Name) { - std::string n = CintName(Name); - if ( n == "-" ) return -1; - else return G__search_tagname(n.c_str(),'c'); - } + int CintTag(const std::string& Name) { + std::string n = CintName(Name); + if ( n == "-" ) return -1; + else return G__search_tagname(n.c_str(),'c'); + } - std::string CintSignature(const Member& func ) { - // Argument signature is: - // <type-char> <'object type name'> <typedef-name> <indirection> <default-value> <argument-Name> - // i - 'Int_t' 0 0 option - string signature; - Type ft = func.TypeOf(); - for ( size_t p = 0 ; p < ft.FunctionParameterSize(); p++ ) { - Type pt = ft.FunctionParameterAt(p); - string arg_sig; - Indirection indir = IndirectionGet(pt); - CintTypeDesc ctype = CintType(indir.second); - if( indir.first == 0 ) arg_sig += ctype.first; - else arg_sig += (ctype.first - ('a'-'A')); // if pointer: 'f' -> 'F' etc. - arg_sig += " "; - if( ctype.second == "-") arg_sig += "-"; - else { - int tagnum = G__defined_tagname(ctype.second.c_str(), 2); - if ( tagnum != -1 ) arg_sig += "'" + string(G__fulltagname(tagnum, 1)) + "'"; - else arg_sig += "'" + ctype.second + "'"; // object type name - } - if ( pt.IsTypedef() ) arg_sig += " '" + CintName(pt.Name(SCOPED)) + "' "; - else arg_sig += " - "; - // Assign indirection. First indirection already taken into account by uppercasing type - if( indir.first == 0 || indir.first == 1 ) { - if ( pt.IsReference() && pt.IsConst() ) arg_sig += "11"; - else if ( pt.IsReference() ) arg_sig += "1"; - else if ( pt.IsConst() ) arg_sig += "10"; - else arg_sig += "0"; - } - else { - arg_sig += char('0'+indir.first); // convert 2 -> '2', 3 ->'3' etc. - } - arg_sig += " "; - // Default value - if ( func.FunctionParameterDefaultAt(p) != "" ) arg_sig += "'" + func.FunctionParameterDefaultAt(p) + "'"; - else arg_sig += "-"; - arg_sig += " "; - // Parameter Name - if ( func.FunctionParameterNameAt(p) != "" ) arg_sig += func.FunctionParameterNameAt(p); - else arg_sig += "-"; + std::string CintSignature(const Member& func ) { + // Argument signature is: + // <type-char> <'object type name'> <typedef-name> <indirection> <default-value> <argument-Name> + // i - 'Int_t' 0 0 option + string signature; + Type ft = func.TypeOf(); + for ( size_t p = 0 ; p < ft.FunctionParameterSize(); p++ ) { + Type pt = ft.FunctionParameterAt(p); + string arg_sig; + Indirection indir = IndirectionGet(pt); + CintTypeDesc ctype = CintType(indir.second); + if( indir.first == 0 ) arg_sig += ctype.first; + else arg_sig += (ctype.first - ('a'-'A')); // if pointer: 'f' -> 'F' etc. + arg_sig += " "; + if( ctype.second == "-") arg_sig += "-"; + else { + int tagnum = G__defined_tagname(ctype.second.c_str(), 2); + if ( tagnum != -1 ) arg_sig += "'" + string(G__fulltagname(tagnum, 1)) + "'"; + else arg_sig += "'" + ctype.second + "'"; // object type name + } + if ( pt.IsTypedef() ) arg_sig += " '" + CintName(pt.Name(SCOPED)) + "' "; + else arg_sig += " - "; + // Assign indirection. First indirection already taken into account by uppercasing type + if( indir.first == 0 || indir.first == 1 ) { + if ( pt.IsReference() && pt.IsConst() ) arg_sig += "11"; + else if ( pt.IsReference() ) arg_sig += "1"; + else if ( pt.IsConst() ) arg_sig += "10"; + else arg_sig += "0"; + } + else { + arg_sig += char('0'+indir.first); // convert 2 -> '2', 3 ->'3' etc. + } + arg_sig += " "; + // Default value + if ( func.FunctionParameterDefaultAt(p) != "" ) arg_sig += "'" + func.FunctionParameterDefaultAt(p) + "'"; + else arg_sig += "-"; + arg_sig += " "; + // Parameter Name + if ( func.FunctionParameterNameAt(p) != "" ) arg_sig += func.FunctionParameterNameAt(p); + else arg_sig += "-"; - signature += arg_sig; - if ( p < ft.FunctionParameterSize() -1 ) signature += " "; - } - return signature; - } + signature += arg_sig; + if ( p < ft.FunctionParameterSize() -1 ) signature += " "; + } + return signature; + } - void FillCintResult( G__value* result, const Type& typ, void* obj ) { - CintTypeDesc ctype = CintType(typ); - char t = ctype.first; - if ( typ.IsPointer() ) t = (t - ('a'-'A')); - result->type = t; - switch( t ) { + void FillCintResult( G__value* result, const Type& typ, void* obj ) { + CintTypeDesc ctype = CintType(typ); + char t = ctype.first; + if ( typ.IsPointer() ) t = (t - ('a'-'A')); + result->type = t; + switch( t ) { case 'y': G__setnull(result); break; case 'Y': Converter<long>::toCint (result, obj); break; case 'g': Converter<bool>::toCint (result, obj); break; @@ -365,13 +365,13 @@ namespace ROOT { namespace Cintex { case 'q': Converter<long double>::toCint (result, obj); break; case 'Q': Converter<int>::toCint (result, obj); break; default: - result->obj.i = (long)obj; - if( ! typ.IsPointer()) result->ref = (long)obj; - else result->ref = 0; - result->tagnum = G__search_tagname(ctype.second.c_str(),'c'); - break; - } - } + result->obj.i = (long)obj; + if( ! typ.IsPointer()) result->ref = (long)obj; + else result->ref = 0; + result->tagnum = G__search_tagname(ctype.second.c_str(),'c'); + break; + } + } }} diff --git a/cintex/src/CINTVariableBuilder.cxx b/cintex/src/CINTVariableBuilder.cxx index 799d6466cb4c8e962be4e4003584229f6bc3eef3..99d914ba2cc48cc9e3186caa6e62e41f5e7b55cc 100644 --- a/cintex/src/CINTVariableBuilder.cxx +++ b/cintex/src/CINTVariableBuilder.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTVariableBuilder.cxx,v 1.1 2005/12/12 09:12:27 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTVariableBuilder.cxx,v 1.2 2006/06/29 15:30:49 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -27,182 +27,186 @@ using namespace std; namespace ROOT { namespace Cintex { - CINTVariableBuilder::CINTVariableBuilder(const ROOT::Reflex::Member& m) - : fVariable(m) { } - - CINTVariableBuilder::~CINTVariableBuilder() { - } - - void CINTVariableBuilder::Setup() { - - CINTScopeBuilder::Setup(fVariable.TypeOf()); - - Scope scope = fVariable.DeclaringScope(); - CINTScopeBuilder::Setup(scope); + CINTVariableBuilder::CINTVariableBuilder(const ROOT::Reflex::Member& m) + : fVariable(m) { + // default constructor + } + + CINTVariableBuilder::~CINTVariableBuilder() { + // destructor + } + + void CINTVariableBuilder::Setup() { + // setup variable info + CINTScopeBuilder::Setup(fVariable.TypeOf()); + + Scope scope = fVariable.DeclaringScope(); + CINTScopeBuilder::Setup(scope); - bool global = scope.IsTopScope(); - - if ( global ) { - ::G__resetplocal(); - } - else { - string sname = scope.Name(SCOPED); - int stagnum = ::G__defined_tagname(sname.c_str(), 2); - ::G__tag_memvar_setup(stagnum); - } - - Setup(fVariable); + bool global = scope.IsTopScope(); + + if ( global ) { + ::G__resetplocal(); + } + else { + string sname = scope.Name(SCOPED); + int stagnum = ::G__defined_tagname(sname.c_str(), 2); + ::G__tag_memvar_setup(stagnum); + } + + Setup(fVariable); - if ( global ) { - ::G__resetglobalenv(); - } - else { - ::G__tag_memvar_reset(); - } - return; - } - - class CommentBuffer { - private: - typedef std::vector<char*> VecC; - VecC fC; - CommentBuffer() {} - ~CommentBuffer() { - for(VecC::iterator i=fC.begin(); i != fC.end(); ++i) - delete [] *i; - fC.clear(); - } - public: - static CommentBuffer& Instance() { - static CommentBuffer inst; - return inst; - } - void add(char* cm) { - fC.push_back(cm); - } - }; - - void CINTVariableBuilder::Setup(const Member& dm ) { - char* comment = NULL; + if ( global ) { + ::G__resetglobalenv(); + } + else { + ::G__tag_memvar_reset(); + } + return; + } + + class CommentBuffer { + private: + typedef std::vector<char*> VecC; + VecC fC; + CommentBuffer() {} + ~CommentBuffer() { + for(VecC::iterator i=fC.begin(); i != fC.end(); ++i) + delete [] *i; + fC.clear(); + } + public: + static CommentBuffer& Instance() { + static CommentBuffer inst; + return inst; + } + void Add(char* cm) { + fC.push_back(cm); + } + }; + + void CINTVariableBuilder::Setup(const Member& dm ) { + // setup variable info + char* comment = NULL; - const char* ref_t = "pool::Reference"; - const char* tok_t = "pool::Token"; + const char* ref_t = "pool::Reference"; + const char* tok_t = "pool::Token"; - Type fClass = Type::ByName(dm.DeclaringScope().Name(SCOPED)); - string fName(CintName(fClass)); + Type fClass = Type::ByName(dm.DeclaringScope().Name(SCOPED)); + string fName(CintName(fClass)); - std::string cm = dm.Properties().HasKey("comment") ? - dm.Properties().PropertyAsString("comment") : std::string(""); + std::string cm = dm.Properties().HasKey("comment") ? + dm.Properties().PropertyAsString("comment") : std::string(""); - Type t = dm.TypeOf(); - while ( t.IsTypedef() ) t = t.ToType(); - if ( !t && dm.IsTransient() ) { - if( Cintex::Debug() ) cout << "Ignore transient member: " - << dm.Name(SCOPED) << " [No valid reflection class]" << endl; - return; - } - else if ( !t ) { - if( Cintex::Debug() > 0 ) { - cout << "WARNING: Member: " - << dm.Name(SCOPED) << " [No valid reflection class]" << endl; + Type t = dm.TypeOf(); + while ( t.IsTypedef() ) t = t.ToType(); + if ( !t && dm.IsTransient() ) { + if( Cintex::Debug() ) cout << "Ignore transient member: " + << dm.Name(SCOPED) << " [No valid reflection class]" << endl; + return; + } + else if ( !t ) { + if( Cintex::Debug() > 0 ) { + cout << "WARNING: Member: " + << dm.Name(SCOPED) << " [No valid reflection class]" << endl; + } + //throw std::runtime_error("Member: "+fName+"::"+dm.Name()+" [No valid reflection class]"); + } + //--- Add the necessary artificial comments ------ + if ( dm.IsTransient() || + IsSTL(fName) || + IsTypeOf(fClass, ref_t) || + IsTypeOf(fClass, tok_t) ) { + char* com = new char[cm.length()+4]; + ::sprintf(com,"! %s",cm.c_str()); + comment = com; + CommentBuffer::Instance().Add(comment); + } + else if ( (t.IsClass() || t.IsStruct()) && + (IsTypeOf(t,ref_t) || IsTypeOf(t,tok_t)) ) { + char* com = new char[cm.length()+4]; + ::sprintf(com,"|| %s",cm.c_str()); + comment = com; + CommentBuffer::Instance().Add(comment); + } + else if ( !cm.empty() ) { + char* com = new char[cm.length()+4]; + ::strcpy(com, cm.c_str()); + comment = com; + CommentBuffer::Instance().Add(comment); } - //throw std::runtime_error("Member: "+fName+"::"+dm.Name()+" [No valid reflection class]"); - } - //--- Add the necessary artificial comments ------ - if ( dm.IsTransient() || - IsSTL(fName) || - IsTypeOf(fClass, ref_t) || - IsTypeOf(fClass, tok_t) ) { - char* com = new char[cm.length()+4]; - ::sprintf(com,"! %s",cm.c_str()); - comment = com; - CommentBuffer::Instance().add(comment); - } - else if ( (t.IsClass() || t.IsStruct()) && - (IsTypeOf(t,ref_t) || IsTypeOf(t,tok_t)) ) { - char* com = new char[cm.length()+4]; - ::sprintf(com,"|| %s",cm.c_str()); - comment = com; - CommentBuffer::Instance().add(comment); - } - else if ( !cm.empty() ) { - char* com = new char[cm.length()+4]; - ::strcpy(com, cm.c_str()); - comment = com; - CommentBuffer::Instance().add(comment); - } - Indirection indir = IndirectionGet(dm.TypeOf()); - CintTypeDesc type = CintType(indir.second); - string dname = dm.Properties().HasKey("ioname") ? dm.Properties().PropertyAsString("ioname") : dm.Name(); - ostringstream ost; - if ( t.IsArray() ) ost << dname << "[" << t.ArrayLength() << "]="; - else ost << dname << "="; - string expr = ost.str(); - int member_type = type.first; - int member_indir = 0; - int member_tagnum = -1; - int member_typnum = -1; - int member_isstatic = dm.IsStatic() ? G__LOCALSTATIC : G__AUTO; - switch(indir.first) { + Indirection indir = IndirectionGet(dm.TypeOf()); + CintTypeDesc type = CintType(indir.second); + string dname = dm.Properties().HasKey("ioname") ? dm.Properties().PropertyAsString("ioname") : dm.Name(); + ostringstream ost; + if ( t.IsArray() ) ost << dname << "[" << t.ArrayLength() << "]="; + else ost << dname << "="; + string expr = ost.str(); + int member_type = type.first; + int member_indir = 0; + int member_tagnum = -1; + int member_typnum = -1; + int member_isstatic = dm.IsStatic() ? G__LOCALSTATIC : G__AUTO; + switch(indir.first) { case 0: - break; + break; case 1: - member_type -= 'a'-'A'; // if pointer: 'f' -> 'F' etc. - break; + member_type -= 'a'-'A'; // if pointer: 'f' -> 'F' etc. + break; default: - member_type -= 'a'-'A'; // if pointer: 'f' -> 'F' etc. - member_indir = indir.first; - break; - } - - if ( type.first == 'u' ) { - //dependencies.push_back(indir.second); - member_tagnum = dm.Properties().HasKey("iotype") ? CintTag(dm.Properties().PropertyAsString("iotype")) : CintTag(type.second); - if ( typeid(longlong) == indir.second.TypeInfo() ) - ::G__loadlonglong(&member_tagnum, &member_typnum, G__LONGLONG); - else if ( typeid(ulonglong) == indir.second.TypeInfo() ) - ::G__loadlonglong(&member_tagnum, &member_typnum, G__ULONGLONG); - else if ( typeid(long double) == indir.second.TypeInfo() ) - ::G__loadlonglong(&member_tagnum, &member_typnum, G__LONGDOUBLE); - } - - int member_access = 0; - if ( dm.IsPrivate() ) member_access = G__PRIVATE; - else if ( dm.IsProtected() ) member_access = G__PROTECTED; - else if ( dm.IsPublic() ) member_access = G__PUBLIC; - - if ( Cintex::Debug() > 2 ) { - std::cout - << std::setw(16) << std::left << "declareField>" - << " [" << char(member_type) - << "," << std::right << std::setw(3) << dm.Offset() - << "," << std::right << std::setw(2) << member_indir - << "," << std::right << std::setw(3) << member_tagnum - << "] " - << (dm.TypeOf().IsConst() ? "const " : "") - << std::left << std::setw(7) - << (G__AUTO==member_isstatic ? "auto " : "static ") - << std::left << std::setw(24) << dname - << " \"" << (char*)(comment ? comment : "(None)") << "\"" - << std::endl - << std::setw(16) << std::left << "declareField>" - << " Type:" - << std::left << std::setw(24) << ("[" + dm.Properties().HasKey("iotype") ? dm.Properties().PropertyAsString("iotype") : t.Name(SCOPED) + "]") - << " DeclBy:" << fClass.Name(SCOPED) - << std::endl; - } - ::G__memvar_setup((void*)dm.Offset(), // p - member_type, // type - member_indir, // indirection - dm.TypeOf().IsConst(), // const - member_tagnum, // tagnum - member_typnum, // typenum - member_isstatic, // statictype - member_access, // accessin - expr.c_str(), // expression - 0, // define macro - comment // comment - ); - } + member_type -= 'a'-'A'; // if pointer: 'f' -> 'F' etc. + member_indir = indir.first; + break; + } + + if ( type.first == 'u' ) { + //dependencies.push_back(indir.second); + member_tagnum = dm.Properties().HasKey("iotype") ? CintTag(dm.Properties().PropertyAsString("iotype")) : CintTag(type.second); + if ( typeid(longlong) == indir.second.TypeInfo() ) + ::G__loadlonglong(&member_tagnum, &member_typnum, G__LONGLONG); + else if ( typeid(ulonglong) == indir.second.TypeInfo() ) + ::G__loadlonglong(&member_tagnum, &member_typnum, G__ULONGLONG); + else if ( typeid(long double) == indir.second.TypeInfo() ) + ::G__loadlonglong(&member_tagnum, &member_typnum, G__LONGDOUBLE); + } + + int member_access = 0; + if ( dm.IsPrivate() ) member_access = G__PRIVATE; + else if ( dm.IsProtected() ) member_access = G__PROTECTED; + else if ( dm.IsPublic() ) member_access = G__PUBLIC; + + if ( Cintex::Debug() > 2 ) { + std::cout + << std::setw(16) << std::left << "declareField>" + << " [" << char(member_type) + << "," << std::right << std::setw(3) << dm.Offset() + << "," << std::right << std::setw(2) << member_indir + << "," << std::right << std::setw(3) << member_tagnum + << "] " + << (dm.TypeOf().IsConst() ? "const " : "") + << std::left << std::setw(7) + << (G__AUTO==member_isstatic ? "auto " : "static ") + << std::left << std::setw(24) << dname + << " \"" << (char*)(comment ? comment : "(None)") << "\"" + << std::endl + << std::setw(16) << std::left << "declareField>" + << " Type:" + << std::left << std::setw(24) << ("[" + dm.Properties().HasKey("iotype") ? dm.Properties().PropertyAsString("iotype") : t.Name(SCOPED) + "]") + << " DeclBy:" << fClass.Name(SCOPED) + << std::endl; + } + ::G__memvar_setup((void*)dm.Offset(), // p + member_type, // type + member_indir, // indirection + dm.TypeOf().IsConst(), // const + member_tagnum, // tagnum + member_typnum, // typenum + member_isstatic, // statictype + member_access, // accessin + expr.c_str(), // expression + 0, // define macro + comment // comment + ); + } }} diff --git a/cintex/src/CINTVariableBuilder.h b/cintex/src/CINTVariableBuilder.h index a896043c4841cab3c798f25e999c48c48a0b2e8a..f9c1b8a3f0495a3fe250324fb861aaa9f014dfb1 100644 --- a/cintex/src/CINTVariableBuilder.h +++ b/cintex/src/CINTVariableBuilder.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTFunctionBuilder.h,v 1.3 2005/11/17 14:12:33 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTVariableBuilder.h,v 1.1 2005/12/12 09:12:27 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -16,19 +16,19 @@ #include "CINTdefs.h" namespace ROOT { - namespace Cintex { + namespace Cintex { - class CINTVariableBuilder { - public: - CINTVariableBuilder(const ROOT::Reflex::Member& m); - ~CINTVariableBuilder(); - void Setup(void); - static void Setup(const ROOT::Reflex::Member&); - private: - const ROOT::Reflex::Member& fVariable; - }; + class CINTVariableBuilder { + public: + CINTVariableBuilder(const ROOT::Reflex::Member& m); + ~CINTVariableBuilder(); + void Setup(void); + static void Setup(const ROOT::Reflex::Member&); + private: + const ROOT::Reflex::Member& fVariable; + }; - } + } } #endif // ROOT_Cintex_CINTVariableBuilder diff --git a/cintex/src/Cintex.cxx b/cintex/src/Cintex.cxx index f4a7897faa8bc5f7cc21e17809ffe299e147c7f3..f444680abbf97c7c97fdc00a95426374fbc9f888 100644 --- a/cintex/src/Cintex.cxx +++ b/cintex/src/Cintex.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: Cintex.cxx,v 1.8 2006/04/28 06:40:18 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: Cintex.cxx,v 1.9 2006/06/21 18:39:30 brun Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -30,156 +30,156 @@ using namespace std; //Build the Cintex dictionary on Reflex and convert it to CINT namespace { - struct Cintex_dict { - public: - Cintex_dict() { - //--Reflex class builder - //NamespaceBuilder( "ROOT::Cintex" ); - Type t_void = TypeBuilder("void"); - Type t_int = TypeBuilder("int"); - Type t_bool = TypeBuilder("bool"); - ClassBuilderT< Cintex >("Cintex", PUBLIC) - .AddFunctionMember(FunctionTypeBuilder(t_void), "Enable", Enable, 0, 0, PUBLIC | STATIC) - .AddFunctionMember(FunctionTypeBuilder(t_void, t_int), "SetDebug", SetDebug, 0, 0, PUBLIC | STATIC) - .AddFunctionMember(FunctionTypeBuilder(t_int), "Debug", Debug, 0, 0, PUBLIC | STATIC) - .AddFunctionMember(FunctionTypeBuilder(t_bool), "PropagateClassTypedefs", PropagateClassTypedefs, 0, 0, PUBLIC | STATIC) - .AddFunctionMember(FunctionTypeBuilder(t_void, t_bool), "SetPropagateClassTypedefs", SetPropagateClassTypedefs, 0, 0, PUBLIC | STATIC); + struct Cintex_dict_t { + public: + Cintex_dict_t() { + //--Reflex class builder + //NamespaceBuilder( "ROOT::Cintex" ); + Type t_void = TypeBuilder("void"); + Type t_int = TypeBuilder("int"); + Type t_bool = TypeBuilder("bool"); + ClassBuilderT< Cintex >("Cintex", PUBLIC) + .AddFunctionMember(FunctionTypeBuilder(t_void), "Enable", Enable, 0, 0, PUBLIC | STATIC) + .AddFunctionMember(FunctionTypeBuilder(t_void, t_int), "SetDebug", SetDebug, 0, 0, PUBLIC | STATIC) + .AddFunctionMember(FunctionTypeBuilder(t_int), "Debug", Debug, 0, 0, PUBLIC | STATIC) + .AddFunctionMember(FunctionTypeBuilder(t_bool), "PropagateClassTypedefs", PropagateClassTypedefs, 0, 0, PUBLIC | STATIC) + .AddFunctionMember(FunctionTypeBuilder(t_void, t_bool), "SetPropagateClassTypedefs", SetPropagateClassTypedefs, 0, 0, PUBLIC | STATIC); - //--CINT class builder - Type t = Type::ByName("Cintex"); - ROOT::Cintex::CINTClassBuilder::Get(t).Setup(); + //--CINT class builder + Type t = Type::ByName("Cintex"); + ROOT::Cintex::CINTClassBuilder::Get(t).Setup(); } static void* Enable(void*, const std::vector<void*>&, void*) { - Cintex::Enable(); - return 0; + Cintex::Enable(); + return 0; } static void* SetDebug(void*, const std::vector<void*>& arg, void*) { - Cintex::SetDebug(*(bool*)arg[0]); - return 0; + Cintex::SetDebug(*(bool*)arg[0]); + return 0; } static void* Debug(void*, const std::vector<void*>&, void*) { - static int b = Cintex::Debug(); - return &b; + static int b = Cintex::Debug(); + return &b; } - static void* PropagateClassTypedefs(void*, const std::vector<void*>&, void*) { - static bool b = Cintex::PropagateClassTypedefs(); - return &b; - } + static void* PropagateClassTypedefs(void*, const std::vector<void*>&, void*) { + static bool b = Cintex::PropagateClassTypedefs(); + return &b; + } - static void* SetPropagateClassTypedefs(void*, const std::vector<void*>& arg, void*) { - Cintex::SetPropagateClassTypedefs(*(bool*)arg[0]); - return 0; - } + static void* SetPropagateClassTypedefs(void*, const std::vector<void*>& arg, void*) { + Cintex::SetPropagateClassTypedefs(*(bool*)arg[0]); + return 0; + } - }; - static Cintex_dict s_dict; + }; + static Cintex_dict_t s_dict; } namespace ROOT { - namespace Cintex { + namespace Cintex { - Cintex& Cintex::Instance() { - static Cintex s_instance; - return s_instance; - } - - Cintex::Cintex() { - fCallback = new Callback(); - fRootcreator = 0; - fDbglevel = 0; - fPropagateClassTypedefs = true; - fPropagateClassEnums = true; - fEnabled = false; - } - - Cintex::~Cintex() { - if( fCallback ) UninstallClassCallback( fCallback ); - delete fCallback; - } - - void Cintex::Enable() { - if ( Instance().fEnabled ) return; - //---Install the callback to fothcoming classes ----// - InstallClassCallback( Instance().fCallback ); - //---Convert to CINT all existing classes ---// - for( size_t i = 0; i < Type::TypeSize(); i++ ) { - - ( * Instance().fCallback)( Type::TypeAt(i) ); - } - //---Convert to CINT all existing free functions and variables - for ( size_t n = 0; n < Scope::ScopeSize(); n++ ) { - Scope ns = Scope::ScopeAt(n); - if ( ns.IsNamespace() ) { - for( size_t m = 0; m < ns.MemberSize(); m++ ) { - ( * Instance().fCallback)( ns.MemberAt(m) ); - } - } - } - Instance().fEnabled = true; - } - - void Cintex::SetROOTCreator(ROOTCreator c) { - Instance().fRootcreator = c; - } - - ROOTCreator Cintex::GetROOTCreator() { - return Instance().fRootcreator; - } - - int Cintex::Debug() { - return Instance().fDbglevel; - } - - void Cintex::SetDebug(int l) { - Instance().fDbglevel = l; - } - - - bool Cintex::PropagateClassTypedefs() { - return Instance().fPropagateClassTypedefs; - } - - void Cintex::SetPropagateClassTypedefs(bool val) { - Instance().fPropagateClassTypedefs = val; - } - - bool Cintex::PropagateClassEnums() { - return Instance().fPropagateClassEnums; - } - - void Cintex::SetPropagateClassEnums(bool val) { - Instance().fPropagateClassEnums = val; - } + Cintex& Cintex::Instance() { + static Cintex s_instance; + return s_instance; + } + + Cintex::Cintex() { + fCallback = new Callback(); + fRootcreator = 0; + fDbglevel = 0; + fPropagateClassTypedefs = true; + fPropagateClassEnums = true; + fEnabled = false; + } + + Cintex::~Cintex() { + if( fCallback ) UninstallClassCallback( fCallback ); + delete fCallback; + } + + void Cintex::Enable() { + if ( Instance().fEnabled ) return; + //---Install the callback to fothcoming classes ----// + InstallClassCallback( Instance().fCallback ); + //---Convert to CINT all existing classes ---// + for( size_t i = 0; i < Type::TypeSize(); i++ ) { + + ( * Instance().fCallback)( Type::TypeAt(i) ); + } + //---Convert to CINT all existing free functions and variables + for ( size_t n = 0; n < Scope::ScopeSize(); n++ ) { + Scope ns = Scope::ScopeAt(n); + if ( ns.IsNamespace() ) { + for( size_t m = 0; m < ns.MemberSize(); m++ ) { + ( * Instance().fCallback)( ns.MemberAt(m) ); + } + } + } + Instance().fEnabled = true; + } + + void Cintex::SetROOTCreator(ROOTCreator c) { + Instance().fRootcreator = c; + } + + ROOTCreator Cintex::GetROOTCreator() { + return Instance().fRootcreator; + } + + int Cintex::Debug() { + return Instance().fDbglevel; + } + + void Cintex::SetDebug(int l) { + Instance().fDbglevel = l; + } + + + bool Cintex::PropagateClassTypedefs() { + return Instance().fPropagateClassTypedefs; + } + + void Cintex::SetPropagateClassTypedefs(bool val) { + Instance().fPropagateClassTypedefs = val; + } + + bool Cintex::PropagateClassEnums() { + return Instance().fPropagateClassEnums; + } + + void Cintex::SetPropagateClassEnums(bool val) { + Instance().fPropagateClassEnums = val; + } - void Callback::operator () ( const Type& t ) { - int autoload = G__set_class_autoloading(0); // To avoid recursive loads - if ( t.IsClass() || t.IsStruct() ) { - ROOTClassEnhancer enhancer(t); - enhancer.Setup(); - CINTClassBuilder::Get(t).Setup(); - enhancer.CreateInfo(); - } - else if ( t.IsTypedef() ) { - CINTTypedefBuilder::Setup(t); - } - else if ( t.IsEnum() ) { - CINTEnumBuilder::Setup(t); - } - G__set_class_autoloading(autoload); - } + void Callback::operator () ( const Type& t ) { + int autoload = G__set_class_autoloading(0); // To avoid recursive loads + if ( t.IsClass() || t.IsStruct() ) { + ROOTClassEnhancer enhancer(t); + enhancer.Setup(); + CINTClassBuilder::Get(t).Setup(); + enhancer.CreateInfo(); + } + else if ( t.IsTypedef() ) { + CINTTypedefBuilder::Setup(t); + } + else if ( t.IsEnum() ) { + CINTEnumBuilder::Setup(t); + } + G__set_class_autoloading(autoload); + } - void Callback::operator () ( const Member& m ) { - int autoload = G__set_class_autoloading(0); // To avoid recursive loads - if ( m.IsFunctionMember() ) { - if( Cintex::Debug() ) cout << "Building function " << m.Name(SCOPED|QUALIFIED) << endl; - CINTFunctionBuilder(m).Setup(); - } - else if ( m.IsDataMember() ) { - if( Cintex::Debug() ) cout << "Building variable " << m.Name(SCOPED|QUALIFIED) << endl; - CINTVariableBuilder(m).Setup(); - } - G__set_class_autoloading(autoload); - } -}} + void Callback::operator () ( const Member& m ) { + int autoload = G__set_class_autoloading(0); // To avoid recursive loads + if ( m.IsFunctionMember() ) { + if( Cintex::Debug() ) cout << "Building function " << m.Name(SCOPED|QUALIFIED) << endl; + CINTFunctionBuilder(m).Setup(); + } + else if ( m.IsDataMember() ) { + if( Cintex::Debug() ) cout << "Building variable " << m.Name(SCOPED|QUALIFIED) << endl; + CINTVariableBuilder(m).Setup(); + } + G__set_class_autoloading(autoload); + } + }} diff --git a/cintex/src/ROOTClassEnhancer.cxx b/cintex/src/ROOTClassEnhancer.cxx index 75a914de2f0716f28dc771645d003733761f92c3..9f53bb6f1283eafc0dc2315bcac69bfd6d2ff858 100644 --- a/cintex/src/ROOTClassEnhancer.cxx +++ b/cintex/src/ROOTClassEnhancer.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: ROOTClassEnhancer.cxx,v 1.8 2006/05/05 15:24:15 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: ROOTClassEnhancer.cxx,v 1.9 2006/06/29 15:30:49 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -31,7 +31,7 @@ #include <sstream> #if ROOT_VERSION_CODE >= ROOT_VERSION(5,1,1) - #include "TVirtualIsAProxy.h" +#include "TVirtualIsAProxy.h" #endif using namespace ROOT::Reflex; @@ -40,487 +40,504 @@ using namespace std; namespace ROOT { namespace Cintex { - class IsAProxy; - - class ROOTClassEnhancerInfo { - - Type fType; - string fName; - TClass* fTclass; - TClass* fLastClass; - std::map<const std::type_info*,TClass*> fSub_types; - const std::type_info* fLastType; - const std::type_info* fMyType; - bool fIsVirtual; - ROOT::TGenericClassInfo* fClassInfo; - #if ROOT_VERSION_CODE >= ROOT_VERSION(5,1,1) - IsAProxy* fIsa_func; - #else - IsAFunc_t fIsa_func; - #endif - VoidFuncPtr_t fDictionary_func; - - public: - ROOTClassEnhancerInfo(Type& t); - virtual ~ROOTClassEnhancerInfo(); - - virtual void Setup(void); - virtual void CreateInfo(void); - TClass* tclass() { - if ( fTclass == 0 ) { - fTclass = ROOT::GetROOT()->GetClass( Name().c_str() /*, kFALSE */); + class IsAProxy; + + class ROOTClassEnhancerInfo { + + Type fType; + string fName; + TClass* fTclass; + TClass* fLastClass; + std::map<const std::type_info*,TClass*> fSub_types; + const std::type_info* fLastType; + const std::type_info* fMyType; + bool fIsVirtual; + ROOT::TGenericClassInfo* fClassInfo; +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,1,1) + IsAProxy* fIsa_func; +#else + IsAFunc_t fIsa_func; +#endif + VoidFuncPtr_t fDictionary_func; + + public: + ROOTClassEnhancerInfo(Type& t); + virtual ~ROOTClassEnhancerInfo(); + + virtual void Setup(void); + virtual void CreateInfo(void); + TClass* Tclass() { + if ( fTclass == 0 ) { + fTclass = ROOT::GetROOT()->GetClass( Name().c_str() /*, kFALSE */); + } + return fTclass; } - return fTclass; - } - const Type& TypeGet() const { return fType; } - const string& Name() const { return fName; } - ROOT::TGenericClassInfo* info() const { return fClassInfo; } + const Type& TypeGet() const { return fType; } + const string& Name() const { return fName; } + ROOT::TGenericClassInfo* Info() const { return fClassInfo; } - void addFunction( const std::string& Name, const ROOT::Reflex::Type& sig, + void AddFunction( const std::string& Name, const ROOT::Reflex::Type& sig, ROOT::Reflex::StubFunction stubFP, void* stubCtx, int ); - TClass* IsA(const void* obj); - static void* stub_IsA2(void* ctxt, void* obj); - static void* stub_IsA(void*, const std::vector<void*>&, void*); - static void* stub_Streamer(void*, const std::vector<void*>&, void*); - static void* stub_StreamerNVirtual(void*, const std::vector<void*>&, void*); - static void* stub_Dictionary(void*, const std::vector<void*>&, void*); - static void* stub_ShowMembers(void*, const std::vector<void*>&, void*); - static void stub_ShowMembers(TClass*, const ROOT::Reflex::Type&, void*, TMemberInspector&, char*); - static void stub_Dictionary( void* ctx ); - static TClass* default_CreateClass(Type typ, ROOT::TGenericClassInfo* info); - }; + TClass* IsA(const void* obj); + static void* Stub_IsA2(void* ctxt, void* obj); + static void* Stub_IsA(void*, const std::vector<void*>&, void*); + static void* Stub_Streamer(void*, const std::vector<void*>&, void*); + static void* Stub_StreamerNVirtual(void*, const std::vector<void*>&, void*); + static void* Stub_Dictionary(void*, const std::vector<void*>&, void*); + static void* Stub_ShowMembers(void*, const std::vector<void*>&, void*); + static void Stub_ShowMembers(TClass*, const ROOT::Reflex::Type&, void*, TMemberInspector&, char*); + static void Stub_Dictionary( void* ctx ); + static TClass* Default_CreateClass(Type typ, ROOT::TGenericClassInfo* info); + }; #if ROOT_VERSION_CODE >= ROOT_VERSION(5,1,1) - class IsAProxy : public TVirtualIsAProxy { - public: - IsAProxy( ROOTClassEnhancerInfo* info ) : fInfo(info), fClass(0) {} - void SetClass(TClass *cl) { fClass = cl;} - TClass* operator()(const void *obj){ return obj == 0 ? fClass : fInfo->IsA(obj); } - private: - ROOTClassEnhancerInfo* fInfo; - TClass* fClass; - }; + class IsAProxy : public TVirtualIsAProxy { + public: + IsAProxy( ROOTClassEnhancerInfo* info ) : fInfo(info), fClass(0) {} + void SetClass(TClass *cl) { fClass = cl;} + TClass* operator()(const void *obj){ return obj == 0 ? fClass : fInfo->IsA(obj); } + private: + ROOTClassEnhancerInfo* fInfo; + TClass* fClass; + }; #endif - class ROOTEnhancerCont : public std::vector<ROOTClassEnhancerInfo*> { - public: - ROOTEnhancerCont() {} - ~ROOTEnhancerCont() { - for(std::vector<ROOTClassEnhancerInfo*>::iterator j=begin(); j!= end(); ++j) - delete (*j); - clear(); - } - }; - - std::vector<ROOTClassEnhancerInfo*>& rootEnhancerInfos() { - static ROOTEnhancerCont s_cont; - return s_cont; - } - - ROOTClassEnhancer::ROOTClassEnhancer(const ROOT::Reflex::Type& cl) { - fClass = CleanType(cl); - fName = CintName(fClass); - } - - ROOTClassEnhancer::~ROOTClassEnhancer() { - } - - void ROOTClassEnhancer::Setup() { - ROOTClassEnhancerInfo* p = new ROOTClassEnhancerInfo(fClass); - fEnhancerinfo = p; - p->Setup(); - } - - void ROOTClassEnhancer::CreateInfo() { - if ( fEnhancerinfo ) { - ROOTClassEnhancerInfo* p = (ROOTClassEnhancerInfo*)fEnhancerinfo; - p->CreateInfo(); - } - } - - - /// Access streamer info from a void (polymorph) pointer - TClass* accessType(const TClass* cl, const void* /* ptr */) { - return (TClass*)cl; - } - - ROOTClassEnhancerInfo::ROOTClassEnhancerInfo(Type& t) : - fTclass(0), fLastClass(0), fLastType(0) - { - fType = CleanType(t); - fName = CintName(fType); - rootEnhancerInfos().push_back(this); - fMyType = &t.TypeInfo(); - fIsVirtual = TypeGet().IsVirtual(); - fClassInfo = 0; - fIsa_func = 0; - fDictionary_func = 0; - } - - ROOTClassEnhancerInfo::~ROOTClassEnhancerInfo() { - fSub_types.clear(); - if ( fClassInfo ) delete fClassInfo; - #if ROOT_VERSION_CODE >= ROOT_VERSION(5,1,1) + class ROOTEnhancerCont : public std::vector<ROOTClassEnhancerInfo*> { + public: + ROOTEnhancerCont() {} + ~ROOTEnhancerCont() { + for(std::vector<ROOTClassEnhancerInfo*>::iterator j=begin(); j!= end(); ++j) + delete (*j); + clear(); + } + }; + + std::vector<ROOTClassEnhancerInfo*>& rootEnhancerInfos() { + static ROOTEnhancerCont s_cont; + return s_cont; + } + + ROOTClassEnhancer::ROOTClassEnhancer(const ROOT::Reflex::Type& cl) { + // constructor + fClass = CleanType(cl); + fName = CintName(fClass); + } + + ROOTClassEnhancer::~ROOTClassEnhancer() { + // destructor + } + + void ROOTClassEnhancer::Setup() { + // enhance root class info + ROOTClassEnhancerInfo* p = new ROOTClassEnhancerInfo(fClass); + fEnhancerinfo = p; + p->Setup(); + } + + void ROOTClassEnhancer::CreateInfo() { + // enhance root class info + if ( fEnhancerinfo ) { + ROOTClassEnhancerInfo* p = (ROOTClassEnhancerInfo*)fEnhancerinfo; + p->CreateInfo(); + } + } + + + /// Access streamer info from a void (polymorph) pointer + TClass* accessType(const TClass* cl, const void* /* ptr */) { + return (TClass*)cl; + } + + ROOTClassEnhancerInfo::ROOTClassEnhancerInfo(Type& t) : + fTclass(0), fLastClass(0), fLastType(0) + { + // constructor + fType = CleanType(t); + fName = CintName(fType); + rootEnhancerInfos().push_back(this); + fMyType = &t.TypeInfo(); + fIsVirtual = TypeGet().IsVirtual(); + fClassInfo = 0; + fIsa_func = 0; + fDictionary_func = 0; + } + + ROOTClassEnhancerInfo::~ROOTClassEnhancerInfo() { + // destructor + fSub_types.clear(); + if ( fClassInfo ) delete fClassInfo; +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,1,1) // fIsa_func is deleted by ROOT - #else +#else if ( fIsa_func ) Free_function((void*)fIsa_func); - #endif - if ( fDictionary_func ) Free_function((void*)fDictionary_func); - } - - void ROOTClassEnhancerInfo::Setup() { - std::string nam = TypeGet().Name(SCOPED); - if ( Cintex::Debug() > 1 ) { - std::cout << "Enhancing:" << nam << std::endl; - } - if ( ! IsSTLext(nam) && (IsSTL(nam) || IsSTLinternal(nam)) ) { +#endif + if ( fDictionary_func ) Free_function((void*)fDictionary_func); + } + + void ROOTClassEnhancerInfo::Setup() { + // setup root class enhance + std::string nam = TypeGet().Name(SCOPED); + if ( Cintex::Debug() > 1 ) { + std::cout << "Enhancing:" << nam << std::endl; + } + if ( ! IsSTLext(nam) && (IsSTL(nam) || IsSTLinternal(nam)) ) { + //--- create TGenericClassInfo Instance + //createInfo(); + return; + } + else { + Type int_t = Type::ByName("int"); + Type void_t = Type::ByName("void"); + Type char_t = Type::ByName("char"); + Type signature; + void* ctxt = this; + + //--- adding TClass* IsA() + signature = FunctionTypeBuilder( PointerBuilder(TypeBuilder("TClass"))); + AddFunction("IsA", signature, Stub_IsA, ctxt, 0); + //--- adding void Data_ShowMembers(void *, TMemberInspector&, char*) + signature = FunctionTypeBuilder( void_t, + ReferenceBuilder(TypeBuilder("TMemberInspector")), + PointerBuilder(char_t)); + AddFunction("ShowMembers", signature, Stub_ShowMembers, ctxt, VIRTUAL); + signature = FunctionTypeBuilder( void_t, ReferenceBuilder(TypeBuilder("TBuffer"))); + AddFunction("Streamer", signature, Stub_Streamer, ctxt, VIRTUAL); + AddFunction("StreamerNVirtual", signature, Stub_StreamerNVirtual, ctxt, 0); + } //--- create TGenericClassInfo Instance //createInfo(); - return; - } - else { - Type int_t = Type::ByName("int"); - Type void_t = Type::ByName("void"); - Type char_t = Type::ByName("char"); - Type signature; - void* ctxt = this; - - //--- adding TClass* IsA() - signature = FunctionTypeBuilder( PointerBuilder(TypeBuilder("TClass"))); - addFunction("IsA", signature, stub_IsA, ctxt, 0); - //--- adding void Data_ShowMembers(void *, TMemberInspector&, char*) - signature = FunctionTypeBuilder( void_t, - ReferenceBuilder(TypeBuilder("TMemberInspector")), - PointerBuilder(char_t)); - addFunction("ShowMembers", signature, stub_ShowMembers, ctxt, VIRTUAL); - signature = FunctionTypeBuilder( void_t, ReferenceBuilder(TypeBuilder("TBuffer"))); - addFunction("Streamer", signature, stub_Streamer, ctxt, VIRTUAL); - addFunction("StreamerNVirtual", signature, stub_StreamerNVirtual, ctxt, 0); - } - //--- create TGenericClassInfo Instance - //createInfo(); - } - - void ROOTClassEnhancerInfo::CreateInfo() { - //---Check is the the dictionary is already defined for the class - VoidFuncPtr_t dict = TClassTable::GetDict(Name().c_str()); - if ( dict ) return; - - void* context = this; + } + + void ROOTClassEnhancerInfo::CreateInfo() { + //---Check is the the dictionary is already defined for the class + VoidFuncPtr_t dict = TClassTable::GetDict(Name().c_str()); + if ( dict ) return; + + void* context = this; #if ROOT_VERSION_CODE >= ROOT_VERSION(5,1,1) - fIsa_func = new IsAProxy(this); + fIsa_func = new IsAProxy(this); #else - fIsa_func = (IsAFunc_t)Allocate_1arg_function(context, stub_IsA2); + fIsa_func = (IsAFunc_t)Allocate_1arg_function(context, Stub_IsA2); #endif - fDictionary_func = Allocate_void_function(context, stub_Dictionary); - - ::ROOT::TGenericClassInfo* info = new ::ROOT::TGenericClassInfo( - Name().c_str(), // Class Name - "", // declaration file Name - 1, // declaration line number - TypeGet().TypeInfo(), // typeid - ROOT::DefineBehavior(0,0), // default behavior - 0, // show members function - fDictionary_func, // dictionary function - fIsa_func, // IsA function - 0, // pragma bits - TypeGet().SizeOf() // sizeof - ); - info->SetImplFile("", 1); - //----Fill the New and Deletete functions - Member getfuncs = TypeGet().MemberByName("__getNewDelFunctions"); - if( getfuncs ) { - NewDelFunctions* newdelfunc = (NewDelFunctions*)( getfuncs.Invoke().Address() ); - if ( newdelfunc ) { - info->SetNew(newdelfunc->New); - info->SetNewArray(newdelfunc->NewArray); - info->SetDelete(newdelfunc->Delete); - info->SetDeleteArray(newdelfunc->DeleteArray); - info->SetDestructor(newdelfunc->Destructor); + fDictionary_func = Allocate_void_function(context, Stub_Dictionary); + + ::ROOT::TGenericClassInfo* info = new ::ROOT::TGenericClassInfo( + Name().c_str(), // Class Name + "", // declaration file Name + 1, // declaration line number + TypeGet().TypeInfo(), // typeid + ROOT::DefineBehavior(0,0), // default behavior + 0, // show members function + fDictionary_func, // dictionary function + fIsa_func, // IsA function + 0, // pragma bits + TypeGet().SizeOf() // sizeof + ); + info->SetImplFile("", 1); + //----Fill the New and Deletete functions + Member getfuncs = TypeGet().MemberByName("__getNewDelFunctions"); + if( getfuncs ) { + NewDelFunctions_t* newdelfunc = (NewDelFunctions_t*)( getfuncs.Invoke().Address() ); + if ( newdelfunc ) { + info->SetNew(newdelfunc->fNew); + info->SetNewArray(newdelfunc->fNewArray); + info->SetDelete(newdelfunc->fDelete); + info->SetDeleteArray(newdelfunc->fDeleteArray); + info->SetDestructor(newdelfunc->fDestructor); + } } - } - fClassInfo = info; - } - - struct fornamespace {}; - void ROOTClassEnhancer::CreateClassForNamespace(const std::string& Name ) { - - ROOT::CreateClass(Name.c_str(), // Name - 0, // version - typeid(fornamespace), // typeid - 0, // TVirtualIsAProxy *isa, - 0, // ShowMembersFunc_t show, - "", // definition file - "", // implementation file - 1, // definition line number - 1 ); // implementation line number - } - - void ROOTClassEnhancerInfo::addFunction( const std::string& Name, - const Type & sig, - StubFunction stubFP, - void* stubCtx, - int mods) - { - fType.AddFunctionMember( Name.c_str(), sig, stubFP, stubCtx, 0, PUBLIC | mods ); - } - - inline static ROOTClassEnhancerInfo& context(void* ctxt) { - if ( ctxt ) { - return *(ROOTClassEnhancerInfo*)ctxt; - } - throw std::runtime_error("Invalid stub context passes to emultated function!"); - } - - - void* ROOTClassEnhancerInfo::stub_IsA(void* obj, const vector<void*>&, void* ctx) { - return context(ctx).IsA(obj); - } - void* ROOTClassEnhancerInfo::stub_IsA2(void* ctx, void* obj) { - return context(ctx).IsA(obj); - } - - struct DynamicStruct { virtual ~DynamicStruct() {} }; - - TClass* ROOTClassEnhancerInfo::IsA(const void* obj) { - if ( ! obj || ! fIsVirtual ) { - return tclass(); - } - else { - // Avoid the case that the first word is a virtual_base_offset_table instead of - // a virtual_function_table - long Offset = **(long**)obj; - if ( Offset == 0 ) return tclass(); - - DynamicStruct* p = (DynamicStruct*)obj; - const std::type_info& typ = typeid(*p); - - if ( &typ == fMyType ) { - return tclass(); + fClassInfo = info; + } + + struct Fornamespace_t {}; + void ROOTClassEnhancer::CreateClassForNamespace(const std::string& Name ) { + // create root class + ROOT::CreateClass(Name.c_str(), // Name + 0, // version + typeid(Fornamespace_t), // typeid + 0, // TVirtualIsAProxy *isa, + 0, // ShowMembersFunc_t show, + "", // definition file + "", // implementation file + 1, // definition line number + 1 ); // implementation line number + } + + void ROOTClassEnhancerInfo::AddFunction( const std::string& Name, + const Type & sig, + StubFunction stubFP, + void* stubCtx, + int mods) + { + // add function info + fType.AddFunctionMember( Name.c_str(), sig, stubFP, stubCtx, 0, PUBLIC | mods ); + } + + inline static ROOTClassEnhancerInfo& context(void* ctxt) { + if ( ctxt ) { + return *(ROOTClassEnhancerInfo*)ctxt; } - else if ( &typ == fLastType ) { - return fLastClass; - } - // Check if TypeNth is already in sub-class cache - else if ( 0 != (fLastClass=fSub_types[&typ]) ) { - fLastType = &typ; + throw std::runtime_error("Invalid stub context passes to emultated function!"); + } + + + void* ROOTClassEnhancerInfo::Stub_IsA(void* obj, const vector<void*>&, void* ctx) { + // root IsA + return context(ctx).IsA(obj); + } + void* ROOTClassEnhancerInfo::Stub_IsA2(void* ctx, void* obj) { + // root AsA + return context(ctx).IsA(obj); + } + + struct DynamicStruct_t { virtual ~DynamicStruct_t() {} }; + + TClass* ROOTClassEnhancerInfo::IsA(const void* obj) { + // root IsA + if ( ! obj || ! fIsVirtual ) { + return Tclass(); } - // Last resort: lookup root class - else { - Type t = Type::ByTypeInfo(typ); - std::string nam = CintName(t); - fLastClass = ROOT::GetROOT()->GetClass(nam.c_str()); - fSub_types[fLastType=&typ] = fLastClass; + else { + // Avoid the case that the first word is a virtual_base_offset_table instead of + // a virtual_function_table + long Offset = **(long**)obj; + if ( Offset == 0 ) return Tclass(); + + DynamicStruct_t* p = (DynamicStruct_t*)obj; + const std::type_info& typ = typeid(*p); + + if ( &typ == fMyType ) { + return Tclass(); + } + else if ( &typ == fLastType ) { + return fLastClass; + } + // Check if TypeNth is already in sub-class cache + else if ( 0 != (fLastClass=fSub_types[&typ]) ) { + fLastType = &typ; + } + // Last resort: lookup root class + else { + Type t = Type::ByTypeInfo(typ); + std::string nam = CintName(t); + fLastClass = ROOT::GetROOT()->GetClass(nam.c_str()); + fSub_types[fLastType=&typ] = fLastClass; + } } - } - //std::cout << "IsA:" << TypeNth.Name(SCOPED) << " dynamic:" << dtype.Name(SCOPED) << std::endl; - return fLastClass; - } + //std::cout << "IsA:" << TypeNth.Name(SCOPED) << " dynamic:" << dtype.Name(SCOPED) << std::endl; + return fLastClass; + } - TClass* ROOTClassEnhancerInfo::default_CreateClass( Type typ, ROOT::TGenericClassInfo* info) { - TClass* root_class = 0; - std::string Name = typ.Name(SCOPED); - int kind = TClassEdit::IsSTLCont(Name.c_str()); - if ( kind < 0 ) kind = -kind; - const char* tagname = Name.c_str(); - int tagnum = ::G__defined_tagname(tagname, 2); - G__ClassInfo cl_info(tagnum); - if ( cl_info.IsValid() ) { - switch(kind) { - case TClassEdit::kVector: - case TClassEdit::kList: - case TClassEdit::kDeque: - case TClassEdit::kMap: - case TClassEdit::kMultiMap: - case TClassEdit::kSet: - case TClassEdit::kMultiSet: - cl_info.SetVersion(4); - break; - case TClassEdit::kNotSTL: - case TClassEdit::kEnd: - cl_info.SetVersion(1); - break; + TClass* ROOTClassEnhancerInfo::Default_CreateClass( Type typ, ROOT::TGenericClassInfo* info) { + // create root class + TClass* root_class = 0; + std::string Name = typ.Name(SCOPED); + int kind = TClassEdit::IsSTLCont(Name.c_str()); + if ( kind < 0 ) kind = -kind; + const char* tagname = Name.c_str(); + int tagnum = ::G__defined_tagname(tagname, 2); + G__ClassInfo cl_info(tagnum); + if ( cl_info.IsValid() ) { + switch(kind) { + case TClassEdit::kVector: + case TClassEdit::kList: + case TClassEdit::kDeque: + case TClassEdit::kMap: + case TClassEdit::kMultiMap: + case TClassEdit::kSet: + case TClassEdit::kMultiSet: + cl_info.SetVersion(4); + break; + case TClassEdit::kNotSTL: + case TClassEdit::kEnd: + cl_info.SetVersion(1); + break; + } } - } - - const std::type_info& tid = typ.TypeInfo(); - root_class = info->GetClass(); - - if ( 0 != root_class ) { - root_class->Size(); - if ( ! typ.IsVirtual() ) root_class->SetGlobalIsA(accessType); - std::auto_ptr<TClassStreamer> str; - switch(kind) { - case TClassEdit::kVector: - case TClassEdit::kList: - case TClassEdit::kDeque: - case TClassEdit::kMap: - case TClassEdit::kMultiMap: - case TClassEdit::kSet: - case TClassEdit::kMultiSet: - { - Member method = typ.MemberByName("createCollFuncTable"); - if ( !method ) { - if ( Cintex::Debug() ) { - cout << Name << "' Setup failed to create this class! " - << "The function createCollFuncTable is not availible." - << endl; - } - return 0; - } - std::auto_ptr<CollFuncTable> m((CollFuncTable*)method.Invoke().Address()); - std::auto_ptr<TCollectionProxy::Proxy_t> proxy( + + const std::type_info& tid = typ.TypeInfo(); + root_class = info->GetClass(); + + if ( 0 != root_class ) { + root_class->Size(); + if ( ! typ.IsVirtual() ) root_class->SetGlobalIsA(accessType); + std::auto_ptr<TClassStreamer> str; + switch(kind) { + case TClassEdit::kVector: + case TClassEdit::kList: + case TClassEdit::kDeque: + case TClassEdit::kMap: + case TClassEdit::kMultiMap: + case TClassEdit::kSet: + case TClassEdit::kMultiSet: + { + Member method = typ.MemberByName("createCollFuncTable"); + if ( !method ) { + if ( Cintex::Debug() ) { + cout << Name << "' Setup failed to create this class! " + << "The function createCollFuncTable is not availible." + << endl; + } + return 0; + } + std::auto_ptr<CollFuncTable> m((CollFuncTable*)method.Invoke().Address()); + std::auto_ptr<TCollectionProxy::Proxy_t> proxy( #if ROOT_VERSION_CODE >= ROOT_VERSION(5,4,0) - TCollectionProxy::GenExplicitProxy(tid, + TCollectionProxy::GenExplicitProxy(tid, #else - TCollectionProxy::genExplicitProxy(tid, + TCollectionProxy::genExplicitProxy(tid, #endif - m->iter_size, - m->value_diff, - m->value_offset, - m->size_func, - m->resize_func, - m->clear_func, - m->first_func, - m->next_func, - m->construct_func, - m->destruct_func, - m->feed_func, - m->collect_func - )); - std::auto_ptr<TClassStreamer> str( + m->iter_size, + m->value_diff, + m->value_offset, + m->size_func, + m->resize_func, + m->clear_func, + m->first_func, + m->next_func, + m->construct_func, + m->destruct_func, + m->feed_func, + m->collect_func + )); + std::auto_ptr<TClassStreamer> str( #if ROOT_VERSION_CODE >= ROOT_VERSION(5,4,0) - TCollectionProxy::GenExplicitClassStreamer(tid, + TCollectionProxy::GenExplicitClassStreamer(tid, #else - TCollectionProxy::genExplicitClassStreamer(tid, + TCollectionProxy::genExplicitClassStreamer(tid, #endif - m->iter_size, - m->value_diff, - m->value_offset, - m->size_func, - m->resize_func, - m->clear_func, - m->first_func, - m->next_func, - m->construct_func, - m->destruct_func, - m->feed_func, - m->collect_func - )); - root_class->CopyCollectionProxy(*(proxy.get())); - root_class->SetBit(TClass::kIsForeign); - if ( str.get() ) { - root_class->AdoptStreamer(str.release()); + m->iter_size, + m->value_diff, + m->value_offset, + m->size_func, + m->resize_func, + m->clear_func, + m->first_func, + m->next_func, + m->construct_func, + m->destruct_func, + m->feed_func, + m->collect_func + )); + root_class->CopyCollectionProxy(*(proxy.get())); + root_class->SetBit(TClass::kIsForeign); + if ( str.get() ) { + root_class->AdoptStreamer(str.release()); + } + } + break; + case TClassEdit::kNotSTL: + case TClassEdit::kEnd: + default: + root_class->SetBit(TClass::kIsForeign); + } } - } - break; - case TClassEdit::kNotSTL: - case TClassEdit::kEnd: - default: - root_class->SetBit(TClass::kIsForeign); - } - } - return root_class; - } - - void ROOTClassEnhancerInfo::stub_Dictionary(void* ctx ) - { - if( Cintex::GetROOTCreator() ) { - (*Cintex::GetROOTCreator())( context(ctx).TypeGet(), context(ctx).info() ); - } - else { - //context(ctx).info()->GetClass(); - default_CreateClass( context(ctx).TypeGet(), context(ctx).info() ); - } - } - - - void* ROOTClassEnhancerInfo::stub_Streamer(void* obj, const vector<void*>& args, void* ctx) { - TBuffer& b = *(TBuffer*)args[0]; - TClass* cl = context(ctx).tclass(); - TClassStreamer* s = cl->GetStreamer(); - if ( s ) { - (*s)(b, obj); - } - else if ( b.IsWriting() ) { - cl->WriteBuffer(b, obj); - } - else { - UInt_t start, count; - Version_t version = b.ReadVersion(&start, &count, cl); - cl->ReadBuffer(b, obj, version, start, count); - } - return 0; - } - - void* ROOTClassEnhancerInfo::stub_StreamerNVirtual(void* obj, const vector<void*>& args, void* ctx) { - TBuffer& b = *(TBuffer*)args[0]; - TClass* cl = context(ctx).tclass(); - TClassStreamer* s = cl->GetStreamer(); - if ( s ) { - (*s)(b, obj); - } - else if ( b.IsWriting() ) { - cl->WriteBuffer(b, obj); - } - else { - UInt_t start, count; - Version_t version = b.ReadVersion(&start, &count, cl); - cl->ReadBuffer(b, obj, version, start, count); - } - return 0; - } - - void* ROOTClassEnhancerInfo::stub_ShowMembers(void* obj, const vector<void*>& args, void* ctx) { - const Type& TypeNth = context(ctx).TypeGet(); - TClass* tcl = context(ctx).tclass(); - TMemberInspector& insp = *(TMemberInspector*)args[0]; - char* par = (char*)args[1]; - if( tcl ) stub_ShowMembers( tcl, TypeNth, obj, insp, par); - return 0; - } - - void ROOTClassEnhancerInfo::stub_ShowMembers(TClass* tcl, const Type& cl, void* obj, TMemberInspector& insp, char* par) { - int ncp = ::strlen(par); - // Loop over data members - if ( IsSTL(cl.Name(SCOPED)) || cl.IsArray() ) return; - for ( size_t m = 0; m < cl.DataMemberSize(); m++) { - Member mem = cl.DataMemberAt(m); - if ( ! mem.IsTransient() ) { - Type typ = mem.TypeOf(); - string nam = mem.Properties().HasKey("ioname") ? + return root_class; + } + + void ROOTClassEnhancerInfo::Stub_Dictionary(void* ctx ) + { + // create class info + if( Cintex::GetROOTCreator() ) { + (*Cintex::GetROOTCreator())( context(ctx).TypeGet(), context(ctx).Info() ); + } + else { + //context(ctx).Info()->GetClass(); + Default_CreateClass( context(ctx).TypeGet(), context(ctx).Info() ); + } + } + + + void* ROOTClassEnhancerInfo::Stub_Streamer(void* obj, const vector<void*>& args, void* ctx) { + // create streamer info + TBuffer& b = *(TBuffer*)args[0]; + TClass* cl = context(ctx).Tclass(); + TClassStreamer* s = cl->GetStreamer(); + if ( s ) { + (*s)(b, obj); + } + else if ( b.IsWriting() ) { + cl->WriteBuffer(b, obj); + } + else { + UInt_t start, count; + Version_t version = b.ReadVersion(&start, &count, cl); + cl->ReadBuffer(b, obj, version, start, count); + } + return 0; + } + + void* ROOTClassEnhancerInfo::Stub_StreamerNVirtual(void* obj, const vector<void*>& args, void* ctx) { + // create streamer info + TBuffer& b = *(TBuffer*)args[0]; + TClass* cl = context(ctx).Tclass(); + TClassStreamer* s = cl->GetStreamer(); + if ( s ) { + (*s)(b, obj); + } + else if ( b.IsWriting() ) { + cl->WriteBuffer(b, obj); + } + else { + UInt_t start, count; + Version_t version = b.ReadVersion(&start, &count, cl); + cl->ReadBuffer(b, obj, version, start, count); + } + return 0; + } + + void* ROOTClassEnhancerInfo::Stub_ShowMembers(void* obj, const vector<void*>& args, void* ctx) { + // create show members + const Type& TypeNth = context(ctx).TypeGet(); + TClass* tcl = context(ctx).Tclass(); + TMemberInspector& insp = *(TMemberInspector*)args[0]; + char* par = (char*)args[1]; + if( tcl ) Stub_ShowMembers( tcl, TypeNth, obj, insp, par); + return 0; + } + + void ROOTClassEnhancerInfo::Stub_ShowMembers(TClass* tcl, const Type& cl, void* obj, TMemberInspector& insp, char* par) { + // create show members + int ncp = ::strlen(par); + // Loop over data members + if ( IsSTL(cl.Name(SCOPED)) || cl.IsArray() ) return; + for ( size_t m = 0; m < cl.DataMemberSize(); m++) { + Member mem = cl.DataMemberAt(m); + if ( ! mem.IsTransient() ) { + Type typ = mem.TypeOf(); + string nam = mem.Properties().HasKey("ioname") ? mem.Properties().PropertyAsString("ioname") : mem.Name(); - if( typ.IsPointer() ) nam = "*" + nam; - if( typ.IsArray() ) { - std::stringstream s; - s << typ.ArrayLength(); - nam += "[" + s.str() + "]"; - } - char* add = (char*)obj + mem.Offset(); - if ( Cintex::Debug() > 2 ) { - cout << "Showmembers: ("<< tcl->GetName() << ") " << par << nam.c_str() - << " = " << (void*)add << " Offset:" << mem.Offset() << endl; - } - insp.Inspect(tcl, par, nam.c_str(), add); - if ( !typ.IsFundamental() && !typ.IsPointer() ) { - string tnam = mem.Properties().HasKey("iotype") ? CintName(mem.Properties().PropertyAsString("iotype")) : CintName(typ); - TClass* tmcl = ROOT::GetROOT()->GetClass(tnam.c_str()); - if ( tmcl ) { - ::strcat(par,nam.c_str()); - ::strcat(par,"."); - stub_ShowMembers(tmcl, typ, add, insp, par); - par[ncp] = 0; - } - } - } - } - // Loop over bases - for ( size_t b = 0; b < cl.BaseSize(); b++ ) { - Base BaseNth = cl.BaseAt(b); - string bname = CintName(BaseNth.ToType()); - char* ptr = (char*)obj + BaseNth.Offset(obj); - TClass* bcl = ROOT::GetROOT()->GetClass(bname.c_str()); - if( bcl ) stub_ShowMembers( bcl, BaseNth.ToType(), ptr, insp, par); - } - } -}} + if( typ.IsPointer() ) nam = "*" + nam; + if( typ.IsArray() ) { + std::stringstream s; + s << typ.ArrayLength(); + nam += "[" + s.str() + "]"; + } + char* add = (char*)obj + mem.Offset(); + if ( Cintex::Debug() > 2 ) { + cout << "Showmembers: ("<< tcl->GetName() << ") " << par << nam.c_str() + << " = " << (void*)add << " Offset:" << mem.Offset() << endl; + } + insp.Inspect(tcl, par, nam.c_str(), add); + if ( !typ.IsFundamental() && !typ.IsPointer() ) { + string tnam = mem.Properties().HasKey("iotype") ? CintName(mem.Properties().PropertyAsString("iotype")) : CintName(typ); + TClass* tmcl = ROOT::GetROOT()->GetClass(tnam.c_str()); + if ( tmcl ) { + ::strcat(par,nam.c_str()); + ::strcat(par,"."); + Stub_ShowMembers(tmcl, typ, add, insp, par); + par[ncp] = 0; + } + } + } + } + // Loop over bases + for ( size_t b = 0; b < cl.BaseSize(); b++ ) { + Base BaseNth = cl.BaseAt(b); + string bname = CintName(BaseNth.ToType()); + char* ptr = (char*)obj + BaseNth.Offset(obj); + TClass* bcl = ROOT::GetROOT()->GetClass(bname.c_str()); + if( bcl ) Stub_ShowMembers( bcl, BaseNth.ToType(), ptr, insp, par); + } + } + }} diff --git a/cintex/src/ROOTClassEnhancer.h b/cintex/src/ROOTClassEnhancer.h index b333be5843aa42d3159b830a54faf3ed403955df..4872d390051d70d3259e3dc7e6de193d50a26590 100644 --- a/cintex/src/ROOTClassEnhancer.h +++ b/cintex/src/ROOTClassEnhancer.h @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name:$:$Id:$ +// @(#)root/cintex:$Name: $:$Id: ROOTClassEnhancer.h,v 1.3 2005/11/17 14:12:33 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -19,22 +19,22 @@ class TClass; class TMemberInspector; namespace ROOT { - namespace Cintex { + namespace Cintex { - class ROOTClassEnhancer { - public: - ROOTClassEnhancer(const ROOT::Reflex::Type& TypeNth); - ~ROOTClassEnhancer(); - void Setup(void); - void CreateInfo(void); - static void CreateClassForNamespace(const std::string&); - private: - ROOT::Reflex::Type fClass; - std::string fName; - void* fEnhancerinfo; - }; + class ROOTClassEnhancer { + public: + ROOTClassEnhancer(const ROOT::Reflex::Type& TypeNth); + ~ROOTClassEnhancer(); + void Setup(void); + void CreateInfo(void); + static void CreateClassForNamespace(const std::string&); + private: + ROOT::Reflex::Type fClass; + std::string fName; + void* fEnhancerinfo; + }; - } + } } #endif // ROOT_Cintex_ROOTClassEnhancer