File: op_sibling_splice.c.inc

package info (click to toggle)
libsyntax-keyword-try-perl 0.30-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 260 kB
  • sloc: perl: 898; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 959 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* vi: set ft=c : */

#ifndef op_sibling_splice
#  define op_sibling_splice(parent, start, del_count, insert)  S_op_sibling_splice(aTHX_ parent, start, del_count, insert)
static OP *S_op_sibling_splice(pTHX_ OP *parent, OP *start, int del_count, OP *insert)
{
  OP *deleted = NULL;

  if(!insert && !del_count)
    return NULL;

  OP **prevp;
  if(start)
    prevp = &(start->op_sibling);
  else
    prevp = &(cLISTOPx(parent)->op_first);

  OP *after = *prevp;

  if(del_count) {
    croak("Back-compat op_sibling_splice with del_count != 0 not yet implemented");
    /* THIS IS AS YET UNTESTED
    deleted = *prevp;
    OP *o = deleted;
    while(del_count > 1)
      o = o->op_sibling, del_count--;
    after = o->op_sibling;
    o->op_sibling = NULL;
    */
  }

  if(insert) {
    *prevp = insert;
    OP *o = insert;
    while(o->op_sibling)
      o = o->op_sibling;
    o->op_sibling = after;
  }
  else
    *prevp = after;

  return deleted;
}
#endif