@@ -96,6 +96,7 @@ typedef enum {
96
96
} pythonModuleRole ;
97
97
98
98
typedef enum {
99
+ PYTHON_UNKNOWN_REFERENCED ,
99
100
PYTHON_UNKNOWN_IMPORTED ,
100
101
PYTHON_UNKNOWN_INDIRECTLY_IMPORTED ,
101
102
} pythonUnknownRole ;
@@ -128,6 +129,7 @@ static roleDefinition PythonModuleRoles [] = {
128
129
};
129
130
130
131
static roleDefinition PythonUnknownRoles [] = {
132
+ { false,"ref" , "referenced anyhow" },
131
133
{ true, "imported" , "imported from the other module" },
132
134
{ true, "indirectlyImported" ,
133
135
"classes/variables/functions/modules imported in alternative name" },
@@ -201,6 +203,7 @@ typedef struct {
201
203
int indent ;
202
204
unsigned long lineNumber ;
203
205
MIOPos filePosition ;
206
+ int reftag ;
204
207
} tokenInfo ;
205
208
206
209
struct pythonNestingLevelUserData {
@@ -244,13 +247,23 @@ static accessType accessFromIdentifier (const vString *const ident,
244
247
return ACCESS_PROTECTED ;
245
248
}
246
249
247
- static void initPythonEntry (tagEntryInfo * const e , const tokenInfo * const token ,
250
+ static void useTokenAsPartOfTag (tokenInfo * const token )
251
+ {
252
+ if (token -> reftag == CORK_NIL )
253
+ return ;
254
+
255
+ markCorkEntryPlaceholder (token -> reftag , true);
256
+ token -> reftag = CORK_NIL ;
257
+ }
258
+
259
+ static void initPythonEntry (tagEntryInfo * const e , tokenInfo * const token ,
248
260
const pythonKind kind )
249
261
{
250
262
accessType access ;
251
263
int parentKind = -1 ;
252
264
NestingLevel * nl ;
253
265
266
+ useTokenAsPartOfTag (token );
254
267
initTagEntry (e , vStringValue (token -> string ), kind );
255
268
256
269
e -> lineNumber = token -> lineNumber ;
@@ -284,7 +297,7 @@ static void initPythonEntry (tagEntryInfo *const e, const tokenInfo *const token
284
297
e -> isFileScope = true;
285
298
}
286
299
287
- static int makeClassTag (const tokenInfo * const token ,
300
+ static int makeClassTag (tokenInfo * const token ,
288
301
const vString * const inheritance ,
289
302
const vString * const decorators )
290
303
{
@@ -307,7 +320,7 @@ static int makeClassTag (const tokenInfo *const token,
307
320
return CORK_NIL ;
308
321
}
309
322
310
- static int makeFunctionTag (const tokenInfo * const token ,
323
+ static int makeFunctionTag (tokenInfo * const token ,
311
324
const vString * const arglist ,
312
325
const vString * const decorators )
313
326
{
@@ -331,7 +344,7 @@ static int makeFunctionTag (const tokenInfo *const token,
331
344
return CORK_NIL ;
332
345
}
333
346
334
- static int makeSimplePythonTag (const tokenInfo * const token , pythonKind const kind )
347
+ static int makeSimplePythonTag (tokenInfo * const token , pythonKind const kind )
335
348
{
336
349
if (PythonKinds [kind ].enabled )
337
350
{
@@ -344,7 +357,7 @@ static int makeSimplePythonTag (const tokenInfo *const token, pythonKind const k
344
357
return CORK_NIL ;
345
358
}
346
359
347
- static int makeSimplePythonRefTag (const tokenInfo * const token ,
360
+ static int makeSimplePythonRefTag (tokenInfo * const token ,
348
361
const vString * const altName ,
349
362
pythonKind const kind ,
350
363
int roleIndex , xtagType xtag )
@@ -354,6 +367,7 @@ static int makeSimplePythonRefTag (const tokenInfo *const token,
354
367
{
355
368
tagEntryInfo e ;
356
369
370
+ useTokenAsPartOfTag (token );
357
371
initRefTagEntry (& e , vStringValue (altName ? altName : token -> string ),
358
372
kind , roleIndex );
359
373
@@ -393,6 +407,7 @@ static void clearPoolToken (void *data)
393
407
token -> lineNumber = getInputLineNumber ();
394
408
token -> filePosition = getInputFilePosition ();
395
409
vStringClear (token -> string );
410
+ token -> reftag = CORK_NIL ;
396
411
}
397
412
398
413
static void copyToken (tokenInfo * const dest , const tokenInfo * const src )
@@ -403,6 +418,7 @@ static void copyToken (tokenInfo *const dest, const tokenInfo *const src)
403
418
dest -> keyword = src -> keyword ;
404
419
dest -> indent = src -> indent ;
405
420
vStringCopy (dest -> string , src -> string );
421
+ dest -> reftag = src -> reftag ;
406
422
}
407
423
408
424
/* Skip a single or double quoted string. */
@@ -479,7 +495,7 @@ static void ungetToken (tokenInfo *const token)
479
495
copyToken (NextToken , token );
480
496
}
481
497
482
- static void readTokenFull (tokenInfo * const token , bool inclWhitespaces )
498
+ static void readTokenFullNoRefTag (tokenInfo * const token , bool inclWhitespaces )
483
499
{
484
500
int c ;
485
501
int n ;
@@ -694,6 +710,29 @@ static void readTokenFull (tokenInfo *const token, bool inclWhitespaces)
694
710
}
695
711
}
696
712
713
+ static void readTokenFull (tokenInfo * const token , bool inclWhitespaces )
714
+ {
715
+ readTokenFullNoRefTag (token , inclWhitespaces );
716
+
717
+ if (token -> type == TOKEN_IDENTIFIER
718
+ /* Don't make a ref tag for a number. */
719
+ && (vStringLength (token -> string ) > 0 &&
720
+ !isdigit ((unsigned char )vStringChar (token -> string , 0 )))
721
+ && PythonKinds [K_UNKNOWN ].enabled
722
+ && PythonUnknownRoles [PYTHON_UNKNOWN_REFERENCED ].enabled )
723
+ {
724
+ const bool in_subparser = (Lang_python != getInputLanguage ());
725
+ if (in_subparser )
726
+ pushLanguage (Lang_python );
727
+
728
+ token -> reftag = makeSimpleRefTag (token -> string ,
729
+ K_UNKNOWN , PYTHON_UNKNOWN_REFERENCED );
730
+
731
+ if (in_subparser )
732
+ popLanguage ();
733
+ }
734
+ }
735
+
697
736
static void readToken (tokenInfo * const token )
698
737
{
699
738
readTokenFull (token , false);
@@ -788,13 +827,18 @@ static void readQualifiedName (tokenInfo *const nameToken)
788
827
vString * qualifiedName = vStringNew ();
789
828
tokenInfo * token = newToken ();
790
829
830
+ unsigned long lineNumber = nameToken -> lineNumber ;
831
+ MIOPos filePosition = nameToken -> filePosition ;
832
+ useTokenAsPartOfTag (token );
833
+
791
834
while (nameToken -> type == TOKEN_IDENTIFIER ||
792
835
nameToken -> type == '.' )
793
836
{
794
837
vStringCat (qualifiedName , nameToken -> string );
795
838
copyToken (token , nameToken );
796
839
797
840
readToken (nameToken );
841
+ useTokenAsPartOfTag (nameToken );
798
842
}
799
843
/* put the last, non-matching, token back */
800
844
ungetToken (nameToken );
@@ -805,6 +849,13 @@ static void readQualifiedName (tokenInfo *const nameToken)
805
849
806
850
deleteToken (token );
807
851
vStringDelete (qualifiedName );
852
+
853
+ tagEntryInfo e ;
854
+ initRefTagEntry (& e , vStringValue (nameToken -> string ),
855
+ K_UNKNOWN , PYTHON_UNKNOWN_REFERENCED );
856
+ e .lineNumber = lineNumber ;
857
+ e .filePosition = filePosition ;
858
+ nameToken -> reftag = makeTagEntry (& e );
808
859
}
809
860
}
810
861
@@ -1490,7 +1541,7 @@ static bool parseVariable (tokenInfo *const token, const pythonKind kind)
1490
1541
1491
1542
do
1492
1543
{
1493
- const tokenInfo * const nameToken = nameTokens [i ];
1544
+ tokenInfo * const nameToken = nameTokens [i ];
1494
1545
vString * * type = & (nameTypes [i ++ ]);
1495
1546
1496
1547
readToken (token );
0 commit comments