Skip to content

Commit

Permalink
Cxx: add "value" 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 "file_read" and
"file_write" with "value" role of "unknown" kind.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 3, 2022
1 parent 73fc434 commit ddf135e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 3 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 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
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 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
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 @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -144,12 +147,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
Expand All @@ -160,6 +165,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
Expand Down Expand Up @@ -254,6 +260,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
Expand Down Expand Up @@ -293,6 +300,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
Expand All @@ -304,6 +312,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
Expand All @@ -316,6 +325,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
Expand All @@ -328,6 +338,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
Expand All @@ -339,6 +350,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
Expand All @@ -357,6 +369,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
Expand All @@ -376,6 +389,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
Expand All @@ -396,6 +410,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
Expand All @@ -415,6 +430,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
Expand All @@ -433,6 +449,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
Expand All @@ -452,6 +469,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
Expand All @@ -472,6 +490,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
Expand All @@ -491,6 +510,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
Expand All @@ -502,6 +522,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
Expand All @@ -513,6 +534,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
Expand All @@ -524,6 +546,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
Expand All @@ -535,6 +558,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
Expand All @@ -546,6 +570,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
Expand All @@ -558,6 +583,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
Expand All @@ -570,6 +596,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
Expand All @@ -581,6 +608,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
Expand All @@ -592,6 +620,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
Expand All @@ -603,6 +632,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
Expand All @@ -614,6 +644,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
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 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
Expand Down
1 change: 1 addition & 0 deletions Units/parser-c.r/c-reftag-member.d/args.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
--fields=+rKZ
--kinds-C=*
--roles-C.{member}=*
--roles-C.{unknown}=+{value}
2 changes: 2 additions & 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,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
38 changes: 38 additions & 0 deletions parsers/cxx/cxx_parser_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,44 @@ 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)
{
cxxTagResetRefTag(pIdentifier->iCorkIndex, iScopeCorkIndex,
CXXTagKindUNKNOWN, CXXTagUnknownRoleVALUE);
}
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;
Expand Down
1 change: 1 addition & 0 deletions parsers/cxx/cxx_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions parsers/cxx/cxx_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum CXXTagCommonKind
enum CXXTagUnknownRole
{
CXXTagUnknownRoleREFERENCED,
CXXTagUnknownRoleVALUE,
};

enum CXXTagMemberRole
Expand Down

0 comments on commit ddf135e

Please sign in to comment.