Skip to content

Commit

Permalink
Merge pull request #3642 from masatake/cxx--optimize-nth-handling
Browse files Browse the repository at this point in the history
Cxx: scan the cork queue instead of the symtab to fill nth fields
  • Loading branch information
masatake committed Mar 20, 2023
2 parents 6e720ab + 0a96308 commit 8606b4b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
1 change: 1 addition & 0 deletions Tmain/c-large-enum.d/exit-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
22 changes: 22 additions & 0 deletions Tmain/c-large-enum.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright: 2023 Masatake YAMATO
# License: GPL-2

input=/tmp/c-large-enum.d-input.c
CTAGS="$1 --quiet --options=NONE"

i=0
{
echo "enum E {"
while [ $i -lt 32770 ]; do
printf "X%x," $i
i=$(($i + 1))
done
echo "};"
} > $input

${CTAGS} --sort=no -n --fields= --fields=+"{nth}" -x --_xformat='%{name} %{nth}' "$input" | tail -10
r=$?

rm -f "$input"

exit $r
Empty file.
10 changes: 10 additions & 0 deletions Tmain/c-large-enum.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
X7ff8 32760
X7ff9 32761
X7ffa 32762
X7ffb 32763
X7ffc 32764
X7ffd 32765
X7ffe 32766
X7fff 32767
X8000 32767
X8001 32767
35 changes: 25 additions & 10 deletions parsers/cxx/cxx_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,28 @@ void cxxTagUseTokensInRangeAsPartOfDefTags(int iCorkIndex, CXXToken * pFrom, CXX
}
}

static bool countSameKindEntry(int corkIndex,
tagEntryInfo * entry,
void * data)
static short cxxTagLookBackLastNth(langType iLangType, int iScopeIndex, unsigned int uKind)
{
unsigned int *uKind = data;
return (entry->kindIndex == *uKind);
for (size_t uCount = countEntryInCorkQueue (); uCount > (CORK_NIL + 1); uCount--)
{
int iCorkIndex = (int)(uCount - 1);
tagEntryInfo *pTag = getEntryInCorkQueue(iCorkIndex);
if (iCorkIndex == iScopeIndex)
return 0;
else if (pTag->extensionFields.scopeIndex == iScopeIndex
&& pTag->langType == iLangType
&& pTag->kindIndex == uKind)
{
return pTag->extensionFields.nth + (
/* Over-wrapped; if the value is too large for sizeof(nth),
* Don't increment more. */
((short)(pTag->extensionFields.nth + 1) > 0)
? 1
: 0
);
}
}
return NO_NTH_FIELD;
}

tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
Expand Down Expand Up @@ -311,14 +327,13 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
g_oCXXTag.extensionFields.scopeName = cxxScopeGetFullName();
// scopeIndex is used in the parser internally.
g_oCXXTag.extensionFields.scopeIndex = cxxScopeGetDefTag();
if (g_oCXXTag.extensionFields.scopeIndex != CORK_NIL)
if (isFieldEnabled(FIELD_NTH) && g_oCXXTag.extensionFields.scopeIndex != CORK_NIL)
{
if (uKind == CXXTagKindMEMBER || uKind == CXXTagKindENUMERATOR
|| uKind == CXXTagKindPARAMETER || uKind == CXXTagCPPKindTEMPLATEPARAM)
g_oCXXTag.extensionFields.nth =
(short) countEntriesInScope(g_oCXXTag.extensionFields.scopeIndex,
true,
countSameKindEntry, &uKind);
g_oCXXTag.extensionFields.nth = cxxTagLookBackLastNth(g_oCXXTag.langType,
g_oCXXTag.extensionFields.scopeIndex,
uKind);
}
}

Expand Down

0 comments on commit 8606b4b

Please sign in to comment.