array_size for multi dimensional arrays
Brought to you by:
senexcanis
I am trying to print the declaration of a struct containing a multi dimensional array. Unfortunately the arrays' dimension and sizes seem to get lost in version 2.5.1. The attribute array_size is set for one dimensional arrays, but not for multi dimensional arrays. Untested suggested fix near CppHeaderParser.py:919:
self["array_size"] = [] for e in arrayStack: if e != '[' and e != ']': self["array_size"].append(e)
That way all array sizes are in the list. Things like char a[1 + 2]; probably mess up my fix, not sure.
Please include sample code of what you are trying to parse and a exactly how you are trying to access its data.
I took a different approach. Please retry 139:231618db8dee and let me know if it works for you. If you have a mult-dimensional array you will have the new keys
'multi_dimensional_array': 1 # Flag to let you know its multi dimensional
'multi_dimensional_array_size': '128x128' # String representing the dimensions
'array_size': 16384 # Product of the dimensions
Unfortunately 'multi_dimensional_array_size' is always empty for me.
Expected output is "2x3x4". Actual output is "".
(By the way: It is confusing that ast.structs is empty, see feature request #4. Maybe use ast.structclasses instead.).
For print(ast.classes["Teststruct"]["properties"]["public"] I get
The 'array_size' has been correctly calculated, but 'multi_dimensional_array_size' is empty. I saw in the diff that you have a unit test for that with the picture struct 'multi_dimensional_array_size' == "128x128". That should have failed.
I think you may not be using the new code. I tried your sample and I get the following when I print out the class
struct Teststruct
{
public
// Properties
{'line_number': 3, 'constant': 0, 'reference': 0, 'raw_type': 'int', 'static': 0, 'array': 1, 'pointer': 0, 'aliases': [], 'typedef': None, 'namespace': '', 'function_pointer': 0, 'multi_dimensional_array': 1, 'mutable': False, 'type': 'int', 'property_of_class': 'Teststruct', 'parent': None, 'ctypes_type': 'ctypes.c_int', 'typedefs': 0, 'extern': False, 'class': 0, 'name': 'mda', 'unresolved': False, 'multi_dimensional_array_size': '2x3x4', 'array_size': 24, 'fundamental': True}
protected
private
}
From above see 'multi_dimensional_array_size': '2x3x4', 'array_size': 24
closing