Skip to content

Commit

Permalink
C: fill properties for a function defined with a struct definition as…
Browse files Browse the repository at this point in the history
… the return type of the function

For the input like:

    static struct S {...} fn (...) { ... }

the original code didn't fill the properties: field of
fn with "static".

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Feb 24, 2024
1 parent 937f93a commit 89e16c5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Units/parser-c.r/properties.c.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--sort=no
--kinds-c=*
--fields=+x
--fields-c=+{properties}
5 changes: 5 additions & 0 deletions Units/parser-c.r/properties.c.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
T input.c /^static struct T {int t;} f1(int i)$/;" s file:
t input.c /^static struct T {int t;} f1(int i)$/;" m struct:T typeref:typename:int file:
f1 input.c /^static struct T {int t;} f1(int i)$/;" f typeref:struct:T file: properties:static
i input.c /^static struct T {int t;} f1(int i)$/;" z function:f1 typeref:typename:int file:
r input.c /^ struct T r = {.t = i};$/;" l function:f1 typeref:struct:T file:
9 changes: 9 additions & 0 deletions Units/parser-c.r/properties.c.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// See #3943.
// static struct S {int s;} fS1(int i);

/* This is invalid input as C++ code. */
static struct T {int t;} f1(int i)
{
struct T r = {.t = i};
return r;
}
19 changes: 19 additions & 0 deletions parsers/cxx/cxx_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,25 @@ static bool cxxParserParseEnumStructClassOrUnionFullDeclarationTrailer(
if(cxxTokenTypeIs(g_cxx.pToken,CXXTokenTypeOpeningBracket))
{
CXX_DEBUG_PRINT("Found opening bracket: possibly a function declaration?");

// Revert keyword states.
// Here we assume the following kind of input:
//
// static struct S {...} fn (...) { ... }
//
// To fill properties: field of fn with "static", g_cxx.uKeywordState
// must be set here.
//
// See cxxParserEmitFunctionTags.
//
// NOTE: C++ doesn't accept such kind of input. So we propagate
// the state only meaningful in C languages.
g_cxx.uKeywordState |= uKeywordState & (0
| CXXParserKeywordStateSeenStatic
| CXXParserKeywordStateSeenInline
| CXXParserKeywordStateSeenExtern
| CXXParserKeywordStateSeenAttributeDeprecated
);
if(!cxxParserParseBlockHandleOpeningBracket())
{
CXX_DEBUG_LEAVE_TEXT("Failed to handle the opening bracket");
Expand Down

0 comments on commit 89e16c5

Please sign in to comment.