Mercurial > cpython-lru_cache-weakref
annotate Python/Python-ast.c @ 35866:9f73dc0953d2 legacy-trunk
Whoops, checkin consistent versions of *all* files to stop polluting
a bunch of names
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Sun, 13 Nov 2005 19:14:20 +0000 |
| parents | 6867995a18a7 |
| children | 52f1d57f237d |
| rev | line source |
|---|---|
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
1 /* File automatically generated by ./Parser/asdl_c.py */ |
| 35742 | 2 |
| 3 #include "Python.h" | |
| 4 #include "Python-ast.h" | |
| 5 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
6 static int marshal_write_mod(PyObject **, int *, mod_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
7 static int marshal_write_stmt(PyObject **, int *, stmt_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
8 static int marshal_write_expr(PyObject **, int *, expr_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
9 static int marshal_write_expr_context(PyObject **, int *, expr_context_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
10 static int marshal_write_slice(PyObject **, int *, slice_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
11 static int marshal_write_boolop(PyObject **, int *, boolop_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
12 static int marshal_write_operator(PyObject **, int *, operator_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
13 static int marshal_write_unaryop(PyObject **, int *, unaryop_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
14 static int marshal_write_cmpop(PyObject **, int *, cmpop_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
15 static int marshal_write_comprehension(PyObject **, int *, comprehension_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
16 static int marshal_write_excepthandler(PyObject **, int *, excepthandler_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
17 static int marshal_write_arguments(PyObject **, int *, arguments_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
18 static int marshal_write_keyword(PyObject **, int *, keyword_ty); |
|
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
19 static int marshal_write_alias(PyObject **, int *, alias_ty); |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
20 |
| 35742 | 21 mod_ty |
| 22 Module(asdl_seq * body) | |
| 23 { | |
| 24 mod_ty p; | |
| 25 p = (mod_ty)malloc(sizeof(*p)); | |
| 26 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
27 PyErr_NoMemory(); |
| 35742 | 28 return NULL; |
| 29 } | |
| 30 p->kind = Module_kind; | |
| 31 p->v.Module.body = body; | |
| 32 return p; | |
| 33 } | |
| 34 | |
| 35 mod_ty | |
| 36 Interactive(asdl_seq * body) | |
| 37 { | |
| 38 mod_ty p; | |
| 39 p = (mod_ty)malloc(sizeof(*p)); | |
| 40 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
41 PyErr_NoMemory(); |
| 35742 | 42 return NULL; |
| 43 } | |
| 44 p->kind = Interactive_kind; | |
| 45 p->v.Interactive.body = body; | |
| 46 return p; | |
| 47 } | |
| 48 | |
| 49 mod_ty | |
| 50 Expression(expr_ty body) | |
| 51 { | |
| 52 mod_ty p; | |
| 53 if (!body) { | |
| 54 PyErr_SetString(PyExc_ValueError, | |
| 55 "field body is required for Expression"); | |
| 56 return NULL; | |
| 57 } | |
| 58 p = (mod_ty)malloc(sizeof(*p)); | |
| 59 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
60 PyErr_NoMemory(); |
| 35742 | 61 return NULL; |
| 62 } | |
| 63 p->kind = Expression_kind; | |
| 64 p->v.Expression.body = body; | |
| 65 return p; | |
| 66 } | |
| 67 | |
| 68 mod_ty | |
| 69 Suite(asdl_seq * body) | |
| 70 { | |
| 71 mod_ty p; | |
| 72 p = (mod_ty)malloc(sizeof(*p)); | |
| 73 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
74 PyErr_NoMemory(); |
| 35742 | 75 return NULL; |
| 76 } | |
| 77 p->kind = Suite_kind; | |
| 78 p->v.Suite.body = body; | |
| 79 return p; | |
| 80 } | |
| 81 | |
| 82 stmt_ty | |
| 83 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * | |
| 84 decorators, int lineno) | |
| 85 { | |
| 86 stmt_ty p; | |
| 87 if (!name) { | |
| 88 PyErr_SetString(PyExc_ValueError, | |
| 89 "field name is required for FunctionDef"); | |
| 90 return NULL; | |
| 91 } | |
| 92 if (!args) { | |
| 93 PyErr_SetString(PyExc_ValueError, | |
| 94 "field args is required for FunctionDef"); | |
| 95 return NULL; | |
| 96 } | |
| 97 p = (stmt_ty)malloc(sizeof(*p)); | |
| 98 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
99 PyErr_NoMemory(); |
| 35742 | 100 return NULL; |
| 101 } | |
| 102 p->kind = FunctionDef_kind; | |
| 103 p->v.FunctionDef.name = name; | |
| 104 p->v.FunctionDef.args = args; | |
| 105 p->v.FunctionDef.body = body; | |
| 106 p->v.FunctionDef.decorators = decorators; | |
| 107 p->lineno = lineno; | |
| 108 return p; | |
| 109 } | |
| 110 | |
| 111 stmt_ty | |
| 112 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno) | |
| 113 { | |
| 114 stmt_ty p; | |
| 115 if (!name) { | |
| 116 PyErr_SetString(PyExc_ValueError, | |
| 117 "field name is required for ClassDef"); | |
| 118 return NULL; | |
| 119 } | |
| 120 p = (stmt_ty)malloc(sizeof(*p)); | |
| 121 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
122 PyErr_NoMemory(); |
| 35742 | 123 return NULL; |
| 124 } | |
| 125 p->kind = ClassDef_kind; | |
| 126 p->v.ClassDef.name = name; | |
| 127 p->v.ClassDef.bases = bases; | |
| 128 p->v.ClassDef.body = body; | |
| 129 p->lineno = lineno; | |
| 130 return p; | |
| 131 } | |
| 132 | |
| 133 stmt_ty | |
| 134 Return(expr_ty value, int lineno) | |
| 135 { | |
| 136 stmt_ty p; | |
| 137 p = (stmt_ty)malloc(sizeof(*p)); | |
| 138 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
139 PyErr_NoMemory(); |
| 35742 | 140 return NULL; |
| 141 } | |
| 142 p->kind = Return_kind; | |
| 143 p->v.Return.value = value; | |
| 144 p->lineno = lineno; | |
| 145 return p; | |
| 146 } | |
| 147 | |
| 148 stmt_ty | |
| 149 Delete(asdl_seq * targets, int lineno) | |
| 150 { | |
| 151 stmt_ty p; | |
| 152 p = (stmt_ty)malloc(sizeof(*p)); | |
| 153 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
154 PyErr_NoMemory(); |
| 35742 | 155 return NULL; |
| 156 } | |
| 157 p->kind = Delete_kind; | |
| 158 p->v.Delete.targets = targets; | |
| 159 p->lineno = lineno; | |
| 160 return p; | |
| 161 } | |
| 162 | |
| 163 stmt_ty | |
| 164 Assign(asdl_seq * targets, expr_ty value, int lineno) | |
| 165 { | |
| 166 stmt_ty p; | |
| 167 if (!value) { | |
| 168 PyErr_SetString(PyExc_ValueError, | |
| 169 "field value is required for Assign"); | |
| 170 return NULL; | |
| 171 } | |
| 172 p = (stmt_ty)malloc(sizeof(*p)); | |
| 173 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
174 PyErr_NoMemory(); |
| 35742 | 175 return NULL; |
| 176 } | |
| 177 p->kind = Assign_kind; | |
| 178 p->v.Assign.targets = targets; | |
| 179 p->v.Assign.value = value; | |
| 180 p->lineno = lineno; | |
| 181 return p; | |
| 182 } | |
| 183 | |
| 184 stmt_ty | |
| 185 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno) | |
| 186 { | |
| 187 stmt_ty p; | |
| 188 if (!target) { | |
| 189 PyErr_SetString(PyExc_ValueError, | |
| 190 "field target is required for AugAssign"); | |
| 191 return NULL; | |
| 192 } | |
| 193 if (!op) { | |
| 194 PyErr_SetString(PyExc_ValueError, | |
| 195 "field op is required for AugAssign"); | |
| 196 return NULL; | |
| 197 } | |
| 198 if (!value) { | |
| 199 PyErr_SetString(PyExc_ValueError, | |
| 200 "field value is required for AugAssign"); | |
| 201 return NULL; | |
| 202 } | |
| 203 p = (stmt_ty)malloc(sizeof(*p)); | |
| 204 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
205 PyErr_NoMemory(); |
| 35742 | 206 return NULL; |
| 207 } | |
| 208 p->kind = AugAssign_kind; | |
| 209 p->v.AugAssign.target = target; | |
| 210 p->v.AugAssign.op = op; | |
| 211 p->v.AugAssign.value = value; | |
| 212 p->lineno = lineno; | |
| 213 return p; | |
| 214 } | |
| 215 | |
| 216 stmt_ty | |
| 217 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno) | |
| 218 { | |
| 219 stmt_ty p; | |
| 220 p = (stmt_ty)malloc(sizeof(*p)); | |
| 221 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
222 PyErr_NoMemory(); |
| 35742 | 223 return NULL; |
| 224 } | |
| 225 p->kind = Print_kind; | |
| 226 p->v.Print.dest = dest; | |
| 227 p->v.Print.values = values; | |
| 228 p->v.Print.nl = nl; | |
| 229 p->lineno = lineno; | |
| 230 return p; | |
| 231 } | |
| 232 | |
| 233 stmt_ty | |
| 234 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int | |
| 235 lineno) | |
| 236 { | |
| 237 stmt_ty p; | |
| 238 if (!target) { | |
| 239 PyErr_SetString(PyExc_ValueError, | |
| 240 "field target is required for For"); | |
| 241 return NULL; | |
| 242 } | |
| 243 if (!iter) { | |
| 244 PyErr_SetString(PyExc_ValueError, | |
| 245 "field iter is required for For"); | |
| 246 return NULL; | |
| 247 } | |
| 248 p = (stmt_ty)malloc(sizeof(*p)); | |
| 249 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
250 PyErr_NoMemory(); |
| 35742 | 251 return NULL; |
| 252 } | |
| 253 p->kind = For_kind; | |
| 254 p->v.For.target = target; | |
| 255 p->v.For.iter = iter; | |
| 256 p->v.For.body = body; | |
| 257 p->v.For.orelse = orelse; | |
| 258 p->lineno = lineno; | |
| 259 return p; | |
| 260 } | |
| 261 | |
| 262 stmt_ty | |
| 263 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno) | |
| 264 { | |
| 265 stmt_ty p; | |
| 266 if (!test) { | |
| 267 PyErr_SetString(PyExc_ValueError, | |
| 268 "field test is required for While"); | |
| 269 return NULL; | |
| 270 } | |
| 271 p = (stmt_ty)malloc(sizeof(*p)); | |
| 272 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
273 PyErr_NoMemory(); |
| 35742 | 274 return NULL; |
| 275 } | |
| 276 p->kind = While_kind; | |
| 277 p->v.While.test = test; | |
| 278 p->v.While.body = body; | |
| 279 p->v.While.orelse = orelse; | |
| 280 p->lineno = lineno; | |
| 281 return p; | |
| 282 } | |
| 283 | |
| 284 stmt_ty | |
| 285 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno) | |
| 286 { | |
| 287 stmt_ty p; | |
| 288 if (!test) { | |
| 289 PyErr_SetString(PyExc_ValueError, | |
| 290 "field test is required for If"); | |
| 291 return NULL; | |
| 292 } | |
| 293 p = (stmt_ty)malloc(sizeof(*p)); | |
| 294 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
295 PyErr_NoMemory(); |
| 35742 | 296 return NULL; |
| 297 } | |
| 298 p->kind = If_kind; | |
| 299 p->v.If.test = test; | |
| 300 p->v.If.body = body; | |
| 301 p->v.If.orelse = orelse; | |
| 302 p->lineno = lineno; | |
| 303 return p; | |
| 304 } | |
| 305 | |
| 306 stmt_ty | |
| 307 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno) | |
| 308 { | |
| 309 stmt_ty p; | |
| 310 p = (stmt_ty)malloc(sizeof(*p)); | |
| 311 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
312 PyErr_NoMemory(); |
| 35742 | 313 return NULL; |
| 314 } | |
| 315 p->kind = Raise_kind; | |
| 316 p->v.Raise.type = type; | |
| 317 p->v.Raise.inst = inst; | |
| 318 p->v.Raise.tback = tback; | |
| 319 p->lineno = lineno; | |
| 320 return p; | |
| 321 } | |
| 322 | |
| 323 stmt_ty | |
| 324 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno) | |
| 325 { | |
| 326 stmt_ty p; | |
| 327 p = (stmt_ty)malloc(sizeof(*p)); | |
| 328 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
329 PyErr_NoMemory(); |
| 35742 | 330 return NULL; |
| 331 } | |
| 332 p->kind = TryExcept_kind; | |
| 333 p->v.TryExcept.body = body; | |
| 334 p->v.TryExcept.handlers = handlers; | |
| 335 p->v.TryExcept.orelse = orelse; | |
| 336 p->lineno = lineno; | |
| 337 return p; | |
| 338 } | |
| 339 | |
| 340 stmt_ty | |
| 341 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno) | |
| 342 { | |
| 343 stmt_ty p; | |
| 344 p = (stmt_ty)malloc(sizeof(*p)); | |
| 345 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
346 PyErr_NoMemory(); |
| 35742 | 347 return NULL; |
| 348 } | |
| 349 p->kind = TryFinally_kind; | |
| 350 p->v.TryFinally.body = body; | |
| 351 p->v.TryFinally.finalbody = finalbody; | |
| 352 p->lineno = lineno; | |
| 353 return p; | |
| 354 } | |
| 355 | |
| 356 stmt_ty | |
| 357 Assert(expr_ty test, expr_ty msg, int lineno) | |
| 358 { | |
| 359 stmt_ty p; | |
| 360 if (!test) { | |
| 361 PyErr_SetString(PyExc_ValueError, | |
| 362 "field test is required for Assert"); | |
| 363 return NULL; | |
| 364 } | |
| 365 p = (stmt_ty)malloc(sizeof(*p)); | |
| 366 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
367 PyErr_NoMemory(); |
| 35742 | 368 return NULL; |
| 369 } | |
| 370 p->kind = Assert_kind; | |
| 371 p->v.Assert.test = test; | |
| 372 p->v.Assert.msg = msg; | |
| 373 p->lineno = lineno; | |
| 374 return p; | |
| 375 } | |
| 376 | |
| 377 stmt_ty | |
| 378 Import(asdl_seq * names, int lineno) | |
| 379 { | |
| 380 stmt_ty p; | |
| 381 p = (stmt_ty)malloc(sizeof(*p)); | |
| 382 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
383 PyErr_NoMemory(); |
| 35742 | 384 return NULL; |
| 385 } | |
| 386 p->kind = Import_kind; | |
| 387 p->v.Import.names = names; | |
| 388 p->lineno = lineno; | |
| 389 return p; | |
| 390 } | |
| 391 | |
| 392 stmt_ty | |
| 393 ImportFrom(identifier module, asdl_seq * names, int lineno) | |
| 394 { | |
| 395 stmt_ty p; | |
| 396 if (!module) { | |
| 397 PyErr_SetString(PyExc_ValueError, | |
| 398 "field module is required for ImportFrom"); | |
| 399 return NULL; | |
| 400 } | |
| 401 p = (stmt_ty)malloc(sizeof(*p)); | |
| 402 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
403 PyErr_NoMemory(); |
| 35742 | 404 return NULL; |
| 405 } | |
| 406 p->kind = ImportFrom_kind; | |
| 407 p->v.ImportFrom.module = module; | |
| 408 p->v.ImportFrom.names = names; | |
| 409 p->lineno = lineno; | |
| 410 return p; | |
| 411 } | |
| 412 | |
| 413 stmt_ty | |
| 414 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno) | |
| 415 { | |
| 416 stmt_ty p; | |
| 417 if (!body) { | |
| 418 PyErr_SetString(PyExc_ValueError, | |
| 419 "field body is required for Exec"); | |
| 420 return NULL; | |
| 421 } | |
| 422 p = (stmt_ty)malloc(sizeof(*p)); | |
| 423 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
424 PyErr_NoMemory(); |
| 35742 | 425 return NULL; |
| 426 } | |
| 427 p->kind = Exec_kind; | |
| 428 p->v.Exec.body = body; | |
| 429 p->v.Exec.globals = globals; | |
| 430 p->v.Exec.locals = locals; | |
| 431 p->lineno = lineno; | |
| 432 return p; | |
| 433 } | |
| 434 | |
| 435 stmt_ty | |
| 436 Global(asdl_seq * names, int lineno) | |
| 437 { | |
| 438 stmt_ty p; | |
| 439 p = (stmt_ty)malloc(sizeof(*p)); | |
| 440 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
441 PyErr_NoMemory(); |
| 35742 | 442 return NULL; |
| 443 } | |
| 444 p->kind = Global_kind; | |
| 445 p->v.Global.names = names; | |
| 446 p->lineno = lineno; | |
| 447 return p; | |
| 448 } | |
| 449 | |
| 450 stmt_ty | |
| 451 Expr(expr_ty value, int lineno) | |
| 452 { | |
| 453 stmt_ty p; | |
| 454 if (!value) { | |
| 455 PyErr_SetString(PyExc_ValueError, | |
| 456 "field value is required for Expr"); | |
| 457 return NULL; | |
| 458 } | |
| 459 p = (stmt_ty)malloc(sizeof(*p)); | |
| 460 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
461 PyErr_NoMemory(); |
| 35742 | 462 return NULL; |
| 463 } | |
| 464 p->kind = Expr_kind; | |
| 465 p->v.Expr.value = value; | |
| 466 p->lineno = lineno; | |
| 467 return p; | |
| 468 } | |
| 469 | |
| 470 stmt_ty | |
| 471 Pass(int lineno) | |
| 472 { | |
| 473 stmt_ty p; | |
| 474 p = (stmt_ty)malloc(sizeof(*p)); | |
| 475 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
476 PyErr_NoMemory(); |
| 35742 | 477 return NULL; |
| 478 } | |
| 479 p->kind = Pass_kind; | |
| 480 p->lineno = lineno; | |
| 481 return p; | |
| 482 } | |
| 483 | |
| 484 stmt_ty | |
| 485 Break(int lineno) | |
| 486 { | |
| 487 stmt_ty p; | |
| 488 p = (stmt_ty)malloc(sizeof(*p)); | |
| 489 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
490 PyErr_NoMemory(); |
| 35742 | 491 return NULL; |
| 492 } | |
| 493 p->kind = Break_kind; | |
| 494 p->lineno = lineno; | |
| 495 return p; | |
| 496 } | |
| 497 | |
| 498 stmt_ty | |
| 499 Continue(int lineno) | |
| 500 { | |
| 501 stmt_ty p; | |
| 502 p = (stmt_ty)malloc(sizeof(*p)); | |
| 503 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
504 PyErr_NoMemory(); |
| 35742 | 505 return NULL; |
| 506 } | |
| 507 p->kind = Continue_kind; | |
| 508 p->lineno = lineno; | |
| 509 return p; | |
| 510 } | |
| 511 | |
| 512 expr_ty | |
| 513 BoolOp(boolop_ty op, asdl_seq * values, int lineno) | |
| 514 { | |
| 515 expr_ty p; | |
| 516 if (!op) { | |
| 517 PyErr_SetString(PyExc_ValueError, | |
| 518 "field op is required for BoolOp"); | |
| 519 return NULL; | |
| 520 } | |
| 521 p = (expr_ty)malloc(sizeof(*p)); | |
| 522 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
523 PyErr_NoMemory(); |
| 35742 | 524 return NULL; |
| 525 } | |
| 526 p->kind = BoolOp_kind; | |
| 527 p->v.BoolOp.op = op; | |
| 528 p->v.BoolOp.values = values; | |
| 529 p->lineno = lineno; | |
| 530 return p; | |
| 531 } | |
| 532 | |
| 533 expr_ty | |
| 534 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno) | |
| 535 { | |
| 536 expr_ty p; | |
| 537 if (!left) { | |
| 538 PyErr_SetString(PyExc_ValueError, | |
| 539 "field left is required for BinOp"); | |
| 540 return NULL; | |
| 541 } | |
| 542 if (!op) { | |
| 543 PyErr_SetString(PyExc_ValueError, | |
| 544 "field op is required for BinOp"); | |
| 545 return NULL; | |
| 546 } | |
| 547 if (!right) { | |
| 548 PyErr_SetString(PyExc_ValueError, | |
| 549 "field right is required for BinOp"); | |
| 550 return NULL; | |
| 551 } | |
| 552 p = (expr_ty)malloc(sizeof(*p)); | |
| 553 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
554 PyErr_NoMemory(); |
| 35742 | 555 return NULL; |
| 556 } | |
| 557 p->kind = BinOp_kind; | |
| 558 p->v.BinOp.left = left; | |
| 559 p->v.BinOp.op = op; | |
| 560 p->v.BinOp.right = right; | |
| 561 p->lineno = lineno; | |
| 562 return p; | |
| 563 } | |
| 564 | |
| 565 expr_ty | |
| 566 UnaryOp(unaryop_ty op, expr_ty operand, int lineno) | |
| 567 { | |
| 568 expr_ty p; | |
| 569 if (!op) { | |
| 570 PyErr_SetString(PyExc_ValueError, | |
| 571 "field op is required for UnaryOp"); | |
| 572 return NULL; | |
| 573 } | |
| 574 if (!operand) { | |
| 575 PyErr_SetString(PyExc_ValueError, | |
| 576 "field operand is required for UnaryOp"); | |
| 577 return NULL; | |
| 578 } | |
| 579 p = (expr_ty)malloc(sizeof(*p)); | |
| 580 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
581 PyErr_NoMemory(); |
| 35742 | 582 return NULL; |
| 583 } | |
| 584 p->kind = UnaryOp_kind; | |
| 585 p->v.UnaryOp.op = op; | |
| 586 p->v.UnaryOp.operand = operand; | |
| 587 p->lineno = lineno; | |
| 588 return p; | |
| 589 } | |
| 590 | |
| 591 expr_ty | |
| 592 Lambda(arguments_ty args, expr_ty body, int lineno) | |
| 593 { | |
| 594 expr_ty p; | |
| 595 if (!args) { | |
| 596 PyErr_SetString(PyExc_ValueError, | |
| 597 "field args is required for Lambda"); | |
| 598 return NULL; | |
| 599 } | |
| 600 if (!body) { | |
| 601 PyErr_SetString(PyExc_ValueError, | |
| 602 "field body is required for Lambda"); | |
| 603 return NULL; | |
| 604 } | |
| 605 p = (expr_ty)malloc(sizeof(*p)); | |
| 606 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
607 PyErr_NoMemory(); |
| 35742 | 608 return NULL; |
| 609 } | |
| 610 p->kind = Lambda_kind; | |
| 611 p->v.Lambda.args = args; | |
| 612 p->v.Lambda.body = body; | |
| 613 p->lineno = lineno; | |
| 614 return p; | |
| 615 } | |
| 616 | |
| 617 expr_ty | |
| 618 Dict(asdl_seq * keys, asdl_seq * values, int lineno) | |
| 619 { | |
| 620 expr_ty p; | |
| 621 p = (expr_ty)malloc(sizeof(*p)); | |
| 622 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
623 PyErr_NoMemory(); |
| 35742 | 624 return NULL; |
| 625 } | |
| 626 p->kind = Dict_kind; | |
| 627 p->v.Dict.keys = keys; | |
| 628 p->v.Dict.values = values; | |
| 629 p->lineno = lineno; | |
| 630 return p; | |
| 631 } | |
| 632 | |
| 633 expr_ty | |
| 634 ListComp(expr_ty elt, asdl_seq * generators, int lineno) | |
| 635 { | |
| 636 expr_ty p; | |
| 637 if (!elt) { | |
| 638 PyErr_SetString(PyExc_ValueError, | |
| 639 "field elt is required for ListComp"); | |
| 640 return NULL; | |
| 641 } | |
| 642 p = (expr_ty)malloc(sizeof(*p)); | |
| 643 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
644 PyErr_NoMemory(); |
| 35742 | 645 return NULL; |
| 646 } | |
| 647 p->kind = ListComp_kind; | |
| 648 p->v.ListComp.elt = elt; | |
| 649 p->v.ListComp.generators = generators; | |
| 650 p->lineno = lineno; | |
| 651 return p; | |
| 652 } | |
| 653 | |
| 654 expr_ty | |
| 655 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno) | |
| 656 { | |
| 657 expr_ty p; | |
| 658 if (!elt) { | |
| 659 PyErr_SetString(PyExc_ValueError, | |
| 660 "field elt is required for GeneratorExp"); | |
| 661 return NULL; | |
| 662 } | |
| 663 p = (expr_ty)malloc(sizeof(*p)); | |
| 664 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
665 PyErr_NoMemory(); |
| 35742 | 666 return NULL; |
| 667 } | |
| 668 p->kind = GeneratorExp_kind; | |
| 669 p->v.GeneratorExp.elt = elt; | |
| 670 p->v.GeneratorExp.generators = generators; | |
| 671 p->lineno = lineno; | |
| 672 return p; | |
| 673 } | |
| 674 | |
| 675 expr_ty | |
| 676 Yield(expr_ty value, int lineno) | |
| 677 { | |
| 678 expr_ty p; | |
| 679 p = (expr_ty)malloc(sizeof(*p)); | |
| 680 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
681 PyErr_NoMemory(); |
| 35742 | 682 return NULL; |
| 683 } | |
| 684 p->kind = Yield_kind; | |
| 685 p->v.Yield.value = value; | |
| 686 p->lineno = lineno; | |
| 687 return p; | |
| 688 } | |
| 689 | |
| 690 expr_ty | |
| 691 Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno) | |
| 692 { | |
| 693 expr_ty p; | |
| 694 if (!left) { | |
| 695 PyErr_SetString(PyExc_ValueError, | |
| 696 "field left is required for Compare"); | |
| 697 return NULL; | |
| 698 } | |
| 699 p = (expr_ty)malloc(sizeof(*p)); | |
| 700 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
701 PyErr_NoMemory(); |
| 35742 | 702 return NULL; |
| 703 } | |
| 704 p->kind = Compare_kind; | |
| 705 p->v.Compare.left = left; | |
| 706 p->v.Compare.ops = ops; | |
| 707 p->v.Compare.comparators = comparators; | |
| 708 p->lineno = lineno; | |
| 709 return p; | |
| 710 } | |
| 711 | |
| 712 expr_ty | |
| 713 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs, | |
| 714 expr_ty kwargs, int lineno) | |
| 715 { | |
| 716 expr_ty p; | |
| 717 if (!func) { | |
| 718 PyErr_SetString(PyExc_ValueError, | |
| 719 "field func is required for Call"); | |
| 720 return NULL; | |
| 721 } | |
| 722 p = (expr_ty)malloc(sizeof(*p)); | |
| 723 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
724 PyErr_NoMemory(); |
| 35742 | 725 return NULL; |
| 726 } | |
| 727 p->kind = Call_kind; | |
| 728 p->v.Call.func = func; | |
| 729 p->v.Call.args = args; | |
| 730 p->v.Call.keywords = keywords; | |
| 731 p->v.Call.starargs = starargs; | |
| 732 p->v.Call.kwargs = kwargs; | |
| 733 p->lineno = lineno; | |
| 734 return p; | |
| 735 } | |
| 736 | |
| 737 expr_ty | |
| 738 Repr(expr_ty value, int lineno) | |
| 739 { | |
| 740 expr_ty p; | |
| 741 if (!value) { | |
| 742 PyErr_SetString(PyExc_ValueError, | |
| 743 "field value is required for Repr"); | |
| 744 return NULL; | |
| 745 } | |
| 746 p = (expr_ty)malloc(sizeof(*p)); | |
| 747 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
748 PyErr_NoMemory(); |
| 35742 | 749 return NULL; |
| 750 } | |
| 751 p->kind = Repr_kind; | |
| 752 p->v.Repr.value = value; | |
| 753 p->lineno = lineno; | |
| 754 return p; | |
| 755 } | |
| 756 | |
| 757 expr_ty | |
| 758 Num(object n, int lineno) | |
| 759 { | |
| 760 expr_ty p; | |
| 761 if (!n) { | |
| 762 PyErr_SetString(PyExc_ValueError, | |
| 763 "field n is required for Num"); | |
| 764 return NULL; | |
| 765 } | |
| 766 p = (expr_ty)malloc(sizeof(*p)); | |
| 767 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
768 PyErr_NoMemory(); |
| 35742 | 769 return NULL; |
| 770 } | |
| 771 p->kind = Num_kind; | |
| 772 p->v.Num.n = n; | |
| 773 p->lineno = lineno; | |
| 774 return p; | |
| 775 } | |
| 776 | |
| 777 expr_ty | |
| 778 Str(string s, int lineno) | |
| 779 { | |
| 780 expr_ty p; | |
| 781 if (!s) { | |
| 782 PyErr_SetString(PyExc_ValueError, | |
| 783 "field s is required for Str"); | |
| 784 return NULL; | |
| 785 } | |
| 786 p = (expr_ty)malloc(sizeof(*p)); | |
| 787 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
788 PyErr_NoMemory(); |
| 35742 | 789 return NULL; |
| 790 } | |
| 791 p->kind = Str_kind; | |
| 792 p->v.Str.s = s; | |
| 793 p->lineno = lineno; | |
| 794 return p; | |
| 795 } | |
| 796 | |
| 797 expr_ty | |
| 798 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno) | |
| 799 { | |
| 800 expr_ty p; | |
| 801 if (!value) { | |
| 802 PyErr_SetString(PyExc_ValueError, | |
| 803 "field value is required for Attribute"); | |
| 804 return NULL; | |
| 805 } | |
| 806 if (!attr) { | |
| 807 PyErr_SetString(PyExc_ValueError, | |
| 808 "field attr is required for Attribute"); | |
| 809 return NULL; | |
| 810 } | |
| 811 if (!ctx) { | |
| 812 PyErr_SetString(PyExc_ValueError, | |
| 813 "field ctx is required for Attribute"); | |
| 814 return NULL; | |
| 815 } | |
| 816 p = (expr_ty)malloc(sizeof(*p)); | |
| 817 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
818 PyErr_NoMemory(); |
| 35742 | 819 return NULL; |
| 820 } | |
| 821 p->kind = Attribute_kind; | |
| 822 p->v.Attribute.value = value; | |
| 823 p->v.Attribute.attr = attr; | |
| 824 p->v.Attribute.ctx = ctx; | |
| 825 p->lineno = lineno; | |
| 826 return p; | |
| 827 } | |
| 828 | |
| 829 expr_ty | |
| 830 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno) | |
| 831 { | |
| 832 expr_ty p; | |
| 833 if (!value) { | |
| 834 PyErr_SetString(PyExc_ValueError, | |
| 835 "field value is required for Subscript"); | |
| 836 return NULL; | |
| 837 } | |
| 838 if (!slice) { | |
| 839 PyErr_SetString(PyExc_ValueError, | |
| 840 "field slice is required for Subscript"); | |
| 841 return NULL; | |
| 842 } | |
| 843 if (!ctx) { | |
| 844 PyErr_SetString(PyExc_ValueError, | |
| 845 "field ctx is required for Subscript"); | |
| 846 return NULL; | |
| 847 } | |
| 848 p = (expr_ty)malloc(sizeof(*p)); | |
| 849 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
850 PyErr_NoMemory(); |
| 35742 | 851 return NULL; |
| 852 } | |
| 853 p->kind = Subscript_kind; | |
| 854 p->v.Subscript.value = value; | |
| 855 p->v.Subscript.slice = slice; | |
| 856 p->v.Subscript.ctx = ctx; | |
| 857 p->lineno = lineno; | |
| 858 return p; | |
| 859 } | |
| 860 | |
| 861 expr_ty | |
| 862 Name(identifier id, expr_context_ty ctx, int lineno) | |
| 863 { | |
| 864 expr_ty p; | |
| 865 if (!id) { | |
| 866 PyErr_SetString(PyExc_ValueError, | |
| 867 "field id is required for Name"); | |
| 868 return NULL; | |
| 869 } | |
| 870 if (!ctx) { | |
| 871 PyErr_SetString(PyExc_ValueError, | |
| 872 "field ctx is required for Name"); | |
| 873 return NULL; | |
| 874 } | |
| 875 p = (expr_ty)malloc(sizeof(*p)); | |
| 876 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
877 PyErr_NoMemory(); |
| 35742 | 878 return NULL; |
| 879 } | |
| 880 p->kind = Name_kind; | |
| 881 p->v.Name.id = id; | |
| 882 p->v.Name.ctx = ctx; | |
| 883 p->lineno = lineno; | |
| 884 return p; | |
| 885 } | |
| 886 | |
| 887 expr_ty | |
| 888 List(asdl_seq * elts, expr_context_ty ctx, int lineno) | |
| 889 { | |
| 890 expr_ty p; | |
| 891 if (!ctx) { | |
| 892 PyErr_SetString(PyExc_ValueError, | |
| 893 "field ctx is required for List"); | |
| 894 return NULL; | |
| 895 } | |
| 896 p = (expr_ty)malloc(sizeof(*p)); | |
| 897 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
898 PyErr_NoMemory(); |
| 35742 | 899 return NULL; |
| 900 } | |
| 901 p->kind = List_kind; | |
| 902 p->v.List.elts = elts; | |
| 903 p->v.List.ctx = ctx; | |
| 904 p->lineno = lineno; | |
| 905 return p; | |
| 906 } | |
| 907 | |
| 908 expr_ty | |
| 909 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno) | |
| 910 { | |
| 911 expr_ty p; | |
| 912 if (!ctx) { | |
| 913 PyErr_SetString(PyExc_ValueError, | |
| 914 "field ctx is required for Tuple"); | |
| 915 return NULL; | |
| 916 } | |
| 917 p = (expr_ty)malloc(sizeof(*p)); | |
| 918 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
919 PyErr_NoMemory(); |
| 35742 | 920 return NULL; |
| 921 } | |
| 922 p->kind = Tuple_kind; | |
| 923 p->v.Tuple.elts = elts; | |
| 924 p->v.Tuple.ctx = ctx; | |
| 925 p->lineno = lineno; | |
| 926 return p; | |
| 927 } | |
| 928 | |
| 929 slice_ty | |
| 930 Ellipsis() | |
| 931 { | |
| 932 slice_ty p; | |
| 933 p = (slice_ty)malloc(sizeof(*p)); | |
| 934 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
935 PyErr_NoMemory(); |
| 35742 | 936 return NULL; |
| 937 } | |
| 938 p->kind = Ellipsis_kind; | |
| 939 return p; | |
| 940 } | |
| 941 | |
| 942 slice_ty | |
| 943 Slice(expr_ty lower, expr_ty upper, expr_ty step) | |
| 944 { | |
| 945 slice_ty p; | |
| 946 p = (slice_ty)malloc(sizeof(*p)); | |
| 947 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
948 PyErr_NoMemory(); |
| 35742 | 949 return NULL; |
| 950 } | |
| 951 p->kind = Slice_kind; | |
| 952 p->v.Slice.lower = lower; | |
| 953 p->v.Slice.upper = upper; | |
| 954 p->v.Slice.step = step; | |
| 955 return p; | |
| 956 } | |
| 957 | |
| 958 slice_ty | |
| 959 ExtSlice(asdl_seq * dims) | |
| 960 { | |
| 961 slice_ty p; | |
| 962 p = (slice_ty)malloc(sizeof(*p)); | |
| 963 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
964 PyErr_NoMemory(); |
| 35742 | 965 return NULL; |
| 966 } | |
| 967 p->kind = ExtSlice_kind; | |
| 968 p->v.ExtSlice.dims = dims; | |
| 969 return p; | |
| 970 } | |
| 971 | |
| 972 slice_ty | |
| 973 Index(expr_ty value) | |
| 974 { | |
| 975 slice_ty p; | |
| 976 if (!value) { | |
| 977 PyErr_SetString(PyExc_ValueError, | |
| 978 "field value is required for Index"); | |
| 979 return NULL; | |
| 980 } | |
| 981 p = (slice_ty)malloc(sizeof(*p)); | |
| 982 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
983 PyErr_NoMemory(); |
| 35742 | 984 return NULL; |
| 985 } | |
| 986 p->kind = Index_kind; | |
| 987 p->v.Index.value = value; | |
| 988 return p; | |
| 989 } | |
| 990 | |
| 991 comprehension_ty | |
| 992 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs) | |
| 993 { | |
| 994 comprehension_ty p; | |
| 995 if (!target) { | |
| 996 PyErr_SetString(PyExc_ValueError, | |
| 997 "field target is required for comprehension"); | |
| 998 return NULL; | |
| 999 } | |
| 1000 if (!iter) { | |
| 1001 PyErr_SetString(PyExc_ValueError, | |
| 1002 "field iter is required for comprehension"); | |
| 1003 return NULL; | |
| 1004 } | |
| 1005 p = (comprehension_ty)malloc(sizeof(*p)); | |
| 1006 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
1007 PyErr_NoMemory(); |
| 35742 | 1008 return NULL; |
| 1009 } | |
| 1010 p->target = target; | |
| 1011 p->iter = iter; | |
| 1012 p->ifs = ifs; | |
| 1013 return p; | |
| 1014 } | |
| 1015 | |
| 1016 excepthandler_ty | |
| 1017 excepthandler(expr_ty type, expr_ty name, asdl_seq * body) | |
| 1018 { | |
| 1019 excepthandler_ty p; | |
| 1020 p = (excepthandler_ty)malloc(sizeof(*p)); | |
| 1021 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
1022 PyErr_NoMemory(); |
| 35742 | 1023 return NULL; |
| 1024 } | |
| 1025 p->type = type; | |
| 1026 p->name = name; | |
| 1027 p->body = body; | |
| 1028 return p; | |
| 1029 } | |
| 1030 | |
| 1031 arguments_ty | |
| 1032 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq * | |
| 1033 defaults) | |
| 1034 { | |
| 1035 arguments_ty p; | |
| 1036 p = (arguments_ty)malloc(sizeof(*p)); | |
| 1037 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
1038 PyErr_NoMemory(); |
| 35742 | 1039 return NULL; |
| 1040 } | |
| 1041 p->args = args; | |
| 1042 p->vararg = vararg; | |
| 1043 p->kwarg = kwarg; | |
| 1044 p->defaults = defaults; | |
| 1045 return p; | |
| 1046 } | |
| 1047 | |
| 1048 keyword_ty | |
| 1049 keyword(identifier arg, expr_ty value) | |
| 1050 { | |
| 1051 keyword_ty p; | |
| 1052 if (!arg) { | |
| 1053 PyErr_SetString(PyExc_ValueError, | |
| 1054 "field arg is required for keyword"); | |
| 1055 return NULL; | |
| 1056 } | |
| 1057 if (!value) { | |
| 1058 PyErr_SetString(PyExc_ValueError, | |
| 1059 "field value is required for keyword"); | |
| 1060 return NULL; | |
| 1061 } | |
| 1062 p = (keyword_ty)malloc(sizeof(*p)); | |
| 1063 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
1064 PyErr_NoMemory(); |
| 35742 | 1065 return NULL; |
| 1066 } | |
| 1067 p->arg = arg; | |
| 1068 p->value = value; | |
| 1069 return p; | |
| 1070 } | |
| 1071 | |
| 1072 alias_ty | |
| 1073 alias(identifier name, identifier asname) | |
| 1074 { | |
| 1075 alias_ty p; | |
| 1076 if (!name) { | |
| 1077 PyErr_SetString(PyExc_ValueError, | |
| 1078 "field name is required for alias"); | |
| 1079 return NULL; | |
| 1080 } | |
| 1081 p = (alias_ty)malloc(sizeof(*p)); | |
| 1082 if (!p) { | |
|
35784
c6dbf88e4b14
Use PyErr_NoMemory() instead of rolling our own.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
1083 PyErr_NoMemory(); |
| 35742 | 1084 return NULL; |
| 1085 } | |
| 1086 p->name = name; | |
| 1087 p->asname = asname; | |
| 1088 return p; | |
| 1089 } | |
| 1090 | |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1091 |
| 35742 | 1092 static void |
| 1093 free_seq_exprs(asdl_seq *seq) | |
| 1094 { | |
| 1095 int i, n; | |
| 1096 n = asdl_seq_LEN(seq); | |
| 1097 for (i = 0; i < n; i++) | |
| 1098 free_expr((expr_ty)asdl_seq_GET(seq, i)); | |
| 1099 asdl_seq_free(seq); | |
| 1100 } | |
| 1101 | |
| 1102 static void | |
| 1103 free_seq_stmts(asdl_seq *seq) | |
| 1104 { | |
| 1105 int i, n; | |
| 1106 n = asdl_seq_LEN(seq); | |
| 1107 for (i = 0; i < n; i++) | |
| 1108 free_stmt((stmt_ty)asdl_seq_GET(seq, i)); | |
| 1109 asdl_seq_free(seq); | |
| 1110 } | |
| 1111 | |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1112 |
| 35742 | 1113 void |
| 1114 free_mod(mod_ty o) | |
| 1115 { | |
| 1116 if (!o) | |
| 1117 return; | |
| 1118 | |
| 1119 switch (o->kind) { | |
| 1120 case Module_kind: | |
| 1121 free_seq_stmts(o->v.Module.body); | |
| 1122 break; | |
| 1123 case Interactive_kind: | |
| 1124 free_seq_stmts(o->v.Interactive.body); | |
| 1125 break; | |
| 1126 case Expression_kind: | |
| 1127 free_expr((expr_ty)o->v.Expression.body); | |
| 1128 break; | |
| 1129 case Suite_kind: | |
| 1130 free_seq_stmts(o->v.Suite.body); | |
| 1131 break; | |
| 1132 } | |
| 1133 | |
| 1134 free(o); | |
| 1135 } | |
| 1136 | |
| 1137 void | |
| 1138 free_stmt(stmt_ty o) | |
| 1139 { | |
| 1140 int i, n; | |
| 1141 asdl_seq *seq; | |
| 1142 | |
| 1143 if (!o) | |
| 1144 return; | |
| 1145 | |
| 1146 switch (o->kind) { | |
| 1147 case FunctionDef_kind: | |
| 1148 Py_DECREF((identifier)o->v.FunctionDef.name); | |
| 1149 free_arguments((arguments_ty)o->v.FunctionDef.args); | |
| 1150 free_seq_stmts(o->v.FunctionDef.body); | |
| 1151 free_seq_exprs(o->v.FunctionDef.decorators); | |
| 1152 break; | |
| 1153 case ClassDef_kind: | |
| 1154 Py_DECREF((identifier)o->v.ClassDef.name); | |
| 1155 free_seq_exprs(o->v.ClassDef.bases); | |
| 1156 free_seq_stmts(o->v.ClassDef.body); | |
| 1157 break; | |
| 1158 case Return_kind: | |
| 1159 if (o->v.Return.value) { | |
| 1160 free_expr((expr_ty)o->v.Return.value); | |
| 1161 } | |
| 1162 break; | |
| 1163 case Delete_kind: | |
| 1164 free_seq_exprs(o->v.Delete.targets); | |
| 1165 break; | |
| 1166 case Assign_kind: | |
| 1167 free_seq_exprs(o->v.Assign.targets); | |
| 1168 free_expr((expr_ty)o->v.Assign.value); | |
| 1169 break; | |
| 1170 case AugAssign_kind: | |
| 1171 free_expr((expr_ty)o->v.AugAssign.target); | |
| 1172 free_operator((operator_ty)o->v.AugAssign.op); | |
| 1173 free_expr((expr_ty)o->v.AugAssign.value); | |
| 1174 break; | |
| 1175 case Print_kind: | |
| 1176 if (o->v.Print.dest) { | |
| 1177 free_expr((expr_ty)o->v.Print.dest); | |
| 1178 } | |
| 1179 free_seq_exprs(o->v.Print.values); | |
| 1180 break; | |
| 1181 case For_kind: | |
| 1182 free_expr((expr_ty)o->v.For.target); | |
| 1183 free_expr((expr_ty)o->v.For.iter); | |
| 1184 free_seq_stmts(o->v.For.body); | |
| 1185 free_seq_stmts(o->v.For.orelse); | |
| 1186 break; | |
| 1187 case While_kind: | |
| 1188 free_expr((expr_ty)o->v.While.test); | |
| 1189 free_seq_stmts(o->v.While.body); | |
| 1190 free_seq_stmts(o->v.While.orelse); | |
| 1191 break; | |
| 1192 case If_kind: | |
| 1193 free_expr((expr_ty)o->v.If.test); | |
| 1194 free_seq_stmts(o->v.If.body); | |
| 1195 free_seq_stmts(o->v.If.orelse); | |
| 1196 break; | |
| 1197 case Raise_kind: | |
| 1198 if (o->v.Raise.type) { | |
| 1199 free_expr((expr_ty)o->v.Raise.type); | |
| 1200 } | |
| 1201 if (o->v.Raise.inst) { | |
| 1202 free_expr((expr_ty)o->v.Raise.inst); | |
| 1203 } | |
| 1204 if (o->v.Raise.tback) { | |
| 1205 free_expr((expr_ty)o->v.Raise.tback); | |
| 1206 } | |
| 1207 break; | |
| 1208 case TryExcept_kind: | |
| 1209 free_seq_stmts(o->v.TryExcept.body); | |
| 1210 seq = o->v.TryExcept.handlers; | |
| 1211 n = asdl_seq_LEN(seq); | |
| 1212 for (i = 0; i < n; i++) | |
| 1213 free_excepthandler((excepthandler_ty)asdl_seq_GET(seq, | |
| 1214 i)); | |
| 1215 asdl_seq_free(seq); | |
| 1216 free_seq_stmts(o->v.TryExcept.orelse); | |
| 1217 break; | |
| 1218 case TryFinally_kind: | |
| 1219 free_seq_stmts(o->v.TryFinally.body); | |
| 1220 free_seq_stmts(o->v.TryFinally.finalbody); | |
| 1221 break; | |
| 1222 case Assert_kind: | |
| 1223 free_expr((expr_ty)o->v.Assert.test); | |
| 1224 if (o->v.Assert.msg) { | |
| 1225 free_expr((expr_ty)o->v.Assert.msg); | |
| 1226 } | |
| 1227 break; | |
| 1228 case Import_kind: | |
| 1229 seq = o->v.Import.names; | |
| 1230 n = asdl_seq_LEN(seq); | |
| 1231 for (i = 0; i < n; i++) | |
| 1232 free_alias((alias_ty)asdl_seq_GET(seq, i)); | |
| 1233 asdl_seq_free(seq); | |
| 1234 break; | |
| 1235 case ImportFrom_kind: | |
| 1236 Py_DECREF((identifier)o->v.ImportFrom.module); | |
| 1237 seq = o->v.ImportFrom.names; | |
| 1238 n = asdl_seq_LEN(seq); | |
| 1239 for (i = 0; i < n; i++) | |
| 1240 free_alias((alias_ty)asdl_seq_GET(seq, i)); | |
| 1241 asdl_seq_free(seq); | |
| 1242 break; | |
| 1243 case Exec_kind: | |
| 1244 free_expr((expr_ty)o->v.Exec.body); | |
| 1245 if (o->v.Exec.globals) { | |
| 1246 free_expr((expr_ty)o->v.Exec.globals); | |
| 1247 } | |
| 1248 if (o->v.Exec.locals) { | |
| 1249 free_expr((expr_ty)o->v.Exec.locals); | |
| 1250 } | |
| 1251 break; | |
| 1252 case Global_kind: | |
| 1253 seq = o->v.Global.names; | |
| 1254 n = asdl_seq_LEN(seq); | |
| 1255 for (i = 0; i < n; i++) | |
| 1256 Py_DECREF((identifier)asdl_seq_GET(seq, i)); | |
| 1257 asdl_seq_free(seq); | |
| 1258 break; | |
| 1259 case Expr_kind: | |
| 1260 free_expr((expr_ty)o->v.Expr.value); | |
| 1261 break; | |
| 1262 case Pass_kind: | |
| 1263 break; | |
| 1264 case Break_kind: | |
| 1265 break; | |
| 1266 case Continue_kind: | |
| 1267 break; | |
| 1268 } | |
| 1269 | |
| 1270 free(o); | |
| 1271 } | |
| 1272 | |
| 1273 void | |
| 1274 free_expr(expr_ty o) | |
| 1275 { | |
| 1276 int i, n; | |
| 1277 asdl_seq *seq; | |
| 1278 | |
| 1279 if (!o) | |
| 1280 return; | |
| 1281 | |
| 1282 switch (o->kind) { | |
| 1283 case BoolOp_kind: | |
| 1284 free_boolop((boolop_ty)o->v.BoolOp.op); | |
| 1285 free_seq_exprs(o->v.BoolOp.values); | |
| 1286 break; | |
| 1287 case BinOp_kind: | |
| 1288 free_expr((expr_ty)o->v.BinOp.left); | |
| 1289 free_operator((operator_ty)o->v.BinOp.op); | |
| 1290 free_expr((expr_ty)o->v.BinOp.right); | |
| 1291 break; | |
| 1292 case UnaryOp_kind: | |
| 1293 free_unaryop((unaryop_ty)o->v.UnaryOp.op); | |
| 1294 free_expr((expr_ty)o->v.UnaryOp.operand); | |
| 1295 break; | |
| 1296 case Lambda_kind: | |
| 1297 free_arguments((arguments_ty)o->v.Lambda.args); | |
| 1298 free_expr((expr_ty)o->v.Lambda.body); | |
| 1299 break; | |
| 1300 case Dict_kind: | |
| 1301 free_seq_exprs(o->v.Dict.keys); | |
| 1302 free_seq_exprs(o->v.Dict.values); | |
| 1303 break; | |
| 1304 case ListComp_kind: | |
| 1305 free_expr((expr_ty)o->v.ListComp.elt); | |
| 1306 seq = o->v.ListComp.generators; | |
| 1307 n = asdl_seq_LEN(seq); | |
| 1308 for (i = 0; i < n; i++) | |
| 1309 free_comprehension((comprehension_ty)asdl_seq_GET(seq, | |
| 1310 i)); | |
| 1311 asdl_seq_free(seq); | |
| 1312 break; | |
| 1313 case GeneratorExp_kind: | |
| 1314 free_expr((expr_ty)o->v.GeneratorExp.elt); | |
| 1315 seq = o->v.GeneratorExp.generators; | |
| 1316 n = asdl_seq_LEN(seq); | |
| 1317 for (i = 0; i < n; i++) | |
| 1318 free_comprehension((comprehension_ty)asdl_seq_GET(seq, | |
| 1319 i)); | |
| 1320 asdl_seq_free(seq); | |
| 1321 break; | |
| 1322 case Yield_kind: | |
| 1323 if (o->v.Yield.value) { | |
| 1324 free_expr((expr_ty)o->v.Yield.value); | |
| 1325 } | |
| 1326 break; | |
| 1327 case Compare_kind: | |
| 1328 free_expr((expr_ty)o->v.Compare.left); | |
| 1329 seq = o->v.Compare.ops; | |
| 1330 n = asdl_seq_LEN(seq); | |
| 1331 for (i = 0; i < n; i++) | |
| 1332 free_cmpop((cmpop_ty)asdl_seq_GET(seq, i)); | |
| 1333 asdl_seq_free(seq); | |
| 1334 free_seq_exprs(o->v.Compare.comparators); | |
| 1335 break; | |
| 1336 case Call_kind: | |
| 1337 free_expr((expr_ty)o->v.Call.func); | |
| 1338 free_seq_exprs(o->v.Call.args); | |
| 1339 seq = o->v.Call.keywords; | |
| 1340 n = asdl_seq_LEN(seq); | |
| 1341 for (i = 0; i < n; i++) | |
| 1342 free_keyword((keyword_ty)asdl_seq_GET(seq, i)); | |
| 1343 asdl_seq_free(seq); | |
| 1344 if (o->v.Call.starargs) { | |
| 1345 free_expr((expr_ty)o->v.Call.starargs); | |
| 1346 } | |
| 1347 if (o->v.Call.kwargs) { | |
| 1348 free_expr((expr_ty)o->v.Call.kwargs); | |
| 1349 } | |
| 1350 break; | |
| 1351 case Repr_kind: | |
| 1352 free_expr((expr_ty)o->v.Repr.value); | |
| 1353 break; | |
| 1354 case Num_kind: | |
| 1355 Py_DECREF((object)o->v.Num.n); | |
| 1356 break; | |
| 1357 case Str_kind: | |
| 1358 Py_DECREF((string)o->v.Str.s); | |
| 1359 break; | |
| 1360 case Attribute_kind: | |
| 1361 free_expr((expr_ty)o->v.Attribute.value); | |
| 1362 Py_DECREF((identifier)o->v.Attribute.attr); | |
| 1363 free_expr_context((expr_context_ty)o->v.Attribute.ctx); | |
| 1364 break; | |
| 1365 case Subscript_kind: | |
| 1366 free_expr((expr_ty)o->v.Subscript.value); | |
| 1367 free_slice((slice_ty)o->v.Subscript.slice); | |
| 1368 free_expr_context((expr_context_ty)o->v.Subscript.ctx); | |
| 1369 break; | |
| 1370 case Name_kind: | |
| 1371 Py_DECREF((identifier)o->v.Name.id); | |
| 1372 free_expr_context((expr_context_ty)o->v.Name.ctx); | |
| 1373 break; | |
| 1374 case List_kind: | |
| 1375 free_seq_exprs(o->v.List.elts); | |
| 1376 free_expr_context((expr_context_ty)o->v.List.ctx); | |
| 1377 break; | |
| 1378 case Tuple_kind: | |
| 1379 free_seq_exprs(o->v.Tuple.elts); | |
| 1380 free_expr_context((expr_context_ty)o->v.Tuple.ctx); | |
| 1381 break; | |
| 1382 } | |
| 1383 | |
| 1384 free(o); | |
| 1385 } | |
| 1386 | |
| 1387 void | |
| 1388 free_expr_context(expr_context_ty o) | |
| 1389 { | |
| 1390 if (!o) | |
| 1391 return; | |
| 1392 | |
| 1393 } | |
| 1394 | |
| 1395 void | |
| 1396 free_slice(slice_ty o) | |
| 1397 { | |
| 1398 int i, n; | |
| 1399 asdl_seq *seq; | |
| 1400 | |
| 1401 if (!o) | |
| 1402 return; | |
| 1403 | |
| 1404 switch (o->kind) { | |
| 1405 case Ellipsis_kind: | |
| 1406 break; | |
| 1407 case Slice_kind: | |
| 1408 if (o->v.Slice.lower) { | |
| 1409 free_expr((expr_ty)o->v.Slice.lower); | |
| 1410 } | |
| 1411 if (o->v.Slice.upper) { | |
| 1412 free_expr((expr_ty)o->v.Slice.upper); | |
| 1413 } | |
| 1414 if (o->v.Slice.step) { | |
| 1415 free_expr((expr_ty)o->v.Slice.step); | |
| 1416 } | |
| 1417 break; | |
| 1418 case ExtSlice_kind: | |
| 1419 seq = o->v.ExtSlice.dims; | |
| 1420 n = asdl_seq_LEN(seq); | |
| 1421 for (i = 0; i < n; i++) | |
| 1422 free_slice((slice_ty)asdl_seq_GET(seq, i)); | |
| 1423 asdl_seq_free(seq); | |
| 1424 break; | |
| 1425 case Index_kind: | |
| 1426 free_expr((expr_ty)o->v.Index.value); | |
| 1427 break; | |
| 1428 } | |
| 1429 | |
| 1430 free(o); | |
| 1431 } | |
| 1432 | |
| 1433 void | |
| 1434 free_boolop(boolop_ty o) | |
| 1435 { | |
| 1436 if (!o) | |
| 1437 return; | |
| 1438 | |
| 1439 } | |
| 1440 | |
| 1441 void | |
| 1442 free_operator(operator_ty o) | |
| 1443 { | |
| 1444 if (!o) | |
| 1445 return; | |
| 1446 | |
| 1447 } | |
| 1448 | |
| 1449 void | |
| 1450 free_unaryop(unaryop_ty o) | |
| 1451 { | |
| 1452 if (!o) | |
| 1453 return; | |
| 1454 | |
| 1455 } | |
| 1456 | |
| 1457 void | |
| 1458 free_cmpop(cmpop_ty o) | |
| 1459 { | |
| 1460 if (!o) | |
| 1461 return; | |
| 1462 | |
| 1463 } | |
| 1464 | |
| 1465 void | |
| 1466 free_comprehension(comprehension_ty o) | |
| 1467 { | |
| 1468 if (!o) | |
| 1469 return; | |
| 1470 | |
| 1471 free_expr((expr_ty)o->target); | |
| 1472 free_expr((expr_ty)o->iter); | |
| 1473 free_seq_exprs(o->ifs); | |
| 1474 | |
| 1475 free(o); | |
| 1476 } | |
| 1477 | |
| 1478 void | |
| 1479 free_excepthandler(excepthandler_ty o) | |
| 1480 { | |
| 1481 if (!o) | |
| 1482 return; | |
| 1483 | |
| 1484 if (o->type) { | |
| 1485 free_expr((expr_ty)o->type); | |
| 1486 } | |
| 1487 if (o->name) { | |
| 1488 free_expr((expr_ty)o->name); | |
| 1489 } | |
| 1490 free_seq_stmts(o->body); | |
| 1491 | |
| 1492 free(o); | |
| 1493 } | |
| 1494 | |
| 1495 void | |
| 1496 free_arguments(arguments_ty o) | |
| 1497 { | |
| 1498 if (!o) | |
| 1499 return; | |
| 1500 | |
| 1501 free_seq_exprs(o->args); | |
| 1502 if (o->vararg) { | |
| 1503 Py_DECREF((identifier)o->vararg); | |
| 1504 } | |
| 1505 if (o->kwarg) { | |
| 1506 Py_DECREF((identifier)o->kwarg); | |
| 1507 } | |
| 1508 free_seq_exprs(o->defaults); | |
| 1509 | |
| 1510 free(o); | |
| 1511 } | |
| 1512 | |
| 1513 void | |
| 1514 free_keyword(keyword_ty o) | |
| 1515 { | |
| 1516 if (!o) | |
| 1517 return; | |
| 1518 | |
| 1519 Py_DECREF((identifier)o->arg); | |
| 1520 free_expr((expr_ty)o->value); | |
| 1521 | |
| 1522 free(o); | |
| 1523 } | |
| 1524 | |
| 1525 void | |
| 1526 free_alias(alias_ty o) | |
| 1527 { | |
| 1528 if (!o) | |
| 1529 return; | |
| 1530 | |
| 1531 Py_DECREF((identifier)o->name); | |
| 1532 if (o->asname) { | |
| 1533 Py_DECREF((identifier)o->asname); | |
| 1534 } | |
| 1535 | |
| 1536 free(o); | |
| 1537 } | |
| 1538 | |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1539 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1540 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1541 #define CHECKSIZE(BUF, OFF, MIN) { \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1542 int need = *(OFF) + MIN; \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1543 if (need >= PyString_GET_SIZE(*(BUF))) { \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1544 int newsize = PyString_GET_SIZE(*(BUF)) * 2; \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1545 if (newsize < need) \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1546 newsize = need; \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1547 if (_PyString_Resize((BUF), newsize) < 0) \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1548 return 0; \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1549 } \ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1550 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1551 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1552 static int |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1553 marshal_write_int(PyObject **buf, int *offset, int x) |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1554 { |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1555 char *s; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1556 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1557 CHECKSIZE(buf, offset, 4) |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1558 s = PyString_AS_STRING(*buf) + (*offset); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1559 s[0] = (x & 0xff); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1560 s[1] = (x >> 8) & 0xff; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1561 s[2] = (x >> 16) & 0xff; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1562 s[3] = (x >> 24) & 0xff; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1563 *offset += 4; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1564 return 1; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1565 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1566 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1567 static int |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1568 marshal_write_bool(PyObject **buf, int *offset, bool b) |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1569 { |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1570 if (b) |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1571 marshal_write_int(buf, offset, 1); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1572 else |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1573 marshal_write_int(buf, offset, 0); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1574 return 1; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1575 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1576 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1577 static int |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1578 marshal_write_identifier(PyObject **buf, int *offset, identifier id) |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1579 { |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1580 int l = PyString_GET_SIZE(id); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1581 marshal_write_int(buf, offset, l); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1582 CHECKSIZE(buf, offset, l); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1583 memcpy(PyString_AS_STRING(*buf) + *offset, |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1584 PyString_AS_STRING(id), l); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1585 *offset += l; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1586 return 1; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1587 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1588 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1589 static int |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1590 marshal_write_string(PyObject **buf, int *offset, string s) |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1591 { |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1592 int len = PyString_GET_SIZE(s); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1593 marshal_write_int(buf, offset, len); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1594 CHECKSIZE(buf, offset, len); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1595 memcpy(PyString_AS_STRING(*buf) + *offset, |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1596 PyString_AS_STRING(s), len); |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1597 *offset += len; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1598 return 1; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1599 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1600 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1601 static int |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1602 marshal_write_object(PyObject **buf, int *offset, object s) |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1603 { |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1604 /* XXX */ |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1605 return 0; |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1606 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1607 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
1608 |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
1609 static int |
| 35742 | 1610 marshal_write_mod(PyObject **buf, int *off, mod_ty o) |
| 1611 { | |
| 1612 int i; | |
| 1613 switch (o->kind) { | |
| 1614 case Module_kind: | |
| 1615 marshal_write_int(buf, off, 1); | |
| 1616 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Module.body)); | |
| 1617 for (i = 0; i < asdl_seq_LEN(o->v.Module.body); i++) { | |
| 1618 void *elt = asdl_seq_GET(o->v.Module.body, i); | |
| 1619 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1620 } | |
| 1621 break; | |
| 1622 case Interactive_kind: | |
| 1623 marshal_write_int(buf, off, 2); | |
| 1624 marshal_write_int(buf, off, | |
| 1625 asdl_seq_LEN(o->v.Interactive.body)); | |
| 1626 for (i = 0; i < asdl_seq_LEN(o->v.Interactive.body); i++) { | |
| 1627 void *elt = asdl_seq_GET(o->v.Interactive.body, i); | |
| 1628 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1629 } | |
| 1630 break; | |
| 1631 case Expression_kind: | |
| 1632 marshal_write_int(buf, off, 3); | |
| 1633 marshal_write_expr(buf, off, o->v.Expression.body); | |
| 1634 break; | |
| 1635 case Suite_kind: | |
| 1636 marshal_write_int(buf, off, 4); | |
| 1637 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Suite.body)); | |
| 1638 for (i = 0; i < asdl_seq_LEN(o->v.Suite.body); i++) { | |
| 1639 void *elt = asdl_seq_GET(o->v.Suite.body, i); | |
| 1640 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1641 } | |
| 1642 break; | |
| 1643 } | |
| 1644 return 1; | |
| 1645 } | |
| 1646 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
1647 static int |
| 35742 | 1648 marshal_write_stmt(PyObject **buf, int *off, stmt_ty o) |
| 1649 { | |
| 1650 int i; | |
| 1651 switch (o->kind) { | |
| 1652 case FunctionDef_kind: | |
| 1653 marshal_write_int(buf, off, 1); | |
| 1654 marshal_write_identifier(buf, off, o->v.FunctionDef.name); | |
| 1655 marshal_write_arguments(buf, off, o->v.FunctionDef.args); | |
| 1656 marshal_write_int(buf, off, | |
| 1657 asdl_seq_LEN(o->v.FunctionDef.body)); | |
| 1658 for (i = 0; i < asdl_seq_LEN(o->v.FunctionDef.body); i++) { | |
| 1659 void *elt = asdl_seq_GET(o->v.FunctionDef.body, i); | |
| 1660 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1661 } | |
| 1662 marshal_write_int(buf, off, | |
| 1663 asdl_seq_LEN(o->v.FunctionDef.decorators)); | |
| 1664 for (i = 0; i < asdl_seq_LEN(o->v.FunctionDef.decorators); i++) | |
| 1665 { | |
| 1666 void *elt = asdl_seq_GET(o->v.FunctionDef.decorators, | |
| 1667 i); | |
| 1668 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1669 } | |
| 1670 break; | |
| 1671 case ClassDef_kind: | |
| 1672 marshal_write_int(buf, off, 2); | |
| 1673 marshal_write_identifier(buf, off, o->v.ClassDef.name); | |
| 1674 marshal_write_int(buf, off, asdl_seq_LEN(o->v.ClassDef.bases)); | |
| 1675 for (i = 0; i < asdl_seq_LEN(o->v.ClassDef.bases); i++) { | |
| 1676 void *elt = asdl_seq_GET(o->v.ClassDef.bases, i); | |
| 1677 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1678 } | |
| 1679 marshal_write_int(buf, off, asdl_seq_LEN(o->v.ClassDef.body)); | |
| 1680 for (i = 0; i < asdl_seq_LEN(o->v.ClassDef.body); i++) { | |
| 1681 void *elt = asdl_seq_GET(o->v.ClassDef.body, i); | |
| 1682 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1683 } | |
| 1684 break; | |
| 1685 case Return_kind: | |
| 1686 marshal_write_int(buf, off, 3); | |
| 1687 if (o->v.Return.value) { | |
| 1688 marshal_write_int(buf, off, 1); | |
| 1689 marshal_write_expr(buf, off, o->v.Return.value); | |
| 1690 } | |
| 1691 else { | |
| 1692 marshal_write_int(buf, off, 0); | |
| 1693 } | |
| 1694 break; | |
| 1695 case Delete_kind: | |
| 1696 marshal_write_int(buf, off, 4); | |
| 1697 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Delete.targets)); | |
| 1698 for (i = 0; i < asdl_seq_LEN(o->v.Delete.targets); i++) { | |
| 1699 void *elt = asdl_seq_GET(o->v.Delete.targets, i); | |
| 1700 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1701 } | |
| 1702 break; | |
| 1703 case Assign_kind: | |
| 1704 marshal_write_int(buf, off, 5); | |
| 1705 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Assign.targets)); | |
| 1706 for (i = 0; i < asdl_seq_LEN(o->v.Assign.targets); i++) { | |
| 1707 void *elt = asdl_seq_GET(o->v.Assign.targets, i); | |
| 1708 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1709 } | |
| 1710 marshal_write_expr(buf, off, o->v.Assign.value); | |
| 1711 break; | |
| 1712 case AugAssign_kind: | |
| 1713 marshal_write_int(buf, off, 6); | |
| 1714 marshal_write_expr(buf, off, o->v.AugAssign.target); | |
| 1715 marshal_write_operator(buf, off, o->v.AugAssign.op); | |
| 1716 marshal_write_expr(buf, off, o->v.AugAssign.value); | |
| 1717 break; | |
| 1718 case Print_kind: | |
| 1719 marshal_write_int(buf, off, 7); | |
| 1720 if (o->v.Print.dest) { | |
| 1721 marshal_write_int(buf, off, 1); | |
| 1722 marshal_write_expr(buf, off, o->v.Print.dest); | |
| 1723 } | |
| 1724 else { | |
| 1725 marshal_write_int(buf, off, 0); | |
| 1726 } | |
| 1727 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Print.values)); | |
| 1728 for (i = 0; i < asdl_seq_LEN(o->v.Print.values); i++) { | |
| 1729 void *elt = asdl_seq_GET(o->v.Print.values, i); | |
| 1730 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1731 } | |
| 1732 marshal_write_bool(buf, off, o->v.Print.nl); | |
| 1733 break; | |
| 1734 case For_kind: | |
| 1735 marshal_write_int(buf, off, 8); | |
| 1736 marshal_write_expr(buf, off, o->v.For.target); | |
| 1737 marshal_write_expr(buf, off, o->v.For.iter); | |
| 1738 marshal_write_int(buf, off, asdl_seq_LEN(o->v.For.body)); | |
| 1739 for (i = 0; i < asdl_seq_LEN(o->v.For.body); i++) { | |
| 1740 void *elt = asdl_seq_GET(o->v.For.body, i); | |
| 1741 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1742 } | |
| 1743 marshal_write_int(buf, off, asdl_seq_LEN(o->v.For.orelse)); | |
| 1744 for (i = 0; i < asdl_seq_LEN(o->v.For.orelse); i++) { | |
| 1745 void *elt = asdl_seq_GET(o->v.For.orelse, i); | |
| 1746 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1747 } | |
| 1748 break; | |
| 1749 case While_kind: | |
| 1750 marshal_write_int(buf, off, 9); | |
| 1751 marshal_write_expr(buf, off, o->v.While.test); | |
| 1752 marshal_write_int(buf, off, asdl_seq_LEN(o->v.While.body)); | |
| 1753 for (i = 0; i < asdl_seq_LEN(o->v.While.body); i++) { | |
| 1754 void *elt = asdl_seq_GET(o->v.While.body, i); | |
| 1755 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1756 } | |
| 1757 marshal_write_int(buf, off, asdl_seq_LEN(o->v.While.orelse)); | |
| 1758 for (i = 0; i < asdl_seq_LEN(o->v.While.orelse); i++) { | |
| 1759 void *elt = asdl_seq_GET(o->v.While.orelse, i); | |
| 1760 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1761 } | |
| 1762 break; | |
| 1763 case If_kind: | |
| 1764 marshal_write_int(buf, off, 10); | |
| 1765 marshal_write_expr(buf, off, o->v.If.test); | |
| 1766 marshal_write_int(buf, off, asdl_seq_LEN(o->v.If.body)); | |
| 1767 for (i = 0; i < asdl_seq_LEN(o->v.If.body); i++) { | |
| 1768 void *elt = asdl_seq_GET(o->v.If.body, i); | |
| 1769 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1770 } | |
| 1771 marshal_write_int(buf, off, asdl_seq_LEN(o->v.If.orelse)); | |
| 1772 for (i = 0; i < asdl_seq_LEN(o->v.If.orelse); i++) { | |
| 1773 void *elt = asdl_seq_GET(o->v.If.orelse, i); | |
| 1774 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1775 } | |
| 1776 break; | |
| 1777 case Raise_kind: | |
| 1778 marshal_write_int(buf, off, 11); | |
| 1779 if (o->v.Raise.type) { | |
| 1780 marshal_write_int(buf, off, 1); | |
| 1781 marshal_write_expr(buf, off, o->v.Raise.type); | |
| 1782 } | |
| 1783 else { | |
| 1784 marshal_write_int(buf, off, 0); | |
| 1785 } | |
| 1786 if (o->v.Raise.inst) { | |
| 1787 marshal_write_int(buf, off, 1); | |
| 1788 marshal_write_expr(buf, off, o->v.Raise.inst); | |
| 1789 } | |
| 1790 else { | |
| 1791 marshal_write_int(buf, off, 0); | |
| 1792 } | |
| 1793 if (o->v.Raise.tback) { | |
| 1794 marshal_write_int(buf, off, 1); | |
| 1795 marshal_write_expr(buf, off, o->v.Raise.tback); | |
| 1796 } | |
| 1797 else { | |
| 1798 marshal_write_int(buf, off, 0); | |
| 1799 } | |
| 1800 break; | |
| 1801 case TryExcept_kind: | |
| 1802 marshal_write_int(buf, off, 12); | |
| 1803 marshal_write_int(buf, off, asdl_seq_LEN(o->v.TryExcept.body)); | |
| 1804 for (i = 0; i < asdl_seq_LEN(o->v.TryExcept.body); i++) { | |
| 1805 void *elt = asdl_seq_GET(o->v.TryExcept.body, i); | |
| 1806 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1807 } | |
| 1808 marshal_write_int(buf, off, | |
| 1809 asdl_seq_LEN(o->v.TryExcept.handlers)); | |
| 1810 for (i = 0; i < asdl_seq_LEN(o->v.TryExcept.handlers); i++) { | |
| 1811 void *elt = asdl_seq_GET(o->v.TryExcept.handlers, i); | |
| 1812 marshal_write_excepthandler(buf, off, | |
| 1813 (excepthandler_ty)elt); | |
| 1814 } | |
| 1815 marshal_write_int(buf, off, | |
| 1816 asdl_seq_LEN(o->v.TryExcept.orelse)); | |
| 1817 for (i = 0; i < asdl_seq_LEN(o->v.TryExcept.orelse); i++) { | |
| 1818 void *elt = asdl_seq_GET(o->v.TryExcept.orelse, i); | |
| 1819 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1820 } | |
| 1821 break; | |
| 1822 case TryFinally_kind: | |
| 1823 marshal_write_int(buf, off, 13); | |
| 1824 marshal_write_int(buf, off, asdl_seq_LEN(o->v.TryFinally.body)); | |
| 1825 for (i = 0; i < asdl_seq_LEN(o->v.TryFinally.body); i++) { | |
| 1826 void *elt = asdl_seq_GET(o->v.TryFinally.body, i); | |
| 1827 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1828 } | |
| 1829 marshal_write_int(buf, off, | |
| 1830 asdl_seq_LEN(o->v.TryFinally.finalbody)); | |
| 1831 for (i = 0; i < asdl_seq_LEN(o->v.TryFinally.finalbody); i++) { | |
| 1832 void *elt = asdl_seq_GET(o->v.TryFinally.finalbody, i); | |
| 1833 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 1834 } | |
| 1835 break; | |
| 1836 case Assert_kind: | |
| 1837 marshal_write_int(buf, off, 14); | |
| 1838 marshal_write_expr(buf, off, o->v.Assert.test); | |
| 1839 if (o->v.Assert.msg) { | |
| 1840 marshal_write_int(buf, off, 1); | |
| 1841 marshal_write_expr(buf, off, o->v.Assert.msg); | |
| 1842 } | |
| 1843 else { | |
| 1844 marshal_write_int(buf, off, 0); | |
| 1845 } | |
| 1846 break; | |
| 1847 case Import_kind: | |
| 1848 marshal_write_int(buf, off, 15); | |
| 1849 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Import.names)); | |
| 1850 for (i = 0; i < asdl_seq_LEN(o->v.Import.names); i++) { | |
| 1851 void *elt = asdl_seq_GET(o->v.Import.names, i); | |
| 1852 marshal_write_alias(buf, off, (alias_ty)elt); | |
| 1853 } | |
| 1854 break; | |
| 1855 case ImportFrom_kind: | |
| 1856 marshal_write_int(buf, off, 16); | |
| 1857 marshal_write_identifier(buf, off, o->v.ImportFrom.module); | |
| 1858 marshal_write_int(buf, off, | |
| 1859 asdl_seq_LEN(o->v.ImportFrom.names)); | |
| 1860 for (i = 0; i < asdl_seq_LEN(o->v.ImportFrom.names); i++) { | |
| 1861 void *elt = asdl_seq_GET(o->v.ImportFrom.names, i); | |
| 1862 marshal_write_alias(buf, off, (alias_ty)elt); | |
| 1863 } | |
| 1864 break; | |
| 1865 case Exec_kind: | |
| 1866 marshal_write_int(buf, off, 17); | |
| 1867 marshal_write_expr(buf, off, o->v.Exec.body); | |
| 1868 if (o->v.Exec.globals) { | |
| 1869 marshal_write_int(buf, off, 1); | |
| 1870 marshal_write_expr(buf, off, o->v.Exec.globals); | |
| 1871 } | |
| 1872 else { | |
| 1873 marshal_write_int(buf, off, 0); | |
| 1874 } | |
| 1875 if (o->v.Exec.locals) { | |
| 1876 marshal_write_int(buf, off, 1); | |
| 1877 marshal_write_expr(buf, off, o->v.Exec.locals); | |
| 1878 } | |
| 1879 else { | |
| 1880 marshal_write_int(buf, off, 0); | |
| 1881 } | |
| 1882 break; | |
| 1883 case Global_kind: | |
| 1884 marshal_write_int(buf, off, 18); | |
| 1885 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Global.names)); | |
| 1886 for (i = 0; i < asdl_seq_LEN(o->v.Global.names); i++) { | |
| 1887 void *elt = asdl_seq_GET(o->v.Global.names, i); | |
| 1888 marshal_write_identifier(buf, off, (identifier)elt); | |
| 1889 } | |
| 1890 break; | |
| 1891 case Expr_kind: | |
| 1892 marshal_write_int(buf, off, 19); | |
| 1893 marshal_write_expr(buf, off, o->v.Expr.value); | |
| 1894 break; | |
| 1895 case Pass_kind: | |
| 1896 marshal_write_int(buf, off, 20); | |
| 1897 break; | |
| 1898 case Break_kind: | |
| 1899 marshal_write_int(buf, off, 21); | |
| 1900 break; | |
| 1901 case Continue_kind: | |
| 1902 marshal_write_int(buf, off, 22); | |
| 1903 break; | |
| 1904 } | |
| 1905 return 1; | |
| 1906 } | |
| 1907 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
1908 static int |
| 35742 | 1909 marshal_write_expr(PyObject **buf, int *off, expr_ty o) |
| 1910 { | |
| 1911 int i; | |
| 1912 switch (o->kind) { | |
| 1913 case BoolOp_kind: | |
| 1914 marshal_write_int(buf, off, 1); | |
| 1915 marshal_write_boolop(buf, off, o->v.BoolOp.op); | |
| 1916 marshal_write_int(buf, off, asdl_seq_LEN(o->v.BoolOp.values)); | |
| 1917 for (i = 0; i < asdl_seq_LEN(o->v.BoolOp.values); i++) { | |
| 1918 void *elt = asdl_seq_GET(o->v.BoolOp.values, i); | |
| 1919 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1920 } | |
| 1921 break; | |
| 1922 case BinOp_kind: | |
| 1923 marshal_write_int(buf, off, 2); | |
| 1924 marshal_write_expr(buf, off, o->v.BinOp.left); | |
| 1925 marshal_write_operator(buf, off, o->v.BinOp.op); | |
| 1926 marshal_write_expr(buf, off, o->v.BinOp.right); | |
| 1927 break; | |
| 1928 case UnaryOp_kind: | |
| 1929 marshal_write_int(buf, off, 3); | |
| 1930 marshal_write_unaryop(buf, off, o->v.UnaryOp.op); | |
| 1931 marshal_write_expr(buf, off, o->v.UnaryOp.operand); | |
| 1932 break; | |
| 1933 case Lambda_kind: | |
| 1934 marshal_write_int(buf, off, 4); | |
| 1935 marshal_write_arguments(buf, off, o->v.Lambda.args); | |
| 1936 marshal_write_expr(buf, off, o->v.Lambda.body); | |
| 1937 break; | |
| 1938 case Dict_kind: | |
| 1939 marshal_write_int(buf, off, 5); | |
| 1940 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Dict.keys)); | |
| 1941 for (i = 0; i < asdl_seq_LEN(o->v.Dict.keys); i++) { | |
| 1942 void *elt = asdl_seq_GET(o->v.Dict.keys, i); | |
| 1943 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1944 } | |
| 1945 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Dict.values)); | |
| 1946 for (i = 0; i < asdl_seq_LEN(o->v.Dict.values); i++) { | |
| 1947 void *elt = asdl_seq_GET(o->v.Dict.values, i); | |
| 1948 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1949 } | |
| 1950 break; | |
| 1951 case ListComp_kind: | |
| 1952 marshal_write_int(buf, off, 6); | |
| 1953 marshal_write_expr(buf, off, o->v.ListComp.elt); | |
| 1954 marshal_write_int(buf, off, | |
| 1955 asdl_seq_LEN(o->v.ListComp.generators)); | |
| 1956 for (i = 0; i < asdl_seq_LEN(o->v.ListComp.generators); i++) { | |
| 1957 void *elt = asdl_seq_GET(o->v.ListComp.generators, i); | |
| 1958 marshal_write_comprehension(buf, off, | |
| 1959 (comprehension_ty)elt); | |
| 1960 } | |
| 1961 break; | |
| 1962 case GeneratorExp_kind: | |
| 1963 marshal_write_int(buf, off, 7); | |
| 1964 marshal_write_expr(buf, off, o->v.GeneratorExp.elt); | |
| 1965 marshal_write_int(buf, off, | |
| 1966 asdl_seq_LEN(o->v.GeneratorExp.generators)); | |
| 1967 for (i = 0; i < asdl_seq_LEN(o->v.GeneratorExp.generators); | |
| 1968 i++) { | |
| 1969 void *elt = asdl_seq_GET(o->v.GeneratorExp.generators, | |
| 1970 i); | |
| 1971 marshal_write_comprehension(buf, off, | |
| 1972 (comprehension_ty)elt); | |
| 1973 } | |
| 1974 break; | |
| 1975 case Yield_kind: | |
| 1976 marshal_write_int(buf, off, 8); | |
| 1977 if (o->v.Yield.value) { | |
| 1978 marshal_write_int(buf, off, 1); | |
| 1979 marshal_write_expr(buf, off, o->v.Yield.value); | |
| 1980 } | |
| 1981 else { | |
| 1982 marshal_write_int(buf, off, 0); | |
| 1983 } | |
| 1984 break; | |
| 1985 case Compare_kind: | |
| 1986 marshal_write_int(buf, off, 9); | |
| 1987 marshal_write_expr(buf, off, o->v.Compare.left); | |
| 1988 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Compare.ops)); | |
| 1989 for (i = 0; i < asdl_seq_LEN(o->v.Compare.ops); i++) { | |
| 1990 void *elt = asdl_seq_GET(o->v.Compare.ops, i); | |
| 1991 marshal_write_cmpop(buf, off, (cmpop_ty)elt); | |
| 1992 } | |
| 1993 marshal_write_int(buf, off, | |
| 1994 asdl_seq_LEN(o->v.Compare.comparators)); | |
| 1995 for (i = 0; i < asdl_seq_LEN(o->v.Compare.comparators); i++) { | |
| 1996 void *elt = asdl_seq_GET(o->v.Compare.comparators, i); | |
| 1997 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 1998 } | |
| 1999 break; | |
| 2000 case Call_kind: | |
| 2001 marshal_write_int(buf, off, 10); | |
| 2002 marshal_write_expr(buf, off, o->v.Call.func); | |
| 2003 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Call.args)); | |
| 2004 for (i = 0; i < asdl_seq_LEN(o->v.Call.args); i++) { | |
| 2005 void *elt = asdl_seq_GET(o->v.Call.args, i); | |
| 2006 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 2007 } | |
| 2008 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Call.keywords)); | |
| 2009 for (i = 0; i < asdl_seq_LEN(o->v.Call.keywords); i++) { | |
| 2010 void *elt = asdl_seq_GET(o->v.Call.keywords, i); | |
| 2011 marshal_write_keyword(buf, off, (keyword_ty)elt); | |
| 2012 } | |
| 2013 if (o->v.Call.starargs) { | |
| 2014 marshal_write_int(buf, off, 1); | |
| 2015 marshal_write_expr(buf, off, o->v.Call.starargs); | |
| 2016 } | |
| 2017 else { | |
| 2018 marshal_write_int(buf, off, 0); | |
| 2019 } | |
| 2020 if (o->v.Call.kwargs) { | |
| 2021 marshal_write_int(buf, off, 1); | |
| 2022 marshal_write_expr(buf, off, o->v.Call.kwargs); | |
| 2023 } | |
| 2024 else { | |
| 2025 marshal_write_int(buf, off, 0); | |
| 2026 } | |
| 2027 break; | |
| 2028 case Repr_kind: | |
| 2029 marshal_write_int(buf, off, 11); | |
| 2030 marshal_write_expr(buf, off, o->v.Repr.value); | |
| 2031 break; | |
| 2032 case Num_kind: | |
| 2033 marshal_write_int(buf, off, 12); | |
| 2034 marshal_write_object(buf, off, o->v.Num.n); | |
| 2035 break; | |
| 2036 case Str_kind: | |
| 2037 marshal_write_int(buf, off, 13); | |
| 2038 marshal_write_string(buf, off, o->v.Str.s); | |
| 2039 break; | |
| 2040 case Attribute_kind: | |
| 2041 marshal_write_int(buf, off, 14); | |
| 2042 marshal_write_expr(buf, off, o->v.Attribute.value); | |
| 2043 marshal_write_identifier(buf, off, o->v.Attribute.attr); | |
| 2044 marshal_write_expr_context(buf, off, o->v.Attribute.ctx); | |
| 2045 break; | |
| 2046 case Subscript_kind: | |
| 2047 marshal_write_int(buf, off, 15); | |
| 2048 marshal_write_expr(buf, off, o->v.Subscript.value); | |
| 2049 marshal_write_slice(buf, off, o->v.Subscript.slice); | |
| 2050 marshal_write_expr_context(buf, off, o->v.Subscript.ctx); | |
| 2051 break; | |
| 2052 case Name_kind: | |
| 2053 marshal_write_int(buf, off, 16); | |
| 2054 marshal_write_identifier(buf, off, o->v.Name.id); | |
| 2055 marshal_write_expr_context(buf, off, o->v.Name.ctx); | |
| 2056 break; | |
| 2057 case List_kind: | |
| 2058 marshal_write_int(buf, off, 17); | |
| 2059 marshal_write_int(buf, off, asdl_seq_LEN(o->v.List.elts)); | |
| 2060 for (i = 0; i < asdl_seq_LEN(o->v.List.elts); i++) { | |
| 2061 void *elt = asdl_seq_GET(o->v.List.elts, i); | |
| 2062 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 2063 } | |
| 2064 marshal_write_expr_context(buf, off, o->v.List.ctx); | |
| 2065 break; | |
| 2066 case Tuple_kind: | |
| 2067 marshal_write_int(buf, off, 18); | |
| 2068 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Tuple.elts)); | |
| 2069 for (i = 0; i < asdl_seq_LEN(o->v.Tuple.elts); i++) { | |
| 2070 void *elt = asdl_seq_GET(o->v.Tuple.elts, i); | |
| 2071 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 2072 } | |
| 2073 marshal_write_expr_context(buf, off, o->v.Tuple.ctx); | |
| 2074 break; | |
| 2075 } | |
| 2076 return 1; | |
| 2077 } | |
| 2078 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2079 static int |
| 35742 | 2080 marshal_write_expr_context(PyObject **buf, int *off, expr_context_ty o) |
| 2081 { | |
| 2082 switch (o) { | |
| 2083 case Load: | |
| 2084 marshal_write_int(buf, off, 1); | |
| 2085 break; | |
| 2086 case Store: | |
| 2087 marshal_write_int(buf, off, 2); | |
| 2088 break; | |
| 2089 case Del: | |
| 2090 marshal_write_int(buf, off, 3); | |
| 2091 break; | |
| 2092 case AugLoad: | |
| 2093 marshal_write_int(buf, off, 4); | |
| 2094 break; | |
| 2095 case AugStore: | |
| 2096 marshal_write_int(buf, off, 5); | |
| 2097 break; | |
| 2098 case Param: | |
| 2099 marshal_write_int(buf, off, 6); | |
| 2100 break; | |
| 2101 } | |
| 2102 return 1; | |
| 2103 } | |
| 2104 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2105 static int |
| 35742 | 2106 marshal_write_slice(PyObject **buf, int *off, slice_ty o) |
| 2107 { | |
| 2108 int i; | |
| 2109 switch (o->kind) { | |
| 2110 case Ellipsis_kind: | |
| 2111 marshal_write_int(buf, off, 1); | |
| 2112 break; | |
| 2113 case Slice_kind: | |
| 2114 marshal_write_int(buf, off, 2); | |
| 2115 if (o->v.Slice.lower) { | |
| 2116 marshal_write_int(buf, off, 1); | |
| 2117 marshal_write_expr(buf, off, o->v.Slice.lower); | |
| 2118 } | |
| 2119 else { | |
| 2120 marshal_write_int(buf, off, 0); | |
| 2121 } | |
| 2122 if (o->v.Slice.upper) { | |
| 2123 marshal_write_int(buf, off, 1); | |
| 2124 marshal_write_expr(buf, off, o->v.Slice.upper); | |
| 2125 } | |
| 2126 else { | |
| 2127 marshal_write_int(buf, off, 0); | |
| 2128 } | |
| 2129 if (o->v.Slice.step) { | |
| 2130 marshal_write_int(buf, off, 1); | |
| 2131 marshal_write_expr(buf, off, o->v.Slice.step); | |
| 2132 } | |
| 2133 else { | |
| 2134 marshal_write_int(buf, off, 0); | |
| 2135 } | |
| 2136 break; | |
| 2137 case ExtSlice_kind: | |
| 2138 marshal_write_int(buf, off, 3); | |
| 2139 marshal_write_int(buf, off, asdl_seq_LEN(o->v.ExtSlice.dims)); | |
| 2140 for (i = 0; i < asdl_seq_LEN(o->v.ExtSlice.dims); i++) { | |
| 2141 void *elt = asdl_seq_GET(o->v.ExtSlice.dims, i); | |
| 2142 marshal_write_slice(buf, off, (slice_ty)elt); | |
| 2143 } | |
| 2144 break; | |
| 2145 case Index_kind: | |
| 2146 marshal_write_int(buf, off, 4); | |
| 2147 marshal_write_expr(buf, off, o->v.Index.value); | |
| 2148 break; | |
| 2149 } | |
| 2150 return 1; | |
| 2151 } | |
| 2152 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2153 static int |
| 35742 | 2154 marshal_write_boolop(PyObject **buf, int *off, boolop_ty o) |
| 2155 { | |
| 2156 switch (o) { | |
| 2157 case And: | |
| 2158 marshal_write_int(buf, off, 1); | |
| 2159 break; | |
| 2160 case Or: | |
| 2161 marshal_write_int(buf, off, 2); | |
| 2162 break; | |
| 2163 } | |
| 2164 return 1; | |
| 2165 } | |
| 2166 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2167 static int |
| 35742 | 2168 marshal_write_operator(PyObject **buf, int *off, operator_ty o) |
| 2169 { | |
| 2170 switch (o) { | |
| 2171 case Add: | |
| 2172 marshal_write_int(buf, off, 1); | |
| 2173 break; | |
| 2174 case Sub: | |
| 2175 marshal_write_int(buf, off, 2); | |
| 2176 break; | |
| 2177 case Mult: | |
| 2178 marshal_write_int(buf, off, 3); | |
| 2179 break; | |
| 2180 case Div: | |
| 2181 marshal_write_int(buf, off, 4); | |
| 2182 break; | |
| 2183 case Mod: | |
| 2184 marshal_write_int(buf, off, 5); | |
| 2185 break; | |
| 2186 case Pow: | |
| 2187 marshal_write_int(buf, off, 6); | |
| 2188 break; | |
| 2189 case LShift: | |
| 2190 marshal_write_int(buf, off, 7); | |
| 2191 break; | |
| 2192 case RShift: | |
| 2193 marshal_write_int(buf, off, 8); | |
| 2194 break; | |
| 2195 case BitOr: | |
| 2196 marshal_write_int(buf, off, 9); | |
| 2197 break; | |
| 2198 case BitXor: | |
| 2199 marshal_write_int(buf, off, 10); | |
| 2200 break; | |
| 2201 case BitAnd: | |
| 2202 marshal_write_int(buf, off, 11); | |
| 2203 break; | |
| 2204 case FloorDiv: | |
| 2205 marshal_write_int(buf, off, 12); | |
| 2206 break; | |
| 2207 } | |
| 2208 return 1; | |
| 2209 } | |
| 2210 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2211 static int |
| 35742 | 2212 marshal_write_unaryop(PyObject **buf, int *off, unaryop_ty o) |
| 2213 { | |
| 2214 switch (o) { | |
| 2215 case Invert: | |
| 2216 marshal_write_int(buf, off, 1); | |
| 2217 break; | |
| 2218 case Not: | |
| 2219 marshal_write_int(buf, off, 2); | |
| 2220 break; | |
| 2221 case UAdd: | |
| 2222 marshal_write_int(buf, off, 3); | |
| 2223 break; | |
| 2224 case USub: | |
| 2225 marshal_write_int(buf, off, 4); | |
| 2226 break; | |
| 2227 } | |
| 2228 return 1; | |
| 2229 } | |
| 2230 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2231 static int |
| 35742 | 2232 marshal_write_cmpop(PyObject **buf, int *off, cmpop_ty o) |
| 2233 { | |
| 2234 switch (o) { | |
| 2235 case Eq: | |
| 2236 marshal_write_int(buf, off, 1); | |
| 2237 break; | |
| 2238 case NotEq: | |
| 2239 marshal_write_int(buf, off, 2); | |
| 2240 break; | |
| 2241 case Lt: | |
| 2242 marshal_write_int(buf, off, 3); | |
| 2243 break; | |
| 2244 case LtE: | |
| 2245 marshal_write_int(buf, off, 4); | |
| 2246 break; | |
| 2247 case Gt: | |
| 2248 marshal_write_int(buf, off, 5); | |
| 2249 break; | |
| 2250 case GtE: | |
| 2251 marshal_write_int(buf, off, 6); | |
| 2252 break; | |
| 2253 case Is: | |
| 2254 marshal_write_int(buf, off, 7); | |
| 2255 break; | |
| 2256 case IsNot: | |
| 2257 marshal_write_int(buf, off, 8); | |
| 2258 break; | |
| 2259 case In: | |
| 2260 marshal_write_int(buf, off, 9); | |
| 2261 break; | |
| 2262 case NotIn: | |
| 2263 marshal_write_int(buf, off, 10); | |
| 2264 break; | |
| 2265 } | |
| 2266 return 1; | |
| 2267 } | |
| 2268 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2269 static int |
| 35742 | 2270 marshal_write_comprehension(PyObject **buf, int *off, comprehension_ty o) |
| 2271 { | |
| 2272 int i; | |
| 2273 marshal_write_expr(buf, off, o->target); | |
| 2274 marshal_write_expr(buf, off, o->iter); | |
| 2275 marshal_write_int(buf, off, asdl_seq_LEN(o->ifs)); | |
| 2276 for (i = 0; i < asdl_seq_LEN(o->ifs); i++) { | |
| 2277 void *elt = asdl_seq_GET(o->ifs, i); | |
| 2278 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 2279 } | |
| 2280 return 1; | |
| 2281 } | |
| 2282 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2283 static int |
| 35742 | 2284 marshal_write_excepthandler(PyObject **buf, int *off, excepthandler_ty o) |
| 2285 { | |
| 2286 int i; | |
| 2287 if (o->type) { | |
| 2288 marshal_write_int(buf, off, 1); | |
| 2289 marshal_write_expr(buf, off, o->type); | |
| 2290 } | |
| 2291 else { | |
| 2292 marshal_write_int(buf, off, 0); | |
| 2293 } | |
| 2294 if (o->name) { | |
| 2295 marshal_write_int(buf, off, 1); | |
| 2296 marshal_write_expr(buf, off, o->name); | |
| 2297 } | |
| 2298 else { | |
| 2299 marshal_write_int(buf, off, 0); | |
| 2300 } | |
| 2301 marshal_write_int(buf, off, asdl_seq_LEN(o->body)); | |
| 2302 for (i = 0; i < asdl_seq_LEN(o->body); i++) { | |
| 2303 void *elt = asdl_seq_GET(o->body, i); | |
| 2304 marshal_write_stmt(buf, off, (stmt_ty)elt); | |
| 2305 } | |
| 2306 return 1; | |
| 2307 } | |
| 2308 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2309 static int |
| 35742 | 2310 marshal_write_arguments(PyObject **buf, int *off, arguments_ty o) |
| 2311 { | |
| 2312 int i; | |
| 2313 marshal_write_int(buf, off, asdl_seq_LEN(o->args)); | |
| 2314 for (i = 0; i < asdl_seq_LEN(o->args); i++) { | |
| 2315 void *elt = asdl_seq_GET(o->args, i); | |
| 2316 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 2317 } | |
| 2318 if (o->vararg) { | |
| 2319 marshal_write_int(buf, off, 1); | |
| 2320 marshal_write_identifier(buf, off, o->vararg); | |
| 2321 } | |
| 2322 else { | |
| 2323 marshal_write_int(buf, off, 0); | |
| 2324 } | |
| 2325 if (o->kwarg) { | |
| 2326 marshal_write_int(buf, off, 1); | |
| 2327 marshal_write_identifier(buf, off, o->kwarg); | |
| 2328 } | |
| 2329 else { | |
| 2330 marshal_write_int(buf, off, 0); | |
| 2331 } | |
| 2332 marshal_write_int(buf, off, asdl_seq_LEN(o->defaults)); | |
| 2333 for (i = 0; i < asdl_seq_LEN(o->defaults); i++) { | |
| 2334 void *elt = asdl_seq_GET(o->defaults, i); | |
| 2335 marshal_write_expr(buf, off, (expr_ty)elt); | |
| 2336 } | |
| 2337 return 1; | |
| 2338 } | |
| 2339 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2340 static int |
| 35742 | 2341 marshal_write_keyword(PyObject **buf, int *off, keyword_ty o) |
| 2342 { | |
| 2343 marshal_write_identifier(buf, off, o->arg); | |
| 2344 marshal_write_expr(buf, off, o->value); | |
| 2345 return 1; | |
| 2346 } | |
| 2347 | |
|
35862
6867995a18a7
Prevent name pollution by making lots of internal functions static.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35784
diff
changeset
|
2348 static int |
| 35742 | 2349 marshal_write_alias(PyObject **buf, int *off, alias_ty o) |
| 2350 { | |
| 2351 marshal_write_identifier(buf, off, o->name); | |
| 2352 if (o->asname) { | |
| 2353 marshal_write_int(buf, off, 1); | |
| 2354 marshal_write_identifier(buf, off, o->asname); | |
| 2355 } | |
| 2356 else { | |
| 2357 marshal_write_int(buf, off, 0); | |
| 2358 } | |
| 2359 return 1; | |
| 2360 } | |
| 2361 | |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2362 |
