Esempio n. 1
0
static PyObject *
pylist_children(D_Parser *parser, D_ParseNode *d, int string) {
  int i, nc = d_get_number_of_children(d);
  PyObject *list = PyList_New(nc);
  for (i=0; i<nc; i++) {
    D_ParseNode *child = d_get_child(d, i);
    PyObject *po = make_pyobject_from_node(parser, child, string);
    if (po == NULL) {
      Py_DECREF(list);
      return NULL;
    }
    PyList_SetItem(list, i, po);
  }
  return list;
}
Esempio n. 2
0
static void
inc_global_state(D_Parser *dp, D_ParseNode *dpn) {
  /* this global state stuff is ugly.  Does anyone actually use it? */
  int n_children = d_get_number_of_children(dpn);
  int i;
  for (i=0; i<n_children; i++) {
    D_ParseNode *child = d_get_child(dpn, i);
    if (has_deeper_nodes(dp, child)) {
      inc_global_state(dp, child);
    } else if (child->globals != NULL && !child->user.inced_global_state) {
      /* global state gets copied by dparser without increfing, fix */
      Py_INCREF(child->globals);
      child->user.inced_global_state = 1;
    }
  }
}
Esempio n. 3
0
static void
xprint_parsetree(D_ParserTables pt, D_ParseNode *pn, int depth, print_node_fn_t fn, void *client_data) {
    int nch = d_get_number_of_children(pn), i;
    char *name = pt.symbols[pn->symbol].name;
    //  int len = pn->end_skip - pn->start_loc.s;
    //  char *value = malloc(len+2);
    //  memcpy(value, pn->start_loc.s, len);
    //  value[len] = 0;
    char *value = dup_str(pn->start_loc.s, pn->end);
    fn(depth, name, value, client_data);
    free(value);

    depth++;
    if (nch != 0) {
        for (i = 0; i < nch; i++) {
            D_ParseNode *xpn = d_get_child(pn,i);
            xprint_parsetree(pt, xpn, depth, fn, client_data);
        }
    }
}