File: ifstmnt.c

package info (click to toggle)
icmake 6.22-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,120 kB
  • ctags: 1,045
  • sloc: ansic: 9,241; makefile: 1,138; asm: 126; sh: 124
file content (63 lines) | stat: -rw-r--r-- 1,547 bytes parent folder | download | duplicates (4)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
                            I F S T M N T . C
*/

#include "iccomp.h"

ESTRUC_ *if_stmnt(e, s, s2)
    ESTRUC_
        *e,
        *s,
        *s2;
{
    register unsigned
        len;
    unsigned
        *list;

    nestlevel--;                            /* reduce nesting level */

    etob(e);                                /* make links for E */

    if (test_type(e, e_const))              /* constant: either always/never */
    {
        discard(e);
        if (e->evalue)                      /* S always executed */
        {
            discard(s2);
            return (s);
        }
        else                                /* S2 always executed */
        {
            discard(s);
            return (s2);
        }
    }

    patchup_true(e, 1);                     /* patch to EOC */

    if (!s2->type)                          /* no S2 */
    {
        catcode(e, s);                      /* E = E ~ S */
        return (e);
    }

    gencode(s, op_jmp, j_falselist);

    list = s->falselist;                    /* save the falselist */
    len  = s->falselen;

    addpatch(list, len, e->codelen);       /* increase the patch targets */

    s->falselen = 0;

    catcode(e, s);                          /* E = E ~ S */
    patchup_false(e, 1);                   /* patch to EOC */

    e->falselen = len;                      /* restore the falselist */
    e->falselist = list;

    catcode(e, s2);                         /* if .. else cat. */

    return (e);                             /* if .. else return */
}