From: cuz Date: Sat, 2 Nov 2002 12:39:10 +0000 (+0000) Subject: Use constants for datatype sizes X-Git-Tag: V2.12.0~2152 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=dadd136ae185971aa6277060e4ffc772ef64a4d9;p=cc65 Use constants for datatype sizes git-svn-id: svn://svn.cc65.org/cc65/trunk@1480 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 6aad02ea3..2080cc95f 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -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; } diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index f6a9ced19..bf03bab41 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -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 []; diff --git a/src/cc65/expr.c b/src/cc65/expr.c index a55486d8e..d60d1ac15 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -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; } diff --git a/src/cc65/locals.c b/src/cc65/locals.c index f8227d5d5..fcadb4e9a 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -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) { diff --git a/src/cc65/stmt.c b/src/cc65/stmt.c index 3ab5fd1d6..ef29b6f02 100644 --- a/src/cc65/stmt.c +++ b/src/cc65/stmt.c @@ -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)); }