From 184973b4e12b1f1694cc23d9a4df04e0f3895415 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Tue, 15 Nov 2022 10:31:38 +0900 Subject: [PATCH 1/7] Cxx: extract reference tags Signed-off-by: Masatake YAMATO --- Tmain/list-kinds-full.d/stdout-expected.txt | 2 + Tmain/list-roles.d/stdout-expected.txt | 31 +++++++++ Tmain/nested-subparsers.d/stdout-expected.txt | 2 + .../c-reftags-unknown-ref.d/args.ctags | 5 ++ .../c-reftags-unknown-ref.d/expected.tags | 13 ++++ .../c-reftags-unknown-ref.d/input.c | 15 +++++ .../bug639644.cpp.d/expected.tags | 4 +- .../namespace.cpp.d/expected.tags | 12 ++-- .../simple-qt-reftag.d/args.ctags | 6 ++ .../simple-qt-reftag.d/expected.tags | 65 +++++++++++++++++++ .../parser-qtmoc.r/simple-qt-reftag.d/input.h | 65 +++++++++++++++++++ misc/mini-geany.expected | 1 + parsers/cxx/cxx_parser_function.c | 2 + parsers/cxx/cxx_parser_namespace.c | 1 + parsers/cxx/cxx_parser_tokenizer.c | 11 +++- parsers/cxx/cxx_parser_variable.c | 1 + parsers/cxx/cxx_qtmoc.c | 1 + parsers/cxx/cxx_reftag.c | 40 ++++++++++++ parsers/cxx/cxx_reftag.h | 15 +++++ parsers/cxx/cxx_tag.c | 23 ++++++- parsers/cxx/cxx_tag.h | 8 +++ parsers/cxx/cxx_token.c | 3 + parsers/cxx/cxx_token.h | 8 +++ parsers/cxx/cxx_token_chain.c | 2 + source.mak | 2 + win32/ctags_vs2013.vcxproj | 2 + win32/ctags_vs2013.vcxproj.filters | 6 ++ 27 files changed, 335 insertions(+), 11 deletions(-) create mode 100644 Units/parser-c.r/c-reftags-unknown-ref.d/args.ctags create mode 100644 Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags create mode 100644 Units/parser-c.r/c-reftags-unknown-ref.d/input.c create mode 100644 Units/parser-qtmoc.r/simple-qt-reftag.d/args.ctags create mode 100644 Units/parser-qtmoc.r/simple-qt-reftag.d/expected.tags create mode 100644 Units/parser-qtmoc.r/simple-qt-reftag.d/input.h create mode 100644 parsers/cxx/cxx_reftag.c create mode 100644 parsers/cxx/cxx_reftag.h diff --git a/Tmain/list-kinds-full.d/stdout-expected.txt b/Tmain/list-kinds-full.d/stdout-expected.txt index 25cd1ec121..fac0644876 100644 --- a/Tmain/list-kinds-full.d/stdout-expected.txt +++ b/Tmain/list-kinds-full.d/stdout-expected.txt @@ -1,6 +1,7 @@ #LETTER NAME ENABLED REFONLY NROLES MASTER DESCRIPTION D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels +Y unknown no yes 1 C unknown identifier d macro yes no 2 C macro definitions e enumerator yes no 0 C enumerators (values inside an enumeration) f function yes no 0 C function definitions @@ -21,6 +22,7 @@ D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels N name no no 0 NONE names imported via using scope::symbol U using no no 0 NONE using namespace statements +Y unknown no yes 1 C unknown identifier Z tparam no no 0 NONE template parameters c class yes no 0 NONE classes d macro yes no 2 C macro definitions diff --git a/Tmain/list-roles.d/stdout-expected.txt b/Tmain/list-roles.d/stdout-expected.txt index 111465ee06..c3b6655396 100644 --- a/Tmain/list-roles.d/stdout-expected.txt +++ b/Tmain/list-roles.d/stdout-expected.txt @@ -18,10 +18,12 @@ Automake d/directory program on directory for PROGRA Automake d/directory script on directory for SCRIPTS primary Basic f/function decl on declared Bats S/script loaded on script loaed with "load" command +C Y/unknown ref off referenced anyhow C d/macro condition off used in part of #if/#ifdef/#elif conditions C d/macro undef on undefined C h/header local on local header C h/header system on system header +C++ Y/unknown ref off referenced anyhow C++ d/macro condition off used in part of #if/#ifdef/#elif conditions C++ d/macro undef on undefined C++ h/header local on local header @@ -30,6 +32,7 @@ CPreProcessor d/macro condition off used in part of #if/ CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header CPreProcessor h/header system on system header +CUDA Y/unknown ref off referenced anyhow CUDA d/macro condition off used in part of #if/#ifdef/#elif conditions CUDA d/macro undef on undefined CUDA h/header local on local header @@ -138,10 +141,12 @@ Automake d/directory program on directory for PROGRA Automake d/directory script on directory for SCRIPTS primary Basic f/function decl on declared Bats S/script loaded on script loaed with "load" command +C Y/unknown ref off referenced anyhow C d/macro condition off used in part of #if/#ifdef/#elif conditions C d/macro undef on undefined C h/header local on local header C h/header system on system header +C++ Y/unknown ref off referenced anyhow C++ d/macro condition off used in part of #if/#ifdef/#elif conditions C++ d/macro undef on undefined C++ h/header local on local header @@ -150,6 +155,7 @@ CPreProcessor d/macro condition off used in part of #if/ CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header CPreProcessor h/header system on system header +CUDA Y/unknown ref off referenced anyhow CUDA d/macro condition off used in part of #if/#ifdef/#elif conditions CUDA d/macro undef on undefined CUDA h/header local on local header @@ -243,6 +249,7 @@ Zsh s/script loaded on loaded # C.* # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -280,6 +287,7 @@ s/script loaded on loaded # C.* with disabling all roles of all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -289,6 +297,7 @@ h/header system off system header # C.* with disabling all roles of all kinds of all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -299,6 +308,7 @@ h/header system off system header # after disabling system role of header kind of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref on referenced anyhow d/macro condition on used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -309,6 +319,7 @@ h/header system on system header # after disabling system role of header kind of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref on referenced anyhow d/macro condition on used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -318,6 +329,7 @@ h/header system on system header # C.* with disabling all roles in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -334,6 +346,7 @@ s/script loaded on loaded # C.* with disabling all roles of all kinds in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -351,6 +364,7 @@ s/script loaded on loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref on referenced anyhow d/macro condition on used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -369,6 +383,7 @@ s/script loaded off loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref on referenced anyhow d/macro condition on used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -386,6 +401,7 @@ s/script loaded off loaded # C.* with disabling all roles of {header} kind in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local off local header @@ -402,6 +418,7 @@ s/script loaded on loaded # C.* with disabling all roles of h kind in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local off local header @@ -419,6 +436,7 @@ s/script loaded on loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -437,6 +455,7 @@ s/script loaded off loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -454,6 +473,7 @@ s/script loaded off loaded # C.* with disabling system role of h kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -463,6 +483,7 @@ h/header system off system header # C.* with disabling system role of {header} kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -472,6 +493,7 @@ h/header system off system header # C.* with enabling system role of h kind after disabling the role # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -481,6 +503,7 @@ h/header system on system header # C.* with enabling system role of {header} kind after disabling the role # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -490,6 +513,7 @@ h/header system on system header # C.* with disabling system and local roles of h kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local off local header @@ -499,6 +523,7 @@ h/header system off system header # C.* with disabling system and local roles of {header} kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local off local header @@ -509,6 +534,7 @@ h/header system off system header # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -519,6 +545,7 @@ h/header system on system header # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -528,6 +555,7 @@ h/header system on system header # C.* with disabling local role of h kind and undef role of d kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -537,6 +565,7 @@ h/header system on system header # C.* with enabling all roles of header kinds after disabling all roles of the kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -546,6 +575,7 @@ h/header system on system header # C.* with enabling all roles of header kinds after disabling all roles of the kinds of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -555,6 +585,7 @@ h/header system on system header # C.* with enabling all roles of header kinds after disabling all roles of the kinds of C language (short notation) # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header diff --git a/Tmain/nested-subparsers.d/stdout-expected.txt b/Tmain/nested-subparsers.d/stdout-expected.txt index 7f7c014023..4435e5857b 100644 --- a/Tmain/nested-subparsers.d/stdout-expected.txt +++ b/Tmain/nested-subparsers.d/stdout-expected.txt @@ -17,6 +17,7 @@ x external and forward variable declarations [off] z function parameters inside function or prototype definitions [off] L goto labels [off] D parameters inside macro definitions [off] +Y unknown identifier [off] # # list kinds Event # @@ -36,6 +37,7 @@ n name #LETTER NAME ENABLED REFONLY NROLES MASTER DESCRIPTION D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels +Y unknown no yes 1 C unknown identifier d macro yes no 2 C macro definitions e enumerator yes no 0 C enumerators (values inside an enumeration) f function yes no 0 C function definitions diff --git a/Units/parser-c.r/c-reftags-unknown-ref.d/args.ctags b/Units/parser-c.r/c-reftags-unknown-ref.d/args.ctags new file mode 100644 index 0000000000..a56fea51c3 --- /dev/null +++ b/Units/parser-c.r/c-reftags-unknown-ref.d/args.ctags @@ -0,0 +1,5 @@ +--sort=no +--extras=+r +--fields=+r +--kinds-C=* +--roles-C.{unknown}=* diff --git a/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags b/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags new file mode 100644 index 0000000000..c8e291bbda --- /dev/null +++ b/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags @@ -0,0 +1,13 @@ +x input.c /^struct x {$/;" s file: roles:def +y input.c /^ int y;$/;" m struct:x typeref:typename:int file: roles:def +X input.c /^enum X {$/;" g file: roles:def +A input.c /^ A, B$/;" e enum:X file: roles:def +B input.c /^ A, B$/;" e enum:X file: roles:def +i input.c /^extern int i;$/;" x typeref:typename:int roles:def +f input.c /^int f(int j)$/;" f typeref:typename:int roles:def +j input.c /^int f(int j)$/;" z function:f typeref:typename:int file: roles:def +j input.c /^ if (j == 0)$/;" Y roles:ref +i input.c /^ return i + B + j + f(0);$/;" Y roles:ref +B input.c /^ return i + B + j + f(0);$/;" Y roles:ref +j input.c /^ return i + B + j + f(0);$/;" Y roles:ref +f input.c /^ return i + B + j + f(0);$/;" Y roles:ref diff --git a/Units/parser-c.r/c-reftags-unknown-ref.d/input.c b/Units/parser-c.r/c-reftags-unknown-ref.d/input.c new file mode 100644 index 0000000000..ddb280b25a --- /dev/null +++ b/Units/parser-c.r/c-reftags-unknown-ref.d/input.c @@ -0,0 +1,15 @@ +struct x { + int y; +}; + +enum X { + A, B +}; + +extern int i; +int f(int j) +{ + if (j == 0) + return 0; + return i + B + j + f(0); +} diff --git a/Units/parser-cxx.r/bug639644.cpp.d/expected.tags b/Units/parser-cxx.r/bug639644.cpp.d/expected.tags index 19f59e96e7..2640de8faf 100644 --- a/Units/parser-cxx.r/bug639644.cpp.d/expected.tags +++ b/Units/parser-cxx.r/bug639644.cpp.d/expected.tags @@ -1,2 +1,2 @@ -__anon21d591360111 input.h /^{$/;" n -foo input.h /^ int foo;$/;" v namespace:__anon21d591360111 typeref:typename:int +__anon21d591360112 input.h /^{$/;" n +foo input.h /^ int foo;$/;" v namespace:__anon21d591360112 typeref:typename:int diff --git a/Units/parser-cxx.r/namespace.cpp.d/expected.tags b/Units/parser-cxx.r/namespace.cpp.d/expected.tags index 2a2ddb6e22..4a0e672ac8 100644 --- a/Units/parser-cxx.r/namespace.cpp.d/expected.tags +++ b/Units/parser-cxx.r/namespace.cpp.d/expected.tags @@ -1,15 +1,15 @@ -__anon396601200111 input.cpp /^namespace {$/;" n file: end:8 -anon_f input.cpp /^ void anon_f() { };$/;" f namespace:__anon396601200111 typeref:typename:void end:3 -__anon396601200211 input.cpp /^ namespace {$/;" n namespace:__anon396601200111 file: end:7 -anon_anon_f input.cpp /^ void anon_anon_f() { };$/;" f namespace:__anon396601200111::__anon396601200211 typeref:typename:void end:6 +__anon396601200112 input.cpp /^namespace {$/;" n file: end:8 +anon_f input.cpp /^ void anon_f() { };$/;" f namespace:__anon396601200112 typeref:typename:void end:3 +__anon396601200212 input.cpp /^ namespace {$/;" n namespace:__anon396601200112 file: end:7 +anon_anon_f input.cpp /^ void anon_anon_f() { };$/;" f namespace:__anon396601200112::__anon396601200212 typeref:typename:void end:6 a1 input.cpp /^namespace a1 {$/;" n file: end:24 a1_f input.cpp /^ void a1_f() { }$/;" f namespace:a1 typeref:typename:void end:11 a2 input.cpp /^ namespace a2 {$/;" n namespace:a1 file: end:19 a1_a2_f input.cpp /^ void a1_a2_f() { }$/;" f namespace:a1::a2 typeref:typename:void end:14 a3 input.cpp /^ namespace a3 {$/;" n namespace:a1::a2 file: end:18 a1_a2_a3_f input.cpp /^ void a1_a2_a3_f() { };$/;" f namespace:a1::a2::a3 typeref:typename:void end:17 -__anon396601200311 input.cpp /^ namespace {$/;" n namespace:a1 file: end:23 -a1_anon_f input.cpp /^ void a1_anon_f() { };$/;" f namespace:a1::__anon396601200311 typeref:typename:void end:22 +__anon396601200312 input.cpp /^ namespace {$/;" n namespace:a1 file: end:23 +a1_anon_f input.cpp /^ void a1_anon_f() { };$/;" f namespace:a1::__anon396601200312 typeref:typename:void end:22 b1 input.cpp /^namespace b1::b2 {$/;" n file: end:32 b2 input.cpp /^namespace b1::b2 {$/;" n namespace:b1 file: end:32 b1_b2_f input.cpp /^ void b1_b2_f() { };$/;" f namespace:b1::b2 typeref:typename:void end:27 diff --git a/Units/parser-qtmoc.r/simple-qt-reftag.d/args.ctags b/Units/parser-qtmoc.r/simple-qt-reftag.d/args.ctags new file mode 100644 index 0000000000..94e926553b --- /dev/null +++ b/Units/parser-qtmoc.r/simple-qt-reftag.d/args.ctags @@ -0,0 +1,6 @@ +--sort=no +--kinds-C++=+p +--fields=+lK +--extras=+r +--kinds-C++=+{unknown} +--roles-C++.{unknown}=+{ref} diff --git a/Units/parser-qtmoc.r/simple-qt-reftag.d/expected.tags b/Units/parser-qtmoc.r/simple-qt-reftag.d/expected.tags new file mode 100644 index 0000000000..6771222eac --- /dev/null +++ b/Units/parser-qtmoc.r/simple-qt-reftag.d/expected.tags @@ -0,0 +1,65 @@ +QFrame input.h /^class ColumnPreferencesFrame : public QFrame$/;" unknown language:C++ +ColumnPreferencesFrame input.h /^class ColumnPreferencesFrame : public QFrame$/;" class language:C++ +Q_OBJECT input.h /^ Q_OBJECT$/;" unknown language:C++ +method0 input.h /^ void method0(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slots input.h /^private slots:$/;" unknown language:C++ +slot0 input.h /^ void slot0(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot0 input.h /^ void slot0(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +slot1 input.h /^ void slot1(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot1 input.h /^ void slot1(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +slots input.h /^public slots:$/;" unknown language:C++ +slot2 input.h /^ void slot2(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot2 input.h /^ void slot2(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +slot3 input.h /^ void slot3(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot3 input.h /^ void slot3(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +Q_SLOTS input.h /^Q_SLOTS:$/;" unknown language:C++ +slot4 input.h /^ void slot4(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot4 input.h /^ void slot4(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +slot5 input.h /^ void slot5(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot5 input.h /^ void slot5(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +field0 input.h /^ int field0;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int +method1 input.h /^ virtual void method1(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +Q_SLOTS input.h /^private Q_SLOTS:$/;" unknown language:C++ +slot6 input.h /^ void slot6(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot6 input.h /^ void slot6(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +slot7 input.h /^ void slot7(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot7 input.h /^ void slot7(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +Q_SLOTS input.h /^public Q_SLOTS:$/;" unknown language:C++ +slot8 input.h /^ void slot8(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot8 input.h /^ void slot8(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +slot9 input.h /^ void slot9(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot9 input.h /^ void slot9(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +slots input.h /^slots:$/;" unknown language:C++ +slot10 input.h /^ void slot10(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot10 input.h /^ void slot10(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +slot11 input.h /^ void slot11(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +slot11 input.h /^ void slot11(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +field1 input.h /^ int field1;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int +signals input.h /^signals:$/;" unknown language:C++ +signal0 input.h /^ void signal0(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +signal0 input.h /^ void signal0(void);$/;" signal language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +signal1 input.h /^ void signal1(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +signal1 input.h /^ void signal1(void);$/;" signal language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +field2 input.h /^ int field2;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int +method2 input.h /^ virtual void method2(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +Q_SIGNALS input.h /^Q_SIGNALS:$/;" unknown language:C++ +signal2 input.h /^ void signal2(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +signal2 input.h /^ void signal2(void);$/;" signal language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +signal3 input.h /^ void signal3(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +signal3 input.h /^ void signal3(void);$/;" signal language:QtMoc class:ColumnPreferencesFrame typeref:typename:void +field3 input.h /^ int field3;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int +method3 input.h /^ virtual void method3(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void +Q_PROPERTY input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ +QString input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ +text input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" property language:QtMoc class:ColumnPreferencesFrame typeref:typename:QString +MEMBER input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ +m_text input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ +NOTIFY input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ +textChanged input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ +Q_PROPERTY input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ +ShowNonprinting input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" property language:QtMoc class:ColumnPreferencesFrame typeref:typename:bool +READ input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ +showsNonprinting input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ +WRITE input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ +setShowsNonprinting input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ +field4 input.h /^ int field4;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int diff --git a/Units/parser-qtmoc.r/simple-qt-reftag.d/input.h b/Units/parser-qtmoc.r/simple-qt-reftag.d/input.h new file mode 100644 index 0000000000..0503ca7a01 --- /dev/null +++ b/Units/parser-qtmoc.r/simple-qt-reftag.d/input.h @@ -0,0 +1,65 @@ +class ColumnPreferencesFrame : public QFrame +{ + Q_OBJECT + void method0(void); + +private slots: + void slot0(void); + void slot1(void); + +public slots: + void slot2(void); + void slot3(void); + +Q_SLOTS: + void slot4(void); + void slot5(void); + +private: + int field0; + +protected: + virtual void method1(void); + +private Q_SLOTS: + void slot6(void); + void slot7(void); + +public Q_SLOTS: + void slot8(void); + void slot9(void); + +slots: + void slot10(void); + void slot11(void); + +private: + int field1; + +signals: + void signal0(void); + void signal1(void); + +private: + int field2; + +protected: + virtual void method2(void); + +Q_SIGNALS: + void signal2(void); + void signal3(void); + +private: + int field3; + +protected: + virtual void method3(void); + + Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged) + Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting ) + +private: + int field4; + +}; diff --git a/misc/mini-geany.expected b/misc/mini-geany.expected index f075db78b3..3b82d0739e 100644 --- a/misc/mini-geany.expected +++ b/misc/mini-geany.expected @@ -17,6 +17,7 @@ x: externvar z: parameter L: label D: macroparam +Y: unknown Parsing buffer: foo line: 1 kind: function lang: C diff --git a/parsers/cxx/cxx_parser_function.c b/parsers/cxx/cxx_parser_function.c index f4e02f554a..33ceda59c2 100644 --- a/parsers/cxx/cxx_parser_function.c +++ b/parsers/cxx/cxx_parser_function.c @@ -1543,6 +1543,7 @@ int cxxParserEmitFunctionTags( 0 ); + cxxTagUseTokensInRangeAsPartOfDefTags(CORK_NIL,pInfo->pIdentifierStart,pInfo->pIdentifierEnd); cxxTokenChainDestroyRange(pInfo->pIdentifierChain,pInfo->pIdentifierStart,pInfo->pIdentifierEnd); CXX_DEBUG_ASSERT( @@ -1694,6 +1695,7 @@ int cxxParserEmitFunctionTags( pInfo->pTemplateSpecializationEnd, 0 ); + /* TODO */ // Tricky. We append it to the specialization chain which will // be then used by cxxTagHandleTemplateFileds() diff --git a/parsers/cxx/cxx_parser_namespace.c b/parsers/cxx/cxx_parser_namespace.c index 0eb4bdcfd4..48bf9559ea 100644 --- a/parsers/cxx/cxx_parser_namespace.c +++ b/parsers/cxx/cxx_parser_namespace.c @@ -141,6 +141,7 @@ bool cxxParserParseNamespace(void) pLastIdentifier, CXXTokenChainExtractRangeNoTrailingSpaces ); + /* TODO */ cxxTagSetField( CXXTagCPPFieldAliasedName, diff --git a/parsers/cxx/cxx_parser_tokenizer.c b/parsers/cxx/cxx_parser_tokenizer.c index f43137bb6c..7e70c3fe00 100644 --- a/parsers/cxx/cxx_parser_tokenizer.c +++ b/parsers/cxx/cxx_parser_tokenizer.c @@ -11,6 +11,7 @@ #include "cxx_debug.h" #include "cxx_keyword.h" +#include "cxx_reftag.h" #include "cxx_token.h" #include "cxx_token_chain.h" @@ -1214,7 +1215,7 @@ void cxxParserUngetCurrentToken(void) // // In some special cases this function may parse more than one token, // however only a single token will always be returned. -bool cxxParserParseNextToken(void) +static bool cxxParserParseNextTokenNoRefTag(void) { // The token chain should not be allowed to grow arbitrarily large. // The token structures are quite big and it's easy to grow up to @@ -1689,3 +1690,11 @@ bool cxxParserParseNextToken(void) return true; } + +bool cxxParserParseNextToken(void) +{ + bool r = cxxParserParseNextTokenNoRefTag(); + if(r) + cxxReftagEvalNewToken(); + return r; +} diff --git a/parsers/cxx/cxx_parser_variable.c b/parsers/cxx/cxx_parser_variable.c index c63476cdad..a71702e2b9 100644 --- a/parsers/cxx/cxx_parser_variable.c +++ b/parsers/cxx/cxx_parser_variable.c @@ -665,6 +665,7 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF ); CXXToken * pScopeId = cxxTokenChainExtractRange(pScopeStart,pPartEnd->pPrev,0); + /* TODO */ cxxScopePush( pScopeId, CXXScopeTypeClass, diff --git a/parsers/cxx/cxx_qtmoc.c b/parsers/cxx/cxx_qtmoc.c index d02f227e29..b7e49e30b6 100644 --- a/parsers/cxx/cxx_qtmoc.c +++ b/parsers/cxx/cxx_qtmoc.c @@ -86,6 +86,7 @@ static void qtMocMakeTagForProperty (CXXToken * pToken, const char *pszType) { tagEntryInfo tag; + cxxTagUseTokenAsPartOfDefTag(CORK_NIL, pToken); initTagEntry(&tag, vStringValue(pToken->pszWord), K_PROPERTY); diff --git a/parsers/cxx/cxx_reftag.c b/parsers/cxx/cxx_reftag.c new file mode 100644 index 0000000000..f7e134de56 --- /dev/null +++ b/parsers/cxx/cxx_reftag.c @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2022, Masatake YAMATO +* +* This source code is released for free distribution under the terms of the +* GNU General Public License version 2 or (at your option) any later version. +* +* This module contains functions for extracting reference tags +*/ + +#include "cxx_reftag.h" + +#include "cxx_token.h" +#include "cxx_parser_internal.h" +#include "read.h" + + +void cxxReftagEvalNewToken(void) +{ + if(cxxTokenTypeIs(g_cxx.pToken,CXXTokenTypeIdentifier) && + cxxTagKindEnabled(CXXTagKindUNKNOWN) && + cxxTagRoleEnabled(CXXTagKindUNKNOWN, CXXTagUnknownRoleREFERENCED)) + { + // QtMoc subparser calls this function indirectly. + // However, "unknown" kind + "ref" role is part of the + // base parser like C++. They are not part of the subparser. + // So we have to swtich the context for making the reference tag + // temporarily here. + const bool in_subparser = (g_cxx.eLangType != getInputLanguage()); + if (in_subparser) + pushLanguage(g_cxx.eLangType); + + g_cxx.pToken->iCorkIndex = makeSimpleRefTag(g_cxx.pToken->pszWord, + CXXTagKindUNKNOWN, + CXXTagUnknownRoleREFERENCED); + g_cxx.pToken->bCorkIndexForReftag = true; + + if (in_subparser) + popLanguage(); + } +} diff --git a/parsers/cxx/cxx_reftag.h b/parsers/cxx/cxx_reftag.h new file mode 100644 index 0000000000..7a03751d63 --- /dev/null +++ b/parsers/cxx/cxx_reftag.h @@ -0,0 +1,15 @@ +#ifndef _cxxReftag_h_ +#define _cxxReftag_h_ +/* +* Copyright (c) 2022, Masatake YAMATO +* +* This source code is released for free distribution under the terms of the +* GNU General Public License version 2 or (at your option) any later version. +* +* This module contains functions for extracting reference tags +*/ + +#include "general.h" + +void cxxReftagEvalNewToken(void); +#endif //!_cxxReftag_h_ diff --git a/parsers/cxx/cxx_tag.c b/parsers/cxx/cxx_tag.c index 06832532e2..718cfc46c4 100644 --- a/parsers/cxx/cxx_tag.c +++ b/parsers/cxx/cxx_tag.c @@ -19,6 +19,15 @@ #include "trashbox.h" #include "xtag.h" +#define CXX_COMMON_UNKNOWN_ROLES(__langPrefix) \ + static roleDefinition __langPrefix##UnknownRoles [] = { \ + { false, "ref", "referenced anyhow" }, \ + } + +CXX_COMMON_UNKNOWN_ROLES(C); +CXX_COMMON_UNKNOWN_ROLES(CXX); +CXX_COMMON_UNKNOWN_ROLES(CUDA); + #define CXX_COMMON_MACRO_ROLES(__langPrefix) \ static roleDefinition __langPrefix##MacroRoles [] = { \ RoleTemplateUndef, \ @@ -60,7 +69,10 @@ CXX_COMMON_HEADER_ROLES(CUDA); { false, 'x', "externvar", "external and forward variable declarations", .syncWith = _syncWith }, \ { false, 'z', "parameter", "function parameters inside function or prototype definitions", .syncWith = _syncWith }, \ { false, 'L', "label", "goto labels", .syncWith = _syncWith }, \ - { false, 'D', "macroparam", "parameters inside macro definitions", .syncWith = _syncWith } + { false, 'D', "macroparam", "parameters inside macro definitions", .syncWith = _syncWith }, \ + { false, 'Y', "unknown", "unknown identifier", \ + .referenceOnly = true, ATTACH_ROLES(_langPrefix##UnknownRoles), .syncWith = _syncWith \ + } static kindDefinition g_aCXXCKinds [] = { /* All other than LANG_AUTO are ignored. @@ -261,7 +273,12 @@ static tagEntryInfo g_oCXXTag; void cxxTagUseTokenAsPartOfDefTag(int iCorkIndex, CXXToken * pToken) { - Assert (pToken->iCorkIndex == CORK_NIL); + if (pToken->iCorkIndex != CORK_NIL) + { + Assert(pToken->bCorkIndexForReftag); + pToken->bCorkIndexForReftag = false; + markCorkEntryAsPlaceholder(pToken->iCorkIndex, true); + } pToken->iCorkIndex = iCorkIndex; } @@ -309,6 +326,7 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken) return NULL; } + cxxTagUseTokenAsPartOfDefTag(CORK_NIL, pToken); initTagEntry( &g_oCXXTag, vStringValue(pToken->pszWord), @@ -577,6 +595,7 @@ CXXToken * cxxTagCheckAndSetTypeField( cxxTokenChainNormalizeTypeNameSpacingInRange(pTypeStart,pTypeEnd); CXXToken * pTypeName = cxxTokenChainExtractRangeFilterTypeName(pTypeStart,pTypeEnd); + /* TODO */ if(!pTypeName) { diff --git a/parsers/cxx/cxx_tag.h b/parsers/cxx/cxx_tag.h index 64e78bdd33..cf98502557 100644 --- a/parsers/cxx/cxx_tag.h +++ b/parsers/cxx/cxx_tag.h @@ -35,10 +35,16 @@ enum CXXTagCommonKind CXXTagKindPARAMETER, CXXTagKindLABEL, CXXTagKindMACROPARAM, + CXXTagKindUNKNOWN, CXXTagCommonKindCount }; +enum CXXTagUnknownRole +{ + CXXTagUnknownRoleREFERENCED, +}; + // Tags specific to the CPP language. enum CXXTagCPPKind { @@ -212,6 +218,8 @@ typedef enum { void cxxTagInitForLanguage(langType eLangType); // Functions for filling iCorkIndex field of tokens. +// With specifying CORK_NIL, you can use these functions +// just for preventing emitting reference tags associated with the token(s). void cxxTagUseTokensInRangeAsPartOfDefTags(int iCorkIndex, CXXToken * pFrom, CXXToken * pTo); void cxxTagUseTokenAsPartOfDefTag(int iCorkIndex, CXXToken * pToken); #endif //!_cxxTag_h_ diff --git a/parsers/cxx/cxx_token.c b/parsers/cxx/cxx_token.c index 8aa47b7792..c28403c40a 100644 --- a/parsers/cxx/cxx_token.c +++ b/parsers/cxx/cxx_token.c @@ -32,6 +32,7 @@ static CXXToken *createToken(void *createArg CTAGS_ATTR_UNUSED) // is being reused..well.. we always want it t->pszWord = vStringNew(); t->iCorkIndex = CORK_NIL; + t->bCorkIndexForReftag = false; return t; } @@ -56,6 +57,7 @@ static void clearToken(CXXToken *t) t->pPrev = NULL; t->iCorkIndex = CORK_NIL; + t->bCorkIndexForReftag = false; } void cxxTokenAPIInit(void) @@ -123,6 +125,7 @@ CXXToken * cxxTokenCopy(CXXToken * pToken) pRetToken->bFollowedBySpace = pToken->bFollowedBySpace; vStringCat(pRetToken->pszWord,pToken->pszWord); pRetToken->iCorkIndex = pToken->iCorkIndex; + pRetToken->bCorkIndexForReftag = pToken->bCorkIndexForReftag; return pRetToken; } diff --git a/parsers/cxx/cxx_token.h b/parsers/cxx/cxx_token.h index 573e64b6a1..82c7ea00c2 100644 --- a/parsers/cxx/cxx_token.h +++ b/parsers/cxx/cxx_token.h @@ -74,6 +74,7 @@ typedef struct _CXXToken CXXKeyword eKeyword; CXXTokenChain * pChain; // this is NOT the parent chain! unsigned int bFollowedBySpace: 1; + unsigned int bCorkIndexForReftag: 1; // iCorkIndex specifies a reference tag? int iLineNumber; MIOPos oFilePosition; @@ -88,6 +89,13 @@ typedef struct _CXXToken unsigned char uInternalScopeType; unsigned char uInternalScopeAccess; + // When reading an identifier, the parser makes a reference tag + // for it. The cork index for the tag is set to this member. + // When the parser recognizes the identifier is part of a definition, + // the parser invalidate the reference tag with + // cxxTagUseTokensInRangeAsPartOfDefTags() or + // cxxTagUseTokenAsPartOfDefTag(). These two functions may + // set the index for definition tag. int iCorkIndex; } CXXToken; diff --git a/parsers/cxx/cxx_token_chain.c b/parsers/cxx/cxx_token_chain.c index dbeaaf0dda..481beb5b9d 100644 --- a/parsers/cxx/cxx_token_chain.c +++ b/parsers/cxx/cxx_token_chain.c @@ -488,6 +488,7 @@ CXXTokenChain * cxxTokenChainSplitOnComma(CXXTokenChain * tc) pToken = pToken->pNext; pNew = cxxTokenChainExtractRange(pStart,pToken,0); + /* TODO */ pToken = pToken->pNext; // comma or nothing } if(pNew) @@ -502,6 +503,7 @@ CXXTokenChain * cxxTokenChainSplitOnComma(CXXTokenChain * tc) { // finished without comma CXXToken * pNew = cxxTokenChainExtractRange(pStart,cxxTokenChainLast(tc),0); + /* TODO */ if(pNew) cxxTokenChainAppend(pRet,pNew); } diff --git a/source.mak b/source.mak index f131acedbe..42401e8938 100644 --- a/source.mak +++ b/source.mak @@ -277,6 +277,7 @@ PARSER_HEADS = \ parsers/cxx/cxx_keyword.h \ parsers/cxx/cxx_parser_internal.h \ parsers/cxx/cxx_parser.h \ + parsers/cxx/cxx_reftag.h \ parsers/cxx/cxx_scope.h \ parsers/cxx/cxx_subparser.h \ parsers/cxx/cxx_subparser_internal.h \ @@ -335,6 +336,7 @@ PARSER_SRCS = \ parsers/cxx/cxx_parser_using.c \ parsers/cxx/cxx_parser_variable.c \ parsers/cxx/cxx_qtmoc.c \ + parsers/cxx/cxx_reftag.c \ parsers/cxx/cxx_scope.c \ parsers/cxx/cxx_subparser.c \ parsers/cxx/cxx_tag.c \ diff --git a/win32/ctags_vs2013.vcxproj b/win32/ctags_vs2013.vcxproj index 1f54833b6e..574a57038d 100644 --- a/win32/ctags_vs2013.vcxproj +++ b/win32/ctags_vs2013.vcxproj @@ -290,6 +290,7 @@ + @@ -450,6 +451,7 @@ + diff --git a/win32/ctags_vs2013.vcxproj.filters b/win32/ctags_vs2013.vcxproj.filters index 0682c7be27..db7a37fe59 100644 --- a/win32/ctags_vs2013.vcxproj.filters +++ b/win32/ctags_vs2013.vcxproj.filters @@ -393,6 +393,9 @@ Source Files\parsers\cxx + + Source Files\parsers\cxx + Source Files\parsers\cxx @@ -869,6 +872,9 @@ Header Files + + Header Files + Header Files From 834cfca444777009d33238a0f09639a57f6652a5 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Thu, 1 Dec 2022 14:07:53 +0900 Subject: [PATCH 2/7] Cxx: fill scope fields of unknown/ref tags Signed-off-by: Masatake YAMATO --- .../c-reftags-unknown-ref.d/expected.tags | 10 ++--- .../simple-qt-reftag.d/expected.tags | 40 +++++++++---------- parsers/cxx/cxx_reftag.c | 9 +++-- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags b/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags index c8e291bbda..78de11b7fb 100644 --- a/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags +++ b/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags @@ -6,8 +6,8 @@ B input.c /^ A, B$/;" e enum:X file: roles:def i input.c /^extern int i;$/;" x typeref:typename:int roles:def f input.c /^int f(int j)$/;" f typeref:typename:int roles:def j input.c /^int f(int j)$/;" z function:f typeref:typename:int file: roles:def -j input.c /^ if (j == 0)$/;" Y roles:ref -i input.c /^ return i + B + j + f(0);$/;" Y roles:ref -B input.c /^ return i + B + j + f(0);$/;" Y roles:ref -j input.c /^ return i + B + j + f(0);$/;" Y roles:ref -f input.c /^ return i + B + j + f(0);$/;" Y roles:ref +j input.c /^ if (j == 0)$/;" Y function:f roles:ref +i input.c /^ return i + B + j + f(0);$/;" Y function:f roles:ref +B input.c /^ return i + B + j + f(0);$/;" Y function:f roles:ref +j input.c /^ return i + B + j + f(0);$/;" Y function:f roles:ref +f input.c /^ return i + B + j + f(0);$/;" Y function:f roles:ref diff --git a/Units/parser-qtmoc.r/simple-qt-reftag.d/expected.tags b/Units/parser-qtmoc.r/simple-qt-reftag.d/expected.tags index 6771222eac..680d452404 100644 --- a/Units/parser-qtmoc.r/simple-qt-reftag.d/expected.tags +++ b/Units/parser-qtmoc.r/simple-qt-reftag.d/expected.tags @@ -1,65 +1,65 @@ QFrame input.h /^class ColumnPreferencesFrame : public QFrame$/;" unknown language:C++ ColumnPreferencesFrame input.h /^class ColumnPreferencesFrame : public QFrame$/;" class language:C++ -Q_OBJECT input.h /^ Q_OBJECT$/;" unknown language:C++ +Q_OBJECT input.h /^ Q_OBJECT$/;" unknown language:C++ class:ColumnPreferencesFrame method0 input.h /^ void method0(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void -slots input.h /^private slots:$/;" unknown language:C++ +slots input.h /^private slots:$/;" unknown language:C++ class:ColumnPreferencesFrame slot0 input.h /^ void slot0(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot0 input.h /^ void slot0(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void slot1 input.h /^ void slot1(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot1 input.h /^ void slot1(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void -slots input.h /^public slots:$/;" unknown language:C++ +slots input.h /^public slots:$/;" unknown language:C++ class:ColumnPreferencesFrame slot2 input.h /^ void slot2(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot2 input.h /^ void slot2(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void slot3 input.h /^ void slot3(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot3 input.h /^ void slot3(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void -Q_SLOTS input.h /^Q_SLOTS:$/;" unknown language:C++ +Q_SLOTS input.h /^Q_SLOTS:$/;" unknown language:C++ class:ColumnPreferencesFrame slot4 input.h /^ void slot4(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot4 input.h /^ void slot4(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void slot5 input.h /^ void slot5(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot5 input.h /^ void slot5(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void field0 input.h /^ int field0;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int method1 input.h /^ virtual void method1(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void -Q_SLOTS input.h /^private Q_SLOTS:$/;" unknown language:C++ +Q_SLOTS input.h /^private Q_SLOTS:$/;" unknown language:C++ class:ColumnPreferencesFrame slot6 input.h /^ void slot6(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot6 input.h /^ void slot6(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void slot7 input.h /^ void slot7(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot7 input.h /^ void slot7(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void -Q_SLOTS input.h /^public Q_SLOTS:$/;" unknown language:C++ +Q_SLOTS input.h /^public Q_SLOTS:$/;" unknown language:C++ class:ColumnPreferencesFrame slot8 input.h /^ void slot8(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot8 input.h /^ void slot8(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void slot9 input.h /^ void slot9(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot9 input.h /^ void slot9(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void -slots input.h /^slots:$/;" unknown language:C++ +slots input.h /^slots:$/;" unknown language:C++ class:ColumnPreferencesFrame slot10 input.h /^ void slot10(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot10 input.h /^ void slot10(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void slot11 input.h /^ void slot11(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void slot11 input.h /^ void slot11(void);$/;" slot language:QtMoc class:ColumnPreferencesFrame typeref:typename:void field1 input.h /^ int field1;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int -signals input.h /^signals:$/;" unknown language:C++ +signals input.h /^signals:$/;" unknown language:C++ class:ColumnPreferencesFrame signal0 input.h /^ void signal0(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void signal0 input.h /^ void signal0(void);$/;" signal language:QtMoc class:ColumnPreferencesFrame typeref:typename:void signal1 input.h /^ void signal1(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void signal1 input.h /^ void signal1(void);$/;" signal language:QtMoc class:ColumnPreferencesFrame typeref:typename:void field2 input.h /^ int field2;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int method2 input.h /^ virtual void method2(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void -Q_SIGNALS input.h /^Q_SIGNALS:$/;" unknown language:C++ +Q_SIGNALS input.h /^Q_SIGNALS:$/;" unknown language:C++ class:ColumnPreferencesFrame signal2 input.h /^ void signal2(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void signal2 input.h /^ void signal2(void);$/;" signal language:QtMoc class:ColumnPreferencesFrame typeref:typename:void signal3 input.h /^ void signal3(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void signal3 input.h /^ void signal3(void);$/;" signal language:QtMoc class:ColumnPreferencesFrame typeref:typename:void field3 input.h /^ int field3;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int method3 input.h /^ virtual void method3(void);$/;" prototype language:C++ class:ColumnPreferencesFrame typeref:typename:void -Q_PROPERTY input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ -QString input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ +Q_PROPERTY input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ class:ColumnPreferencesFrame +QString input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ class:ColumnPreferencesFrame text input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" property language:QtMoc class:ColumnPreferencesFrame typeref:typename:QString -MEMBER input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ -m_text input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ -NOTIFY input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ -textChanged input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ -Q_PROPERTY input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ +MEMBER input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ class:ColumnPreferencesFrame +m_text input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ class:ColumnPreferencesFrame +NOTIFY input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ class:ColumnPreferencesFrame +textChanged input.h /^ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)$/;" unknown language:C++ class:ColumnPreferencesFrame +Q_PROPERTY input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ class:ColumnPreferencesFrame ShowNonprinting input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" property language:QtMoc class:ColumnPreferencesFrame typeref:typename:bool -READ input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ -showsNonprinting input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ -WRITE input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ -setShowsNonprinting input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ +READ input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ class:ColumnPreferencesFrame +showsNonprinting input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ class:ColumnPreferencesFrame +WRITE input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ class:ColumnPreferencesFrame +setShowsNonprinting input.h /^ Q_PROPERTY( bool ShowNonprinting READ showsNonprinting WRITE setShowsNonprinting )$/;" unknown language:C++ class:ColumnPreferencesFrame field4 input.h /^ int field4;$/;" member language:C++ class:ColumnPreferencesFrame typeref:typename:int diff --git a/parsers/cxx/cxx_reftag.c b/parsers/cxx/cxx_reftag.c index f7e134de56..e819a2bccc 100644 --- a/parsers/cxx/cxx_reftag.c +++ b/parsers/cxx/cxx_reftag.c @@ -11,6 +11,7 @@ #include "cxx_token.h" #include "cxx_parser_internal.h" +#include "cxx_scope.h" #include "read.h" @@ -29,9 +30,11 @@ void cxxReftagEvalNewToken(void) if (in_subparser) pushLanguage(g_cxx.eLangType); - g_cxx.pToken->iCorkIndex = makeSimpleRefTag(g_cxx.pToken->pszWord, - CXXTagKindUNKNOWN, - CXXTagUnknownRoleREFERENCED); + tagEntryInfo oEntry; + initRefTagEntry(&oEntry, vStringValue(g_cxx.pToken->pszWord), + CXXTagKindUNKNOWN, CXXTagUnknownRoleREFERENCED); + oEntry.extensionFields.scopeIndex = cxxScopeGetDefTag(); + g_cxx.pToken->iCorkIndex = makeTagEntry(&oEntry); g_cxx.pToken->bCorkIndexForReftag = true; if (in_subparser) From 81b9bad4610da4d906599cf8edf9119314b4f4dc Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 4 Dec 2022 01:04:27 +0900 Subject: [PATCH 3/7] Cxx: add a helper function for resetting kind, role, and scope Signed-off-by: Masatake YAMATO --- parsers/cxx/cxx_reftag.c | 20 ++++++++++++++++++++ parsers/cxx/cxx_reftag.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/parsers/cxx/cxx_reftag.c b/parsers/cxx/cxx_reftag.c index e819a2bccc..2f4e5682e9 100644 --- a/parsers/cxx/cxx_reftag.c +++ b/parsers/cxx/cxx_reftag.c @@ -41,3 +41,23 @@ void cxxReftagEvalNewToken(void) popLanguage(); } } + +void cxxReftagReset(int iCorkIndex, int iScopeCorkIndex, + int iKindIndex, int iRoleIndex, bool bUpdateScope) +{ + tagEntryInfo *pEntry = getEntryInCorkQueue(iCorkIndex); + if(pEntry == NULL) + return; + if (pEntry->placeholder) + return; + + clearRoles(pEntry); + if(bUpdateScope && pEntry->extensionFields.scopeIndex != CORK_NIL) + unregisterEntry(iCorkIndex); + if (bUpdateScope) + pEntry->extensionFields.scopeIndex = iScopeCorkIndex; + pEntry->kindIndex = iKindIndex; + assignRole(pEntry, iRoleIndex); + if (bUpdateScope) + registerEntry(iCorkIndex); +} diff --git a/parsers/cxx/cxx_reftag.h b/parsers/cxx/cxx_reftag.h index 7a03751d63..411b763cb7 100644 --- a/parsers/cxx/cxx_reftag.h +++ b/parsers/cxx/cxx_reftag.h @@ -12,4 +12,10 @@ #include "general.h" void cxxReftagEvalNewToken(void); + +// Reset the kind and role of the tag specified with iCorkIndex. +// The scope of the tag is also updated with iScopeCorkIndex. +void cxxReftagReset(int iCorkIndex, int iScopeCorkIndex, + int iKindIndex, int iRoleIndex, bool bUpdateValue); + #endif //!_cxxReftag_h_ From 992c772330ba7c900b01621f2936aa03a64877b0 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 4 Dec 2022 01:05:57 +0900 Subject: [PATCH 4/7] Cxx: add "initialized" role to "member" kind struct opt file_ops { .read = file_read, .write = file_write, }; The parser extracts "read" and "write" with "initialized" role of "member" kind. Signed-off-by: Masatake YAMATO --- .../stdout-expected.txt | 2 + .../json-output-format.d/stdout-expected.txt | 1 + Tmain/list-kinds-full.d/stdout-expected.txt | 4 +- Tmain/list-roles.d/stdout-expected.txt | 331 ++++++++++-------- Tmain/nested-subparsers.d/stdout-expected.txt | 2 +- Units/parser-c.r/c-reftag-member.d/args.ctags | 5 + .../c-reftag-member.d/expected.tags | 3 + Units/parser-c.r/c-reftag-member.d/input.c | 4 + parsers/cxx/cxx_parser_variable.c | 70 ++++ parsers/cxx/cxx_tag.c | 13 +- parsers/cxx/cxx_tag.h | 5 + 11 files changed, 286 insertions(+), 154 deletions(-) create mode 100644 Units/parser-c.r/c-reftag-member.d/args.ctags create mode 100644 Units/parser-c.r/c-reftag-member.d/expected.tags create mode 100644 Units/parser-c.r/c-reftag-member.d/input.c diff --git a/Tmain/extras-field-for-pseudo-tags.d/stdout-expected.txt b/Tmain/extras-field-for-pseudo-tags.d/stdout-expected.txt index 862fa41775..fb208e6da7 100644 --- a/Tmain/extras-field-for-pseudo-tags.d/stdout-expected.txt +++ b/Tmain/extras-field-for-pseudo-tags.d/stdout-expected.txt @@ -26,6 +26,7 @@ !_TAG_ROLE_DESCRIPTION!C!header local /local header/ !_TAG_ROLE_DESCRIPTION!C!header system /system header/ !_TAG_ROLE_DESCRIPTION!C!macro undef /undefined/ +!_TAG_ROLE_DESCRIPTION!C!member initialized /initialized with form '.member = ...'/ main input.c /^int main (void) { return 0; }$/ # option: --format=2 !_TAG_EXTRA_DESCRIPTION pseudo /Include pseudo tags/;" extras:pseudo @@ -55,4 +56,5 @@ main input.c /^int main (void) { return 0; }$/ !_TAG_ROLE_DESCRIPTION!C!header local /local header/;" extras:pseudo !_TAG_ROLE_DESCRIPTION!C!header system /system header/;" extras:pseudo !_TAG_ROLE_DESCRIPTION!C!macro undef /undefined/;" extras:pseudo +!_TAG_ROLE_DESCRIPTION!C!member initialized /initialized with form '.member = ...'/;" extras:pseudo main input.c /^int main (void) { return 0; }$/ diff --git a/Tmain/json-output-format.d/stdout-expected.txt b/Tmain/json-output-format.d/stdout-expected.txt index 597ebe69c2..c271ce7356 100644 --- a/Tmain/json-output-format.d/stdout-expected.txt +++ b/Tmain/json-output-format.d/stdout-expected.txt @@ -93,6 +93,7 @@ {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C", "kindName": "header", "path": "local", "pattern": "local header"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C", "kindName": "header", "path": "system", "pattern": "system header"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C", "kindName": "macro", "path": "undef", "pattern": "undefined"} +{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C", "kindName": "member", "path": "initialized", "pattern": "initialized with form '.member = ...'"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Go", "kindName": "package", "path": "imported", "pattern": "imported package"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Go", "kindName": "unknown", "path": "receiverType", "pattern": "receiver type"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python", "kindName": "module", "path": "imported", "pattern": "imported modules"} diff --git a/Tmain/list-kinds-full.d/stdout-expected.txt b/Tmain/list-kinds-full.d/stdout-expected.txt index fac0644876..a4a8e3829a 100644 --- a/Tmain/list-kinds-full.d/stdout-expected.txt +++ b/Tmain/list-kinds-full.d/stdout-expected.txt @@ -8,7 +8,7 @@ f function yes no 0 C function definitions g enum yes no 0 C enumeration names h header yes yes 2 C included header files l local no no 0 C local variables -m member yes no 0 C struct, and union members +m member yes no 1 C struct, and union members p prototype no no 0 C function prototypes s struct yes no 0 C structure names t typedef yes no 0 C typedefs @@ -31,7 +31,7 @@ f function yes no 0 C function definitions g enum yes no 0 C enumeration names h header yes yes 2 C included header files l local no no 0 C local variables -m member yes no 0 C class, struct, and union members +m member yes no 1 C class, struct, and union members n namespace yes no 0 NONE namespaces p prototype no no 0 C function prototypes s struct yes no 0 C structure names diff --git a/Tmain/list-roles.d/stdout-expected.txt b/Tmain/list-roles.d/stdout-expected.txt index c3b6655396..cf0c2f7c55 100644 --- a/Tmain/list-roles.d/stdout-expected.txt +++ b/Tmain/list-roles.d/stdout-expected.txt @@ -23,11 +23,13 @@ C d/macro condition off used in part of #if/ C d/macro undef on undefined C h/header local on local header C h/header system on system header +C m/member initialized on initialized with form '.member = ...' C++ Y/unknown ref off referenced anyhow C++ d/macro condition off used in part of #if/#ifdef/#elif conditions C++ d/macro undef on undefined C++ h/header local on local header C++ h/header system on system header +C++ m/member initialized on initialized with form '.member = ...' CPreProcessor d/macro condition off used in part of #if/#ifdef/#elif conditions CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header @@ -37,6 +39,7 @@ CUDA d/macro condition off used in part of #if/ CUDA d/macro undef on undefined CUDA h/header local on local header CUDA h/header system on system header +CUDA m/member initialized on initialized with form '.member = ...' Cobol S/sourcefile copied on copied in source file CobolFree S/sourcefile copied on copied in source file CobolVariable S/sourcefile copied on copied in source file @@ -146,11 +149,13 @@ C d/macro condition off used in part of #if/ C d/macro undef on undefined C h/header local on local header C h/header system on system header +C m/member initialized on initialized with form '.member = ...' C++ Y/unknown ref off referenced anyhow C++ d/macro condition off used in part of #if/#ifdef/#elif conditions C++ d/macro undef on undefined C++ h/header local on local header C++ h/header system on system header +C++ m/member initialized on initialized with form '.member = ...' CPreProcessor d/macro condition off used in part of #if/#ifdef/#elif conditions CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header @@ -160,6 +165,7 @@ CUDA d/macro condition off used in part of #if/ CUDA d/macro undef on undefined CUDA h/header local on local header CUDA h/header system on system header +CUDA m/member initialized on initialized with form '.member = ...' Cobol S/sourcefile copied on copied in source file CobolFree S/sourcefile copied on copied in source file CobolVariable S/sourcefile copied on copied in source file @@ -248,12 +254,13 @@ Zsh s/script loaded on loaded # # C.* # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # all.d @@ -286,54 +293,59 @@ s/script loaded on loaded # # C.* with disabling all roles of all languages # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local off local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local off local header +h/header system off system header +m/member initialized off initialized with form '.member = ...' # # C.* with disabling all roles of all kinds of all languages # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local off local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local off local header +h/header system off system header +m/member initialized off initialized with form '.member = ...' # # C.* with enabling all roles of all kinds in all languages # after disabling system role of header kind of C language # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref on referenced anyhow -d/macro condition on used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref on referenced anyhow +d/macro condition on used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # C.* with enabling all roles in all languages # after disabling system role of header kind of C language # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref on referenced anyhow -d/macro condition on used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref on referenced anyhow +d/macro condition on used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # C.* with disabling all roles in C language # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local off local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local off local header +h/header system off system header +m/member initialized off initialized with form '.member = ...' # # Sh.* with disabling all roles in C language @@ -345,12 +357,13 @@ s/script loaded on loaded # # C.* with disabling all roles of all kinds in C language # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local off local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local off local header +h/header system off system header +m/member initialized off initialized with form '.member = ...' # # Sh.* with disabling all roles of all kinds in C language @@ -363,12 +376,13 @@ s/script loaded on loaded # C.* with enabling all roles in C language # after disabling all roles in all languages # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref on referenced anyhow -d/macro condition on used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref on referenced anyhow +d/macro condition on used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # Sh.* with enabling all roles in C language @@ -382,12 +396,13 @@ s/script loaded off loaded # C.* with enabling all roles of all kinds in C language # after disabling all roles in all languages # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref on referenced anyhow -d/macro condition on used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref on referenced anyhow +d/macro condition on used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # Sh.* with enabling all roles of all kinds in C language @@ -400,12 +415,13 @@ s/script loaded off loaded # # C.* with disabling all roles of {header} kind in C language # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local off local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local off local header +h/header system off system header +m/member initialized on initialized with form '.member = ...' # # Sh.* with disabling all roles of {header} kind in C language @@ -417,12 +433,13 @@ s/script loaded on loaded # # C.* with disabling all roles of h kind in C language # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local off local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local off local header +h/header system off system header +m/member initialized on initialized with form '.member = ...' # # Sh.* with disabling all roles of h kind in C language @@ -435,12 +452,13 @@ s/script loaded on loaded # C.* with enabling all roles of {header} kind in C language # after disabling all roles in all languages # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local on local header +h/header system on system header +m/member initialized off initialized with form '.member = ...' # # Sh.* with enabling all roles of {header} kind in C language @@ -454,12 +472,13 @@ s/script loaded off loaded # C.* with enabling all roles of h kind in C language # after disabling all roles in all languages # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local on local header +h/header system on system header +m/member initialized off initialized with form '.member = ...' # # Sh.* with enabling all roles of h kind in C language @@ -472,121 +491,133 @@ s/script loaded off loaded # # C.* with disabling system role of h kind # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system off system header +m/member initialized on initialized with form '.member = ...' # # C.* with disabling system role of {header} kind # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system off system header +m/member initialized on initialized with form '.member = ...' # # C.* with enabling system role of h kind after disabling the role # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # C.* with enabling system role of {header} kind after disabling the role # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # C.* with disabling system and local roles of h kind # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local off local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local off local header +h/header system off system header +m/member initialized on initialized with form '.member = ...' # # C.* with disabling system and local roles of {header} kind # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local off local header -h/header system off system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local off local header +h/header system off system header +m/member initialized on initialized with form '.member = ...' # # C.* with enabling system and local roles of h kind # after disabling all roles in all languages # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local on local header +h/header system on system header +m/member initialized off initialized with form '.member = ...' # # C.* with enabling system and local roles of {header} kind # after disabling all roles in all languages # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local on local header +h/header system on system header +m/member initialized off initialized with form '.member = ...' # # C.* with disabling local role of h kind and undef role of d kind # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local off local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local off local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # C.* with enabling all roles of header kinds after disabling all roles of the kind # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef on undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef on undefined +h/header local on local header +h/header system on system header +m/member initialized on initialized with form '.member = ...' # # C.* with enabling all roles of header kinds after disabling all roles of the kinds of C language # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local on local header +h/header system on system header +m/member initialized off initialized with form '.member = ...' # # C.* with enabling all roles of header kinds after disabling all roles of the kinds of C language (short notation) # -#KIND(L/N) NAME ENABLED DESCRIPTION -Y/unknown ref off referenced anyhow -d/macro condition off used in part of #if/#ifdef/#elif conditions -d/macro undef off undefined -h/header local on local header -h/header system on system header +#KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown ref off referenced anyhow +d/macro condition off used in part of #if/#ifdef/#elif conditions +d/macro undef off undefined +h/header local on local header +h/header system on system header +m/member initialized off initialized with form '.member = ...' diff --git a/Tmain/nested-subparsers.d/stdout-expected.txt b/Tmain/nested-subparsers.d/stdout-expected.txt index 4435e5857b..ee476ead3b 100644 --- a/Tmain/nested-subparsers.d/stdout-expected.txt +++ b/Tmain/nested-subparsers.d/stdout-expected.txt @@ -44,7 +44,7 @@ f function yes no 0 C function definitions g enum yes no 0 C enumeration names h header yes yes 2 C included header files l local no no 0 C local variables -m member yes no 0 C struct, and union members +m member yes no 1 C struct, and union members p prototype no no 0 C function prototypes s struct yes no 0 C structure names t typedef yes no 0 C typedefs diff --git a/Units/parser-c.r/c-reftag-member.d/args.ctags b/Units/parser-c.r/c-reftag-member.d/args.ctags new file mode 100644 index 0000000000..819501e374 --- /dev/null +++ b/Units/parser-c.r/c-reftag-member.d/args.ctags @@ -0,0 +1,5 @@ +--sort=no +--extras=+r +--fields=+rKZ +--kinds-C=* +--roles-C.{member}=* diff --git a/Units/parser-c.r/c-reftag-member.d/expected.tags b/Units/parser-c.r/c-reftag-member.d/expected.tags new file mode 100644 index 0000000000..baa5cd547a --- /dev/null +++ b/Units/parser-c.r/c-reftag-member.d/expected.tags @@ -0,0 +1,3 @@ +file_ops input.c /^static struct ops file_ops = {$/;" variable typeref:struct:ops file: roles:def +read input.c /^ .read = file_read_fn,$/;" member scope:variable:file_ops roles:initialized +write input.c /^ .write = file_write_fn,$/;" member scope:variable:file_ops roles:initialized diff --git a/Units/parser-c.r/c-reftag-member.d/input.c b/Units/parser-c.r/c-reftag-member.d/input.c new file mode 100644 index 0000000000..e49292cadc --- /dev/null +++ b/Units/parser-c.r/c-reftag-member.d/input.c @@ -0,0 +1,4 @@ +static struct ops file_ops = { + .read = file_read_fn, + .write = file_write_fn, +}; diff --git a/parsers/cxx/cxx_parser_variable.c b/parsers/cxx/cxx_parser_variable.c index a71702e2b9..2d7f3dc932 100644 --- a/parsers/cxx/cxx_parser_variable.c +++ b/parsers/cxx/cxx_parser_variable.c @@ -14,6 +14,7 @@ #include "cxx_token.h" #include "cxx_token_chain.h" #include "cxx_scope.h" +#include "cxx_reftag.h" #include "vstring.h" #include "read.h" @@ -67,6 +68,62 @@ CXXToken * cxxParserFindFirstPossiblyNestedAndQualifiedIdentifier( return cxxTokenChainNextTokenOfType(pId,CXXTokenTypeIdentifier); } +static void cxxParserExtractMembersInitialization(CXXTokenChain * pChain, int iScopeCorkIndex) +{ + tagEntryInfo *pTag = getEntryInCorkQueue(iScopeCorkIndex); + if(!pTag || pTag->kindIndex != CXXTagKindVARIABLE) + return; + + // Looking for the pattern: + // + // { .member = ... + // + // or + // + // ; .member = ... + // + for (CXXToken *t = cxxTokenChainFirst(pChain); t && t != pChain->pTail; t = t->pNext) + { + if( + (cxxTokenTypeIs(t, CXXTokenTypeOpeningBracket) + || cxxTokenTypeIs(t, CXXTokenTypeComma)) && + (t->pNext + && cxxTokenTypeIs(t->pNext, CXXTokenTypeDotOperator)) && + (t->pNext->pNext + && cxxTokenTypeIs(t->pNext->pNext, CXXTokenTypeIdentifier)) && + (t->pNext->pNext->pNext + && cxxTokenTypeIs(t->pNext->pNext->pNext, CXXTokenTypeAssignment)) + ) + { + CXXToken *pIdentifier = t->pNext->pNext; + if(pIdentifier->iCorkIndex != CORK_NIL && pIdentifier->bCorkIndexForReftag) + { + // Tagged with "unknown" kind already. Reset it. + cxxReftagReset(pIdentifier->iCorkIndex, iScopeCorkIndex, + CXXTagKindMEMBER, CXXTagMemberRoleINITIALIZED, true); + } + else if(pIdentifier->iCorkIndex == CORK_NIL) + { + tagEntryInfo oEntry; + initRefTagEntry(&oEntry, vStringValue(pIdentifier->pszWord), + CXXTagKindMEMBER, CXXTagMemberRoleINITIALIZED); + oEntry.lineNumber = pIdentifier->iLineNumber; + oEntry.filePosition = pIdentifier->oFilePosition; + oEntry.isFileScope = false; + // TODO: Other scope field must be filled. + oEntry.extensionFields.scopeIndex = iScopeCorkIndex; + pIdentifier->iCorkIndex = makeTagEntry(&oEntry); + registerEntry(pIdentifier->iCorkIndex); + pIdentifier->bCorkIndexForReftag = 1; + + } + // Point t to the assignment. + t = t->pNext->pNext->pNext; + } + } + return; +} + // // Attempt to extract variable declarations from the chain. // Returns true if at least one variable was extracted. @@ -817,11 +874,18 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF return bGotVariable; } + // pointing {} of ... = {} + CXXToken * pTokenBracketChain = NULL; if(!cxxTokenTypeIsOneOf( t, CXXTokenTypeComma | CXXTokenTypeSemicolon | CXXTokenTypeOpeningBracket )) { + if(iCorkIndex != CORK_NIL && + cxxTokenTypeIs(t, CXXTokenTypeAssignment) && + t->pNext && cxxTokenTypeIs(t->pNext, CXXTokenTypeBracketChain) && + t->pNext->pChain) + pTokenBracketChain = t->pNext; // look for it, but also check for "<" signs: these usually indicate an uncondensed // template. We give up on them as they are too complicated in this context. // It's rather unlikely to have multiple declarations with templates after the first one @@ -846,6 +910,9 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF { if (iCorkIndex != CORK_NIL) { + if(pTokenBracketChain) + cxxParserExtractMembersInitialization(pTokenBracketChain->pChain, + iCorkIndex); cxxParserSetEndLineForTagInCorkQueue (iCorkIndex, t->iLineNumber); iCorkIndex = CORK_NIL; if(iCorkIndexFQ != CORK_NIL) @@ -861,6 +928,9 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF // Comma. Might have other declarations here. if (iCorkIndex != CORK_NIL) { + if(pTokenBracketChain) + cxxParserExtractMembersInitialization(pTokenBracketChain->pChain, + iCorkIndex); cxxParserSetEndLineForTagInCorkQueue (iCorkIndex, t->iLineNumber); iCorkIndex = CORK_NIL; if(iCorkIndexFQ != CORK_NIL) diff --git a/parsers/cxx/cxx_tag.c b/parsers/cxx/cxx_tag.c index 718cfc46c4..054cce1dbc 100644 --- a/parsers/cxx/cxx_tag.c +++ b/parsers/cxx/cxx_tag.c @@ -28,6 +28,15 @@ CXX_COMMON_UNKNOWN_ROLES(C); CXX_COMMON_UNKNOWN_ROLES(CXX); CXX_COMMON_UNKNOWN_ROLES(CUDA); +#define CXX_COMMON_MEMBER_ROLES(__langPrefix) \ + static roleDefinition __langPrefix##MemberRoles [] = { \ + { true, "initialized", "initialized with form '.member = ...'" }, \ + } + +CXX_COMMON_MEMBER_ROLES(C); +CXX_COMMON_MEMBER_ROLES(CXX); +CXX_COMMON_MEMBER_ROLES(CUDA); + #define CXX_COMMON_MACRO_ROLES(__langPrefix) \ static roleDefinition __langPrefix##MacroRoles [] = { \ RoleTemplateUndef, \ @@ -60,7 +69,9 @@ CXX_COMMON_HEADER_ROLES(CUDA); .referenceOnly = true, ATTACH_ROLES(_langPrefix##HeaderRoles), .syncWith = _syncWith \ }, \ { false, 'l', "local", "local variables", .syncWith = _syncWith }, \ - { true, 'm', "member", _szMemberDescription, .syncWith = _syncWith }, \ + { true, 'm', "member", _szMemberDescription, .syncWith = _syncWith, \ + .referenceOnly = false, ATTACH_ROLES(_langPrefix##MemberRoles), .syncWith = _syncWith \ + },\ { false, 'p', "prototype", "function prototypes", .syncWith = _syncWith }, \ { true, 's', "struct", "structure names", .syncWith = _syncWith }, \ { true, 't', "typedef", "typedefs", .syncWith = _syncWith }, \ diff --git a/parsers/cxx/cxx_tag.h b/parsers/cxx/cxx_tag.h index cf98502557..6ac34edaf5 100644 --- a/parsers/cxx/cxx_tag.h +++ b/parsers/cxx/cxx_tag.h @@ -45,6 +45,11 @@ enum CXXTagUnknownRole CXXTagUnknownRoleREFERENCED, }; +enum CXXTagMemberRole +{ + CXXTagMemberRoleINITIALIZED, +}; + // Tags specific to the CPP language. enum CXXTagCPPKind { From 51e317e6b6425dc3fd17ef8401bf134daea89d44 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 4 Dec 2022 02:17:23 +0900 Subject: [PATCH 5/7] Cxx: add "value" role to "unknown" kind struct opt file_ops { .read = file_read, .write = file_write, }; The parser with this change extracts "file_read" and "file_write" with "value" role of "unknown" kind. Signed-off-by: Masatake YAMATO --- Tmain/list-kinds-full.d/stdout-expected.txt | 4 +- Tmain/list-roles.d/stdout-expected.txt | 31 +++++++++++++++ Tmain/nested-subparsers.d/stdout-expected.txt | 2 +- Units/parser-c.r/c-reftag-member.d/args.ctags | 1 + .../c-reftag-member.d/expected.tags | 2 + parsers/cxx/cxx_parser_variable.c | 39 +++++++++++++++++++ parsers/cxx/cxx_tag.c | 1 + parsers/cxx/cxx_tag.h | 1 + 8 files changed, 78 insertions(+), 3 deletions(-) diff --git a/Tmain/list-kinds-full.d/stdout-expected.txt b/Tmain/list-kinds-full.d/stdout-expected.txt index a4a8e3829a..d0fb6550ed 100644 --- a/Tmain/list-kinds-full.d/stdout-expected.txt +++ b/Tmain/list-kinds-full.d/stdout-expected.txt @@ -1,7 +1,7 @@ #LETTER NAME ENABLED REFONLY NROLES MASTER DESCRIPTION D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels -Y unknown no yes 1 C unknown identifier +Y unknown no yes 2 C unknown identifier d macro yes no 2 C macro definitions e enumerator yes no 0 C enumerators (values inside an enumeration) f function yes no 0 C function definitions @@ -22,7 +22,7 @@ D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels N name no no 0 NONE names imported via using scope::symbol U using no no 0 NONE using namespace statements -Y unknown no yes 1 C unknown identifier +Y unknown no yes 2 C unknown identifier Z tparam no no 0 NONE template parameters c class yes no 0 NONE classes d macro yes no 2 C macro definitions diff --git a/Tmain/list-roles.d/stdout-expected.txt b/Tmain/list-roles.d/stdout-expected.txt index cf0c2f7c55..a560128cbe 100644 --- a/Tmain/list-roles.d/stdout-expected.txt +++ b/Tmain/list-roles.d/stdout-expected.txt @@ -19,12 +19,14 @@ Automake d/directory script on directory for SCRIPT Basic f/function decl on declared Bats S/script loaded on script loaed with "load" command C Y/unknown ref off referenced anyhow +C Y/unknown value on used as right side value C d/macro condition off used in part of #if/#ifdef/#elif conditions C d/macro undef on undefined C h/header local on local header C h/header system on system header C m/member initialized on initialized with form '.member = ...' C++ Y/unknown ref off referenced anyhow +C++ Y/unknown value on used as right side value C++ d/macro condition off used in part of #if/#ifdef/#elif conditions C++ d/macro undef on undefined C++ h/header local on local header @@ -35,6 +37,7 @@ CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header CPreProcessor h/header system on system header CUDA Y/unknown ref off referenced anyhow +CUDA Y/unknown value on used as right side value CUDA d/macro condition off used in part of #if/#ifdef/#elif conditions CUDA d/macro undef on undefined CUDA h/header local on local header @@ -145,12 +148,14 @@ Automake d/directory script on directory for SCRIPT Basic f/function decl on declared Bats S/script loaded on script loaed with "load" command C Y/unknown ref off referenced anyhow +C Y/unknown value on used as right side value C d/macro condition off used in part of #if/#ifdef/#elif conditions C d/macro undef on undefined C h/header local on local header C h/header system on system header C m/member initialized on initialized with form '.member = ...' C++ Y/unknown ref off referenced anyhow +C++ Y/unknown value on used as right side value C++ d/macro condition off used in part of #if/#ifdef/#elif conditions C++ d/macro undef on undefined C++ h/header local on local header @@ -161,6 +166,7 @@ CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header CPreProcessor h/header system on system header CUDA Y/unknown ref off referenced anyhow +CUDA Y/unknown value on used as right side value CUDA d/macro condition off used in part of #if/#ifdef/#elif conditions CUDA d/macro undef on undefined CUDA h/header local on local header @@ -256,6 +262,7 @@ Zsh s/script loaded on loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -295,6 +302,7 @@ s/script loaded on loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -306,6 +314,7 @@ m/member initialized off initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -318,6 +327,7 @@ m/member initialized off initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref on referenced anyhow +Y/unknown value on used as right side value d/macro condition on used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -330,6 +340,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref on referenced anyhow +Y/unknown value on used as right side value d/macro condition on used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -341,6 +352,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -359,6 +371,7 @@ s/script loaded on loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -378,6 +391,7 @@ s/script loaded on loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref on referenced anyhow +Y/unknown value on used as right side value d/macro condition on used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -398,6 +412,7 @@ s/script loaded off loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref on referenced anyhow +Y/unknown value on used as right side value d/macro condition on used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -417,6 +432,7 @@ s/script loaded off loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local off local header @@ -435,6 +451,7 @@ s/script loaded on loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local off local header @@ -454,6 +471,7 @@ s/script loaded on loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -474,6 +492,7 @@ s/script loaded off loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -493,6 +512,7 @@ s/script loaded off loaded # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -504,6 +524,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -515,6 +536,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -526,6 +548,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -537,6 +560,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local off local header @@ -548,6 +572,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local off local header @@ -560,6 +585,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -572,6 +598,7 @@ m/member initialized off initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -583,6 +610,7 @@ m/member initialized off initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local off local header @@ -594,6 +622,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined h/header local on local header @@ -605,6 +634,7 @@ m/member initialized on initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header @@ -616,6 +646,7 @@ m/member initialized off initialized with form '.member = ...' # #KIND(L/N) NAME ENABLED DESCRIPTION Y/unknown ref off referenced anyhow +Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined h/header local on local header diff --git a/Tmain/nested-subparsers.d/stdout-expected.txt b/Tmain/nested-subparsers.d/stdout-expected.txt index ee476ead3b..d59a8c57b4 100644 --- a/Tmain/nested-subparsers.d/stdout-expected.txt +++ b/Tmain/nested-subparsers.d/stdout-expected.txt @@ -37,7 +37,7 @@ n name #LETTER NAME ENABLED REFONLY NROLES MASTER DESCRIPTION D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels -Y unknown no yes 1 C unknown identifier +Y unknown no yes 2 C unknown identifier d macro yes no 2 C macro definitions e enumerator yes no 0 C enumerators (values inside an enumeration) f function yes no 0 C function definitions diff --git a/Units/parser-c.r/c-reftag-member.d/args.ctags b/Units/parser-c.r/c-reftag-member.d/args.ctags index 819501e374..05d5b6508b 100644 --- a/Units/parser-c.r/c-reftag-member.d/args.ctags +++ b/Units/parser-c.r/c-reftag-member.d/args.ctags @@ -3,3 +3,4 @@ --fields=+rKZ --kinds-C=* --roles-C.{member}=* +--roles-C.{unknown}=+{value} diff --git a/Units/parser-c.r/c-reftag-member.d/expected.tags b/Units/parser-c.r/c-reftag-member.d/expected.tags index baa5cd547a..c815c4f73c 100644 --- a/Units/parser-c.r/c-reftag-member.d/expected.tags +++ b/Units/parser-c.r/c-reftag-member.d/expected.tags @@ -1,3 +1,5 @@ file_ops input.c /^static struct ops file_ops = {$/;" variable typeref:struct:ops file: roles:def read input.c /^ .read = file_read_fn,$/;" member scope:variable:file_ops roles:initialized +file_read_fn input.c /^ .read = file_read_fn,$/;" unknown scope:variable:file_ops roles:value write input.c /^ .write = file_write_fn,$/;" member scope:variable:file_ops roles:initialized +file_write_fn input.c /^ .write = file_write_fn,$/;" unknown scope:variable:file_ops roles:value diff --git a/parsers/cxx/cxx_parser_variable.c b/parsers/cxx/cxx_parser_variable.c index 2d7f3dc932..c7ceb9d061 100644 --- a/parsers/cxx/cxx_parser_variable.c +++ b/parsers/cxx/cxx_parser_variable.c @@ -119,6 +119,45 @@ static void cxxParserExtractMembersInitialization(CXXTokenChain * pChain, int iS } // Point t to the assignment. t = t->pNext->pNext->pNext; + + // Looking for the pattern: + // + // = unknown, + // + // or + // + // = unknown} + // + if(t->pNext && + cxxTokenTypeIs(t->pNext, CXXTokenTypeIdentifier) && + t->pNext->pNext && + cxxTokenTypeIsOneOf(t->pNext->pNext, + CXXTokenTypeComma|CXXTokenTypeClosingBracket)) + + { + CXXToken *pIdentifier = t->pNext; + if(pIdentifier->iCorkIndex != CORK_NIL && pIdentifier->bCorkIndexForReftag) + { + cxxReftagReset(pIdentifier->iCorkIndex, iScopeCorkIndex, + CXXTagKindUNKNOWN, CXXTagUnknownRoleVALUE, + true); + } + else if(pIdentifier->iCorkIndex == CORK_NIL) + { + tagEntryInfo oEntry; + initRefTagEntry(&oEntry, vStringValue(pIdentifier->pszWord), + CXXTagKindUNKNOWN, CXXTagUnknownRoleVALUE); + oEntry.lineNumber = pIdentifier->iLineNumber; + oEntry.filePosition = pIdentifier->oFilePosition; + oEntry.isFileScope = false; + // TODO: Other scope field must be filled. + oEntry.extensionFields.scopeIndex = iScopeCorkIndex; + pIdentifier->iCorkIndex = makeTagEntry(&oEntry); + registerEntry(pIdentifier->iCorkIndex); + pIdentifier->bCorkIndexForReftag = 1; + } + t = t->pNext; + } } } return; diff --git a/parsers/cxx/cxx_tag.c b/parsers/cxx/cxx_tag.c index 054cce1dbc..a812bd167d 100644 --- a/parsers/cxx/cxx_tag.c +++ b/parsers/cxx/cxx_tag.c @@ -22,6 +22,7 @@ #define CXX_COMMON_UNKNOWN_ROLES(__langPrefix) \ static roleDefinition __langPrefix##UnknownRoles [] = { \ { false, "ref", "referenced anyhow" }, \ + { true, "value", "used as right side value" }, \ } CXX_COMMON_UNKNOWN_ROLES(C); diff --git a/parsers/cxx/cxx_tag.h b/parsers/cxx/cxx_tag.h index 6ac34edaf5..119538dbde 100644 --- a/parsers/cxx/cxx_tag.h +++ b/parsers/cxx/cxx_tag.h @@ -43,6 +43,7 @@ enum CXXTagCommonKind enum CXXTagUnknownRole { CXXTagUnknownRoleREFERENCED, + CXXTagUnknownRoleVALUE, }; enum CXXTagMemberRole From 6301118d960a38e2fb866b25e026f209622c3472 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 4 Dec 2022 02:52:03 +0900 Subject: [PATCH 6/7] Cxx: add "defvar" role to "unknown" kind struct opt file_ops { .read = file_read, .write = file_write, }; The parser with this change extracts "opt" with "defvar" role of "unknown" kind. Signed-off-by: Masatake YAMATO --- Tmain/list-kinds-full.d/stdout-expected.txt | 4 +-- Tmain/list-roles.d/stdout-expected.txt | 31 +++++++++++++++++++ Tmain/nested-subparsers.d/stdout-expected.txt | 2 +- Units/parser-c.r/c-reftag-member.d/args.ctags | 2 +- .../c-reftag-member.d/expected.tags | 1 + parsers/cxx/cxx_parser.c | 2 +- parsers/cxx/cxx_parser_function.c | 7 +++-- parsers/cxx/cxx_parser_lambda.c | 2 +- parsers/cxx/cxx_parser_template.c | 3 +- parsers/cxx/cxx_parser_typedef.c | 3 +- parsers/cxx/cxx_parser_variable.c | 2 +- parsers/cxx/cxx_tag.c | 27 ++++++++++++++-- parsers/cxx/cxx_tag.h | 4 ++- 13 files changed, 75 insertions(+), 15 deletions(-) diff --git a/Tmain/list-kinds-full.d/stdout-expected.txt b/Tmain/list-kinds-full.d/stdout-expected.txt index d0fb6550ed..14b82eda07 100644 --- a/Tmain/list-kinds-full.d/stdout-expected.txt +++ b/Tmain/list-kinds-full.d/stdout-expected.txt @@ -1,7 +1,7 @@ #LETTER NAME ENABLED REFONLY NROLES MASTER DESCRIPTION D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels -Y unknown no yes 2 C unknown identifier +Y unknown no yes 3 C unknown identifier d macro yes no 2 C macro definitions e enumerator yes no 0 C enumerators (values inside an enumeration) f function yes no 0 C function definitions @@ -22,7 +22,7 @@ D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels N name no no 0 NONE names imported via using scope::symbol U using no no 0 NONE using namespace statements -Y unknown no yes 2 C unknown identifier +Y unknown no yes 3 C unknown identifier Z tparam no no 0 NONE template parameters c class yes no 0 NONE classes d macro yes no 2 C macro definitions diff --git a/Tmain/list-roles.d/stdout-expected.txt b/Tmain/list-roles.d/stdout-expected.txt index a560128cbe..f7bc6ceff7 100644 --- a/Tmain/list-roles.d/stdout-expected.txt +++ b/Tmain/list-roles.d/stdout-expected.txt @@ -18,6 +18,7 @@ Automake d/directory program on directory for PROGRA Automake d/directory script on directory for SCRIPTS primary Basic f/function decl on declared Bats S/script loaded on script loaed with "load" command +C Y/unknown defvar on (maybe type) used for defining variables C Y/unknown ref off referenced anyhow C Y/unknown value on used as right side value C d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -25,6 +26,7 @@ C d/macro undef on undefined C h/header local on local header C h/header system on system header C m/member initialized on initialized with form '.member = ...' +C++ Y/unknown defvar on (maybe type) used for defining variables C++ Y/unknown ref off referenced anyhow C++ Y/unknown value on used as right side value C++ d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -36,6 +38,7 @@ CPreProcessor d/macro condition off used in part of #if/ CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header CPreProcessor h/header system on system header +CUDA Y/unknown defvar on (maybe type) used for defining variables CUDA Y/unknown ref off referenced anyhow CUDA Y/unknown value on used as right side value CUDA d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -147,6 +150,7 @@ Automake d/directory program on directory for PROGRA Automake d/directory script on directory for SCRIPTS primary Basic f/function decl on declared Bats S/script loaded on script loaed with "load" command +C Y/unknown defvar on (maybe type) used for defining variables C Y/unknown ref off referenced anyhow C Y/unknown value on used as right side value C d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -154,6 +158,7 @@ C d/macro undef on undefined C h/header local on local header C h/header system on system header C m/member initialized on initialized with form '.member = ...' +C++ Y/unknown defvar on (maybe type) used for defining variables C++ Y/unknown ref off referenced anyhow C++ Y/unknown value on used as right side value C++ d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -165,6 +170,7 @@ CPreProcessor d/macro condition off used in part of #if/ CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header CPreProcessor h/header system on system header +CUDA Y/unknown defvar on (maybe type) used for defining variables CUDA Y/unknown ref off referenced anyhow CUDA Y/unknown value on used as right side value CUDA d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -261,6 +267,7 @@ Zsh s/script loaded on loaded # C.* # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -301,6 +308,7 @@ s/script loaded on loaded # C.* with disabling all roles of all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -313,6 +321,7 @@ m/member initialized off initialized with form '.member = ...' # C.* with disabling all roles of all kinds of all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -326,6 +335,7 @@ m/member initialized off initialized with form '.member = ...' # after disabling system role of header kind of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref on referenced anyhow Y/unknown value on used as right side value d/macro condition on used in part of #if/#ifdef/#elif conditions @@ -339,6 +349,7 @@ m/member initialized on initialized with form '.member = ...' # after disabling system role of header kind of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref on referenced anyhow Y/unknown value on used as right side value d/macro condition on used in part of #if/#ifdef/#elif conditions @@ -351,6 +362,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with disabling all roles in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -370,6 +382,7 @@ s/script loaded on loaded # C.* with disabling all roles of all kinds in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -390,6 +403,7 @@ s/script loaded on loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref on referenced anyhow Y/unknown value on used as right side value d/macro condition on used in part of #if/#ifdef/#elif conditions @@ -411,6 +425,7 @@ s/script loaded off loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref on referenced anyhow Y/unknown value on used as right side value d/macro condition on used in part of #if/#ifdef/#elif conditions @@ -431,6 +446,7 @@ s/script loaded off loaded # C.* with disabling all roles of {header} kind in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -450,6 +466,7 @@ s/script loaded on loaded # C.* with disabling all roles of h kind in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -470,6 +487,7 @@ s/script loaded on loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -491,6 +509,7 @@ s/script loaded off loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -511,6 +530,7 @@ s/script loaded off loaded # C.* with disabling system role of h kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -523,6 +543,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with disabling system role of {header} kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -535,6 +556,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with enabling system role of h kind after disabling the role # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -547,6 +569,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with enabling system role of {header} kind after disabling the role # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -559,6 +582,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with disabling system and local roles of h kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -571,6 +595,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with disabling system and local roles of {header} kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -584,6 +609,7 @@ m/member initialized on initialized with form '.member = ...' # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -597,6 +623,7 @@ m/member initialized off initialized with form '.member = ...' # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -609,6 +636,7 @@ m/member initialized off initialized with form '.member = ...' # C.* with disabling local role of h kind and undef role of d kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -621,6 +649,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with enabling all roles of header kinds after disabling all roles of the kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -633,6 +662,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with enabling all roles of header kinds after disabling all roles of the kinds of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions @@ -645,6 +675,7 @@ m/member initialized off initialized with form '.member = ...' # C.* with enabling all roles of header kinds after disabling all roles of the kinds of C language (short notation) # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value d/macro condition off used in part of #if/#ifdef/#elif conditions diff --git a/Tmain/nested-subparsers.d/stdout-expected.txt b/Tmain/nested-subparsers.d/stdout-expected.txt index d59a8c57b4..a83115aef3 100644 --- a/Tmain/nested-subparsers.d/stdout-expected.txt +++ b/Tmain/nested-subparsers.d/stdout-expected.txt @@ -37,7 +37,7 @@ n name #LETTER NAME ENABLED REFONLY NROLES MASTER DESCRIPTION D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels -Y unknown no yes 2 C unknown identifier +Y unknown no yes 3 C unknown identifier d macro yes no 2 C macro definitions e enumerator yes no 0 C enumerators (values inside an enumeration) f function yes no 0 C function definitions diff --git a/Units/parser-c.r/c-reftag-member.d/args.ctags b/Units/parser-c.r/c-reftag-member.d/args.ctags index 05d5b6508b..6e0571e5a0 100644 --- a/Units/parser-c.r/c-reftag-member.d/args.ctags +++ b/Units/parser-c.r/c-reftag-member.d/args.ctags @@ -3,4 +3,4 @@ --fields=+rKZ --kinds-C=* --roles-C.{member}=* ---roles-C.{unknown}=+{value} +--roles-C.{unknown}=+{value}{defvar} diff --git a/Units/parser-c.r/c-reftag-member.d/expected.tags b/Units/parser-c.r/c-reftag-member.d/expected.tags index c815c4f73c..084b03f12a 100644 --- a/Units/parser-c.r/c-reftag-member.d/expected.tags +++ b/Units/parser-c.r/c-reftag-member.d/expected.tags @@ -1,3 +1,4 @@ +ops input.c /^static struct ops file_ops = {$/;" unknown roles:defvar file_ops input.c /^static struct ops file_ops = {$/;" variable typeref:struct:ops file: roles:def read input.c /^ .read = file_read_fn,$/;" member scope:variable:file_ops roles:initialized file_read_fn input.c /^ .read = file_read_fn,$/;" unknown scope:variable:file_ops roles:value diff --git a/parsers/cxx/cxx_parser.c b/parsers/cxx/cxx_parser.c index 6ed9a83dd5..404ff24615 100644 --- a/parsers/cxx/cxx_parser.c +++ b/parsers/cxx/cxx_parser.c @@ -873,7 +873,7 @@ bool cxxParserParseEnum(void) if(pTypeEnd) { CXX_DEBUG_ASSERT(pTypeBegin,"Type begin should be also set here"); - pTypeName = cxxTagCheckAndSetTypeField(pTypeBegin,pTypeEnd); + pTypeName = cxxTagCheckAndSetTypeField(pTypeBegin,pTypeEnd, false); } if(bIsScopedEnum) diff --git a/parsers/cxx/cxx_parser_function.c b/parsers/cxx/cxx_parser_function.c index 33ceda59c2..40bc5f9db6 100644 --- a/parsers/cxx/cxx_parser_function.c +++ b/parsers/cxx/cxx_parser_function.c @@ -1654,7 +1654,7 @@ int cxxParserEmitFunctionTags( CXXToken * pTokenBeforeParenthesis = pInfo->pParenthesis->pPrev; cxxTokenChainTake(pInfo->pParenthesisContainerChain,pInfo->pParenthesis); - pTypeName = cxxTagCheckAndSetTypeField(pInfo->pTypeStart,pInfo->pTypeEnd); + pTypeName = cxxTagCheckAndSetTypeField(pInfo->pTypeStart,pInfo->pTypeEnd, false); cxxTokenChainInsertAfter( pInfo->pParenthesisContainerChain, @@ -1665,7 +1665,7 @@ int cxxParserEmitFunctionTags( pTypeName = NULL; } } else { - pTypeName = cxxTagCheckAndSetTypeField(pInfo->pTypeStart,pInfo->pTypeEnd); + pTypeName = cxxTagCheckAndSetTypeField(pInfo->pTypeStart,pInfo->pTypeEnd, false); } } else { pTypeName = NULL; @@ -1921,7 +1921,8 @@ void cxxParserEmitFunctionParameterTags(CXXTypedVariableSet * pInfo) pTypeName = cxxTagCheckAndSetTypeField( pTypeStart, - pTypeEnd + pTypeEnd, + false ); } else { // The declaration contains only the identifier! diff --git a/parsers/cxx/cxx_parser_lambda.c b/parsers/cxx/cxx_parser_lambda.c index bfc73749c4..9625f5418a 100644 --- a/parsers/cxx/cxx_parser_lambda.c +++ b/parsers/cxx/cxx_parser_lambda.c @@ -239,7 +239,7 @@ bool cxxParserHandleLambda(CXXToken * pParenthesis) markTagExtraBit (tag, XTAG_ANONYMOUS); if(pTypeStart) - pTypeName = cxxTagCheckAndSetTypeField(pTypeStart,pTypeEnd); + pTypeName = cxxTagCheckAndSetTypeField(pTypeStart,pTypeEnd, false); else pTypeName = NULL; diff --git a/parsers/cxx/cxx_parser_template.c b/parsers/cxx/cxx_parser_template.c index 71bbd67845..0902a200aa 100644 --- a/parsers/cxx/cxx_parser_template.c +++ b/parsers/cxx/cxx_parser_template.c @@ -825,7 +825,8 @@ void cxxParserEmitTemplateParameterTags(void) CXXToken * pTypeToken = cxxTagCheckAndSetTypeField( g_cxx.oTemplateParameters.aTypeStarts[i], - g_cxx.oTemplateParameters.aTypeEnds[i] + g_cxx.oTemplateParameters.aTypeEnds[i], + false ); cxxTagCommit(NULL); diff --git a/parsers/cxx/cxx_parser_typedef.c b/parsers/cxx/cxx_parser_typedef.c index 34895c0b95..0160339421 100644 --- a/parsers/cxx/cxx_parser_typedef.c +++ b/parsers/cxx/cxx_parser_typedef.c @@ -433,7 +433,8 @@ void cxxParserExtractTypedef( pTypeName = cxxTagCheckAndSetTypeField( cxxTokenChainFirst(pChain), - pComma ? pComma->pPrev : cxxTokenChainLast(pChain) + pComma ? pComma->pPrev : cxxTokenChainLast(pChain), + false ); } diff --git a/parsers/cxx/cxx_parser_variable.c b/parsers/cxx/cxx_parser_variable.c index c7ceb9d061..e49a3471e6 100644 --- a/parsers/cxx/cxx_parser_variable.c +++ b/parsers/cxx/cxx_parser_variable.c @@ -828,7 +828,7 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF } // anything that remains is part of type - CXXToken * pTypeToken = cxxTagCheckAndSetTypeField(cxxTokenChainFirst(pChain),t->pPrev); + CXXToken * pTypeToken = cxxTagCheckAndSetTypeField(cxxTokenChainFirst(pChain),t->pPrev, true); tag->isFileScope = bKnRStyleParameters ? true : diff --git a/parsers/cxx/cxx_tag.c b/parsers/cxx/cxx_tag.c index a812bd167d..686a679f46 100644 --- a/parsers/cxx/cxx_tag.c +++ b/parsers/cxx/cxx_tag.c @@ -12,6 +12,7 @@ #include "cxx_debug.h" #include "cxx_token_chain.h" #include "cxx_parser_internal.h" +#include "cxx_reftag.h" #include "entry.h" #include "../cpreprocessor.h" @@ -23,6 +24,7 @@ static roleDefinition __langPrefix##UnknownRoles [] = { \ { false, "ref", "referenced anyhow" }, \ { true, "value", "used as right side value" }, \ + { true, "defvar", "(maybe type) used for defining variables" }, \ } CXX_COMMON_UNKNOWN_ROLES(C); @@ -535,7 +537,8 @@ static bool cxxTagCheckTypeField( CXXToken * cxxTagCheckAndSetTypeField( CXXToken * pTypeStart, - CXXToken * pTypeEnd + CXXToken * pTypeEnd, + bool bVardef ) { CXX_DEBUG_ASSERT(pTypeStart,"Non null type start is expected here"); @@ -607,7 +610,6 @@ CXXToken * cxxTagCheckAndSetTypeField( cxxTokenChainNormalizeTypeNameSpacingInRange(pTypeStart,pTypeEnd); CXXToken * pTypeName = cxxTokenChainExtractRangeFilterTypeName(pTypeStart,pTypeEnd); - /* TODO */ if(!pTypeName) { @@ -615,6 +617,27 @@ CXXToken * cxxTagCheckAndSetTypeField( return NULL; } + if (bVardef && pTypeEnd && cxxTokenTypeIs(pTypeEnd, CXXTokenTypeIdentifier) && + cxxTagRoleEnabled(CXXTagKindUNKNOWN, CXXTagUnknownRoleDEFVAR)) + { + CXXToken *t = pTypeEnd; + if(t->iCorkIndex != CORK_NIL && t->bCorkIndexForReftag) + cxxReftagReset(t->iCorkIndex, CORK_NIL, + CXXTagKindUNKNOWN, CXXTagUnknownRoleDEFVAR, false); + else if(t->iCorkIndex == CORK_NIL) + { + tagEntryInfo oEntry; + initRefTagEntry(&oEntry, vStringValue(t->pszWord), + CXXTagKindUNKNOWN, CXXTagUnknownRoleDEFVAR); + oEntry.lineNumber = t->iLineNumber; + oEntry.filePosition = t->oFilePosition; + oEntry.isFileScope = false; + // TODO: Other scope field must be filled. + t->iCorkIndex = makeTagEntry(&oEntry); + t->bCorkIndexForReftag = 1; + } + } + CXX_DEBUG_PRINT("Type name is '%s'",vStringValue(pTypeName->pszWord)); g_oCXXTag.extensionFields.typeRef[0] = szTypeRef0; diff --git a/parsers/cxx/cxx_tag.h b/parsers/cxx/cxx_tag.h index 119538dbde..c0f5d4233d 100644 --- a/parsers/cxx/cxx_tag.h +++ b/parsers/cxx/cxx_tag.h @@ -44,6 +44,7 @@ enum CXXTagUnknownRole { CXXTagUnknownRoleREFERENCED, CXXTagUnknownRoleVALUE, + CXXTagUnknownRoleDEFVAR, }; enum CXXTagMemberRole @@ -123,7 +124,8 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken); // be destroyed after cxxTagCommit() has been called. CXXToken * cxxTagCheckAndSetTypeField( CXXToken * pTypeStart, - CXXToken * pTypeEnd + CXXToken * pTypeEnd, + bool bVardef ); typedef enum _CXXTagProperty From ef7e809fe5c6abedb9dc844c569a8b615150c2d3 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Wed, 4 Jan 2023 05:29:25 +0900 Subject: [PATCH 7/7] Cxx: add "applied" role to "unknown" kind #include int main(void) { return puts("hello, world\n"); } The parser with this change extracts "puts" with "applied" role of "unknown" kind. TODO: consider sub parsers. Signed-off-by: Masatake YAMATO --- Tmain/list-kinds-full.d/stdout-expected.txt | 4 +-- Tmain/list-roles.d/stdout-expected.txt | 31 +++++++++++++++++++ Tmain/nested-subparsers.d/stdout-expected.txt | 2 +- .../c-reftags-unknown-ref.d/expected.tags | 2 +- parsers/cxx/cxx_reftag.c | 15 +++++++++ parsers/cxx/cxx_tag.c | 1 + parsers/cxx/cxx_tag.h | 1 + 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Tmain/list-kinds-full.d/stdout-expected.txt b/Tmain/list-kinds-full.d/stdout-expected.txt index 14b82eda07..ad6535cdc9 100644 --- a/Tmain/list-kinds-full.d/stdout-expected.txt +++ b/Tmain/list-kinds-full.d/stdout-expected.txt @@ -1,7 +1,7 @@ #LETTER NAME ENABLED REFONLY NROLES MASTER DESCRIPTION D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels -Y unknown no yes 3 C unknown identifier +Y unknown no yes 4 C unknown identifier d macro yes no 2 C macro definitions e enumerator yes no 0 C enumerators (values inside an enumeration) f function yes no 0 C function definitions @@ -22,7 +22,7 @@ D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels N name no no 0 NONE names imported via using scope::symbol U using no no 0 NONE using namespace statements -Y unknown no yes 3 C unknown identifier +Y unknown no yes 4 C unknown identifier Z tparam no no 0 NONE template parameters c class yes no 0 NONE classes d macro yes no 2 C macro definitions diff --git a/Tmain/list-roles.d/stdout-expected.txt b/Tmain/list-roles.d/stdout-expected.txt index f7bc6ceff7..b040755542 100644 --- a/Tmain/list-roles.d/stdout-expected.txt +++ b/Tmain/list-roles.d/stdout-expected.txt @@ -18,6 +18,7 @@ Automake d/directory program on directory for PROGRA Automake d/directory script on directory for SCRIPTS primary Basic f/function decl on declared Bats S/script loaded on script loaed with "load" command +C Y/unknown applied on (maybe macro, function, or member) called or expanded C Y/unknown defvar on (maybe type) used for defining variables C Y/unknown ref off referenced anyhow C Y/unknown value on used as right side value @@ -26,6 +27,7 @@ C d/macro undef on undefined C h/header local on local header C h/header system on system header C m/member initialized on initialized with form '.member = ...' +C++ Y/unknown applied on (maybe macro, function, or member) called or expanded C++ Y/unknown defvar on (maybe type) used for defining variables C++ Y/unknown ref off referenced anyhow C++ Y/unknown value on used as right side value @@ -38,6 +40,7 @@ CPreProcessor d/macro condition off used in part of #if/ CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header CPreProcessor h/header system on system header +CUDA Y/unknown applied on (maybe macro, function, or member) called or expanded CUDA Y/unknown defvar on (maybe type) used for defining variables CUDA Y/unknown ref off referenced anyhow CUDA Y/unknown value on used as right side value @@ -150,6 +153,7 @@ Automake d/directory program on directory for PROGRA Automake d/directory script on directory for SCRIPTS primary Basic f/function decl on declared Bats S/script loaded on script loaed with "load" command +C Y/unknown applied on (maybe macro, function, or member) called or expanded C Y/unknown defvar on (maybe type) used for defining variables C Y/unknown ref off referenced anyhow C Y/unknown value on used as right side value @@ -158,6 +162,7 @@ C d/macro undef on undefined C h/header local on local header C h/header system on system header C m/member initialized on initialized with form '.member = ...' +C++ Y/unknown applied on (maybe macro, function, or member) called or expanded C++ Y/unknown defvar on (maybe type) used for defining variables C++ Y/unknown ref off referenced anyhow C++ Y/unknown value on used as right side value @@ -170,6 +175,7 @@ CPreProcessor d/macro condition off used in part of #if/ CPreProcessor d/macro undef on undefined CPreProcessor h/header local on local header CPreProcessor h/header system on system header +CUDA Y/unknown applied on (maybe macro, function, or member) called or expanded CUDA Y/unknown defvar on (maybe type) used for defining variables CUDA Y/unknown ref off referenced anyhow CUDA Y/unknown value on used as right side value @@ -267,6 +273,7 @@ Zsh s/script loaded on loaded # C.* # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -308,6 +315,7 @@ s/script loaded on loaded # C.* with disabling all roles of all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -321,6 +329,7 @@ m/member initialized off initialized with form '.member = ...' # C.* with disabling all roles of all kinds of all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -335,6 +344,7 @@ m/member initialized off initialized with form '.member = ...' # after disabling system role of header kind of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref on referenced anyhow Y/unknown value on used as right side value @@ -349,6 +359,7 @@ m/member initialized on initialized with form '.member = ...' # after disabling system role of header kind of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref on referenced anyhow Y/unknown value on used as right side value @@ -362,6 +373,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with disabling all roles in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -382,6 +394,7 @@ s/script loaded on loaded # C.* with disabling all roles of all kinds in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -403,6 +416,7 @@ s/script loaded on loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref on referenced anyhow Y/unknown value on used as right side value @@ -425,6 +439,7 @@ s/script loaded off loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref on referenced anyhow Y/unknown value on used as right side value @@ -446,6 +461,7 @@ s/script loaded off loaded # C.* with disabling all roles of {header} kind in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -466,6 +482,7 @@ s/script loaded on loaded # C.* with disabling all roles of h kind in C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -487,6 +504,7 @@ s/script loaded on loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -509,6 +527,7 @@ s/script loaded off loaded # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -530,6 +549,7 @@ s/script loaded off loaded # C.* with disabling system role of h kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -543,6 +563,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with disabling system role of {header} kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -556,6 +577,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with enabling system role of h kind after disabling the role # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -569,6 +591,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with enabling system role of {header} kind after disabling the role # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -582,6 +605,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with disabling system and local roles of h kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -595,6 +619,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with disabling system and local roles of {header} kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -609,6 +634,7 @@ m/member initialized on initialized with form '.member = ...' # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -623,6 +649,7 @@ m/member initialized off initialized with form '.member = ...' # after disabling all roles in all languages # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -636,6 +663,7 @@ m/member initialized off initialized with form '.member = ...' # C.* with disabling local role of h kind and undef role of d kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -649,6 +677,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with enabling all roles of header kinds after disabling all roles of the kind # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied on (maybe macro, function, or member) called or expanded Y/unknown defvar on (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value on used as right side value @@ -662,6 +691,7 @@ m/member initialized on initialized with form '.member = ...' # C.* with enabling all roles of header kinds after disabling all roles of the kinds of C language # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value @@ -675,6 +705,7 @@ m/member initialized off initialized with form '.member = ...' # C.* with enabling all roles of header kinds after disabling all roles of the kinds of C language (short notation) # #KIND(L/N) NAME ENABLED DESCRIPTION +Y/unknown applied off (maybe macro, function, or member) called or expanded Y/unknown defvar off (maybe type) used for defining variables Y/unknown ref off referenced anyhow Y/unknown value off used as right side value diff --git a/Tmain/nested-subparsers.d/stdout-expected.txt b/Tmain/nested-subparsers.d/stdout-expected.txt index a83115aef3..f0494c96e0 100644 --- a/Tmain/nested-subparsers.d/stdout-expected.txt +++ b/Tmain/nested-subparsers.d/stdout-expected.txt @@ -37,7 +37,7 @@ n name #LETTER NAME ENABLED REFONLY NROLES MASTER DESCRIPTION D macroparam no no 0 C parameters inside macro definitions L label no no 0 C goto labels -Y unknown no yes 3 C unknown identifier +Y unknown no yes 4 C unknown identifier d macro yes no 2 C macro definitions e enumerator yes no 0 C enumerators (values inside an enumeration) f function yes no 0 C function definitions diff --git a/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags b/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags index 78de11b7fb..d2687c75f1 100644 --- a/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags +++ b/Units/parser-c.r/c-reftags-unknown-ref.d/expected.tags @@ -10,4 +10,4 @@ j input.c /^ if (j == 0)$/;" Y function:f roles:ref i input.c /^ return i + B + j + f(0);$/;" Y function:f roles:ref B input.c /^ return i + B + j + f(0);$/;" Y function:f roles:ref j input.c /^ return i + B + j + f(0);$/;" Y function:f roles:ref -f input.c /^ return i + B + j + f(0);$/;" Y function:f roles:ref +f input.c /^ return i + B + j + f(0);$/;" Y function:f roles:applied diff --git a/parsers/cxx/cxx_reftag.c b/parsers/cxx/cxx_reftag.c index 2f4e5682e9..efd5eba1c6 100644 --- a/parsers/cxx/cxx_reftag.c +++ b/parsers/cxx/cxx_reftag.c @@ -40,6 +40,21 @@ void cxxReftagEvalNewToken(void) if (in_subparser) popLanguage(); } + else if (cxxTokenTypeIs(g_cxx.pToken,CXXTokenTypeOpeningParenthesis) + && cxxTagKindEnabled(CXXTagKindUNKNOWN) && + cxxTagRoleEnabled(CXXTagKindUNKNOWN, CXXTagUnknownRoleAPPLIED)) + { + if(g_cxx.pToken->pPrev && cxxTokenTypeIs(g_cxx.pToken->pPrev, + CXXTokenTypeIdentifier)) + { + CXXToken * i = g_cxx.pToken->pPrev; + if(i->iCorkIndex != CORK_NIL && i->bCorkIndexForReftag) + cxxReftagReset(i->iCorkIndex, CORK_NIL, + CXXTagKindUNKNOWN, CXXTagUnknownRoleAPPLIED, false); + else + ; + } + } } void cxxReftagReset(int iCorkIndex, int iScopeCorkIndex, diff --git a/parsers/cxx/cxx_tag.c b/parsers/cxx/cxx_tag.c index 686a679f46..88d0d55332 100644 --- a/parsers/cxx/cxx_tag.c +++ b/parsers/cxx/cxx_tag.c @@ -25,6 +25,7 @@ { false, "ref", "referenced anyhow" }, \ { true, "value", "used as right side value" }, \ { true, "defvar", "(maybe type) used for defining variables" }, \ + { true, "applied", "(maybe macro, function, or member) called or expanded" }, \ } CXX_COMMON_UNKNOWN_ROLES(C); diff --git a/parsers/cxx/cxx_tag.h b/parsers/cxx/cxx_tag.h index c0f5d4233d..3187f2e904 100644 --- a/parsers/cxx/cxx_tag.h +++ b/parsers/cxx/cxx_tag.h @@ -45,6 +45,7 @@ enum CXXTagUnknownRole CXXTagUnknownRoleREFERENCED, CXXTagUnknownRoleVALUE, CXXTagUnknownRoleDEFVAR, + CXXTagUnknownRoleAPPLIED, }; enum CXXTagMemberRole