From 1723d6bd444edf4f2173b99114863c4adc5586d1 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Tue, 15 Nov 2022 10:31:38 +0900 Subject: [PATCH] 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 + Units/parser-c.r/c-reftags.d/args.ctags | 5 ++ Units/parser-c.r/c-reftags.d/expected.tags | 13 ++++ Units/parser-c.r/c-reftags.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 +++++++++++++++++++ parsers/cxx/cxx_parser_function.c | 1 + parsers/cxx/cxx_parser_tokenizer.c | 27 +++++++- parsers/cxx/cxx_qtmoc.c | 2 + parsers/cxx/cxx_tag.c | 34 +++++++++- parsers/cxx/cxx_tag.h | 10 +++ parsers/cxx/cxx_token.c | 4 ++ parsers/cxx/cxx_token.h | 7 ++ 18 files changed, 295 insertions(+), 10 deletions(-) create mode 100644 Units/parser-c.r/c-reftags.d/args.ctags create mode 100644 Units/parser-c.r/c-reftags.d/expected.tags create mode 100644 Units/parser-c.r/c-reftags.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 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 9efc80a302..7b4dc770b2 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 @@ -136,10 +139,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 @@ -148,6 +153,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 @@ -239,6 +245,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 @@ -276,6 +283,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 @@ -285,6 +293,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 @@ -295,6 +304,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 @@ -305,6 +315,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 @@ -314,6 +325,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 @@ -330,6 +342,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 @@ -347,6 +360,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 @@ -365,6 +379,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 @@ -382,6 +397,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 @@ -398,6 +414,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 @@ -415,6 +432,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 @@ -433,6 +451,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 @@ -450,6 +469,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 @@ -459,6 +479,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 @@ -468,6 +489,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 @@ -477,6 +499,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 @@ -486,6 +509,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 @@ -495,6 +519,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 @@ -505,6 +530,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 @@ -515,6 +541,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 @@ -524,6 +551,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 @@ -533,6 +561,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 @@ -542,6 +571,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 @@ -551,6 +581,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.d/args.ctags b/Units/parser-c.r/c-reftags.d/args.ctags new file mode 100644 index 0000000000..a56fea51c3 --- /dev/null +++ b/Units/parser-c.r/c-reftags.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.d/expected.tags b/Units/parser-c.r/c-reftags.d/expected.tags new file mode 100644 index 0000000000..c8e291bbda --- /dev/null +++ b/Units/parser-c.r/c-reftags.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.d/input.c b/Units/parser-c.r/c-reftags.d/input.c new file mode 100644 index 0000000000..ddb280b25a --- /dev/null +++ b/Units/parser-c.r/c-reftags.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/parsers/cxx/cxx_parser_function.c b/parsers/cxx/cxx_parser_function.c index 311b209509..e3e5cac009 100644 --- a/parsers/cxx/cxx_parser_function.c +++ b/parsers/cxx/cxx_parser_function.c @@ -1542,6 +1542,7 @@ int cxxParserEmitFunctionTags( 0 ); + cxxTagUseTokensInRangeAsPartOfDefTags(pInfo->pIdentifierStart,pInfo->pIdentifierEnd); cxxTokenChainDestroyRange(pInfo->pIdentifierChain,pInfo->pIdentifierStart,pInfo->pIdentifierEnd); CXX_DEBUG_ASSERT( diff --git a/parsers/cxx/cxx_parser_tokenizer.c b/parsers/cxx/cxx_parser_tokenizer.c index f43137bb6c..ab9f419bf1 100644 --- a/parsers/cxx/cxx_parser_tokenizer.c +++ b/parsers/cxx/cxx_parser_tokenizer.c @@ -1214,7 +1214,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 +1689,28 @@ bool cxxParserParseNextToken(void) return true; } + +bool cxxParserParseNextToken(void) +{ + bool r = cxxParserParseNextTokenNoRefTag(); + if (r && cxxTokenTypeIs(g_cxx.pToken,CXXTokenTypeIdentifier) + && cxxTagKindEnabled(CXXTagKindUNKNOWN)) + { + // 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->iReftag = makeSimpleRefTag (g_cxx.pToken->pszWord, + CXXTagKindUNKNOWN, + CXXTagUnknownRoleREFERENCED); + + if (in_subparser) + popLanguage(); + } + return r; +} diff --git a/parsers/cxx/cxx_qtmoc.c b/parsers/cxx/cxx_qtmoc.c index d02f227e29..7aacbcb829 100644 --- a/parsers/cxx/cxx_qtmoc.c +++ b/parsers/cxx/cxx_qtmoc.c @@ -86,6 +86,8 @@ static void qtMocMakeTagForProperty (CXXToken * pToken, const char *pszType) { tagEntryInfo tag; + cxxTagUseTokenAsPartOfDefTag(pToken); + initTagEntry(&tag, vStringValue(pToken->pszWord), K_PROPERTY); diff --git a/parsers/cxx/cxx_tag.c b/parsers/cxx/cxx_tag.c index 6b9166de9d..786116f08b 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. @@ -244,6 +256,24 @@ bool cxxTagFieldEnabled(unsigned int uField) static tagEntryInfo g_oCXXTag; +void cxxTagUseTokenAsPartOfDefTag(CXXToken * pToken) +{ + if (pToken->iReftag == CORK_NIL) + return; + + markCorkEntryPlaceholder (pToken->iReftag, true); + pToken->iReftag = CORK_NIL; +} + +void cxxTagUseTokensInRangeAsPartOfDefTags(CXXToken * pFrom, CXXToken * pTo) +{ + cxxTagUseTokenAsPartOfDefTag(pFrom); + while (pFrom != pTo) + { + pFrom = pFrom->pNext; + cxxTagUseTokenAsPartOfDefTag(pFrom); + } +} tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken) { @@ -255,6 +285,8 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken) return NULL; } + cxxTagUseTokenAsPartOfDefTag(pToken); + initTagEntry( &g_oCXXTag, vStringValue(pToken->pszWord), diff --git a/parsers/cxx/cxx_tag.h b/parsers/cxx/cxx_tag.h index b9eb9f0c50..fbdbb4fe75 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 { @@ -200,4 +206,8 @@ typedef enum { // Must be called before attempting to access the kind options. void cxxTagInitForLanguage(langType eLangType); +// Prevent emitting reference tags associated with token(s). +void cxxTagUseTokensInRangeAsPartOfDefTags(CXXToken * pFrom, CXXToken * pTo); +void cxxTagUseTokenAsPartOfDefTag(CXXToken * pToken); + #endif //!_cxxTag_h_ diff --git a/parsers/cxx/cxx_token.c b/parsers/cxx/cxx_token.c index cc3e7932cf..db431576be 100644 --- a/parsers/cxx/cxx_token.c +++ b/parsers/cxx/cxx_token.c @@ -31,6 +31,7 @@ static CXXToken *createToken(void *createArg CTAGS_ATTR_UNUSED) // we almost always want a string, and since this token // is being reused..well.. we always want it t->pszWord = vStringNew(); + t->iReftag = CORK_NIL; return t; } @@ -53,6 +54,8 @@ static void clearToken(CXXToken *t) t->pChain = NULL; t->pNext = NULL; t->pPrev = NULL; + + t->iReftag = CORK_NIL; } void cxxTokenAPIInit(void) @@ -119,6 +122,7 @@ CXXToken * cxxTokenCopy(CXXToken * pToken) pRetToken->eKeyword = pToken->eKeyword; pRetToken->bFollowedBySpace = pToken->bFollowedBySpace; vStringCat(pRetToken->pszWord,pToken->pszWord); + pRetToken->iReftag = pToken->iReftag; return pRetToken; } diff --git a/parsers/cxx/cxx_token.h b/parsers/cxx/cxx_token.h index 367a52f5a9..d5aa6e325b 100644 --- a/parsers/cxx/cxx_token.h +++ b/parsers/cxx/cxx_token.h @@ -87,6 +87,13 @@ typedef struct _CXXToken // uninitialized and must be treated as undefined. 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 cxxTagConsumeToken() + // or cxxTagConsumeRange(). + int iReftag; } CXXToken; CXXToken * cxxTokenCreate(void);