From d841bbe49825f604d0d52365675d2332ed76fae7 Mon Sep 17 00:00:00 2001 From: acqn Date: Sun, 2 Aug 2020 21:51:32 +0800 Subject: [PATCH] Utility to check for castability. --- src/cc65/datatype.c | 16 ++++++++++++++++ src/cc65/datatype.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index d1c34c825..cffec7880 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -1018,6 +1018,22 @@ Type* ArrayToPtr (Type* T) +int IsClassArithmetic (const Type* T) +/* Return true if this is an arithmetic type */ +{ + return IsClassInt (T) || IsClassFloat (T); +} + + + +int IsCastType (const Type* T) +/* Return true if this type can be used for casting */ +{ + return IsClassArithmetic (T) || IsClassPtr (T) || IsTypeVoid (T); +} + + + int IsVariadicFunc (const Type* T) /* Return true if this is a function type or pointer to function type with ** variable parameter list diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index ad382d50f..66f1b8b05 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -578,6 +578,12 @@ INLINE int IsClassFunc (const Type* T) # define IsClassFunc(T) (GetClass (T) == T_CLASS_FUNC) #endif +int IsClassArithmetic (const Type* T); +/* Return true if this is an arithmetic type */ + +int IsCastType (const Type* T); +/* Return true if this type can be used for casting */ + #if defined(HAVE_INLINE) INLINE TypeCode GetRawSignedness (const Type* T) /* Get the raw signedness of a type */