1 //********************************************************** 2 // CR_ERROR.HPP 3 // Coco/R C++ Support Library. 4 // Author: Frankie Arzu <farzu@uvg.edu.gt> 5 // 6 // Jun 12, 1996 Version 1.06 7 // Many fixes and suggestions thanks to 8 // Pat Terry <p.terry@.ru.ac.za> 9 // Oct 11, 1997 Version 1.07 10 // Change definition of FileName to local storage 11 //********************************************************** 12 13 #ifndef CR_ERROR_H 14 #define CR_ERROR_H 15 16 #include "cr_abs.hpp" 17 #include <stdio.h> 18 19 const int MINERRORNO = 1000; // Error numbers > MINERRORNO are user numbers 20 21 class ErrDesc { 22 public: ErrDesc(int n,int l=0,int c=0)23 ErrDesc(int n, int l = 0, int c = 0) 24 { nr = n; line = l; col = c; next = NULL; }; ~ErrDesc()25 ~ErrDesc() 26 { if (next) delete next; }; SetNext(ErrDesc * n)27 void SetNext(ErrDesc *n) 28 { next = n; }; GetNext()29 ErrDesc *GetNext() 30 { return next; }; 31 int nr, line, col; 32 private: 33 ErrDesc *next; 34 }; 35 36 class CRError : public AbsError { 37 public: 38 CRError(char *name, AbsScanner *S, 39 int MinUserNo = MINERRORNO, int MinErr = 2); 40 // Create error reporter and associate with SourceFile and scanner S 41 // Set MinErr as a limit on error message clustering, and MinUserNo as 42 // a barrier for distinguishing private and user defined numbers 43 44 ~CRError(); 45 ReportError(int nr)46 virtual void ReportError(int nr) 47 // Associates error nr with most recently parsed token 48 { if (nr <= MinUserError) nr = MinUserError; 49 StoreErr(nr, Scanner->CurrSym); }; 50 GetErrorMsg(int n)51 virtual char *GetErrorMsg(int n) { return ""; }; 52 // Retrieves automatically derived error message text for error n 53 GetUserErrorMsg(int n)54 virtual char *GetUserErrorMsg(int n) { return ""; }; 55 // Retrieves user supplied error message text for error n 56 SetOutput(FILE * file)57 void SetOutput(FILE *file) { lst = file; }; 58 // Specifies file for error listing and reporting 59 60 void PrintListing(AbsScanner *Scanner); 61 // Generates source listing with error messages merged into it 62 63 virtual void SummarizeErrors(); 64 // Generates listing of errors only 65 66 int MinUserError; // Barrier for distinguishing private error numbers 67 int ErrorDist; // Number of tokens parsed since last error detected 68 int Errors; // Number of errors reported 69 70 // following were specified in abstract base class 71 virtual void Store(int nr, int line, int col, long pos); 72 virtual void StoreErr(int nr, AbsToken &Token); 73 virtual void StoreWarn(int nr, AbsToken &Token); 74 protected: 75 AbsScanner *Scanner; 76 FILE *lst; 77 char FileName[256]; 78 int MinErrorDist; 79 void PrintErrMsg(int nr); 80 void PrintErr(int nr, int col); 81 ErrDesc *FirstErr, *LastErr; 82 }; 83 84 #endif // CR_ERROR_H 85 86