File: callfun.c

package info (click to toggle)
icmake 7.18.00-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,840 kB
  • sloc: ansic: 7,784; makefile: 3,811; sh: 319; cpp: 83
file content (94 lines) | stat: -rw-r--r-- 2,292 bytes parent folder | download | duplicates (2)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
                            C A L L F U N . C
*/

#include "iccomp.h"

ESTRUC_ *callfun(x, e)
    size_t
        x;
    ESTRUC_
        *e;
{
    ESTRUC_
        *a;
    register size_t
        idx,
        n_pars;
    size_t
        err,
        old_sem;

/*
    fprintf(stderr,
        "type: %d\n"
        "truelen: %d\n"
        "falselen: %d\n"
        "codelen: %d\n"
        "evalue: %d\n"
        "truelist: %p\n"
        "falselist: %p\n"
        "code: %p\n",
        e->type,
        e->truelen,
        e->falselen,
        e->codelen,
        e->evalue,
        e->truelist,
        e->falselist,
        e->code);
*/            

    if (x == funtab.n_defined)              /* function name not found ? */
        return e;                           /* nothing to do here        */


                                            /* then check correct # of args */
    n_pars = funtab.symbol[x].var.vu.i->ls.list.size;
    if ((size_t)e->type != n_pars)
    {
        err = 1;
        semantic("Function '%s()' requires %u arguments",
                    funtab.symbol[x].name, n_pars);
    }
    else
    {                                   /* and check argument types */
        for
        (
            err = 0,
            a = (ESTRUC_ *)e->code,
            idx = 0;
                idx < n_pars;
                    idx++,
                    a++
        )
        {
            if
            (
                !
                (
                    ((char *)
                       funtab.symbol[x].var.vu.i->ls.list.element)[idx]
                    & a->type & ALLTYPES
                )
            )
            {
                old_sem = sem_err;
                err = 1;
                semantic("Incorrect type of argument %u of function '%s()'",
                    idx + 1, funtab.symbol[x].name);
                sem_err = old_sem;
            }
        }
        sem_err |= err;
    }

    catargs(e);                             /* convert args to code */

                                            /* call function and clean stack */
    gencode(e, op_call, funtab.symbol[x].var.vu.i->count);
    gencode(e, op_asp,  n_pars);
    set_type(e, funtab.symbol[x].var.type);

    return e;                               /* return called function code */
}