jnikula / hawkmoth

Hawkmoth - Sphinx Autodoc for C
https://jnikula.github.io/hawkmoth/
BSD 2-Clause "Simplified" License
74 stars 12 forks source link

Error with function pointer #21

Closed HobbitDur closed 3 years ago

HobbitDur commented 4 years ago

I got an error parsing comments for function pointer. The code is not released yet so maybe there is an error in those declaration, but at least the compiler doesn't give me any error and I don't see any obvious mistake.

Here the code:

/**
 * Here is describe the low level API as defined by the High level RTC driver
 */
typedef struct drv_rtc_func_s
{
  /** Configure the hardware */
  sys_status_t (*configure_hw)( uint8_t hw_device );
  /** Get the I2C message to send in order to configure the external RTC */
  sys_status_t (*get_i2c_message_configure)( uint8_t hw_device,
                                             drv_i2c_io_t *ios, int *nbios );
  /** Set the hardware to a specific POSIX time */
  sys_status_t (*set_hw_time)( uint8_t hw_device, rtc_time_t time );
  /** Get the time from the harware in POSIX format */
  sys_status_t (*get_hw_time)( uint8_t hw_device, rtc_time_t *time );
  /** Get the I2C message to send in order to get the POSIX time from the external RTC */
  sys_status_t (*get_i2c_message_get_time)( uint8_t hw_device,
                                            drv_i2c_io_t *ios, int *nbios,
                                            rtc_time_t time );
  /** Get the I2C message to send in order to set the POSIX time into the external RTC */
  sys_status_t (*get_i2c_message_set_time)( uint8_t hw_device,
                                            drv_i2c_io_t *ios, int *nbios,
                                            rtc_time_t time );
  /** Get the POSIX time from an I2C message */
  sys_status_t (*extract_time_from_i2c)( uint8_t hw_device, drv_i2c_io_t *ios,
                                         int nbios, rtc_time_t *time );
} drv_rtc_func_t;

Here the error:

C:\Users\ludovic.guerra\Desktop\Code\f1\ula//include/drv/rtc.h:116: WARNING: Error in declarator If declarator-id with parameters: Invalid C declaration: Expected identifier in nested name. [error at 13] sys_status_t ()(int) configure_hw -------------^ If parenthesis in noptr-declarator: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 15] sys_status_t ()(int) configure_hw ---------------^

C:\Users\ludovic.guerra\Desktop\Code\f1\ula//include/drv/rtc.h:118: WARNING: Error in declarator If declarator-id with parameters: Invalid C declaration: Expected identifier in nested name. [error at 13] sys_status_t ()(int, drv_i2c_io_t , int ) get_i2c_message_configure -------------^ If parenthesis in noptr-declarator: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 15] sys_status_t ()(int, drv_i2c_io_t , int ) get_i2c_message_configure ---------------^

C:\Users\ludovic.guerra\Desktop\Code\f1\ula//include/drv/rtc.h:121: WARNING: Error in declarator If declarator-id with parameters: Invalid C declaration: Expected identifier in nested name. [error at 13] sys_status_t ()(int, rtc_time_t) set_hw_time -------------^ If parenthesis in noptr-declarator: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 15] sys_status_t ()(int, rtc_time_t) set_hw_time ---------------^

C:\Users\ludovic.guerra\Desktop\Code\f1\ula//include/drv/rtc.h:123: WARNING: Error in declarator If declarator-id with parameters: Invalid C declaration: Expected identifier in nested name. [error at 13] sys_status_t ()(int, rtc_time_t ) get_hw_time -------------^ If parenthesis in noptr-declarator: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 15] sys_status_t ()(int, rtc_time_t ) get_hw_time ---------------^

C:\Users\ludovic.guerra\Desktop\Code\f1\ula//include/drv/rtc.h:125: WARNING: Error in declarator If declarator-id with parameters: Invalid C declaration: Expected identifier in nested name. [error at 13] sys_status_t ()(int, drv_i2c_io_t , int , rtc_time_t) get_i2c_message_get_time -------------^ If parenthesis in noptr-declarator: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 15] sys_status_t ()(int, drv_i2c_io_t , int , rtc_time_t) get_i2c_message_get_time ---------------^

C:\Users\ludovic.guerra\Desktop\Code\f1\ula//include/drv/rtc.h:129: WARNING: Error in declarator If declarator-id with parameters: Invalid C declaration: Expected identifier in nested name. [error at 13] sys_status_t ()(int, drv_i2c_io_t , int , rtc_time_t) get_i2c_message_set_time -------------^ If parenthesis in noptr-declarator: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 15] sys_status_t ()(int, drv_i2c_io_t , int , rtc_time_t) get_i2c_message_set_time ---------------^

C:\Users\ludovic.guerra\Desktop\Code\f1\ula//include/drv/rtc.h:133: WARNING: Error in declarator If declarator-id with parameters: Invalid C declaration: Expected identifier in nested name. [error at 13] sys_status_t ()(int, drv_i2c_io_t , int, rtc_time_t ) extract_time_from_i2c -------------^ If parenthesis in noptr-declarator: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 15] sys_status_t ()(int, drv_i2c_io_t , int, rtc_time_t ) extract_time_from_i2c

jnikula commented 3 years ago

Please try with the just released Hawkmoth 0.6, and if it's still failing, please provide a small example that reproduces the issue.

HobbitDur commented 3 years ago

Hi. Thank you for the update. I just tried and it is still falling. A small example is simply a file with a typedef:

typedef struct drv_rtc_func_s
{
  /** Test */
  int (*tutu)(int tata);
} drv_rtc_func_t;

And the error:

WARNING: Error in declarator If declarator-id with parameters: Invalid C declaration: Expected identifier in nested name. [error at 4] int (*)(int) tutu ----^ If parenthesis in noptr-declarator: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 6] int (*)(int) tutu ------^

jnikula commented 3 years ago

Thanks for the minimal example. The quick fix is in the function-pointer-fix branch.

https://github.com/jnikula/hawkmoth/tree/function-pointer-fix

HobbitDur commented 3 years ago

@jnikula On my windows, I did a pip install git+https://github.com/jnikula/hawkmoth.git@function-pointer-fix, and got the answer: Collecting git+https://github.com/jnikula/hawkmoth.git@function-pointer-fix Cloning https://github.com/jnikula/hawkmoth.git (to revision function-pointer-fix)

So I guess the cloning worked fine. But I still got the same error.

What did I miss ?

jnikula commented 3 years ago

I am not sure, but if you're installing in a (virtual) environment where you have hawkmoth already installed, the branch would actually still have the same version, and pip perhaps does not know to upgrade. Maybe you'd also need to use -U. Anyway, perhaps try removing and reinstalling?

HobbitDur commented 3 years ago

Removed and reinstalled. It worked ! The bug is solved then.

jnikula commented 3 years ago

Thanks for testing! Again, I'll give @BrunoMSantos a little bit of time before going ahead and pushing and releasing.

BrunoMSantos commented 3 years ago

Hey. I do have a comment on this one. I can't figure out where to place the comments though. Maybe this should have been a pull request in order to get the github machinery working? Of course I'm so used to gitlab and mailing lists I may just be missing something really obvious :/

For now I'll just leave my comment here. It relates to this line: fptr_type = ttype.replace('(*)', '(*{})'.format(name), 1). This will still break if it is a pointer to a pointer of a function, and so on. I don't suppose that's the kind of code that gets written often, but a regex would fix it.

BrunoMSantos commented 3 years ago

Forgive me, I'm definitely being dumb. I should have looked over all of my inbox :facepalm: