Skip to content

Commit 42b349d

Browse files
committed
Python: add "super" role to "class" kind
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent cfea32b commit 42b349d

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

Tmain/json-output-format.d/stdout-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C", "kindName": "struct", "path": "foreigndecl", "pattern": "declared in foreign languages"}
9898
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Go", "kindName": "package", "path": "imported", "pattern": "imported package"}
9999
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Go", "kindName": "unknown", "path": "receiverType", "pattern": "receiver type"}
100+
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python", "kindName": "class", "path": "super", "pattern": "super class"}
100101
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python", "kindName": "module", "path": "imported", "pattern": "imported modules"}
101102
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python", "kindName": "module", "path": "indirectlyImported", "pattern": "module imported in alternative name"}
102103
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python", "kindName": "module", "path": "namespace", "pattern": "namespace from where classes/variables/functions are imported"}

Tmain/list-roles.d/stdout-expected.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Protobuf m/message extension on extending the messag
9292
Python Y/unknown imported on imported from the other module
9393
Python Y/unknown indirectlyImported on classes/variables/functions/modules imported in alternative name
9494
Python Y/unknown ref off (EXPERIMENTAL)referenced anyhow
95+
Python c/class super on super class
9596
Python i/module imported on imported modules
9697
Python i/module indirectlyImported on module imported in alternative name
9798
Python i/module namespace on namespace from where classes/variables/functions are imported
@@ -226,6 +227,7 @@ Protobuf m/message extension on extending the messag
226227
Python Y/unknown imported on imported from the other module
227228
Python Y/unknown indirectlyImported on classes/variables/functions/modules imported in alternative name
228229
Python Y/unknown ref off (EXPERIMENTAL)referenced anyhow
230+
Python c/class super on super class
229231
Python i/module imported on imported modules
230232
Python i/module indirectlyImported on module imported in alternative name
231233
Python i/module namespace on namespace from where classes/variables/functions are imported

Units/parser-python.r/reftag.d/expected.tags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
a.b input.py /^import a.b$/;" i roles:imported
2-
object input.py /^class X(object):$/;" Y roles:ref
2+
object input.py /^class X(object):$/;" c roles:super
33
X input.py /^class X(object):$/;" c roles:def
44
__init__ input.py /^ def __init__(self, n):$/;" m class:X roles:def
55
self input.py /^ def __init__(self, n):$/;" z member:X.__init__ file: roles:def

Units/parser-python.r/simple.py.d/expected.tags

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ this input.py /^ @blah class this is seen???$/;" kind:class l
3737
_test.ignored_function.more_nesting.deeply_nested.even_more.this input.py /^ @blah class this is seen???$/;" kind:class line:41 language:Python scope:member:_test.ignored_function.more_nesting.deeply_nested.even_more file: inherits: access:private roles:def extras:qualified end:42 decorators:blah
3838
this input.py /^ @bleh def this also? good!$/;" kind:member line:42 language:Python scope:class:_test.ignored_function.more_nesting.deeply_nested.even_more.this access:public roles:def end:42 decorators:bleh
3939
_test.ignored_function.more_nesting.deeply_nested.even_more.this.this input.py /^ @bleh def this also? good!$/;" kind:member line:42 language:Python scope:class:_test.ignored_function.more_nesting.deeply_nested.even_more.this access:public roles:def extras:qualified end:42 decorators:bleh
40+
one input.py /^class two (one):$/;" kind:class line:46 language:Python roles:super extras:reference
4041
two input.py /^class two (one):$/;" kind:class line:46 language:Python inherits:one access:public roles:def end:48
4142
only input.py /^ def only(arg):$/;" kind:member line:48 language:Python scope:class:two access:public signature:(arg) roles:def end:48
4243
two.only input.py /^ def only(arg):$/;" kind:member line:48 language:Python scope:class:two access:public signature:(arg) roles:def extras:qualified end:48
44+
A input.py /^(A, B,$/;" kind:class line:53 language:Python roles:super extras:reference
45+
B input.py /^(A, B,$/;" kind:class line:53 language:Python roles:super extras:reference
46+
C input.py /^C):$/;" kind:class line:54 language:Python roles:super extras:reference
4347
three input.py /^three\\$/;" kind:class line:52 language:Python inherits:A, B, C access:public roles:def end:54
4448
foo input.py /^foo($/;" kind:function line:57 language:Python access:public signature:( x , y, z) roles:def end:60
4549
input.py input.py 1;" kind:file line:1 language:Python roles:def extras:inputFile end:60

parsers/python.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ typedef enum {
101101
PYTHON_UNKNOWN_INDIRECTLY_IMPORTED,
102102
} pythonUnknownRole;
103103

104+
typedef enum {
105+
PYTHON_CLASS_SUPERCLASS,
106+
} pythonClassRole;
107+
104108
/* Roles related to `import'
105109
* ==========================
106110
* import X X = (kind:module, role:imported)
@@ -135,8 +139,13 @@ static roleDefinition PythonUnknownRoles [] = {
135139
"classes/variables/functions/modules imported in alternative name" },
136140
};
137141

142+
static roleDefinition PythonClassRoles [] = {
143+
{ true, "super", "super class" },
144+
};
145+
138146
static kindDefinition PythonKinds[COUNT_KIND] = {
139-
{true, 'c', "class", "classes"},
147+
{true, 'c', "class", "classes",
148+
.referenceOnly = false, ATTACH_ROLES(PythonClassRoles) },
140149
{true, 'f', "function", "functions"},
141150
{true, 'm', "member", "class members"},
142151
{true, 'v', "variable", "variables"},
@@ -1042,13 +1051,41 @@ static void deleteTypedParam (struct typedParam *p)
10421051
static void parseInheritanceList (tokenInfo *const token,
10431052
vString *const inneritanceList)
10441053
{
1054+
tokenInfo *lastToken = newToken ();
1055+
10451056
do
10461057
{
1058+
copyToken (lastToken, token);
10471059
readTokenFull (token, true);
1060+
if (lastToken->type == TOKEN_IDENTIFIER
1061+
&& (token->type == ',' || token->type == ')'))
1062+
{
1063+
if (lastToken->reftag == CORK_NIL)
1064+
{
1065+
tagEntryInfo e;
1066+
initRefTagEntry(&e, vStringValue (lastToken->string),
1067+
K_CLASS, PYTHON_CLASS_SUPERCLASS);
1068+
e.lineNumber = lastToken->lineNumber;
1069+
e.filePosition = lastToken->filePosition;
1070+
lastToken->reftag = makeTagEntry (&e);
1071+
}
1072+
else
1073+
{
1074+
tagEntryInfo *e = getEntryInCorkQueue (lastToken->reftag);
1075+
if (e)
1076+
{
1077+
clearRoles(e);
1078+
e->kindIndex = K_CLASS;
1079+
assignRole(e, PYTHON_CLASS_SUPERCLASS);
1080+
}
1081+
}
1082+
}
10481083
if (token->type != ')')
10491084
reprCat (inneritanceList, token);
10501085
}
10511086
while (token->type != TOKEN_EOF && token->type != ')');
1087+
1088+
deleteToken (lastToken);
10521089
}
10531090

10541091
static void parseArglist (tokenInfo *const token,

0 commit comments

Comments
 (0)