68
module = PyImport_ImportModule("storm");
72
Undef = PyObject_GetAttrString(module, "Undef");
80
module = PyImport_ImportModule("storm.variables");
84
raise_none_error = PyObject_GetAttrString(module, "raise_none_error");
85
if (!raise_none_error)
88
LazyValue = PyObject_GetAttrString(module, "LazyValue");
96
module = PyImport_ImportModule("storm.info");
100
get_cls_info = PyObject_GetAttrString(module, "get_cls_info");
108
module = PyImport_ImportModule("storm.event");
112
EventSystem = PyObject_GetAttrString(module, "EventSystem");
168
/* Import objects from storm module */
169
module = PyImport_ImportModule("storm");
173
Undef = PyObject_GetAttrString(module, "Undef");
179
/* Import objects from storm.variables module */
180
module = PyImport_ImportModule("storm.variables");
184
raise_none_error = PyObject_GetAttrString(module, "raise_none_error");
185
if (!raise_none_error)
188
LazyValue = PyObject_GetAttrString(module, "LazyValue");
194
/* Import objects from storm.info module */
195
module = PyImport_ImportModule("storm.info");
199
get_cls_info = PyObject_GetAttrString(module, "get_cls_info");
205
/* Import objects from storm.event module */
206
module = PyImport_ImportModule("storm.event");
210
EventSystem = PyObject_GetAttrString(module, "EventSystem");
216
/* Import objects from storm.expr module */
217
module = PyImport_ImportModule("storm.expr");
221
SQLRaw = PyObject_GetAttrString(module, "SQLRaw");
225
SQLToken = PyObject_GetAttrString(module, "SQLToken");
229
State = PyObject_GetAttrString(module, "State");
233
CompileError = PyObject_GetAttrString(module, "CompileError");
239
/* A few frequently used objects which are part of the fast path. */
241
parenthesis_format = PyUnicode_DecodeASCII("(%s)", 4, "strict");
242
default_compile_join = PyUnicode_DecodeASCII(", ", 2, "strict");
249
EventSystem_init(EventSystemObject *self, PyObject *args, PyObject *kwargs)
251
static char *kwlist[] = {"owner", NULL};
255
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &owner))
258
/* self._owner_ref = weakref.ref(owner) */
259
self->_owner_ref = PyWeakref_NewRef(owner, NULL);
260
if (self->_owner_ref) {
261
/* self._hooks = {} */
262
self->_hooks = PyDict_New();
272
EventSystem_traverse(EventSystemObject *self, visitproc visit, void *arg)
274
Py_VISIT(self->_owner_ref);
275
Py_VISIT(self->_hooks);
280
EventSystem_clear(EventSystemObject *self)
282
Py_CLEAR(self->_owner_ref);
283
Py_CLEAR(self->_hooks);
288
EventSystem_dealloc(EventSystemObject *self)
290
EventSystem_clear(self);
291
self->ob_type->tp_free((PyObject *)self);
295
EventSystem_hook(EventSystemObject *self, PyObject *args)
297
PyObject *result = NULL;
298
PyObject *name, *callback, *data;
300
if (PyTuple_GET_SIZE(args) < 2) {
301
PyErr_SetString(PyExc_TypeError, "Invalid number of arguments");
305
name = PyTuple_GET_ITEM(args, 0);
306
callback = PyTuple_GET_ITEM(args, 1);
307
data = PyTuple_GetSlice(args, 2, PyTuple_GET_SIZE(args));
310
callbacks = self._hooks.get(name)
311
if callbacks is None:
312
self._hooks.setdefault(name, set()).add((callback, data))
314
callbacks.add((callback, data))
316
PyObject *callbacks = PyDict_GetItem(self->_hooks, name);
317
if (!PyErr_Occurred()) {
318
if (callbacks == NULL) {
319
callbacks = PySet_New(NULL);
321
PyDict_SetItem(self->_hooks, name, callbacks) == -1) {
322
Py_DECREF(callbacks);
326
Py_INCREF(callbacks);
329
PyObject *tuple = PyTuple_New(2);
332
PyTuple_SET_ITEM(tuple, 0, callback);
334
PyTuple_SET_ITEM(tuple, 1, data);
335
if (PySet_Add(callbacks, tuple) != -1) {
341
Py_DECREF(callbacks);
351
EventSystem_unhook(EventSystemObject *self, PyObject *args)
353
PyObject *result = NULL;
354
PyObject *name, *callback, *data;
356
if (PyTuple_GET_SIZE(args) < 2) {
357
PyErr_SetString(PyExc_TypeError, "Invalid number of arguments");
361
name = PyTuple_GET_ITEM(args, 0);
362
callback = PyTuple_GET_ITEM(args, 1);
363
data = PyTuple_GetSlice(args, 2, PyTuple_GET_SIZE(args));
366
callbacks = self._hooks.get(name)
367
if callbacks is not None:
368
callbacks.discard((callback, data))
370
PyObject *callbacks = PyDict_GetItem(self->_hooks, name);
372
PyObject *tuple = PyTuple_New(2);
375
PyTuple_SET_ITEM(tuple, 0, callback);
377
PyTuple_SET_ITEM(tuple, 1, data);
378
if (PySet_Discard(callbacks, tuple) != -1) {
384
} else if (!PyErr_Occurred()) {
395
EventSystem__do_emit_call(PyObject *callback, PyObject *owner,
396
PyObject *args, PyObject *data)
398
/* return callback(owner, *(args+data)) */
399
PyObject *result = NULL;
400
PyObject *tuple = PyTuple_New(PyTuple_GET_SIZE(args) +
401
PyTuple_GET_SIZE(data) + 1);
403
Py_ssize_t i, tuple_i;
406
PyTuple_SET_ITEM(tuple, 0, owner);
408
for (i = 0; i != PyTuple_GET_SIZE(args); i++) {
409
PyObject *item = PyTuple_GET_ITEM(args, i);
411
PyTuple_SET_ITEM(tuple, tuple_i++, item);
413
for (i = 0; i != PyTuple_GET_SIZE(data); i++) {
414
PyObject *item = PyTuple_GET_ITEM(data, i);
416
PyTuple_SET_ITEM(tuple, tuple_i++, item);
418
result = PyObject_Call(callback, tuple, NULL);
425
EventSystem_emit(EventSystemObject *self, PyObject *all_args)
427
PyObject *result = NULL;
428
PyObject *name, *args;
430
if (PyTuple_GET_SIZE(all_args) == 0) {
431
PyErr_SetString(PyExc_TypeError, "Invalid number of arguments");
435
/* XXX In the following code we trust on the format inserted by
436
* the hook() method. If it's hacked somehow, it may blow up. */
438
name = PyTuple_GET_ITEM(all_args, 0);
439
args = PyTuple_GetSlice(all_args, 1, PyTuple_GET_SIZE(all_args));
441
/* owner = self._owner_ref() */
442
PyObject *owner = PyWeakref_GET_OBJECT(self->_owner_ref);
443
/* if owner is not None: */
444
if (owner != Py_None) {
445
/* callbacks = self._hooks.get(name) */
446
PyObject *callbacks = PyDict_GetItem(self->_hooks, name);
449
if (callbacks && PySet_GET_SIZE(callbacks) != 0) {
450
/* for callback, data in tuple(callbacks): */
451
PyObject *sequence = \
452
PySequence_Fast(callbacks, "callbacks object isn't a set");
456
for (i = 0; i != PySequence_Fast_GET_SIZE(sequence); i++) {
457
PyObject *item = PySequence_Fast_GET_ITEM(sequence, i);
458
PyObject *callback = PyTuple_GET_ITEM(item, 0);
459
PyObject *data = PyTuple_GET_ITEM(item, 1);
462
if callback(owner, *(args+data)) is False:
463
callbacks.discard((callback, data))
465
res = EventSystem__do_emit_call(callback, owner,
470
PySet_Discard(callbacks, item) == -1)) {
481
} else if (!PyErr_Occurred()) {
497
static PyMethodDef EventSystem_methods[] = {
498
{"hook", (PyCFunction)EventSystem_hook, METH_VARARGS, NULL},
499
{"unhook", (PyCFunction)EventSystem_unhook, METH_VARARGS, NULL},
500
{"emit", (PyCFunction)EventSystem_emit, METH_VARARGS, NULL},
504
#define OFFSETOF(x) offsetof(EventSystemObject, x)
505
static PyMemberDef EventSystem_members[] = {
506
{"_object_ref", T_OBJECT, OFFSETOF(_owner_ref), READONLY, 0},
507
{"_hooks", T_OBJECT, OFFSETOF(_hooks), READONLY, 0},
512
statichere PyTypeObject EventSystem_Type = {
513
PyObject_HEAD_INIT(NULL)
515
"storm.variables.EventSystem", /*tp_name*/
516
sizeof(EventSystemObject), /*tp_basicsize*/
518
(destructor)EventSystem_dealloc, /*tp_dealloc*/
525
0, /*tp_as_sequence*/
530
PyObject_GenericGetAttr,/*tp_getattro*/
531
PyObject_GenericSetAttr,/*tp_setattro*/
533
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
535
(traverseproc)EventSystem_traverse, /*tp_traverse*/
536
(inquiry)EventSystem_clear, /*tp_clear*/
537
0, /*tp_richcompare*/
538
0, /*tp_weaklistoffset*/
541
EventSystem_methods, /*tp_methods*/
542
EventSystem_members, /*tp_members*/
549
(initproc)EventSystem_init, /*tp_init*/
550
PyType_GenericAlloc, /*tp_alloc*/
551
PyType_GenericNew, /*tp_new*/
552
PyObject_GC_Del, /*tp_free*/
123
557
static PyObject *
124
558
Variable_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
680
1173
static PyObject *
1174
Compile__update_cache(CompileObject *self, PyObject *args);
1177
Compile_init(CompileObject *self, PyObject *args, PyObject *kwargs)
1179
static char *kwlist[] = {"parent", NULL};
1181
PyObject *parent = Py_None;
1183
PyObject *module = NULL;
1184
PyObject *WeakKeyDictionary = NULL;
1186
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &parent))
1190
self._local_dispatch_table = {}
1191
self._local_precedence = {}
1192
self._local_reserved_words = {}
1193
self._dispatch_table = {}
1194
self._precedence = {}
1195
self._reserved_words = {}
1197
CATCH(NULL, self->_local_dispatch_table = PyDict_New());
1198
CATCH(NULL, self->_local_precedence = PyDict_New());
1199
CATCH(NULL, self->_local_reserved_words = PyDict_New());
1200
CATCH(NULL, self->_dispatch_table = PyDict_New());
1201
CATCH(NULL, self->_precedence = PyDict_New());
1202
CATCH(NULL, self->_reserved_words = PyDict_New());
1204
/* self._children = WeakKeyDictionary() */
1205
CATCH(NULL, module = PyImport_ImportModule("weakref"));
1206
CATCH(NULL, WeakKeyDictionary = \
1207
PyObject_GetAttrString(module, "WeakKeyDictionary"));
1209
CATCH(NULL, self->_children = \
1210
PyObject_CallFunctionObjArgs(WeakKeyDictionary, NULL));
1211
Py_CLEAR(WeakKeyDictionary);
1213
/* self._parents = [] */
1214
CATCH(NULL, self->_parents = PyList_New(0));
1217
if (parent != Py_None) {
1220
/* self._parents.extend(parent._parents) */
1221
CompileObject *parent_object = (CompileObject *)parent;
1222
CATCH(-1, PyList_SetSlice(self->_parents, 0, 0,
1223
parent_object->_parents));
1225
/* self._parents.append(parent) */
1226
CATCH(-1, PyList_Append(self->_parents, parent));
1228
/* parent._children[self] = True */
1229
CATCH(-1, PyObject_SetItem(parent_object->_children,
1230
(PyObject *)self, Py_True));
1232
/* self._update_cache() */
1233
CATCH(NULL, tmp = Compile__update_cache(self, NULL));
1241
Py_XDECREF(WeakKeyDictionary);
1246
Compile_traverse(CompileObject *self, visitproc visit, void *arg)
1248
Py_VISIT(self->_local_dispatch_table);
1249
Py_VISIT(self->_local_precedence);
1250
Py_VISIT(self->_local_reserved_words);
1251
Py_VISIT(self->_dispatch_table);
1252
Py_VISIT(self->_precedence);
1253
Py_VISIT(self->_reserved_words);
1254
Py_VISIT(self->_children);
1255
Py_VISIT(self->_parents);
1260
Compile_clear(CompileObject *self)
1262
if (self->__weakreflist)
1263
PyObject_ClearWeakRefs((PyObject *)self);
1264
Py_CLEAR(self->_local_dispatch_table);
1265
Py_CLEAR(self->_local_precedence);
1266
Py_CLEAR(self->_local_reserved_words);
1267
Py_CLEAR(self->_dispatch_table);
1268
Py_CLEAR(self->_precedence);
1269
Py_CLEAR(self->_reserved_words);
1270
Py_CLEAR(self->_children);
1271
Py_CLEAR(self->_parents);
1276
Compile_dealloc(CompileObject *self)
1278
Compile_clear(self);
1279
self->ob_type->tp_free((PyObject *)self);
1283
Compile__update_cache(CompileObject *self, PyObject *args)
1285
PyObject *iter = NULL;
1286
PyObject *child = NULL;
1290
/* for parent in self._parents: */
1291
size = PyList_GET_SIZE(self->_parents);
1292
for (i = 0; i != size; i++) {
1293
CompileObject *parent = \
1294
(CompileObject *)PyList_GET_ITEM(self->_parents, i);
1295
/* self._dispatch_table.update(parent._local_dispatch_table) */
1296
CATCH(-1, PyDict_Update(self->_dispatch_table,
1297
parent->_local_dispatch_table));
1298
/* self._precedence.update(parent._local_precedence) */
1299
CATCH(-1, PyDict_Update(self->_precedence,
1300
parent->_local_precedence));
1301
/* self._reserved_words.update(parent._local_reserved_words) */
1302
CATCH(-1, PyDict_Update(self->_reserved_words,
1303
parent->_local_reserved_words));
1305
/* self._dispatch_table.update(self._local_dispatch_table) */
1306
CATCH(-1, PyDict_Update(self->_dispatch_table,
1307
self->_local_dispatch_table));
1308
/* self._precedence.update(self._local_precedence) */
1309
CATCH(-1, PyDict_Update(self->_precedence, self->_local_precedence));
1310
/* self._reserved_words.update(self._local_reserved_words) */
1311
CATCH(-1, PyDict_Update(self->_reserved_words,
1312
self->_local_reserved_words));
1314
/* for child in self._children: */
1315
CATCH(NULL, iter = PyObject_GetIter(self->_children));
1316
while((child = PyIter_Next(iter))) {
1319
/* child._update_cache() */
1320
CATCH(NULL, tmp = Compile__update_cache((CompileObject *)child, NULL));
1324
if (PyErr_Occurred())
1337
Compile_when(CompileObject *self, PyObject *types)
1339
PyObject *result = NULL;
1340
PyObject *module = PyImport_ImportModule("storm.expr");
1342
PyObject *_when = PyObject_GetAttrString(module, "_when");
1344
result = PyObject_CallFunctionObjArgs(_when, self, types, NULL);
1353
Compile_add_reserved_words(CompileObject *self, PyObject *words)
1355
PyObject *lower_word = NULL;
1356
PyObject *iter = NULL;
1357
PyObject *word = NULL;
1360
/* self._local_reserved_words.update((word.lower(), True)
1361
for word in words) */
1362
CATCH(NULL, iter = PyObject_GetIter(words));
1363
while ((word = PyIter_Next(iter))) {
1364
CATCH(NULL, lower_word = PyObject_CallMethod(word, "lower", NULL));
1365
CATCH(-1, PyDict_SetItem(self->_local_reserved_words,
1366
lower_word, Py_True));
1367
Py_CLEAR(lower_word);
1370
if (PyErr_Occurred())
1374
/* self._update_cache() */
1375
CATCH(NULL, tmp = Compile__update_cache(self, NULL));
1381
Py_XDECREF(lower_word);
1388
Compile_remove_reserved_words(CompileObject *self, PyObject *words)
1390
PyObject *lower_word = NULL;
1391
PyObject *word = NULL;
1392
PyObject *iter = NULL;
1395
/* self._local_reserved_words.update((word.lower(), None)
1396
for word in words) */
1397
CATCH(NULL, iter = PyObject_GetIter(words));
1398
while ((word = PyIter_Next(iter))) {
1399
CATCH(NULL, lower_word = PyObject_CallMethod(word, "lower", NULL));
1400
CATCH(-1, PyDict_SetItem(self->_local_reserved_words,
1401
lower_word, Py_None));
1402
Py_CLEAR(lower_word);
1405
if (PyErr_Occurred())
1409
/* self._update_cache() */
1410
CATCH(NULL, tmp = Compile__update_cache(self, NULL));
1416
Py_XDECREF(lower_word);
1423
Compile_is_reserved_word(CompileObject *self, PyObject *word)
1425
PyObject *lower_word = NULL;
1426
PyObject *result = Py_False;
1429
/* return self._reserved_words.get(word.lower()) is not None */
1430
CATCH(NULL, lower_word = PyObject_CallMethod(word, "lower", NULL));
1431
item = PyDict_GetItem(self->_reserved_words, lower_word);
1432
if (item == NULL && PyErr_Occurred()) {
1434
} else if (item != NULL && item != Py_None) {
1437
Py_DECREF(lower_word);
1442
Py_XDECREF(lower_word);
1446
staticforward PyTypeObject Compile_Type;
1449
Compile_create_child(CompileObject *self, PyObject *args)
1451
/* return self.__class__(self) */
1452
return PyObject_CallFunctionObjArgs((PyObject *)self->ob_type, self, NULL);
1456
Compile_get_precedence(CompileObject *self, PyObject *type)
1458
/* return self._precedence.get(type, MAX_PRECEDENCE) */
1459
PyObject *result = PyDict_GetItem(self->_precedence, type);
1460
if (result == NULL && !PyErr_Occurred()) {
1461
/* That should be MAX_PRECEDENCE, defined in expr.py */
1462
return PyInt_FromLong(1000);
1469
Compile_set_precedence(CompileObject *self, PyObject *args)
1471
Py_ssize_t size = PyTuple_GET_SIZE(args);
1472
PyObject *precedence = NULL;
1477
PyErr_SetString(PyExc_TypeError,
1478
"set_precedence() takes at least 2 arguments.");
1482
/* for type in types: */
1483
precedence = PyTuple_GET_ITEM(args, 0);
1484
for (i = 1; i != size; i++) {
1485
PyObject *type = PyTuple_GET_ITEM(args, i);
1486
/* self._local_precedence[type] = precedence */
1487
CATCH(-1, PyDict_SetItem(self->_local_precedence, type, precedence));
1490
/* self._update_cache() */
1491
CATCH(NULL, tmp = Compile__update_cache(self, NULL));
1500
Compile_single(CompileObject *self,
1501
PyObject *expr, PyObject *state, PyObject *outer_precedence)
1503
PyObject *inner_precedence = NULL;
1504
PyObject *statement = NULL;
1506
/* cls = expr.__class__ */
1507
PyObject *cls = (PyObject *)expr->ob_type;
1510
dispatch_table = self._dispatch_table
1511
if cls in dispatch_table:
1512
handler = dispatch_table[cls]
1515
PyObject *handler = PyDict_GetItem(self->_dispatch_table, cls);
1520
if (PyErr_Occurred())
1523
/* for mro_cls in cls.__mro__: */
1524
mro = expr->ob_type->tp_mro;
1525
size = PyTuple_GET_SIZE(mro);
1526
for (i = 0; i != size; i++) {
1527
PyObject *mro_cls = PyTuple_GET_ITEM(mro, i);
1529
if mro_cls in dispatch_table:
1530
handler = dispatch_table[mro_cls]
1533
handler = PyDict_GetItem(self->_dispatch_table, mro_cls);
1537
if (PyErr_Occurred())
1543
raise CompileError("Don't know how to compile type %r of %r"
1544
% (expr.__class__, expr))
1546
PyObject *repr = PyObject_Repr(expr);
1548
PyErr_Format(CompileError,
1549
"Don't know how to compile type %s of %s",
1550
expr->ob_type->tp_name, PyString_AS_STRING(repr));
1558
inner_precedence = state.precedence = \
1559
self._precedence.get(cls, MAX_PRECEDENCE)
1561
CATCH(NULL, inner_precedence = Compile_get_precedence(self, cls));
1562
CATCH(-1, PyObject_SetAttrString(state, "precedence", inner_precedence));
1564
/* statement = handler(self, expr, state) */
1565
CATCH(NULL, statement = PyObject_CallFunctionObjArgs(handler, self, expr,
1568
/* if inner_precedence < outer_precedence: */
1569
if (PyObject_Compare(inner_precedence, outer_precedence) == -1) {
1570
PyObject *args, *tmp;
1572
if (PyErr_Occurred())
1575
/* return "(%s)" % statement */
1576
CATCH(NULL, args = PyTuple_Pack(1, statement));
1577
tmp = PyUnicode_Format(parenthesis_format, args);
1580
Py_DECREF(statement);
1584
Py_DECREF(inner_precedence);
1589
Py_XDECREF(inner_precedence);
1590
Py_XDECREF(statement);
1596
Compile_one_or_many(CompileObject *self, PyObject *expr, PyObject *state,
1597
PyObject *join, int raw, int token)
1599
PyObject *outer_precedence = NULL;
1600
PyObject *compiled = NULL;
1601
PyObject *sequence = NULL;
1602
PyObject *statement = NULL;
1608
expr_type = type(expr)
1609
if (expr_type is SQLRaw or
1610
raw and (expr_type is str or expr_type is unicode)):
1613
if ((PyObject *)expr->ob_type == SQLRaw ||
1614
(raw && (PyString_CheckExact(expr) || PyUnicode_CheckExact(expr)))) {
1615
/* Pass our reference on. */
1620
if token and (expr_type is str or expr_type is unicode):
1621
expr = SQLToken(expr)
1623
if (token && (PyString_CheckExact(expr) || PyUnicode_CheckExact(expr))) {
1625
CATCH(NULL, tmp = PyObject_CallFunctionObjArgs(SQLToken, expr, NULL));
1634
/* That's done in Compile__call__ just once. */
1636
/* outer_precedence = state.precedence */
1637
CATCH(NULL, outer_precedence = PyObject_GetAttrString(state, "precedence"));
1638
/* if expr_type is tuple or expr_type is list: */
1639
if (PyTuple_CheckExact(expr) || PyList_CheckExact(expr)) {
1641
CATCH(NULL, compiled = PyList_New(0));
1643
/* for subexpr in expr: */
1644
sequence = PySequence_Fast(expr, "This can't actually fail! ;-)");
1645
size = PySequence_Fast_GET_SIZE(sequence);
1646
for (i = 0; i != size; i++) {
1647
PyObject *subexpr = PySequence_Fast_GET_ITEM(sequence, i);
1649
subexpr_type = type(subexpr)
1650
if subexpr_type is SQLRaw or raw and (subexpr_type is str or
1651
subexpr_type is unicode):
1653
if ((PyObject *)subexpr->ob_type == (PyObject *)SQLRaw ||
1654
(raw && (PyString_CheckExact(subexpr) ||
1655
PyUnicode_CheckExact(subexpr)))) {
1656
/* statement = subexpr */
1658
statement = subexpr;
1659
/* elif subexpr_type is tuple or subexpr_type is list: */
1660
} else if (PyTuple_CheckExact(subexpr) ||
1661
PyList_CheckExact(subexpr)) {
1662
/* state.precedence = outer_precedence */
1663
CATCH(-1, PyObject_SetAttrString(state, "precedence",
1665
/* statement = self(subexpr, state, join, raw, token) */
1667
statement = Compile_one_or_many(self, subexpr, state,
1672
if token and (subexpr_type is unicode or
1673
subexpr_type is str):
1675
if (token && (PyUnicode_CheckExact(subexpr) ||
1676
PyString_CheckExact(subexpr))) {
1677
/* subexpr = SQLToken(subexpr) */
1679
subexpr = PyObject_CallFunctionObjArgs(SQLToken,
1687
statement = self._compile_single(subexpr, state,
1690
statement = Compile_single(self, subexpr, state,
1693
CATCH(NULL, statement);
1696
/* compiled.append(statement) */
1697
CATCH(-1, PyList_Append(compiled, statement));
1698
Py_CLEAR(statement);
1702
/* statement = join.join(compiled) */
1703
CATCH(NULL, statement = PyUnicode_Join(join, compiled));
1706
/* statement = self._compile_single(expr, state, outer_precedence) */
1707
CATCH(NULL, statement = Compile_single(self, expr, state,
1711
/* state.precedence = outer_precedence */
1712
CATCH(-1, PyObject_SetAttrString(state, "precedence", outer_precedence));
1713
Py_CLEAR(outer_precedence);
1721
Py_XDECREF(outer_precedence);
1722
Py_XDECREF(compiled);
1723
Py_XDECREF(sequence);
1724
Py_XDECREF(statement);
1730
Compile__call__(CompileObject *self, PyObject *args, PyObject *kwargs)
1732
static char *kwlist[] = {"expr", "state", "join", "raw", "token", NULL};
1733
PyObject *expr = NULL;
1734
PyObject *state = Py_None;
1739
PyObject *result = NULL;
1741
if (!initialize_globals())
1744
join = default_compile_join;
1746
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OSbb", kwlist,
1747
&expr, &state, &join, &raw, &token)) {
1751
if (state == Py_None) {
1752
state = PyObject_CallFunctionObjArgs(State, NULL);
1757
result = Compile_one_or_many(self, expr, state, join, raw, token);
1764
static PyMethodDef Compile_methods[] = {
1765
{"_update_cache", (PyCFunction)Compile__update_cache, METH_NOARGS, NULL},
1766
{"when", (PyCFunction)Compile_when, METH_VARARGS, NULL},
1767
{"add_reserved_words", (PyCFunction)Compile_add_reserved_words,
1769
{"remove_reserved_words", (PyCFunction)Compile_remove_reserved_words,
1771
{"is_reserved_word", (PyCFunction)Compile_is_reserved_word, METH_O, NULL},
1772
{"create_child", (PyCFunction)Compile_create_child, METH_NOARGS, NULL},
1773
{"get_precedence", (PyCFunction)Compile_get_precedence, METH_O, NULL},
1774
{"set_precedence", (PyCFunction)Compile_set_precedence, METH_VARARGS, NULL},
1778
#define OFFSETOF(x) offsetof(CompileObject, x)
1779
static PyMemberDef Compile_members[] = {
1780
{"_local_dispatch_table", T_OBJECT, OFFSETOF(_local_dispatch_table), 0, 0},
1781
{"_local_precedence", T_OBJECT, OFFSETOF(_local_precedence), 0, 0},
1782
{"_local_reserved_words", T_OBJECT, OFFSETOF(_local_reserved_words), 0, 0},
1783
{"_dispatch_table", T_OBJECT, OFFSETOF(_dispatch_table), 0, 0},
1784
{"_precedence", T_OBJECT, OFFSETOF(_precedence), 0, 0},
1785
{"_reserved_words", T_OBJECT, OFFSETOF(_reserved_words), 0, 0},
1786
{"_children", T_OBJECT, OFFSETOF(_children), 0, 0},
1787
{"_parents", T_OBJECT, OFFSETOF(_parents), 0, 0},
1792
statichere PyTypeObject Compile_Type = {
1793
PyObject_HEAD_INIT(NULL)
1795
"storm.variables.Compile", /*tp_name*/
1796
sizeof(CompileObject), /*tp_basicsize*/
1798
(destructor)Compile_dealloc, /*tp_dealloc*/
1805
0, /*tp_as_sequence*/
1806
0, /*tp_as_mapping*/
1808
(ternaryfunc)Compile__call__, /*tp_call*/
1810
PyObject_GenericGetAttr,/*tp_getattro*/
1811
PyObject_GenericSetAttr,/*tp_setattro*/
1813
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1815
(traverseproc)Compile_traverse, /*tp_traverse*/
1816
(inquiry)Compile_clear, /*tp_clear*/
1817
0, /*tp_richcompare*/
1818
offsetof(CompileObject, __weakreflist), /*tp_weaklistoffset*/
1821
Compile_methods, /*tp_methods*/
1822
Compile_members, /*tp_members*/
1828
0, /*tp_dictoffset*/
1829
(initproc)Compile_init, /*tp_init*/
1830
PyType_GenericAlloc, /*tp_alloc*/
1831
PyType_GenericNew, /*tp_new*/
1832
PyObject_GC_Del, /*tp_free*/
681
1838
ObjectInfo__emit_object_deleted(ObjectInfoObject *self, PyObject *args)
683
1840
/* self.event.emit("object-deleted") */