From: cuz Date: Sun, 19 Feb 2006 15:53:11 +0000 (+0000) Subject: Cleanup. Added a few general purpose functions. X-Git-Tag: V2.12.0~144 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f196e7c5c93c3f29f1bb672d70be20e120d68729;p=cc65 Cleanup. Added a few general purpose functions. git-svn-id: svn://svn.cc65.org/cc65/trunk@3710 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index dbaf69e29..f4b5b0c96 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -286,185 +286,214 @@ Type* Indirect (Type* T); Type* ArrayToPtr (const Type* T); /* Convert an array to a pointer to it's first element */ +#if defined(HAVE_INLINE) +INLINE TypeCode GetType (const Type* T) +/* Get the raw type */ +{ + return (T->C & T_MASK_TYPE); +} +#else +# define GetType(T) ((T)->C & T_MASK_TYPE) +#endif + #if defined(HAVE_INLINE) INLINE int IsTypeChar (const Type* T) /* Return true if this is a character type */ { - return (T->C & T_MASK_TYPE) == T_TYPE_CHAR; + return (GetType (T) == T_TYPE_CHAR); } #else -# define IsTypeChar(T) (((T)->C & T_MASK_TYPE) == T_TYPE_CHAR) +# define IsTypeChar(T) (GetType (T) == T_TYPE_CHAR) #endif #if defined(HAVE_INLINE) INLINE int IsTypeInt (const Type* T) /* Return true if this is an int type (signed or unsigned) */ { - return (T->C & T_MASK_TYPE) == T_TYPE_INT; + return (GetType (T) == T_TYPE_INT); } #else -# define IsTypeInt(T) (((T)->C & T_MASK_TYPE) == T_TYPE_INT) +# define IsTypeInt(T) (GetType (T) == T_TYPE_INT) #endif #if defined(HAVE_INLINE) INLINE int IsTypeLong (const Type* T) /* Return true if this is a long type (signed or unsigned) */ { - return (T->C & T_MASK_TYPE) == T_TYPE_LONG; + return (GetType (T) == T_TYPE_LONG); } #else -# define IsTypeLong(T) (((T)->C & T_MASK_TYPE) == T_TYPE_LONG) +# define IsTypeLong(T) (GetType (T) == T_TYPE_LONG) #endif #if defined(HAVE_INLINE) INLINE int IsTypeFloat (const Type* T) /* Return true if this is a float type */ { - return (T->C & T_MASK_TYPE) == T_TYPE_FLOAT; + return (GetType (T) == T_TYPE_FLOAT); } #else -# define IsTypeFloat(T) (((T)->C & T_MASK_TYPE) == T_TYPE_FLOAT) +# define IsTypeFloat(T) (GetType (T) == T_TYPE_FLOAT) #endif #if defined(HAVE_INLINE) INLINE int IsTypeDouble (const Type* T) /* Return true if this is a double type */ { - return (T->C & T_MASK_TYPE) == T_TYPE_DOUBLE; + return (GetType (T) == T_TYPE_DOUBLE); } #else -# define IsTypeDouble(T) (((T)->C & T_MASK_TYPE) == T_TYPE_DOUBLE) +# define IsTypeDouble(T) (GetType (T) == T_TYPE_DOUBLE) #endif #if defined(HAVE_INLINE) INLINE int IsTypePtr (const Type* T) /* Return true if this is a pointer type */ { - return ((T->C & T_MASK_TYPE) == T_TYPE_PTR); + return (GetType (T) == T_TYPE_PTR); } #else -# define IsTypePtr(T) (((T)->C & T_MASK_TYPE) == T_TYPE_PTR) +# define IsTypePtr(T) (GetType (T) == T_TYPE_PTR) #endif #if defined(HAVE_INLINE) INLINE int IsTypeStruct (const Type* T) /* Return true if this is a struct type */ { - return ((T->C & T_MASK_TYPE) == T_TYPE_STRUCT); + return (GetType (T) == T_TYPE_STRUCT); } #else -# define IsTypeStruct(T) (((T)->C & T_MASK_TYPE) == T_TYPE_STRUCT) +# define IsTypeStruct(T) (GetType (T) == T_TYPE_STRUCT) #endif #if defined(HAVE_INLINE) INLINE int IsTypeUnion (const Type* T) /* Return true if this is a union type */ { - return ((T->C & T_MASK_TYPE) == T_TYPE_UNION); + return (GetType (T) == T_TYPE_UNION); } #else -# define IsTypeUnion(T) (((T)->C & T_MASK_TYPE) == T_TYPE_UNION) +# define IsTypeUnion(T) (GetType (T) == T_TYPE_UNION) #endif #if defined(HAVE_INLINE) INLINE int IsTypeArray (const Type* T) /* Return true if this is an array type */ { - return ((T->C & T_MASK_TYPE) == T_TYPE_ARRAY); + return (GetType (T) == T_TYPE_ARRAY); } #else -# define IsTypeArray(T) (((T)->C & T_MASK_TYPE) == T_TYPE_ARRAY) +# define IsTypeArray(T) (GetType (T) == T_TYPE_ARRAY) #endif #if defined(HAVE_INLINE) INLINE int IsTypeVoid (const Type* T) /* Return true if this is a void type */ { - return (T->C & T_MASK_TYPE) == T_TYPE_VOID; + return (GetType (T) == T_TYPE_VOID); } #else -# define IsTypeVoid(T) (((T)->C & T_MASK_TYPE) == T_TYPE_VOID) +# define IsTypeVoid(T) (GetType (T) == T_TYPE_VOID) #endif #if defined(HAVE_INLINE) INLINE int IsTypeFunc (const Type* T) /* Return true if this is a function class */ { - return ((T->C & T_MASK_TYPE) == T_TYPE_FUNC); + return (GetType (T) == T_TYPE_FUNC); } #else -# define IsTypeFunc(T) (((T)->C & T_MASK_TYPE) == T_TYPE_FUNC) +# define IsTypeFunc(T) (GetType (T) == T_TYPE_FUNC) #endif #if defined(HAVE_INLINE) INLINE int IsTypeFuncPtr (const Type* T) /* Return true if this is a function pointer */ { - return ((T[0].C & T_MASK_TYPE) == T_TYPE_PTR && (T[1].C & T_MASK_TYPE) == T_TYPE_FUNC); + return (IsTypePtr (T) && IsTypeFunc (T+1)); } #else -# define IsTypeFuncPtr(T) \ - ((((T)[0].C & T_MASK_TYPE) == T_TYPE_PTR) && (((T)[1].C & T_MASK_TYPE) == T_TYPE_FUNC)) +# define IsTypeFuncPtr(T) (IsTypePtr (T) && IsTypeFunc (T+1)) +#endif + +#if defined(HAVE_INLINE) +INLINE TypeCode GetClass (const Type* T) +/* Get the class of a type string */ +{ + return (T->C & T_MASK_CLASS); +} +#else +# define GetClass(T) ((T)->C & T_MASK_CLASS) #endif #if defined(HAVE_INLINE) INLINE int IsClassInt (const Type* T) /* Return true if this is an integer type */ { - return (T->C & T_MASK_CLASS) == T_CLASS_INT; + return (GetClass (T) == T_CLASS_INT); } #else -# define IsClassInt(T) (((T)->C & T_MASK_CLASS) == T_CLASS_INT) +# define IsClassInt(T) (GetClass (T) == T_CLASS_INT) #endif #if defined(HAVE_INLINE) INLINE int IsClassFloat (const Type* T) /* Return true if this is a float type */ { - return (T->C & T_MASK_CLASS) == T_CLASS_FLOAT; + return (GetClass (T) == T_CLASS_FLOAT); } #else -# define IsClassFloat(T) (((T)->C & T_MASK_CLASS) == T_CLASS_FLOAT) +# define IsClassFloat(T) (GetClass (T) == T_CLASS_FLOAT) #endif #if defined(HAVE_INLINE) INLINE int IsClassPtr (const Type* T) /* Return true if this is a pointer type */ { - return (T->C & T_MASK_CLASS) == T_CLASS_PTR; + return (GetClass (T) == T_CLASS_PTR); } #else -# define IsClassPtr(T) (((T)->C & T_MASK_CLASS) == T_CLASS_PTR) +# define IsClassPtr(T) (GetClass (T) == T_CLASS_PTR) #endif #if defined(HAVE_INLINE) INLINE int IsClassStruct (const Type* T) /* Return true if this is a struct type */ { - return (T->C & T_MASK_CLASS) == T_CLASS_STRUCT; + return (GetClass (T) == T_CLASS_STRUCT); } #else -# define IsClassStruct(T) (((T)->C & T_MASK_CLASS) == T_CLASS_STRUCT) +# define IsClassStruct(T) (GetClass (T) == T_CLASS_STRUCT) #endif #if defined(HAVE_INLINE) INLINE int IsClassFunc (const Type* T) /* Return true if this is a function type */ { - return (T->C & T_MASK_CLASS) == T_CLASS_FUNC; + return (GetClass (T) == T_CLASS_FUNC); +} +#else +# define IsClassFunc(T) (GetClass (T) == T_CLASS_FUNC) +#endif + +#if defined(HAVE_INLINE) +INLINE TypeCode GetSignedness (const Type* T) +/* Get the sign of a type */ +{ + return (T->C & T_MASK_SIGN); } #else -# define IsClassFunc(T) (((T)->C & T_MASK_CLASS) == T_CLASS_FUNC) +# define GetSignedness(T) ((T)->C & T_MASK_SIGN) #endif #if defined(HAVE_INLINE) INLINE int IsSignUnsigned (const Type* T) /* Return true if this is an unsigned type */ { - return (T->C & T_MASK_SIGN) == T_SIGN_UNSIGNED; + return (GetSignedness (T) == T_SIGN_UNSIGNED); } #else -# define IsSignUnsigned(T) (((T)->C & T_MASK_SIGN) == T_SIGN_UNSIGNED) +# define IsSignUnsigned(T) (GetSignedness (T) == T_SIGN_UNSIGNED) #endif TypeCode GetQualifier (const Type* T) attribute ((const)); @@ -477,7 +506,7 @@ INLINE int IsQualConst (const Type* T) return (GetQualifier (T) & T_QUAL_CONST) != 0; } #else -# define IsQualConst(T) (((T)->C & T_QUAL_CONST) != 0) +# define IsQualConst(T) (GetQualifier (T) & T_QUAL_CONST) != 0) #endif #if defined(HAVE_INLINE) @@ -487,7 +516,17 @@ INLINE int IsQualVolatile (const Type* T) return (GetQualifier (T) & T_QUAL_VOLATILE) != 0; } #else -# define IsQualVolatile(T) (((T)->C & T_QUAL_VOLATILE) != 0) +# define IsQualVolatile(T) (GetQualifier (T) & T_QUAL_VOLATILE) != 0) +#endif + +#if defined(HAVE_INLINE) +INLINE int IsQualRestrict (const Type* T) +/* Return true if the given type has a restrict qualifier */ +{ + return (GetQualifier (T) & T_QUAL_RESTRICT) != 0; +} +#else +# define IsQualRestrict(T) (GetQualifier (T) & T_QUAL_RESTRICT) != 0) #endif int IsFastCallFunc (const Type* T) attribute ((const)); @@ -500,36 +539,6 @@ int IsVariadicFunc (const Type* T) attribute ((const)); * variable parameter list */ -#if defined(HAVE_INLINE) -INLINE TypeCode GetType (const Type* T) -/* Get the raw type */ -{ - return (T->C & T_MASK_TYPE); -} -#else -# define GetType(T) ((T)->C & T_MASK_TYPE) -#endif - -#if defined(HAVE_INLINE) -INLINE TypeCode GetClass (const Type* T) -/* Get the class of a type string */ -{ - return (T->C & T_MASK_CLASS); -} -#else -# define GetClass(T) ((T)->C & T_MASK_CLASS) -#endif - -#if defined(HAVE_INLINE) -INLINE TypeCode GetSignedness (const Type* T) -/* Get the sign of a type */ -{ - return (T->C & T_MASK_SIGN); -} -#else -# define GetSignedness(T) ((T)->C & T_MASK_SIGN) -#endif - #if defined(HAVE_INLINE) INLINE TypeCode GetSizeModifier (const Type* T) /* Get the size modifier of a type */ diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 9c98cbab0..2af76831c 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1146,7 +1146,7 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode) -void ParseDeclSpec (DeclSpec* D, unsigned DefStorage, int DefType) +void ParseDeclSpec (DeclSpec* D, unsigned DefStorage, long DefType) /* Parse a declaration specification */ { TypeCode Qualifiers; diff --git a/src/cc65/declare.h b/src/cc65/declare.h index be7443340..606ca36d4 100644 --- a/src/cc65/declare.h +++ b/src/cc65/declare.h @@ -92,7 +92,7 @@ Type* ParseType (Type* Type); void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode); /* Parse a variable, type or function declaration */ -void ParseDeclSpec (DeclSpec* D, unsigned DefStorage, int DefType); +void ParseDeclSpec (DeclSpec* D, unsigned DefStorage, long DefType); /* Parse a declaration specification */ void CheckEmptyDecl (const DeclSpec* D); @@ -104,7 +104,7 @@ void CheckEmptyDecl (const DeclSpec* D); unsigned ParseInit (Type* T); /* Parse initialization of variables. Return the number of initialized data * bytes. - */ + */ diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index 6516a396c..e8e13ee6a 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -199,6 +199,15 @@ static int SkipWhite (void) +int TokIsFuncSpec (const Token* T) +/* Return true if the token is a function specifier */ +{ + return (T->Tok == TOK_INLINE) || (T->Tok == TOK_FASTCALL) || + (T->Tok == TOK_NEAR) || (T->Tok == TOK_FAR); +} + + + void SymName (char* S) /* Read a symbol from the input stream. The first character must have been * checked before calling this function. The buffer is expected to be at diff --git a/src/cc65/scanner.h b/src/cc65/scanner.h index c22c796dc..b98170697 100644 --- a/src/cc65/scanner.h +++ b/src/cc65/scanner.h @@ -56,11 +56,13 @@ typedef enum token_t { TOK_CEOF, /* Storage specifiers */ - TOK_AUTO, + TOK_FIRST_STORAGE_CLASS, + TOK_AUTO = TOK_FIRST_STORAGE_CLASS, TOK_EXTERN, TOK_REGISTER, TOK_STATIC, TOK_TYPEDEF, + TOK_LAST_STORAGE_CLASS = TOK_TYPEDEF, /* Tokens denoting type qualifiers */ TOK_FIRST_TYPEQUAL, @@ -71,6 +73,7 @@ typedef enum token_t { /* Function specifiers */ TOK_INLINE, + TOK_FASTCALL, /* Tokens denoting types */ TOK_FIRST_TYPE, @@ -167,7 +170,6 @@ typedef enum token_t { TOK_ATTRIBUTE, TOK_FAR, TOK_NEAR, - TOK_FASTCALL, TOK_A, TOK_X, TOK_Y, @@ -207,6 +209,17 @@ extern Token NextTok; /* The next token */ +#if defined(HAVE_INLINE) +INLINE int TokIsStorageClass (const Token* T) +/* Return true if the token is a storage class specifier */ +{ + return (T->Tok >= TOK_FIRST_STORAGE_CLASS && T->Tok <= TOK_LAST_STORAGE_CLASS); +} +#else +# define TokIsStorageClass(T) \ + ((T)->Tok >= TOK_FIRST_STORAGE_CLASS && (T)->Tok <= TOK_LAST_STORAGE_CLASS) +#endif + #if defined(HAVE_INLINE) INLINE int TokIsType (const Token* T) /* Return true if the token is a type */ @@ -227,6 +240,9 @@ INLINE int TokIsTypeQual (const Token* T) # define TokIsTypeQual(T) ((T)->Tok >= TOK_FIRST_TYPEQUAL && (T)->Tok <= TOK_LAST_TYPEQUAL) #endif +int TokIsFuncSpec (const Token* T); +/* Return true if the token is a function specifier */ + void SymName (char* S); /* Read a symbol from the input stream. The first character must have been * checked before calling this function. The buffer is expected to be at