Skip to content

Commit 80370d1

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

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
@@ -91,6 +91,7 @@
9191
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "C!macro", "path": "undef", "pattern": "undefined"}
9292
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Go!package", "path": "imported", "pattern": "imported package"}
9393
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Go!unknown", "path": "receiverType", "pattern": "receiver type"}
94+
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python!class", "path": "super", "pattern": "super class"}
9495
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python!module", "path": "imported", "pattern": "imported modules"}
9596
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python!module", "path": "indirectlyImported", "pattern": "module imported in alternative name"}
9697
{"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", "parserName": "Python!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
@@ -82,6 +82,7 @@ Protobuf m/message extension on extending the messag
8282
Python Y/unknown imported on imported from the other module
8383
Python Y/unknown indirectlyImported on classes/variables/functions/modules imported in alternative name
8484
Python Y/unknown ref off (EXPERIMENTAL)referenced anyhow
85+
Python c/class super on super class
8586
Python i/module imported on imported modules
8687
Python i/module indirectlyImported on module imported in alternative name
8788
Python i/module namespace on namespace from where classes/variables/functions are imported
@@ -201,6 +202,7 @@ Protobuf m/message extension on extending the messag
201202
Python Y/unknown imported on imported from the other module
202203
Python Y/unknown indirectlyImported on classes/variables/functions/modules imported in alternative name
203204
Python Y/unknown ref off (EXPERIMENTAL)referenced anyhow
205+
Python c/class super on super class
204206
Python i/module imported on imported modules
205207
Python i/module indirectlyImported on module imported in alternative name
206208
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"},
@@ -1044,13 +1053,41 @@ static void deleteTypedParam (struct typedParam *p)
10441053
static void parseInheritanceList (tokenInfo *const token,
10451054
vString *const inneritanceList)
10461055
{
1056+
tokenInfo *lastToken = newToken ();
1057+
10471058
do
10481059
{
1060+
copyToken (lastToken, token);
10491061
readTokenFull (token, true);
1062+
if (lastToken->type == TOKEN_IDENTIFIER
1063+
&& (token->type == ',' || token->type == ')'))
1064+
{
1065+
if (lastToken->reftag == CORK_NIL)
1066+
{
1067+
tagEntryInfo e;
1068+
initRefTagEntry(&e, vStringValue (lastToken->string),
1069+
K_CLASS, PYTHON_CLASS_SUPERCLASS);
1070+
e.lineNumber = lastToken->lineNumber;
1071+
e.filePosition = lastToken->filePosition;
1072+
lastToken->reftag = makeTagEntry (&e);
1073+
}
1074+
else
1075+
{
1076+
tagEntryInfo *e = getEntryInCorkQueue (lastToken->reftag);
1077+
if (e)
1078+
{
1079+
clearRoles(e);
1080+
e->kindIndex = K_CLASS;
1081+
assignRole(e, PYTHON_CLASS_SUPERCLASS);
1082+
}
1083+
}
1084+
}
10501085
if (token->type != ')')
10511086
reprCat (inneritanceList, token);
10521087
}
10531088
while (token->type != TOKEN_EOF && token->type != ')');
1089+
1090+
deleteToken (lastToken);
10541091
}
10551092

10561093
static void parseArglist (tokenInfo *const token,

0 commit comments

Comments
 (0)