home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Harvest C 1.3 / Source Code / Errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-15  |  8.3 KB  |  386 lines  |  [TEXT/ALFA]

  1. /*
  2.     Harvest C
  3.     Copyright 1992 Eric W. Sink.  All rights reserved.
  4.     
  5.     This file is part of Harvest C.
  6.     
  7.     Harvest C is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU Generic Public License as published by
  9.     the Free Software Foundation; either version 2, or (at your option)
  10.     any later version.
  11.     
  12.     Harvest C is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.     
  17.     You should have received a copy of the GNU General Public License
  18.     along with Harvest C; see the file COPYING.  If not, write to
  19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.     
  21.     Harvest C is not in any way a product of the Free Software Foundation.
  22.     Harvest C is not GNU software.
  23.     Harvest C is not public domain.
  24.  
  25.     This file may have other copyrights which are applicable as well.
  26.  
  27. */
  28.  
  29. /*
  30.  * Harvest C
  31.  * 
  32.  * Copyright 1991 Eric W. Sink   All rights reserved.
  33.  * 
  34.  * This file contains routines for error handling
  35.  * 
  36.  * 
  37.  * 
  38.  */
  39.  
  40. #include "conditcomp.h"
  41. #include <stdio.h>
  42. #include <console.h>
  43. #include <ctype.h>
  44. #include <string.h>
  45. #include <math.h>
  46. #include "tokens.h"
  47. #include "limitations.h"
  48. #include "structs.h"
  49.  
  50. #include "CHarvestDoc.h"
  51. #include "CHarvestOptions.h"
  52. #include "CErrorLog.h"
  53.  
  54. extern CHarvestDoc *gProject;
  55. extern CErrorLog *gErrs;
  56.  
  57.  
  58. /*
  59.  * The following routines are used for communication of errors and warnings
  60.  * to the user.  I have broken them down greatly for later portability.  The
  61.  * lowest level routine is UserMesg().
  62.  */
  63.  
  64. void
  65. Output(char *mesg, GenericFileVia_t thefile)
  66. /*
  67.  * This is a general routine for sending output.  It is separated as an
  68.  * entity because it is implementation dependent.
  69.  */
  70. {
  71. #ifdef Undefined
  72.     int                             bad;
  73.     if (Via(thefile)->theWind) {
  74.     /* Display in the window */
  75.     long                            count;
  76.     count = strlen(mesg);
  77.     } else {
  78.     /* Write directly to the file */
  79.     long                            count;
  80.     count = strlen(mesg);
  81.     bad = FSWrite(Via(thefile)->refnum, &count, mesg);
  82.     }
  83. #endif
  84.     gErrs->Hprintf(mesg);
  85. }
  86.  
  87. void
  88. OutputCR(char *mesg, GenericFileVia_t thefile)
  89. /*
  90.  * This is a general routine for sending output.  It is separated as an
  91.  * entity because it is implementation dependent. This routine appends a
  92.  * carriage return.
  93.  */
  94. {
  95. #ifdef Undefined
  96.     int                             bad;
  97.     char                            m[256];
  98.     sprintf(m, "%s\n", mesg);
  99.     if (Via(thefile)->theWind) {
  100.     /* Display in the window */
  101.     long                            count;
  102.     count = strlen(m);
  103.     } else {
  104.     /* Write directly to the file */
  105.     long                            count;
  106.     count = strlen(m);
  107.     bad = FSWrite(Via(thefile)->refnum, &count, m);
  108. }
  109. #endif
  110.     gErrs->Hprintf(mesg);
  111. }
  112.  
  113. void
  114. UserMesg(char *mesg)
  115. /*
  116.  * This is a general routine for issuing a message to the user.  It is
  117.  * separated as an entity because the fprintf to the err channel is
  118.  * implementation dependent, and the Macintosh version will not do it this
  119.  * way.
  120.  */
  121. {
  122.     char                            buf[256];
  123.     sprintf(buf, "%s", mesg);
  124.     Output(buf, errfile);
  125. }
  126.  
  127. void
  128. UserMesgCR(char *mesg)
  129. /*
  130.  * This is a general routine for issuing a message to the user.  It is
  131.  * separated as an entity because the fprintf to the err channel is
  132.  * implementation dependent, and the Macintosh version will not do it this
  133.  * way.  This routine appends a carriage return.
  134.  */
  135. {
  136.     char                            buf[256];
  137.     sprintf(buf, "%s", mesg);
  138.     Output(buf, errfile);
  139. }
  140.  
  141. void
  142. File_Line(char *buf)
  143. /*
  144.  * Outputs the current line number and file to the err channel. This is used
  145.  * when issuing an error to the user.  Unfortunately, because of token
  146.  * lookahead, this does not always give the actual line on which the error
  147.  * occurred.
  148.  */
  149. {
  150.     if (CurrentSRC.fileKind == SRC_SYSHEADER) {
  151.             sprintf(buf, "<%s>:%d ", CurrentSRC.fname, CurrentSRC.LineCount);
  152.     }
  153.     else {
  154.             sprintf(buf, "\"%s\":%d ", CurrentSRC.fname, CurrentSRC.LineCount);
  155.     }
  156. }
  157.  
  158. void
  159. EccErrorNOFILE(char *mesg)
  160. /*
  161.  * General error routine.
  162.  */
  163. {
  164.     NumErrors++;
  165.     UserMesg(" ERRR ");
  166.     UserMesgCR(mesg);
  167. }
  168.  
  169. void
  170. CodegenError(char *mesg)
  171. {
  172.     EccErrorNOFILE(mesg);
  173. }
  174.  
  175. void
  176. EccError(char *mesg)
  177. /*
  178.  * General error routine.  ALL errors should pass through here, so they may
  179.  * be counted properly.
  180.  */
  181. {
  182.     char buf[256];
  183.     NumErrors++;
  184.     File_Line(buf);
  185.     strcat(buf,mesg);
  186.     UserMesgCR(buf);
  187. }
  188.  
  189. int
  190. AssertError(char *file, int line, char *expr)
  191. {
  192.     char                            tmp[128];
  193.     sprintf(tmp, "Assertion failed: %s line %d: %s\n", file, line, expr);
  194.     c2pstr(tmp);
  195.     DebugStr(tmp);
  196.     return 1;
  197. }
  198.  
  199. void
  200. TypeError(char *mesg)
  201. {
  202.     char                            tmp[128];
  203.     sprintf(tmp, "Type, : %s", mesg);
  204.     EccError(tmp);
  205. }
  206.  
  207. void
  208. SemanticError(char *mesg)
  209. {
  210.     char                            tmp[128];
  211.     sprintf(tmp, "Semantic, : %s", mesg);
  212.     EccError(tmp);
  213. }
  214.  
  215. void
  216. DeclError2(char *mesg, char *info)
  217. {
  218.     char                            tmp[128];
  219.     sprintf(tmp, "Declaration, : %s %s", mesg, info);
  220.     EccError(tmp);
  221. }
  222.  
  223. void
  224. DeclErrorSYM(char *mesg, SYMVia_t thesym)
  225. {
  226.     char                            tmp[128];
  227. #ifdef OLDMEM
  228.     HLock((Handle) thesym);
  229. #endif
  230.     sprintf(tmp, "Declaration, : %s %s", mesg, (Via(thesym)->name));
  231. #ifdef OLDMEM
  232.     HUnlock((Handle) thesym);
  233. #endif
  234.     EccError(tmp);
  235.     /* TODO Generate info here about previous declaration */
  236. }
  237.  
  238. void
  239. DeclError(char *mesg)
  240. {
  241.     char                            tmp[128];
  242.     sprintf(tmp, "Declaration, : %s", mesg);
  243.     EccError(tmp);
  244. }
  245.  
  246. void
  247. FatalError2(char *mesg, char *info)
  248. {
  249.     char                            tmp[196];
  250.     sprintf(tmp, "FATAL, : %s %s", mesg, info);
  251.     gAbortCompile = 1;
  252.     EccError(tmp);
  253. }
  254.  
  255. void
  256. FatalError(char *mesg)
  257. {
  258.     char                            tmp[196];
  259.     sprintf(tmp, "FATAL, : %s", mesg);
  260.     EccError(tmp);
  261. }
  262.  
  263. void
  264. PreprocError2(char *mesg, char *info)
  265. {
  266.     char                            tmp[128];
  267.     sprintf(tmp, "Preproc, : %s %s", mesg, info);
  268.     EccError(tmp);
  269. }
  270.  
  271. void
  272. UserError(char *mesg)
  273. {
  274.     char                            tmp[128];
  275.     sprintf(tmp, "User, : %s", mesg);
  276.     EccError(tmp);
  277. }
  278.  
  279. void
  280. PreprocError(char *mesg)
  281. {
  282.     char                            tmp[128];
  283.     sprintf(tmp, "Preproc, : %s", mesg);
  284.     EccError(tmp);
  285. }
  286.  
  287. void
  288. LexError(char *mesg)
  289. {
  290.     char                            tmp[128];
  291.     sprintf(tmp, "Lexical, : %s", mesg);
  292.     EccError(tmp);
  293. }
  294.  
  295. void
  296. SemanticError2(char *mesg, char *info)
  297. {
  298.     char                            tmp[128];
  299.     sprintf(tmp, "Semantic, : %s %s", mesg, info);
  300.     EccError(tmp);
  301. }
  302.  
  303. void
  304. InlineAsmError(char *mesg)
  305. {
  306.     char                            tmp[128];
  307.     sprintf(tmp, "Asm Syntax : %s", mesg);
  308.     EccError(tmp);
  309. }
  310.  
  311. void
  312. SyntaxError(char *mesg)
  313. {
  314.     char                            tmp[128];
  315.     sprintf(tmp, "Syntax, before %s: %s", LastToken, mesg);
  316.     EccError(tmp);
  317. }
  318.  
  319. void
  320. Gen68Error(char *mesg)
  321. {
  322.     char                            tmp[128];
  323.     sprintf(tmp, "VERYBAD: %s", mesg);
  324.     c2pstr(tmp);
  325.     DebugStr(tmp);
  326. }
  327.  
  328. void
  329. VeryBadParseError(char *mesg)
  330. {
  331.     char                            tmp[128];
  332.     sprintf(tmp, "File %s Line %d VERYBAD: %s",
  333.         CurrentSRC.fname, CurrentSRC.LineCount, mesg);
  334.     c2pstr(tmp);
  335.     DebugStr(tmp);
  336. }
  337.  
  338. void
  339. UserWarning(int num)
  340. {
  341.     char buf[256];
  342.     AttemptWarnings++;
  343.     if (!gProject->itsOptions->noWarnings) {
  344.     if (gProject->itsOptions->allWarnings || gProject->itsOptions->warnings[num]) {
  345.         NumWarnings++;
  346.         File_Line(buf);
  347.         strcat(buf," WARN ");
  348.         GetWarningText(buf,num);
  349.         UserMesgCR(buf);
  350.     }
  351.     }
  352. }
  353.  
  354. void
  355. UserWarning2(int num, char *mesg)
  356. {
  357.     char buf[256];
  358.     AttemptWarnings++;
  359.     if (!gProject->itsOptions->noWarnings) {
  360.     if (gProject->itsOptions->allWarnings || gProject->itsOptions->warnings[num]) {
  361.         NumWarnings++;
  362.         File_Line(buf);
  363.         strcat(buf," WARN ");
  364.         GetWarningText(buf,num);
  365.         strcat(buf,mesg);
  366.         UserMesgCR(buf);
  367.     }
  368.     }
  369. }
  370.  
  371. void
  372. EccWarning(char *mesg)
  373. /*
  374.  * General warning routine.  ALL warnings should pass through here, so that
  375.  * they may be counted properly and not issued if warnings are disabled.
  376.  */
  377. {
  378.     char buf[256];
  379.     NumWarnings++;
  380.     if (!gProject->itsOptions->noWarnings) {
  381.     File_Line(buf);
  382.     strcat(buf,mesg);
  383.     UserMesgCR(buf);
  384.     }
  385. }
  386.