robotpy / robotpy-cppheaderparser

DEPRECATED: use cxxheaderparser instead
Other
123 stars 39 forks source link

"Text(const char* fmt, ...) IM_FMTARGS(1);" failed parse #14

Closed ghost closed 5 years ago

ghost commented 5 years ago

imgui.h

#pragma once

#if defined(__clang__) || defined(__GNUC__)
#define IM_FMTARGS(FMT)             __attribute__((format(printf, FMT, FMT+1))) // Apply printf-style warnings to user functions.
#define IM_FMTLIST(FMT)             __attribute__((format(printf, FMT, 0)))
#else
#define IM_FMTARGS(FMT)
#define IM_FMTLIST(FMT)
#endif

namespace ImGui
{
    IMGUI_API void          Text(const char* fmt, ...)                                      IM_FMTARGS(1); // simple formatted text
    IMGUI_API void          TextV(const char* fmt, va_list args)                            IM_FMTLIST(1);

} // namespace ImGui
#!/usr/bin/env python
import sys,json

import CppHeaderParser
try:
    cppHeader = CppHeaderParser.CppHeader("x.h")
except CppHeaderParser.CppParseError as e:
    print(e)
    sys.exit(1)

for func in cppHeader.functions:
    if func['name'] in ['Text', 'TextV']:
        for x in func['parameters']:
            print(x)
        print('\n\n')

output

$ ./gen_lua_binding.py
{'line_number': 14, 'constant': 1, 'name': 'fmt', 'reference': 0, 'type': 'const char *', 'static': 0, 'extern': False, 'pointer': 1}
{'line_number': 14, 'constant': 0, 'name': '(', 'reference': 0, 'type': ') IM_FMTARGS', 'static': 0, 'extern': False, 'pointer': 0}

{'line_number': 15, 'constant': 1, 'name': 'fmt', 'reference': 0, 'type': 'const char *', 'static': 0, 'extern': False, 'pointer': 1}
{'line_number': 15, 'constant': 0, 'name': '(', 'reference': 0, 'type': 'va_list args ) IM_FMTLIST', 'static': 0, 'extern': False, 'pointer': 0}

result

Text: params' types = ['const char', ') IM_FMTARGS'], names = ['fmt', '('] TextV: params' types = ['const char','va_list args ) IM_FMTLIST'], names = ['fmt', '(']

I think :

  1. the Text 's params type should be ['conts char*', ''], name = ['fmt', '...']
  2. TextV 's params type should be ['const char *', 'va_list'], name = ['fmt', args]
auscompgeek commented 5 years ago

CppHeaderParser doesn't handle macros. See:

ghost commented 5 years ago

Thanks for your info.

how about:

namespace ImGui
{
   void          Text(const char* fmt, ...)                   ;
} // namespace ImGui

can not process (const char* fmt, ...) too.

auscompgeek commented 5 years ago
>>> h = CppHeaderParser.CppHeader(...)
>>> len(h.functions)
1
>>> h.functions[0]['namespace']
'ImGui::'
>>> h.functions[0]['name']
'Text'
>>> h.functions[0]['vararg']
True
>>> len(h.functions[0]['parameters'])
1
>>> h.functions[0]['parameters'][0]['name']
'fmt'
>>> h.functions[0]['parameters'][0]['type']
'const char *'

I don't see a problem here.