Skip to content

Commit 73095c5

Browse files
committed
Python: Add another AST test.
1 parent 7b8468d commit 73095c5

File tree

3 files changed

+365
-0
lines changed

3 files changed

+365
-0
lines changed
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
| test.py:0:0 | Module test | test.py:5:1 | ClassDef |
2+
| test.py:0:0 | Module test | test.py:11:1 | FunctionDef |
3+
| test.py:0:0 | Module test | test.py:14:1 | FunctionDef |
4+
| test.py:0:0 | Module test | test.py:17:1 | FunctionDef |
5+
| test.py:0:0 | Module test | test.py:51:1 | FunctionDef |
6+
| test.py:2:2 | deco1() | test.py:2:2 | deco1 |
7+
| test.py:2:2 | deco1() | test.py:3:1 | deco2()() |
8+
| test.py:3:1 | deco2() | test.py:3:2 | deco2 |
9+
| test.py:3:1 | deco2()() | test.py:3:1 | deco2() |
10+
| test.py:3:1 | deco2()() | test.py:4:2 | Attribute() |
11+
| test.py:4:2 | Attribute | test.py:4:2 | Attribute |
12+
| test.py:4:2 | Attribute | test.py:4:2 | deco3 |
13+
| test.py:4:2 | Attribute() | test.py:4:2 | Attribute |
14+
| test.py:4:2 | Attribute() | test.py:5:1 | ClassExpr |
15+
| test.py:5:1 | Class C | test.py:7:5 | FunctionDef |
16+
| test.py:5:1 | ClassDef | test.py:2:2 | deco1() |
17+
| test.py:5:1 | ClassDef | test.py:5:7 | C |
18+
| test.py:5:1 | ClassExpr | test.py:5:1 | Class C |
19+
| test.py:5:1 | ClassExpr | test.py:5:9 | Base |
20+
| test.py:7:5 | Function __init__ | test.py:7:18 | self |
21+
| test.py:7:5 | Function __init__ | test.py:8:9 | Pass |
22+
| test.py:7:5 | FunctionDef | test.py:7:5 | FunctionExpr |
23+
| test.py:7:5 | FunctionDef | test.py:7:9 | __init__ |
24+
| test.py:7:5 | FunctionExpr | test.py:7:5 | Function __init__ |
25+
| test.py:10:1 | Attribute() | test.py:10:2 | Attribute |
26+
| test.py:10:1 | Attribute()() | test.py:10:1 | Attribute() |
27+
| test.py:10:1 | Attribute()() | test.py:11:1 | FunctionExpr |
28+
| test.py:10:2 | Attribute | test.py:10:2 | deco4 |
29+
| test.py:11:1 | Function f | test.py:12:5 | Pass |
30+
| test.py:11:1 | FunctionDef | test.py:10:1 | Attribute()() |
31+
| test.py:11:1 | FunctionDef | test.py:11:5 | f |
32+
| test.py:11:1 | FunctionExpr | test.py:11:1 | Function f |
33+
| test.py:14:1 | Function f | test.py:14:7 | pos0 |
34+
| test.py:14:1 | Function f | test.py:14:13 | pos1 |
35+
| test.py:14:1 | Function f | test.py:14:20 | args |
36+
| test.py:14:1 | Function f | test.py:14:28 | kwargs |
37+
| test.py:14:1 | Function f | test.py:15:5 | Pass |
38+
| test.py:14:1 | FunctionDef | test.py:14:1 | FunctionExpr |
39+
| test.py:14:1 | FunctionDef | test.py:14:5 | f |
40+
| test.py:14:1 | FunctionExpr | test.py:14:1 | Function f |
41+
| test.py:17:1 | Function simple_stmts | test.py:18:5 | Pass |
42+
| test.py:17:1 | Function simple_stmts | test.py:19:5 | ExprStmt |
43+
| test.py:17:1 | Function simple_stmts | test.py:19:13 | Delete |
44+
| test.py:17:1 | Function simple_stmts | test.py:19:20 | Pass |
45+
| test.py:17:1 | Function simple_stmts | test.py:20:5 | If |
46+
| test.py:17:1 | Function simple_stmts | test.py:24:5 | AssignStmt |
47+
| test.py:17:1 | Function simple_stmts | test.py:44:5 | ExprStmt |
48+
| test.py:17:1 | Function simple_stmts | test.py:45:5 | ExprStmt |
49+
| test.py:17:1 | Function simple_stmts | test.py:46:5 | ExprStmt |
50+
| test.py:17:1 | Function simple_stmts | test.py:47:5 | ExprStmt |
51+
| test.py:17:1 | Function simple_stmts | test.py:48:5 | ExprStmt |
52+
| test.py:17:1 | Function simple_stmts | test.py:49:5 | ExprStmt |
53+
| test.py:17:1 | FunctionDef | test.py:17:1 | FunctionExpr |
54+
| test.py:17:1 | FunctionDef | test.py:17:5 | simple_stmts |
55+
| test.py:17:1 | FunctionExpr | test.py:17:1 | Function simple_stmts |
56+
| test.py:19:5 | ExprStmt | test.py:19:5 | foo() |
57+
| test.py:19:5 | foo() | test.py:19:5 | foo |
58+
| test.py:19:13 | Delete | test.py:19:17 | x |
59+
| test.py:20:5 | If | test.py:20:8 | thing |
60+
| test.py:20:5 | If | test.py:21:9 | For |
61+
| test.py:21:9 | For | test.py:21:13 | a |
62+
| test.py:21:9 | For | test.py:21:18 | b |
63+
| test.py:21:9 | For | test.py:22:13 | Pass |
64+
| test.py:24:5 | AssignStmt | test.py:24:5 | tmp |
65+
| test.py:24:5 | AssignStmt | test.py:25:9 | Yield |
66+
| test.py:25:9 | Yield | test.py:25:15 | Tuple |
67+
| test.py:25:15 | Tuple | test.py:25:15 | IntegerLiteral |
68+
| test.py:25:15 | Tuple | test.py:26:9 | name |
69+
| test.py:25:15 | Tuple | test.py:27:9 | Attribute |
70+
| test.py:25:15 | Tuple | test.py:28:9 | BinaryExpr |
71+
| test.py:25:15 | Tuple | test.py:29:9 | BinaryExpr |
72+
| test.py:25:15 | Tuple | test.py:30:9 | BinaryExpr |
73+
| test.py:25:15 | Tuple | test.py:31:9 | Attribute |
74+
| test.py:25:15 | Tuple | test.py:32:9 | Subscript |
75+
| test.py:25:15 | Tuple | test.py:33:9 | Lambda |
76+
| test.py:25:15 | Tuple | test.py:34:9 | BoolExpr |
77+
| test.py:25:15 | Tuple | test.py:35:9 | Compare |
78+
| test.py:25:15 | Tuple | test.py:36:9 | DictComp |
79+
| test.py:25:15 | Tuple | test.py:37:9 | SetComp |
80+
| test.py:25:15 | Tuple | test.py:38:9 | ListComp |
81+
| test.py:25:15 | Tuple | test.py:39:9 | List |
82+
| test.py:25:15 | Tuple | test.py:40:9 | Dict |
83+
| test.py:25:15 | Tuple | test.py:41:9 | Tuple |
84+
| test.py:25:15 | Tuple | test.py:42:10 | Tuple |
85+
| test.py:27:9 | Attribute | test.py:27:9 | attr |
86+
| test.py:28:9 | BinaryExpr | test.py:28:9 | a |
87+
| test.py:28:9 | BinaryExpr | test.py:28:13 | b |
88+
| test.py:29:9 | BinaryExpr | test.py:29:9 | IntegerLiteral |
89+
| test.py:29:9 | BinaryExpr | test.py:29:13 | IntegerLiteral |
90+
| test.py:30:9 | BinaryExpr | test.py:30:9 | FloatLiteral |
91+
| test.py:30:9 | BinaryExpr | test.py:30:15 | IntegerLiteral |
92+
| test.py:31:9 | Attribute | test.py:31:9 | Attribute |
93+
| test.py:31:9 | Attribute | test.py:31:9 | a |
94+
| test.py:32:9 | Attribute | test.py:32:9 | a() |
95+
| test.py:32:9 | Subscript | test.py:32:9 | Attribute |
96+
| test.py:32:9 | Subscript | test.py:32:15 | c |
97+
| test.py:32:9 | a() | test.py:32:9 | a |
98+
| test.py:33:9 | Function lambda | test.py:33:16 | x |
99+
| test.py:33:9 | Function lambda | test.py:33:19 | Return |
100+
| test.py:33:9 | Lambda | test.py:33:9 | Function lambda |
101+
| test.py:33:19 | BinaryExpr | test.py:33:19 | x |
102+
| test.py:33:19 | BinaryExpr | test.py:33:21 | IntegerLiteral |
103+
| test.py:33:19 | Return | test.py:33:19 | BinaryExpr |
104+
| test.py:34:9 | BoolExpr | test.py:34:9 | p |
105+
| test.py:34:9 | BoolExpr | test.py:34:14 | BoolExpr |
106+
| test.py:34:14 | BoolExpr | test.py:34:14 | q |
107+
| test.py:34:14 | BoolExpr | test.py:34:20 | BinaryExpr |
108+
| test.py:34:20 | BinaryExpr | test.py:34:20 | r |
109+
| test.py:34:20 | BinaryExpr | test.py:34:24 | s |
110+
| test.py:35:9 | Compare | test.py:35:9 | a |
111+
| test.py:35:9 | Compare | test.py:35:13 | b |
112+
| test.py:35:9 | Compare | test.py:35:17 | c |
113+
| test.py:35:9 | Compare | test.py:35:22 | IntegerLiteral |
114+
| test.py:36:9 | DictComp | test.py:36:9 | Function dictcomp |
115+
| test.py:36:9 | DictComp | test.py:36:26 | x |
116+
| test.py:36:9 | For | test.py:36:9 | .0 |
117+
| test.py:36:9 | For | test.py:36:9 | For |
118+
| test.py:36:9 | For | test.py:36:11 | ExprStmt |
119+
| test.py:36:9 | For | test.py:36:21 | z |
120+
| test.py:36:9 | For | test.py:36:32 | y |
121+
| test.py:36:9 | For | test.py:36:37 | z |
122+
| test.py:36:9 | Function dictcomp | test.py:36:9 | .0 |
123+
| test.py:36:9 | Function dictcomp | test.py:36:9 | For |
124+
| test.py:36:11 | ExprStmt | test.py:36:11 | Yield |
125+
| test.py:36:11 | Tuple | test.py:36:11 | IntegerLiteral |
126+
| test.py:36:11 | Tuple | test.py:36:15 | y |
127+
| test.py:36:11 | Yield | test.py:36:11 | Tuple |
128+
| test.py:37:9 | For | test.py:37:9 | .0 |
129+
| test.py:37:9 | For | test.py:37:9 | For |
130+
| test.py:37:9 | For | test.py:37:12 | ExprStmt |
131+
| test.py:37:9 | For | test.py:37:22 | z |
132+
| test.py:37:9 | For | test.py:37:33 | y |
133+
| test.py:37:9 | For | test.py:37:38 | z |
134+
| test.py:37:9 | Function setcomp | test.py:37:9 | .0 |
135+
| test.py:37:9 | Function setcomp | test.py:37:9 | For |
136+
| test.py:37:9 | SetComp | test.py:37:9 | Function setcomp |
137+
| test.py:37:9 | SetComp | test.py:37:27 | x |
138+
| test.py:37:12 | ExprStmt | test.py:37:12 | Yield |
139+
| test.py:37:12 | Tuple | test.py:37:12 | IntegerLiteral |
140+
| test.py:37:12 | Tuple | test.py:37:15 | y |
141+
| test.py:37:12 | Yield | test.py:37:12 | Tuple |
142+
| test.py:38:9 | For | test.py:38:9 | .0 |
143+
| test.py:38:9 | For | test.py:38:11 | ExprStmt |
144+
| test.py:38:9 | For | test.py:38:20 | y |
145+
| test.py:38:9 | Function listcomp | test.py:38:9 | .0 |
146+
| test.py:38:9 | Function listcomp | test.py:38:9 | For |
147+
| test.py:38:9 | ListComp | test.py:38:9 | Function listcomp |
148+
| test.py:38:9 | ListComp | test.py:38:25 | z |
149+
| test.py:38:11 | BinaryExpr | test.py:38:11 | y |
150+
| test.py:38:11 | BinaryExpr | test.py:38:14 | IntegerLiteral |
151+
| test.py:38:11 | ExprStmt | test.py:38:11 | Yield |
152+
| test.py:38:11 | Yield | test.py:38:11 | BinaryExpr |
153+
| test.py:42:10 | Tuple | test.py:42:10 | IntegerLiteral |
154+
| test.py:44:5 | ExprStmt | test.py:44:5 | foo() |
155+
| test.py:44:5 | foo() | test.py:44:5 | foo |
156+
| test.py:44:5 | foo() | test.py:44:9 | IntegerLiteral |
157+
| test.py:45:5 | ExprStmt | test.py:45:5 | foo() |
158+
| test.py:45:5 | foo() | test.py:45:5 | foo |
159+
| test.py:45:5 | foo() | test.py:45:9 | Keyword |
160+
| test.py:45:9 | Keyword | test.py:45:11 | IntegerLiteral |
161+
| test.py:46:5 | ExprStmt | test.py:46:5 | foo() |
162+
| test.py:46:5 | foo() | test.py:46:5 | foo |
163+
| test.py:46:5 | foo() | test.py:46:9 | IntegerLiteral |
164+
| test.py:46:5 | foo() | test.py:46:11 | IntegerLiteral |
165+
| test.py:46:5 | foo() | test.py:46:13 | Starred |
166+
| test.py:46:13 | Starred | test.py:46:14 | t |
167+
| test.py:47:5 | ExprStmt | test.py:47:5 | foo() |
168+
| test.py:47:5 | foo() | test.py:47:5 | foo |
169+
| test.py:47:5 | foo() | test.py:47:9 | IntegerLiteral |
170+
| test.py:47:5 | foo() | test.py:47:11 | Keyword |
171+
| test.py:47:5 | foo() | test.py:47:15 | Starred |
172+
| test.py:47:11 | Keyword | test.py:47:13 | IntegerLiteral |
173+
| test.py:47:15 | Starred | test.py:47:16 | t |
174+
| test.py:48:5 | ExprStmt | test.py:48:5 | foo() |
175+
| test.py:48:5 | foo() | test.py:48:5 | foo |
176+
| test.py:48:5 | foo() | test.py:48:9 | IntegerLiteral |
177+
| test.py:48:5 | foo() | test.py:48:11 | Keyword |
178+
| test.py:48:5 | foo() | test.py:48:15 | Starred |
179+
| test.py:48:5 | foo() | test.py:48:18 | DictUnpacking |
180+
| test.py:48:11 | Keyword | test.py:48:13 | IntegerLiteral |
181+
| test.py:48:15 | Starred | test.py:48:16 | t |
182+
| test.py:48:18 | DictUnpacking | test.py:48:20 | d |
183+
| test.py:49:5 | ExprStmt | test.py:49:5 | f() |
184+
| test.py:49:5 | f() | test.py:49:5 | f |
185+
| test.py:49:5 | f() | test.py:49:7 | DictUnpacking |
186+
| test.py:49:7 | DictUnpacking | test.py:49:9 | d |
187+
| test.py:51:1 | Function compound_stmts | test.py:52:5 | If |
188+
| test.py:51:1 | Function compound_stmts | test.py:56:5 | While |
189+
| test.py:51:1 | Function compound_stmts | test.py:61:5 | For |
190+
| test.py:51:1 | Function compound_stmts | test.py:63:5 | With |
191+
| test.py:51:1 | Function compound_stmts | test.py:65:5 | Try |
192+
| test.py:51:1 | Function compound_stmts | test.py:69:5 | Try |
193+
| test.py:51:1 | Function compound_stmts | test.py:73:5 | Try |
194+
| test.py:51:1 | Function compound_stmts | test.py:77:5 | Try |
195+
| test.py:51:1 | Function compound_stmts | test.py:81:5 | Try |
196+
| test.py:51:1 | Function compound_stmts | test.py:87:5 | Try |
197+
| test.py:51:1 | FunctionDef | test.py:51:1 | FunctionExpr |
198+
| test.py:51:1 | FunctionDef | test.py:51:5 | compound_stmts |
199+
| test.py:51:1 | FunctionExpr | test.py:51:1 | Function compound_stmts |
200+
| test.py:52:5 | If | test.py:52:8 | cond |
201+
| test.py:52:5 | If | test.py:53:9 | Return |
202+
| test.py:52:5 | If | test.py:55:9 | Raise |
203+
| test.py:53:9 | Return | test.py:53:16 | x |
204+
| test.py:55:9 | Raise | test.py:55:15 | y |
205+
| test.py:56:5 | While | test.py:56:11 | True |
206+
| test.py:56:5 | While | test.py:57:9 | If |
207+
| test.py:57:9 | If | test.py:57:12 | cond |
208+
| test.py:57:9 | If | test.py:58:13 | Break |
209+
| test.py:57:9 | If | test.py:60:13 | Continue |
210+
| test.py:61:5 | For | test.py:61:9 | x |
211+
| test.py:61:5 | For | test.py:61:14 | y |
212+
| test.py:61:5 | For | test.py:62:9 | Pass |
213+
| test.py:63:5 | With | test.py:63:5 | With |
214+
| test.py:63:5 | With | test.py:63:10 | a |
215+
| test.py:63:5 | With | test.py:63:15 | b |
216+
| test.py:63:5 | With | test.py:63:18 | c |
217+
| test.py:63:5 | With | test.py:63:23 | d |
218+
| test.py:63:5 | With | test.py:64:9 | ExprStmt |
219+
| test.py:64:9 | ExprStmt | test.py:64:9 | body |
220+
| test.py:65:5 | Try | test.py:66:9 | ExprStmt |
221+
| test.py:65:5 | Try | test.py:67:5 | ExceptStmt |
222+
| test.py:66:9 | ExprStmt | test.py:66:9 | t1 |
223+
| test.py:67:5 | ExceptStmt | test.py:68:9 | ExprStmt |
224+
| test.py:68:9 | ExprStmt | test.py:68:9 | e1 |
225+
| test.py:69:5 | Try | test.py:70:9 | ExprStmt |
226+
| test.py:69:5 | Try | test.py:71:5 | ExceptStmt |
227+
| test.py:70:9 | ExprStmt | test.py:70:9 | t2 |
228+
| test.py:71:5 | ExceptStmt | test.py:71:12 | Exception |
229+
| test.py:71:5 | ExceptStmt | test.py:72:9 | ExprStmt |
230+
| test.py:72:9 | ExprStmt | test.py:72:9 | e2 |
231+
| test.py:73:5 | Try | test.py:74:9 | ExprStmt |
232+
| test.py:73:5 | Try | test.py:75:5 | ExceptStmt |
233+
| test.py:74:9 | ExprStmt | test.py:74:9 | t3 |
234+
| test.py:75:5 | ExceptStmt | test.py:75:12 | Exception |
235+
| test.py:75:5 | ExceptStmt | test.py:75:25 | ex |
236+
| test.py:75:5 | ExceptStmt | test.py:76:9 | ExprStmt |
237+
| test.py:76:9 | ExprStmt | test.py:76:9 | e3 |
238+
| test.py:77:5 | Try | test.py:78:9 | ExprStmt |
239+
| test.py:77:5 | Try | test.py:80:9 | ExprStmt |
240+
| test.py:78:9 | ExprStmt | test.py:78:9 | t4 |
241+
| test.py:80:9 | ExprStmt | test.py:80:9 | f4 |
242+
| test.py:81:5 | Try | test.py:82:9 | ExprStmt |
243+
| test.py:81:5 | Try | test.py:83:5 | ExceptStmt |
244+
| test.py:81:5 | Try | test.py:86:9 | ExprStmt |
245+
| test.py:82:9 | ExprStmt | test.py:82:9 | t5 |
246+
| test.py:83:5 | ExceptStmt | test.py:83:12 | Exception |
247+
| test.py:83:5 | ExceptStmt | test.py:83:25 | ex |
248+
| test.py:83:5 | ExceptStmt | test.py:84:9 | ExprStmt |
249+
| test.py:84:9 | ExprStmt | test.py:84:9 | e5 |
250+
| test.py:86:9 | ExprStmt | test.py:86:9 | f5 |
251+
| test.py:87:5 | Try | test.py:88:9 | ExprStmt |
252+
| test.py:87:5 | Try | test.py:90:9 | Try |
253+
| test.py:88:9 | ExprStmt | test.py:88:9 | t6 |
254+
| test.py:90:9 | Try | test.py:91:13 | ExprStmt |
255+
| test.py:90:9 | Try | test.py:93:13 | ExprStmt |
256+
| test.py:91:13 | ExprStmt | test.py:91:13 | t7 |
257+
| test.py:93:13 | ExprStmt | test.py:93:13 | f7 |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import python
2+
3+
4+
string loc(AstNode a) {
5+
exists(Location l |
6+
l = a.getLocation() |
7+
result = l.getFile().getBaseName() + ":" + l.getStartLine() + ":" + l.getStartColumn()
8+
)
9+
}
10+
11+
from AstNode p, AstNode c
12+
where p.getAChildNode() = c
13+
select loc(p), p.toString(), loc(c), c.toString()
14+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
@deco1
3+
@deco2()
4+
@deco3.attr1.attr2
5+
class C(Base):
6+
7+
def __init__(self):
8+
pass
9+
10+
@deco4.attr()
11+
def f():
12+
pass
13+
14+
def f(pos0, pos1, *args, **kwargs):
15+
pass
16+
17+
def simple_stmts():
18+
pass
19+
foo() ; del x; pass
20+
if thing:
21+
for a in b:
22+
pass
23+
#Expressions
24+
tmp = (
25+
yield 3,
26+
name,
27+
attr.attrname,
28+
a + b,
29+
3 & 4,
30+
3.0 * 4,
31+
a.b.c.d,
32+
a().b[c],
33+
lambda x: x+1,
34+
p or q and r ^ s,
35+
a < b > c in 5,
36+
{ 1 : y for z in x for y in z},
37+
{ (1, y) for z in x for y in z},
38+
[ y**2 for y in z ],
39+
[],
40+
{},
41+
(),
42+
(1,),
43+
)
44+
foo(1)
45+
foo(a=1)
46+
foo(1,2,*t)
47+
foo(1,a=1,*t)
48+
foo(1,a=1,*t,**d)
49+
f(**d)
50+
51+
def compound_stmts():
52+
if cond:
53+
return x
54+
else:
55+
raise y
56+
while True:
57+
if cond:
58+
break
59+
else:
60+
continue
61+
for x in y:
62+
pass
63+
with a as b, c as d:
64+
body
65+
try:
66+
t1
67+
except:
68+
e1
69+
try:
70+
t2
71+
except Exception:
72+
e2
73+
try:
74+
t3
75+
except Exception as ex:
76+
e3
77+
try:
78+
t4
79+
finally:
80+
f4
81+
try:
82+
t5
83+
except Exception as ex:
84+
e5
85+
finally:
86+
f5
87+
try:
88+
t6
89+
finally:
90+
try:
91+
t7
92+
finally:
93+
f7
94+

0 commit comments

Comments
 (0)