From 937f93ad4c8fb0c6e7946749d9a935c479b6842d Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sat, 24 Feb 2024 10:42:18 +0900 Subject: [PATCH] C++,C: fill properties for variables defined with its struct definition 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 --- Tmain/extras-field.d/run.sh | 2 +- Tmain/extras-field.d/stdout-expected.txt | 4 ++-- .../properties.cpp.d/expected.tags | 5 +++++ Units/parser-cxx.r/properties.cpp.d/input.cpp | 2 ++ parsers/cxx/cxx_parser.c | 19 +++++++++++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Tmain/extras-field.d/run.sh b/Tmain/extras-field.d/run.sh index 2d9c2ed676..86cb00a239 100644 --- a/Tmain/extras-field.d/run.sh +++ b/Tmain/extras-field.d/run.sh @@ -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|' diff --git a/Tmain/extras-field.d/stdout-expected.txt b/Tmain/extras-field.d/stdout-expected.txt index 400922819d..62279189ab 100644 --- a/Tmain/extras-field.d/stdout-expected.txt +++ b/Tmain/extras-field.d/stdout-expected.txt @@ -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 diff --git a/Units/parser-cxx.r/properties.cpp.d/expected.tags b/Units/parser-cxx.r/properties.cpp.d/expected.tags index dd88f46f89..0e1f1d08a9 100644 --- a/Units/parser-cxx.r/properties.cpp.d/expected.tags +++ b/Units/parser-cxx.r/properties.cpp.d/expected.tags @@ -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 diff --git a/Units/parser-cxx.r/properties.cpp.d/input.cpp b/Units/parser-cxx.r/properties.cpp.d/input.cpp index 7749860f0a..9d29b61483 100644 --- a/Units/parser-cxx.r/properties.cpp.d/input.cpp +++ b/Units/parser-cxx.r/properties.cpp.d/input.cpp @@ -42,3 +42,5 @@ static void f01() static inline void f02() { } + +static struct point { float x, y; } p0, p1; diff --git a/parsers/cxx/cxx_parser.c b/parsers/cxx/cxx_parser.c index 68973ed855..65fe77c69e 100644 --- a/parsers/cxx/cxx_parser.c +++ b/parsers/cxx/cxx_parser.c @@ -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;