ERROR.C
上传用户:hlzzc88
上传日期:2007-01-06
资源大小:220k
文件大小:30k
源码类别:

编译器/解释器

开发平台:

Others

  1. /*
  2.  * 68K/386 32-bit C compiler.
  3.  *
  4.  * copyright (c) 1997, David Lindauer
  5.  * 
  6.  * This compiler is intended for educational use.  It may not be used
  7.  * for profit without the express written consent of the author.
  8.  *
  9.  * It may be freely redistributed, as long as this notice remains intact
  10.  * and either the original sources or derived sources 
  11.  * are distributed along with any executables derived from the originals.
  12.  *
  13.  * The author is not responsible for any damages that may arise from use
  14.  * of this software, either idirect or consequential.
  15.  *
  16.  * v1.35 March 1997
  17.  * David Lindauer, gclind01@starbase.spd.louisville.edu
  18.  *
  19.  * Credits to Mathew Brandt for original K&R C compiler
  20.  *
  21.  */
  22. /* 
  23.  * error handler
  24.  */
  25. #include        <stdio.h>
  26. #include  <string.h>
  27. #include        "expr.h"
  28. #include        "c.h"
  29. #include        "errors.h"
  30. #include  "diag.h"
  31. extern int prm_errfile;
  32. extern FILE *errFile;
  33. extern int global_flag;
  34. extern FILE *listFile;
  35. extern int errlineno;
  36. extern char *errfile;
  37. extern int prm_asmfile;
  38. extern FILE *outputFile;
  39. extern int prm_maxerr;
  40. extern int prm_diag;
  41. extern int prm_listfile;
  42. extern int lastch;
  43. extern enum e_sym lastst;
  44. extern char lastid[];
  45. extern int lineno;
  46. extern FILE            *inclfile[10];  /* shared with preproc */
  47. extern int             incldepth;      /* shared with preproc */
  48. extern char *infile;
  49. extern SYM *currentfunc;
  50. extern int prm_warning,prm_cplusplus;
  51. int diagcount = 0;
  52. ERRORS *errlist = 0;
  53. static ERRORS *errtail = 0;
  54. static ERRORS *curerr = 0; 
  55. static char expectlist[] = { "########################=##############,:;#[]{}()" };
  56. static int errline;
  57. /* table of which warnings are enabled */
  58. char nowarn[ERR_MAX];
  59. /* table of warning keywords for the -w command line option
  60.  */
  61. char warnarray[ERR_MAX][4] = { 
  62. "all","","","","","","","",
  63. "","","","","","","","",
  64. "","","","","","","","",
  65. "","","","","","","","",
  66. "","","","","cln","","","",
  67. "","","","","","","","",
  68. "","","","","","ret","sun","sud",
  69. "sas","npo","urc","fun","cno","ieq","","nco",
  70. "lad","","","zer","dpc","nsf","lun","pro",
  71. "cnv","","irg","san","ssu","","","",
  72. "","","tua","","tui","","","",
  73. "","","","","","","","",
  74. "","","","","","suz","fsu","lli",
  75.   "","","","","","spc","","",
  76. "","","","","","","","",
  77.   "","","","","",""
  78. };
  79. int             total_errors = 0;
  80. void initerr(void)
  81. {
  82.                                 errlist = errtail = curerr = 0;
  83.         total_errors = 0;
  84.                                 diagcount  = 0;                 
  85. errline = 0;
  86. }
  87. /*
  88.  * handling for warnings on the command line
  89.  */
  90. void warning_setup(char select, char *string)
  91. {
  92. int bool = FALSE;
  93. while (*string) {
  94. int i;
  95. if (string[0] == '-') {
  96. bool = TRUE;
  97. string++;
  98. }
  99. else
  100. if (string[0] == '+')
  101. string++;
  102. for (i=0; i < ERR_MAX; i++)
  103. if (!strncmp(warnarray[i],string,3)) {
  104. if (i== 0) {
  105. int j;
  106. for (j =0; j < ERR_MAX; j++)
  107. nowarn[j] = (unsigned char)bool;
  108. }
  109. else
  110. nowarn[i] = (unsigned char)bool;
  111. string += 3;
  112. break;
  113. }
  114. if (i==ERR_MAX) {
  115. fatal("Invalid warning");
  116. }
  117. }
  118. }
  119. #ifdef DIAGNOSTICS
  120. void diag(char *s)
  121. /*
  122.  * internal diags come here
  123.  */
  124.         diagcount++;
  125.   if (prm_diag) {
  126.                 printf("DIAG - %sn",s);
  127.                 if (prm_errfile && errFile)
  128.                         fprintf(errFile,"/*DIAG - %s*/",s);
  129.                 if (prm_listfile && listFile)
  130.                         fprintf(listFile,"/*DIAG - %s*/",s);
  131.                 if (prm_asmfile)
  132.                         fprintf(outputFile,"DIAG - %sn",s);
  133.         }
  134. }
  135. #endif
  136. int printerr(char *buf, ERRORS *err)
  137. /*
  138.  * subroutine gets the error code and returns whether it is an error or
  139.  * warning
  140.  */
  141. {
  142.         int errlvl = 0;
  143.         switch (err->errornumber) {
  144. case ERR_NOCASE:
  145.                         sprintf(buf,"Expected 'case' or 'default'");
  146.                         break;
  147.                 case ERR_PUNCT:
  148.                         sprintf(buf,"Expected '%c'",expectlist[(int)err->data]);
  149.                         break;
  150.                 case ERR_INSERT:
  151.                         sprintf(buf,"Inserted '%c'",expectlist[(int)err->data]);
  152.                         break;
  153.                 case ERR_NEEDCHAR:
  154.                         sprintf(buf,"Expected '%c'",(char)err->data);
  155.                         break;
  156.                 case ERR_ILLCHAR:
  157.                         sprintf(buf,"Illegal character '%c'",(char)err->data);
  158.                         break;
  159.                 case ERR_NEEDCONST:
  160.                         sprintf(buf,"Constant value expected");
  161.                         break;
  162.                 case ERR_UNDEFINED:
  163.                         sprintf(buf,"Undefined symbol '%s'", (char *)err->data);
  164.                         break;
  165.                 case ERR_DUPSYM:
  166.                         sprintf(buf,"Duplicate symbol '%s'", (char *)err->data);
  167.                         break;
  168.                 case ERR_IDENTEXPECT:
  169.                         sprintf(buf,"Expected '%s'",(char *)err->data);
  170.                         break;
  171.                 case ERR_IDEXPECT:
  172.                         sprintf(buf,"Identifier expected");
  173.                         break;
  174.                 case ERR_INITSIZE:
  175.                         sprintf(buf,"Too many initializers");
  176.                         break;
  177.                 case ERR_NOINIT:
  178.                         sprintf(buf,"Cannot initialize '%s'",(char *)err->data);
  179.                         break;
  180.                 case ERR_PREPROCID:
  181.                         sprintf(buf,"Invalid preprocessor directive '%s'",(char *)err->data);
  182.                         break;
  183.                 case ERR_INCLFILE:
  184.                         sprintf(buf,"File name expected in #include directive");
  185.                         break;
  186.                 case ERR_CANTOPEN:
  187.                         sprintf(buf,"Cannot open file "%s" for read access",(char *)err->data);
  188.                         break;
  189.                 case ERR_ILLCLASS:
  190.                         sprintf(buf,"Illegal storage class specifier '%s'",(char *)err->data);
  191.                         break;
  192.                 case ERR_ILLCLASS2:
  193.                         sprintf(buf,"Illegal storage class specifier on '%s'",(char *)err->data);
  194.                         break;
  195.                 case ERR_DUPCASE:
  196.                         sprintf(buf,"Duplicate case %d",(int)err->data);
  197.                         break;
  198.                 case ERR_RETMISMATCH:
  199.                         sprintf(buf,"Type mismatch in return");
  200.                         break;
  201.                 case ERR_ARGMISMATCH:
  202.                         sprintf(buf,"Type mismatch in arg '%s'",(char *)err->data);
  203.                         break;
  204.                 case ERR_ARGLENSHORT:
  205.                         sprintf(buf,"Argument list too short in redeclaration of function '%s'",(char *)err->data);
  206.                         break;
  207.                 case ERR_ARGLENLONG:
  208.                         sprintf(buf,"Argument list too long in redeclaration of function '%s'",(char*)err->data);
  209.                         break;
  210.                 case ERR_DECLMISMATCH:
  211.                         sprintf(buf,"Type mismatch in redeclaration of '%s'",(char *)err->data);
  212.                         break;
  213.                 case ERR_CALLMISMATCH:
  214.                         sprintf(buf,"Type mismatch in arg %s",(char *)err->data);
  215.                         break;
  216.                 case ERR_CALLLENSHORT:
  217.                         sprintf(buf,"Argument list too short %s",(char *)err->data);
  218.                         break;
  219.                 case ERR_CALLLENLONG:
  220.                         sprintf(buf,"Argument list too long %s",(char *)err->data);
  221.                         errlvl = 1;
  222.                         break;
  223.                 case ERR_LABEL:
  224.                         sprintf(buf,"'%s' is not a label",(char *)err->data);
  225.                         break;
  226.                 case ERR_NOPOINTER:
  227.                         sprintf(buf,"Pointer type expected");
  228.                         break;
  229.                 case ERR_LVALUE:
  230.                         sprintf(buf,"Lvalue expected");
  231.                         break;
  232.                 case ERR_NOFUNC:
  233.                         sprintf(buf,"'%s' is not a function",(char *)err->data);
  234.                         break;
  235.                 case ERR_MISMATCH:
  236.                         sprintf(buf,"Type mismatch");
  237.                         break;
  238.                 case ERR_ELSE:
  239.                         sprintf(buf,"Misplaced else");
  240.                         break;
  241.                 case ERR_EXPREXPECT:
  242.                         sprintf(buf,"Expression expected");
  243.                         break;
  244.                 case ERR_DEREF:
  245.                         sprintf(buf,"Illegal pointer");
  246.                         break;
  247.                 case ERR_UNEXPECT:
  248.                         if (lastst == id)
  249.                                 sprintf(buf,"Unexpected '%s'",lastid);
  250.                         else
  251.                                 sprintf(buf,"Unexpected '%c'",lastch);
  252.                         break;
  253.                 case ERR_ILLTYPE:
  254.                         sprintf(buf,"Illegal typedef of '%s'",(char *)err->data);
  255.                         break;
  256.                 case ERR_ARRAYMISMATCH:
  257.                         sprintf(buf,"Non-scalar array index");
  258.                         break;
  259.                 case ERR_PREPROCMATCH:
  260.                         sprintf(buf,"Unbalanced preprocessor directives");
  261.                         break;
  262.                 case ERR_MACROSUBS:
  263.                         sprintf(buf,"Macro substitution error");
  264.                         break;
  265.                 case ERR_DECLEXPECT:
  266.                         sprintf(buf,"Declaration expected");
  267.                         break;
  268.                 case ERR_INVFLOAT:
  269.                         sprintf(buf,"Invalid floating point");
  270.                         break;
  271.                 case ERR_INVTRAP:
  272.                         sprintf(buf,"Invalid trap id");
  273.                         break;
  274.                 case ERR_BFILLEGAL:
  275.                         sprintf(buf,"Cannot use bit field as a non-member");
  276.                         break;
  277.                 case ERR_BFTOOBIG:
  278.                         sprintf(buf,"Bit field too big");
  279.                         break;
  280.                 case ERR_BFTYPE:
  281.                         sprintf(buf,"Bit field only allowed on scalar types");
  282.                         break;
  283.                 case ERR_ERROR:
  284.                         sprintf(buf,"User error: %s",(char *)err->data);
  285.                         break;
  286.                 case ERR_INTERP:
  287.                         sprintf(buf,"%s",(char *)err->data);
  288.                         break;
  289.                 case ERR_BFADDR:
  290.                         sprintf(buf,"Cannot take address of bit field");
  291.                         break;
  292.                 case ERR_MODCONS:
  293.                         sprintf(buf,"Cannot modify a const val");
  294.                         break;
  295.                 case ERR_SZTYPE:
  296.                         sprintf(buf,"Type expected in sizeof");
  297.                         break;
  298.                 case ERR_FUNCRETVAL:
  299.                         sprintf(buf,"Function should return a value");
  300.                         errlvl = 1;
  301.                         break;
  302.                 case ERR_STATICSYMUNUSED:
  303.                         sprintf(buf,"Static variable '%s' is declared but never used",(char *)err->data);
  304.                         errlvl = 1;
  305.                         break;
  306.                 case ERR_SYMUNUSED:
  307.                         sprintf(buf,"Variable '%s' is declared but never used",(char *)err->data);
  308.                         errlvl = 1;
  309.                         break;
  310.                 case ERR_FUNCUNUSED:
  311.                         sprintf(buf,"Static function '%s' is declared but never used",(char *)err->data);
  312.                         errlvl = 1;
  313.                         break;
  314.                 case ERR_SYMUNDEF:
  315.                         sprintf(buf,"Possible use of '%s' before assignment",(char *)err->data);
  316.                         errlvl = 1;
  317.                         break;
  318.                 case ERR_SYMASSIGNED:
  319.                         sprintf(buf,"Variable '%s' is possibly assigned a value which is never used",(char *)err->data);
  320.                         errlvl = 1;
  321.                         break;
  322.                 case ERR_NONPORT:
  323.                         sprintf(buf,"Nonportable pointer conversion");
  324.                         errlvl = 1;
  325.                         break;
  326.                 case ERR_UNREACHABLE:
  327.                         sprintf(buf,"Unreachable code");
  328.                         errlvl = 1;
  329.                         break;
  330. case ERR_CODENONE:
  331. sprintf(buf,"Code has no effect");
  332. errlvl = 1;
  333. break;
  334. case ERR_BADEQUATE:
  335. sprintf(buf,"Possible incorrect assignment");
  336. errlvl = 1;
  337. break;
  338. case ERR_NOANDREG:
  339. sprintf(buf,"Invalid '&' on register var '%s'",(char *)err->data);
  340. break;
  341. case ERR_NOCONTINUE:
  342. sprintf(buf,"Continue not allowed");
  343. break;
  344. case ERR_DUPLABEL:
  345. sprintf(buf,"Duplicate label '%s'",(char *)err->data);
  346. break;
  347. case ERR_NOFUNCARRAY:
  348. sprintf(buf,"Function cannot return array");
  349. break;
  350. case ERR_NOVOIDRET:
  351. sprintf(buf,"Return type is void");
  352. errlvl = 1;
  353. break;
  354. case ERR_ZEROSTORAGE:
  355. sprintf(buf,"No memory allocated for '%s'",(char *)err->data);
  356. errlvl = 1;
  357. break;
  358. case ERR_ZEROPTR:
  359. sprintf(buf,"Illegal use of void pointer");
  360. break;
  361. case ERR_SHORTPOINTER:
  362. sprintf(buf,"Dangerous pointer cast");
  363. errlvl = 1;
  364. break;
  365. case ERR_NOSTATICFUNC:
  366. sprintf(buf,"Nonexistant static func '%s'",(char *)err->data);
  367. break;
  368. case ERR_UNUSEDLABEL:
  369. errlvl = 1;
  370. sprintf(buf,"Unused label '%s'",(char *)err->data);
  371. break;
  372. case ERR_NOPROTO:
  373. sprintf(buf,"Call to function '%s' with no prototype",(char *)err->data);
  374. errlvl = prm_cplusplus==0;
  375. break;
  376. case ERR_LOSTCONV:
  377. sprintf(buf,"Conversion may truncate significant digits");
  378. errlvl = 1;
  379. break;
  380. case ERR_UNDEFLABEL:
  381. sprintf(buf,"Undefined label '%s'",(char *)err->data);
  382. break;
  383. case ERR_ILLREGISTER:
  384. sprintf(buf,"Illegal register var '%s'",(char *)err->data);
  385. errlvl = 1;
  386. break;
  387. case ERR_SUPERAND:
  388. sprintf(buf,"Possible superfluous &");
  389. errlvl = 1;
  390. break;
  391. case ERR_NODECLARE:
  392. sprintf(buf,"Declaration not allowed here");
  393. break;
  394. case ERR_NOMAIN:
  395. sprintf(buf,"Illegal call to main() from within program");
  396. break;
  397. case ERR_NOREF:
  398. sprintf(buf,"Illegal use of reference operator");
  399. break;
  400. case ERR_CANTREF:
  401. sprintf(buf,"Cannot define a pointer or reference to a reference");
  402. break;
  403. case ERR_TEMPUSED:
  404. sprintf(buf,"Temporary used for parameter %s",(char *)err->data);
  405. errlvl = 1;
  406. break;
  407. case ERR_REFMUSTINIT:
  408. sprintf(buf,"Reference variable '%s' must be initialized",(char *)err->data);
  409. break;
  410. case ERR_TEMPINIT:
  411. sprintf(buf,"Temporary used to initialize %s",(char *)err->data);
  412. errlvl = 1;
  413. break;
  414. case ERR_REFLVALUE:
  415. sprintf(buf,"Reference initialization needs lvalue");
  416. break;
  417. case ERR_REFNOCONS:
  418. sprintf(buf,"Reference member '%s' in a class with no constructors",(char *)err->data);
  419. break;
  420. case ERR_MISSINGDEFAULT:
  421. sprintf(buf,"Default missing after parameter '%s'",(char *)err->data);
  422. break;
  423. case ERR_AMBIGFUNC:
  424. sprintf(buf,"Ambiguity between %s",(char *)err->data);
  425. break;
  426. case ERR_NOLOCALDEFAULT:
  427. sprintf(buf,"Local variables may not be used as parameter defaults");
  428. break;
  429. case ERR_CPPMISMATCH:
  430. sprintf(buf,"Cannot cast %s",(char *)err->data);
  431. break;
  432. case ERR_NOOVERMAIN:
  433. sprintf(buf,"Cannot overload 'main'",(char *)err->data);
  434. break;
  435. case ERR_SWITCHINT:
  436. sprintf(buf,"Switch argument must be of integral type");
  437. break;
  438. case ERR_NOFUNCMATCH:
  439. sprintf(buf,"Could not find a match for '%s'",(char *)err->data);
  440. break;
  441. /*
  442. case ERR_PREDEFSTRUCT:
  443. sprintf(buf,"'%s' must be a predefined class or struct",(char *)err->data);
  444. break;
  445. case ERR_LOCALCLASS:
  446. sprintf(buf,"Local class functions not supported",(char *)err->data);
  447. break;
  448. case ERR_PUREDECL:
  449. sprintf(buf,"Illegal pure declaration syntzx of '%s'",(char *)err->data);
  450. break;
  451. case ERR_BADESTRUCT:
  452. sprintf(buf,"Destructor for class '%s' expected",(char *)err->data);
  453. break;
  454. case ERR_TYPECONSTRUCT:
  455. sprintf(buf,"Constructor/destructor must be untyped");
  456. break;
  457. case ERR_NOTYPEQUAL:
  458. sprintf(buf,"Variable '%s' cannot have a type qualifier",(char *)err->data);
  459. break;
  460. case ERR_NOTACLASS:
  461. sprintf(buf,"Variable '%s' is not a class instance",(char *)err->data);
  462. break;
  463. */                case ERR_SIZE:
  464. if (err->data)
  465.   sprintf(buf,"Size of '%s' is unknown or zero",(char *)err->data);
  466. else
  467.   sprintf(buf,"Size is unknown or zero");
  468. break;
  469. case ERR_NEVERSTRUCT:
  470. sprintf(buf,"Structure '%s' is undefined",(char *)err->data);
  471. errlvl = 1;
  472. break;
  473. case ERR_LONGLONG:
  474. sprintf(buf,"long long int type not supported, defaulting to long int");
  475. errlvl = 1;
  476. break;
  477. case ERR_UPDOWN:
  478. sprintf(buf,"Startup/rundown function '%s' is unknown or not a function",(char *)err->data);
  479. break;
  480. case ERR_INTBITFIELDS:
  481.                          sprintf(buf,"Bit fields must be signed or unsigned int");
  482. break;
  483. case ERR_COMMENTMATCH:
  484. sprintf(buf,"File ended with comment in progress");
  485. break;
  486. case ERR_PASCAL_NO_ELLIPSE:
  487. sprintf(buf,"Ellipse (...) not allowed in pascal declaration");
  488. break;
  489. case ERR_PASCAL_NO_INT:
  490. sprintf(buf,"_int keyword not allowed in pascal declaration");
  491. break;
  492.     case ERR_SUSPICIOUS:
  493. sprintf(buf,"Suspicious pointer conversion");
  494.   errlvl = 1;
  495. break;
  496.     case ERR_NOFUNCSTRUCT:
  497. sprintf(buf,"Function declaration not allowed here");
  498. break;
  499.     case ERR_STRINGTOOBIG:
  500. sprintf(buf,"String constant too long");
  501. break;
  502.     case ERR_CONSTTOOLARGE:
  503. sprintf(buf,"Numeric constant is too large");
  504. break;
  505. case ERR_MULTIPLEINIT:
  506.   sprintf(buf,"Multiple initialization for '%s'",(char *)err->data);
  507. break;
  508. case ERR_INVALIDSTRING:
  509.   sprintf(buf,"Invalid string operation");
  510. break;
  511. case ERR_AMODEEXPECT:
  512.   sprintf(buf,"Assembler: Address mode expected");
  513. break;
  514. case ERR_ASCALE:
  515.   sprintf(buf,"Assembler: Valid scale factor expected");
  516. break;
  517. case ERR_AINVINDXMODE:
  518.   sprintf(buf,"Assembler: Invalid indexing");
  519. break;
  520. case ERR_AILLADDRESS:
  521.   sprintf(buf,"Assembler: Invalid address mode");
  522. break;
  523. case ERR_ATOOMANYSPECS:
  524.   sprintf(buf,"Assembler: Too many specifiers");
  525. break;
  526. case ERR_ATOOMANYSEGS:
  527.   sprintf(buf,"Assembler: Too many segments");
  528. break;
  529. case ERR_AINVOP:
  530.   sprintf(buf,"Assembler: Invalid opcode");
  531. break;
  532. case ERR_AINVSIZE:
  533.   sprintf(buf,"Assembler: Size mismatch");
  534. break;
  535. case ERR_AUSELEA:
  536.   sprintf(buf,"Assembler: Must use LEA to take the address of a local variable");
  537. break;
  538. case ERR_ALABEXPECT:
  539.   sprintf(buf,"Assembler: Label expected");
  540. break;
  541. case ERR_ANEEDFP:
  542.   sprintf(buf,"Assembler: Floating point register expected");
  543. break;
  544.   default:
  545.                         sprintf(buf,"Error #%d",err->errornumber);
  546.                         break;
  547.         }
  548.         return errlvl;
  549. }
  550. void     lferror(void)
  551. /*
  552.  * sticck an error in the list file
  553.  */
  554. {  
  555.         char buf[100];
  556.         while(curerr) {
  557.                                                 int errlvl = printerr(buf,curerr);
  558.                                                 if (!errlvl) {
  559. if (prm_listfile)
  560.                                                         fprintf(listFile,"**** ERROR: %sn",buf);
  561. }
  562.                                                 else if (prm_warning) {
  563. if (prm_listfile)
  564.                                                         fprintf(listFile,"** WARNING: %sn",buf);
  565. }
  566.                                                 curerr = curerr->link;
  567.                                 }
  568.                                                 
  569. }
  570. void basicskim(int *skimlist)
  571. /*
  572.  * simple skim for a token with no nesting
  573.  */
  574. {
  575.                 int i;
  576.                 for (i=0;;i++) {
  577.                         if (lastst == skimlist[i] || lastst == eof)
  578.                                 break;
  579.                         if (skimlist[i] == 0) {
  580.                                 getsym();
  581.                                 i = 0;
  582.                         }
  583.                 }
  584. }
  585. /*
  586.  * the following routines do token skimming and keep track of parenthesis
  587.  * and brace nesting levels as well
  588.  */
  589. BALANCE *newbalance(BALANCE *bal)
  590. {
  591.         BALANCE *rv = xalloc(sizeof(BALANCE));
  592.         rv->back = bal;
  593.         rv->count = 0;
  594.         if (lastst == openpa)
  595.                 rv->type = BAL_PAREN;
  596.         else
  597.                 rv->type = BAL_BRACKET;
  598.         return(rv);
  599. }
  600. void setbalance(BALANCE **bal)
  601. {
  602.         if (*bal == 0)
  603.                 if (lastst = openpa || lastst == closepa)
  604.                         *bal = newbalance(*bal);
  605.                 else
  606.                         return;
  607.         switch (lastst) {
  608.                 case closepa:
  609.                                         while (*bal && (*bal)->type != BAL_PAREN) {
  610.                                                 (*bal) = (*bal)->back;
  611.                                         }
  612.                                         if (!((*bal)->type)--)
  613.                                                 (*bal) = (*bal)->back;
  614.                                         else return;    
  615.                 case closebr:
  616.                                         while (*bal && (*bal)->type != BAL_BRACKET) {
  617.                                                 (*bal) = (*bal)->back;
  618.                                         }
  619.                                         if (!((*bal)->type)--)
  620.                                                 (*bal) = (*bal)->back;
  621.                 case openpa:
  622.                                         if ((*bal)->type != BAL_PAREN)
  623.                                                 *bal = newbalance(*bal);
  624.                                         (*bal)->count++;
  625.                                         break;
  626.                                         
  627.                 case openbr:
  628.                                         if ((*bal)->type != BAL_BRACKET)
  629.                                                 *bal = newbalance(*bal);
  630.                                         (*bal)->count++;
  631.                                         break;
  632.         }
  633.         return;
  634. }
  635. void expskim(int *skimlist)
  636. {
  637.         BALANCE *bal = 0;
  638.         int i = 0;
  639.         for (i = 0; ; i++) {
  640.                 if (lastst == openpa || lastst == openbr) {
  641.                         setbalance(&bal);
  642.                         getsym();
  643.                 }
  644.                 else
  645.                         if (lastst == eof)
  646.                                 break;
  647.                         else
  648.                                 if (lastst == skimlist[i])
  649.                                         if (lastst == closepa || lastst == openpa) {
  650.                                                 if (!bal)
  651.                                                         break;
  652.                                                 setbalance(&bal);
  653.                                                 getsym();
  654.                                         }
  655.                                         else
  656.                                                 break;
  657.                                 else
  658.                                         if (skimlist[i] == 0) {
  659.                                                 i = 0;
  660.                                                 getsym();
  661.                                         }
  662.         }
  663.         
  664. }
  665. void basicerror(int n, void *data)
  666. /*
  667.  * standard routine for putting out an error
  668.  */
  669. {
  670.         char buf[100];
  671.         ERRORS *nexterr;
  672.         int errlvl,errored = 0;;
  673.         global_flag++;
  674.         nexterr = xalloc(sizeof(ERRORS));
  675.          global_flag--;
  676.          nexterr->errornumber = n;
  677.          nexterr->link = 0;
  678.          nexterr->data = data;
  679.         if (errlist == 0)
  680.                  errlist = errtail = nexterr;
  681.          else {
  682.                  errtail->link = nexterr;
  683.                  errtail = nexterr;
  684.         }
  685.         errlvl = printerr(buf, nexterr);
  686.         if (curerr == 0)
  687.                 curerr = nexterr;
  688.         if (!errlvl) {
  689. errline = lineno;
  690.                 fprintf(stdout,"Error   %s(%d):  %s",errfile,errlineno,buf);
  691. if (prm_errfile)
  692.                  fprintf(errFile,"Error   %s(%d):  %s",errfile,errlineno,buf);
  693. errored++;
  694.                 total_errors++;
  695.         }
  696.         else if (prm_warning && !nowarn[n] && (errline != lineno)) {
  697. errored++;
  698.                 fprintf(stdout,"Warning %s(%d):  %s",errfile,errlineno,buf);
  699. if (prm_errfile)
  700.                  fprintf(errFile,"Warning %s(%d):  %s",errfile,errlineno,buf);
  701. }
  702. if (errored) {
  703.          if (currentfunc) {
  704. unmangle(buf,currentfunc->name);
  705.                 fprintf(stdout," in function '%s'",buf);
  706. if (prm_errfile)
  707.                  fprintf(errFile," in function '%s'",buf);
  708. }
  709.          fputc('n',stdout);
  710. if (prm_errfile)
  711.          fputc('n',errFile);
  712. }
  713.   if (total_errors > prm_maxerr) {
  714.                 fatal("Too many errors");
  715.         }
  716. }
  717. void Error(char *string)
  718. /*
  719.  * some of the library functions required a generic error function
  720.  *
  721.  * we are remapping it to the C/C++ error routines
  722.  */
  723. {
  724.         basicerror(ERR_INTERP,(void *)string);
  725. }
  726. void generror(int n, int data, int *skimlist)
  727. /*
  728.  * most errors come here
  729.  */
  730. {                
  731.         basicerror(n,(void *)data);
  732.         if (skimlist) 
  733.                 basicskim(skimlist);
  734. }
  735. void gensymerror(int n, char *data)
  736. /*
  737.  * errors come here if the error has a symbol name
  738.  */
  739. {
  740. char buf[100];
  741. if (data)
  742. unmangle(buf,data);
  743. else
  744. buf[0] = 0;
  745.         global_flag++;
  746.         basicerror(n,(void *)litlate(buf));
  747.         global_flag--;
  748. }
  749. /*
  750.  * the next two functions are for reporting full C++ functions with
  751.  * the argument list types
  752.  */
  753. void genfuncerror(int n, char*func, char *data)
  754. {
  755. char buf[100],buf1[100],buf2[100];
  756. unmangle(buf1,func);
  757. if (data) {
  758. unmangle(buf2,data);
  759. buf[0] = ''';
  760. buf[1] = 0;
  761. strcat(buf,buf2);
  762. strcat(buf,"' ");
  763. }
  764. else
  765. buf[0] = 0;
  766. strcat(buf,"in call to function ");
  767. strcat(buf,"'");
  768. strcat(buf,buf1);
  769. strcat(buf,"'");
  770.         global_flag++;
  771.         basicerror(n,(void *)litlate(buf));
  772.         global_flag--;
  773. }
  774. void genfunc2error(int n, char*func, char *func2)
  775. {
  776. char buf[100],buf1[100],buf2[100];
  777. unmangle(buf1,func);
  778. unmangle(buf2,func2);
  779. buf[0] = ''';
  780. buf[1] = 0;
  781. strcpy(buf,buf2);
  782. strcat(buf,"'");
  783. strcat(buf," and ");
  784. strcat(buf,"'");
  785. strcat(buf,buf1);
  786. strcat(buf,"'");
  787.         global_flag++;
  788.         basicerror(n,(void *)litlate(buf));
  789.         global_flag--;
  790. }
  791. /*
  792.  * C++ errors for class names and type checking
  793.  */
  794. void genclasserror(int n, char *struc, char *elem)
  795. {
  796. char buf[100],buf1[100],buf2[100];
  797. unmangle(buf1,elem);
  798. unmangle(buf2,struc);
  799. buf[0] = ''';
  800. buf[1] = 0;
  801. strcpy(buf,buf2);
  802. strcat(buf,"::");
  803. strcat(buf,buf1);
  804. strcat(buf,"'");
  805.         global_flag++;
  806.         basicerror(n,(void *)litlate(buf));
  807.         global_flag--;
  808. }
  809. void genmismatcherror(TYP *tp1, TYP *tp2)
  810. {
  811. #ifdef CPLUSPLUS
  812. char buf[100],buf1[100],buf2[100];
  813. typenum(buf1,tp1);
  814. typenum(buf2,tp2);
  815. buf[0] = ''';
  816. buf[1] = 0;
  817. strcat(buf,buf1);
  818. strcat(buf,"'");
  819. strcat(buf," to ");
  820. strcat(buf,"'");
  821. strcat(buf,buf2);
  822. strcat(buf,"'");
  823.         global_flag++;
  824.         basicerror(ERR_CPPMISMATCH,(void *)litlate(buf));
  825.         global_flag--;
  826. #endif
  827. }
  828. /*
  829.  * various utilities for special case errors
  830.  */
  831. void expecttoken(int n, int *skimlist)
  832. {
  833.         if (skimlist)
  834.                 generror(ERR_PUNCT, n, skimlist);
  835.         else
  836.                 generror(ERR_INSERT, n, 0);
  837. }
  838. void generrorexp(int n, int data, int *skimlist)
  839. {                
  840.         basicerror(n,(void *)data);
  841.         if (skimlist) 
  842.                 expskim(skimlist);
  843. }
  844. void gensymerrorexp(int n, char *data)
  845. {
  846.         global_flag++;
  847.         basicerror(n,(void *)litlate(data));
  848.         global_flag--;
  849. }
  850. void expecttokenexp(int n, int *skimlist)
  851. {
  852.         if (skimlist)
  853.                 generrorexp(ERR_PUNCT, n, skimlist);
  854.         else
  855.                 generrorexp(ERR_INSERT, n, 0);
  856. }