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

[BUG]: `#define` immediately after a class definition before opening bracket hides the class

Open alandtse opened this issue 1 year ago • 4 comments

Problem description

I am parsing a project which uses ifdefs. While using pcpp to test variants of the code, some classes were no longer being detected by cppheaderparser. This is because cppheaderparse will leave behind #line 2 where 2 is the line number wherever a preprocessor directive is processed/replaced.

While I'm not sure if #line is valid cpp syntax, I've determined the existence of the # does break cppheaderparser so a valid #define 1 also causes the behavior.

Specifically, the #define 1 below immediately after the class declaration but before the { will break parsing of the class. While this is a toy example and it won't break if the #define is after the {, this may be valid syntax if the class inheritance is controlled by an ifdef.

This was tested with the command line:

python -m CppHeaderParser.tojson processed_playercharacter.h > test_processed.json

Operating System

MacOS

Installed Python Packages

Package                 Version
----------------------- ---------
aiocsv                  1.2.3
aiofiles                22.1.0
black                   23.1.0
bleach                  6.0.0
certifi                 2022.12.7
charset-normalizer      3.1.0
click                   8.1.3
click-log               0.4.0
colorama                0.4.6
docutils                0.19
dotty-dict              1.3.1
gitdb                   4.0.10
GitPython               3.1.31
idna                    3.4
importlib-metadata      6.1.0
invoke                  1.7.3
jaraco.classes          3.2.3
keyring                 23.13.1
more-itertools          9.1.0
mypy                    1.1.1
mypy-extensions         1.0.0
numpy                   1.24.2
packaging               23.0
pandas                  1.5.3
pathspec                0.11.1
pcpp                    1.30
pip                     22.3.1
pkginfo                 1.9.6
platformdirs            3.1.1
ply                     3.11
Pygments                2.14.0
python-dateutil         2.8.2
python-gitlab           3.13.0
python-semantic-release 7.33.2
pytz                    2023.2
readme-renderer         37.3
requests                2.28.2
requests-toolbelt       0.10.1
rfc3986                 2.0.0
robotpy-cppheaderparser 5.1.0
semver                  2.13.0
setuptools              65.5.1
six                     1.16.0
smmap                   5.0.0
tomli                   2.0.1
tomlkit                 0.11.6
tqdm                    4.65.0
twine                   3.8.0
typing_extensions       4.5.0
urllib3                 1.26.15
webencodings            0.5.1
wheel                   0.40.0
zipp                    3.15.0

Reproducible example code

namespace RE
{
    class PlayerCharacter
#define 1 // This define breaks the discovery of PlayerCharacter. If this line is commented out, the class will be discovered.
    {
    }
}

alandtse avatar Mar 26 '23 00:03 alandtse