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