Download presentation
Presentation is loading. Please wait.
Published byBartholomew Horn Modified over 9 years ago
1
The SEAL C++ Reflection System Stefan Roiser (for the LCG/SEAL Dictionary work package) CHEP 2004, 27. Sept. - 1. Oct., Interlaken
2
27. Sept. 2004stefan.roiser@cern.ch2 Content Reflection and C++ The Model Use Cases Production of reflection information Packages and users Status and Conclusion
3
27. Sept. 2004stefan.roiser@cern.ch3 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
27. Sept. 2004stefan.roiser@cern.ch4 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
27. Sept. 2004stefan.roiser@cern.ch5 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 proposes XTI (eXtended Type Information) as inherent extension
6
27. Sept. 2004stefan.roiser@cern.ch6 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
27. Sept. 2004stefan.roiser@cern.ch7 Reflection Model Type TypeBase Scope ScopeBase Member Class PropertyList … Function Typedef Reference Pointer Namespace InstTemplate TemplFamily InstTFunction InstTClass
8
27. Sept. 2004stefan.roiser@cern.ch8 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
27. Sept. 2004stefan.roiser@cern.ch9 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
27. Sept. 2004stefan.roiser@cern.ch10 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
27. Sept. 2004stefan.roiser@cern.ch11 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
27. Sept. 2004stefan.roiser@cern.ch12 Reflection Use Cases (ctd.) More Types –Reference, Pointer, PointerToMember, Array, Enum, Union, Fundamental Typedefs Scopes –Search scopes –Retrieve Base-/ Subscopes 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
27. Sept. 2004stefan.roiser@cern.ch13 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
27. Sept. 2004stefan.roiser@cern.ch14 [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 -I/my/include[lxplus]~> lcgdict Particle.h -s selection.xml -I/my/include Parsing File Particle.h with GCC_XML OK Generating LCG Dictionary class Particle [lxplus]~> lcgdict Particle.h -s selection.xml -I/my/include Parsing File Particle.h with GCC_XML OK Generating LCG Dictionary class Particle [lxplus]~> ls Particle.h Particle.xml Particle_dict.cpp [lxplus]~>
15
27. Sept. 2004stefan.roiser@cern.ch15 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
27. Sept. 2004stefan.roiser@cern.ch16 Status Current version - Reflection(Builder) - in production –POOL & SEAL PyLCGDict Prototype of new version - Reflex - released –In collaboration with the ROOT team –The idea is a common dictionary of LCG & ROOT –Several enhancements (e.g. references, enums) –Closer to ISO standard
17
27. Sept. 2004stefan.roiser@cern.ch17 Users POOL –The LCG project for persistence of objects (#381, D. Duellmann, Wed. 14 20 -14 40, Core SW) SEAL PyLCGDict –Python binding to the Reflection system (#494, W. Lavrijsen, Mon. 15 00 -15 20, Core SW) SUN Microsystems –Porting to SUN forte compiler
18
27. Sept. 2004stefan.roiser@cern.ch18 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
19
27. Sept. 2004stefan.roiser@cern.ch19 Conclusion SEAL Dictionaries extend C++ RTTI –Light, standalone system –Non intrusive, automated code production –Dictionaries for any gcc compileable program New system ready for integration –In collaboration with ROOT –Several enhancements, closer to ISO std. Current version in production
20
27. Sept. 2004stefan.roiser@cern.ch20 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.