Removed error numbers in favour of literal error messages. The error numbers

were harder to manage, made the code harder to read, and lead no less
verbose messages, since it was effort to add a new message. The new approach
has the drawback that it's more difficult to translate, but this won't
happen anyway.


git-svn-id: svn://svn.cc65.org/cc65/trunk@428 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-11-02 21:22:33 +00:00
parent 7bb82698d1
commit d341e0ad76
18 changed files with 311 additions and 402 deletions

View File

@@ -94,7 +94,7 @@ static void CheckLocalOffs (unsigned Offs)
if (Offs >= 256) { if (Offs >= 256) {
/* Too many local vars */ /* Too many local vars */
AddCodeLine (";*** Too many locals"); AddCodeLine (";*** Too many locals");
Error (ERR_TOO_MANY_LOCALS); Error ("Too many local variables");
} }
} }

View File

@@ -99,7 +99,7 @@ static void Parse (void)
/* Don't accept illegal storage classes */ /* Don't accept illegal storage classes */
if (Spec.StorageClass == SC_AUTO || Spec.StorageClass == SC_REGISTER) { if (Spec.StorageClass == SC_AUTO || Spec.StorageClass == SC_REGISTER) {
Error (ERR_ILLEGAL_STORAGE_CLASS); Error ("Illegal storage class");
Spec.StorageClass = SC_EXTERN | SC_STATIC; Spec.StorageClass = SC_EXTERN | SC_STATIC;
} }
@@ -164,11 +164,11 @@ static void Parse (void)
if (!IsTypeVoid (Decl.Type)) { if (!IsTypeVoid (Decl.Type)) {
if (!IsTypeArray (Decl.Type)) { if (!IsTypeArray (Decl.Type)) {
/* Size is unknown and not an array */ /* Size is unknown and not an array */
Error (ERR_UNKNOWN_SIZE); Error ("Variable `%s' has unknown size", Decl.Ident);
} }
} else if (ANSI) { } else if (ANSI) {
/* We cannot declare variables of type void */ /* We cannot declare variables of type void */
Error (ERR_ILLEGAL_TYPE); Error ("Illegal type for variable `%s'", Decl.Ident);
} }
} }
@@ -191,10 +191,10 @@ static void Parse (void)
if (IsTypeVoid (Decl.Type)) { if (IsTypeVoid (Decl.Type)) {
/* We cannot declare variables of type void */ /* We cannot declare variables of type void */
Error (ERR_ILLEGAL_TYPE); Error ("Illegal type for variable `%s'", Decl.Ident);
} else if (Size == 0) { } else if (Size == 0) {
/* Size is unknown */ /* Size is unknown */
Error (ERR_UNKNOWN_SIZE); Error ("Variable `%s' has unknown size", Decl.Ident);
} }
/* Switch to the BSS segment */ /* Switch to the BSS segment */

View File

@@ -382,7 +382,7 @@ unsigned SizeOf (const type* T)
switch (UnqualifiedType (T[0])) { switch (UnqualifiedType (T[0])) {
case T_VOID: case T_VOID:
Error (ERR_ILLEGAL_SIZE); Error ("Variable has unknown size");
return 1; /* Return something that makes sense */ return 1; /* Return something that makes sense */
case T_SCHAR: case T_SCHAR:
@@ -484,7 +484,7 @@ unsigned TypeOf (const type* T)
return CF_INT | CF_UNSIGNED; return CF_INT | CF_UNSIGNED;
default: default:
Error (ERR_ILLEGAL_TYPE); Error ("Illegal type");
return CF_INT; return CF_INT;
} }
} }

View File

@@ -58,14 +58,14 @@ static type OptionalQualifiers (type Q)
case TOK_CONST: case TOK_CONST:
if (Q & T_QUAL_CONST) { if (Q & T_QUAL_CONST) {
Error (ERR_DUPLICATE_QUALIFIER, "const"); Error ("Duplicate qualifier: `const'");
} }
Q |= T_QUAL_CONST; Q |= T_QUAL_CONST;
break; break;
case TOK_VOLATILE: case TOK_VOLATILE:
if (Q & T_QUAL_VOLATILE) { if (Q & T_QUAL_VOLATILE) {
Error (ERR_DUPLICATE_QUALIFIER, "volatile"); Error ("Duplicate qualifier: `volatile'");
} }
Q |= T_QUAL_VOLATILE; Q |= T_QUAL_VOLATILE;
break; break;
@@ -192,7 +192,7 @@ static void ParseEnumDecl (void)
/* We expect an identifier */ /* We expect an identifier */
if (curtok != TOK_IDENT) { if (curtok != TOK_IDENT) {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
continue; continue;
} }
@@ -241,7 +241,7 @@ static SymEntry* ParseStructDecl (const char* Name, type StructType)
Entry = AddStructSym (Name, 0, 0); Entry = AddStructSym (Name, 0, 0);
} else if (SymIsLocal (Entry) && (Entry->Flags & SC_STRUCT) == 0) { } else if (SymIsLocal (Entry) && (Entry->Flags & SC_STRUCT) == 0) {
/* Already defined in the level but no struct */ /* Already defined in the level but no struct */
Error (ERR_SYMBOL_KIND); Error ("Symbol `%s' is already different kind", Name);
} }
return Entry; return Entry;
} }
@@ -469,7 +469,7 @@ static void ParseTypeSpec (DeclSpec* D, int Default)
Entry = FindTagSym (CurTok.Ident); Entry = FindTagSym (CurTok.Ident);
if (Entry) { if (Entry) {
if (SymIsLocal (Entry) && (Entry->Flags & SC_ENUM) == 0) { if (SymIsLocal (Entry) && (Entry->Flags & SC_ENUM) == 0) {
Error (ERR_SYMBOL_KIND); Error ("Symbol `%s' is already different kind", Entry->Name);
} }
} else { } else {
/* Insert entry into table ### */ /* Insert entry into table ### */
@@ -477,7 +477,7 @@ static void ParseTypeSpec (DeclSpec* D, int Default)
/* Skip the identifier */ /* Skip the identifier */
NextToken (); NextToken ();
} else { } else {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
} }
} }
/* Remember we have an extra type decl */ /* Remember we have an extra type decl */
@@ -500,7 +500,7 @@ static void ParseTypeSpec (DeclSpec* D, int Default)
default: default:
if (Default < 0) { if (Default < 0) {
Error (ERR_TYPE_EXPECTED); Error ("Type expected");
D->Type[0] = T_INT; D->Type[0] = T_INT;
D->Type[1] = T_END; D->Type[1] = T_END;
} else { } else {
@@ -539,7 +539,7 @@ static void ParseOldStyleParamList (FuncDesc* F)
/* List of identifiers expected */ /* List of identifiers expected */
if (curtok != TOK_IDENT) { if (curtok != TOK_IDENT) {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
} }
/* Create a symbol table entry with type int */ /* Create a symbol table entry with type int */
@@ -567,7 +567,7 @@ static void ParseOldStyleParamList (FuncDesc* F)
/* An optional list of type specifications follows */ /* An optional list of type specifications follows */
while (curtok != TOK_LCURLY) { while (curtok != TOK_LCURLY) {
DeclSpec Spec; DeclSpec Spec;
/* Read the declaration specifier */ /* Read the declaration specifier */
ParseDeclSpec (&Spec, SC_AUTO, T_INT); ParseDeclSpec (&Spec, SC_AUTO, T_INT);
@@ -577,7 +577,7 @@ static void ParseOldStyleParamList (FuncDesc* F)
*/ */
if ((Spec.StorageClass & SC_AUTO) == 0 && if ((Spec.StorageClass & SC_AUTO) == 0 &&
(Spec.StorageClass & SC_REGISTER) == 0) { (Spec.StorageClass & SC_REGISTER) == 0) {
Error (ERR_ILLEGAL_STORAGE_CLASS); Error ("Illegal storage class");
} }
/* Parse a comma separated variable list */ /* Parse a comma separated variable list */
@@ -595,7 +595,7 @@ static void ParseOldStyleParamList (FuncDesc* F)
/* Found it, change the default type to the one given */ /* Found it, change the default type to the one given */
ChangeSymType (Sym, ParamTypeCvt (Decl.Type)); ChangeSymType (Sym, ParamTypeCvt (Decl.Type));
} else { } else {
Error (ERR_UNKNOWN_IDENT, Decl.Ident); Error ("Unknown identifier: `%s'", Decl.Ident);
} }
} }
@@ -639,7 +639,7 @@ static void ParseAnsiParamList (FuncDesc* F)
*/ */
if ((Spec.StorageClass & SC_AUTO) == 0 && if ((Spec.StorageClass & SC_AUTO) == 0 &&
(Spec.StorageClass & SC_REGISTER) == 0) { (Spec.StorageClass & SC_REGISTER) == 0) {
Error (ERR_ILLEGAL_STORAGE_CLASS); Error ("Illegal storage class");
} }
Spec.StorageClass = SC_AUTO | SC_PARAM | SC_DEF; Spec.StorageClass = SC_AUTO | SC_PARAM | SC_DEF;
@@ -687,7 +687,7 @@ static void ParseAnsiParamList (FuncDesc* F)
* parameters. * parameters.
*/ */
if (ANSI && (F->Flags & FD_UNNAMED_PARAMS) != 0) { if (ANSI && (F->Flags & FD_UNNAMED_PARAMS) != 0) {
Error (ERR_MISSING_PARAM_NAME); Error ("Parameter name omitted");
} }
} }
} }
@@ -775,7 +775,7 @@ static void Decl (Declaration* D, unsigned Mode)
Decl (D, Mode); Decl (D, Mode);
/* Set the fastcall flag */ /* Set the fastcall flag */
if (!IsTypeFunc (T)) { if (!IsTypeFunc (T)) {
Error (ERR_ILLEGAL_MODIFIER); Error ("__fastcall__ modifier applied to non function");
} else { } else {
FuncDesc* F = DecodePtr (T+1); FuncDesc* F = DecodePtr (T+1);
F->Flags |= FD_FASTCALL; F->Flags |= FD_FASTCALL;
@@ -799,7 +799,7 @@ static void Decl (Declaration* D, unsigned Mode)
NextToken (); NextToken ();
} else { } else {
if (Mode == DM_NEED_IDENT) { if (Mode == DM_NEED_IDENT) {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
} }
D->Ident[0] = '\0'; D->Ident[0] = '\0';
return; return;
@@ -879,7 +879,11 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
/* Check the size of the generated type */ /* Check the size of the generated type */
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type) && SizeOf (D->Type) >= 0x10000) { if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type) && SizeOf (D->Type) >= 0x10000) {
Error (ERR_ILLEGAL_SIZE); if (D->Ident[0] != '\0') {
Error ("Size of `%s' is invalid", D->Ident);
} else {
Error ("Invalid size");
}
} }
} }
@@ -952,7 +956,7 @@ static void ParseVoidInit (void)
break; break;
default: default:
Error (ERR_ILLEGAL_TYPE); Error ("Illegal type in initialization");
break; break;
} }
@@ -986,7 +990,7 @@ static void ParseStructInit (type* Type)
*/ */
Tab = Entry->V.S.SymTab; Tab = Entry->V.S.SymTab;
if (Tab == 0) { if (Tab == 0) {
Error (ERR_INIT_INCOMPLETE_TYPE); Error ("Cannot initialize variables with incomplete type");
/* Returning here will cause lots of errors, but recovery is difficult */ /* Returning here will cause lots of errors, but recovery is difficult */
return; return;
} }
@@ -995,7 +999,7 @@ static void ParseStructInit (type* Type)
Entry = Tab->SymHead; Entry = Tab->SymHead;
while (curtok != TOK_RCURLY) { while (curtok != TOK_RCURLY) {
if (Entry == 0) { if (Entry == 0) {
Error (ERR_TOO_MANY_INITIALIZERS); Error ("Too many initializers");
return; return;
} }
ParseInit (Entry->Type); ParseInit (Entry->Type);
@@ -1091,7 +1095,7 @@ void ParseInit (type* T)
} else if (count < sz) { } else if (count < sz) {
g_zerobytes ((sz - count) * SizeOf (T + DECODE_SIZE + 1)); g_zerobytes ((sz - count) * SizeOf (T + DECODE_SIZE + 1));
} else if (count > sz) { } else if (count > sz) {
Error (ERR_TOO_MANY_INITIALIZERS); Error ("Too many initializers");
} }
break; break;
@@ -1109,7 +1113,7 @@ void ParseInit (type* T)
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
Error (ERR_ILLEGAL_TYPE); Error ("Illegal type");
break; break;
} }

View File

@@ -92,14 +92,14 @@ static void AliasAttrib (const Declaration* D, DeclAttr* A)
/* The next identifier is the name of the alias symbol */ /* The next identifier is the name of the alias symbol */
if (CurTok.Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
return; return;
} }
/* Lookup the symbol for this name, it must exist */ /* Lookup the symbol for this name, it must exist */
Sym = FindSym (CurTok.Ident); Sym = FindSym (CurTok.Ident);
if (Sym == 0) { if (Sym == 0) {
Error (ERR_UNKNOWN_IDENT, CurTok.Ident); Error ("Unknown identifier: `%s'", CurTok.Ident);
NextToken (); NextToken ();
return; return;
} }
@@ -110,7 +110,7 @@ static void AliasAttrib (const Declaration* D, DeclAttr* A)
/* Check if the types of the symbols are identical */ /* Check if the types of the symbols are identical */
if (TypeCmp (D->Type, Sym->Type) < TC_EQUAL) { if (TypeCmp (D->Type, Sym->Type) < TC_EQUAL) {
/* Types are not identical */ /* Types are not identical */
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
return; return;
} }
@@ -124,6 +124,7 @@ static void AliasAttrib (const Declaration* D, DeclAttr* A)
void ParseAttribute (const Declaration* D, DeclAttr* A) void ParseAttribute (const Declaration* D, DeclAttr* A)
/* Parse an additional __attribute__ modifier */ /* Parse an additional __attribute__ modifier */
{ {
ident AttrName;
attrib_t AttrType; attrib_t AttrType;
/* Initialize the attribute description with "no attribute" */ /* Initialize the attribute description with "no attribute" */
@@ -144,13 +145,14 @@ void ParseAttribute (const Declaration* D, DeclAttr* A)
/* Identifier follows */ /* Identifier follows */
if (CurTok.Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
/* We should *really* try to recover here, but for now: */ /* We should *really* try to recover here, but for now: */
return; return;
} }
/* Map the attribute name to its id, then skip the identifier */ /* Map the attribute name to its id, then skip the identifier */
AttrType = FindAttribute (CurTok.Ident); strcpy (AttrName, CurTok.Ident);
AttrType = FindAttribute (AttrName);
NextToken (); NextToken ();
/* Handle possible attributes */ /* Handle possible attributes */
@@ -162,7 +164,7 @@ void ParseAttribute (const Declaration* D, DeclAttr* A)
default: default:
/* Attribute not known, maybe typo */ /* Attribute not known, maybe typo */
Error (ERR_ILLEGAL_ATTRIBUTE); Error ("Illegal attribute: `%s'", AttrName);
break; break;
} }

View File

@@ -46,86 +46,11 @@
/*****************************************************************************/ /*****************************************************************************/
/* Data */ /* Data */
/*****************************************************************************/ /*****************************************************************************/
/* Error messages sorted by ErrTypes */
static char* ErrMsg [ERR_COUNT-1] = {
"Syntax error",
"`\"' expected",
"`:' expected",
"`;' expected",
"`,' expected",
"`(' expected",
"`)' expected",
"`[' expected",
"`]' expected",
"`{' expected",
"`}' expected",
"Identifier expected",
"Type expected",
"Incompatible types",
"Incompatible pointer types",
"Too many arguments in function call",
"Too few arguments in function call",
"Duplicate macro parameter: %s",
"Variable identifier expected",
"Integer expression expected",
"Constant expression expected",
"No active loop",
"Redefinition of `%s'",
"Conflicting types for `%s'",
"String literal expected",
"`while' expected",
"Function must return a value",
"Function cannot return a value",
"Unexpected `continue'",
"Undefined symbol: `%s'",
"Undefined label: `%s'",
"Too many local variables",
"Too many initializers",
"Cannot initialize incomplete type",
"Cannot subscript",
"Operation not allowed with this type of argument",
"Struct expected",
"Struct/union has no field named `%s'",
"Struct pointer expected",
"lvalue expected",
"Expression expected",
"Preprocessor expression expected",
"Illegal type",
"Illegal function call",
"Illegal indirection",
"Illegal address",
"Illegal hex digit",
"Illegal character constant",
"Illegal modifier",
"Illegal type qualifier",
"Illegal storage class",
"Illegal attribute",
"Illegal segment name: `%s'",
"Division by zero",
"Modulo operation with zero",
"Range error",
"Symbol is already different kind",
"Too many lexical levels",
"Parameter name omitted",
"Old style function decl used as prototype",
"Declaration for parameter `%s' but no such parameter",
"Cannot take address of a register variable",
"Illegal size of data type",
"__fastcall__ is not allowed for C functions",
"Variable has unknown size",
"Unknown identifier: `%s'",
"Duplicate qualifier: `%s'",
"Assignment to const",
"Pointer types differ in type qualifiers",
};
/* Count of errors/warnings */ /* Count of errors/warnings */
unsigned ErrorCount = 0; unsigned ErrorCount = 0;
unsigned WarningCount = 0; unsigned WarningCount = 0;
@@ -195,18 +120,7 @@ static void IntError (const char* Filename, unsigned Line, const char* Msg, va_l
void Error (unsigned ErrNum, ...) void Error (const char* Format, ...)
/* Print an error message */
{
va_list ap;
va_start (ap, ErrNum);
IntError (GetCurrentFile(), curpos, ErrMsg [ErrNum-1], ap);
va_end (ap);
}
void MError (const char* Format, ...)
/* Print an error message */ /* Print an error message */
{ {
va_list ap; va_list ap;

View File

@@ -49,81 +49,6 @@
/* Error numbers */
enum Errors {
ERR_NONE, /* No error */
ERR_SYNTAX,
ERR_QUOTE_EXPECTED,
ERR_COLON_EXPECTED,
ERR_SEMICOLON_EXPECTED,
ERR_COMMA_EXPECTED,
ERR_LPAREN_EXPECTED,
ERR_RPAREN_EXPECTED,
ERR_LBRACK_EXPECTED,
ERR_RBRACK_EXPECTED,
ERR_LCURLY_EXPECTED,
ERR_RCURLY_EXPECTED,
ERR_IDENT_EXPECTED,
ERR_TYPE_EXPECTED,
ERR_INCOMPATIBLE_TYPES,
ERR_INCOMPATIBLE_POINTERS,
ERR_TOO_MANY_FUNC_ARGS,
ERR_TOO_FEW_FUNC_ARGS,
ERR_DUPLICATE_MACRO_ARG,
ERR_VAR_IDENT_EXPECTED,
ERR_INT_EXPR_EXPECTED,
ERR_CONST_EXPR_EXPECTED,
ERR_NO_ACTIVE_LOOP,
ERR_MULTIPLE_DEFINITION,
ERR_CONFLICTING_TYPES,
ERR_STRLIT_EXPECTED,
ERR_WHILE_EXPECTED,
ERR_MUST_RETURN_VALUE,
ERR_CANNOT_RETURN_VALUE,
ERR_UNEXPECTED_CONTINUE,
ERR_UNDEFINED_SYMBOL,
ERR_UNDEFINED_LABEL,
ERR_TOO_MANY_LOCALS,
ERR_TOO_MANY_INITIALIZERS,
ERR_INIT_INCOMPLETE_TYPE,
ERR_CANNOT_SUBSCRIPT,
ERR_OP_NOT_ALLOWED,
ERR_STRUCT_EXPECTED,
ERR_STRUCT_FIELD_MISMATCH,
ERR_STRUCT_PTR_EXPECTED,
ERR_LVALUE_EXPECTED,
ERR_EXPR_EXPECTED,
ERR_CPP_EXPR_EXPECTED,
ERR_ILLEGAL_TYPE,
ERR_ILLEGAL_FUNC_CALL,
ERR_ILLEGAL_INDIRECT,
ERR_ILLEGAL_ADDRESS,
ERR_ILLEGAL_HEX_DIGIT,
ERR_ILLEGAL_CHARCONST,
ERR_ILLEGAL_MODIFIER,
ERR_ILLEGAL_QUALIFIER,
ERR_ILLEGAL_STORAGE_CLASS,
ERR_ILLEGAL_ATTRIBUTE,
ERR_ILLEGAL_SEG_NAME,
ERR_DIV_BY_ZERO,
ERR_MOD_BY_ZERO,
ERR_RANGE,
ERR_SYMBOL_KIND,
ERR_LEVEL_NESTING,
ERR_MISSING_PARAM_NAME,
ERR_OLD_STYLE_PROTO,
ERR_PARAM_DECL,
ERR_CANNOT_TAKE_ADDR_OF_REG,
ERR_ILLEGAL_SIZE,
ERR_FASTCALL,
ERR_UNKNOWN_SIZE,
ERR_UNKNOWN_IDENT,
ERR_DUPLICATE_QUALIFIER,
ERR_CONST_ASSIGN,
ERR_QUAL_DIFF,
ERR_COUNT /* Error count */
};
/* Count of errors/warnings */ /* Count of errors/warnings */
extern unsigned ErrorCount; extern unsigned ErrorCount;
extern unsigned WarningCount; extern unsigned WarningCount;
@@ -142,10 +67,7 @@ void Warning (const char* Format, ...) attribute ((format (printf, 1, 2)));
void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2))); 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 (const char* Format, ...) attribute ((format (printf, 1, 2)));
/* Print an error message */
void MError (const char* Format, ...) attribute ((format (printf, 1, 2)));
/* Print an error message */ /* Print an error message */
void PPError (const char* Format, ...) attribute ((format (printf, 1, 2))); void PPError (const char* Format, ...) attribute ((format (printf, 1, 2)));

View File

@@ -209,13 +209,13 @@ unsigned assignadjust (type* lhst, struct expent* rhs)
/* If one of the sides are of type void, output a more apropriate /* If one of the sides are of type void, output a more apropriate
* error message. * error message.
*/ */
Error (ERR_ILLEGAL_TYPE); Error ("Illegal type");
} else if (IsClassInt (lhst)) { } else if (IsClassInt (lhst)) {
if (IsClassPtr (rhst)) { if (IsClassPtr (rhst)) {
/* Pointer -> int conversion */ /* Pointer -> int conversion */
Warning ("Converting pointer to integer without a cast"); Warning ("Converting pointer to integer without a cast");
} else if (!IsClassInt (rhst)) { } else if (!IsClassInt (rhst)) {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
} else { } else {
/* Adjust the int types. To avoid manipulation of TOS mark lhs /* Adjust the int types. To avoid manipulation of TOS mark lhs
* as const. * as const.
@@ -238,11 +238,11 @@ unsigned assignadjust (type* lhst, struct expent* rhs)
switch (TypeCmp (lhst, rhst)) { switch (TypeCmp (lhst, rhst)) {
case TC_INCOMPATIBLE: case TC_INCOMPATIBLE:
Error (ERR_INCOMPATIBLE_POINTERS); Error ("Incompatible pointer types");
break; break;
case TC_QUAL_DIFF: case TC_QUAL_DIFF:
Error (ERR_QUAL_DIFF); Error ("Pointer types differ in type qualifiers");
break; break;
default: default:
@@ -260,13 +260,13 @@ unsigned assignadjust (type* lhst, struct expent* rhs)
* that both functions have the same parameter list. * that both functions have the same parameter list.
*/ */
if (TypeCmp (Indirect (lhst), rhst) < TC_EQUAL) { if (TypeCmp (Indirect (lhst), rhst) < TC_EQUAL) {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
} }
} else { } else {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
} }
} else { } else {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
} }
/* Return an int value in all cases where the operands are not both ints */ /* Return an int value in all cases where the operands are not both ints */
@@ -292,7 +292,7 @@ void DefineData (struct expent* lval)
* allowed. * allowed.
*/ */
if (!AllowRegVarAddr) { if (!AllowRegVarAddr) {
Error (ERR_CANNOT_TAKE_ADDR_OF_REG); Error ("Cannot take the address of a register variable");
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
@@ -333,7 +333,7 @@ static void lconst (unsigned flags, struct expent* lval)
* allowed. * allowed.
*/ */
if (!AllowRegVarAddr) { if (!AllowRegVarAddr) {
Error (ERR_CANNOT_TAKE_ADDR_OF_REG); Error ("Cannot take the address of a register variable");
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
@@ -387,13 +387,13 @@ static int kcalc (int tok, long val1, long val2)
return (val1 * val2); return (val1 * val2);
case TOK_DIV: case TOK_DIV:
if (val2 == 0) { if (val2 == 0) {
Error (ERR_DIV_BY_ZERO); Error ("Division by zero");
return 0x7FFFFFFF; return 0x7FFFFFFF;
} }
return (val1 / val2); return (val1 / val2);
case TOK_MOD: case TOK_MOD:
if (val2 == 0) { if (val2 == 0) {
Error (ERR_MOD_BY_ZERO); Error ("Modulo operation with zero");
return 0; return 0;
} }
return (val1 % val2); return (val1 % val2);
@@ -568,7 +568,7 @@ static void callfunction (struct expent* lval)
/* Too many arguments. Do we have an open param list? */ /* Too many arguments. Do we have an open param list? */
if ((Func->Flags & FD_ELLIPSIS) == 0) { if ((Func->Flags & FD_ELLIPSIS) == 0) {
/* End of param list reached, no ellipsis */ /* End of param list reached, no ellipsis */
Error (ERR_TOO_MANY_FUNC_ARGS); Error ("Too many arguments in function call");
} }
/* Assume an ellipsis even in case of errors to avoid an error /* Assume an ellipsis even in case of errors to avoid an error
* message for each other argument. * message for each other argument.
@@ -633,7 +633,7 @@ static void callfunction (struct expent* lval)
/* Check if we had enough parameters */ /* Check if we had enough parameters */
if (ParamCount < Func->ParamCount) { if (ParamCount < Func->ParamCount) {
Error (ERR_TOO_FEW_FUNC_ARGS); Error ("Too few arguments in function call");
} }
/* */ /* */
@@ -667,7 +667,7 @@ void doasm (void)
/* String literal */ /* String literal */
if (curtok != TOK_SCONST) { if (curtok != TOK_SCONST) {
Error (ERR_STRLIT_EXPECTED); Error ("String literal expected");
} else { } else {
/* Write the string directly into the output, followed by a newline */ /* Write the string directly into the output, followed by a newline */
AddCodeLine (GetLiteral (curval)); AddCodeLine (GetLiteral (curval));
@@ -722,7 +722,7 @@ static int primary (struct expent* lval)
*/ */
if (Preprocessing) { if (Preprocessing) {
/* Illegal expression in PP mode */ /* Illegal expression in PP mode */
Error (ERR_CPP_EXPR_EXPECTED); Error ("Preprocessor expression expected");
lval->e_flags = E_MCONST; lval->e_flags = E_MCONST;
lval->e_tptr = type_int; lval->e_tptr = type_int;
return 0; return 0;
@@ -747,13 +747,10 @@ static int primary (struct expent* lval)
lval->e_tptr = Sym->Type; lval->e_tptr = Sym->Type;
/* Check for illegal symbol types */ /* Check for illegal symbol types */
if ((Sym->Flags & SC_LABEL) == SC_LABEL) { CHECK ((Sym->Flags & SC_LABEL) != SC_LABEL);
/* Cannot use labels in expressions */ if (Sym->Flags & SC_TYPE) {
Error (ERR_SYMBOL_KIND);
return 1;
} else if (Sym->Flags & SC_TYPE) {
/* Cannot use type symbols */ /* Cannot use type symbols */
Error (ERR_VAR_IDENT_EXPECTED); Error ("Variable identifier expected");
/* Assume an int type to make lval valid */ /* Assume an int type to make lval valid */
lval->e_flags = E_MLOCAL | E_TLOFFS; lval->e_flags = E_MLOCAL | E_TLOFFS;
lval->e_tptr = type_int; lval->e_tptr = type_int;
@@ -830,7 +827,7 @@ static int primary (struct expent* lval)
lval->e_flags = E_MLOCAL | E_TLOFFS; lval->e_flags = E_MLOCAL | E_TLOFFS;
lval->e_tptr = type_int; lval->e_tptr = type_int;
lval->e_const = 0; lval->e_const = 0;
Error (ERR_UNDEFINED_SYMBOL, Ident); Error ("Undefined symbol: `%s'", Ident);
return 1; return 1;
} }
@@ -865,7 +862,7 @@ static int primary (struct expent* lval)
} }
/* Illegal primary. */ /* Illegal primary. */
Error (ERR_EXPR_EXPECTED); Error ("Expression expected");
lval->e_flags = E_MCONST; lval->e_flags = E_MCONST;
lval->e_tptr = type_int; lval->e_tptr = type_int;
return 0; return 0;
@@ -973,7 +970,7 @@ static int arrayref (int k, struct expent* lval)
/* */ /* */
lval->e_tptr = lval2.e_tptr; lval->e_tptr = lval2.e_tptr;
} else { } else {
Error (ERR_CANNOT_SUBSCRIPT); Error ("Cannot subscript");
} }
/* Add the subscript. Since arrays are indexed by integers, /* Add the subscript. Since arrays are indexed by integers,
@@ -1023,7 +1020,7 @@ static int arrayref (int k, struct expent* lval)
g_scale (TypeOf (tptr1), SizeOf (lval2.e_tptr)); g_scale (TypeOf (tptr1), SizeOf (lval2.e_tptr));
lval->e_tptr = lval2.e_tptr; lval->e_tptr = lval2.e_tptr;
} else { } else {
Error (ERR_CANNOT_SUBSCRIPT); Error ("Cannot subscript");
} }
/* The offset is now in the primary register. It didn't have a /* The offset is now in the primary register. It didn't have a
@@ -1116,7 +1113,7 @@ static int structref (int k, struct expent* lval)
/* Skip the token and check for an identifier */ /* Skip the token and check for an identifier */
NextToken (); NextToken ();
if (curtok != TOK_IDENT) { if (curtok != TOK_IDENT) {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
lval->e_tptr = type_int; lval->e_tptr = type_int;
return 0; return 0;
} }
@@ -1126,7 +1123,7 @@ static int structref (int k, struct expent* lval)
NextToken (); NextToken ();
Field = FindStructField (lval->e_tptr, Ident); Field = FindStructField (lval->e_tptr, Ident);
if (Field == 0) { if (Field == 0) {
Error (ERR_STRUCT_FIELD_MISMATCH, Ident); Error ("Struct/union has no field named `%s'", Ident);
lval->e_tptr = type_int; lval->e_tptr = type_int;
return 0; return 0;
} }
@@ -1187,14 +1184,14 @@ static int hie11 (struct expent *lval)
lval->e_flags = E_MEXPR; lval->e_flags = E_MEXPR;
lval->e_tptr += DECODE_SIZE + 1; /* Set to result */ lval->e_tptr += DECODE_SIZE + 1; /* Set to result */
} else { } else {
Error (ERR_ILLEGAL_FUNC_CALL); Error ("Illegal function call");
} }
k = 0; k = 0;
} else if (curtok == TOK_DOT) { } else if (curtok == TOK_DOT) {
if (!IsClassStruct (lval->e_tptr)) { if (!IsClassStruct (lval->e_tptr)) {
Error (ERR_STRUCT_EXPECTED); Error ("Struct expected");
} }
k = structref (0, lval); k = structref (0, lval);
@@ -1202,7 +1199,7 @@ static int hie11 (struct expent *lval)
tptr = lval->e_tptr; tptr = lval->e_tptr;
if (tptr[0] != T_PTR || (tptr[1] & T_STRUCT) == 0) { if (tptr[0] != T_PTR || (tptr[1] & T_STRUCT) == 0) {
Error (ERR_STRUCT_PTR_EXPECTED); Error ("Struct pointer expected");
} }
k = structref (k, lval); k = structref (k, lval);
@@ -1260,7 +1257,7 @@ static void pre_incdec (struct expent* lval, void (*inc) (unsigned, unsigned lon
NextToken (); NextToken ();
if ((k = hie10 (lval)) == 0) { if ((k = hie10 (lval)) == 0) {
Error (ERR_LVALUE_EXPECTED); Error ("Invalid lvalue");
return; return;
} }
@@ -1339,7 +1336,7 @@ static void post_incdec (struct expent *lval, int k, void (*inc) (unsigned, unsi
NextToken (); NextToken ();
if (k == 0) { if (k == 0) {
Error (ERR_LVALUE_EXPECTED); Error ("Invalid lvalue");
return; return;
} }
@@ -1540,7 +1537,7 @@ static int hie10 (struct expent* lval)
if (IsClassPtr (t)) { if (IsClassPtr (t)) {
lval->e_tptr = Indirect (t); lval->e_tptr = Indirect (t);
} else { } else {
Error (ERR_ILLEGAL_INDIRECT); Error ("Illegal indirection");
} }
return 1; return 1;
@@ -1550,7 +1547,7 @@ static int hie10 (struct expent* lval)
if (k == 0) { if (k == 0) {
/* Allow the & operator with an array */ /* Allow the & operator with an array */
if (!IsTypeArray (lval->e_tptr)) { if (!IsTypeArray (lval->e_tptr)) {
Error (ERR_ILLEGAL_ADDRESS); Error ("Illegal address");
} }
} else { } else {
t = TypeAlloc (TypeLen (lval->e_tptr) + 2); t = TypeAlloc (TypeLen (lval->e_tptr) + 2);
@@ -1630,7 +1627,7 @@ static int hie_internal (GenDesc** ops, /* List of generators */
/* All operators that call this function expect an int on the lhs */ /* All operators that call this function expect an int on the lhs */
if (!IsClassInt (lval->e_tptr)) { if (!IsClassInt (lval->e_tptr)) {
Error (ERR_INT_EXPR_EXPECTED); Error ("Integer expression expected");
} }
/* Remember the operator token, then skip it */ /* Remember the operator token, then skip it */
@@ -1656,7 +1653,7 @@ static int hie_internal (GenDesc** ops, /* List of generators */
/* Check the type of the rhs */ /* Check the type of the rhs */
if (!IsClassInt (lval2.e_tptr)) { if (!IsClassInt (lval2.e_tptr)) {
Error (ERR_INT_EXPR_EXPECTED); Error ("Integer expression expected");
} }
/* Check for const operands */ /* Check for const operands */
@@ -1685,9 +1682,9 @@ static int hie_internal (GenDesc** ops, /* List of generators */
type |= CF_CONST; type |= CF_CONST;
rtype |= CF_CONST; rtype |= CF_CONST;
if (tok == TOK_DIV && lval2.e_const == 0) { if (tok == TOK_DIV && lval2.e_const == 0) {
Error (ERR_DIV_BY_ZERO); Error ("Division by zero");
} else if (tok == TOK_MOD && lval2.e_const == 0) { } else if (tok == TOK_MOD && lval2.e_const == 0) {
Error (ERR_MOD_BY_ZERO); Error ("Modulo operation with zero");
} }
if ((Gen->Flags & GEN_NOPUSH) != 0) { if ((Gen->Flags & GEN_NOPUSH) != 0) {
RemoveCode (Mark2); RemoveCode (Mark2);
@@ -1757,7 +1754,7 @@ static int hie_compare (GenDesc** ops, /* List of generators */
/* Make sure, the types are compatible */ /* Make sure, the types are compatible */
if (IsClassInt (lval->e_tptr)) { if (IsClassInt (lval->e_tptr)) {
if (!IsClassInt (lval2.e_tptr) && !(IsClassPtr(lval2.e_tptr) && IsNullPtr(lval))) { if (!IsClassInt (lval2.e_tptr) && !(IsClassPtr(lval2.e_tptr) && IsNullPtr(lval))) {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
} }
} else if (IsClassPtr (lval->e_tptr)) { } else if (IsClassPtr (lval->e_tptr)) {
if (IsClassPtr (lval2.e_tptr)) { if (IsClassPtr (lval2.e_tptr)) {
@@ -1768,10 +1765,10 @@ static int hie_compare (GenDesc** ops, /* List of generators */
type* right = Indirect (lval2.e_tptr); type* right = Indirect (lval2.e_tptr);
if (TypeCmp (left, right) < TC_EQUAL && *left != T_VOID && *right != T_VOID) { if (TypeCmp (left, right) < TC_EQUAL && *left != T_VOID && *right != T_VOID) {
/* Incomatible pointers */ /* Incomatible pointers */
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
} }
} else if (!IsNullPtr (&lval2)) { } else if (!IsNullPtr (&lval2)) {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
} }
} }
@@ -1896,7 +1893,7 @@ static void parseadd (int k, struct expent* lval)
typeadjust (lval, &lval2, 1); typeadjust (lval, &lval2, 1);
} else { } else {
/* OOPS */ /* OOPS */
Error (ERR_OP_NOT_ALLOWED); Error ("Invalid operands for binary operator `+'");
} }
/* Result is constant, condition codes not set */ /* Result is constant, condition codes not set */
@@ -1924,7 +1921,7 @@ static void parseadd (int k, struct expent* lval)
flags = typeadjust (lval, &lval2, 1); flags = typeadjust (lval, &lval2, 1);
} else { } else {
/* OOPS */ /* OOPS */
Error (ERR_OP_NOT_ALLOWED); Error ("Invalid operands for binary operator `+'");
} }
/* Generate code for the add */ /* Generate code for the add */
@@ -1970,7 +1967,7 @@ static void parseadd (int k, struct expent* lval)
flags = typeadjust (lval, &lval2, 1); flags = typeadjust (lval, &lval2, 1);
} else { } else {
/* OOPS */ /* OOPS */
Error (ERR_OP_NOT_ALLOWED); Error ("Invalid operands for binary operator `+'");
} }
/* Generate code for the add */ /* Generate code for the add */
@@ -2004,7 +2001,7 @@ static void parseadd (int k, struct expent* lval)
flags = typeadjust (lval, &lval2, 0); flags = typeadjust (lval, &lval2, 0);
} else { } else {
/* OOPS */ /* OOPS */
Error (ERR_OP_NOT_ALLOWED); Error ("Invalid operands for binary operator `+'");
} }
/* Generate code for the add */ /* Generate code for the add */
@@ -2032,7 +2029,7 @@ static void parsesub (int k, struct expent* lval)
type* lhst; /* Type of left hand side */ type* lhst; /* Type of left hand side */
type* rhst; /* Type of right hand side */ type* rhst; /* Type of right hand side */
CodeMark Mark1; /* Save position of output queue */ CodeMark Mark1; /* Save position of output queue */
CodeMark Mark2; /* Another position in the queue */ CodeMark Mark2; /* Another position in the queue */
int rscale; /* Scale factor for the result */ int rscale; /* Scale factor for the result */
@@ -2071,7 +2068,7 @@ static void parsesub (int k, struct expent* lval)
} else if (IsClassPtr (lhst) && IsClassPtr (rhst)) { } else if (IsClassPtr (lhst) && IsClassPtr (rhst)) {
/* Left is pointer, right is pointer, must scale result */ /* Left is pointer, right is pointer, must scale result */
if (TypeCmp (Indirect (lhst), Indirect (rhst)) < TC_EQUAL) { if (TypeCmp (Indirect (lhst), Indirect (rhst)) < TC_EQUAL) {
Error (ERR_INCOMPATIBLE_POINTERS); Error ("Incompatible pointer types");
} else { } else {
lval->e_const = (lval->e_const - lval2.e_const) / PSizeOf (lhst); lval->e_const = (lval->e_const - lval2.e_const) / PSizeOf (lhst);
} }
@@ -2083,7 +2080,7 @@ static void parsesub (int k, struct expent* lval)
lval->e_const -= lval2.e_const; lval->e_const -= lval2.e_const;
} else { } else {
/* OOPS */ /* OOPS */
Error (ERR_OP_NOT_ALLOWED); Error ("Invalid operands for binary operator `-'");
} }
/* Result is constant, condition codes not set */ /* Result is constant, condition codes not set */
@@ -2106,7 +2103,7 @@ static void parsesub (int k, struct expent* lval)
} else if (IsClassPtr (lhst) && IsClassPtr (rhst)) { } else if (IsClassPtr (lhst) && IsClassPtr (rhst)) {
/* Left is pointer, right is pointer, must scale result */ /* Left is pointer, right is pointer, must scale result */
if (TypeCmp (Indirect (lhst), Indirect (rhst)) < TC_EQUAL) { if (TypeCmp (Indirect (lhst), Indirect (rhst)) < TC_EQUAL) {
Error (ERR_INCOMPATIBLE_POINTERS); Error ("Incompatible pointer types");
} else { } else {
rscale = PSizeOf (lhst); rscale = PSizeOf (lhst);
} }
@@ -2118,7 +2115,7 @@ static void parsesub (int k, struct expent* lval)
flags = typeadjust (lval, &lval2, 1); flags = typeadjust (lval, &lval2, 1);
} else { } else {
/* OOPS */ /* OOPS */
Error (ERR_OP_NOT_ALLOWED); Error ("Invalid operands for binary operator `-'");
} }
/* Do the subtraction */ /* Do the subtraction */
@@ -2149,7 +2146,7 @@ static void parsesub (int k, struct expent* lval)
} else if (IsClassPtr (lhst) && IsClassPtr (rhst)) { } else if (IsClassPtr (lhst) && IsClassPtr (rhst)) {
/* Left is pointer, right is pointer, must scale result */ /* Left is pointer, right is pointer, must scale result */
if (TypeCmp (Indirect (lhst), Indirect (rhst)) < TC_EQUAL) { if (TypeCmp (Indirect (lhst), Indirect (rhst)) < TC_EQUAL) {
Error (ERR_INCOMPATIBLE_POINTERS); Error ("Incompatible pointer types");
} else { } else {
rscale = PSizeOf (lhst); rscale = PSizeOf (lhst);
} }
@@ -2168,7 +2165,7 @@ static void parsesub (int k, struct expent* lval)
flags = typeadjust (lval, &lval2, 0); flags = typeadjust (lval, &lval2, 0);
} else { } else {
/* OOPS */ /* OOPS */
Error (ERR_OP_NOT_ALLOWED); Error ("Invalid operands for binary operator `-'");
} }
/* Generate code for the sub (the & is a hack here) */ /* Generate code for the sub (the & is a hack here) */
@@ -2508,7 +2505,7 @@ static int hieQuest (struct expent *lval)
} else if (IsClassPtr (type2) && IsClassPtr (type3)) { } else if (IsClassPtr (type2) && IsClassPtr (type3)) {
/* Must point to same type */ /* Must point to same type */
if (TypeCmp (Indirect (type2), Indirect (type3)) < TC_EQUAL) { if (TypeCmp (Indirect (type2), Indirect (type3)) < TC_EQUAL) {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible pointer types");
} }
/* Result has the common type */ /* Result has the common type */
rtype = lval2.e_tptr; rtype = lval2.e_tptr;
@@ -2519,7 +2516,7 @@ static int hieQuest (struct expent *lval)
/* Result type is pointer, no cast needed */ /* Result type is pointer, no cast needed */
rtype = lval3.e_tptr; rtype = lval3.e_tptr;
} else { } else {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
rtype = lval2.e_tptr; /* Doesn't matter here */ rtype = lval2.e_tptr; /* Doesn't matter here */
} }
@@ -2548,7 +2545,7 @@ static void opeq (GenDesc* Gen, struct expent *lval, int k)
NextToken (); NextToken ();
if (k == 0) { if (k == 0) {
Error (ERR_LVALUE_EXPECTED); Error ("Invalid lvalue in assignment");
return; return;
} }
@@ -2628,7 +2625,7 @@ static void addsubeq (GenDesc* Gen, struct expent *lval, int k)
if (k == 0) { if (k == 0) {
Error (ERR_LVALUE_EXPECTED); Error ("Invalid lvalue in assignment");
return; return;
} }
@@ -2721,7 +2718,7 @@ static void Assignment (struct expent* lval)
/* Check for assignment to const */ /* Check for assignment to const */
if (IsQualConst (ltype)) { if (IsQualConst (ltype)) {
Error (ERR_CONST_ASSIGN); Error ("Assignment to const");
} }
/* cc65 does not have full support for handling structs by value. Since /* cc65 does not have full support for handling structs by value. Since
@@ -2741,7 +2738,7 @@ static void Assignment (struct expent* lval)
exprhs (0, 0, &lval2); exprhs (0, 0, &lval2);
} else { } else {
/* We need an lvalue */ /* We need an lvalue */
Error (ERR_LVALUE_EXPECTED); Error ("Invalid lvalue in assignment");
} }
/* Push the address (or whatever is in ax in case of errors) */ /* Push the address (or whatever is in ax in case of errors) */
@@ -2749,7 +2746,7 @@ static void Assignment (struct expent* lval)
/* Check for equality of the structs */ /* Check for equality of the structs */
if (TypeCmp (ltype, lval2.e_tptr) < TC_EQUAL) { if (TypeCmp (ltype, lval2.e_tptr) < TC_EQUAL) {
Error (ERR_INCOMPATIBLE_TYPES); Error ("Incompatible types");
} }
/* Load the size of the struct into the primary */ /* Load the size of the struct into the primary */
@@ -2803,7 +2800,7 @@ int hie1 (struct expent* lval)
case TOK_ASSIGN: case TOK_ASSIGN:
NextToken (); NextToken ();
if (k == 0) { if (k == 0) {
Error (ERR_LVALUE_EXPECTED); Error ("Invalid lvalue in assignment");
} else { } else {
Assignment (lval); Assignment (lval);
} }
@@ -2943,7 +2940,7 @@ void constexpr (struct expent* lval)
{ {
memset (lval, 0, sizeof (*lval)); memset (lval, 0, sizeof (*lval));
if (expr (hie1, lval) != 0 || (lval->e_flags & E_MCONST) == 0) { if (expr (hie1, lval) != 0 || (lval->e_flags & E_MCONST) == 0) {
Error (ERR_CONST_EXPR_EXPECTED); Error ("Constant expression expected");
/* To avoid any compiler errors, make the expression a valid const */ /* To avoid any compiler errors, make the expression a valid const */
lval->e_flags = E_MCONST; lval->e_flags = E_MCONST;
lval->e_tptr = type_int; lval->e_tptr = type_int;
@@ -2958,7 +2955,7 @@ void intexpr (struct expent* lval)
{ {
expression (lval); expression (lval);
if (!IsClassInt (lval->e_tptr)) { if (!IsClassInt (lval->e_tptr)) {
Error (ERR_INT_EXPR_EXPECTED); Error ("Integer expression expected");
/* To avoid any compiler errors, make the expression a valid int */ /* To avoid any compiler errors, make the expression a valid int */
lval->e_flags = E_MCONST; lval->e_flags = E_MCONST;
lval->e_tptr = type_int; lval->e_tptr = type_int;
@@ -2975,11 +2972,10 @@ void boolexpr (struct expent* lval)
expression (lval); expression (lval);
/* If it's an integer, it's ok. If it's not an integer, but a pointer, /* If it's an integer, it's ok. If it's not an integer, but a pointer,
* the pointer used in a boolean context is also ok (Ootherwise check if it's a pointer * the pointer used in a boolean context is also ok
* expression.
*/ */
if (!IsClassInt (lval->e_tptr) && !IsClassPtr (lval->e_tptr)) { if (!IsClassInt (lval->e_tptr) && !IsClassPtr (lval->e_tptr)) {
Error (ERR_INT_EXPR_EXPECTED); Error ("Boolean expression expected");
/* To avoid any compiler errors, make the expression a valid int */ /* To avoid any compiler errors, make the expression a valid int */
lval->e_flags = E_MCONST; lval->e_flags = E_MCONST;
lval->e_tptr = type_int; lval->e_tptr = type_int;

View File

@@ -213,12 +213,12 @@ void NewFunc (SymEntry* Func)
/* C functions cannot currently have __fastcall__ calling conventions */ /* C functions cannot currently have __fastcall__ calling conventions */
if (IsFastCallFunc (Func->Type)) { if (IsFastCallFunc (Func->Type)) {
Error (ERR_FASTCALL); Error ("__fastcall__ is not allowed for C functions");
} }
/* Need a starting curly brace */ /* Need a starting curly brace */
if (curtok != TOK_LCURLY) { if (curtok != TOK_LCURLY) {
Error (ERR_LCURLY_EXPECTED); Error ("`{' expected");
} }
/* Setup register variables */ /* Setup register variables */
@@ -247,7 +247,7 @@ void NewFunc (SymEntry* Func)
#if 0 #if 0
/* If the function has a return type, flag an error */ /* If the function has a return type, flag an error */
if (!voidfunc) { if (!voidfunc) {
Error (ERR_MUST_RETURN_VALUE); Error ("Function `%s' must return a value", Func->Name);
} }
#endif #endif
RestoreRegVars (0); RestoreRegVars (0);

View File

@@ -56,7 +56,7 @@ void DoGoto (void)
/* Label name must follow */ /* Label name must follow */
if (curtok != TOK_IDENT) { if (curtok != TOK_IDENT) {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
} else { } else {

View File

@@ -1,81 +1,104 @@
/* /*****************************************************************************/
* loop.c /* */
* /* loop.c */
* Ullrich von Bassewitz, 20.06.1998 /* */
*/ /* Loop management */
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#include "../common/xmalloc.h" /* common */
#include "xmalloc.h"
/* cc65 */
#include "error.h" #include "error.h"
#include "loop.h" #include "loop.h"
/*****************************************************************************/ /*****************************************************************************/
/* data */ /* Data */
/*****************************************************************************/ /*****************************************************************************/
/* The root */ /* The root */
static struct loopdesc* loopstack = 0; static LoopDesc* LoopStack = 0;
/*****************************************************************************/ /*****************************************************************************/
/* code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/
struct loopdesc* addloop (unsigned sp, unsigned loop, unsigned label, LoopDesc* AddLoop (unsigned sp, unsigned loop, unsigned label,
unsigned linc, unsigned lstat) unsigned linc, unsigned lstat)
/* Create and add a new loop descriptor */ /* Create and add a new loop descriptor */
{ {
struct loopdesc* l; LoopDesc* L;
/* Allocate a new struct */ /* Allocate a new struct */
l = xmalloc (sizeof (struct loopdesc)); L = xmalloc (sizeof (LoopDesc));
/* Fill in the data */ /* Fill in the data */
l->sp = sp; L->StackPtr = sp;
l->loop = loop; L->Loop = loop;
l->label = label; L->Label = label;
l->linc = linc; L->linc = linc;
l->lstat = lstat; L->lstat = lstat;
/* Insert it into the list */ /* Insert it into the list */
l->next = loopstack; L->Next = LoopStack;
loopstack = l; LoopStack = L;
/* Return a pointer to the struct */ /* Return a pointer to the struct */
return l; return L;
} }
struct loopdesc* currentloop (void) LoopDesc* CurrentLoop (void)
/* Return a pointer to the descriptor of the current loop */ /* Return a pointer to the descriptor of the current loop */
{ {
if (loopstack == 0) { return LoopStack;
/* Stack is empty */
Error (ERR_NO_ACTIVE_LOOP);
}
return loopstack;
} }
void delloop (void) void DelLoop (void)
/* Remove the current loop */ /* Remove the current loop */
{ {
struct loopdesc* l; LoopDesc* L = LoopStack;
LoopStack = LoopStack->Next;
l = loopstack; xfree (L);
loopstack = loopstack->next;
xfree (l);
} }

View File

@@ -1,8 +1,35 @@
/* /*****************************************************************************/
* loop.h /* */
* /* loop.h */
* Ullrich von Bassewitz, 20.06.1998 /* */
*/ /* Loop management */
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
@@ -17,13 +44,14 @@
struct loopdesc { typedef struct LoopDesc LoopDesc;
struct loopdesc* next; struct LoopDesc {
unsigned sp; LoopDesc* Next;
unsigned loop; unsigned StackPtr;
unsigned label; unsigned Loop;
unsigned linc; unsigned Label;
unsigned lstat; unsigned linc;
unsigned lstat;
}; };
@@ -34,14 +62,14 @@ struct loopdesc {
struct loopdesc* addloop (unsigned sp, unsigned loop, unsigned label, LoopDesc* AddLoop (unsigned sp, unsigned loop, unsigned label,
unsigned linc, unsigned lstat); unsigned linc, unsigned lstat);
/* Create and add a new loop descriptor */ /* Create and add a new loop descriptor */
struct loopdesc* currentloop (void); LoopDesc* CurrentLoop (void);
/* Return a pointer to the descriptor of the current loop */ /* Return a pointer to the descriptor of the current loop */
void delloop (void); void DelLoop (void);
/* Remove the current loop */ /* Remove the current loop */

View File

@@ -283,7 +283,7 @@ void AddMacroArg (Macro* M, const char* Arg)
for (I = 0; I < M->ArgCount; ++I) { for (I = 0; I < M->ArgCount; ++I) {
if (strcmp (M->FormalArgs[I], Arg) == 0) { if (strcmp (M->FormalArgs[I], Arg) == 0) {
/* Found */ /* Found */
Error (ERR_DUPLICATE_MACRO_ARG, Arg); Error ("Duplicate macro parameter: `%s'", Arg);
break; break;
} }
} }

View File

@@ -117,7 +117,7 @@ static void StringPragma (void (*Func) (const char*))
/* Handle a pragma that expects a string parameter */ /* Handle a pragma that expects a string parameter */
{ {
if (curtok != TOK_SCONST) { if (curtok != TOK_SCONST) {
Error (ERR_STRLIT_EXPECTED); Error ("String literal expected");
} else { } else {
/* Get the string */ /* Get the string */
const char* Name = GetLiteral (curval); const char* Name = GetLiteral (curval);
@@ -139,7 +139,7 @@ static void SegNamePragma (void (*Func) (const char*))
/* Handle a pragma that expects a segment name parameter */ /* Handle a pragma that expects a segment name parameter */
{ {
if (curtok != TOK_SCONST) { if (curtok != TOK_SCONST) {
Error (ERR_STRLIT_EXPECTED); Error ("String literal expected");
} else { } else {
/* Get the segment name */ /* Get the segment name */
const char* Name = GetLiteral (curval); const char* Name = GetLiteral (curval);
@@ -153,7 +153,7 @@ static void SegNamePragma (void (*Func) (const char*))
} else { } else {
/* Segment name is invalid */ /* Segment name is invalid */
Error (ERR_ILLEGAL_SEG_NAME, Name); Error ("Illegal segment name: `%s'", Name);
} }
@@ -190,7 +190,7 @@ void DoPragma (void)
/* Identifier must follow */ /* Identifier must follow */
if (curtok != TOK_IDENT) { if (curtok != TOK_IDENT) {
Error (ERR_IDENT_EXPECTED); Error ("Identifier expected");
return; return;
} }

View File

@@ -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 */
{ {
MError ("Invalid input character with code %02X", C & 0xFF); Error ("Invalid input character with code %02X", C & 0xFF);
NextChar (); /* Skip */ NextChar (); /* Skip */
} }
@@ -202,7 +202,7 @@ static unsigned hexval (int c)
/* Convert a hex digit into a value */ /* Convert a hex digit into a value */
{ {
if (!isxdigit (c)) { if (!isxdigit (c)) {
Error (ERR_ILLEGAL_HEX_DIGIT); Error ("Invalid hexadecimal digit: `%c'", c);
} }
if (isdigit (c)) { if (isdigit (c)) {
return c - '0'; return c - '0';
@@ -288,7 +288,7 @@ static int ParseChar (void)
} }
break; break;
default: default:
Error (ERR_ILLEGAL_CHARCONST); Error ("Illegal character constant");
C = ' '; C = ' ';
break; break;
} }
@@ -318,7 +318,7 @@ static void CharConst (void)
/* Check for closing quote */ /* Check for closing quote */
if (CurC != '\'') { if (CurC != '\'') {
Error (ERR_QUOTE_EXPECTED); Error ("`\'' expected");
} else { } else {
/* Skip the quote */ /* Skip the quote */
NextChar (); NextChar ();
@@ -350,7 +350,7 @@ static void StringConst (void)
while (CurC != '\"') { while (CurC != '\"') {
if (CurC == '\0') { if (CurC == '\0') {
MError ("Unexpected newline"); Error ("Unexpected newline");
break; break;
} }
AddLiteralChar (ParseChar ()); AddLiteralChar (ParseChar ());
@@ -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 */
MError ("Preprocessor directive expected"); Error ("Preprocessor directive expected");
} }
nxttok = TOK_PRAGMA; nxttok = TOK_PRAGMA;
break; break;
@@ -768,7 +768,7 @@ void NextToken (void)
void Consume (token_t Token, unsigned ErrNum) void Consume (token_t Token, const char* ErrorMsg)
/* Eat token if it is the next in the input stream, otherwise print an error /* Eat token if it is the next in the input stream, otherwise print an error
* message. * message.
*/ */
@@ -776,7 +776,7 @@ void Consume (token_t Token, unsigned ErrNum)
if (curtok == Token) { if (curtok == Token) {
NextToken (); NextToken ();
} else { } else {
Error (ErrNum); Error (ErrorMsg);
} }
} }
@@ -785,7 +785,7 @@ void Consume (token_t Token, unsigned ErrNum)
void ConsumeColon (void) void ConsumeColon (void)
/* Check for a colon and skip it. */ /* Check for a colon and skip it. */
{ {
Consume (TOK_COLON, ERR_COLON_EXPECTED); Consume (TOK_COLON, "`:' expected");
} }
@@ -797,7 +797,7 @@ void ConsumeSemi (void)
if (curtok == TOK_SEMI) { if (curtok == TOK_SEMI) {
NextToken (); NextToken ();
} else { } else {
Error (ERR_SEMICOLON_EXPECTED); Error ("`;' expected");
if (curtok == TOK_COLON || curtok == TOK_COMMA) { if (curtok == TOK_COLON || curtok == TOK_COMMA) {
NextToken (); NextToken ();
} }
@@ -813,7 +813,7 @@ void ConsumeComma (void)
if (CurTok.Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextToken (); NextToken ();
} else { } else {
Error (ERR_COMMA_EXPECTED); Error ("`,' expected");
if (CurTok.Tok == TOK_SEMI) { if (CurTok.Tok == TOK_SEMI) {
NextToken (); NextToken ();
} }
@@ -825,7 +825,7 @@ void ConsumeComma (void)
void ConsumeLParen (void) void ConsumeLParen (void)
/* Check for a left parenthesis and skip it */ /* Check for a left parenthesis and skip it */
{ {
Consume (TOK_LPAREN, ERR_LPAREN_EXPECTED); Consume (TOK_LPAREN, "`(' expected");
} }
@@ -833,7 +833,7 @@ void ConsumeLParen (void)
void ConsumeRParen (void) void ConsumeRParen (void)
/* Check for a right parenthesis and skip it */ /* Check for a right parenthesis and skip it */
{ {
Consume (TOK_RPAREN, ERR_RPAREN_EXPECTED); Consume (TOK_RPAREN, "`)' expected");
} }
@@ -841,7 +841,7 @@ void ConsumeRParen (void)
void ConsumeLBrack (void) void ConsumeLBrack (void)
/* Check for a left bracket and skip it */ /* Check for a left bracket and skip it */
{ {
Consume (TOK_LBRACK, ERR_LBRACK_EXPECTED); Consume (TOK_LBRACK, "`[' expected");
} }
@@ -849,7 +849,7 @@ void ConsumeLBrack (void)
void ConsumeRBrack (void) void ConsumeRBrack (void)
/* Check for a right bracket and skip it */ /* Check for a right bracket and skip it */
{ {
Consume (TOK_RBRACK, ERR_RBRACK_EXPECTED); Consume (TOK_RBRACK, "`]' expected");
} }
@@ -857,7 +857,7 @@ void ConsumeRBrack (void)
void ConsumeLCurly (void) void ConsumeLCurly (void)
/* Check for a left curly brace and skip it */ /* Check for a left curly brace and skip it */
{ {
Consume (TOK_LCURLY, ERR_LCURLY_EXPECTED); Consume (TOK_LCURLY, "`{' expected");
} }
@@ -865,7 +865,7 @@ void ConsumeLCurly (void)
void ConsumeRCurly (void) void ConsumeRCurly (void)
/* Check for a right curly brace and skip it */ /* Check for a right curly brace and skip it */
{ {
Consume (TOK_RCURLY, ERR_RCURLY_EXPECTED); Consume (TOK_RCURLY, "`}' expected");
} }

View File

@@ -187,7 +187,7 @@ int IsSym (char* s);
void NextToken (void); void NextToken (void);
/* Get next token from input stream */ /* Get next token from input stream */
void Consume (token_t Token, unsigned ErrNum); void Consume (token_t Token, const char* ErrorMsg);
/* Eat token if it is the next in the input stream, otherwise print an error /* Eat token if it is the next in the input stream, otherwise print an error
* message. * message.
*/ */

View File

@@ -122,7 +122,7 @@ static void dowhile (char wtype)
NextToken (); NextToken ();
loop = GetLabel (); loop = GetLabel ();
lab = GetLabel (); lab = GetLabel ();
addloop (oursp, loop, lab, 0, 0); AddLoop (oursp, loop, lab, 0, 0);
g_defloclabel (loop); g_defloclabel (loop);
if (wtype == 'w') { if (wtype == 'w') {
@@ -151,13 +151,13 @@ static void dowhile (char wtype)
/* Do loop */ /* Do loop */
statement (); statement ();
Consume (TOK_WHILE, ERR_WHILE_EXPECTED); Consume (TOK_WHILE, "`while' expected");
test (loop, 1); test (loop, 1);
ConsumeSemi (); ConsumeSemi ();
g_defloclabel (lab); g_defloclabel (lab);
} }
delloop (); DelLoop ();
} }
@@ -173,7 +173,7 @@ static void doreturn (void)
NextToken (); NextToken ();
if (curtok != TOK_SEMI) { if (curtok != TOK_SEMI) {
if (HasVoidReturn (CurrentFunc)) { if (HasVoidReturn (CurrentFunc)) {
Error (ERR_CANNOT_RETURN_VALUE); Error ("Returning a value in function with return type void");
} }
if (evalexpr (CF_NONE, hie0, &lval) == 0) { if (evalexpr (CF_NONE, hie0, &lval) == 0) {
/* Constant value */ /* Constant value */
@@ -188,7 +188,7 @@ static void doreturn (void)
etype |= assignadjust (GetReturnType (CurrentFunc), &lval) & ~CF_CONST; etype |= assignadjust (GetReturnType (CurrentFunc), &lval) & ~CF_CONST;
} }
} else if (!HasVoidReturn (CurrentFunc)) { } else if (!HasVoidReturn (CurrentFunc)) {
Error (ERR_MUST_RETURN_VALUE); Error ("Function `%s' must return a value", GetFuncName (CurrentFunc));
} }
RestoreRegVars (HaveVal); RestoreRegVars (HaveVal);
g_leave (etype, lval.e_const); g_leave (etype, lval.e_const);
@@ -199,15 +199,26 @@ static void doreturn (void)
static void dobreak (void) static void dobreak (void)
/* Handle 'break' statement here */ /* Handle 'break' statement here */
{ {
struct loopdesc* l; LoopDesc* L;
/* Skip the break */
NextToken (); NextToken ();
if ((l = currentloop ()) == 0) {
/* Get the current loop descriptor */
L = CurrentLoop ();
/* Check if we are inside a loop */
if (L == 0) {
/* Error: No current loop */ /* Error: No current loop */
return; Error ("`break' statement not within loop or switch");
return;
} }
g_space (oursp - l->sp);
g_jump (l->label); /* Correct the stack pointer if needed */
g_space (oursp - L->StackPtr);
/* Jump to the exit label of the loop */
g_jump (L->Label);
} }
@@ -215,28 +226,37 @@ static void dobreak (void)
static void docontinue (void) static void docontinue (void)
/* Handle 'continue' statement here */ /* Handle 'continue' statement here */
{ {
struct loopdesc* l; LoopDesc* L;
/* Skip the continue */
NextToken (); NextToken ();
if ((l = currentloop ()) == 0) {
/* Error: Not in loop */ /* Get the current loop descriptor */
return; L = CurrentLoop ();
if (L) {
/* Search for the correct loop */
do {
if (L->Loop) {
break;
}
L = L->Next;
} while (L);
} }
do {
if (l->loop) { /* Did we find it? */
break; if (L == 0) {
} Error ("`continue' statement not within a loop");
l = l->next; return;
} while (l);
if (l == 0) {
Error (ERR_UNEXPECTED_CONTINUE);
return;
} }
g_space (oursp - l->sp);
if (l->linc) { /* Correct the stackpointer if needed */
g_jump (l->linc); g_space (oursp - L->StackPtr);
/* Output the loop code */
if (L->linc) {
g_jump (L->linc);
} else { } else {
g_jump (l->loop); g_jump (L->Loop);
} }
} }
@@ -257,7 +277,7 @@ static void cascadeswitch (struct expent* eval)
/* Create a loop so we may break out, init labels */ /* Create a loop so we may break out, init labels */
exitlab = GetLabel (); exitlab = GetLabel ();
addloop (oursp, 0, exitlab, 0, 0); AddLoop (oursp, 0, exitlab, 0, 0);
/* Setup some variables needed in the loop below */ /* Setup some variables needed in the loop below */
flags = TypeOf (eval->e_tptr) | CF_CONST | CF_FORCECHAR; flags = TypeOf (eval->e_tptr) | CF_CONST | CF_FORCECHAR;
@@ -301,7 +321,7 @@ static void cascadeswitch (struct expent* eval)
/* Read the selector expression */ /* Read the selector expression */
constexpr (&lval); constexpr (&lval);
if (!IsClassInt (lval.e_tptr)) { if (!IsClassInt (lval.e_tptr)) {
Error (ERR_ILLEGAL_TYPE); Error ("Switch quantity not an integer");
} }
/* Check the range of the expression */ /* Check the range of the expression */
@@ -311,25 +331,25 @@ static void cascadeswitch (struct expent* eval)
case T_SCHAR: case T_SCHAR:
/* Signed char */ /* Signed char */
if (val < -128 || val > 127) { if (val < -128 || val > 127) {
Error (ERR_RANGE); Error ("Range error");
} }
break; break;
case T_UCHAR: case T_UCHAR:
if (val < 0 || val > 255) { if (val < 0 || val > 255) {
Error (ERR_RANGE); Error ("Range error");
} }
break; break;
case T_INT: case T_INT:
if (val < -32768 || val > 32767) { if (val < -32768 || val > 32767) {
Error (ERR_RANGE); Error ("Range error");
} }
break; break;
case T_UINT: case T_UINT:
if (val < 0 || val > 65535) { if (val < 0 || val > 65535) {
Error (ERR_RANGE); Error ("Range error");
} }
break; break;
@@ -410,7 +430,7 @@ static void cascadeswitch (struct expent* eval)
g_defloclabel (exitlab); g_defloclabel (exitlab);
/* End the loop */ /* End the loop */
delloop (); DelLoop ();
} }
@@ -443,7 +463,7 @@ static void tableswitch (struct expent* eval)
dlabel = 0; /* init */ dlabel = 0; /* init */
lab = GetLabel (); /* get exit */ lab = GetLabel (); /* get exit */
p = swtab; p = swtab;
addloop (oursp, 0, lab, 0, 0); AddLoop (oursp, 0, lab, 0, 0);
/* Jump behind the code for the CASE labels */ /* Jump behind the code for the CASE labels */
g_jump (lcase = GetLabel ()); g_jump (lcase = GetLabel ());
@@ -459,7 +479,7 @@ static void tableswitch (struct expent* eval)
NextToken (); NextToken ();
constexpr (&lval); constexpr (&lval);
if (!IsClassInt (lval.e_tptr)) { if (!IsClassInt (lval.e_tptr)) {
Error (ERR_ILLEGAL_TYPE); Error ("Switch quantity not an integer");
} }
p->sw_const = lval.e_const; p->sw_const = lval.e_const;
p->sw_lab = label; p->sw_lab = label;
@@ -515,7 +535,7 @@ static void tableswitch (struct expent* eval)
g_jump (dlabel); g_jump (dlabel);
} }
g_defloclabel (lab); g_defloclabel (lab);
delloop (); DelLoop ();
/* Free the allocated space for the labels */ /* Free the allocated space for the labels */
xfree (swtab); xfree (swtab);
@@ -565,7 +585,7 @@ static void dofor (void)
lab = GetLabel (); lab = GetLabel ();
linc = GetLabel (); linc = GetLabel ();
lstat = GetLabel (); lstat = GetLabel ();
addloop (oursp, loop, lab, linc, lstat); AddLoop (oursp, loop, lab, linc, lstat);
ConsumeLParen (); ConsumeLParen ();
if (curtok != TOK_SEMI) { /* exp1 */ if (curtok != TOK_SEMI) { /* exp1 */
expression (&lval1); expression (&lval1);
@@ -590,7 +610,7 @@ static void dofor (void)
statement (); statement ();
g_jump (linc); g_jump (linc);
g_defloclabel (lab); g_defloclabel (lab);
delloop (); DelLoop ();
} }

View File

@@ -176,7 +176,7 @@ static void CheckSymTable (SymTable* Tab)
if (Flags & SC_LABEL) { if (Flags & SC_LABEL) {
if ((Flags & SC_DEF) == 0) { if ((Flags & SC_DEF) == 0) {
/* Undefined label */ /* Undefined label */
Error (ERR_UNDEFINED_LABEL, Entry->Name); Error ("Undefined label: `%s'", Entry->Name);
} else if ((Flags & SC_REF) == 0) { } else if ((Flags & SC_REF) == 0) {
/* Defined but not used */ /* Defined but not used */
Warning ("`%s' is defined but never used", Entry->Name); Warning ("`%s' is defined but never used", Entry->Name);
@@ -536,10 +536,10 @@ SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab)
/* We do have an entry. This may be a forward, so check it. */ /* We do have an entry. This may be a forward, so check it. */
if ((Entry->Flags & SC_STRUCT) == 0) { if ((Entry->Flags & SC_STRUCT) == 0) {
/* Existing symbol is not a struct */ /* Existing symbol is not a struct */
Error (ERR_SYMBOL_KIND); Error ("Symbol `%s' is already different kind", Name);
} else if (Size > 0 && Entry->V.S.Size > 0) { } else if (Size > 0 && Entry->V.S.Size > 0) {
/* Both structs are definitions. */ /* Both structs are definitions. */
Error (ERR_MULTIPLE_DEFINITION, Name); Error ("Multiple definition for `%s'", Name);
} else { } else {
/* Define the struct size if it is given */ /* Define the struct size if it is given */
if (Size > 0) { if (Size > 0) {
@@ -574,9 +574,9 @@ SymEntry* AddEnumSym (const char* Name, int Val)
SymEntry* Entry = FindSymInTable (SymTab, Name, HashStr (Name)); SymEntry* Entry = FindSymInTable (SymTab, Name, HashStr (Name));
if (Entry) { if (Entry) {
if (Entry->Flags != SC_ENUM) { if (Entry->Flags != SC_ENUM) {
Error (ERR_SYMBOL_KIND); Error ("Symbol `%s' is already different kind", Name);
} else { } else {
Error (ERR_MULTIPLE_DEFINITION, Name); Error ("Multiple definition for `%s'", Name);
} }
return Entry; return Entry;
} }
@@ -608,7 +608,7 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags)
if ((Entry->Flags & SC_DEF) != 0 && (Flags & SC_DEF) != 0) { if ((Entry->Flags & SC_DEF) != 0 && (Flags & SC_DEF) != 0) {
/* Trying to define the label more than once */ /* Trying to define the label more than once */
Error (ERR_MULTIPLE_DEFINITION, Name); Error ("Label `%s' is defined more than once", Name);
} }
Entry->Flags |= Flags; Entry->Flags |= Flags;
@@ -639,7 +639,7 @@ SymEntry* AddLocalSym (const char* Name, type* Type, unsigned Flags, int Offs)
if (Entry) { if (Entry) {
/* We have a symbol with this name already */ /* We have a symbol with this name already */
Error (ERR_MULTIPLE_DEFINITION, Name); Error ("Multiple definition for `%s'", Name);
} else { } else {
@@ -675,7 +675,7 @@ SymEntry* AddGlobalSym (const char* Name, type* Type, unsigned Flags)
/* We have a symbol with this name already */ /* We have a symbol with this name already */
if (Entry->Flags & SC_TYPE) { if (Entry->Flags & SC_TYPE) {
Error (ERR_MULTIPLE_DEFINITION, Name); Error ("Multiple definition for `%s'", Name);
return Entry; return Entry;
} }
@@ -695,7 +695,7 @@ SymEntry* AddGlobalSym (const char* Name, type* Type, unsigned Flags)
if ((Size != 0 && ESize != 0) || if ((Size != 0 && ESize != 0) ||
TypeCmp (Type+DECODE_SIZE+1, EType+DECODE_SIZE+1) < TC_EQUAL) { TypeCmp (Type+DECODE_SIZE+1, EType+DECODE_SIZE+1) < TC_EQUAL) {
/* Types not identical: Conflicting types */ /* Types not identical: Conflicting types */
Error (ERR_CONFLICTING_TYPES, Name); Error ("Conflicting types for `%s'", Name);
} else { } else {
/* Check if we have a size in the existing definition */ /* Check if we have a size in the existing definition */
if (ESize == 0) { if (ESize == 0) {
@@ -707,7 +707,7 @@ SymEntry* AddGlobalSym (const char* Name, type* Type, unsigned Flags)
} else { } else {
/* New type must be identical */ /* New type must be identical */
if (TypeCmp (EType, Type) < TC_EQUAL) { if (TypeCmp (EType, Type) < TC_EQUAL) {
Error (ERR_CONFLICTING_TYPES, Name); Error ("Conflicting types for `%s'", Name);
} }
/* In case of a function, use the new type descriptor, since it /* In case of a function, use the new type descriptor, since it
@@ -772,7 +772,7 @@ void MakeZPSym (const char* Name)
if (Entry) { if (Entry) {
Entry->Flags |= SC_ZEROPAGE; Entry->Flags |= SC_ZEROPAGE;
} else { } else {
Error (ERR_UNDEFINED_SYMBOL, Name); Error ("Undefined symbol: `%s'", Name);
} }
} }