1 /* 2 * The contents of this file are subject to the Mozilla Public License 3 * Version 1.0 (the "License"); you may not use this file except in 4 * compliance with the License. You may obtain a copy of the License at 5 * http://www.mozilla.org/MPL/ 6 * 7 * Software distributed under the License is distributed on an "AS IS" 8 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 9 * License for the specific language governing rights and limitations 10 * under the License. 11 * 12 * The Initial Developer of this code is David Baum. 13 * Portions created by David Baum are Copyright (C) 1999 David Baum. 14 * All Rights Reserved. 15 * 16 * Portions created by John Hansen are Copyright (C) 2005 John Hansen. 17 * All Rights Reserved. 18 * 19 */ 20 21 #ifndef __Error_h 22 #define __Error_h 23 24 #include <stdint.h> 25 26 enum ErrorCode 27 { 28 kErr_None = 0, 29 kErr_Parser, 30 kErr_UnterminatedIfdef, 31 kErr_UnexpectedElse, 32 kErr_UnknownDirective, 33 kErr_IncludeNeedsName, 34 kErr_FileOpen, 35 kErr_SymbolNameNeeded, 36 kErr_DefineRedef, 37 kErr_DefineArgs, 38 kErr_CircularDef, 39 kErr_WrongArgCount, 40 kErr_CondExpression, 41 kErr_UnexpectedEOL, 42 kErr_UnbalancedParens, 43 kErr_UnterminatedComment, 44 45 kErr_SymRedef, 46 kErr_NoVarDecl, 47 kErr_NoMoreVars, 48 kErr_Undeclared, 49 kErr_ConstantNeeded, 50 kErr_LValueNeeded, 51 52 kErr_UndefinedTask, 53 kErr_TooManySubs, 54 kErr_TooManyTasks, 55 kErr_UnknownInit, 56 kErr_UndefinedMain, 57 kErr_NoContinueContext, 58 kErr_NoSwitch, 59 kErr_NoBreakContext, 60 kErr_BadExpression, 61 kErr_NoMoreTemps, 62 kErr_NestedSubs, 63 kErr_ParamCount, 64 kErr_UndefinedFunction, 65 kErr_ParamType, 66 kErr_UndefinedVar, 67 68 kErr_CaseRange, 69 kErr_DuplicateCase, 70 kErr_RecursiveCall, 71 kErr_NumberRange, 72 73 kErr_NoTargetResources, 74 kErr_NoTargetEvents, 75 kErr_NoTargetArrays, 76 kErr_NoTargetPartialCatch, 77 kErr_NoTargetIndirect, 78 kErr_NoTargetSubParams, 79 80 kErr_BadEventSource, 81 kErr_NoNestedResources, 82 kErr_NoNestedEvents, 83 kErr_CouldNotReserveVars, 84 85 kErr_VarIsNotPointer, 86 kErr_VarIsArray, 87 kErr_VarIsNotArray, 88 kErr_TaskIdUnknown, 89 kErr_ErrorDirective, 90 91 kErr_UndefinedLabel, 92 kErr_RedefinedLabel, 93 94 kErr_BadResourceType, 95 kErr_TooManyResources, 96 97 kErr_AddrOfNonConstantIndex, 98 99 // catch-all for things in progress 100 kErr_NotSupported, 101 102 // warnings 103 kWarn_Base, 104 kWarn_IllegalPragma, 105 kWarn_WarningDirective, 106 107 kErr_Last 108 }; 109 110 111 class ErrorHandler; 112 struct LexLocation; 113 114 class Error 115 { 116 public: 117 enum 118 { 119 kMaxErrorMsg = 256 120 }; 121 fCode(code)122 Error(ErrorCode code, intptr_t data=0) : fCode(code), fData(data) {} Error(ErrorCode code,const char * s)123 Error(ErrorCode code, const char *s) : fCode(code), fData((intptr_t)s) {} 124 125 // raising errors 126 void Raise(const LexLocation *loc) const; // raise error at specified location 127 void RaiseLex() const; // raise error at current lex location 128 129 // useful for error handlers GetCode()130 ErrorCode GetCode() const { return fCode; } GetData()131 intptr_t GetData() const { return fData; } 132 bool IsWarning() const; 133 void SPrint(char *str) const; 134 135 private: 136 ErrorCode fCode; 137 intptr_t fData; 138 }; 139 140 141 class ErrorHandler 142 { 143 public: 144 void Raise(const Error&e, const LexLocation *loc); 145 void Reset(); GetErrorCount()146 int GetErrorCount() { return fErrorCount; } GetWarningCount()147 int GetWarningCount() { return fWarningCount; } 148 149 virtual void ClearErrors(); 150 virtual void AddError(const Error &e, const LexLocation *loc) = 0; 151 Get()152 static ErrorHandler* Get() { return sErrorHandler; } 153 154 protected: ErrorHandler()155 ErrorHandler() { sErrorHandler = this; } 156 private: 157 int fErrorCount; 158 int fWarningCount; 159 160 static ErrorHandler* sErrorHandler; 161 }; 162 163 #endif 164