Skip to content

Commit

Permalink
Merge pull request #3344 from masatake/c--func-after-typedef-for-func…
Browse files Browse the repository at this point in the history
…tion-returning-struct

Cxx: add missing code for resetting typedef parsing state
MERGING without getting a review from @pragmaware.
  • Loading branch information
masatake authored Jun 19, 2022
2 parents bbfadb6 + 277e3bd commit cbdc5c4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+S
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
s input.c /^enum s { E };$/;" g file:
E input.c /^enum s { E };$/;" e enum:s file:
g input.c /^typedef enum s (*g)(void);$/;" t typeref:enum:s (*)(void) file:
f input.c /^void f(void){}$/;" f typeref:typename:void signature:(void)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enum s { E };
typedef enum s (*g)(void);
void f(void){}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+S
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
s input.c /^struct s {};$/;" s file:
g input.c /^typedef struct s (*g)(void);$/;" t typeref:struct:s (*)(void) file:
f input.c /^void f(void){}$/;" f typeref:typename:void signature:(void)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct s {};
typedef struct s (*g)(void);
void f(void){}
12 changes: 10 additions & 2 deletions parsers/cxx/cxx_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,12 @@ bool cxxParserParseEnum(void)
{
if(uInitialKeywordState & CXXParserKeywordStateSeenTypedef)
{
bool bR;
g_cxx.uKeywordState &= ~CXXParserKeywordStateSeenTypedef;
CXX_DEBUG_LEAVE_TEXT("Found parenthesis after typedef: parsing as generic typedef");
return cxxParserParseGenericTypedef();
bR = cxxParserParseGenericTypedef();
cxxParserNewStatement();
return bR;
}
// probably a function declaration/prototype
// something like enum x func()....
Expand Down Expand Up @@ -1066,8 +1070,12 @@ static bool cxxParserParseClassStructOrUnionInternal(
{
if(uInitialKeywordState & CXXParserKeywordStateSeenTypedef)
{
bool bR;
g_cxx.uKeywordState &= ~CXXParserKeywordStateSeenTypedef;
CXX_DEBUG_LEAVE_TEXT("Found parenthesis after typedef: parsing as generic typedef");
return cxxParserParseGenericTypedef();
bR = cxxParserParseGenericTypedef();
cxxParserNewStatement();
return bR;
}

// probably a function declaration/prototype
Expand Down

0 comments on commit cbdc5c4

Please sign in to comment.