Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.56
 
1.57
 
MAIN:ragge:20030617115142
 
pftn.c
_>20922092         p->n_type = p->n_left->n_type;
 20932093 }
 20942094 
<> 2095+static NODE *
  2096+argcast(NODE *p, TWORD t, union dimfun *d, struct suedef *sue)
  2097+{
  2098+        NODE *u, *r = talloc();
  2099+
  2100+        r->n_op = NAME;
  2101+        r->n_type = t;
  2102+        r->n_df = d;
  2103+        r->n_sue = sue;
  2104+
  2105+        u = buildtree(CAST, r, p);
  2106+        u->n_left->n_op = FREE;
  2107+        u->n_op = FREE;
  2108+        return u->n_right;
  2109+}
  2110+
  2111+#define ISSTR(ty) (ty == STRTY || ty == UNIONTY || ty == ENUMTY)
  2112+#define ISSOU(ty) (ty == STRTY || ty == UNIONTY)
  2113+#define MKTY(p, t, d, s) r = talloc(); *r = *p; \
  2114+        r = argcast(r, t, d, s); *p = *r; r->n_op = FREE;
  2115+
  2116+
  2117+/*
  2118+ * Do prototype checking and add conversions before calling a function.
  2119+ */
  2120+NODE *
  2121+doacall(NODE *f, NODE *a)
  2122+{
  2123+        NODE *w, *r;
  2124+        union arglist *al;
  2125+        struct ap {
  2126+                struct ap *next;
  2127+                NODE *node;
  2128+        } *at, *apole = NULL;
  2129+        int argidx;
  2130+        TWORD type, arrt;
  2131+
  2132+        /*
  2133+         * Do some basic checks.
  2134+         */
  2135+        if ((al = f->n_df[0].dfun) == NULL) {
  2136+                werror("no prototype for function");
  2137+                goto build;
  2138+        }
  2139+        if (al->type == UNDEF) {
  2140+                if (a != NULL)
  2141+                        uerror("function takes no arguments");
  2142+                goto build; /* void function */
  2143+        } else {
  2144+                if (a == NULL) {
  2145+                        uerror("function needs arguments");
  2146+                        goto build;
  2147+                }
  2148+        }
  2149+
  2150+        /*
  2151+         * Create a list of pointers to the nodes given as arg.
  2152+         */
  2153+        for (w = a; w->n_op == CM; w = w->n_left) {
  2154+                at = tmpalloc(sizeof(struct ap));
  2155+                at->node = w->n_right;
  2156+                at->next = apole;
  2157+                apole = at;
  2158+        }
  2159+        at = tmpalloc(sizeof(struct ap));
  2160+        at->node = w;
  2161+        at->next = apole;
  2162+        apole = at;
  2163+
  2164+        /*
  2165+         * Do the typechecking by walking up the list.
  2166+         */
  2167+        argidx = 1;
  2168+        while (al->type != TNULL) {
  2169+                if (apole == NULL) {
  2170+                        uerror("too few arguments to function");
  2171+                        goto build;
  2172+                }
  2173+                if (al->type == TELLIPSIS)
  2174+                        goto build;
  2175+                type = apole->node->n_type;
  2176+                arrt = al->type;
  2177+
  2178+                /* Check structs */
  2179+                if (type <= BTMASK && arrt <= BTMASK) {
  2180+                        if (type != arrt) {
  2181+                                if (ISSOU(BTYPE(type)) || ISSOU(BTYPE(arrt))) {
  2182+incomp:                                 uerror("incompatible types for arg %d",
  2183+                                            argidx);
  2184+                                } else {
  2185+                                        MKTY(apole->node, arrt, 0, 0)
  2186+                                }
  2187+                        } else if (ISSOU(BTYPE(type))) {
  2188+                                if (apole->node->n_sue != al[1].sue)
  2189+                                        goto incomp;
  2190+                        }
  2191+                        goto out;
  2192+                }
  2193+
  2194+                /* Hereafter its only pointers left */
  2195+                if (((type <= BTMASK) && ISSOU(BTYPE(type))) ||
  2196+                    ((arrt <= BTMASK) && ISSOU(BTYPE(arrt))))
  2197+                        goto incomp;
  2198+
  2199+                if (type == arrt) {
  2200+                        if (ISSOU(BTYPE(type))) {
  2201+                                if (apole->node->n_sue == al[1].sue)
  2202+                                        goto out;
  2203+                        } else
  2204+                                goto out;
  2205+                }
  2206+                if (BTYPE(arrt) == UNDEF && type > BTMASK)
  2207+                        goto skip; /* void *f = some pointer */
  2208+                if (arrt > BTMASK && BTYPE(type) == UNDEF)
  2209+                        goto skip; /* some *f = void pointer */
  2210+                if (apole->node->n_op == ICON && apole->node->n_lval == 0)
  2211+                        goto skip; /* Anything assigned a zero */
  2212+
  2213+                werror("implicit conversion of argument %d due to prototype",
  2214+                    argidx);
  2215+
  2216+skip:           if (ISSTR(BTYPE(arrt))) {
  2217+                        MKTY(apole->node, arrt, 0, al[1].sue)
  2218+                } else {
  2219+                        MKTY(apole->node, arrt, 0, 0)
  2220+                }
  2221+
  2222+out:            al++;
  2223+                if (ISSTR(BTYPE(arrt)))
  2224+                        al++;
  2225+                apole = apole->next;
  2226+                argidx++;
  2227+        }
  2228+        if (apole != NULL)
  2229+                uerror("too many arguments to function");
  2230+
  2231+build:  return buildtree(a == NIL ? UNARY CALL : CALL, f, a);
  2232+}
  2233+
<_20952234 void
 20962235 fixtype(NODE *p, int class)
 20972236 {
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-10-31 09:27 +0100