Skip to content

Commit 2cb65d3

Browse files
authored
Merge pull request #3558 from masatake/cxx--nth-member
Cxx: fill "nth:" field for "member" and "enum" kind
2 parents 8f1b32e + b9249a8 commit 2cb65d3

File tree

16 files changed

+130
-15
lines changed

16 files changed

+130
-15
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+
};

main/entry.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,43 @@ extern bool foreachEntriesInScope (int corkIndex,
13381338
return true;
13391339
}
13401340

1341+
struct countData {
1342+
bool onlyDefinitionTag;
1343+
unsigned int count;
1344+
entryForeachFunc func;
1345+
void *cbData;
1346+
};
1347+
1348+
static bool countEntryMaybe (int corkIndex, tagEntryInfo *entry, void *cbData)
1349+
{
1350+
struct countData *data = cbData;
1351+
if (data->onlyDefinitionTag
1352+
&& !isRoleAssigned (entry, ROLE_DEFINITION_INDEX))
1353+
return true;
1354+
1355+
if (data->func == NULL
1356+
|| data->func (corkIndex, entry, data->cbData))
1357+
data->count++;
1358+
return true;
1359+
}
1360+
1361+
unsigned int countEntriesInScope (int corkIndex, bool onlyDefinitionTag,
1362+
entryForeachFunc func, void *cbData)
1363+
{
1364+
struct countData data = {
1365+
.onlyDefinitionTag = onlyDefinitionTag,
1366+
.count = 0,
1367+
.func = func,
1368+
.cbData = cbData,
1369+
};
1370+
1371+
foreachEntriesInScope (corkIndex, NULL,
1372+
&countEntryMaybe,
1373+
&data);
1374+
1375+
return data.count;
1376+
}
1377+
13411378
struct anyEntryInScopeData {
13421379
int index;
13431380
bool onlyDefinitionTag;

main/entry.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ struct sTagEntryInfo {
8181
int scopeIndex; /* cork queue entry for upper scope tag.
8282
This field is meaningful if the value
8383
is not CORK_NIL, scopeKindIndex is KIND_GHOST_INDEX,
84-
and scopeName is NULL. */
84+
and scopeName is NULL.
85+
CXX parser violates this rule; see the comment inside
86+
cxxTagBegin(). */
8587

8688
const char* signature;
8789

@@ -190,6 +192,9 @@ bool foreachEntriesInScope (int corkIndex,
190192
entryForeachFunc func,
191193
void *data);
192194

195+
unsigned int countEntriesInScope (int corkIndex, bool onlyDefinitionTag,
196+
entryForeachFunc func, void *data);
197+
193198
/* Return the cork index for NAME in the scope specified with CORKINDEX.
194199
* Even if more than one entries for NAME are in the scope, this function
195200
* just returns one of them. Returning CORK_NIL means there is no entry

parsers/cxx/cxx_parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ bool cxxParserParseEnum(void)
880880
pszProperties = cxxTagSetProperties(CXXTagPropertyScopedEnum);
881881

882882
iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
883+
cxxTagUseTokenAsPartOfDefTag(iCorkQueueIndex, pEnumName);
883884

884885
if (pszProperties)
885886
vStringDelete (pszProperties);
@@ -1352,6 +1353,7 @@ static bool cxxParserParseClassStructOrUnionInternal(
13521353
tag->isFileScope = !isInputHeaderFile();
13531354

13541355
iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
1356+
cxxTagUseTokenAsPartOfDefTag(iCorkQueueIndex, pClassName);
13551357

13561358
}
13571359

parsers/cxx/cxx_parser_function.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ int cxxParserMaybeParseKnRStyleFunctionDefinition(void)
304304
tag->extensionFields.signature = vStringValue(pszSignature);
305305

306306
iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
307+
cxxTagUseTokenAsPartOfDefTag(iCorkQueueIndex, pIdentifier);
307308

308309
if(pszSignature)
309310
vStringDelete(pszSignature);
@@ -1757,6 +1758,7 @@ int cxxParserEmitFunctionTags(
17571758
}
17581759

17591760
int iCorkQueueIndex = cxxTagCommit(piCorkQueueIndexFQ);
1761+
cxxTagUseTokenAsPartOfDefTag(iCorkQueueIndex, pIdentifier);
17601762

17611763
if(piCorkQueueIndex)
17621764
*piCorkQueueIndex = iCorkQueueIndex;
@@ -1923,7 +1925,6 @@ void cxxParserEmitFunctionParameterTags(CXXTypedVariableSet * pInfo)
19231925
} else {
19241926
pTypeName = NULL;
19251927
}
1926-
tag->extensionFields.nth = i;
19271928

19281929
tag->isFileScope = true;
19291930

parsers/cxx/cxx_parser_lambda.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ bool cxxParserHandleLambda(CXXToken * pParenthesis)
268268
tag->extensionFields.signature = vStringValue(pszSignature);
269269

270270
iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
271+
cxxTagUseTokenAsPartOfDefTag(iCorkQueueIndex, pIdentifier);
271272

272273
if(pTypeName)
273274
cxxTokenDestroy(pTypeName);

parsers/cxx/cxx_parser_template.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,6 @@ void cxxParserEmitTemplateParameterTags(void)
823823
if(!tag)
824824
continue;
825825

826-
tag->extensionFields.nth = (short)i;
827-
828826
CXXToken * pTypeToken = cxxTagCheckAndSetTypeField(
829827
g_cxx.oTemplateParameters.aTypeStarts[i],
830828
g_cxx.oTemplateParameters.aTypeEnds[i]

parsers/cxx/cxx_parser_typedef.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ void cxxParserExtractTypedef(
442442
if(bGotTemplate)
443443
cxxTagHandleTemplateFields();
444444

445-
cxxTagCommit(NULL);
445+
int iCorkQueueIndex = cxxTagCommit(NULL);
446+
cxxTagUseTokenAsPartOfDefTag(iCorkQueueIndex, t);
446447

447448
if (
448449
bGotTemplate &&

parsers/cxx/cxx_parser_variable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF
767767
cxxTagHandleTemplateFields();
768768

769769
iCorkIndex = cxxTagCommit(&iCorkIndexFQ);
770+
cxxTagUseTokenAsPartOfDefTag(iCorkIndexFQ, pIdentifier);
770771

771772
if(pTypeToken)
772773
cxxTokenDestroy(pTypeToken);

0 commit comments

Comments
 (0)