Menu

#10 array_size for multi dimensional arrays

closed
nobody
None
5
2015-06-08
2015-04-24
Toger
No

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.

Discussion

  • Jashua Cloutier

    Jashua Cloutier - 2015-04-24

    Please include sample code of what you are trying to parse and a exactly how you are trying to access its data.

     
  • Jashua Cloutier

    Jashua Cloutier - 2015-04-27

    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

     
  • Toger

    Toger - 2015-04-27

    Unfortunately 'multi_dimensional_array_size' is always empty for me.

    import CppHeaderParser
    ast = CppHeaderParser.CppHeader("""
    struct Teststruct{
        int mda[2][3][4];
    };
    """,  argType='string')
    print(ast.classes["Teststruct"]["properties"]["public"][0]["multi_dimensional_array_size"])
    

    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

    [{'name': 'mda', 'multi_dimensional_array': 1, 'fundamental': True, 'property_of_class': 'Teststruct', 'parent': None, 'multi_dimensional_array_size': '', 'namespace': '', 'class': 0, 'aliases': [], 'type': 'int', 'typedef': None, 'line_number': 3, 'constant': 0, 'raw_type': 'int', 'pointer': 0, 'reference': 0, 'ctypes_type': 'ctypes.c_int', 'function_pointer': 0, 'static': 0, 'typedefs': 0, 'extern': False, 'unresolved': False, 'array_size': 24, 'array': 1, 'mutable': False}]
    

    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.

     
  • Jashua Cloutier

    Jashua Cloutier - 2015-05-02

    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

     
  • Jashua Cloutier

    Jashua Cloutier - 2015-06-08
    • status: open --> closed
     
  • Jashua Cloutier

    Jashua Cloutier - 2015-06-08

    closing

     

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.