Error handling cleanup/changes.
git-svn-id: svn://svn.cc65.org/cc65/trunk@369 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -3372,7 +3372,7 @@ void g_lt (unsigned flags, unsigned long val)
|
|||||||
|
|
||||||
/* Give a warning in some special cases */
|
/* Give a warning in some special cases */
|
||||||
if ((flags & CF_UNSIGNED) && val == 0) {
|
if ((flags & CF_UNSIGNED) && val == 0) {
|
||||||
Warning (WARN_COND_NEVER_TRUE);
|
Warning ("Condition is never true");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look at the type */
|
/* Look at the type */
|
||||||
@@ -3587,7 +3587,7 @@ void g_ge (unsigned flags, unsigned long val)
|
|||||||
|
|
||||||
/* Give a warning in some special cases */
|
/* Give a warning in some special cases */
|
||||||
if ((flags & CF_UNSIGNED) && val == 0) {
|
if ((flags & CF_UNSIGNED) && val == 0) {
|
||||||
Warning (WARN_COND_ALWAYS_TRUE);
|
Warning ("Condition is always true");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look at the type */
|
/* Look at the type */
|
||||||
|
|||||||
@@ -907,7 +907,7 @@ void CheckEmptyDecl (const DeclSpec* D)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
if ((D->Flags & DS_EXTRA_TYPE) == 0) {
|
if ((D->Flags & DS_EXTRA_TYPE) == 0) {
|
||||||
Warning (WARN_USELESS_DECL);
|
Warning ("Useless declaration");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
158
src/cc65/error.c
158
src/cc65/error.c
@@ -51,30 +51,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char* WarnMsg [WARN_COUNT-1] = {
|
|
||||||
"Unreachable code",
|
|
||||||
"Condition is never true",
|
|
||||||
"Condition is always true",
|
|
||||||
"Converting pointer to integer without a cast",
|
|
||||||
"Converting integer to pointer without a cast",
|
|
||||||
"Function call without a prototype",
|
|
||||||
"Unknown #pragma",
|
|
||||||
"No case labels",
|
|
||||||
"Function must be extern",
|
|
||||||
"Parameter `%s' is never used",
|
|
||||||
"`%s' is defined but never used",
|
|
||||||
"Constant is long",
|
|
||||||
"`/*' found inside a comment",
|
|
||||||
"Useless declaration",
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Error messages sorted by ErrTypes */
|
/* Error messages sorted by ErrTypes */
|
||||||
static char* ErrMsg [ERR_COUNT-1] = {
|
static char* ErrMsg [ERR_COUNT-1] = {
|
||||||
"Invalid character (%u)",
|
|
||||||
"Unexpected newline",
|
|
||||||
"End-of-file reached in comment starting at line %u",
|
|
||||||
"Syntax error",
|
"Syntax error",
|
||||||
"`\"' expected",
|
"`\"' expected",
|
||||||
"`:' expected",
|
"`:' expected",
|
||||||
@@ -92,23 +70,11 @@ static char* ErrMsg [ERR_COUNT-1] = {
|
|||||||
"Incompatible pointer types",
|
"Incompatible pointer types",
|
||||||
"Too many arguments in function call",
|
"Too many arguments in function call",
|
||||||
"Too few arguments in function call",
|
"Too few arguments in function call",
|
||||||
"Macro argument count mismatch",
|
|
||||||
"Duplicate macro parameter: %s",
|
"Duplicate macro parameter: %s",
|
||||||
"Macro redefinition is not identical",
|
|
||||||
"Variable identifier expected",
|
"Variable identifier expected",
|
||||||
"Integer expression expected",
|
"Integer expression expected",
|
||||||
"Constant expression expected",
|
"Constant expression expected",
|
||||||
"No active loop",
|
"No active loop",
|
||||||
"`\"' or `<' expected",
|
|
||||||
"Missing terminator or name too long",
|
|
||||||
"Include file `%s' not found",
|
|
||||||
"Cannot open include file `%s': %s",
|
|
||||||
"Invalid #error directive",
|
|
||||||
"#error: %s",
|
|
||||||
"Unexpected `#endif'",
|
|
||||||
"Unexpected `#else'",
|
|
||||||
"`#endif' expected",
|
|
||||||
"Compiler directive expected",
|
|
||||||
"Redefinition of `%s'",
|
"Redefinition of `%s'",
|
||||||
"Conflicting types for `%s'",
|
"Conflicting types for `%s'",
|
||||||
"String literal expected",
|
"String literal expected",
|
||||||
@@ -118,7 +84,6 @@ static char* ErrMsg [ERR_COUNT-1] = {
|
|||||||
"Unexpected `continue'",
|
"Unexpected `continue'",
|
||||||
"Undefined symbol: `%s'",
|
"Undefined symbol: `%s'",
|
||||||
"Undefined label: `%s'",
|
"Undefined label: `%s'",
|
||||||
"Include nesting too deep",
|
|
||||||
"Too many local variables",
|
"Too many local variables",
|
||||||
"Too many initializers",
|
"Too many initializers",
|
||||||
"Cannot initialize incomplete type",
|
"Cannot initialize incomplete type",
|
||||||
@@ -134,7 +99,6 @@ static char* ErrMsg [ERR_COUNT-1] = {
|
|||||||
"Illegal function call",
|
"Illegal function call",
|
||||||
"Illegal indirection",
|
"Illegal indirection",
|
||||||
"Illegal address",
|
"Illegal address",
|
||||||
"Illegal macro call",
|
|
||||||
"Illegal hex digit",
|
"Illegal hex digit",
|
||||||
"Illegal character constant",
|
"Illegal character constant",
|
||||||
"Illegal modifier",
|
"Illegal modifier",
|
||||||
@@ -162,20 +126,6 @@ static char* ErrMsg [ERR_COUNT-1] = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char* FatMsg [FAT_COUNT-1] = {
|
|
||||||
"Too many errors",
|
|
||||||
"Cannot open output file: %s",
|
|
||||||
"Cannot write to output file (disk full?)",
|
|
||||||
"Cannot open input file: %s",
|
|
||||||
"Out of memory",
|
|
||||||
"Stack overflow",
|
|
||||||
"Stack empty",
|
|
||||||
"Out of string space",
|
|
||||||
"Too many case labels",
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Count of errors/warnings */
|
/* Count of errors/warnings */
|
||||||
unsigned ErrorCount = 0;
|
unsigned ErrorCount = 0;
|
||||||
unsigned WarningCount = 0;
|
unsigned WarningCount = 0;
|
||||||
@@ -188,44 +138,59 @@ unsigned WarningCount = 0;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Warning (unsigned WarnNum, ...)
|
static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
|
||||||
/* Print warning message. */
|
/* Print warning message - internal function. */
|
||||||
{
|
{
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
if (!NoWarn) {
|
if (!NoWarn) {
|
||||||
fprintf (stderr, "%s(%u): Warning #%u: ",
|
fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
|
||||||
GetCurrentFile(), curpos, WarnNum);
|
vfprintf (stderr, Msg, ap);
|
||||||
|
|
||||||
va_start (ap, WarnNum);
|
|
||||||
vfprintf (stderr, WarnMsg [WarnNum-1], ap);
|
|
||||||
va_end (ap);
|
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
if (Verbose) {
|
if (Verbose) {
|
||||||
fprintf (stderr, "Line: %s\n", line);
|
fprintf (stderr, "Line: %s\n", line);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
++WarningCount;
|
++WarningCount;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PPWarning (unsigned WarnNum, ...)
|
void Warning (const char* Format, ...)
|
||||||
|
/* Print warning message. */
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, Format);
|
||||||
|
IntWarning (GetCurrentFile(), curpos, Format, ap);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void PPWarning (const char* Format, ...)
|
||||||
/* Print warning message. For use within the preprocessor. */
|
/* Print warning message. For use within the preprocessor. */
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
va_start (ap, Format);
|
||||||
if (!NoWarn) {
|
IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
|
||||||
fprintf (stderr, "%s(%u): Warning #%u: ",
|
|
||||||
GetCurrentFile(), GetCurrentLine(), WarnNum);
|
|
||||||
|
|
||||||
va_start (ap, WarnNum);
|
|
||||||
vfprintf (stderr, WarnMsg [WarnNum-1], ap);
|
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
fprintf (stderr, "\n");
|
|
||||||
}
|
}
|
||||||
++WarningCount;
|
|
||||||
|
|
||||||
|
|
||||||
|
static void IntError (const char* Filename, unsigned Line, const char* Msg, va_list ap)
|
||||||
|
/* Print an error message - internal function*/
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s(%u): Error: ", Filename, Line);
|
||||||
|
vfprintf (stderr, Msg, ap);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
if (Verbose) {
|
||||||
|
fprintf (stderr, "Line: %s\n", line);
|
||||||
|
}
|
||||||
|
++ErrorCount;
|
||||||
|
if (ErrorCount > 10) {
|
||||||
|
Fatal ("Too many errors");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -234,57 +199,44 @@ void Error (unsigned ErrNum, ...)
|
|||||||
/* Print an error message */
|
/* Print an error message */
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
fprintf (stderr, "%s(%u): Error #%u: ",
|
|
||||||
GetCurrentFile(), curpos, ErrNum);
|
|
||||||
|
|
||||||
va_start (ap, ErrNum);
|
va_start (ap, ErrNum);
|
||||||
vfprintf (stderr, ErrMsg [ErrNum-1], ap);
|
IntError (GetCurrentFile(), curpos, ErrMsg [ErrNum-1], ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
fprintf (stderr, "\n");
|
|
||||||
|
|
||||||
if (Verbose) {
|
|
||||||
fprintf (stderr, "Line: %s\n", line);
|
|
||||||
}
|
|
||||||
++ErrorCount;
|
|
||||||
if (ErrorCount > 10) {
|
|
||||||
Fatal (FAT_TOO_MANY_ERRORS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PPError (unsigned ErrNum, ...)
|
void MError (const char* Format, ...)
|
||||||
|
/* Print an error message */
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, Format);
|
||||||
|
IntError (GetCurrentFile(), curpos, Format, ap);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void PPError (const char* Format, ...)
|
||||||
/* Print an error message. For use within the preprocessor. */
|
/* Print an error message. For use within the preprocessor. */
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
va_start (ap, Format);
|
||||||
fprintf (stderr, "%s(%u): Error #%u: ",
|
IntError (GetCurrentFile(), GetCurrentLine(), Format, ap);
|
||||||
GetCurrentFile(), GetCurrentLine(), ErrNum);
|
|
||||||
|
|
||||||
va_start (ap, ErrNum);
|
|
||||||
vfprintf (stderr, ErrMsg [ErrNum-1], ap);
|
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
fprintf (stderr, "\n");
|
|
||||||
|
|
||||||
++ErrorCount;
|
|
||||||
if (ErrorCount > 10) {
|
|
||||||
Fatal (FAT_TOO_MANY_ERRORS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Fatal (unsigned FatNum, ...)
|
void Fatal (const char* Format, ...)
|
||||||
/* Print a message about a fatal error and die */
|
/* Print a message about a fatal error and die */
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
fprintf (stderr, "%s(%u): Fatal #%u: ",
|
fprintf (stderr, "%s(%u): Fatal: ", GetCurrentFile(), curpos);
|
||||||
GetCurrentFile(), curpos, FatNum);
|
|
||||||
|
|
||||||
va_start (ap, FatNum);
|
va_start (ap, Format);
|
||||||
vfprintf (stderr, FatMsg [FatNum-1], ap);
|
vfprintf (stderr, Format, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
|||||||
@@ -49,32 +49,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Warning numbers */
|
|
||||||
enum Warnings {
|
|
||||||
WARN_NONE, /* No warning */
|
|
||||||
WARN_UNREACHABLE_CODE,
|
|
||||||
WARN_COND_NEVER_TRUE,
|
|
||||||
WARN_COND_ALWAYS_TRUE,
|
|
||||||
WARN_PTR_TO_INT_CONV,
|
|
||||||
WARN_INT_TO_PTR_CONV,
|
|
||||||
WARN_FUNC_WITHOUT_PROTO,
|
|
||||||
WARN_UNKNOWN_PRAGMA,
|
|
||||||
WARN_NO_CASE_LABELS,
|
|
||||||
WARN_FUNC_MUST_BE_EXTERN,
|
|
||||||
WARN_UNUSED_PARM,
|
|
||||||
WARN_UNUSED_ITEM,
|
|
||||||
WARN_CONSTANT_IS_LONG,
|
|
||||||
WARN_NESTED_COMMENT,
|
|
||||||
WARN_USELESS_DECL,
|
|
||||||
WARN_COUNT /* Warning count */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Error numbers */
|
/* Error numbers */
|
||||||
enum Errors {
|
enum Errors {
|
||||||
ERR_NONE, /* No error */
|
ERR_NONE, /* No error */
|
||||||
ERR_INVALID_CHAR,
|
|
||||||
ERR_UNEXPECTED_NEWLINE,
|
|
||||||
ERR_EOF_IN_COMMENT,
|
|
||||||
ERR_SYNTAX,
|
ERR_SYNTAX,
|
||||||
ERR_QUOTE_EXPECTED,
|
ERR_QUOTE_EXPECTED,
|
||||||
ERR_COLON_EXPECTED,
|
ERR_COLON_EXPECTED,
|
||||||
@@ -92,23 +69,11 @@ enum Errors {
|
|||||||
ERR_INCOMPATIBLE_POINTERS,
|
ERR_INCOMPATIBLE_POINTERS,
|
||||||
ERR_TOO_MANY_FUNC_ARGS,
|
ERR_TOO_MANY_FUNC_ARGS,
|
||||||
ERR_TOO_FEW_FUNC_ARGS,
|
ERR_TOO_FEW_FUNC_ARGS,
|
||||||
ERR_MACRO_ARGCOUNT,
|
|
||||||
ERR_DUPLICATE_MACRO_ARG,
|
ERR_DUPLICATE_MACRO_ARG,
|
||||||
ERR_MACRO_REDEF,
|
|
||||||
ERR_VAR_IDENT_EXPECTED,
|
ERR_VAR_IDENT_EXPECTED,
|
||||||
ERR_INT_EXPR_EXPECTED,
|
ERR_INT_EXPR_EXPECTED,
|
||||||
ERR_CONST_EXPR_EXPECTED,
|
ERR_CONST_EXPR_EXPECTED,
|
||||||
ERR_NO_ACTIVE_LOOP,
|
ERR_NO_ACTIVE_LOOP,
|
||||||
ERR_INCLUDE_LTERM_EXPECTED,
|
|
||||||
ERR_INCLUDE_RTERM_EXPECTED,
|
|
||||||
ERR_INCLUDE_NOT_FOUND,
|
|
||||||
ERR_INCLUDE_OPEN_FAILURE,
|
|
||||||
ERR_INVALID_USER_ERROR,
|
|
||||||
ERR_USER_ERROR,
|
|
||||||
ERR_UNEXPECTED_CPP_ENDIF,
|
|
||||||
ERR_UNEXPECTED_CPP_ELSE,
|
|
||||||
ERR_CPP_ENDIF_EXPECTED,
|
|
||||||
ERR_CPP_DIRECTIVE_EXPECTED,
|
|
||||||
ERR_MULTIPLE_DEFINITION,
|
ERR_MULTIPLE_DEFINITION,
|
||||||
ERR_CONFLICTING_TYPES,
|
ERR_CONFLICTING_TYPES,
|
||||||
ERR_STRLIT_EXPECTED,
|
ERR_STRLIT_EXPECTED,
|
||||||
@@ -118,7 +83,6 @@ enum Errors {
|
|||||||
ERR_UNEXPECTED_CONTINUE,
|
ERR_UNEXPECTED_CONTINUE,
|
||||||
ERR_UNDEFINED_SYMBOL,
|
ERR_UNDEFINED_SYMBOL,
|
||||||
ERR_UNDEFINED_LABEL,
|
ERR_UNDEFINED_LABEL,
|
||||||
ERR_INCLUDE_NESTING,
|
|
||||||
ERR_TOO_MANY_LOCALS,
|
ERR_TOO_MANY_LOCALS,
|
||||||
ERR_TOO_MANY_INITIALIZERS,
|
ERR_TOO_MANY_INITIALIZERS,
|
||||||
ERR_INIT_INCOMPLETE_TYPE,
|
ERR_INIT_INCOMPLETE_TYPE,
|
||||||
@@ -134,7 +98,6 @@ enum Errors {
|
|||||||
ERR_ILLEGAL_FUNC_CALL,
|
ERR_ILLEGAL_FUNC_CALL,
|
||||||
ERR_ILLEGAL_INDIRECT,
|
ERR_ILLEGAL_INDIRECT,
|
||||||
ERR_ILLEGAL_ADDRESS,
|
ERR_ILLEGAL_ADDRESS,
|
||||||
ERR_ILLEGAL_MACRO_CALL,
|
|
||||||
ERR_ILLEGAL_HEX_DIGIT,
|
ERR_ILLEGAL_HEX_DIGIT,
|
||||||
ERR_ILLEGAL_CHARCONST,
|
ERR_ILLEGAL_CHARCONST,
|
||||||
ERR_ILLEGAL_MODIFIER,
|
ERR_ILLEGAL_MODIFIER,
|
||||||
@@ -161,23 +124,6 @@ enum Errors {
|
|||||||
ERR_COUNT /* Error count */
|
ERR_COUNT /* Error count */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Fatal errors */
|
|
||||||
enum Fatals {
|
|
||||||
FAT_NONE,
|
|
||||||
FAT_TOO_MANY_ERRORS,
|
|
||||||
FAT_CANNOT_OPEN_OUTPUT,
|
|
||||||
FAT_CANNOT_WRITE_OUTPUT,
|
|
||||||
FAT_CANNOT_OPEN_INPUT,
|
|
||||||
FAT_OUT_OF_MEMORY,
|
|
||||||
FAT_STACK_OVERFLOW,
|
|
||||||
FAT_STACK_EMPTY,
|
|
||||||
FAT_OUT_OF_STRSPACE,
|
|
||||||
FAT_TOO_MANY_CASE_LABELS,
|
|
||||||
FAT_COUNT /* Fatal error count */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Count of errors/warnings */
|
/* Count of errors/warnings */
|
||||||
extern unsigned ErrorCount;
|
extern unsigned ErrorCount;
|
||||||
extern unsigned WarningCount;
|
extern unsigned WarningCount;
|
||||||
@@ -190,22 +136,25 @@ extern unsigned WarningCount;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Warning (unsigned WarnNum, ...);
|
void Warning (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||||
/* Print warning message. */
|
/* Print warning message. */
|
||||||
|
|
||||||
void PPWarning (unsigned WarnNum, ...);
|
void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||||
/* Print warning message. For use within the preprocessor. */
|
/* Print warning message. For use within the preprocessor. */
|
||||||
|
|
||||||
void Error (unsigned ErrNum, ...);
|
void Error (unsigned ErrNum, ...);
|
||||||
/* Print an error message */
|
/* Print an error message */
|
||||||
|
|
||||||
void PPError (unsigned ErrNum, ...);
|
void MError (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||||
|
/* Print an error message */
|
||||||
|
|
||||||
|
void PPError (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||||
/* Print an error message. For use within the preprocessor. */
|
/* Print an error message. For use within the preprocessor. */
|
||||||
|
|
||||||
void Fatal (unsigned FatNum, ...);
|
void Fatal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2)));
|
||||||
/* Print a message about a fatal error and die */
|
/* Print a message about a fatal error and die */
|
||||||
|
|
||||||
void Internal (char* Format, ...) attribute ((noreturn));
|
void Internal (char* Format, ...) attribute ((noreturn, format (printf, 1, 2)));
|
||||||
/* Print a message about an internal compiler error and die. */
|
/* Print a message about an internal compiler error and die. */
|
||||||
|
|
||||||
void ErrorReport (void);
|
void ErrorReport (void);
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ unsigned assignadjust (type* lhst, struct expent* rhs)
|
|||||||
} else if (IsClassInt (lhst)) {
|
} else if (IsClassInt (lhst)) {
|
||||||
if (IsClassPtr (rhst)) {
|
if (IsClassPtr (rhst)) {
|
||||||
/* Pointer -> int conversion */
|
/* Pointer -> int conversion */
|
||||||
Warning (WARN_PTR_TO_INT_CONV);
|
Warning ("Converting pointer to integer without a cast");
|
||||||
} else if (!IsClassInt (rhst)) {
|
} else if (!IsClassInt (rhst)) {
|
||||||
Error (ERR_INCOMPATIBLE_TYPES);
|
Error (ERR_INCOMPATIBLE_TYPES);
|
||||||
} else {
|
} else {
|
||||||
@@ -253,7 +253,7 @@ unsigned assignadjust (type* lhst, struct expent* rhs)
|
|||||||
} else if (IsClassInt (rhst)) {
|
} else if (IsClassInt (rhst)) {
|
||||||
/* Int to pointer assignment is valid only for constant zero */
|
/* Int to pointer assignment is valid only for constant zero */
|
||||||
if ((rhs->e_flags & E_MCONST) == 0 || rhs->e_const != 0) {
|
if ((rhs->e_flags & E_MCONST) == 0 || rhs->e_const != 0) {
|
||||||
Warning (WARN_INT_TO_PTR_CONV);
|
Warning ("Converting integer to pointer without a cast");
|
||||||
}
|
}
|
||||||
} else if (IsTypeFuncPtr (lhst) && IsTypeFunc(rhst)) {
|
} else if (IsTypeFuncPtr (lhst) && IsTypeFunc(rhst)) {
|
||||||
/* Assignment of function to function pointer is allowed, provided
|
/* Assignment of function to function pointer is allowed, provided
|
||||||
@@ -815,7 +815,7 @@ static int primary (struct expent* lval)
|
|||||||
* function signature for a function having an empty param list
|
* function signature for a function having an empty param list
|
||||||
* and returning int.
|
* and returning int.
|
||||||
*/
|
*/
|
||||||
Warning (WARN_FUNC_WITHOUT_PROTO);
|
Warning ("Function call without a prototype");
|
||||||
Sym = AddGlobalSym (Ident, GetImplicitFuncType(), SC_EXTERN | SC_REF | SC_FUNC);
|
Sym = AddGlobalSym (Ident, GetImplicitFuncType(), SC_EXTERN | SC_REF | SC_FUNC);
|
||||||
lval->e_tptr = Sym->Type;
|
lval->e_tptr = Sym->Type;
|
||||||
lval->e_flags = E_MGLOBAL | E_MCONST | E_TGLAB;
|
lval->e_flags = E_MGLOBAL | E_MCONST | E_TGLAB;
|
||||||
@@ -3008,7 +3008,7 @@ void test (unsigned label, int cond)
|
|||||||
/* Constant rvalue */
|
/* Constant rvalue */
|
||||||
if (cond == 0 && lval.e_const == 0) {
|
if (cond == 0 && lval.e_const == 0) {
|
||||||
g_jump (label);
|
g_jump (label);
|
||||||
Warning (WARN_UNREACHABLE_CODE);
|
Warning ("Unreachable code");
|
||||||
} else if (cond && lval.e_const) {
|
} else if (cond && lval.e_const) {
|
||||||
g_jump (label);
|
g_jump (label);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ void OpenMainFile (const char* Name)
|
|||||||
FILE* F = fopen (Name, "r");
|
FILE* F = fopen (Name, "r");
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
/* Cannot open */
|
/* Cannot open */
|
||||||
Fatal (FAT_CANNOT_OPEN_INPUT, strerror (errno));
|
Fatal ("Cannot open input file `%s': %s", Name, strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate a new AFile structure for the file */
|
/* Allocate a new AFile structure for the file */
|
||||||
@@ -216,14 +216,14 @@ void OpenIncludeFile (const char* Name, unsigned DirSpec)
|
|||||||
|
|
||||||
/* Check for the maximum include nesting */
|
/* Check for the maximum include nesting */
|
||||||
if (CollCount (&AFiles) > MAX_INC_NESTING) {
|
if (CollCount (&AFiles) > MAX_INC_NESTING) {
|
||||||
PPError (ERR_INCLUDE_NESTING);
|
PPError ("Include nesting too deep");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for the file */
|
/* Search for the file */
|
||||||
N = FindInclude (Name, DirSpec);
|
N = FindInclude (Name, DirSpec);
|
||||||
if (N == 0) {
|
if (N == 0) {
|
||||||
PPError (ERR_INCLUDE_NOT_FOUND, Name);
|
PPError ("Include file `%s' not found", Name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ void OpenIncludeFile (const char* Name, unsigned DirSpec)
|
|||||||
F = fopen (IF->Name, "r");
|
F = fopen (IF->Name, "r");
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
/* Error opening the file */
|
/* Error opening the file */
|
||||||
PPError (ERR_INCLUDE_OPEN_FAILURE, IF->Name, strerror (errno));
|
PPError ("Cannot open include file `%s': %s", IF->Name, strerror (errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ void AddLiteralChar (char C)
|
|||||||
/* Add one character to the literal pool */
|
/* Add one character to the literal pool */
|
||||||
{
|
{
|
||||||
if (LiteralOffs >= LITPOOL_SIZE) {
|
if (LiteralOffs >= LITPOOL_SIZE) {
|
||||||
Fatal (FAT_OUT_OF_STRSPACE);
|
Fatal ("Out of literal space");
|
||||||
}
|
}
|
||||||
LiteralPool[LiteralOffs++] = C;
|
LiteralPool[LiteralOffs++] = C;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
|||||||
if (IsTypeFunc (Decl.Type)) {
|
if (IsTypeFunc (Decl.Type)) {
|
||||||
/* Function prototypes are always external */
|
/* Function prototypes are always external */
|
||||||
if ((SC & SC_EXTERN) == 0) {
|
if ((SC & SC_EXTERN) == 0) {
|
||||||
Warning (WARN_FUNC_MUST_BE_EXTERN);
|
Warning ("Function must be extern");
|
||||||
}
|
}
|
||||||
SC |= SC_FUNC | SC_EXTERN;
|
SC |= SC_FUNC | SC_EXTERN;
|
||||||
|
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ static void DoCreateDep (const char* OutputName)
|
|||||||
/* Open the file */
|
/* Open the file */
|
||||||
FILE* F = fopen (DepName, "w");
|
FILE* F = fopen (DepName, "w");
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
Fatal (FAT_CANNOT_OPEN_OUTPUT, strerror (errno));
|
Fatal ("Cannot open dependency file `%s': %s", DepName, strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the dependencies to the file */
|
/* Write the dependencies to the file */
|
||||||
@@ -200,7 +200,7 @@ static void DoCreateDep (const char* OutputName)
|
|||||||
/* Close the file, check for errors */
|
/* Close the file, check for errors */
|
||||||
if (fclose (F) != 0) {
|
if (fclose (F) != 0) {
|
||||||
remove (DepName);
|
remove (DepName);
|
||||||
Fatal (FAT_CANNOT_WRITE_OUTPUT);
|
Fatal ("Cannot write to dependeny file (disk full?)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the name */
|
/* Free the name */
|
||||||
@@ -615,7 +615,7 @@ int main (int argc, char* argv[])
|
|||||||
/* Open the file */
|
/* Open the file */
|
||||||
F = fopen (OutputFile, "w");
|
F = fopen (OutputFile, "w");
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
Fatal (FAT_CANNOT_OPEN_OUTPUT, strerror (errno));
|
Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the output to the file */
|
/* Write the output to the file */
|
||||||
@@ -624,7 +624,7 @@ int main (int argc, char* argv[])
|
|||||||
/* Close the file, check for errors */
|
/* Close the file, check for errors */
|
||||||
if (fclose (F) != 0) {
|
if (fclose (F) != 0) {
|
||||||
remove (OutputFile);
|
remove (OutputFile);
|
||||||
Fatal (FAT_CANNOT_WRITE_OUTPUT);
|
Fatal ("Cannot write to output file (disk full?)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create dependencies if requested */
|
/* Create dependencies if requested */
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ void DoPragma (void)
|
|||||||
* for unknown pragmas, however, we're allowed to warn - and we will
|
* for unknown pragmas, however, we're allowed to warn - and we will
|
||||||
* do so. Otherwise one typo may give you hours of bug hunting...
|
* do so. Otherwise one typo may give you hours of bug hunting...
|
||||||
*/
|
*/
|
||||||
Warning (WARN_UNKNOWN_PRAGMA);
|
Warning ("Unknown #pragma `%s'", CurTok.Ident);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,12 +98,13 @@ static void Comment (void)
|
|||||||
while (CurC != '*' || NextC != '/') {
|
while (CurC != '*' || NextC != '/') {
|
||||||
if (CurC == '\0') {
|
if (CurC == '\0') {
|
||||||
if (NextLine () == 0) {
|
if (NextLine () == 0) {
|
||||||
PPError (ERR_EOF_IN_COMMENT, StartingLine);
|
PPError ("End-of-file reached in comment starting at line %u",
|
||||||
|
StartingLine);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (CurC == '/' && NextC == '*') {
|
if (CurC == '/' && NextC == '*') {
|
||||||
PPWarning (WARN_NESTED_COMMENT);
|
PPWarning ("`/*' found inside a comment");
|
||||||
}
|
}
|
||||||
NextChar ();
|
NextChar ();
|
||||||
}
|
}
|
||||||
@@ -170,7 +171,7 @@ static int MacName (char* Ident)
|
|||||||
/* Get macro symbol name. If error, print message and clear line. */
|
/* Get macro symbol name. If error, print message and clear line. */
|
||||||
{
|
{
|
||||||
if (IsSym (Ident) == 0) {
|
if (IsSym (Ident) == 0) {
|
||||||
PPError (ERR_IDENT_EXPECTED);
|
PPError ("Identifier expected");
|
||||||
ClearLine ();
|
ClearLine ();
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -242,7 +243,7 @@ static int MacroCall (Macro* M)
|
|||||||
/* Expect an argument list */
|
/* Expect an argument list */
|
||||||
SkipBlank ();
|
SkipBlank ();
|
||||||
if (CurC != '(') {
|
if (CurC != '(') {
|
||||||
PPError (ERR_ILLEGAL_MACRO_CALL);
|
PPError ("Illegal macro call");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +316,7 @@ static int MacroCall (Macro* M)
|
|||||||
|
|
||||||
/* Compare formal argument count with actual */
|
/* Compare formal argument count with actual */
|
||||||
if (M->ArgCount != ArgCount) {
|
if (M->ArgCount != ArgCount) {
|
||||||
PPError (ERR_MACRO_ARGCOUNT);
|
PPError ("Macro argument count mismatch");
|
||||||
/* Be sure to make enough empty arguments available */
|
/* Be sure to make enough empty arguments available */
|
||||||
while (ArgCount < M->ArgCount) {
|
while (ArgCount < M->ArgCount) {
|
||||||
M->ActualArgs [ArgCount++] = "";
|
M->ActualArgs [ArgCount++] = "";
|
||||||
@@ -395,7 +396,7 @@ static void addmac (void)
|
|||||||
|
|
||||||
/* Check for a right paren and eat it if we find one */
|
/* Check for a right paren and eat it if we find one */
|
||||||
if (CurC != ')') {
|
if (CurC != ')') {
|
||||||
PPError (ERR_RPAREN_EXPECTED);
|
PPError ("`)' expected");
|
||||||
ClearLine ();
|
ClearLine ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -421,7 +422,7 @@ static void addmac (void)
|
|||||||
*/
|
*/
|
||||||
if (Existing) {
|
if (Existing) {
|
||||||
if (MacroCmp (M, Existing) != 0) {
|
if (MacroCmp (M, Existing) != 0) {
|
||||||
PPError (ERR_MACRO_REDEF);
|
PPError ("Macro redefinition is not identical");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -465,7 +466,7 @@ static int Pass1 (const char* From, char* To)
|
|||||||
SkipBlank();
|
SkipBlank();
|
||||||
}
|
}
|
||||||
if (!IsIdent (CurC)) {
|
if (!IsIdent (CurC)) {
|
||||||
PPError (ERR_IDENT_EXPECTED);
|
PPError ("Identifier expected");
|
||||||
*mptr++ = '0';
|
*mptr++ = '0';
|
||||||
} else {
|
} else {
|
||||||
SymName (Ident);
|
SymName (Ident);
|
||||||
@@ -473,7 +474,7 @@ static int Pass1 (const char* From, char* To)
|
|||||||
if (HaveParen) {
|
if (HaveParen) {
|
||||||
SkipBlank();
|
SkipBlank();
|
||||||
if (CurC != ')') {
|
if (CurC != ')') {
|
||||||
PPError (ERR_RPAREN_EXPECTED);
|
PPError ("`)' expected");
|
||||||
} else {
|
} else {
|
||||||
NextChar ();
|
NextChar ();
|
||||||
}
|
}
|
||||||
@@ -701,7 +702,7 @@ static void doinclude (void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
PPError (ERR_INCLUDE_LTERM_EXPECTED);
|
PPError ("`\"' or `<' expected");
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
NextChar ();
|
NextChar ();
|
||||||
@@ -719,7 +720,7 @@ static void doinclude (void)
|
|||||||
/* Check if we got a terminator */
|
/* Check if we got a terminator */
|
||||||
if (CurC != RTerm) {
|
if (CurC != RTerm) {
|
||||||
/* No terminator found */
|
/* No terminator found */
|
||||||
PPError (ERR_INCLUDE_RTERM_EXPECTED);
|
PPError ("Missing terminator or file name too long");
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -740,9 +741,9 @@ static void doerror (void)
|
|||||||
{
|
{
|
||||||
SkipBlank ();
|
SkipBlank ();
|
||||||
if (CurC == '\0') {
|
if (CurC == '\0') {
|
||||||
PPError (ERR_INVALID_USER_ERROR);
|
PPError ("Invalid #error directive");
|
||||||
} else {
|
} else {
|
||||||
PPError (ERR_USER_ERROR, lptr);
|
PPError ("#error: %s", lptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear rest of line */
|
/* clear rest of line */
|
||||||
@@ -818,7 +819,7 @@ void Preprocess (void)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!IsSym (Directive)) {
|
if (!IsSym (Directive)) {
|
||||||
PPError (ERR_CPP_DIRECTIVE_EXPECTED);
|
PPError ("Preprocessor directive expected");
|
||||||
ClearLine ();
|
ClearLine ();
|
||||||
} else {
|
} else {
|
||||||
switch (searchtok (Directive, pre_toks)) {
|
switch (searchtok (Directive, pre_toks)) {
|
||||||
@@ -836,7 +837,7 @@ void Preprocess (void)
|
|||||||
}
|
}
|
||||||
s_ifdef[i_ifdef] ^= 2;
|
s_ifdef[i_ifdef] ^= 2;
|
||||||
} else {
|
} else {
|
||||||
PPError (ERR_UNEXPECTED_CPP_ELSE);
|
PPError ("Unexpected `#else'");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -844,7 +845,7 @@ void Preprocess (void)
|
|||||||
if (i_ifdef >= 0) {
|
if (i_ifdef >= 0) {
|
||||||
Skip = s_ifdef[i_ifdef--] & 1;
|
Skip = s_ifdef[i_ifdef--] & 1;
|
||||||
} else {
|
} else {
|
||||||
PPError (ERR_UNEXPECTED_CPP_ENDIF);
|
PPError ("Unexpected `#endif'");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -875,7 +876,7 @@ void Preprocess (void)
|
|||||||
case PP_LINE:
|
case PP_LINE:
|
||||||
/* Not allowed in strict ANSI mode */
|
/* Not allowed in strict ANSI mode */
|
||||||
if (ANSI) {
|
if (ANSI) {
|
||||||
PPError (ERR_CPP_DIRECTIVE_EXPECTED);
|
PPError ("Preprocessor directive expected");
|
||||||
ClearLine ();
|
ClearLine ();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -896,7 +897,7 @@ void Preprocess (void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
PPError (ERR_CPP_DIRECTIVE_EXPECTED);
|
PPError ("Preprocessor directive expected");
|
||||||
ClearLine ();
|
ClearLine ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -904,7 +905,7 @@ void Preprocess (void)
|
|||||||
}
|
}
|
||||||
if (NextLine () == 0) {
|
if (NextLine () == 0) {
|
||||||
if (i_ifdef >= 0) {
|
if (i_ifdef >= 0) {
|
||||||
PPError (ERR_CPP_ENDIF_EXPECTED);
|
PPError ("`#endif' expected");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ int IsSym (char *s)
|
|||||||
static void unknown (char C)
|
static void unknown (char C)
|
||||||
/* Error message for unknown character */
|
/* Error message for unknown character */
|
||||||
{
|
{
|
||||||
Error (ERR_INVALID_CHAR, C);
|
MError ("Invalid input character with code %02X", C & 0xFF);
|
||||||
NextChar (); /* Skip */
|
NextChar (); /* Skip */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +350,7 @@ static void StringConst (void)
|
|||||||
|
|
||||||
while (CurC != '\"') {
|
while (CurC != '\"') {
|
||||||
if (CurC == '\0') {
|
if (CurC == '\0') {
|
||||||
Error (ERR_UNEXPECTED_NEWLINE);
|
MError ("Unexpected newline");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
AddLiteralChar (ParseChar ());
|
AddLiteralChar (ParseChar ());
|
||||||
@@ -458,7 +458,7 @@ void NextToken (void)
|
|||||||
* warning.
|
* warning.
|
||||||
*/
|
*/
|
||||||
if (k <= 0xFFFF && (types & IT_UINT) == 0 && !HaveSuffix) {
|
if (k <= 0xFFFF && (types & IT_UINT) == 0 && !HaveSuffix) {
|
||||||
Warning (WARN_CONSTANT_IS_LONG);
|
Warning ("Constant is long");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (k > 0xFFFF) {
|
if (k > 0xFFFF) {
|
||||||
@@ -754,7 +754,7 @@ void NextToken (void)
|
|||||||
} while (CurC == ' ');
|
} while (CurC == ' ');
|
||||||
if (!IsSym (token) || strcmp (token, "pragma") != 0) {
|
if (!IsSym (token) || strcmp (token, "pragma") != 0) {
|
||||||
/* OOPS - should not happen */
|
/* OOPS - should not happen */
|
||||||
Error (ERR_CPP_DIRECTIVE_EXPECTED);
|
MError ("Preprocessor directive expected");
|
||||||
}
|
}
|
||||||
nxttok = TOK_PRAGMA;
|
nxttok = TOK_PRAGMA;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ static void cascadeswitch (struct expent* eval)
|
|||||||
|
|
||||||
/* Check if we have any labels */
|
/* Check if we have any labels */
|
||||||
if (lcount == 0) {
|
if (lcount == 0) {
|
||||||
Warning (WARN_NO_CASE_LABELS);
|
Warning ("No case labels");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Eat the closing curly brace */
|
/* Eat the closing curly brace */
|
||||||
@@ -451,7 +451,7 @@ static void tableswitch (struct expent* eval)
|
|||||||
while (curtok != TOK_RCURLY) {
|
while (curtok != TOK_RCURLY) {
|
||||||
if (curtok == TOK_CASE || curtok == TOK_DEFAULT) {
|
if (curtok == TOK_CASE || curtok == TOK_DEFAULT) {
|
||||||
if (lcount >= CASE_MAX) {
|
if (lcount >= CASE_MAX) {
|
||||||
Fatal (FAT_TOO_MANY_CASE_LABELS);
|
Fatal ("Too many case labels");
|
||||||
}
|
}
|
||||||
label = GetLabel ();
|
label = GetLabel ();
|
||||||
do {
|
do {
|
||||||
@@ -481,7 +481,7 @@ static void tableswitch (struct expent* eval)
|
|||||||
|
|
||||||
/* Check if we have any labels */
|
/* Check if we have any labels */
|
||||||
if (lcount == 0) {
|
if (lcount == 0) {
|
||||||
Warning (WARN_NO_CASE_LABELS);
|
Warning ("No case labels");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Eat the closing curly brace */
|
/* Eat the closing curly brace */
|
||||||
|
|||||||
@@ -165,9 +165,9 @@ static void CheckSymTable (SymTable* Tab)
|
|||||||
if (((Flags & SC_AUTO) || (Flags & SC_STATIC)) && (Flags & SC_EXTERN) == 0) {
|
if (((Flags & SC_AUTO) || (Flags & SC_STATIC)) && (Flags & SC_EXTERN) == 0) {
|
||||||
if ((Flags & SC_DEF) && !(Flags & SC_REF)) {
|
if ((Flags & SC_DEF) && !(Flags & SC_REF)) {
|
||||||
if (Flags & SC_PARAM) {
|
if (Flags & SC_PARAM) {
|
||||||
Warning (WARN_UNUSED_PARM, Entry->Name);
|
Warning ("Parameter `%s' is never used", Entry->Name);
|
||||||
} else {
|
} else {
|
||||||
Warning (WARN_UNUSED_ITEM, Entry->Name);
|
Warning ("`%s' is defined but never used", Entry->Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ static void CheckSymTable (SymTable* Tab)
|
|||||||
Error (ERR_UNDEFINED_LABEL, Entry->Name);
|
Error (ERR_UNDEFINED_LABEL, Entry->Name);
|
||||||
} else if ((Flags & SC_REF) == 0) {
|
} else if ((Flags & SC_REF) == 0) {
|
||||||
/* Defined but not used */
|
/* Defined but not used */
|
||||||
Warning (WARN_UNUSED_ITEM, Entry->Name);
|
Warning ("`%s' is defined but never used", Entry->Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user