#49 No 'array' attribute

closed-works-for-me
nobody
None
5
2012-09-20
2012-09-20
bgrupczy
No

Noticed that one of your enhancements was to have the 'array' attributes.

Identify array data members as arrays - ID: 3488050
Variables have the following 2 new attributes:
* array: 0 or 1 depending on if its an array
* array_size: If something is between [ and ], that will go here

But I don't see 'array'. My work around will be to use 'array_size' to infer it.

CODE:
from CppHeaderParser import CppHeader
code = """
struct sInfo
{
char name[10];
char ssn[SSN_LEN];
};
"""
cppheader = CppHeader(code, argType="string")
print cppheader

OUTPUT:
struct sInfo
{
public
// Properties
{'line_number': 4, 'constant': 0, 'name': 'name', 'reference': 0, 'array_size': '10', 'type': 'char', 'static': 0, 'pointer': 0}
{'line_number': 5, 'constant': 0, 'name': 'ssn', 'reference': 0, 'array_size': 'SSN_LEN', 'type': 'char', 'static': 0, 'pointer': 0}
protected
private
}

Discussion

  • Actually, its there. When you do a print on cppheader object it suppresses many attributes an object (CppClass/CppMethod etc) has to be more readable. If you want to see all of them try you can see its keys as such

    print cppheader.classes["sInfo"]["properties"]["public"][0].keys()
    ['line_number', 'constant', 'reference', 'raw_type', 'static', 'array', 'pointer', 'aliases', 'typedef', 'namespace', 'function_pointer', 'mutable', 'type', 'property_of_class', 'parent', 'ctypes_type', 'typedefs', 'class', 'unresolved', 'name', 'array_size', 'fundamental']

    Or here is a snippet to print out all its values:
    for key in cppheader.classes["sInfo"]["properties"]["public"][0].keys():
    print "name[%s]=%s"%(key,cppheader.classes["sInfo"]["properties"]["public"][0][key])
    name[line_number]=4
    name[constant]=0
    name[reference]=0
    name[raw_type]=char
    name[static]=0
    name[array]=1
    name[pointer]=0
    name[aliases]=[]
    name[typedef]=None
    name[namespace]=
    name[function_pointer]=0
    name[mutable]=False
    name[type]=char
    name[property_of_class]=sInfo
    name[parent]=None
    name[ctypes_type]=ctypes.c_char
    name[typedefs]=0
    name[class]=0
    name[unresolved]=False
    name[name]=name
    name[array_size]=10
    name[fundamental]=True

    I do hope to create better documentation one day which should cover these things.

     
  • bgrupczy
    bgrupczy
    2012-09-20

    Ah, please close then. I'll try to be more careful.

     
    • status: open --> closed-works-for-me