X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=support%2FUtil%2FSDCCerr.c;h=a20917f0b6c73e28e20e813274afdd582cf56a82;hb=85cb1c7d9f34e31311e7a2d7fa1d47aeb3a11c4e;hp=e8b25529f1c21450822283324cc2e96d94c293c2;hpb=6debd5bce497b8fda011030faa8749b6cff49aab;p=fw%2Fsdcc diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index e8b25529..a20917f0 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -17,22 +17,19 @@ */ #include +#include #include "SDCCerr.h" - -#define USE_STDOUT_FOR_ERRORS 0 +#define USE_STDOUT_FOR_ERRORS 0 #if USE_STDOUT_FOR_ERRORS -#define DEFAULT_ERROR_OUT stdout +#define DEFAULT_ERROR_OUT stdout #else -#define DEFAULT_ERROR_OUT stderr +#define DEFAULT_ERROR_OUT stderr #endif -static struct { - ERROR_LOG_LEVEL logLevel; - FILE *out; -} _SDCCERRG; +struct SDCCERRG _SDCCERRG; extern char *filename ; extern int lineno ; @@ -42,11 +39,11 @@ extern int fatalError ; * entry in the array. It is only included in order to make * human error lookup easier. */ -struct +struct { - int errIndex; - ERROR_LOG_LEVEL errType; - const char *errText; + int errIndex; + ERROR_LOG_LEVEL errType; + const char *errText; } ErrTab [] = { { E_DUPLICATE, ERROR_LEVEL_ERROR, @@ -71,23 +68,23 @@ struct "FATAL Compiler Internal Error in file '%s' line number '%d' : %s \n" "Contact Author with source code" }, { E_LVALUE_REQUIRED, ERROR_LEVEL_ERROR, - "'lvalue' required for '%s' operation ." }, + "'lvalue' required for '%s' operation." }, { E_TMPFILE_FAILED, ERROR_LEVEL_ERROR, "Creation of temp file failed" }, { E_FUNCTION_EXPECTED, ERROR_LEVEL_ERROR, "called object is not a function" }, { E_USING_ERROR, ERROR_LEVEL_ERROR, - "'using', 'interrupt' or 'reentrant' must follow a function definiton .'%s'" }, + "'using', 'interrupt' or 'reentrant' must follow a function definiton.'%s'" }, { E_SFR_INIT, ERROR_LEVEL_ERROR, "Absolute address & initial value both cannot be specified for\n" " a 'sfr','sbit' storage class, initial value ignored '%s'" }, { W_INIT_IGNORED, ERROR_LEVEL_WARNING, "Variable in the storage class cannot be initialized.'%s'" }, { E_AUTO_ASSUMED, ERROR_LEVEL_ERROR, - "storage class not allowed for automatic variable '%s' in reentrant function unless static" }, + "variable '%s' must be static to have storage class in reentrant function" }, { E_AUTO_ABSA, ERROR_LEVEL_ERROR, "absolute address not allowed for automatic var '%s' in reentrant function " }, -{ E_INIT_WRONG, ERROR_LEVEL_ERROR, +{ W_INIT_WRONG, ERROR_LEVEL_WARNING, "Initializer different levels of indirections" }, { E_FUNC_REDEF, ERROR_LEVEL_ERROR, "Function name '%s' redefined " }, @@ -99,8 +96,8 @@ struct "Array or pointer required for '%s' operation " }, { E_IDX_NOT_INT, ERROR_LEVEL_ERROR, "Array index not an integer" }, -{ E_ARRAY_BOUND, ERROR_LEVEL_ERROR, - "Array bound Exceeded, assuming zero" }, +{ W_IDX_OUT_OF_BOUNDS, ERROR_LEVEL_WARNING, + "index %i is outside of the array bounds (array size is %i)" }, { E_STRUCT_UNION, ERROR_LEVEL_ERROR, "Structure/Union expected left of '.%s'" }, { E_NOT_MEMBER, ERROR_LEVEL_ERROR, @@ -114,11 +111,11 @@ struct { E_INT_REQD, ERROR_LEVEL_ERROR, "type must be INT for bit field definition" }, { E_BITFLD_SIZE, ERROR_LEVEL_ERROR, - "bit field size greater than 16 . assuming 16" }, + "bit field size cannot be greater than int (%d bits)" }, { W_TRUNCATION, ERROR_LEVEL_WARNING, "high order truncation might occur" }, { E_CODE_WRITE, ERROR_LEVEL_ERROR, - "Attempt to assign value to a constant variable %s" }, + "Attempt to assign value to a constant variable (%s)" }, { E_LVALUE_CONST, ERROR_LEVEL_ERROR, "Lvalue specifies constant object" }, { E_ILLEGAL_ADDR, ERROR_LEVEL_ERROR, @@ -132,7 +129,7 @@ struct { E_ARG_COUNT, ERROR_LEVEL_ERROR, "Function was expecting more arguments" }, { E_FUNC_EXPECTED, ERROR_LEVEL_ERROR, - "Function name expected '%s'.ANSI style declaration REQUIRED" }, + "Function name expected '%s'. ANSI style declaration REQUIRED" }, { E_PLUS_INVALID, ERROR_LEVEL_ERROR, "invalid operand '%s'" }, { E_PTR_PLUS_PTR, ERROR_LEVEL_ERROR, @@ -154,7 +151,7 @@ struct { E_BIT_ARRAY, ERROR_LEVEL_ERROR, "Array or Pointer to bit|sbit|sfr not allowed.'%s'" }, { E_DUPLICATE_TYPEDEF, ERROR_LEVEL_ERROR, - "typedef/enum '%s' duplicate.Previous definiton Ignored" }, + "typedef/enum '%s' duplicate. Previous definiton Ignored" }, { E_ARG_TYPE, ERROR_LEVEL_ERROR, "Actual Argument type different from declaration %d" }, { E_RET_VALUE, ERROR_LEVEL_ERROR, @@ -164,19 +161,19 @@ struct { E_FUNC_DEF, ERROR_LEVEL_ERROR, "ANSI Style declaration needed" }, { E_DUPLICATE_LABEL, ERROR_LEVEL_ERROR, - "Label name redefined '%s'" }, + "Duplicate label '%s'" }, { E_LABEL_UNDEF, ERROR_LEVEL_ERROR, "Label undefined '%s'" }, { E_FUNC_VOID, ERROR_LEVEL_ERROR, "void function returning value" }, -{ E_VOID_FUNC, ERROR_LEVEL_ERROR, +{ W_VOID_FUNC, ERROR_LEVEL_WARNING, "function '%s' must return value" }, { W_RETURN_MISMATCH, ERROR_LEVEL_WARNING, "function return value mismatch" }, { E_CASE_CONTEXT, ERROR_LEVEL_ERROR, - "'case/default' found without 'switch'.statement ignored" }, + "'case/default' found without 'switch'. Statement ignored" }, { E_CASE_CONSTANT, ERROR_LEVEL_ERROR, - "'case' expression not constant. statement ignored" }, + "'case' expression not constant. Statement ignored" }, { E_BREAK_CONTEXT, ERROR_LEVEL_ERROR, "'break/continue' statement out of context" }, { E_SWITCH_AGGR, ERROR_LEVEL_ERROR, @@ -190,7 +187,7 @@ struct { E_INIT_COUNT, ERROR_LEVEL_ERROR, "too many initializers" }, { E_INIT_STRUCT, ERROR_LEVEL_ERROR, - "struct/union/array '%s' :initialization needs curly braces" }, + "struct/union/array '%s': initialization needs curly braces" }, { E_INIT_NON_ADDR, ERROR_LEVEL_ERROR, "non-address initialization expression" }, { E_INT_DEFINED, ERROR_LEVEL_ERROR, @@ -198,11 +195,11 @@ struct { E_INT_ARGS, ERROR_LEVEL_ERROR, "interrupt routine cannot have arguments, arguments ingored" }, { E_INCLUDE_MISSING, ERROR_LEVEL_ERROR, - "critical compiler #include file missing. " }, + "critical compiler #include file missing. " }, { E_NO_MAIN, ERROR_LEVEL_ERROR, "function 'main' undefined" }, { E_EXTERN_INIT, ERROR_LEVEL_ERROR, - "'extern' variable '%s' cannot be initialised " }, + "'extern' variable '%s' cannot be initialised " }, { E_PRE_PROC_FAILED, ERROR_LEVEL_ERROR, "Pre-Processor %s" }, { E_DUP_FAILED, ERROR_LEVEL_ERROR, @@ -210,9 +207,9 @@ struct { E_INCOMPAT_TYPES, ERROR_LEVEL_ERROR, "incompatible types" }, { W_LOOP_ELIMINATE, ERROR_LEVEL_WARNING, - "'while' loop with 'zero' constant.loop eliminated" }, + "'while' loop with 'zero' constant. Loop eliminated" }, { W_NO_SIDE_EFFECTS, ERROR_LEVEL_WARNING, - "%s expression has NO side effects.expr eliminated" }, + "%s expression has NO side effects. Expr eliminated" }, { W_CONST_TOO_LARGE, ERROR_LEVEL_PEDANTIC, "constant value '%s', out of range." }, { W_BAD_COMPARE, ERROR_LEVEL_WARNING, @@ -220,13 +217,13 @@ struct { E_TERMINATING, ERROR_LEVEL_ERROR, "Compiler Terminating , contact author with source" }, { W_LOCAL_NOINIT, ERROR_LEVEL_WARNING, - "'auto' variable '%s' may be used before initialization at %s(%d)" }, + "'auto' variable '%s' may be used before initialization" }, { W_NO_REFERENCE, ERROR_LEVEL_WARNING, "in function %s unreferenced %s : '%s'" }, { E_OP_UNKNOWN_SIZE, ERROR_LEVEL_ERROR, "unknown size for operand" }, { W_LONG_UNSUPPORTED, ERROR_LEVEL_WARNING, - "'%s' 'long' not supported , declared as 'int' ." }, + "'%s' 'long' not supported , declared as 'int'." }, { E_LITERAL_GENERIC, ERROR_LEVEL_ERROR, //"illegal cast of LITERAL value to 'generic' pointer: assuming 'xdata' pointer" }, "illegal cast of LITERAL value to 'generic' pointer" }, @@ -240,8 +237,8 @@ struct "Functions called via pointers must be 'reentrant' to take arguments" }, { W_DOUBLE_UNSUPPORTED, ERROR_LEVEL_WARNING, "type 'double' not supported assuming 'float'" }, -{ W_IF_NEVER_TRUE, ERROR_LEVEL_WARNING, - "if-statement condition always false, if-statement not generated" }, +{ W_COMP_RANGE, ERROR_LEVEL_WARNING, + "comparison is always %s due to limited range of data type" }, { W_FUNC_NO_RETURN, ERROR_LEVEL_WARNING, "no 'return' statement found for function '%s'" }, { W_PRE_PROC_WARNING, ERROR_LEVEL_WARNING, @@ -273,9 +270,9 @@ struct { W_FUNC_TOO_LARGE, ERROR_LEVEL_WARNING, "function '%s' too large for global optimization" }, { W_CONTROL_FLOW, ERROR_LEVEL_PEDANTIC, - "conditional flow changed by optimizer '%s(%d)':so said EVELYN the modified DOG" }, + "conditional flow changed by optimizer: so said EVELYN the modified DOG" }, { W_PTR_TYPE_INVALID, ERROR_LEVEL_WARNING, - "invalid type specifier for pointer type specifier ignored" }, + "invalid type specifier for pointer type; specifier ignored" }, { W_IMPLICIT_FUNC, ERROR_LEVEL_WARNING, "function '%s' implicit declaration" }, { W_CONTINUE, ERROR_LEVEL_WARNING, @@ -293,7 +290,7 @@ struct { W_UNKNOWN_FEXT, ERROR_LEVEL_WARNING, "don't know what to do with file '%s'. file extension unsupported" }, { W_TOO_MANY_SRC, ERROR_LEVEL_WARNING, - "cannot compile more than one source file . file '%s' ignored" }, + "cannot compile more than one source file. file '%s' ignored" }, { I_CYCLOMATIC, ERROR_LEVEL_INFO, "function '%s', # edges %d , # nodes %d , cyclomatic complexity %d" }, { E_DIVIDE_BY_ZERO, ERROR_LEVEL_ERROR, @@ -305,7 +302,7 @@ struct { W_CONST_RANGE, ERROR_LEVEL_WARNING, "constant is out of range %s" }, { W_CODE_UNREACH, ERROR_LEVEL_PEDANTIC, - "unreachable code %s(%d)" }, + "unreachable code" }, { E_NONPTR2_GENPTR, ERROR_LEVEL_ERROR, "non-pointer type cast to generic pointer" }, { W_POSSBUG, ERROR_LEVEL_WARNING, @@ -349,7 +346,7 @@ struct { E_TWO_OR_MORE_STORAGE_CLASSES, ERROR_LEVEL_ERROR, "two or more storage classes in declaration for '%s'" }, { W_EXCESS_INITIALIZERS, ERROR_LEVEL_WARNING, - "excess elements in %s initializer after `%s' at line %d" }, + "excess elements in %s initializer after '%s'" }, { E_ARGUMENT_MISSING, ERROR_LEVEL_ERROR, "Option %s requires an argument." }, { W_STRAY_BACKSLASH, ERROR_LEVEL_WARNING, @@ -369,11 +366,84 @@ struct { W_SYMBOL_NAME_TOO_LONG, ERROR_LEVEL_WARNING, "symbol name too long, truncated to %d chars" }, { W_CAST_STRUCT_PTR,ERROR_LEVEL_WARNING, - "cast of struct %s * to struct %s * " }, -{ W_IF_ALWAYS_TRUE, ERROR_LEVEL_WARNING, - "if-statement condition always true, if-statement not generated" }, + "cast of struct %s * to struct %s * " }, +{ W_LIT_OVERFLOW, ERROR_LEVEL_WARNING, + "overflow in implicit constant conversion" }, { E_PARAM_NAME_OMITTED, ERROR_LEVEL_ERROR, "in function %s: name omitted for parameter %d" }, +{ W_NO_FILE_ARG_IN_C1, ERROR_LEVEL_WARNING, + "only standard input is compiled in c1 mode. file '%s' ignored" }, +{ E_NEED_OPT_O_IN_C1, ERROR_LEVEL_ERROR, + "must specify assembler file name with -o in c1 mode" }, +{ W_ILLEGAL_OPT_COMBINATION, ERROR_LEVEL_WARNING, + "illegal combination of options (--c1mode, -E, -S -c)" }, +{ E_DUPLICATE_MEMBER, ERROR_LEVEL_ERROR, + "duplicate %s member '%s'" }, +{ E_STACK_VIOLATION, ERROR_LEVEL_ERROR, + "'%s' internal stack %s" }, +{ W_INT_OVL, ERROR_LEVEL_PEDANTIC, + "integer overflow in expression" }, +{ W_USELESS_DECL, ERROR_LEVEL_WARNING, + "useless declaration (possible use of keyword as variable name)" }, +{ E_INT_BAD_INTNO, ERROR_LEVEL_ERROR, + "interrupt number '%u' is not valid" }, +{ W_BITFLD_NAMED, ERROR_LEVEL_WARNING, + "ignoring declarator of 0 length bitfield" }, +{ E_FUNC_ATTR, ERROR_LEVEL_ERROR, + "function attribute following non-function declaration"}, +{ W_SAVE_RESTORE, ERROR_LEVEL_PEDANTIC, + "unmatched #pragma save and #pragma restore" }, +{ E_INVALID_CRITICAL, ERROR_LEVEL_ERROR, + "not allowed in a critical section" }, +{ E_NOT_ALLOWED, ERROR_LEVEL_ERROR, + "%s not allowed here" }, +{ E_BAD_TAG, ERROR_LEVEL_ERROR, + "'%s' is not a %s tag" }, +{ E_ENUM_NON_INTEGER, ERROR_LEVEL_ERROR, + "enumeration constant not an integer" }, +{ W_DEPRECATED_PRAGMA, ERROR_LEVEL_WARNING, + "pragma %s is deprecated, please see documentation for details" }, +{ E_SIZEOF_INCOMPLETE_TYPE, ERROR_LEVEL_ERROR, + "sizeof applied to an incomplete type" }, +{ E_PREVIOUS_DEF, ERROR_LEVEL_ERROR, + "previously defined here" }, +{ W_SIZEOF_VOID, ERROR_LEVEL_WARNING, + "size of void is zero" }, +{ W_POSSBUG2, ERROR_LEVEL_WARNING, + "possible code generation error at %s line %d,\n" + " please report problem and send source code at SDCC-USER list on SF.Net"}, +{ W_COMPLEMENT, ERROR_LEVEL_WARNING, + "using ~ on bit/bool/unsigned char variables can give unexpected results due to promotion to int" }, +{ E_SHADOWREGS_NO_ISR, ERROR_LEVEL_ERROR, + "ISR function attribute 'shadowregs' following non-ISR function '%s'" }, +{ W_SFR_ABSRANGE, ERROR_LEVEL_WARNING, + "absolute address for sfr '%s' probably out of range." }, +{ E_BANKED_WITH_CALLEESAVES, ERROR_LEVEL_ERROR, + "Both banked and callee-saves cannot be used together." }, +{ W_INVALID_INT_CONST, ERROR_LEVEL_WARNING, + "integer constant '%s' out of range, truncated to %.0lf." }, +{ W_CMP_SU_CHAR, ERROR_LEVEL_PEDANTIC, + "comparison of 'signed char' with 'unsigned char' requires promotion to int" }, +{ W_INVALID_FLEXARRAY, ERROR_LEVEL_WARNING, + "invalid use of structure with flexible array member" }, +{ W_C89_NO_FLEXARRAY, ERROR_LEVEL_PEDANTIC, + "ISO C90 does not support flexible array members" }, +{ E_FLEXARRAY_NOTATEND, ERROR_LEVEL_ERROR, + "flexible array member not at end of struct" }, +{ E_FLEXARRAY_INEMPTYSTRCT, ERROR_LEVEL_ERROR, + "flexible array in otherwise empty struct" }, +{ W_EMPTY_SOURCE_FILE, ERROR_LEVEL_WARNING, + "ISO C forbids an empty source file" }, +{ W_BAD_PRAGMA_ARGUMENTS, ERROR_LEVEL_WARNING, + "#pragma %s: bad argument(s); pragma ignored" }, +{ E_BAD_RESTRICT, ERROR_LEVEL_ERROR, + "Only pointers may be qualified with 'restrict'" }, +{ E_BAD_INLINE, ERROR_LEVEL_ERROR, + "Only functions may be qualified with 'inline'" }, +{ E_BAD_INT_ARGUMENT, ERROR_LEVEL_ERROR, + "Bad integer argument for option %s" }, +{ E_NEGATIVE_ARRAY_SIZE, ERROR_LEVEL_ERROR, + "Size of array '%s' is negative" }, }; /* @@ -384,15 +454,13 @@ SetErrorOut - Set the error output file */ FILE *SetErrorOut(FILE *NewErrorOut) - { _SDCCERRG.out = NewErrorOut ; -return NewErrorOut ; + return NewErrorOut ; } -void -setErrorLogLevel (ERROR_LOG_LEVEL level) +void setErrorLogLevel (ERROR_LOG_LEVEL level) { _SDCCERRG.logLevel = level; } @@ -410,46 +478,46 @@ void vwerror (int errNum, va_list marker) _SDCCERRG.out = DEFAULT_ERROR_OUT; } - if (ErrTab[errNum].errIndex != errNum) - { + if (ErrTab[errNum].errIndex != errNum) { fprintf(_SDCCERRG.out, - "Internal error: error table entry for %d inconsistent.", errNum); + "Internal error: error table entry for %d inconsistent.", errNum); } - - if (ErrTab[errNum].errType >= _SDCCERRG.logLevel) { + if ((ErrTab[errNum].errType >= _SDCCERRG.logLevel) && (!_SDCCERRG.disabled[errNum])) { if ( ErrTab[errNum].errType == ERROR_LEVEL_ERROR ) fatalError++ ; if ( filename && lineno ) { - fprintf(_SDCCERRG.out, "%s:%d: ",filename,lineno); + if(_SDCCERRG.style) + fprintf(_SDCCERRG.out, "%s(%d) : ",filename,lineno); + else + fprintf(_SDCCERRG.out, "%s:%d: ",filename,lineno); } else if (lineno) { fprintf(_SDCCERRG.out, "at %d: ", lineno); } else { fprintf(_SDCCERRG.out, "-:0: "); } - + switch(ErrTab[errNum].errType) { case ERROR_LEVEL_ERROR: - fprintf(_SDCCERRG.out, "error: "); - break; + fprintf(_SDCCERRG.out, "error %d: ", errNum); + break; case ERROR_LEVEL_WARNING: case ERROR_LEVEL_PEDANTIC: - fprintf(_SDCCERRG.out, "warning: "); - break; + fprintf(_SDCCERRG.out, "warning %d: ", errNum); + break; case ERROR_LEVEL_INFO: - fprintf(_SDCCERRG.out, "info: "); - break; - default: - break; + fprintf(_SDCCERRG.out, "info %d: ", errNum); + break; + default: + break; } vfprintf(_SDCCERRG.out, ErrTab[errNum].errText,marker); fprintf(_SDCCERRG.out, "\n"); - } - else { - // Below the logging level, drop. + } else { + /* Below the logging level, drop. */ } } /* @@ -459,11 +527,75 @@ werror - Output a standard eror message with variable number of arguements ------------------------------------------------------------------------------- */ -void werror (int errNum, ... ) +void werror (int errNum, ...) +{ + va_list marker; + va_start(marker,errNum); + vwerror(errNum, marker); + va_end(marker); +} + +/* +------------------------------------------------------------------------------- +werrorfl - Output a standard eror message with variable number of arguements. + Use a specified filename and line number instead of the default. + +------------------------------------------------------------------------------- +*/ + +void werrorfl (char *newFilename, int newLineno, int errNum, ...) +{ + char *oldFilename = filename; + int oldLineno = lineno; + va_list marker; + + filename = newFilename; + lineno = newLineno; + + va_start(marker,errNum); + vwerror(errNum, marker); + va_end(marker); + + filename = oldFilename; + lineno = oldLineno; +} + + +/* +------------------------------------------------------------------------------- +fatal - Output a standard eror message with variable number of arguements and + call exit() +------------------------------------------------------------------------------- +*/ +void fatal (int exitCode, int errNum, ...) { - va_list marker; + va_list marker; va_start(marker,errNum); vwerror(errNum, marker); - va_end( marker ); + va_end(marker); + + exit(exitCode); } +/* +------------------------------------------------------------------------------- +style - Change the output error style to MSVC +------------------------------------------------------------------------------- +*/ + +void MSVC_style (int style) +{ + _SDCCERRG.style = style; +} + +/* +------------------------------------------------------------------------------- +disabled - Disable output of specified warning +------------------------------------------------------------------------------- +*/ + +void setWarningDisabled (int errNum) +{ + if ((errNum < MAX_ERROR_WARNING) && (ErrTab[errNum].errType <= ERROR_LEVEL_WARNING)) + _SDCCERRG.disabled[errNum] = 1; +}