Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.58
 
1.59
 
MAIN:ragge:20030619140917
 
pftn.c
_>1414 
 1515 struct params;
 1616 
<> 17+#define ISSTR(ty) (ty == STRTY || ty == UNIONTY || ty == ENUMTY)
  18+#define ISSOU(ty) (ty == STRTY || ty == UNIONTY)
  19+#define MKTY(p, t, d, s) r = talloc(); *r = *p; \
  20+        r = argcast(r, t, d, s); *p = *r; r->n_op = FREE;
  21+
1722 /*
 1823  * Argument list member info when storing prototypes.
 1924  */
     
 !
169174                         ++dsym;
 170175                         ++ddef;
 171176                 } else if (ISFTN(temp)) {
<>172 -                        union arglist *usym = dsym->dfun;
 173 -                        union arglist *udef = ddef->dfun;
 174 -                        if (usym == NULL) {
 175 -                                dsym++, ddef++;
 176 -                                continue;
 177 -                        }
 178 -                        if (udef == NULL && usym->type != TNULL)
 179 -                                goto mismatch;
 180 -                        while (usym->type != TNULL) {
 181 -                                TWORD t2 = usym->type;
 182 -                                if (usym->type != udef->type)
 183 -                                        goto mismatch;
 184 -                                while (t2 > BTMASK) {
 185 -                                        /* XXX no multilevel checks */
 186 -                                        if (ISFTN(t2))
 187 -                                                usym++, udef++;
 188 -                                        t2 = DECREF(t2);
 189 -                                }
 190 -                                usym++, udef++;
 191 -                        }
 192 -                        if (usym->type != udef->type)
 193 -                                goto mismatch;
  177+                        if (!oldstyle && chkftn(dsym->dfun, ddef->dfun))
  178+                                uerror("declaration doesn't match prototype");
194179                         dsym++, ddef++;
 195180                 }
 196181         }
     
 !
236221         case STATIC:
 237222                 if (scl==USTATIC || (scl==EXTERN && blevel==0)) {
 238223                         p->sclass = STATIC;
<>239 -                        if (ISFTN(type))
 240 -                                cftnsp = p;
241224                         return;
 242225                 }
 243226                 break;
     
 !
260243         case FORTRAN:
 261244                 if (scl == UFORTRAN) {
 262245                         p->sclass = FORTRAN;
<>263 -                        if (ISFTN(type))
 264 -                                cftnsp = p;
265246                         return;
 266247                 }
 267248                 break;
     
 !
285266                 switch (scl) {
 286267                 case EXTERN:
 287268                         p->sclass = EXTDEF;
<>288 -                        if (ISFTN(type))
 289 -                                cftnsp = p;
290269                         return;
 291270                 case USTATIC:
 292271                         p->sclass = STATIC;
<>293 -                        if (ISFTN(type))
 294 -                                cftnsp = p;
295272                         return;
 296273                 }
 297274                 break;
     
 !
318295         if (blevel == slev || class == EXTERN || class == FORTRAN ||
 319296             class == UFORTRAN) {
 320297                 uerror("redeclaration of %s", p->sname);
<>321 -                if (class == EXTDEF && ISFTN(type))
 322 -                        cftnsp = p;
323298                 return;
 324299         }
 325300         q->n_sp = p = hide(p);
     
 !
373348                 p->soffset = getlab();
 374349                 if (class == STATIC && blevel > 0)
 375350                         p->sflags |= SLABEL;
<>376 -                if (ISFTN(type))
 377 -                        cftnsp = p;
378351                 break;
 379352 
 380353         case EXTERN:
     
 !
471444 void
 472445 dclargs()
 473446 {
<> 447+        union dimfun *df;
  448+        union arglist *al, *al2, *alb;
474449         struct params *a;
 475450         struct symtab *p, **parr;
 476451         int i;
 477452 
<>478 -        blevel = 1;
479453         argoff = ARGINIT;
 480454 #ifdef PCC_DEBUG
 481455         if (ddebug > 2)
 482456                 printf("dclargs()\n");
 483457 #endif
 484458 
 485459         /*
<> 460+         * Deal with fun(void) properly.
  461+         */
  462+        if (nparams == 1 && lparam->sym->stype == UNDEF)
  463+                goto done;
  464+
  465+        /*
486466          * Generate a list for bfcode().
 487467          * Parameters were pushed in reverse order.
 488468          */
     
 !
492472         for (a = lparam, i = 0; a != NULL && a != (struct params *)&lpole;
 493473             a = a->prev) {
 494474 
<>495 -                /*
 496 -                 * Enter function args into the symbol table.
 497 -                 */
 498 -                p = lookup(a->sym->sname, 0);
 499 -                if (p->stype != UNDEF)
 500 -                        p = hide(p);
 501 -
 502 -                p->stype = a->sym->stype;
 503 -                p->soffset = NOOFFSET;
 504 -                p->sclass = PARAM;
 505 -                p->sdf = a->sym->sdf;
 506 -                p->ssue = a->sym->ssue;
 507 -
  475+                p = a->sym;
508476                 parr[i++] = p;
<> 477+                if (p->stype == FARG) {
  478+                        p->stype = INT;
  479+                        p->ssue = MKSUE(INT);
  480+                }
  481+                if (ISARY(p->stype)) {
  482+                        p->stype += (PTR-ARY);
  483+                        p->sdf++;
  484+                }
509485 #ifdef PCC_DEBUG
 510486                 if (ddebug > 2) {       /* XXX 4.4 */
<>511 -                        printf("\t%s (%p) ",p->sname, p);
  487+                        printf("\t%s (%p) ", p->sname, p);
512488                         tprint(p->stype);
 513489                         printf("\n");
 514490                 }
 515491 #endif
 516492                 /* always set aside space, even for register arguments */
 517493                 oalloc(p, &argoff);
 518494         }
<>519 -        cendarg();
  495+        if (oldstyle && (df = cftnsp->sdf) && (al = df->dfun)) {
  496+                /*
  497+                 * Check against prototype of oldstyle function.
  498+                 */
  499+                alb = al2 = tmpalloc(sizeof(union arglist) * nparams * 3 + 1);
  500+                for (i = 0; i < nparams; i++) {
  501+                        TWORD type = parr[i]->stype;
  502+                        (al2++)->type = type;
  503+                        if (ISSTR(BTYPE(type)))
  504+                                (al2++)->sue = parr[i]->ssue;
  505+                        while (!ISFTN(type) && !ISARY(type) && type > BTMASK)
  506+                                type = DECREF(type);
  507+                        if (type > BTMASK)
  508+                                (al2++)->df = parr[i]->sdf;
  509+                }
  510+                al2->type = TNULL;
  511+                if (chkftn(al, alb))
  512+                        uerror("function doesn't match prototype");
  513+        }
  514+done:   cendarg();
520515         locctr(PROG);
 521516         defalign(ALINT);
 522517         ftnno = getlab();
     
 !
768763                 printf("ftnarg(%p)\n", p);
 769764 #endif
 770765         /*
<>771 -         * Enter argument into param stack.
  766+         * Enter argument onto param stack.
772767          * Do not declare parameters until later (in dclargs);
 773768          * the function must be declared first.
 774769          * put it on the param stack in reverse order, due to the
     
 !
782777         }
 783778 
 784779         p = p->n_right;
<> 780+        blevel = 1;
785781 
 786782         while (p->n_op == CM) {
 787783                 q = p->n_right;
 788784                 if (q->n_op != ELLIPSIS) {
<>789 -                        s = getsymtab((char *)q->n_sp, STEMP);
  785+                        s = lookup((char *)q->n_sp, 0);
  786+                        if (s->stype != UNDEF) {
  787+                                if (s->slevel > 0)
  788+                                        uerror("parameter '%s' redefined",
  789+                                            s->sname);
  790+                                s = hide(s);
  791+                        }
  792+                        s->soffset = NOOFFSET;
  793+                        s->sclass = PARAM;
790794                         s->stype = q->n_type;
 791795                         s->sdf = q->n_df;
 792796                         s->ssue = q->n_sue;
     
 !
800804                 }
 801805                 p = p->n_left;
 802806         }
<>803 -        s = getsymtab((char *)p->n_sp, STEMP);
  807+        s = lookup((char *)p->n_sp, 0);
  808+        if (s->stype != UNDEF) {
  809+                if (s->slevel > 0)
  810+                        uerror("parameter '%s' redefined", s->sname);
  811+                s = hide(s);
  812+        }
  813+        s->soffset = NOOFFSET;
  814+        s->sclass = PARAM;
804815         s->stype = p->n_type;
 805816         s->sdf = p->n_df;
 806817         s->ssue = p->n_sue;
 807818         ssave(s);
 808819         nparams++;
<> 820+        blevel = 0;
  821+
809822 #ifdef PCC_DEBUG
 810823         if (ddebug > 2)
 811824                 printf("        saving sym %s (%p) from (%p)\n",
     
 !
20262039                         ap[j]->n_op = ICON; /* for tfree() */
 20272040                         continue;
 20282041                 }
<> 2042+                /* Convert arrays to pointers */
  2043+                if (ISARY(ap[j]->n_type)) {
  2044+                        ap[j]->n_type += (PTR-ARY);
  2045+                        ap[j]->n_df++;
  2046+                }
20292047                 ty = ap[j]->n_type;
 20302048                 al[k++].type = ty;
 20312049                 if (BTYPE(ty) == STRTY || BTYPE(ty) == UNIONTY ||
     
 !
21152133         return u->n_right;
 21162134 }
 21172135 
<>2118 -#define ISSTR(ty) (ty == STRTY || ty == UNIONTY || ty == ENUMTY)
 2119 -#define ISSOU(ty) (ty == STRTY || ty == UNIONTY)
 2120 -#define MKTY(p, t, d, s) r = talloc(); *r = *p; \
 2121 -        r = argcast(r, t, d, s); *p = *r; r->n_op = FREE;
21222136 
<>2123 -
21242137 /*
 21252138  * Do prototype checking and add conversions before calling a function.
 21262139  */
     
 !
21332146                 struct ap *next;
 21342147                 NODE *node;
 21352148         } *at, *apole = NULL;
<>2136 -        int argidx;
  2149+        int argidx, hasarray;
21372150         TWORD type, arrt;
 21382151 
 21392152         /*
 21402153          * Do some basic checks.
 21412154          */
<>2142 -        if ((al = f->n_df[0].dfun) == NULL) {
  2155+        if (f->n_df == NULL || (al = f->n_df[0].dfun) == NULL) {
21432156                 werror("no prototype for function");
 21442157                 goto build;
 21452158         }
     
 !
21732186          */
 21742187         argidx = 1;
 21752188         while (al->type != TNULL) {
<> 2189+                if (al->type == TELLIPSIS)
  2190+                        goto build;
21762191                 if (apole == NULL) {
 21772192                         uerror("too few arguments to function");
 21782193                         goto build;
 21792194                 }
<>2180 -                if (al->type == TELLIPSIS)
 2181 -                        goto build;
21822195                 type = apole->node->n_type;
 21832196                 arrt = al->type;
<> 2197+                if ((hasarray = ISARY(arrt)))
  2198+                        arrt += (PTR-ARY);
  2199+                if (ISARY(type))
  2200+                        type += (PTR-ARY);
21842201 
 21852202                 /* Check structs */
 21862203                 if (type <= BTMASK && arrt <= BTMASK) {
     
 !
22292246 out:            al++;
 22302247                 if (ISSTR(BTYPE(arrt)))
 22312248                         al++;
<> 2249+                while (arrt > BTMASK && !ISFTN(arrt))
  2250+                        arrt = DECREF(arrt);
  2251+                if (ISFTN(arrt) || hasarray)
  2252+                        al++;
22322253                 apole = apole->next;
 22332254                 argidx++;
 22342255         }
     
 !
22382259 build:  return buildtree(a == NIL ? UNARY CALL : CALL, f, a);
 22392260 }
 22402261 
<> 2262+static int
  2263+chk2(TWORD type, union dimfun *dsym, union dimfun *ddef)
  2264+{
  2265+        while (type > BTMASK) {
  2266+                switch (type & TMASK) {
  2267+                case ARY:
  2268+                        if ((dsym++)->ddim != (ddef++)->ddim)
  2269+                                return 1;
  2270+                        break;
  2271+                case FTN:
  2272+                        if (chkftn((dsym++)->dfun, (ddef++)->dfun))
  2273+                                return 1;
  2274+                        break;
  2275+                }
  2276+                type = DECREF(type);
  2277+        }
  2278+        return 0;
  2279+}
  2280+
  2281+int
  2282+chkftn(union arglist *usym, union arglist *udef)
  2283+{
  2284+        TWORD t2;
  2285+        int ty;
  2286+
  2287+        if (usym == NULL)
  2288+                return 0;
  2289+        if (cftnsp != NULL && udef == NULL && usym->type == UNDEF)
  2290+                return 0; /* foo() { function with foo(void); prototype */
  2291+        if (udef == NULL && usym->type != TNULL)
  2292+                return 1;
  2293+        while (usym->type != TNULL) {
  2294+                if (usym->type != udef->type)
  2295+                        return 1;
  2296+                ty = BTYPE(usym->type);
  2297+                t2 = usym->type;
  2298+                if (ISSTR(ty)) {
  2299+                        usym++, udef++;
  2300+                        if (usym->sue != udef->sue)
  2301+                                return 1;
  2302+                }
  2303+
  2304+                while (ISFTN(t2) == 0 && ISARY(t2) == 0 && t2 > BTMASK)
  2305+                        t2 = DECREF(t2);
  2306+                if (t2 > BTMASK) {
  2307+                        usym++, udef++;
  2308+                        if (chk2(t2, usym->df, udef->df))
  2309+                                return 1;
  2310+                }
  2311+                usym++, udef++;
  2312+        }
  2313+        if (usym->type != udef->type)
  2314+                return 1;
  2315+        return 0;
  2316+}
  2317+
<_22412318 void
 22422319 fixtype(NODE *p, int class)
 22432320 {
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-22 05:58 +0100