Reflex new rootcint Stefan Roiser CERN PH SFT
- Slides: 26
Reflex & new rootcint Stefan Roiser CERN / PH / SFT ROOT Users Workshop 28 -30 Sep 2005
Content • Reflection in general • Reflex introduction • Design • API • Code Examples • • Reflex Integration with ROOT/CINT Generation of Dictionaries Status Outlook Stefan Roiser ROOT Users Workshop - 28 Sep 2005 2
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 Stefan Roiser ROOT Users Workshop - 28 Sep 2005 3
r o i r p out t u ho e a b t i W edg s l t c w e o j kn ob What is Reflection? Type t = p; Particle Type: : By. Name(“Particle”); std: : cout << p. mass(); Object o = t. Construct(); std: : cout << object_cast<double> (o. Invoke(“mass”)); Class. Builder(“Particle”). Add. Data. Member(“m_mass”). Add. Function. Member(“mass”); o. Destruct(); class Particle { public: double mass(); private: double m_mass; }; Stefan Roiser ROOT Users Workshop - 28 Sep 2005 4
Reflection and C++ • Very limited support by the language (RTTI) • Other languages do (e. g. Java, Python, …) • CINT • Supports reflection of C++ constructs • Several other approaches exist, but … • Tied to a system or • Instrumentation of code needed • Stroustrup proposed XTI (e. Xtended Type Information) • Dormant project Stefan Roiser ROOT Users Workshop - 28 Sep 2005 5
Goals • Enhance C++ with reflection capabilities • non intrusive, automated • Close to the C++ ISO 14882 standard • Extra information stored in “properties” • Light and standalone system • Small memory footprint • Multi platform • Linux, Windows, Mac OSX, … Stefan Roiser ROOT Users Workshop - 28 Sep 2005 6
3 Levels of Reflection Reflex supports: • Introspection • Retrieve information (e. g. class name, return type) • Interaction • Handle objects (e. g. create instance, call function, get/set data member) • Modification • Change information (e. g. add function member, add properties, add class template instance) Stefan Roiser ROOT Users Workshop - 28 Sep 2005 7
Design ideas • API • Handful (i. e. 8 ) classes the user has to deal with • Full functionality, mainly through forward functions • Identification • A unique immutable id of each type/scope (no delete) • Implementation • Provides the content of the reflection information Stefan Roiser ROOT Users Workshop - 28 Sep 2005 8
Reflection Model Object Type Member Scope Type. Templ Member. Templ Property. List Base Type. Name Scope. Base Type. Base User Level Identification Implementation Member. Base Pointer Enum Member. TImpl Data. Member Fundamental Union Type. TImpl Func. Member Namespace Typedef Pointer 2 Mem Class. TInst Array Function Prop. List. Impl Stefan Roiser ROOT Users Workshop - 28 Sep 2005 Fun. Mem. TInst Template. Inst 9
User Classes (general) • Small memory allocation • ~ sizeof (Pointer) + sizeof(int) • By value semantics • operator bool() • Will return true if the Type, Scope, etc. is declared and implemented • Function “std: : string Name(unsigned)” • Returns the “SCOPED | FINAL | QUALIFIED” name • Many “Is*” functions to ask questions • e. g. Is. Volatile, Is. Class, etc. Stefan Roiser ROOT Users Workshop - 28 Sep 2005 10
User Classes • Type • Pointer, Pointer to Member, Typedef, Array, Function, Union, Enum, Fundamental, Class, Instantiated Template Class • Contains CV qualification (plus Reference) • Function return/parameter types, array length, typedef types • Scope • Namespace, Class, Union, Enum • Walk up/down hierarchy, access type/member information • Member • Function Member, Data Member • Invoke function members, get/set data members Stefan Roiser ROOT Users Workshop - 28 Sep 2005 11
User Classes (ctd. ) • Object • Represents a C++ class instance (address + type) • Invoke functions, get/set members, dynamic type • Property. List • Attach collection of key/value pairs to Types, Scopes, Members • Key is string, Value is “Any” object • Base type, access, offset • Type. Template / Member. Template • Template instances, template parameters Stefan Roiser ROOT Users Workshop - 28 Sep 2005 12
Example: Introspection // The Reflex namespace inside Root using namespace ROOT: : Reflex; // Get type by its name Type cl = Type: : By. Name(“Particle”); // If class print all data members if ( cl. Is. Class() ) { for ( size_t d = 0; d < cl. Data. Member. Count(); d++ ) { Member dm = cl. Data. Member. Nth(d); cout << dm. Type(). Name(SCOPED) << " " << dm. Name() <<"; "; // output comment line if exists if ( dm. Property. List(). Has. Key("comment") ) { cout << m. Property. List. Get(). Property. As. String("comment"); } cout << endl; } } Stefan Roiser ROOT Users Workshop - 28 Sep 2005 13
Example: Interaction // Get a type by its name Type cl = Type: : By. Name(“Particle”); // Instantiate an instance Object obj = cl. Construct(); // Call a method Object ret = obj. Invoke(“function”); // Alternatively for ( size_t f = 0; f < cl. Function. Member. Count(); f++ ) { if (cl. Function. Member. Nth(f). Name() == “function”) { ret = cl. Function. Member. Nth(f). Invoke(obj); } } // Delete the instance obj. Destruct(); Stefan Roiser ROOT Users Workshop - 28 Sep 2005 14
Why using Reflex? • Advantages • 100 % C++ code • Better C++ coverage • Smaller memory footprint Memory Allocation ROOT / CINT Reflex -> Mini workshop 2005 @ CERN - Decision to use Reflex Stefan Roiser ROOT Users Workshop - 28 Sep 2005 15
Integration with ROOT CINT Datastructs Cint. Dict. so ROOT Meta Datastructs ROOT meta Rflx. Dict. so CINT API CINT interpreter Cintex Py. Root Reflex API pyreflex Reflex Datastructs Stefan Roiser ROOT Users Workshop - 28 Sep 2005 16
Integration with ROOT CINT API ROOT Meta Datastructs ROOT meta CINT interpreter Py. Root Reflex API Rflx. Dict. so pyreflex Reflex/CINT Datastructs Stefan Roiser ROOT Users Workshop - 28 Sep 2005 17
Integration with ROOT CINT API ROOT Meta ROOT meta CINT interpreter Py. Root Reflex API Rflx. Dict. so pyreflex Reflex/CINT Datastructs Stefan Roiser ROOT Users Workshop - 28 Sep 2005 18
Dictionary Generation with CINT Type Linkdef. Selection h rflx_gendict CINT parser. h G__*. cxx rootcint -reflex make . so . cxx User Program Stefan Roiser ROOT Users Workshop - 28 Sep 2005 make Reflex. so X Cintex. so Cint. so Core. so 19
Dictionary Generation with gccxml Type Linkdef. selection Selection h . xml (temp) gcc_xml. h . xml make gendict. py rootcint -gccxml . so . cxx User Program Stefan Roiser ROOT Users Workshop - G__*. cxx 28 Sep 2005 make Reflex. so X Cintex. so Cint. so Core. so 20
selection. xml file • Functionality • • Allows inclusion/exclusion of types Usage of patterns Apply special information (transient, class ID) Non-intrusive way of attaching information • Simple adaptation to user requests <lcgdict> <class pattern=“T*”/> <class name=“Particle”> <field name=“f. Only. In. Memory” transient=“true”/> </class> <exclusion> <class name=“Vertex”/> </exclusion> </lcgdict> Stefan Roiser ROOT Users Workshop - 28 Sep 2005 21
gcc_xml • “[…] generate an XML description of a C++ program from GCC's internal representation. ” • Any gcc compilable program can be used as input • “rootcint -gccxml” uses the temporary XML file to produce dictionary C++ source files Stefan Roiser ROOT Users Workshop - 28 Sep 2005 22
Parser commands Current Status [] ~ > rootcint -f dict. cxx –c … (Cint dictionaries) Transition phase [] ~ > rootcint -f dict. cxx -c … [] ~ > rootcint -f dict. cxx –c -reflex … [] ~ > rootcint -f dict. cxx -c -gccxml … (Cint dictionaries) (Reflex dict wth Cint) (Reflex dict wth gccxml) Final status [] ~ > rootcint -f dict. cxx -c … [] ~ > rootcint -f dict. cxx -c -gccxml … Stefan Roiser ROOT Users Workshop - 28 Sep 2005 (Reflex dict wth Cint) (Reflex dict wth gccxml) 23
Status • Reflex • Ready to use (available through ROOT cvs) • For the time being optional in ROOT (--enable-reflex) • Cintex • Ready to use (available through ROOT cvs) • For the time being optional in ROOT (--enable-cintex) • rootcint -reflex • rootcint integration missing (trivial) • makecint produces reflex dictionaries (~ 80 % of C++ standard) • rootcint -reflex -gccxml • rootcint integration missing (trivial) • Works with selection. xml file • Understand Linkdef. h syntax Stefan Roiser ROOT Users Workshop - 28 Sep 2005 24
Outlook • Reflex/Cintex • New versions will be imported in ROOT cvs • Selection classes for Reflex (allows type selection from within C++) • rootcint -reflex • October release: most functionality will be available • December release: ready • rootcint -reflex -gccxml • October release: gendict. py understanding Linkdef. h syntax • December release: ready • Reflex/Cint datastructures merge • See Philippe’s talk Stefan Roiser ROOT Users Workshop - 28 Sep 2005 25
Pointers • Seal Dictionary page • http: //seal. web. cern. ch/seal/snapshot/workpackages/dictionary/index. html • Reflex page (work in progress …) • http: //cern. ch/seal-reflex • GCC_XML • http: //www. gccxml. org Stefan Roiser ROOT Users Workshop - 28 Sep 2005 26
- Sft compliance
- Internettherapeut
- Meta sft
- Sympathetic
- Ans
- Asymmetrical tonic neck reflex
- Split speech example
- New york, new jersey, pennsylvania, and delaware
- Fresh oil, new wine scripture
- Marquee cinema new hartford ny
- Weaknesses and strengths of the articles of confederation
- New-old approach to creating new ventures
- New marketing realities pdf
- New years old is new again
- New classical macroeconomics
- Chapter 16 toward a new heaven and a new earth
- Both new hampshire and new york desire more territory
- New classical and new keynesian macroeconomics
- Roosevelt vs taft venn diagram
- Stefan brands
- Imn lui stefan cel mare
- Stefan senczyna
- Katarina blomberg
- Stefan wyszyński krótki życiorys
- Stefan lunkenheimer
- Stefan finsterbusch
- Bahn signallampe 1939