This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define ENSURE_CONSTANT(NODE) \ | |
if ((NODE) != NULL && (NODE)->kind != Constant_kind) \ | |
return 1; | |
#define GET_CONSTANT(NODE) (((NODE) != NULL) ? (NODE)->v.Constant.value : NULL) | |
static int | |
fold_subscr(expr_ty node, PyArena *arena, int optimize) | |
{ | |
PyObject *newval, *key; | |
expr_ty arg; | |
slice_ty slice; | |
arg = node->v.Subscript.value; | |
slice = node->v.Subscript.slice; | |
if (node->v.Subscript.ctx != Load) | |
{ | |
return 1; | |
} | |
ENSURE_CONSTANT(arg) | |
switch (slice->kind) { | |
case Index_kind: | |
ENSURE_CONSTANT(slice->v.Index.value) | |
key = GET_CONSTANT(slice->v.Index.value); | |
break; | |
case Slice_kind: | |
ENSURE_CONSTANT(slice->v.Slice.lower) | |
ENSURE_CONSTANT(slice->v.Slice.upper) | |
ENSURE_CONSTANT(slice->v.Slice.step) | |
key = PySlice_New(GET_CONSTANT(slice->v.Slice.lower), | |
GET_CONSTANT(slice->v.Slice.upper), | |
GET_CONSTANT(slice->v.Slice.step)); | |
break; | |
default: | |
return 1; | |
} | |
newval = PyObject_GetItem(GET_CONSTANT(arg), key); | |
return make_const(node, newval, arena); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment