From 73fc4342ed896696626e6da149118437abd2185d Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 4 Dec 2022 01:05:57 +0900 Subject: [PATCH] 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 | 69 ++++ parsers/cxx/cxx_tag.c | 13 +- parsers/cxx/cxx_tag.h | 5 + 11 files changed, 285 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 13f854c1a2..dd15459d22 100644 --- a/Tmain/json-output-format.d/stdout-expected.txt +++ b/Tmain/json-output-format.d/stdout-expected.txt @@ -89,6 +89,7 @@ {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C!header", "path": "local", "pattern": "local header"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C!header", "path": "system", "pattern": "system header"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C!macro", "path": "undef", "pattern": "undefined"} +{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C!member", "path": "initialized", "pattern": "initialized with form '.member = ...'"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Go!package", "path": "imported", "pattern": "imported package"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Go!unknown", "path": "receiverType", "pattern": "receiver type"} {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python!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 d00e32bbd1..69afbca192 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 @@ -145,11 +148,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 @@ -159,6 +164,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 @@ -246,12 +252,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 @@ -284,54 +291,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 @@ -343,12 +355,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 @@ -361,12 +374,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 @@ -380,12 +394,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 @@ -398,12 +413,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 @@ -415,12 +431,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 @@ -433,12 +450,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 @@ -452,12 +470,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 @@ -470,121 +489,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 dd6f851570..e361f91214 100644 --- a/parsers/cxx/cxx_parser_variable.c +++ b/parsers/cxx/cxx_parser_variable.c @@ -67,6 +67,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. + cxxTagResetRefTag(pIdentifier->iCorkIndex, iScopeCorkIndex, + CXXTagKindMEMBER, CXXTagMemberRoleINITIALIZED); + } + 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. @@ -800,11 +856,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 @@ -829,6 +892,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) @@ -844,6 +910,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 28e1b1b5d8..c7d416dd5c 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 7adb735bde..b3e7aec0e1 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 {