Skip to content

Commit 8707721

Browse files
committed
Cxx: fill "nth:" field of tags of member and enumerator kinds
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 14eb82f commit 8707721

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Units/parser-cxx.r/field-nth.d/expected.tags

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ C input.h /^class C {};$/;" c template:<class T1,class T2,int I>
88
T1 input.h /^template<class T1, class T2, int I>$/;" Z class:C typeref:meta:class nth:0
99
T2 input.h /^template<class T1, class T2, int I>$/;" Z class:C typeref:meta:class nth:1
1010
I input.h /^template<class T1, class T2, int I>$/;" Z class:C typeref:typename:int nth:2
11+
D input.h /^class D {$/;" c
12+
i input.h /^ int i, j;$/;" m class:D typeref:typename:int nth:0
13+
j input.h /^ int i, j;$/;" m class:D typeref:typename:int nth:1
14+
c input.h /^ char c;$/;" m class:D typeref:typename:char nth:2
15+
color input.h /^enum color {$/;" g
16+
red input.h /^ red, green, blue,$/;" e enum:color nth:0
17+
green input.h /^ red, green, blue,$/;" e enum:color nth:1
18+
blue input.h /^ red, green, blue,$/;" e enum:color nth:2

Units/parser-cxx.r/field-nth.d/input.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ inline void f(int x, int y) {}
33

44
template<class T1, class T2, int I>
55
class C {};
6+
7+
class D {
8+
int i, j;
9+
char c;
10+
};
11+
12+
enum color {
13+
red, green, blue,
14+
};

parsers/cxx/cxx_tag.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ void cxxTagUseTokensInRangeAsPartOfDefTags(int iCorkIndex, CXXToken * pFrom, CXX
260260
}
261261
}
262262

263+
static bool countSameKindEntry(int corkIndex,
264+
tagEntryInfo * entry,
265+
void * data)
266+
{
267+
unsigned int *uKind = data;
268+
return (entry->kindIndex == *uKind);
269+
}
270+
263271
tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
264272
{
265273
kindDefinition * pKindDefinitions = g_cxx.pKindDefinitions;
@@ -288,6 +296,14 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
288296
g_oCXXTag.extensionFields.scopeName = cxxScopeGetFullName();
289297
// scopeIndex is used in the parser internally.
290298
g_oCXXTag.extensionFields.scopeIndex = cxxScopeGetDefTag();
299+
if (g_oCXXTag.extensionFields.scopeIndex != CORK_NIL)
300+
{
301+
if (uKind == CXXTagKindMEMBER || uKind == CXXTagKindENUMERATOR)
302+
g_oCXXTag.extensionFields.nth =
303+
(short) countEntriesInScope(g_oCXXTag.extensionFields.scopeIndex,
304+
true,
305+
countSameKindEntry, &uKind);
306+
}
291307
}
292308

293309
// FIXME: meaning of "is file scope" is quite debatable...
@@ -654,6 +670,8 @@ int cxxTagCommit(int *piCorkQueueIndexFQ)
654670
#endif
655671

656672
int iCorkQueueIndex = makeTagEntry(&g_oCXXTag);
673+
if (iCorkQueueIndex != CORK_NIL)
674+
registerEntry(iCorkQueueIndex);
657675

658676
// Handle --extra=+q
659677
if(!isXtagEnabled(XTAG_QUALIFIED_TAGS))

0 commit comments

Comments
 (0)