robotpy-cppheaderparser icon indicating copy to clipboard operation
robotpy-cppheaderparser copied to clipboard

Multidimensional array dimensions not parsed when using variable

Open Marvin-TMG opened this issue 4 years ago • 3 comments
trafficstars

I am trying to parse C structs which contain array's defined using variables.

The single dimension arrays are parsed correctly, i.e. long my1dArray[SOME_VAR];

which returns something like: 'array_size': 'SOME_VAR'

However, for multidimensional arrays the array size is not parsed correctly and returns an empty string: long my2dArray[SOME_VAR][SOME_VAR];

'array_size':1 'multi_dimensional_array':1 'multi_dimensional_array_size':''

It would be great if array sizes using variable names for multi-dimensional arrays can be supported, since now I need to write a custom parser to retrieve the dimensions myself.

Marvin-TMG avatar Sep 22 '21 08:09 Marvin-TMG

It's likely that cxxheaderparser can handle such constructs, recommend you give that a try as eventually I will abandon this fork in favor of cxxheaderparser.

Alternatively, happy to accept a fix for this. If I recall correctly, CppHeaderParser's multi-dimensional array support was indeed quite terrible, so this doesn't surprise me at all.

virtuald avatar Sep 22 '21 19:09 virtuald

Thanks for the recommendation and quick reply. I will give that library a shot.

In the meantime, I managed to work around the issue with a fairly simple solution. I am running the parser twice, the first time to get all #defines, which I then do a string replace on in Python. This allows me to parse the parched code again and obtain the correct array dimensions. It’s far from elegant, but it works :)

On 22. Sep 2021, at 21:43, Dustin Spicuzza @.***> wrote:

 The following message was sent from an external e-mail address! Be cautious when clicking on links, opening attachments or providing sensitive information.


It's likely that cxxheaderparserhttps://github.com/robotpy/cxxheaderparser can handle such constructs, recommend you give that a try as eventually I will abandon this fork in favor of cxxheaderparser.

Alternatively, happy to accept a fix for this. If I recall correctly, CppHeaderParser's multi-dimensional array support was indeed quite terrible, so this doesn't surprise me at all.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/robotpy/robotpy-cppheaderparser/issues/72#issuecomment-925271968, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALLMUUX2ELRU6R57RZTNLUDUDIWVVANCNFSM5EQXGJVQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.


TOYOTA GAZOO Racing Europe GmbH | Toyota-Allee 7 | 50858 Köln / Cologne | Deutschland / Germany Geschäftsführer / Managing Directors: Koji Sato, Katsuyoshi Hikichi, Robertus Leupen, Matthew Harrison Sitz der GmbH / Registered Office: Köln / Cologne | HRB 9846 | Tax-No.: 22358190628 | VAT-ID No.: DE123471187 T: +49 2234 1823 0 | F: +49 2234 1823 2800 | E: @.*** | W: www.tgr-europe.com TGR-E-Datenschutzinformationen / TGR-E‘s privacy policy: https://www.tgr-europe.com/en/privacy DISCLAIMER

  • This email and any attachment may contain confidential information. If you are not the intended recipient you are not authorised to copy or disclose all or any part of it without the prior written consent of TOYOTA GAZOO Racing Europe GmbH.
  • TOYOTA GAZOO Racing Europe GmbH treats any information exchanged with business partners as confidential regardless whether they are marked as such or not and, therefore, rejects any request for marking documents.
  • Please scan this email and any attachment for viruses. TOYOTA GAZOO Racing Europe GmbH does not accept any responsibility for problems caused by viruses whether it is the fault of TOYOTA GAZOO Racing Europe GmbH or not.

Marvin-TMG avatar Sep 22 '21 21:09 Marvin-TMG

Are these "variables" actually #defines? If so, note from the readme:

CppHeaderParser only does some very minimal interpretation of preprocessor directives -- and we're looking at removing some of that from this library. If you need anything complex, you should preprocess the code yourself. You can use the excellent pure python preprocessor pcpp, or the preprocessing facilities provided by your favorite compiler.

We don't implement macros in cxxheaderparser either.

auscompgeek avatar Sep 23 '21 01:09 auscompgeek