Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Getting typedef name of a return value of a typedef function #57

Closed
xlab opened this issue Sep 24, 2016 · 4 comments
Closed

Getting typedef name of a return value of a typedef function #57

xlab opened this issue Sep 24, 2016 · 4 comments
Assignees

Comments

@xlab
Copy link
Collaborator

xlab commented Sep 24, 2016

Hey, I'm struggling with this case and CC, there seems to be no way to distinguish the typedef name of a return value type and the function typedef name.

typedef int hb_bool_t;

typedef hb_bool_t (*hb_font_get_font_extents_func_t) (hb_font_t *font, void *font_data,
                               hb_font_extents_t *metrics,
                               void *user_data);

typedef hb_font_get_font_extents_func_t hb_font_get_font_h_extents_func_t;
typedef hb_font_get_font_extents_func_t hb_font_get_font_v_extents_func_t;

I can get either

hb_bool_t
hb_font_get_font_extents_func_t
hb_font_get_font_extents_func_t

trying to resolve the returning values of these three functions or

int
int
int

whereas the real situation is

hb_bool_t
hb_bool_t
hb_bool_t

See https://github.com/xlab/cgogen/blob/ce6cef3a5c56da7c4d87379c35594a413418b024/translator/ast_walker.go#L348-L351 how this should be actually handled? Accessing the typ.Result() doesn't provide the typedef name of its type (I get int), trying to get it via typ.Result().Declarator().RawSpecifier() would yield specifier of a function typedef, not the resulting type. I'm not sure if the CC API is incomplete or it's a bug or I don't know something.

@cznic
Copy link
Owner

cznic commented Sep 25, 2016

@xlab Max please take a look at the test I've just pushed. It passes, so I probably did not understood the problem. Please clarify or adjust the test to fail, thank you.

@xlab
Copy link
Collaborator Author

xlab commented Sep 25, 2016

@cznic
Alright this is a good idea! I've adjusted the test so it fails, also I hope it's clear now what is the problem I'm experiencing there. Check my commit pls.

typedef int bool_t;

typedef bool_t (*bool_func) (void);
typedef bool_func func1;

cznic pushed a commit that referenced this issue Sep 25, 2016
@cznic
Copy link
Owner

cznic commented Sep 25, 2016

@xlab PTAL, thanks.

@xlab
Copy link
Collaborator Author

xlab commented Sep 25, 2016

@cznic

 +  // RawDefDeclarator returns the typedef declarator associated with a
 +  RawDeclarator() 

This needs a typo fix, otherwise works fine! Brilliant!

@cznic cznic closed this as completed in 668d148 Sep 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants