Presentation is loading. Please wait.

Presentation is loading. Please wait.

SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

Similar presentations


Presentation on theme: "SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004."— Presentation transcript:

1 SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004

2 6. Oct. 2004Stefan Roiser2 Content Reflection and C++ The Model Use Cases Producing reflection information Current status, future enhancements CHEP ‘04 Conclusion

3 6. Oct. 2004Stefan Roiser3 Definitions Reflection is the ability of a language to introspect it’s own structure at runtime and interact with it in a generic way A dictionary provides reflection information about types of a certain language to the user

4 6. Oct. 2004Stefan Roiser4 What is Reflection? class Particle { public: double mass(); private: double m_mass; }; Without prior knowledge about types Particle p; std::cout << p.mass(); ClassBuilder(“Particle”). addDataMember(“m_mass”). addFunctionMember(“mass”); const Type* t = Type::byName(“Particle”); Object o = t->construct(); cout << *(double*) o.invoke(“mass”); t->destruct(o);

5 6. Oct. 2004Stefan Roiser5 Reflection and C++ Very limited support by the language (RTTI) –Other languages do (e.g. Java, Python,…) Several approaches exist, but … –Tied to a system or –Instrumentation of code needed Stroustrup proposed XTI (eXtended Type Information)

6 6. Oct. 2004Stefan Roiser6 Goals Enhance C++ with reflection capabilities – non intrusive, automated Close to the C++ ISO 14882 standard Light and standalone system Small memory footprint Multi platform –Linux, Windows, Mac OSX, …

7 6. Oct. 2004Stefan Roiser7 Reflection Model Type TypeBase Scope ScopeBase Member Class PropertyList … Function Typedef Reference Pointer Namespace InstTemplate TemplFamily InstTFunction InstTClass

8 6. Oct. 2004Stefan Roiser8 Reflection Use Cases const Type * t = Type::byName(“Particle”); size_t s = t->sizeOf(); bool t = t->isClass(); Types –Retrieve a specific type –Introspect the actual type

9 6. Oct. 2004Stefan Roiser9 Reflection Use Cases (ctd.) Classes –Inspect inheritance tree –Create / delete instances const Class * c = t->asClass(); const Base * b = c->base(0); Object o = c->construct(); c->destruct(o);

10 6. Oct. 2004Stefan Roiser10 Reflection Use Cases (ctd.) Data Members –Get / set values –Retrieve offset relative to beginning of class const DataMember * dm = c->dataMember(0); double d = *(double*) dm->get(v); size_t s2 = dm->offset();

11 6. Oct. 2004Stefan Roiser11 Reflection Use Cases (ctd.) const FunctionMember * fm = c->functionMember(0); const Type * rt = fm->type()->asFunction()->returnType(); void * r = fm->invoke(o); Function Members –Inspect return and parameter types –Invoke a function and retrieve return values

12 6. Oct. 2004Stefan Roiser12 Reflection Use Cases (ctd.) All Types –Reference, Pointer, PointerToMember, Array, Enum, Union, Fundamental, Class, Function Typedefs Scopes –Search scopes –Retrieve scopes Additional Properties –For Types, Scopes and Members –Everything that does not fit ISO standard –Any type supported CV qualifiers Templates –Inspect families –Look for instantiations

13 6. Oct. 2004Stefan Roiser13 System Overview.h _dict.cpp gcc_xml. xml gendict.py lcgdict.xml Type Selection make.so.cpp _dict.so make Reflex.so User Program

14 6. Oct. 2004Stefan Roiser14 [lxplus]~> Dictionary Creation #include “Particle.h” class Particle_dict { public: Particle_dict(); }; void* stubfun(void* o) { return (void*)((Particle*)o)->mass(); } Particle_dict::Particle_dict() { ClassBuilder (“Particle”).addDataMember (”m_mass”,Offset(Particle,m_mass),PRIVATE).addFunctionMember (”mass”,&stubfun,0,0,PUBLIC); } static Particle_dict instance; [lxplus]~> lcgdict Particle.h -s selection.xml --reflex -I../incl[lxplus]~> lcgdict Particle.h -s selection.xml --reflex -I../incl Parsing File Particle.h with GCC_XML OK Generating LCG Dictionary (reflex) class Particle [lxplus]~> lcgdict Particle.h -s selection.xml --reflex -I../incl Parsing File Particle.h with GCC_XML OK Generating LCG Dictionary (reflex) class Particle [lxplus]~> ls Particle.h Particle.xml Particle_dict.cpp [lxplus]~>

15 6. Oct. 2004Stefan Roiser15 gcc_xml “[…] generate an XML description of a C++ program from GCC's internal representation.” Any gcc compilable program can be used as input lcgdict uses the XML file to produce dictionary files

16 6. Oct. 2004Stefan Roiser16 Library Sizes SEAL ROOT Dictionary: 405 classes

17 6. Oct. 2004Stefan Roiser17 Library Sizes (ctd.) CLHEP Dictionary : 56 classes

18 6. Oct. 2004Stefan Roiser18 Status Reflex - new version will be released with SEAL 1_4_2 and 1_5_2 –In collaboration with the ROOT team –Idea is common LCG & ROOT dictionary –Several enhancements References, Enums, Unions, Typedefs, … –Closer to ISO standard

19 6. Oct. 2004Stefan Roiser19 Future Enhancements Template types –Full implementation needed Measuring the memory footprint –Instructing new / delete –Counting instances Unloading libraries –Proper deletion of types / scopes

20 6. Oct. 2004Stefan Roiser20 Future Enhancements (ctd.) Missing Builders –UnionBuilder, EnumBuilder STL like iterators –In addition to current implementation String parser –Could be used when building types

21 6. Oct. 2004Stefan Roiser21 Integration with LCG SW POOL –Reflex provides sufficient functionality –Integration foreseen SEAL Scripting –PyLCGDict will become PyReflex –Work has already started

22 6. Oct. 2004Stefan Roiser22 Integration with ROOT For ROOT I/O –ROOT Meta Classes (e.g. TClass, TMethod) may be implemented using Reflex –Check of sufficient functionality needed For interactive ROOT (CINT) –Creation of CINT data structures needed –Equivalent to existing CINT/Lcgdict gateway in POOL Easy for data members Function members not so straight forward

23 6. Oct. 2004Stefan Roiser23 Integration with ROOT.h lcgdict _dict.so rootcint CINT cint.so Reflex ROOT CINT DS TDictionary Current Situation Reflex DS

24 6. Oct. 2004Stefan Roiser24 Integration with ROOT.h lcgdict _dict.so rootcint CINT cint.so Reflex ROOT CINT DS Enabling ROOT I/O Reflex DS

25 6. Oct. 2004Stefan Roiser25 Integration with ROOT.h lcgdict _dict.so rootcint CINT cint.so Reflex ROOT CINT DS Reflex DS Enabling ROOT I/O & interactive CINT

26 6. Oct. 2004Stefan Roiser26 Integration with ROOT.h lcgdict _dict.so rootcint CINT cint.so Reflex ROOT Common DS Final Goal

27 6. Oct. 2004Stefan Roiser27 CHEP ‘04 Other projects showed interest –FreeHEP Java Library –Panoramix Improving Standard C++ –Compile time reflection wanted feature –No proposal for the time being Summary talk of Core Software –Propose reflection as part of ISO standard

28 6. Oct. 2004Stefan Roiser28 SW packages Reflection library –Current implementation Reflection, ReflectionBuilder –New model Reflex DictionaryGenerator –Produce dictionary files for both versions Dictionaries CLHEP, STL, ROOT –Standard dictionaries ready to use

29 6. Oct. 2004Stefan Roiser29 Conclusion SEAL Dictionaries –Light, standalone system –Non intrusive, automated code production –Dictionaries for any gcc compileable program New system - Reflex - ready for integration –In collaboration with ROOT –Common LCG/ROOT dictionary envisaged –Several enhancements, closer to ISO std –Positive feedback from CHEP’04

30 6. Oct. 2004Stefan Roiser30 Pointers The SEAL project –http://cern.ch/Seal/ CVS repository –SEAL.cvs.cern.ch:/cvs/SEAL/Dictionary access: kserver, ssh, (anonymous) pserver gcc_xml –http://www.gccxml.org


Download ppt "SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004."

Similar presentations


Ads by Google