Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit eb4dc92

Browse files
authored
Merge pull request #125 from juanjux/fix/new_annotations
Use the new annotations
2 parents 5df023e + 0bfd5d7 commit eb4dc92

29 files changed

+333
-196
lines changed

driver/normalizer/annotation.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,26 @@ var AnnotationRules = On(Any).Self(
7171
),
7272

7373
// Comparison operators
74-
On(pyast.Eq).Roles(uast.Binary, uast.Operator, uast.Equal),
75-
On(pyast.NotEq).Roles(uast.Binary, uast.Operator, uast.Equal, uast.Not),
76-
On(pyast.Lt).Roles(uast.Binary, uast.Operator, uast.LessThan),
77-
On(pyast.LtE).Roles(uast.Binary, uast.Operator, uast.LessThanOrEqual),
78-
On(pyast.Gt).Roles(uast.Binary, uast.Operator, uast.GreaterThan),
79-
On(pyast.GtE).Roles(uast.Binary, uast.Operator, uast.GreaterThanOrEqual),
80-
On(pyast.Is).Roles(uast.Binary, uast.Operator, uast.Identical),
81-
On(pyast.IsNot).Roles(uast.Binary, uast.Operator, uast.Identical, uast.Not),
82-
On(pyast.In).Roles(uast.Binary, uast.Operator, uast.Contains),
83-
On(pyast.NotIn).Roles(uast.Binary, uast.Operator, uast.Contains, uast.Not),
84-
85-
// Aritmetic operators
86-
On(pyast.Add).Roles(uast.Binary, uast.Operator, uast.Add),
87-
On(pyast.Sub).Roles(uast.Binary, uast.Operator, uast.Substract),
88-
On(pyast.Mult).Roles(uast.Binary, uast.Operator, uast.Multiply),
89-
On(pyast.Div).Roles(uast.Binary, uast.Operator, uast.Divide),
90-
On(pyast.Mod).Roles(uast.Binary, uast.Operator, uast.Modulo),
91-
On(pyast.FloorDiv).Roles(uast.Binary, uast.Operator, uast.Divide, uast.Incomplete),
92-
On(pyast.Pow).Roles(uast.Binary, uast.Operator, uast.Incomplete),
93-
On(pyast.MatMult).Roles(uast.Binary, uast.Operator, uast.Multiply, uast.Incomplete),
74+
On(pyast.Eq).Roles(uast.Binary, uast.Operator, uast.Equal, uast.Relational),
75+
On(pyast.NotEq).Roles(uast.Binary, uast.Operator, uast.Equal, uast.Not, uast.Relational),
76+
On(pyast.Lt).Roles(uast.Binary, uast.Operator, uast.LessThan, uast.Relational),
77+
On(pyast.LtE).Roles(uast.Binary, uast.Operator, uast.LessThanOrEqual, uast.Relational),
78+
On(pyast.Gt).Roles(uast.Binary, uast.Operator, uast.GreaterThan, uast.Relational),
79+
On(pyast.GtE).Roles(uast.Binary, uast.Operator, uast.GreaterThanOrEqual, uast.Relational),
80+
On(pyast.Is).Roles(uast.Binary, uast.Operator, uast.Identical, uast.Relational),
81+
On(pyast.IsNot).Roles(uast.Binary, uast.Operator, uast.Identical, uast.Not, uast.Relational),
82+
On(pyast.In).Roles(uast.Binary, uast.Operator, uast.Contains, uast.Relational),
83+
On(pyast.NotIn).Roles(uast.Binary, uast.Operator, uast.Contains, uast.Not, uast.Relational),
84+
85+
// Arithmetic operators
86+
On(pyast.Add).Roles(uast.Binary, uast.Operator, uast.Add, uast.Arithmetic),
87+
On(pyast.Sub).Roles(uast.Binary, uast.Operator, uast.Substract, uast.Arithmetic),
88+
On(pyast.Mult).Roles(uast.Binary, uast.Operator, uast.Multiply, uast.Arithmetic),
89+
On(pyast.Div).Roles(uast.Binary, uast.Operator, uast.Divide, uast.Arithmetic),
90+
On(pyast.Mod).Roles(uast.Binary, uast.Operator, uast.Modulo, uast.Arithmetic),
91+
On(pyast.FloorDiv).Roles(uast.Binary, uast.Operator, uast.Divide, uast.Arithmetic, uast.Incomplete),
92+
On(pyast.Pow).Roles(uast.Binary, uast.Operator, uast.Arithmetic, uast.Incomplete),
93+
On(pyast.MatMult).Roles(uast.Binary, uast.Operator, uast.Multiply, uast.Arithmetic, uast.Incomplete),
9494

9595
// Bitwise operators
9696
On(pyast.LShift).Roles(uast.Binary, uast.Operator, uast.Bitwise, uast.LeftShift),
@@ -151,7 +151,7 @@ var AnnotationRules = On(Any).Self(
151151
On(pyast.AsyncFuncDecorators).Roles(uast.Function, uast.Declaration, uast.Call, uast.Incomplete),
152152
On(pyast.AsyncFuncDefBody).Roles(uast.Function, uast.Declaration, uast.Body),
153153
// FIXME: change to Function, Declaration, ArgumentS once the PR has been merged
154-
On(pyast.Lambda).Roles(uast.Function, uast.Declaration, uast.Expression, uast.Incomplete).Children(
154+
On(pyast.Lambda).Roles(uast.Function, uast.Declaration, uast.Expression, uast.Anonymous).Children(
155155
On(pyast.LambdaBody).Roles(uast.Function, uast.Declaration, uast.Body),
156156
argumentsAnn,
157157
),
@@ -304,12 +304,12 @@ var AnnotationRules = On(Any).Self(
304304
// have any semantic information by themselves and this we consider it comments
305305
// (some preprocessors or linters can use them, the runtimes ignore them). The
306306
// TOKEN will take the annotation in the UAST node so the information is keept in
307-
// any case. FIXME: need annotation or type UAST roles
308-
On(pyast.AnnAssign).Roles(uast.Operator, uast.Binary, uast.Assignment, uast.Comment, uast.Incomplete),
309-
On(HasInternalRole("annotation")).Roles(uast.Comment, uast.Incomplete),
310-
On(HasInternalRole("returns")).Roles(uast.Comment, uast.Incomplete),
307+
// any case.
308+
On(pyast.AnnAssign).Roles(uast.Operator, uast.Binary, uast.Assignment),
309+
On(HasInternalRole("annotation")).Roles(uast.Annotation),
310+
On(HasInternalRole("returns")).Roles(uast.Annotation),
311311

312-
// Python very odd ellipsis operatouast. Has a special rule in tonoder synthetic tokens
312+
// Python very odd ellipsis operator. Has a special rule in tonoder synthetic tokens
313313
// map to load it with the token "PythonEllipsisuast.Operator" and gets the role uast.Identifier
314314
On(pyast.Ellipsis).Roles(uast.Identifier, uast.Incomplete),
315315

fixtures/annotations.py.uast

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Module {
55
. Roles: File,Module
66
. Children: {
77
. . 0: AnnAssign {
8-
. . . Roles: Operator,Binary,Assignment,Comment,Incomplete
8+
. . . Roles: Operator,Binary,Assignment
99
. . . StartPosition: {
1010
. . . . Offset: 0
1111
. . . . Line: 1
@@ -17,7 +17,7 @@ Module {
1717
. . . }
1818
. . . Children: {
1919
. . . . 0: Name {
20-
. . . . . Roles: Identifier,Expression,Comment,Incomplete
20+
. . . . . Roles: Identifier,Expression,Annotation
2121
. . . . . TOKEN "int"
2222
. . . . . StartPosition: {
2323
. . . . . . Offset: 3
@@ -72,7 +72,7 @@ Module {
7272
. . . }
7373
. . }
7474
. . 1: AnnAssign {
75-
. . . Roles: Operator,Binary,Assignment,Comment,Incomplete
75+
. . . Roles: Operator,Binary,Assignment
7676
. . . StartPosition: {
7777
. . . . Offset: 11
7878
. . . . Line: 2
@@ -85,7 +85,7 @@ Module {
8585
. . . }
8686
. . . Children: {
8787
. . . . 0: Name {
88-
. . . . . Roles: Identifier,Expression,Comment,Incomplete
88+
. . . . . Roles: Identifier,Expression,Annotation
8989
. . . . . TOKEN "float"
9090
. . . . . StartPosition: {
9191
. . . . . . Offset: 14
@@ -165,7 +165,7 @@ Module {
165165
. . . . . . . }
166166
. . . . . . . Children: {
167167
. . . . . . . . 0: Name {
168-
. . . . . . . . . Roles: Identifier,Expression,Comment,Incomplete
168+
. . . . . . . . . Roles: Identifier,Expression,Annotation
169169
. . . . . . . . . TOKEN "int"
170170
. . . . . . . . . StartPosition: {
171171
. . . . . . . . . . Offset: 36
@@ -202,7 +202,7 @@ Module {
202202
. . . . . . . }
203203
. . . . . . . Children: {
204204
. . . . . . . . 0: Name {
205-
. . . . . . . . . Roles: Identifier,Expression,Comment,Incomplete
205+
. . . . . . . . . Roles: Identifier,Expression,Annotation
206206
. . . . . . . . . TOKEN "str"
207207
. . . . . . . . . StartPosition: {
208208
. . . . . . . . . . Offset: 44
@@ -265,7 +265,7 @@ Module {
265265
. . . . . }
266266
. . . . }
267267
. . . . 2: Name {
268-
. . . . . Roles: Identifier,Expression,Comment,Incomplete
268+
. . . . . Roles: Identifier,Expression,Annotation
269269
. . . . . TOKEN "float"
270270
. . . . . StartPosition: {
271271
. . . . . . Offset: 52

fixtures/aritmeticops.py.uast

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Module {
6161
. . . . . . . }
6262
. . . . . . }
6363
. . . . . . 2: Add {
64-
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Add
64+
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Add,Arithmetic
6565
. . . . . . . TOKEN "+"
6666
. . . . . . . Properties: {
6767
. . . . . . . . internalRole: op
@@ -128,7 +128,7 @@ Module {
128128
. . . . . . . }
129129
. . . . . . }
130130
. . . . . . 2: Sub {
131-
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Substract
131+
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Substract,Arithmetic
132132
. . . . . . . TOKEN "-"
133133
. . . . . . . Properties: {
134134
. . . . . . . . internalRole: op
@@ -195,7 +195,7 @@ Module {
195195
. . . . . . . }
196196
. . . . . . }
197197
. . . . . . 2: Mult {
198-
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply
198+
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply,Arithmetic
199199
. . . . . . . TOKEN "*"
200200
. . . . . . . Properties: {
201201
. . . . . . . . internalRole: op
@@ -262,7 +262,7 @@ Module {
262262
. . . . . . . }
263263
. . . . . . }
264264
. . . . . . 2: Div {
265-
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Divide
265+
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Divide,Arithmetic
266266
. . . . . . . TOKEN "/"
267267
. . . . . . . Properties: {
268268
. . . . . . . . internalRole: op
@@ -329,7 +329,7 @@ Module {
329329
. . . . . . . }
330330
. . . . . . }
331331
. . . . . . 2: FloorDiv {
332-
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Divide,Incomplete
332+
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Divide,Arithmetic,Incomplete
333333
. . . . . . . TOKEN "//"
334334
. . . . . . . Properties: {
335335
. . . . . . . . internalRole: op
@@ -396,7 +396,7 @@ Module {
396396
. . . . . . . }
397397
. . . . . . }
398398
. . . . . . 2: Mod {
399-
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Modulo
399+
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Modulo,Arithmetic
400400
. . . . . . . TOKEN "%%"
401401
. . . . . . . Properties: {
402402
. . . . . . . . internalRole: op
@@ -463,7 +463,7 @@ Module {
463463
. . . . . . . }
464464
. . . . . . }
465465
. . . . . . 2: Pow {
466-
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Incomplete
466+
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Arithmetic,Incomplete
467467
. . . . . . . TOKEN "**"
468468
. . . . . . . Properties: {
469469
. . . . . . . . internalRole: op

fixtures/augassign.py.uast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Module {
5757
. . . . . }
5858
. . . . }
5959
. . . . 2: Add {
60-
. . . . . Roles: Binary,Operator,Add,Operator,Binary
60+
. . . . . Roles: Binary,Operator,Add,Arithmetic,Operator,Binary
6161
. . . . . TOKEN "+"
6262
. . . . . Properties: {
6363
. . . . . . internalRole: op
@@ -113,7 +113,7 @@ Module {
113113
. . . . . }
114114
. . . . }
115115
. . . . 2: Sub {
116-
. . . . . Roles: Binary,Operator,Substract,Operator,Binary
116+
. . . . . Roles: Binary,Operator,Substract,Arithmetic,Operator,Binary
117117
. . . . . TOKEN "-"
118118
. . . . . Properties: {
119119
. . . . . . internalRole: op
@@ -169,7 +169,7 @@ Module {
169169
. . . . . }
170170
. . . . }
171171
. . . . 2: Mult {
172-
. . . . . Roles: Binary,Operator,Multiply,Operator,Binary
172+
. . . . . Roles: Binary,Operator,Multiply,Arithmetic,Operator,Binary
173173
. . . . . TOKEN "*"
174174
. . . . . Properties: {
175175
. . . . . . internalRole: op
@@ -225,7 +225,7 @@ Module {
225225
. . . . . }
226226
. . . . }
227227
. . . . 2: Div {
228-
. . . . . Roles: Binary,Operator,Divide,Operator,Binary
228+
. . . . . Roles: Binary,Operator,Divide,Arithmetic,Operator,Binary
229229
. . . . . TOKEN "/"
230230
. . . . . Properties: {
231231
. . . . . . internalRole: op

fixtures/bitwise.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Module {
549549
. . . . . . . . . }
550550
. . . . . . . . }
551551
. . . . . . . . 2: Add {
552-
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Add
552+
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Add,Arithmetic
553553
. . . . . . . . . TOKEN "+"
554554
. . . . . . . . . Properties: {
555555
. . . . . . . . . . internalRole: op
@@ -604,7 +604,7 @@ Module {
604604
. . . . . . . . . }
605605
. . . . . . . . }
606606
. . . . . . . . 2: Add {
607-
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Add
607+
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Add,Arithmetic
608608
. . . . . . . . . TOKEN "+"
609609
. . . . . . . . . Properties: {
610610
. . . . . . . . . . internalRole: op

fixtures/comparisonop.py.uast

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Module {
7272
. . . . . . . }
7373
. . . . . . . Children: {
7474
. . . . . . . . 0: Eq {
75-
. . . . . . . . . Roles: Binary,Operator,Equal
75+
. . . . . . . . . Roles: Binary,Operator,Equal,Relational
7676
. . . . . . . . . TOKEN "=="
7777
. . . . . . . . }
7878
. . . . . . . }
@@ -149,7 +149,7 @@ Module {
149149
. . . . . . . }
150150
. . . . . . . Children: {
151151
. . . . . . . . 0: NotEq {
152-
. . . . . . . . . Roles: Binary,Operator,Equal,Not
152+
. . . . . . . . . Roles: Binary,Operator,Equal,Not,Relational
153153
. . . . . . . . . TOKEN "!="
154154
. . . . . . . . }
155155
. . . . . . . }
@@ -290,11 +290,11 @@ Module {
290290
. . . . . . . }
291291
. . . . . . . Children: {
292292
. . . . . . . . 0: Eq {
293-
. . . . . . . . . Roles: Binary,Operator,Equal
293+
. . . . . . . . . Roles: Binary,Operator,Equal,Relational
294294
. . . . . . . . . TOKEN "=="
295295
. . . . . . . . }
296296
. . . . . . . . 1: Eq {
297-
. . . . . . . . . Roles: Binary,Operator,Equal
297+
. . . . . . . . . Roles: Binary,Operator,Equal,Relational
298298
. . . . . . . . . TOKEN "=="
299299
. . . . . . . . }
300300
. . . . . . . }
@@ -385,11 +385,11 @@ Module {
385385
. . . . . . . }
386386
. . . . . . . Children: {
387387
. . . . . . . . 0: Lt {
388-
. . . . . . . . . Roles: Binary,Operator,LessThan
388+
. . . . . . . . . Roles: Binary,Operator,LessThan,Relational
389389
. . . . . . . . . TOKEN "<"
390390
. . . . . . . . }
391391
. . . . . . . . 1: Gt {
392-
. . . . . . . . . Roles: Binary,Operator,GreaterThan
392+
. . . . . . . . . Roles: Binary,Operator,GreaterThan,Relational
393393
. . . . . . . . . TOKEN ">"
394394
. . . . . . . . }
395395
. . . . . . . }
@@ -480,11 +480,11 @@ Module {
480480
. . . . . . . }
481481
. . . . . . . Children: {
482482
. . . . . . . . 0: Lt {
483-
. . . . . . . . . Roles: Binary,Operator,LessThan
483+
. . . . . . . . . Roles: Binary,Operator,LessThan,Relational
484484
. . . . . . . . . TOKEN "<"
485485
. . . . . . . . }
486486
. . . . . . . . 1: NotEq {
487-
. . . . . . . . . Roles: Binary,Operator,Equal,Not
487+
. . . . . . . . . Roles: Binary,Operator,Equal,Not,Relational
488488
. . . . . . . . . TOKEN "!="
489489
. . . . . . . . }
490490
. . . . . . . }

fixtures/complex.py.uast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Module {
8787
. . . . . . . }
8888
. . . . . . }
8989
. . . . . . 2: Mult {
90-
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply
90+
. . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply,Arithmetic
9191
. . . . . . . TOKEN "*"
9292
. . . . . . . Properties: {
9393
. . . . . . . . internalRole: op

fixtures/comprehension_dict.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Module {
9191
. . . . . . . . . . . }
9292
. . . . . . . . . . . Children: {
9393
. . . . . . . . . . . . 0: Gt {
94-
. . . . . . . . . . . . . Roles: Binary,Operator,GreaterThan
94+
. . . . . . . . . . . . . Roles: Binary,Operator,GreaterThan,Relational
9595
. . . . . . . . . . . . . TOKEN ">"
9696
. . . . . . . . . . . . }
9797
. . . . . . . . . . . }
@@ -201,7 +201,7 @@ Module {
201201
. . . . . . . . . }
202202
. . . . . . . . }
203203
. . . . . . . . 2: Mult {
204-
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply
204+
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply,Arithmetic
205205
. . . . . . . . . TOKEN "*"
206206
. . . . . . . . . Properties: {
207207
. . . . . . . . . . internalRole: op

fixtures/comprehension_list.py.uast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Module {
7373
. . . . . . . . . }
7474
. . . . . . . . }
7575
. . . . . . . . 2: Mult {
76-
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply
76+
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply,Arithmetic
7777
. . . . . . . . . TOKEN "*"
7878
. . . . . . . . . Properties: {
7979
. . . . . . . . . . internalRole: op
@@ -146,7 +146,7 @@ Module {
146146
. . . . . . . . . . . }
147147
. . . . . . . . . . . Children: {
148148
. . . . . . . . . . . . 0: Gt {
149-
. . . . . . . . . . . . . Roles: Binary,Operator,GreaterThan
149+
. . . . . . . . . . . . . Roles: Binary,Operator,GreaterThan,Relational
150150
. . . . . . . . . . . . . TOKEN ">"
151151
. . . . . . . . . . . . }
152152
. . . . . . . . . . . }
@@ -264,7 +264,7 @@ Module {
264264
. . . . . . . . . }
265265
. . . . . . . . }
266266
. . . . . . . . 2: Mult {
267-
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply
267+
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply,Arithmetic
268268
. . . . . . . . . TOKEN "*"
269269
. . . . . . . . . Properties: {
270270
. . . . . . . . . . internalRole: op

fixtures/comprehension_set.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Module {
7373
. . . . . . . . . }
7474
. . . . . . . . }
7575
. . . . . . . . 2: Mult {
76-
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply
76+
. . . . . . . . . Roles: Expression,Binary,Operator,Binary,Operator,Multiply,Arithmetic
7777
. . . . . . . . . TOKEN "*"
7878
. . . . . . . . . Properties: {
7979
. . . . . . . . . . internalRole: op
@@ -146,7 +146,7 @@ Module {
146146
. . . . . . . . . . . }
147147
. . . . . . . . . . . Children: {
148148
. . . . . . . . . . . . 0: Gt {
149-
. . . . . . . . . . . . . Roles: Binary,Operator,GreaterThan
149+
. . . . . . . . . . . . . Roles: Binary,Operator,GreaterThan,Relational
150150
. . . . . . . . . . . . . TOKEN ">"
151151
. . . . . . . . . . . . }
152152
. . . . . . . . . . . }

0 commit comments

Comments
 (0)