Skip to content

Commit

Permalink
C++,C: fill properties for variables defined with its struct definition
Browse files Browse the repository at this point in the history
For the input like:

  static struct S {...} svar;

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

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Feb 24, 2024
1 parent 8706976 commit 937f93a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Tmain/extras-field.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

CTAGS=$1

${CTAGS} --quiet --options=NONE --fields=+Ere-T --extras=+qrf -o - input.cpp \
${CTAGS} --quiet --options=NONE --kinds-C++=+x --fields=+Ere-T --extras=+qrf -o - input.cpp \
| sed -e 's|[^ ]*\(input.cpp\)|\1|'
4 changes: 2 additions & 2 deletions Tmain/extras-field.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
X input.cpp /^namespace X {$/;" n file: roles:def extras:fileScope end:6
X::Y input.cpp /^ extern class Y {$/;" c namespace:X file: roles:def extras:fileScope,qualified end:5
X::Y::m input.cpp /^ int m;$/;" m class:X::Y typeref:typename:int file: roles:def extras:fileScope,qualified end:4
X::v input.cpp /^ } v;$/;" v namespace:X typeref:class:X::Y roles:def extras:qualified end:5
X::v input.cpp /^ } v;$/;" x namespace:X typeref:class:X::Y roles:def extras:qualified end:5
Y input.cpp /^ extern class Y {$/;" c namespace:X file: roles:def extras:fileScope end:5
Z input.cpp /^#define Z$/;" d file: roles:def extras:fileScope end:1
Z input.cpp /^#undef Z$/;" d file: roles:undef extras:fileScope,reference
input.cpp input.cpp 1;" F roles:def extras:inputFile end:7
m input.cpp /^ int m;$/;" m class:X::Y typeref:typename:int file: roles:def extras:fileScope end:4
v input.cpp /^ } v;$/;" v namespace:X typeref:class:X::Y roles:def end:5
v input.cpp /^ } v;$/;" x namespace:X typeref:class:X::Y roles:def end:5
5 changes: 5 additions & 0 deletions Units/parser-cxx.r/properties.cpp.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ p01 input.cpp /^static void p01();$/;" p typeref:typename:void file: properties:
p02 input.cpp /^extern void p02();$/;" p typeref:typename:void file: properties:extern
f01 input.cpp /^static void f01()$/;" f typeref:typename:void file: properties:static
f02 input.cpp /^static inline void f02()$/;" f typeref:typename:void file: properties:inline,static
point input.cpp /^static struct point { float x, y; } p0, p1;$/;" s file:
x input.cpp /^static struct point { float x, y; } p0, p1;$/;" m struct:point typeref:typename:float file:
y input.cpp /^static struct point { float x, y; } p0, p1;$/;" m struct:point typeref:typename:float file:
p0 input.cpp /^static struct point { float x, y; } p0, p1;$/;" v typeref:struct:point file: properties:static
p1 input.cpp /^static struct point { float x, y; } p0, p1;$/;" v typeref:struct:point file: properties:static
2 changes: 2 additions & 0 deletions Units/parser-cxx.r/properties.cpp.d/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ static void f01()
static inline void f02()
{
}

static struct point { float x, y; } p0, p1;
19 changes: 19 additions & 0 deletions parsers/cxx/cxx_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,26 @@ static bool cxxParserParseEnumStructClassOrUnionFullDeclarationTrailer(
if(uKeywordState & CXXParserKeywordStateSeenTypedef)
cxxParserExtractTypedef(g_cxx.pTokenChain,true,false);
else
{
// Revert keyword states.
// Here we assume the following kind of input:
//
// static struct S {...} s;
//
// To fill properties: field of s with "static", g_cxx.uKeywordState
// must be set here.
g_cxx.uKeywordState |= uKeywordState & (0
| CXXParserKeywordStateSeenStatic
| CXXParserKeywordStateSeenExtern
| CXXParserKeywordStateSeenMutable
| CXXParserKeywordStateSeenInline
| CXXParserKeywordStateSeenAttributeDeprecated
| CXXParserKeywordStateSeenConstexpr
| CXXParserKeywordStateSeenConstinit
| CXXParserKeywordStateSeenThreadLocal
);
cxxParserExtractVariableDeclarations(g_cxx.pTokenChain,0);
}

CXX_DEBUG_LEAVE();
return true;
Expand Down

0 comments on commit 937f93a

Please sign in to comment.