From 062a84b758b90135e2610a6fefd886b83c2881b3 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Mon, 2 Dec 2024 09:50:33 -0500 Subject: [PATCH] Simplify HAS_DATE and HAS_TIME macros by making type values into bitmasks. --- src/funcs.c | 4 ++-- src/types.h | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/funcs.c b/src/funcs.c index 0a075d85..73b6254b 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -210,8 +210,8 @@ static int CacheHebYear, CacheHebMon, CacheHebDay; /* Macro for getting time part of a time or datetime value */ #define TIMEPART(x) ((x).type == TIME_TYPE ? (x).v.val : ((x).v.val % MINUTES_PER_DAY)) -#define HASDATE(x) ((x).type == DATE_TYPE || (x).type == DATETIME_TYPE) -#define HASTIME(x) ((x).type == TIME_TYPE || (x).type == DATETIME_TYPE) +#define HASDATE(x) ((x).type & DATE_TYPE) +#define HASTIME(x) ((x).type & TIME_TYPE) /* Macro for copying a value while destroying original copy */ #define DCOPYVAL(x, y) ( (x) = (y), (y).type = ERR_TYPE ) diff --git a/src/types.h b/src/types.h index 71199527..9836e0bf 100644 --- a/src/types.h +++ b/src/types.h @@ -15,15 +15,18 @@ typedef struct udf_struct UserFunc; -/* Define the types of values */ -#define ERR_TYPE 0 -#define INT_TYPE 1 -#define TIME_TYPE 2 -#define DATE_TYPE 3 -#define STR_TYPE 4 -#define DATETIME_TYPE 5 -#define SPECIAL_TYPE 6 /* Only for system variables */ -#define CONST_INT_TYPE 7 /* Only for system variables */ +/* Define the types of values. We use bitmasks so we can define + DATETIME_TYPE as a combo of DATE_TYPE and TIME_TYPE */ + +#define ERR_TYPE 0x0 +#define INT_TYPE 0x1 +#define TIME_TYPE 0x2 +#define DATE_TYPE 0x4 +/* DATETIME_TYPE has both DATE and TIME bits turned on */ +#define DATETIME_TYPE (TIME_TYPE | DATE_TYPE) +#define STR_TYPE 0x8 +#define SPECIAL_TYPE 0x10 /* Only for system variables */ +#define CONST_INT_TYPE 0x20 /* Only for system variables */ #define BEG_OF_EXPR '[' #define END_OF_EXPR ']'