Skip to content

Commit

Permalink
Cxx: add "defvar" role to "unknown" kind
Browse files Browse the repository at this point in the history
    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 <[email protected]>
  • Loading branch information
masatake committed Dec 3, 2022
1 parent 27fc421 commit e47cb40
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Tmain/list-kinds-full.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions Tmain/list-roles.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ 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
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
Expand All @@ -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
Expand Down Expand Up @@ -146,13 +149,15 @@ 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
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
Expand All @@ -164,6 +169,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
Expand Down Expand Up @@ -259,6 +265,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
Expand Down Expand Up @@ -299,6 +306,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
Expand All @@ -311,6 +319,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
Expand All @@ -324,6 +333,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
Expand All @@ -337,6 +347,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
Expand All @@ -349,6 +360,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
Expand All @@ -368,6 +380,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
Expand All @@ -388,6 +401,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
Expand All @@ -409,6 +423,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
Expand All @@ -429,6 +444,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
Expand All @@ -448,6 +464,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
Expand All @@ -468,6 +485,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
Expand All @@ -489,6 +507,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
Expand All @@ -509,6 +528,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
Expand All @@ -521,6 +541,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
Expand All @@ -533,6 +554,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
Expand All @@ -545,6 +567,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
Expand All @@ -557,6 +580,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
Expand All @@ -569,6 +593,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
Expand All @@ -582,6 +607,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
Expand All @@ -595,6 +621,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
Expand All @@ -607,6 +634,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
Expand All @@ -619,6 +647,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
Expand All @@ -631,6 +660,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
Expand All @@ -643,6 +673,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
Expand Down
2 changes: 1 addition & 1 deletion Tmain/nested-subparsers.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Units/parser-c.r/c-reftag-member.d/args.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
--fields=+rKZ
--kinds-C=*
--roles-C.{member}=*
--roles-C.{unknown}=+{value}
--roles-C.{unknown}=+{value}{defvar}
1 change: 1 addition & 0 deletions Units/parser-c.r/c-reftag-member.d/expected.tags
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion parsers/cxx/cxx_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions parsers/cxx/cxx_parser_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -1918,7 +1918,8 @@ void cxxParserEmitFunctionParameterTags(CXXTypedVariableSet * pInfo)

pTypeName = cxxTagCheckAndSetTypeField(
pTypeStart,
pTypeEnd
pTypeEnd,
false
);
} else {
// The declaration contains only the identifier!
Expand Down
2 changes: 1 addition & 1 deletion parsers/cxx/cxx_parser_lambda.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion parsers/cxx/cxx_parser_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion parsers/cxx/cxx_parser_typedef.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ void cxxParserExtractTypedef(

pTypeName = cxxTagCheckAndSetTypeField(
cxxTokenChainFirst(pChain),
pComma ? pComma->pPrev : cxxTokenChainLast(pChain)
pComma ? pComma->pPrev : cxxTokenChainLast(pChain),
false
);
}

Expand Down
2 changes: 1 addition & 1 deletion parsers/cxx/cxx_parser_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,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 :
Expand Down
Loading

0 comments on commit e47cb40

Please sign in to comment.