Wrong case on file SDCCerr.c
[fw/sdcc] / support / Util / SDCCerr.c
1 /*
2  * SDCCerr - Standard error handler
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Library General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 #include <stdio.h>
20
21 #include "SDCCerr.h"
22
23 #define USE_STDOUT_FOR_ERRORS           0
24
25 #if USE_STDOUT_FOR_ERRORS
26 #define DEFAULT_ERROR_OUT       stdout
27 #else
28 #define DEFAULT_ERROR_OUT       stderr
29 #endif
30
31 static FILE *ErrorOut ;
32
33 #define ERROR           0
34 #define WARNING         1
35
36 extern char *filename ;
37 extern int lineno ;
38 extern int fatalError ;
39
40 struct  {
41         int             errType ;
42         char    *errText ;
43 } ErrTab [] =
44 {
45 {  ERROR  ,"error *** Duplicate symbol '%s', symbol IGNORED\n"                },
46 { ERROR  ,"error *** Syntax Error Declaration ingonerd\n"                             },
47 { ERROR  ,"error *** Constant Expected Found Variable\n"                          },
48 { ERROR  ,"error *** 'malloc' failed file '%s' for size %ld\n"                },
49 { ERROR  ,"error *** 'fopen' failed on file '%s'\n"                                   },
50 { ERROR  ,"error *** Internal Error Oclass invalid '%s'\n"                            },
51 { ERROR  ,"error *** Cannot allocate variable '%s'.\n"                        },
52 { ERROR  ,"error *** Old style C declaration. IGNORED '%s'\n"                 },
53 { ERROR  ,"error *** Out of stack Space. '%s' not allocted\n"                 },
54 { ERROR  ,"error *** FATAL Compiler Internal Error in file '%s' line number '%d' : %s \nContact Author with source code\n" },
55 { ERROR  ,"error *** 'lvalue' required for '%s' operation .\n"                },
56 { ERROR  ,"error *** Creation of temp file failed\n"                          },
57 { ERROR  ,"error *** Function expected here '%s'\n"                                   },
58 { ERROR  ,"error *** 'using', 'interrupt' or 'reentrant' must follow a function definiton .'%s'\n"},
59 { ERROR  ,"error *** Absolute address & initial value both cannot be specified for\n a 'sfr','sbit' storage class, initial value ignored '%s'\n"  },
60 { WARNING,"warning *** Variable in the storage class cannot be initialized.'%s'\n"},
61 { WARNING,"warning *** storage class not allowed for automatic variable '%s' in reentrant function\n"   },
62 { ERROR  ,"error *** absolute address not allowed for automatic var '%s' in reentrant function \n"            },
63 { WARNING,"warning *** Initializer different levels of indirections\n"        },
64 { ERROR  ,"error *** Function name '%s' redefined \n"                         },
65 { ERROR  ,"error *** Undefined identifier '%s'\n"                                 },
66 { WARNING,"warning *** stack exceeds 256 bytes for function '%s'\n"},
67 { ERROR  ,"error *** Array or pointer required for '%s' operation \n"         },
68 { ERROR  ,"error *** Array index not an integer\n"                                },
69 { ERROR  ,"error *** Array bound Exceeded, assuming zero\n"                           },
70 { ERROR  ,"error *** Structure/Union expected left of '.%s'\n"                    },
71 { ERROR  ,"error *** '%s' not a structure/union member\n"                         },
72 { ERROR  ,"error *** Pointer required\n"                                              },
73 { ERROR  ,"error *** 'unary %c': illegal operand\n"                                   },
74 { ERROR  ,"error *** convertion error: integral promotion failed\n"                   },
75 { ERROR  ,"error *** type must be INT for bit field definition\n"                     },
76 { ERROR  ,"error *** bit field size greater than 16 . assuming 16\n"              },
77 { WARNING,"warning *** high order truncation might occur\n"                           },
78 { ERROR  ,"error *** Attempt to assign value to a constant variable %s\n"         },
79 { ERROR  ,"error *** Lvalue specifies constant object\n"                          },
80 { ERROR  ,"error *** '&' illegal operand , %s\n"                                  },
81 { ERROR  ,"error *** illegal cast (cast cannot be aggregate)\n"                   },
82 { ERROR  ,"error *** '*' bad operand\n"                                           },
83 { ERROR  ,"error *** Argument count error, argument ignored\n"                    },
84 { ERROR  ,"error *** Function was expecting more arguments\n"                     },
85 { ERROR  ,"error *** Function name expected '%s'.ANSI style declaration REQUIRED\n"},
86 { ERROR  ,"error *** invalid operand '%s'\n"                                          },
87 { ERROR  ,"error *** pointer + pointer invalid\n"                                     },
88 { ERROR  ,"error *** invalid operand for shift operator\n"                            },
89 { ERROR  ,"error *** compare operand cannot be struct/union\n"                },
90 { ERROR  ,"error *** operand invalid for bitwise operation\n"                 },
91 { ERROR  ,"error *** Invalid operand for '&&' or '||'\n"                              },
92 { WARNING,"warning *** indirections to different types %s %s \n"                      },
93 { ERROR  ,"error *** cannot assign values to aggregates\n"                            },
94 { ERROR  ,"error *** bit Arrays can be accessed by literal index only\n"              },
95 { ERROR  ,"error *** Array or Pointer to bit|sbit|sfr not allowed.'%s'\n"             },
96 { ERROR  ,"error *** typedef/enum '%s' duplicate.Previous definiton Ignored\n"    },
97 { ERROR  ,"error *** Actual Argument type different from declaration %d\n"            },
98 { ERROR  ,"error *** Function return value mismatch\n"                        },
99 { ERROR  ,"error *** Function cannot return aggregate. Func body ignored\n"           },
100 { ERROR  ,"error *** ANSI Style declaration needed\n"                         },
101 { ERROR  ,"error *** Label name redefined '%s'\n"                                     },
102 { ERROR  ,"error *** Label undefined '%s'\n"                                  },
103 { ERROR  ,"error *** void function returning value\n"                         },
104 { ERROR  ,"error *** function '%s' must return value\n"                       },
105 { WARNING,"warning *** function return value mismatch\n"                              },
106 { ERROR  ,"error *** 'case/default' found without 'switch'.statement ignored\n"   },
107 { ERROR  ,"error *** 'case' expression not constant. statement ignored\n"             },
108 { ERROR  ,"error *** 'break/continue' statement out of context\n"                     },
109 { ERROR  ,"error *** nonintegral used in switch expression\n"                 },
110 { ERROR  ,"error *** function '%s' already has body\n"                        },
111 { ERROR  ,"error *** attempt to allocate variable of unknown size '%s'\n"             },
112 { ERROR  ,"error *** aggregate 'auto' variable '%s' cannot be initialized\n"      },
113 { ERROR  ,"error *** too many initializers\n"                                 },
114 { ERROR  ,"error *** struct/union/array '%s' :initialization needs curly braces\n"},
115 { ERROR  ,"error *** non-address initialization expression\n"                 },
116 { ERROR  ,"error *** interrupt no '%d' already has a service routine '%s'\n"          },
117 { ERROR  ,"error *** interrupt routine cannot have arguments, arguments ingored\n"},
118 { ERROR  ,"error *** critical compiler #include file missing.           \n"   },
119 { ERROR  ,"error *** function 'main' undefined\n"                                 },
120 { ERROR  ,"error *** 'extern' variable '%s' cannot be initialised       \n"           },
121 { ERROR  ,"error *** Pre-Processor %s\n"                                              },
122 { ERROR  ,"error *** _dup call failed\n"                                          },
123 { WARNING,"warning *** pointer being cast to incompatible type \n"                        },
124 { WARNING,"warning *** 'while' loop with 'zero' constant.loop eliminated\n"           },
125 { WARNING,"warning *** %s expression has NO side effects.expr eliminated\n"           },
126 { WARNING,"warning *** constant value '%s', out of range.\n"                  },
127 { WARNING,"warning *** comparison will either, ALWAYs succeed or ALWAYs fail\n"   },
128 { ERROR  ,"error *** Compiler Terminating , contact author with source\n"             },
129 { WARNING,"warning *** 'auto' variable '%s' may be used before initialization at %s(%d)\n"      },
130 { WARNING,"warning *** in function %s unreferenced %s : '%s'\n"                       },
131 { ERROR  ,"error *** unknown size for operand\n"                                      },
132 { WARNING,"warning *** '%s' 'long' not supported , declared as 'int' .\n"             },
133 { WARNING,"warning *** LITERAL value being cast to '_generic' pointer\n"              },
134 { ERROR  ,"error *** %s '%s' address out of range\n"                                  },
135 { ERROR  ,"error *** storage class CANNOT be specified for bit variable '%s'\n"    },
136 { WARNING,"warning *** extern definition for '%s' mismatches with declaration.\n"  },
137 { WARNING,"warning *** Functions called via pointers must be 'reentrant' to take arguments\n"   },
138 { WARNING,"warning *** type 'double' not supported assuming 'float'\n"                },
139 { WARNING,"warning *** if-statement condition always false.if-statement not generated\n"},
140 { WARNING,"warning *** no 'return' statement found for function '%s'\n"       },
141 { WARNING,"warning *** Pre-Processor %s\n"                                            },
142 { WARNING,"warning *** structure '%s' passed as function argument changed to pointer\n"},
143 { ERROR  ,"error *** conflict with previous definition of '%s' for attribute '%s'\n" },
144 { ERROR  ,"error *** variable '%s' declared in code space must have initialiser\n" },
145 { ERROR  ,"error *** operands not integral for assignment operation\n"            },
146 { ERROR  ,"error *** too many parameters \n"                                      },
147 { ERROR  ,"error *** to few parameters\n"                                         },
148 { ERROR  ,"error *** code not generated for '%s' due to previous errors\n"},
149 { WARNING,"warning *** type mismatch for parameter number %d\n"},
150 { ERROR  ,"error *** invalid float constant '%s'\n"},
151 { ERROR  ,"error *** invalid operand for '%s' operation\n"},
152 { ERROR  ,"error *** switch value not an integer\n"},
153 { ERROR  ,"error *** case label not an integer\n"},
154 { WARNING,"warning *** function '%s' too large for global optimization\n"},
155 { WARNING,"warning *** conditional flow changed by optimizer '%s(%d)':so said EVELYN the modified DOG\n"},
156 { WARNING,"warning *** invalid type specifier for pointer type specifier ignored\n"},
157 { WARNING,"warning *** function '%s' implicit declaration\n"},
158 { WARNING,"warning *** %s"},
159 { WARNING,"info *** %s extended by %d bytes for compiler temp(s) :in function  '%s': %s \n"},
160 { WARNING,"warning *** unknown or unsupported #pragma directive '%s'\n"},
161 { WARNING,"warning *** %s shifting more than size of object changed to zero\n"},
162 { WARNING,"warning *** unknown compiler option '%s' ignored\n"},
163 { WARNING,"warning *** option '%s' no longer supported  '%s' \n"},
164 { WARNING,"warning *** don't know what to do with file '%s'. file extension unsupported\n"},
165 { WARNING,"warning *** cannot compile more than one source file . file '%s' ignored\n"},
166 { WARNING,"info *** function '%s', # edges %d , # nodes %d , cyclomatic complexity %d\n"},
167 { ERROR  ,"error *** dividing by ZERO\n"},
168 { ERROR  ,"error *** function cannot return 'bit'\n"},
169 { ERROR  ,"error *** casting from to type 'void' is illegal\n"},
170 { WARNING,"warning *** constant is out of range %s\n" },
171 { WARNING,"warning *** unreachable code %s(%d)\n"},
172 { WARNING,"warning *** non-pointer type cast to _generic pointer\n"},
173 { WARNING,"warning *** possible code generation error at line %d,\n send source to sandeep.dutta@usa.net\n"},
174 { WARNING,"warning *** pointer types incompatible \n" },
175 { WARNING,"warning *** unknown memory model at %s : %d\n" },
176 { ERROR  ,"error   *** cannot generate code for target '%s'\n"},
177 { WARNING,"warning *** Indirect call to a banked function not implemented.\n"},
178 { WARNING,"warning *** Model '%s' not supported for %s, ignored.\n"},
179 { WARNING,"warning *** Both banked and nonbanked attributes used.  nonbanked wins.\n"},
180 { WARNING,"warning *** Both banked and static used.  static wins.\n"},
181 { WARNING,"warning *** converting integer type to generic pointer: assuming XDATA\n"}
182 };
183 /*
184 -------------------------------------------------------------------------------
185 SetErrorOut - Set the error output file
186
187 -------------------------------------------------------------------------------
188 */
189
190 FILE *SetErrorOut(FILE *NewErrorOut)
191
192 {
193 ErrorOut = NewErrorOut ;
194
195 return NewErrorOut ;
196 }
197 /*
198 -------------------------------------------------------------------------------
199 vwerror - Output a standard eror message with variable number of arguements
200
201 -------------------------------------------------------------------------------
202 */
203
204 void vwerror (int errNum, va_list marker)
205
206 {
207 if (!ErrorOut)
208         ErrorOut = DEFAULT_ERROR_OUT ;
209
210 if ( ErrTab[errNum].errType == ERROR )
211     fatalError++ ;
212
213 if ( filename && lineno ) 
214     fprintf(ErrorOut, "%s(%d):",filename,lineno);
215
216 vfprintf(ErrorOut, ErrTab[errNum].errText,marker);
217 }
218 /*
219 -------------------------------------------------------------------------------
220 werror - Output a standard eror message with variable number of arguements
221
222 -------------------------------------------------------------------------------
223 */
224
225 void werror (int errNum, ... )
226
227 {
228 va_list marker;
229 va_start(marker,errNum);
230 vwerror(errNum, marker);
231 va_end( marker );
232 }
233