Skip to content

Commit e7326d7

Browse files
authored
Merge pull request #3164 from fwmechanic/fix-missing-end-in-fully-qualified-tag
C++ fix: tags generated by --extras=+q now contain 'end' field
2 parents c0b04ae + be1b734 commit e7326d7

13 files changed

+101
-40
lines changed

Tmain/extras-field.d/stdout-expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
X input.cpp /^namespace X {$/;" n file: roles:def extras:fileScope end:6
2-
X::Y input.cpp /^ extern class Y {$/;" c namespace:X file: roles:def extras:fileScope,qualified
3-
X::Y::m input.cpp /^ int m;$/;" m class:X::Y typeref:typename:int file: roles:def extras:fileScope,qualified
4-
X::v input.cpp /^ } v;$/;" v namespace:X typeref:class:X::Y roles:def extras:qualified
2+
X::Y input.cpp /^ extern class Y {$/;" c namespace:X file: roles:def extras:fileScope,qualified end:5
3+
X::Y::m input.cpp /^ int m;$/;" m class:X::Y typeref:typename:int file: roles:def extras:fileScope,qualified end:4
4+
X::v input.cpp /^ } v;$/;" v namespace:X typeref:class:X::Y roles:def extras:qualified end:5
55
Y input.cpp /^ extern class Y {$/;" c namespace:X file: roles:def extras:fileScope end:5
66
Z input.cpp /^#define Z$/;" d file: roles:def extras:fileScope end:1
77
Z input.cpp /^#undef Z$/;" d file: roles:undef extras:fileScope,reference

parsers/cxx/cxx_parser.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ bool cxxParserParseEnum(void)
831831
tagEntryInfo * tag = cxxTagBegin(CXXTagKindENUM,pEnumName);
832832

833833
int iCorkQueueIndex = CORK_NIL;
834+
int iCorkQueueIndexFQ = CORK_NIL;
834835

835836
if(tag)
836837
{
@@ -852,7 +853,7 @@ bool cxxParserParseEnum(void)
852853
if(bIsScopedEnum)
853854
pszProperties = cxxTagSetProperties(CXXTagPropertyScopedEnum);
854855

855-
iCorkQueueIndex = cxxTagCommit();
856+
iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
856857

857858
if (pszProperties)
858859
vStringDelete (pszProperties);
@@ -894,7 +895,7 @@ bool cxxParserParseEnum(void)
894895
if(tag)
895896
{
896897
tag->isFileScope = !isInputHeaderFile();
897-
cxxTagCommit();
898+
cxxTagCommit(NULL);
898899
}
899900
}
900901

@@ -906,7 +907,11 @@ bool cxxParserParseEnum(void)
906907
}
907908

908909
if(iCorkQueueIndex > CORK_NIL)
910+
{
909911
cxxParserMarkEndLineForTagInCorkQueue(iCorkQueueIndex);
912+
if(iCorkQueueIndexFQ > CORK_NIL)
913+
cxxParserMarkEndLineForTagInCorkQueue(iCorkQueueIndexFQ);
914+
}
910915

911916
while(iPushedScopes > 0)
912917
{
@@ -1261,6 +1266,7 @@ static bool cxxParserParseClassStructOrUnionInternal(
12611266
tagEntryInfo * tag = cxxTagBegin(uTagKind,pClassName);
12621267

12631268
int iCorkQueueIndex = CORK_NIL;
1269+
int iCorkQueueIndexFQ = CORK_NIL;
12641270

12651271
bool bGotTemplate = g_cxx.pTemplateTokenChain &&
12661272
(g_cxx.pTemplateTokenChain->iCount > 0) &&
@@ -1315,7 +1321,7 @@ static bool cxxParserParseClassStructOrUnionInternal(
13151321

13161322
tag->isFileScope = !isInputHeaderFile();
13171323

1318-
iCorkQueueIndex = cxxTagCommit();
1324+
iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
13191325

13201326
}
13211327

@@ -1343,7 +1349,11 @@ static bool cxxParserParseClassStructOrUnionInternal(
13431349
}
13441350

13451351
if(iCorkQueueIndex > CORK_NIL)
1352+
{
13461353
cxxParserMarkEndLineForTagInCorkQueue(iCorkQueueIndex);
1354+
if(iCorkQueueIndexFQ > CORK_NIL)
1355+
cxxParserMarkEndLineForTagInCorkQueue(iCorkQueueIndexFQ);
1356+
}
13471357

13481358
iPushedScopes++;
13491359
while(iPushedScopes > 0)
@@ -1505,12 +1515,14 @@ void cxxParserAnalyzeOtherStatement(void)
15051515
// out its proper scope. Better avoid emitting this one.
15061516
CXX_DEBUG_PRINT("But it has been preceded by the 'friend' keyword: this is not a real prototype");
15071517
} else {
1508-
int piCorkQueueIndex;
1509-
int iScopesPushed = cxxParserEmitFunctionTags(&oInfo,CXXTagKindPROTOTYPE,CXXEmitFunctionTagsPushScopes, &piCorkQueueIndex);
1510-
if (piCorkQueueIndex != CORK_NIL)
1518+
int iCorkQueueIndex, iCorkQueueIndexFQ;
1519+
int iScopesPushed = cxxParserEmitFunctionTags(&oInfo,CXXTagKindPROTOTYPE,CXXEmitFunctionTagsPushScopes,&iCorkQueueIndex,&iCorkQueueIndexFQ);
1520+
if (iCorkQueueIndex != CORK_NIL)
15111521
{
15121522
CXXToken * t = cxxTokenChainLast(g_cxx.pTokenChain);
1513-
cxxParserSetEndLineForTagInCorkQueue (piCorkQueueIndex, t->iLineNumber);
1523+
cxxParserSetEndLineForTagInCorkQueue (iCorkQueueIndex, t->iLineNumber);
1524+
if (iCorkQueueIndexFQ != CORK_NIL)
1525+
cxxParserSetEndLineForTagInCorkQueue (iCorkQueueIndexFQ, t->iLineNumber);
15141526
}
15151527

15161528
if(bPrototypeParams)

parsers/cxx/cxx_parser_block.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,15 @@ bool cxxParserParseBlockHandleOpeningBracket(void)
141141

142142
int iScopes;
143143
int iCorkQueueIndex = CORK_NIL;
144+
int iCorkQueueIndexFQ = CORK_NIL;
144145

145146
CXXFunctionSignatureInfo oInfo;
146147

147148
if(eScopeType != CXXScopeTypeFunction)
148149
{
149150
// very likely a function definition
150151
// (but may be also a toplevel block, like "extern "C" { ... }")
151-
iScopes = cxxParserExtractFunctionSignatureBeforeOpeningBracket(&oInfo,&iCorkQueueIndex);
152+
iScopes = cxxParserExtractFunctionSignatureBeforeOpeningBracket(&oInfo,&iCorkQueueIndex,&iCorkQueueIndexFQ);
152153

153154
// FIXME: Handle syntax (5) of list initialization:
154155
// Class::Class() : member { arg1, arg2, ... } {...
@@ -237,8 +238,11 @@ bool cxxParserParseBlockHandleOpeningBracket(void)
237238
}
238239

239240
if(iCorkQueueIndex > CORK_NIL)
241+
{
240242
cxxParserSetEndLineForTagInCorkQueue(iCorkQueueIndex,uEndPosition);
241-
243+
if(iCorkQueueIndexFQ > CORK_NIL)
244+
cxxParserSetEndLineForTagInCorkQueue(iCorkQueueIndexFQ,uEndPosition);
245+
}
242246
while(iScopes > 0)
243247
{
244248
cxxScopePop();
@@ -702,7 +706,7 @@ static bool cxxParserParseBlockInternal(bool bExpectClosingBracket)
702706
if(tag)
703707
{
704708
tag->isFileScope = true;
705-
cxxTagCommit();
709+
cxxTagCommit(NULL);
706710
}
707711
} else {
708712
// what is this? (default: and similar things have been handled at keyword level)

parsers/cxx/cxx_parser_function.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ int cxxParserMaybeParseKnRStyleFunctionDefinition(void)
280280
tagEntryInfo * tag = cxxTagBegin(CXXTagKindFUNCTION,pIdentifier);
281281

282282
int iCorkQueueIndex = CORK_NIL;
283+
int iCorkQueueIndexFQ = CORK_NIL;
283284

284285
if(tag)
285286
{
@@ -302,7 +303,7 @@ int cxxParserMaybeParseKnRStyleFunctionDefinition(void)
302303
if(pszSignature)
303304
tag->extensionFields.signature = vStringValue(pszSignature);
304305

305-
iCorkQueueIndex = cxxTagCommit();
306+
iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
306307

307308
if(pszSignature)
308309
vStringDelete(pszSignature);
@@ -348,7 +349,11 @@ int cxxParserMaybeParseKnRStyleFunctionDefinition(void)
348349
}
349350

350351
if(iCorkQueueIndex > CORK_NIL)
352+
{
351353
cxxParserMarkEndLineForTagInCorkQueue(iCorkQueueIndex);
354+
if(iCorkQueueIndexFQ > CORK_NIL)
355+
cxxParserMarkEndLineForTagInCorkQueue(iCorkQueueIndexFQ);
356+
}
352357

353358
cxxScopePop();
354359
return 1;
@@ -1407,7 +1412,8 @@ int cxxParserEmitFunctionTags(
14071412
CXXFunctionSignatureInfo * pInfo,
14081413
unsigned int uTagKind,
14091414
unsigned int uOptions,
1410-
int * piCorkQueueIndex
1415+
int * piCorkQueueIndex,
1416+
int * piCorkQueueIndexFQ
14111417
)
14121418
{
14131419
CXX_DEBUG_ENTER();
@@ -1416,6 +1422,8 @@ int cxxParserEmitFunctionTags(
14161422

14171423
if(piCorkQueueIndex)
14181424
*piCorkQueueIndex = CORK_NIL;
1425+
if(piCorkQueueIndexFQ)
1426+
*piCorkQueueIndexFQ = CORK_NIL;
14191427

14201428
enum CXXScopeType eOuterScopeType = cxxScopeGetType();
14211429

@@ -1703,7 +1711,7 @@ int cxxParserEmitFunctionTags(
17031711
pszProperties = cxxTagSetProperties(uProperties);
17041712
}
17051713

1706-
int iCorkQueueIndex = cxxTagCommit();
1714+
int iCorkQueueIndex = cxxTagCommit(piCorkQueueIndexFQ);
17071715

17081716
if(piCorkQueueIndex)
17091717
*piCorkQueueIndex = iCorkQueueIndex;
@@ -1765,7 +1773,8 @@ int cxxParserEmitFunctionTags(
17651773
//
17661774
int cxxParserExtractFunctionSignatureBeforeOpeningBracket(
17671775
CXXFunctionSignatureInfo * pInfo,
1768-
int * piCorkQueueIndex
1776+
int * piCorkQueueIndex,
1777+
int * piCorkQueueIndexFQ
17691778
)
17701779
{
17711780
CXX_DEBUG_ENTER();
@@ -1805,7 +1814,8 @@ int cxxParserExtractFunctionSignatureBeforeOpeningBracket(
18051814
pInfo,
18061815
CXXTagKindFUNCTION,
18071816
CXXEmitFunctionTagsPushScopes,
1808-
piCorkQueueIndex
1817+
piCorkQueueIndex,
1818+
piCorkQueueIndexFQ
18091819
);
18101820

18111821
if(bParams)
@@ -1875,7 +1885,7 @@ void cxxParserEmitFunctionParameterTags(CXXTypedVariableSet * pInfo)
18751885
if (pInfo->uAnonymous & (0x1u << i))
18761886
markTagExtraBit(tag, XTAG_ANONYMOUS);
18771887

1878-
cxxTagCommit();
1888+
cxxTagCommit(NULL);
18791889

18801890
if(pTypeName)
18811891
{

parsers/cxx/cxx_parser_internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ typedef struct _CXXFunctionSignatureInfo
157157
int cxxParserMaybeParseKnRStyleFunctionDefinition(void);
158158
int cxxParserExtractFunctionSignatureBeforeOpeningBracket(
159159
CXXFunctionSignatureInfo * pInfo,
160-
int * piCorkQueueIndex
160+
int * piCorkQueueIndex,
161+
int * piCorkQueueIndexFQ
161162
);
162163

163164
/* This must be smaller than (sizeof(unsigned int) * 8).
@@ -201,7 +202,8 @@ int cxxParserEmitFunctionTags(
201202
CXXFunctionSignatureInfo * pInfo,
202203
unsigned int uTagKind,
203204
unsigned int uOptions,
204-
int * piCorkQueueIndex
205+
int * piCorkQueueIndex,
206+
int * piCorkQueueIndexFQ
205207
);
206208

207209
void cxxParserEmitFunctionParameterTags(CXXTypedVariableSet * pInfo);

parsers/cxx/cxx_parser_lambda.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ bool cxxParserHandleLambda(CXXToken * pParenthesis)
228228
}
229229

230230
int iCorkQueueIndex = CORK_NIL;
231+
int iCorkQueueIndexFQ = CORK_NIL;
231232

232233
if(tag)
233234
{
@@ -266,7 +267,7 @@ bool cxxParserHandleLambda(CXXToken * pParenthesis)
266267
if(pszSignature)
267268
tag->extensionFields.signature = vStringValue(pszSignature);
268269

269-
iCorkQueueIndex = cxxTagCommit();
270+
iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
270271

271272
if(pTypeName)
272273
cxxTokenDestroy(pTypeName);
@@ -297,7 +298,11 @@ bool cxxParserHandleLambda(CXXToken * pParenthesis)
297298
bool bRet = cxxParserParseBlock(true);
298299

299300
if(iCorkQueueIndex > CORK_NIL)
301+
{
300302
cxxParserMarkEndLineForTagInCorkQueue(iCorkQueueIndex);
303+
if(iCorkQueueIndexFQ > CORK_NIL)
304+
cxxParserMarkEndLineForTagInCorkQueue(iCorkQueueIndexFQ);
305+
}
301306

302307
cxxScopePop();
303308

parsers/cxx/cxx_parser_namespace.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ bool cxxParserParseNamespace(void)
6565

6666
int i;
6767

68-
int aCorkQueueIndices[MAX_NESTED_NAMESPACES];
69-
68+
struct { int leafnm, fqnm; } aCorkQueueIndices[MAX_NESTED_NAMESPACES];
7069
for(i=0;i<MAX_NESTED_NAMESPACES;i++)
71-
aCorkQueueIndices[i] = CORK_NIL;
70+
{
71+
aCorkQueueIndices[i].leafnm = CORK_NIL;
72+
aCorkQueueIndices[i].fqnm = CORK_NIL;
73+
}
7274

7375
if(!cxxParserParseNextToken())
7476
{
@@ -146,7 +148,7 @@ bool cxxParserParseNamespace(void)
146148
false
147149
);
148150

149-
cxxTagCommit();
151+
cxxTagCommit(NULL);
150152

151153
cxxTokenDestroy(pAliasedName);
152154
}
@@ -244,10 +246,13 @@ bool cxxParserParseNamespace(void)
244246

245247
vString * pszProperties = uProperties ? cxxTagSetProperties(uProperties) : NULL;
246248

247-
int iCorkQueueIndex = cxxTagCommit();
248-
249+
int iCorkQueueIndexFQ;
250+
int iCorkQueueIndex = cxxTagCommit(&iCorkQueueIndexFQ);
249251
if(iScopeCount < MAX_NESTED_NAMESPACES)
250-
aCorkQueueIndices[iScopeCount] = iCorkQueueIndex;
252+
{
253+
aCorkQueueIndices[iScopeCount].leafnm = iCorkQueueIndex;
254+
aCorkQueueIndices[iScopeCount].fqnm = iCorkQueueIndexFQ;
255+
}
251256

252257
if(pszProperties)
253258
vStringDelete(pszProperties);
@@ -283,7 +288,9 @@ bool cxxParserParseNamespace(void)
283288

284289
vString * pszProperties = uProperties ? cxxTagSetProperties(uProperties) : NULL;
285290

286-
aCorkQueueIndices[0] = cxxTagCommit();
291+
int iCorkQueueIndexFQ;
292+
aCorkQueueIndices[0].leafnm = cxxTagCommit(&iCorkQueueIndexFQ);
293+
aCorkQueueIndices[0].fqnm = iCorkQueueIndexFQ;
287294

288295
if(pszProperties)
289296
vStringDelete(pszProperties);
@@ -324,8 +331,13 @@ bool cxxParserParseNamespace(void)
324331
cxxScopePop();
325332
iScopeCount--;
326333

327-
if(iScopeCount < MAX_NESTED_NAMESPACES && aCorkQueueIndices[iScopeCount] > CORK_NIL)
328-
cxxParserMarkEndLineForTagInCorkQueue(aCorkQueueIndices[iScopeCount]);
334+
if(iScopeCount < MAX_NESTED_NAMESPACES)
335+
{
336+
if(aCorkQueueIndices[iScopeCount].leafnm > CORK_NIL)
337+
cxxParserMarkEndLineForTagInCorkQueue(aCorkQueueIndices[iScopeCount].leafnm);
338+
if(aCorkQueueIndices[iScopeCount].fqnm > CORK_NIL)
339+
cxxParserMarkEndLineForTagInCorkQueue(aCorkQueueIndices[iScopeCount].fqnm);
340+
}
329341
}
330342

331343
CXX_DEBUG_LEAVE_TEXT("Finished parsing namespace");

parsers/cxx/cxx_parser_template.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ void cxxParserEmitTemplateParameterTags(void)
851851
g_cxx.oTemplateParameters.aTypeEnds[i]
852852
);
853853

854-
cxxTagCommit();
854+
cxxTagCommit(NULL);
855855
if (pTypeToken)
856856
cxxTokenDestroy(pTypeToken);
857857
}

parsers/cxx/cxx_parser_typedef.c

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

445-
cxxTagCommit();
445+
cxxTagCommit(NULL);
446446

447447
if (
448448
bGotTemplate &&

parsers/cxx/cxx_parser_using.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bool cxxParserParseUsingClause(void)
152152
{
153153
tag->isFileScope = (cxxScopeGetType() == CXXScopeTypeNamespace) &&
154154
(!isInputHeaderFile());
155-
cxxTagCommit();
155+
cxxTagCommit(NULL);
156156
}
157157
}
158158
}

0 commit comments

Comments
 (0)