File: callfun.c

package info (click to toggle)
icmake 6.30-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,360 kB
  • ctags: 1,415
  • sloc: ansic: 7,727; makefile: 1,465; sh: 244; asm: 126; cpp: 39
file content (74 lines) | stat: -rw-r--r-- 2,087 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
64
65
66
67
68
69
70
71
72
73
74
/*
                            C A L L F U N . C
*/

#include "iccomp.h"

ESTRUC_ *callfun(x, e)
    unsigned
        x;
    ESTRUC_
        *e;
{
    ESTRUC_
        *a;
    register unsigned
        index,
        n_pars;
    unsigned
        err,
        old_sem;

    if (x != funtab.n_defined)              /* function name found ? */
    {                                       /* then check correct # of args */
        n_pars = funtab.symbol[x].var.vu.i->ls.list.size;
        if ((unsigned)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,
                index = 0;
                    index < n_pars;
                        index++,
                        a++
            )
            {
                if
                (
                    !
                    (
                        ((char *)
                           funtab.symbol[x].var.vu.i->ls.list.element)[index]
                        & a->type & ALLTYPES
                    )
                )
                {
                    old_sem = sem_err;
                    err = 1;
                    semantic("Incorrect type of argument %u of function '%s()'",
                        index + 1, funtab.symbol[x].name);
                    sem_err = old_sem;
                }
            }
            sem_err |= err;
        }
    }
    else
        n_pars = 0;                         /* prevent unitialized n_pars */

    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 */
}