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

Exception thrown when parsing the header file in Microsoft SDK

Open ShadowLL opened this issue 5 years ago • 3 comments
trafficstars

typedef enum _WSACOMPLETIONTYPE {
    NSP_NOTIFY_IMMEDIATELY = 0,
    NSP_NOTIFY_HWND,
    NSP_NOTIFY_EVENT,
    NSP_NOTIFY_PORT,
    NSP_NOTIFY_APC,
} WSACOMPLETIONTYPE, *PWSACOMPLETIONTYPE, FAR * LPWSACOMPLETIONTYPE;

This is detailed exception information:

Connected to pydev debugger (build 192.6262.63)
Traceback (most recent call last):
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 2913, in __init__
    self._evaluate_stack()
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 3343, in _evaluate_stack
    self._parse_enum()
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 3536, in _parse_enum
    self._next_token_must_be(";")
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 3113, in _next_token_must_be
    raise self._parse_error((tok,), "' or '".join(tokenTypes))
CppHeaderParser.CppHeaderParser.CppParseError: unexpected ',', expected ';'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/pydevd.py", line 2060, in <module>
    main()
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/pydevd.py", line 2054, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/pydevd.py", line 1405, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/pydevd.py", line 1412, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/fuzz/workspace/xfuzz/database/src_code_analysis/analysis.py", line 3, in <module>
    header = CppHeaderParser.CppHeader('/home/fuzz/workspace/xfuzz/database/windos_sdk_hfs/Include/WinSock2.h')
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 3048, in __init__
    CppParseError(msg), e,
  File "<string>", line 1, in raise_exc
CppHeaderParser.CppHeaderParser.CppParseError: Not able to parse /home/fuzz/workspace/xfuzz/database/windos_sdk_hfs/Include/WinSock2.h on line 1074 evaluating ',': unexpected ',', expected ';'
Error around: typedef enum _WSACOMPLETIONTYPE

ShadowLL avatar Apr 09 '20 07:04 ShadowLL

Definitely a bug. I don't really have an interest in fixing this myself (lots of stuff going on), but I can provide guidance for debugging/fixing this if you would like to fix it and make a PR.

In particular, I find that setting the environment variable CPPHEADERPARSER_DEBUG=1 is really useful for figuring out what the parser is doing.

I imagine that this isn't the only piece in the SDK that would cause problems. Might try just commenting out that enum and see what else breaks.

virtuald avatar Apr 09 '20 22:04 virtuald

The following code has the same parsing error: evaluating '': unexpected '', expected ';' struct AudioPortCapability { enum AudioFormat* formats; /**< Supported audio formats. For details, see {@link AudioFormat}. */ };


After I modified the following code, the program can run normally: def _parse_enum(self): ...... # TODO: nested_name_specifier name = "" if nametok.type == "NAME": name = nametok.value debug_print("enum name is '%s'", name) tok = self.lex.token() #MODIFED: if tok.value == "*": name = name + ' *' tok = self.lex.token() else: debug_print("anonymous enum") tok = nametok

liuyongbao1982 avatar Jan 11 '22 09:01 liuyongbao1982

@liuyongbao1982 That looks like a different parse error to me. If you open a PR though with your change and a test, we'd be happy to take your change, since that's also a bug.

auscompgeek avatar Jan 11 '22 12:01 auscompgeek