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