func.c (80284) | func.c (91592) |
---|---|
1/* $NetBSD: func.c,v 1.7 1995/10/02 17:31:40 jpo Exp $ */ | 1/* $NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $ */ |
2 3/* 4 * Copyright (c) 1994, 1995 Jochen Pohl 5 * All Rights Reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 16 unchanged lines hidden (view full) --- 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 | 2 3/* 4 * Copyright (c) 1994, 1995 Jochen Pohl 5 * All Rights Reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 16 unchanged lines hidden (view full) --- 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 |
34#ifndef lint 35static const char rcsid[] = 36 "$FreeBSD: head/usr.bin/xlint/lint1/func.c 80284 2001-07-24 14:02:07Z obrien $"; | 34#include <sys/cdefs.h> 35#if defined(__RCSID) && !defined(lint) 36__RCSID("$NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $"); |
37#endif | 37#endif |
38__FBSDID("$FreeBSD: head/usr.bin/xlint/lint1/func.c 91592 2002-03-03 15:12:50Z markm $"); |
|
38 39#include <stdlib.h> 40#include <string.h> 41 42#include "lint1.h" | 39 40#include <stdlib.h> 41#include <string.h> 42 43#include "lint1.h" |
43#include "y.tab.h" | 44#include "cgram.h" |
44 45/* 46 * Contains a pointer to the symbol table entry of the current function 47 * definition. 48 */ 49sym_t *funcsym; 50 51/* Is set as long as a statement can be reached. Must be set at level 0. */ --- 73 unchanged lines hidden (view full) --- 125int llibflg; 126 127/* 128 * Nonzero if warnings are suppressed by a LINTED directive 129 */ 130int nowarn; 131 132/* | 45 46/* 47 * Contains a pointer to the symbol table entry of the current function 48 * definition. 49 */ 50sym_t *funcsym; 51 52/* Is set as long as a statement can be reached. Must be set at level 0. */ --- 73 unchanged lines hidden (view full) --- 126int llibflg; 127 128/* 129 * Nonzero if warnings are suppressed by a LINTED directive 130 */ 131int nowarn; 132 133/* |
134 * Nonzero if bitfield type errors are suppressed by a BITFIELDTYPE 135 * directive. 136 */ 137int bitfieldtype_ok; 138 139/* |
|
133 * Nonzero if complaints about use of "long long" are suppressed in 134 * the next statement or declaration. 135 */ 136int quadflg; 137 138/* 139 * Puts a new element at the top of the stack used for control statements. 140 */ 141void | 140 * Nonzero if complaints about use of "long long" are suppressed in 141 * the next statement or declaration. 142 */ 143int quadflg; 144 145/* 146 * Puts a new element at the top of the stack used for control statements. 147 */ 148void |
142pushctrl(env) 143 int env; | 149pushctrl(int env) |
144{ 145 cstk_t *ci; 146 147 if ((ci = calloc(1, sizeof (cstk_t))) == NULL) 148 nomem(); 149 ci->c_env = env; 150 ci->c_nxt = cstk; 151 cstk = ci; 152} 153 154/* 155 * Removes the top element of the stack used for control statements. 156 */ 157void | 150{ 151 cstk_t *ci; 152 153 if ((ci = calloc(1, sizeof (cstk_t))) == NULL) 154 nomem(); 155 ci->c_env = env; 156 ci->c_nxt = cstk; 157 cstk = ci; 158} 159 160/* 161 * Removes the top element of the stack used for control statements. 162 */ 163void |
158popctrl(env) 159 int env; | 164popctrl(int env) |
160{ 161 cstk_t *ci; 162 clst_t *cl; 163 164 if (cstk == NULL || cstk->c_env != env) 165 lerror("popctrl() 1"); 166 167 cstk = (ci = cstk)->c_nxt; --- 8 unchanged lines hidden (view full) --- 176 177 free(ci); 178} 179 180/* 181 * Prints a warning if a statement cannot be reached. 182 */ 183void | 165{ 166 cstk_t *ci; 167 clst_t *cl; 168 169 if (cstk == NULL || cstk->c_env != env) 170 lerror("popctrl() 1"); 171 172 cstk = (ci = cstk)->c_nxt; --- 8 unchanged lines hidden (view full) --- 181 182 free(ci); 183} 184 185/* 186 * Prints a warning if a statement cannot be reached. 187 */ 188void |
184chkreach() | 189chkreach(void) |
185{ 186 if (!reached && !rchflg) { 187 /* statement not reached */ 188 warning(193); 189 reached = 1; 190 } 191} 192 193/* 194 * Called after a function declaration which introduces a function definition 195 * and before an (optional) old style argument declaration list. 196 * 197 * Puts all symbols declared in the Prototype or in an old style argument 198 * list back to the symbol table. 199 * 200 * Does the usual checking of storage class, type (return value), 201 * redeclaration etc.. 202 */ 203void | 190{ 191 if (!reached && !rchflg) { 192 /* statement not reached */ 193 warning(193); 194 reached = 1; 195 } 196} 197 198/* 199 * Called after a function declaration which introduces a function definition 200 * and before an (optional) old style argument declaration list. 201 * 202 * Puts all symbols declared in the Prototype or in an old style argument 203 * list back to the symbol table. 204 * 205 * Does the usual checking of storage class, type (return value), 206 * redeclaration etc.. 207 */ 208void |
204funcdef(fsym) 205 sym_t *fsym; | 209funcdef(sym_t *fsym) |
206{ 207 int n, warn; 208 sym_t *arg, *sym, *rdsym; 209 210 funcsym = fsym; 211 212 /* 213 * Put all symbols declared in the argument list back to the --- 105 unchanged lines hidden (view full) --- 319 320 if (fsym->s_osdef && !fsym->s_type->t_proto) { 321 if (sflag && hflag && strcmp(fsym->s_name, "main") != 0) 322 /* function definition is not a prototyp */ 323 warning(286); 324 } 325 326 if (dcs->d_notyp) | 210{ 211 int n, warn; 212 sym_t *arg, *sym, *rdsym; 213 214 funcsym = fsym; 215 216 /* 217 * Put all symbols declared in the argument list back to the --- 105 unchanged lines hidden (view full) --- 323 324 if (fsym->s_osdef && !fsym->s_type->t_proto) { 325 if (sflag && hflag && strcmp(fsym->s_name, "main") != 0) 326 /* function definition is not a prototyp */ 327 warning(286); 328 } 329 330 if (dcs->d_notyp) |
327 /* return value is implizitly declared to be int */ | 331 /* return value is implicitly declared to be int */ |
328 fsym->s_rimpl = 1; 329 330 reached = 1; 331} 332 333/* 334 * Called at the end of a function definition. 335 */ 336void | 332 fsym->s_rimpl = 1; 333 334 reached = 1; 335} 336 337/* 338 * Called at the end of a function definition. 339 */ 340void |
337funcend() | 341funcend(void) |
338{ 339 sym_t *arg; 340 int n; 341 342 if (reached) { 343 cstk->c_noretval = 1; 344 if (funcsym->s_type->t_subt->t_tspec != VOID && 345 !funcsym->s_rimpl) { --- 19 unchanged lines hidden (view full) --- 365 arg = arg->s_nxt; 366 n++; 367 } 368 nargusg = -1; 369 370 /* 371 * write the information about the function definition to the 372 * output file | 342{ 343 sym_t *arg; 344 int n; 345 346 if (reached) { 347 cstk->c_noretval = 1; 348 if (funcsym->s_type->t_subt->t_tspec != VOID && 349 !funcsym->s_rimpl) { --- 19 unchanged lines hidden (view full) --- 369 arg = arg->s_nxt; 370 n++; 371 } 372 nargusg = -1; 373 374 /* 375 * write the information about the function definition to the 376 * output file |
373 * inline functions explicitely declared extern are written as | 377 * inline functions explicitly declared extern are written as |
374 * declarations only. 375 */ 376 if (dcs->d_scl == EXTERN && funcsym->s_inline) { 377 outsym(funcsym, funcsym->s_scl, DECL); 378 } else { 379 outfdef(funcsym, &dcs->d_fdpos, cstk->c_retval, 380 funcsym->s_osdef, dcs->d_fargs); 381 } --- 13 unchanged lines hidden (view full) --- 395/* 396 * Process a label. 397 * 398 * typ type of the label (T_NAME, T_DEFAULT or T_CASE). 399 * sym symbol table entry of label if typ == T_NAME 400 * tn expression if typ == T_CASE 401 */ 402void | 378 * declarations only. 379 */ 380 if (dcs->d_scl == EXTERN && funcsym->s_inline) { 381 outsym(funcsym, funcsym->s_scl, DECL); 382 } else { 383 outfdef(funcsym, &dcs->d_fdpos, cstk->c_retval, 384 funcsym->s_osdef, dcs->d_fargs); 385 } --- 13 unchanged lines hidden (view full) --- 399/* 400 * Process a label. 401 * 402 * typ type of the label (T_NAME, T_DEFAULT or T_CASE). 403 * sym symbol table entry of label if typ == T_NAME 404 * tn expression if typ == T_CASE 405 */ 406void |
403label(typ, sym, tn) 404 int typ; 405 sym_t *sym; 406 tnode_t *tn; | 407label(int typ, sym_t *sym, tnode_t *tn) |
407{ 408 cstk_t *ci; 409 clst_t *cl; | 408{ 409 cstk_t *ci; 410 clst_t *cl; |
410 val_t *v, *nv; | 411 val_t *v; 412 val_t nv; |
411 tspec_t t; 412 413 switch (typ) { 414 415 case T_NAME: 416 if (sym->s_set) { 417 /* label %s redefined */ 418 error(194, sym->s_name); 419 } else { 420 setsflg(sym); 421 } 422 break; 423 424 case T_CASE: 425 426 /* find the stack entry for the innermost switch statement */ | 413 tspec_t t; 414 415 switch (typ) { 416 417 case T_NAME: 418 if (sym->s_set) { 419 /* label %s redefined */ 420 error(194, sym->s_name); 421 } else { 422 setsflg(sym); 423 } 424 break; 425 426 case T_CASE: 427 428 /* find the stack entry for the innermost switch statement */ |
427 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ; | 429 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) 430 continue; |
428 429 if (ci == NULL) { 430 /* case not in switch */ 431 error(195); 432 tn = NULL; 433 } else if (tn != NULL && tn->tn_op != CON) { 434 /* non-constant case expression */ 435 error(197); --- 23 unchanged lines hidden (view full) --- 459 warning(203); 460 } 461 462 /* 463 * get the value of the expression and convert it 464 * to the type of the switch expression 465 */ 466 v = constant(tn); | 431 432 if (ci == NULL) { 433 /* case not in switch */ 434 error(195); 435 tn = NULL; 436 } else if (tn != NULL && tn->tn_op != CON) { 437 /* non-constant case expression */ 438 error(197); --- 23 unchanged lines hidden (view full) --- 462 warning(203); 463 } 464 465 /* 466 * get the value of the expression and convert it 467 * to the type of the switch expression 468 */ 469 v = constant(tn); |
467 if ((nv = calloc(1, sizeof (val_t))) == NULL) 468 nomem(); 469 cvtcon(CASE, 0, ci->c_swtype, nv, v); | 470 (void) memset(&nv, 0, sizeof nv); 471 cvtcon(CASE, 0, ci->c_swtype, &nv, v); |
470 free(v); 471 472 /* look if we had this value already */ 473 for (cl = ci->c_clst; cl != NULL; cl = cl->cl_nxt) { | 472 free(v); 473 474 /* look if we had this value already */ 475 for (cl = ci->c_clst; cl != NULL; cl = cl->cl_nxt) { |
474 if (cl->cl_val.v_quad == nv->v_quad) | 476 if (cl->cl_val.v_quad == nv.v_quad) |
475 break; 476 } | 477 break; 478 } |
477 if (cl != NULL && isutyp(nv->v_tspec)) { | 479 if (cl != NULL && isutyp(nv.v_tspec)) { |
478 /* duplicate case in switch, %lu */ | 480 /* duplicate case in switch, %lu */ |
479 error(200, (u_long)nv->v_quad); | 481 error(200, (u_long)nv.v_quad); |
480 } else if (cl != NULL) { 481 /* duplicate case in switch, %ld */ | 482 } else if (cl != NULL) { 483 /* duplicate case in switch, %ld */ |
482 error(199, (long)nv->v_quad); | 484 error(199, (long)nv.v_quad); |
483 } else { 484 /* 485 * append the value to the list of 486 * case values 487 */ | 485 } else { 486 /* 487 * append the value to the list of 488 * case values 489 */ |
488 if ((cl = calloc(1, sizeof (clst_t))) == NULL) 489 nomem(); 490 STRUCT_ASSIGN(cl->cl_val, *nv); | 490 cl = xcalloc(1, sizeof (clst_t)); 491 STRUCT_ASSIGN(cl->cl_val, nv); |
491 cl->cl_nxt = ci->c_clst; 492 ci->c_clst = cl; 493 } 494 } 495 tfreeblk(); 496 break; 497 498 case T_DEFAULT: 499 500 /* find the stack entry for the innermost switch statement */ | 492 cl->cl_nxt = ci->c_clst; 493 ci->c_clst = cl; 494 } 495 } 496 tfreeblk(); 497 break; 498 499 case T_DEFAULT: 500 501 /* find the stack entry for the innermost switch statement */ |
501 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ; | 502 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) 503 continue; |
502 503 if (ci == NULL) { 504 /* default outside switch */ 505 error(201); 506 } else if (ci->c_default) { 507 /* duplicate default in switch */ 508 error(202); 509 } else { --- 8 unchanged lines hidden (view full) --- 518 }; 519 reached = 1; 520} 521 522/* 523 * T_IF T_LPARN expr T_RPARN 524 */ 525void | 504 505 if (ci == NULL) { 506 /* default outside switch */ 507 error(201); 508 } else if (ci->c_default) { 509 /* duplicate default in switch */ 510 error(202); 511 } else { --- 8 unchanged lines hidden (view full) --- 520 }; 521 reached = 1; 522} 523 524/* 525 * T_IF T_LPARN expr T_RPARN 526 */ 527void |
526if1(tn) 527 tnode_t *tn; | 528if1(tnode_t *tn) |
528{ | 529{ |
530 |
|
529 if (tn != NULL) 530 tn = cconv(tn); 531 if (tn != NULL) 532 tn = promote(NOOP, 0, tn); 533 expr(tn, 0, 1); 534 pushctrl(T_IF); 535} 536 537/* 538 * if_without_else 539 * if_without_else T_ELSE 540 */ 541void | 531 if (tn != NULL) 532 tn = cconv(tn); 533 if (tn != NULL) 534 tn = promote(NOOP, 0, tn); 535 expr(tn, 0, 1); 536 pushctrl(T_IF); 537} 538 539/* 540 * if_without_else 541 * if_without_else T_ELSE 542 */ 543void |
542if2() | 544if2(void) |
543{ | 545{ |
546 |
|
544 cstk->c_rchif = reached ? 1 : 0; 545 reached = 1; 546} 547 548/* 549 * if_without_else 550 * if_without_else T_ELSE stmnt 551 */ 552void | 547 cstk->c_rchif = reached ? 1 : 0; 548 reached = 1; 549} 550 551/* 552 * if_without_else 553 * if_without_else T_ELSE stmnt 554 */ 555void |
553if3(els) 554 int els; | 556if3(int els) |
555{ | 557{ |
558 |
|
556 if (els) { 557 reached |= cstk->c_rchif; 558 } else { 559 reached = 1; 560 } 561 popctrl(T_IF); 562} 563 564/* 565 * T_SWITCH T_LPARN expr T_RPARN 566 */ 567void | 559 if (els) { 560 reached |= cstk->c_rchif; 561 } else { 562 reached = 1; 563 } 564 popctrl(T_IF); 565} 566 567/* 568 * T_SWITCH T_LPARN expr T_RPARN 569 */ 570void |
568switch1(tn) 569 tnode_t *tn; | 571switch1(tnode_t *tn) |
570{ 571 tspec_t t; 572 type_t *tp; 573 574 if (tn != NULL) 575 tn = cconv(tn); 576 if (tn != NULL) 577 tn = promote(NOOP, 0, tn); --- 35 unchanged lines hidden (view full) --- 613 reached = rchflg = 0; 614 ftflg = 1; 615} 616 617/* 618 * switch_expr stmnt 619 */ 620void | 572{ 573 tspec_t t; 574 type_t *tp; 575 576 if (tn != NULL) 577 tn = cconv(tn); 578 if (tn != NULL) 579 tn = promote(NOOP, 0, tn); --- 35 unchanged lines hidden (view full) --- 615 reached = rchflg = 0; 616 ftflg = 1; 617} 618 619/* 620 * switch_expr stmnt 621 */ 622void |
621switch2() | 623switch2(void) |
622{ | 624{ |
623 int nenum, nclab; | 625 int nenum = 0, nclab = 0; |
624 sym_t *esym; 625 clst_t *cl; 626 627 if (cstk->c_swtype == NULL) 628 lerror("switch2() 1"); 629 630 /* 631 * If the switch expression was of type enumeration, count the case --- 36 unchanged lines hidden (view full) --- 668 669 popctrl(T_SWITCH); 670} 671 672/* 673 * T_WHILE T_LPARN expr T_RPARN 674 */ 675void | 626 sym_t *esym; 627 clst_t *cl; 628 629 if (cstk->c_swtype == NULL) 630 lerror("switch2() 1"); 631 632 /* 633 * If the switch expression was of type enumeration, count the case --- 36 unchanged lines hidden (view full) --- 670 671 popctrl(T_SWITCH); 672} 673 674/* 675 * T_WHILE T_LPARN expr T_RPARN 676 */ 677void |
676while1(tn) 677 tnode_t *tn; | 678while1(tnode_t *tn) |
678{ | 679{ |
680 |
|
679 if (!reached) { 680 /* loop not entered at top */ 681 warning(207); 682 reached = 1; 683 } 684 685 if (tn != NULL) 686 tn = cconv(tn); --- 18 unchanged lines hidden (view full) --- 705 expr(tn, 0, 1); 706} 707 708/* 709 * while_expr stmnt 710 * while_expr error 711 */ 712void | 681 if (!reached) { 682 /* loop not entered at top */ 683 warning(207); 684 reached = 1; 685 } 686 687 if (tn != NULL) 688 tn = cconv(tn); --- 18 unchanged lines hidden (view full) --- 707 expr(tn, 0, 1); 708} 709 710/* 711 * while_expr stmnt 712 * while_expr error 713 */ 714void |
713while2() | 715while2(void) |
714{ | 716{ |
717 |
|
715 /* 716 * The end of the loop can be reached if it is no endless loop 717 * or there was a break statement which was reached. 718 */ 719 reached = !cstk->c_infinite || cstk->c_break; 720 rchflg = 0; 721 722 popctrl(T_WHILE); 723} 724 725/* 726 * T_DO 727 */ 728void | 718 /* 719 * The end of the loop can be reached if it is no endless loop 720 * or there was a break statement which was reached. 721 */ 722 reached = !cstk->c_infinite || cstk->c_break; 723 rchflg = 0; 724 725 popctrl(T_WHILE); 726} 727 728/* 729 * T_DO 730 */ 731void |
729do1() | 732do1(void) |
730{ | 733{ |
734 |
|
731 if (!reached) { 732 /* loop not entered at top */ 733 warning(207); 734 reached = 1; 735 } 736 737 pushctrl(T_DO); 738 cstk->c_loop = 1; 739} 740 741/* 742 * do stmnt do_while_expr 743 * do error 744 */ 745void | 735 if (!reached) { 736 /* loop not entered at top */ 737 warning(207); 738 reached = 1; 739 } 740 741 pushctrl(T_DO); 742 cstk->c_loop = 1; 743} 744 745/* 746 * do stmnt do_while_expr 747 * do error 748 */ 749void |
746do2(tn) 747 tnode_t *tn; | 750do2(tnode_t *tn) |
748{ | 751{ |
752 |
|
749 /* 750 * If there was a continue statement the expression controlling the 751 * loop is reached. 752 */ 753 if (cstk->c_cont) 754 reached = 1; 755 756 if (tn != NULL) --- 25 unchanged lines hidden (view full) --- 782 783 popctrl(T_DO); 784} 785 786/* 787 * T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN 788 */ 789void | 753 /* 754 * If there was a continue statement the expression controlling the 755 * loop is reached. 756 */ 757 if (cstk->c_cont) 758 reached = 1; 759 760 if (tn != NULL) --- 25 unchanged lines hidden (view full) --- 786 787 popctrl(T_DO); 788} 789 790/* 791 * T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN 792 */ 793void |
790for1(tn1, tn2, tn3) 791 tnode_t *tn1, *tn2, *tn3; | 794for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3) |
792{ | 795{ |
796 |
|
793 /* 794 * If there is no initialisation expression it is possible that 795 * it is intended not to enter the loop at top. 796 */ 797 if (tn1 != NULL && !reached) { 798 /* loop not entered at top */ 799 warning(207); 800 reached = 1; --- 42 unchanged lines hidden (view full) --- 843 reached = 1; 844} 845 846/* 847 * for_exprs stmnt 848 * for_exprs error 849 */ 850void | 797 /* 798 * If there is no initialisation expression it is possible that 799 * it is intended not to enter the loop at top. 800 */ 801 if (tn1 != NULL && !reached) { 802 /* loop not entered at top */ 803 warning(207); 804 reached = 1; --- 42 unchanged lines hidden (view full) --- 847 reached = 1; 848} 849 850/* 851 * for_exprs stmnt 852 * for_exprs error 853 */ 854void |
851for2() | 855for2(void) |
852{ 853 pos_t cpos, cspos; 854 tnode_t *tn3; 855 856 if (cstk->c_cont) 857 reached = 1; 858 859 STRUCT_ASSIGN(cpos, curr_pos); --- 28 unchanged lines hidden (view full) --- 888 popctrl(T_FOR); 889} 890 891/* 892 * T_GOTO identifier T_SEMI 893 * T_GOTO error T_SEMI 894 */ 895void | 856{ 857 pos_t cpos, cspos; 858 tnode_t *tn3; 859 860 if (cstk->c_cont) 861 reached = 1; 862 863 STRUCT_ASSIGN(cpos, curr_pos); --- 28 unchanged lines hidden (view full) --- 892 popctrl(T_FOR); 893} 894 895/* 896 * T_GOTO identifier T_SEMI 897 * T_GOTO error T_SEMI 898 */ 899void |
896dogoto(lab) 897 sym_t *lab; | 900dogoto(sym_t *lab) |
898{ | 901{ |
902 |
|
899 setuflg(lab, 0, 0); 900 901 chkreach(); 902 903 reached = rchflg = 0; 904} 905 906/* 907 * T_BREAK T_SEMI 908 */ 909void | 903 setuflg(lab, 0, 0); 904 905 chkreach(); 906 907 reached = rchflg = 0; 908} 909 910/* 911 * T_BREAK T_SEMI 912 */ 913void |
910dobreak() | 914dobreak(void) |
911{ 912 cstk_t *ci; 913 914 ci = cstk; 915 while (ci != NULL && !ci->c_loop && !ci->c_switch) 916 ci = ci->c_nxt; 917 918 if (ci == NULL) { --- 9 unchanged lines hidden (view full) --- 928 929 reached = rchflg = 0; 930} 931 932/* 933 * T_CONTINUE T_SEMI 934 */ 935void | 915{ 916 cstk_t *ci; 917 918 ci = cstk; 919 while (ci != NULL && !ci->c_loop && !ci->c_switch) 920 ci = ci->c_nxt; 921 922 if (ci == NULL) { --- 9 unchanged lines hidden (view full) --- 932 933 reached = rchflg = 0; 934} 935 936/* 937 * T_CONTINUE T_SEMI 938 */ 939void |
936docont() | 940docont(void) |
937{ 938 cstk_t *ci; 939 | 941{ 942 cstk_t *ci; 943 |
940 for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt) ; | 944 for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt) 945 continue; |
941 942 if (ci == NULL) { 943 /* continue outside loop */ 944 error(209); 945 } else { 946 ci->c_cont = 1; 947 } 948 949 chkreach(); 950 951 reached = rchflg = 0; 952} 953 954/* 955 * T_RETURN T_SEMI 956 * T_RETURN expr T_SEMI 957 */ 958void | 946 947 if (ci == NULL) { 948 /* continue outside loop */ 949 error(209); 950 } else { 951 ci->c_cont = 1; 952 } 953 954 chkreach(); 955 956 reached = rchflg = 0; 957} 958 959/* 960 * T_RETURN T_SEMI 961 * T_RETURN expr T_SEMI 962 */ 963void |
959doreturn(tn) 960 tnode_t *tn; | 964doreturn(tnode_t *tn) |
961{ 962 tnode_t *ln, *rn; 963 cstk_t *ci; 964 op_t op; 965 | 965{ 966 tnode_t *ln, *rn; 967 cstk_t *ci; 968 op_t op; 969 |
966 for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt) ; | 970 for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt) 971 continue; |
967 968 if (tn != NULL) { 969 ci->c_retval = 1; 970 } else { 971 ci->c_noretval = 1; 972 } 973 974 if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) { --- 45 unchanged lines hidden (view full) --- 1020 reached = rchflg = 0; 1021} 1022 1023/* 1024 * Do some cleanup after a global declaration or definition. 1025 * Especially remove informations about unused lint comments. 1026 */ 1027void | 972 973 if (tn != NULL) { 974 ci->c_retval = 1; 975 } else { 976 ci->c_noretval = 1; 977 } 978 979 if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) { --- 45 unchanged lines hidden (view full) --- 1025 reached = rchflg = 0; 1026} 1027 1028/* 1029 * Do some cleanup after a global declaration or definition. 1030 * Especially remove informations about unused lint comments. 1031 */ 1032void |
1028glclup(silent) 1029 int silent; | 1033glclup(int silent) |
1030{ 1031 pos_t cpos; 1032 1033 STRUCT_ASSIGN(cpos, curr_pos); 1034 1035 if (nargusg != -1) { 1036 if (!silent) { 1037 STRUCT_ASSIGN(curr_pos, aupos); --- 34 unchanged lines hidden (view full) --- 1072 1073/* 1074 * ARGSUSED comment 1075 * 1076 * Only the first n arguments of the following function are checked 1077 * for usage. A missing argument is taken to be 0. 1078 */ 1079void | 1034{ 1035 pos_t cpos; 1036 1037 STRUCT_ASSIGN(cpos, curr_pos); 1038 1039 if (nargusg != -1) { 1040 if (!silent) { 1041 STRUCT_ASSIGN(curr_pos, aupos); --- 34 unchanged lines hidden (view full) --- 1076 1077/* 1078 * ARGSUSED comment 1079 * 1080 * Only the first n arguments of the following function are checked 1081 * for usage. A missing argument is taken to be 0. 1082 */ 1083void |
1080argsused(n) 1081 int n; | 1084argsused(int n) |
1082{ | 1085{ |
1086 |
|
1083 if (n == -1) 1084 n = 0; 1085 1086 if (dcs->d_ctx != EXTERN) { 1087 /* must be outside function: ** %s ** */ 1088 warning(280, "ARGSUSED"); 1089 return; 1090 } --- 7 unchanged lines hidden (view full) --- 1098 1099/* 1100 * VARARGS comment 1101 * 1102 * Makes that lint2 checks only the first n arguments for compatibility 1103 * to the function definition. A missing argument is taken to be 0. 1104 */ 1105void | 1087 if (n == -1) 1088 n = 0; 1089 1090 if (dcs->d_ctx != EXTERN) { 1091 /* must be outside function: ** %s ** */ 1092 warning(280, "ARGSUSED"); 1093 return; 1094 } --- 7 unchanged lines hidden (view full) --- 1102 1103/* 1104 * VARARGS comment 1105 * 1106 * Makes that lint2 checks only the first n arguments for compatibility 1107 * to the function definition. A missing argument is taken to be 0. 1108 */ 1109void |
1106varargs(n) 1107 int n; | 1110varargs(int n) |
1108{ | 1111{ |
1112 |
|
1109 if (n == -1) 1110 n = 0; 1111 1112 if (dcs->d_ctx != EXTERN) { 1113 /* must be outside function: ** %s ** */ 1114 warning(280, "VARARGS"); 1115 return; 1116 } --- 7 unchanged lines hidden (view full) --- 1124 1125/* 1126 * PRINTFLIKE comment 1127 * 1128 * Check all arguments until the (n-1)-th as usual. The n-th argument is 1129 * used the check the types of remaining arguments. 1130 */ 1131void | 1113 if (n == -1) 1114 n = 0; 1115 1116 if (dcs->d_ctx != EXTERN) { 1117 /* must be outside function: ** %s ** */ 1118 warning(280, "VARARGS"); 1119 return; 1120 } --- 7 unchanged lines hidden (view full) --- 1128 1129/* 1130 * PRINTFLIKE comment 1131 * 1132 * Check all arguments until the (n-1)-th as usual. The n-th argument is 1133 * used the check the types of remaining arguments. 1134 */ 1135void |
1132printflike(n) 1133 int n; | 1136printflike(int n) |
1134{ | 1137{ |
1138 |
|
1135 if (n == -1) 1136 n = 0; 1137 1138 if (dcs->d_ctx != EXTERN) { 1139 /* must be outside function: ** %s ** */ 1140 warning(280, "PRINTFLIKE"); 1141 return; 1142 } --- 7 unchanged lines hidden (view full) --- 1150 1151/* 1152 * SCANFLIKE comment 1153 * 1154 * Check all arguments until the (n-1)-th as usual. The n-th argument is 1155 * used the check the types of remaining arguments. 1156 */ 1157void | 1139 if (n == -1) 1140 n = 0; 1141 1142 if (dcs->d_ctx != EXTERN) { 1143 /* must be outside function: ** %s ** */ 1144 warning(280, "PRINTFLIKE"); 1145 return; 1146 } --- 7 unchanged lines hidden (view full) --- 1154 1155/* 1156 * SCANFLIKE comment 1157 * 1158 * Check all arguments until the (n-1)-th as usual. The n-th argument is 1159 * used the check the types of remaining arguments. 1160 */ 1161void |
1158scanflike(n) 1159 int n; | 1162scanflike(int n) |
1160{ | 1163{ |
1164 |
|
1161 if (n == -1) 1162 n = 0; 1163 1164 if (dcs->d_ctx != EXTERN) { 1165 /* must be outside function: ** %s ** */ 1166 warning(280, "SCANFLIKE"); 1167 return; 1168 } --- 6 unchanged lines hidden (view full) --- 1175} 1176 1177/* 1178 * Set the linenumber for a CONSTCOND comment. At this and the following 1179 * line no warnings about constants in conditional contexts are printed. 1180 */ 1181/* ARGSUSED */ 1182void | 1165 if (n == -1) 1166 n = 0; 1167 1168 if (dcs->d_ctx != EXTERN) { 1169 /* must be outside function: ** %s ** */ 1170 warning(280, "SCANFLIKE"); 1171 return; 1172 } --- 6 unchanged lines hidden (view full) --- 1179} 1180 1181/* 1182 * Set the linenumber for a CONSTCOND comment. At this and the following 1183 * line no warnings about constants in conditional contexts are printed. 1184 */ 1185/* ARGSUSED */ 1186void |
1183constcond(n) 1184 int n; | 1187constcond(int n) |
1185{ | 1188{ |
1189 |
|
1186 ccflg = 1; 1187} 1188 1189/* 1190 * Suppress printing of "fallthrough on ..." warnings until next 1191 * statement. 1192 */ 1193/* ARGSUSED */ 1194void | 1190 ccflg = 1; 1191} 1192 1193/* 1194 * Suppress printing of "fallthrough on ..." warnings until next 1195 * statement. 1196 */ 1197/* ARGSUSED */ 1198void |
1195fallthru(n) 1196 int n; | 1199fallthru(int n) |
1197{ | 1200{ |
1201 |
|
1198 ftflg = 1; 1199} 1200 1201/* 1202 * Stop warnings about statements which cannot be reached. Also tells lint 1203 * that the following statements cannot be reached (e.g. after exit()). 1204 */ 1205/* ARGSUSED */ 1206void | 1202 ftflg = 1; 1203} 1204 1205/* 1206 * Stop warnings about statements which cannot be reached. Also tells lint 1207 * that the following statements cannot be reached (e.g. after exit()). 1208 */ 1209/* ARGSUSED */ 1210void |
1207notreach(n) 1208 int n; | 1211notreach(int n) |
1209{ | 1212{ |
1213 |
|
1210 reached = 0; 1211 rchflg = 1; 1212} 1213 1214/* ARGSUSED */ 1215void | 1214 reached = 0; 1215 rchflg = 1; 1216} 1217 1218/* ARGSUSED */ 1219void |
1216lintlib(n) 1217 int n; | 1220lintlib(int n) |
1218{ | 1221{ |
1222 |
|
1219 if (dcs->d_ctx != EXTERN) { 1220 /* must be outside function: ** %s ** */ 1221 warning(280, "LINTLIBRARY"); 1222 return; 1223 } 1224 llibflg = 1; 1225 vflag = 0; 1226} 1227 1228/* 1229 * Suppress most warnings at the current and the following line. 1230 */ 1231/* ARGSUSED */ 1232void | 1223 if (dcs->d_ctx != EXTERN) { 1224 /* must be outside function: ** %s ** */ 1225 warning(280, "LINTLIBRARY"); 1226 return; 1227 } 1228 llibflg = 1; 1229 vflag = 0; 1230} 1231 1232/* 1233 * Suppress most warnings at the current and the following line. 1234 */ 1235/* ARGSUSED */ 1236void |
1233linted(n) 1234 int n; | 1237linted(int n) |
1235{ | 1238{ |
1239 1240#ifdef DEBUG 1241 printf("%s, %d: nowarn = 1\n", curr_pos.p_file, curr_pos.p_line); 1242#endif |
|
1236 nowarn = 1; 1237} 1238 1239/* | 1243 nowarn = 1; 1244} 1245 1246/* |
1247 * Suppress bitfield type errors on the current line. 1248 */ 1249/* ARGSUSED */ 1250void 1251bitfieldtype(int n) 1252{ 1253 1254#ifdef DEBUG 1255 printf("%s, %d: bitfieldtype_ok = 1\n", curr_pos.p_file, 1256 curr_pos.p_line); 1257#endif 1258 bitfieldtype_ok = 1; 1259} 1260 1261/* |
|
1240 * PROTOTLIB in conjunction with LINTLIBRARY can be used to handle 1241 * prototypes like function definitions. This is done if the argument 1242 * to PROTOLIB is nonzero. Otherwise prototypes are handled normaly. 1243 */ 1244void | 1262 * PROTOTLIB in conjunction with LINTLIBRARY can be used to handle 1263 * prototypes like function definitions. This is done if the argument 1264 * to PROTOLIB is nonzero. Otherwise prototypes are handled normaly. 1265 */ 1266void |
1245protolib(n) 1246 int n; | 1267protolib(int n) |
1247{ | 1268{ |
1269 |
|
1248 if (dcs->d_ctx != EXTERN) { 1249 /* must be outside function: ** %s ** */ 1250 warning(280, "PROTOLIB"); 1251 return; 1252 } 1253 plibflg = n == 0 ? 0 : 1; 1254} 1255 1256/* 1257 * Set quadflg to nonzero which means that the next statement/declaration 1258 * may use "long long" without an error or warning. 1259 */ 1260/* ARGSUSED */ 1261void | 1270 if (dcs->d_ctx != EXTERN) { 1271 /* must be outside function: ** %s ** */ 1272 warning(280, "PROTOLIB"); 1273 return; 1274 } 1275 plibflg = n == 0 ? 0 : 1; 1276} 1277 1278/* 1279 * Set quadflg to nonzero which means that the next statement/declaration 1280 * may use "long long" without an error or warning. 1281 */ 1282/* ARGSUSED */ 1283void |
1262longlong(n) 1263 int n; | 1284longlong(int n) |
1264{ | 1285{ |
1286 |
|
1265 quadflg = 1; 1266} | 1287 quadflg = 1; 1288} |