1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-25 13:29:41 +00:00

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

View File

@ -145,8 +145,13 @@ typedef unsigned short type;
/* Sizes */
#define SIZEOF_CHAR 1
#define SIZEOF_SHORT 2
#define SIZEOF_INT 2
#define SIZEOF_LONG 4
#define SIZEOF_LONGLONG 8
#define SIZEOF_FLOAT 4
#define SIZEOF_DOUBLE 4
#define SIZEOF_PTR 2
/* Predefined type strings */
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_MLOCAL; /* Local array */
if (ConstSubAddr && CheckedSizeOf (lval->Type) == 1) {
if (ConstSubAddr && CheckedSizeOf (lval->Type) == SIZEOF_CHAR) {
type* SavedType;
/* 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);
/* 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
* with characters.
*/
if (CheckedSizeOf (lval->Type) == 1) {
if (CheckedSizeOf (lval->Type) == SIZEOF_CHAR) {
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
* with characters.
*/
if (CheckedSizeOf (lval->Type) == 1) {
if (CheckedSizeOf (lval->Type) == SIZEOF_CHAR) {
flags |= CF_FORCECHAR;
}

View File

@ -193,7 +193,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
F_AllocLocalSpace (CurrentFunc);
/* 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 */
if (evalexpr (Flags, hie1, &lval) == 0) {
@ -266,7 +266,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
} else {
/* 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 */
if (evalexpr (Flags, hie1, &lval) == 0) {

View File

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