Skip to content

Commit

Permalink
CXX: extract reference tags
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 1, 2022
1 parent 99d7fc5 commit 1fa9825
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Tmain/list-kinds-full.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
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,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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Tmain/nested-subparsers.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Units/parser-cxx.r/bug639644.cpp.d/expected.tags
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions Units/parser-cxx.r/namespace.cpp.d/expected.tags
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions misc/mini-geany.expected
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ x: externvar
z: parameter
L: label
D: macroparam
Y: unknown

Parsing buffer:
foo line: 1 kind: function lang: C
Expand Down
2 changes: 2 additions & 0 deletions parsers/cxx/cxx_parser_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,7 @@ int cxxParserEmitFunctionTags(
0
);

cxxTagUseTokensInRangeAsPartOfDefTags(CORK_NIL,pInfo->pIdentifierStart,pInfo->pIdentifierEnd);
cxxTokenChainDestroyRange(pInfo->pIdentifierChain,pInfo->pIdentifierStart,pInfo->pIdentifierEnd);

CXX_DEBUG_ASSERT(
Expand Down Expand Up @@ -1694,6 +1695,7 @@ int cxxParserEmitFunctionTags(
pInfo->pTemplateSpecializationEnd,
0
);
/* TODO */

// Tricky. We append it to the specialization chain which will
// be then used by cxxTagHandleTemplateFileds()
Expand Down
1 change: 1 addition & 0 deletions parsers/cxx/cxx_parser_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ bool cxxParserParseNamespace(void)
pLastIdentifier,
CXXTokenChainExtractRangeNoTrailingSpaces
);
/* TODO */

cxxTagSetField(
CXXTagCPPFieldAliasedName,
Expand Down
28 changes: 27 additions & 1 deletion parsers/cxx/cxx_parser_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1689,3 +1689,29 @@ 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->iCorkIndex = makeSimpleRefTag(g_cxx.pToken->pszWord,
CXXTagKindUNKNOWN,
CXXTagUnknownRoleREFERENCED);
g_cxx.pToken->bCorkIndexForReftag = true;

if (in_subparser)
popLanguage();
}
return r;
}
1 change: 1 addition & 0 deletions parsers/cxx/cxx_parser_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF
);

CXXToken * pScopeId = cxxTokenChainExtractRange(pScopeStart,pPartEnd->pPrev,0);
/* TODO */
cxxScopePush(
pScopeId,
CXXScopeTypeClass,
Expand Down
1 change: 1 addition & 0 deletions parsers/cxx/cxx_qtmoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static void qtMocMakeTagForProperty (CXXToken * pToken, const char *pszType)
{
tagEntryInfo tag;

cxxTagUseTokenAsPartOfDefTag(CORK_NIL, pToken);
initTagEntry(&tag,
vStringValue(pToken->pszWord),
K_PROPERTY);
Expand Down
Loading

0 comments on commit 1fa9825

Please sign in to comment.