Menu

#62 Enum inherited type

v1.0 (example)
closed-fixed
nobody
5
2016-09-06
2016-02-23
No

the 'type' key of the CppEnum contains actual type <class int=""> or str if it has commas in values
but c++ allows enum inheritance from different primitives like long, long long...
if I understand the code correctly, there is a casting of the string of the raw header file to python types.
If so than it should be canceled and instead stored as raw string, while the type should contain the actual c++ type.
just in my opinion conversion to actual python type should be under responsibility of the user of this lib in code where he uses it

to reproduce use following enum example:

enum DoubleEnum : double
{
    PI = 3.14
}

the values will be correct but the type still remains 'int' the inheritance type is just ignored in the parsing process.

now I did notice that there is a raw_value in the dictionary... just believe its redundant

suggested fix (without breaking the original logic):

meanwhile quick and dirty fix I've done in my local version 2.7.2 is add the following code peaces in file 'CppHeaderParser.py', method 'init':
1) after line 1091:

#set default cpp raw type, further it will be overriden if needed 
self['raw_type'] = 'int'

2) after line 1126:

#if the base type of the enum was specified explicitly than update it raw type
if len(preBraceStack) == 4 and preBraceStack[2] == ':':
self['raw_type'] = preBraceStack[3]

2) after line 1132:

#if the base type of the enum was specified explicitly than update it raw type
#but the typedef has no default Name
if preBraceStack[2] == ':' and len(preBraceStack) >= 4:
    self['raw_type'] = preBraceStack[3]
#if the base type of the enum was specified explicitly than update it raw type
#but the typedef has a default Name
elif preBraceStack[3] == ':' and len(preBraceStack) >= 5:
    self['raw_type'] = preBraceStack[4]

Discussion

  • Jashua Cloutier

    Jashua Cloutier - 2016-09-06
    • status: open --> closed-fixed
     
  • Jashua Cloutier

    Jashua Cloutier - 2016-09-06

    With the fix in commit 3ba0648e8f42 it will now say double.

    I did see that python raw type conversion in there, I want to take it out but worry about breaking existing code...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.