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,220 +286,6 @@ 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 int IsTypeChar (const Type* T) -/* Return true if this is a character type */ -{ - return (T->C & T_MASK_TYPE) == T_TYPE_CHAR; -} -#else -# define IsTypeChar(T) (((T)->C & T_MASK_TYPE) == 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; -} -#else -# define IsTypeInt(T) (((T)->C & T_MASK_TYPE) == 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; -} -#else -# define IsTypeLong(T) (((T)->C & T_MASK_TYPE) == 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; -} -#else -# define IsTypeFloat(T) (((T)->C & T_MASK_TYPE) == 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; -} -#else -# define IsTypeDouble(T) (((T)->C & T_MASK_TYPE) == 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); -} -#else -# define IsTypePtr(T) (((T)->C & T_MASK_TYPE) == 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); -} -#else -# define IsTypeStruct(T) (((T)->C & T_MASK_TYPE) == 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); -} -#else -# define IsTypeUnion(T) (((T)->C & T_MASK_TYPE) == 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); -} -#else -# define IsTypeArray(T) (((T)->C & T_MASK_TYPE) == 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; -} -#else -# define IsTypeVoid(T) (((T)->C & T_MASK_TYPE) == 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); -} -#else -# define IsTypeFunc(T) (((T)->C & T_MASK_TYPE) == 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); -} -#else -# define IsTypeFuncPtr(T) \ - ((((T)[0].C & T_MASK_TYPE) == T_TYPE_PTR) && (((T)[1].C & T_MASK_TYPE) == T_TYPE_FUNC)) -#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; -} -#else -# define IsClassInt(T) (((T)->C & T_MASK_CLASS) == 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; -} -#else -# define IsClassFloat(T) (((T)->C & T_MASK_CLASS) == 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; -} -#else -# define IsClassPtr(T) (((T)->C & T_MASK_CLASS) == 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; -} -#else -# define IsClassStruct(T) (((T)->C & T_MASK_CLASS) == 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; -} -#else -# define IsClassFunc(T) (((T)->C & T_MASK_CLASS) == T_CLASS_FUNC) -#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; -} -#else -# define IsSignUnsigned(T) (((T)->C & T_MASK_SIGN) == T_SIGN_UNSIGNED) -#endif - -TypeCode GetQualifier (const Type* T) attribute ((const)); -/* Get the qualifier from the given type string */ - -#if defined(HAVE_INLINE) -INLINE int IsQualConst (const Type* T) -/* Return true if the given type has a const memory image */ -{ - return (GetQualifier (T) & T_QUAL_CONST) != 0; -} -#else -# define IsQualConst(T) (((T)->C & T_QUAL_CONST) != 0) -#endif - -#if defined(HAVE_INLINE) -INLINE int IsQualVolatile (const Type* T) -/* Return true if the given type has a volatile type qualifier */ -{ - return (GetQualifier (T) & T_QUAL_VOLATILE) != 0; -} -#else -# define IsQualVolatile(T) (((T)->C & T_QUAL_VOLATILE) != 0) -#endif - -int IsFastCallFunc (const Type* T) attribute ((const)); -/* Return true if this is a function type or pointer to function with - * __fastcall__ calling conventions - */ - -int IsVariadicFunc (const Type* T) attribute ((const)); -/* Return true if this is a function type or pointer to function type with - * variable parameter list - */ - #if defined(HAVE_INLINE) INLINE TypeCode GetType (const Type* T) /* Get the raw type */ @@ -510,6 +296,126 @@ INLINE TypeCode GetType (const Type* T) # 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 (GetType (T) == T_TYPE_CHAR); +} +#else +# 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 (GetType (T) == T_TYPE_INT); +} +#else +# 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 (GetType (T) == T_TYPE_LONG); +} +#else +# 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 (GetType (T) == T_TYPE_FLOAT); +} +#else +# 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 (GetType (T) == T_TYPE_DOUBLE); +} +#else +# 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 (GetType (T) == T_TYPE_PTR); +} +#else +# 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 (GetType (T) == T_TYPE_STRUCT); +} +#else +# 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 (GetType (T) == T_TYPE_UNION); +} +#else +# 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 (GetType (T) == T_TYPE_ARRAY); +} +#else +# 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 (GetType (T) == T_TYPE_VOID); +} +#else +# 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 (GetType (T) == T_TYPE_FUNC); +} +#else +# 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 (IsTypePtr (T) && IsTypeFunc (T+1)); +} +#else +# 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 */ @@ -520,6 +426,56 @@ INLINE TypeCode GetClass (const Type* T) # 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 (GetClass (T) == T_CLASS_INT); +} +#else +# 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 (GetClass (T) == T_CLASS_FLOAT); +} +#else +# 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 (GetClass (T) == T_CLASS_PTR); +} +#else +# 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 (GetClass (T) == T_CLASS_STRUCT); +} +#else +# 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 (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 */ @@ -530,6 +486,59 @@ INLINE TypeCode GetSignedness (const Type* T) # 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 (GetSignedness (T) == T_SIGN_UNSIGNED); +} +#else +# define IsSignUnsigned(T) (GetSignedness (T) == T_SIGN_UNSIGNED) +#endif + +TypeCode GetQualifier (const Type* T) attribute ((const)); +/* Get the qualifier from the given type string */ + +#if defined(HAVE_INLINE) +INLINE int IsQualConst (const Type* T) +/* Return true if the given type has a const memory image */ +{ + return (GetQualifier (T) & T_QUAL_CONST) != 0; +} +#else +# define IsQualConst(T) (GetQualifier (T) & T_QUAL_CONST) != 0) +#endif + +#if defined(HAVE_INLINE) +INLINE int IsQualVolatile (const Type* T) +/* Return true if the given type has a volatile type qualifier */ +{ + return (GetQualifier (T) & T_QUAL_VOLATILE) != 0; +} +#else +# 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)); +/* Return true if this is a function type or pointer to function with + * __fastcall__ calling conventions + */ + +int IsVariadicFunc (const Type* T) attribute ((const)); +/* Return true if this is a function type or pointer to function type with + * variable parameter list + */ + #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