Use constants for datatype sizes

git-svn-id: svn://svn.cc65.org/cc65/trunk@1480 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2002-11-02 12:39:10 +00:00
parent 2275e4c2a8
commit dadd136ae1
5 changed files with 28 additions and 14 deletions

View File

@@ -442,30 +442,36 @@ unsigned SizeOf (const type* T)
case T_SCHAR: case T_SCHAR:
case T_UCHAR: case T_UCHAR:
return 1; return SIZEOF_CHAR;
case T_SHORT: case T_SHORT:
case T_USHORT: case T_USHORT:
return SIZEOF_SHORT;
case T_INT: case T_INT:
case T_UINT: case T_UINT:
return SIZEOF_INT;
case T_PTR: case T_PTR:
case T_FUNC: /* Maybe pointer to function */ case T_FUNC: /* Maybe pointer to function */
return 2; return SIZEOF_PTR;
case T_LONG: case T_LONG:
case T_ULONG: case T_ULONG:
return 4; return SIZEOF_LONG;
case T_LONGLONG: case T_LONGLONG:
case T_ULONGLONG: case T_ULONGLONG:
return 8; return SIZEOF_LONGLONG;
case T_ENUM: case T_ENUM:
return 2; return SIZEOF_INT;
case T_FLOAT: case T_FLOAT:
return SIZEOF_FLOAT;
case T_DOUBLE: case T_DOUBLE:
return 4; return SIZEOF_DOUBLE;
case T_STRUCT: case T_STRUCT:
case T_UNION: case T_UNION:
@@ -509,7 +515,7 @@ unsigned CheckedSizeOf (const type* T)
unsigned Size = SizeOf (T); unsigned Size = SizeOf (T);
if (Size == 0) { if (Size == 0) {
Error ("Size of data type is unknown"); Error ("Size of data type is unknown");
Size = 1; Size = SIZEOF_CHAR; /* Don't return zero */
} }
return Size; return Size;
} }
@@ -525,7 +531,7 @@ unsigned CheckedPSizeOf (const type* T)
unsigned Size = PSizeOf (T); unsigned Size = PSizeOf (T);
if (Size == 0) { if (Size == 0) {
Error ("Size of data type is unknown"); Error ("Size of data type is unknown");
Size = 1; Size = SIZEOF_CHAR; /* Don't return zero */
} }
return Size; return Size;
} }

View File

@@ -145,8 +145,13 @@ typedef unsigned short type;
/* Sizes */ /* Sizes */
#define SIZEOF_CHAR 1 #define SIZEOF_CHAR 1
#define SIZEOF_SHORT 2
#define SIZEOF_INT 2 #define SIZEOF_INT 2
#define SIZEOF_LONG 4 #define SIZEOF_LONG 4
#define SIZEOF_LONGLONG 8
#define SIZEOF_FLOAT 4
#define SIZEOF_DOUBLE 4
#define SIZEOF_PTR 2
/* Predefined type strings */ /* Predefined type strings */
extern type type_uchar []; extern type type_uchar [];

View File

@@ -1194,12 +1194,12 @@ static int arrayref (int k, ExprDesc* lval)
(rflags & E_MGLOBAL) != 0 || /* Static array, or ... */ (rflags & E_MGLOBAL) != 0 || /* Static array, or ... */
rflags == E_MLOCAL; /* Local array */ rflags == E_MLOCAL; /* Local array */
if (ConstSubAddr && CheckedSizeOf (lval->Type) == 1) { if (ConstSubAddr && CheckedSizeOf (lval->Type) == SIZEOF_CHAR) {
type* SavedType; type* SavedType;
/* Reverse the order of evaluation */ /* Reverse the order of evaluation */
unsigned flags = (CheckedSizeOf (lval2.Type) == 1)? CF_CHAR : CF_INT; unsigned flags = (CheckedSizeOf (lval2.Type) == SIZEOF_CHAR)? CF_CHAR : CF_INT;
RemoveCode (Mark2); RemoveCode (Mark2);
/* Get a pointer to the array into the primary. We have changed /* Get a pointer to the array into the primary. We have changed
@@ -2788,7 +2788,7 @@ static void opeq (const GenDesc* Gen, ExprDesc *lval, int k)
/* If the lhs is character sized, the operation may be later done /* If the lhs is character sized, the operation may be later done
* with characters. * with characters.
*/ */
if (CheckedSizeOf (lval->Type) == 1) { if (CheckedSizeOf (lval->Type) == SIZEOF_CHAR) {
flags |= CF_FORCECHAR; flags |= CF_FORCECHAR;
} }
@@ -2810,7 +2810,7 @@ static void opeq (const GenDesc* Gen, ExprDesc *lval, int k)
/* If the lhs is character sized, the operation may be later done /* If the lhs is character sized, the operation may be later done
* with characters. * with characters.
*/ */
if (CheckedSizeOf (lval->Type) == 1) { if (CheckedSizeOf (lval->Type) == SIZEOF_CHAR) {
flags |= CF_FORCECHAR; flags |= CF_FORCECHAR;
} }

View File

@@ -193,7 +193,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
F_AllocLocalSpace (CurrentFunc); F_AllocLocalSpace (CurrentFunc);
/* Setup the type flags for the assignment */ /* Setup the type flags for the assignment */
Flags = (Size == 1)? CF_FORCECHAR : CF_NONE; Flags = (Size == SIZEOF_CHAR)? CF_FORCECHAR : CF_NONE;
/* Get the expression into the primary */ /* Get the expression into the primary */
if (evalexpr (Flags, hie1, &lval) == 0) { if (evalexpr (Flags, hie1, &lval) == 0) {
@@ -266,7 +266,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
} else { } else {
/* Setup the type flags for the assignment */ /* Setup the type flags for the assignment */
Flags = (Size == 1)? CF_FORCECHAR : CF_NONE; Flags = (Size == SIZEOF_CHAR)? CF_FORCECHAR : CF_NONE;
/* Get the expression into the primary */ /* Get the expression into the primary */
if (evalexpr (Flags, hie1, &lval) == 0) { if (evalexpr (Flags, hie1, &lval) == 0) {

View File

@@ -242,6 +242,8 @@ static void ReturnStatement (void)
NextToken (); NextToken ();
if (CurTok.Tok != TOK_SEMI) { if (CurTok.Tok != TOK_SEMI) {
/* Check if the function has a return value declared */
if (F_HasVoidReturn (CurrentFunc)) { if (F_HasVoidReturn (CurrentFunc)) {
Error ("Returning a value in function with return type void"); Error ("Returning a value in function with return type void");
} }
@@ -253,6 +255,7 @@ static void ReturnStatement (void)
if (!F_HasVoidReturn (CurrentFunc)) { if (!F_HasVoidReturn (CurrentFunc)) {
assignadjust (F_GetReturnType (CurrentFunc), &lval); assignadjust (F_GetReturnType (CurrentFunc), &lval);
} }
} else if (!F_HasVoidReturn (CurrentFunc) && !F_HasOldStyleIntRet (CurrentFunc)) { } else if (!F_HasVoidReturn (CurrentFunc) && !F_HasOldStyleIntRet (CurrentFunc)) {
Error ("Function `%s' must return a value", F_GetFuncName (CurrentFunc)); Error ("Function `%s' must return a value", F_GetFuncName (CurrentFunc));
} }