44#include " PyStrings.h"
55#include " CPPDataMember.h"
66#include " CPPInstance.h"
7+ #include " CPPEnum.h"
78#include " Dimensions.h"
89#include " LowLevelViews.h"
910#include " ProxyWrappers.h"
@@ -47,30 +48,23 @@ static PyObject* dm_get(CPPDataMember* dm, CPPInstance* pyobj, PyObject* /* kls
4748 }
4849 }
4950
50- // non-initialized or public data accesses through class (e.g. by help())
51- void * address = dm->GetAddress (pyobj);
52- if (!address || (intptr_t )address == -1 /* Cling error */ )
53- return nullptr ;
5451
5552 if (dm->fFlags & (kIsEnumPrep | kIsEnumType )) {
5653 if (dm->fFlags & kIsEnumPrep ) {
5754 // still need to do lookup; only ever try this once, then fallback on converter
5855 dm->fFlags &= ~kIsEnumPrep ;
5956
6057 // fDescription contains the full name of the actual enum value object
61- const std::string& lookup = CPyCppyy_PyText_AsString (dm->fDescription );
62- const std::string& enum_type = TypeManip::extract_namespace (lookup);
63- const std::string& enum_scope = TypeManip::extract_namespace (enum_type);
58+ const Cppyy::TCppScope_t enum_type = Cppyy::GetParentScope (dm->fScope );
59+ const Cppyy::TCppScope_t enum_scope = Cppyy::GetParentScope (enum_type);
6460
65- PyObject* pyscope = nullptr ;
66- if (enum_scope.empty ()) pyscope = GetScopeProxy (Cppyy::gGlobalScope );
67- else pyscope = CreateScopeProxy (enum_scope);
61+ PyObject* pyscope = CreateScopeProxy (enum_scope);
6862 if (pyscope) {
69- PyObject* pyEnumType = PyObject_GetAttrString (pyscope,
70- enum_type. substr (enum_scope. size () ? enum_scope. size ()+ 2 : 0 , std::string::npos ).c_str ());
63+ PyObject* pyEnumType =
64+ PyObject_GetAttrString (pyscope, Cppyy::GetFinalName (enum_type ).c_str ());
7165 if (pyEnumType) {
72- PyObject* pyval = PyObject_GetAttrString (pyEnumType,
73- lookup. substr (enum_type. size ()+ 2 , std::string::npos ).c_str ());
66+ PyObject* pyval =
67+ PyObject_GetAttrString (pyEnumType, Cppyy::GetFinalName (dm-> fScope ).c_str ());
7468 Py_DECREF (pyEnumType);
7569 if (pyval) {
7670 Py_DECREF (dm->fDescription );
@@ -88,7 +82,16 @@ static PyObject* dm_get(CPPDataMember* dm, CPPInstance* pyobj, PyObject* /* kls
8882 Py_INCREF (dm->fDescription );
8983 return dm->fDescription ;
9084 }
85+
86+ if (Cppyy::IsEnumConstant (dm->fScope )) {
87+ // anonymous enum
88+ return pyval_from_enum (Cppyy::ResolveEnum (dm->fScope ), nullptr , nullptr , dm->fScope );
89+ }
9190 }
91+ // non-initialized or public data accesses through class (e.g. by help())
92+ void * address = dm->GetAddress (pyobj);
93+ if (!address || (intptr_t )address == -1 /* Cling error */ )
94+ return nullptr ;
9295
9396 if (dm->fConverter != 0 ) {
9497 PyObject* result = dm->fConverter ->FromMemory ((dm->fFlags & kIsArrayType ) ? &address : address);
@@ -319,53 +322,54 @@ PyTypeObject CPPDataMember_Type = {
319322
320323
321324// - public members -----------------------------------------------------------
322- void CPyCppyy::CPPDataMember::Set (Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata )
325+ void CPyCppyy::CPPDataMember::Set (Cppyy::TCppScope_t scope, Cppyy::TCppScope_t data )
323326{
324- fEnclosingScope = scope;
325- fOffset = Cppyy::GetDatamemberOffset (scope, idata); // TODO: make lazy
326- fFlags = Cppyy::IsStaticData (scope, idata) ? kIsStaticData : 0 ;
327-
328- std::vector<dim_t > dims;
329- int ndim = 0 ; Py_ssize_t size = 0 ;
330- while (0 < (size = Cppyy::GetDimensionSize (scope, idata, ndim))) {
331- ndim += 1 ;
332- if (size == INT_MAX) // meaning: incomplete array type
333- size = UNKNOWN_SIZE;
334- if (ndim == 1 ) dims.reserve (4 );
335- dims.push_back ((dim_t )size);
327+ if (Cppyy::IsLambdaClass (Cppyy::GetDatamemberType (data))) {
328+ fScope = Cppyy::WrapLambdaFromVariable (data);
329+ } else {
330+ fScope = data;
336331 }
337- if (!dims.empty ())
338- fFlags |= kIsArrayType ;
339332
340- const std::string name = Cppyy::GetDatamemberName (scope, idata);
341- fFullType = Cppyy::GetDatamemberType (scope, idata);
342- if (Cppyy::IsEnumData (scope, idata)) {
333+ fEnclosingScope = scope;
334+ fOffset = Cppyy::GetDatamemberOffset (fScope , fScope == data ? scope : Cppyy::GetScope (" __cppyy_internal_wrap_g" )); // XXX: Check back here // TODO: make lazy
335+ fFlags = Cppyy::IsStaticDatamember (fScope ) ? kIsStaticData : 0 ;
336+
337+ const std::string name = Cppyy::GetFinalName (fScope );
338+ Cppyy::TCppType_t type;
339+
340+
341+ if (Cppyy::IsEnumConstant (fScope )) {
342+ type = Cppyy::GetEnumConstantType (fScope );
343+ fFullType = Cppyy::GetTypeAsString (type);
343344 if (fFullType .find (" (anonymous)" ) == std::string::npos &&
344345 fFullType .find (" (unnamed)" ) == std::string::npos) {
345346 // repurpose fDescription for lazy lookup of the enum later
346347 fDescription = CPyCppyy_PyText_FromString ((fFullType + " ::" + name).c_str ());
347348 fFlags |= kIsEnumPrep ;
348349 }
349- fFullType = Cppyy::ResolveEnum (fFullType );
350- fFlags |= kIsConstData ;
351- } else if (Cppyy::IsConstData (scope, idata)) {
350+ type = Cppyy::ResolveType (type);
352351 fFlags |= kIsConstData ;
352+ } else {
353+ type = Cppyy::GetDatamemberType (fScope );
354+ fFullType = Cppyy::GetTypeAsString (type);
355+
356+ // Get the integer type if it's an enum
357+ if (Cppyy::IsEnumType (type))
358+ type = Cppyy::ResolveType (type);
359+
360+ if (Cppyy::IsConstVar (fScope ))
361+ fFlags |= kIsConstData ;
353362 }
354363
355- // if this data member is an array, the conversion needs to be pointer to object for instances,
356- // to prevent the need for copying in the conversion; furthermore, fixed arrays' full type for
357- // builtins are not declared as such if more than 1-dim (TODO: fix in clingwrapper)
358- if (!dims.empty () && fFullType .back () != ' *' ) {
359- if (Cppyy::GetScope (fFullType )) fFullType += ' *' ;
360- else if (fFullType .back () != ' ]' ) {
361- for (auto d: dims) fFullType += d == UNKNOWN_SIZE ? " *" : " []" ;
362- }
363- }
364+ std::vector<dim_t > dims = Cppyy::GetDimensions (type);
365+
366+ if (!dims.empty ())
367+ fFlags |= kIsArrayType ;
364368
365369 if (dims.empty ())
366- fConverter = CreateConverter (fFullType );
370+ fConverter = CreateConverter (type, 0 );
367371 else
368- fConverter = CreateConverter (fFullType , {(dim_t )dims.size (), dims.data ()});
372+ fConverter = CreateConverter (type , {(dim_t )dims.size (), dims.data ()});
369373
370374 if (!(fFlags & kIsEnumPrep ))
371375 fDescription = CPyCppyy_PyText_FromString (name.c_str ());
0 commit comments