1 /***************************************************************/ 2 /* */ 3 /* EXPR.H */ 4 /* */ 5 /* Contains a few definitions used by expression evaluator. */ 6 /* */ 7 /* This file is part of REMIND. */ 8 /* Copyright (C) 1992-2021 by Dianne Skoll */ 9 /* */ 10 /***************************************************************/ 11 12 /* Define the types of values */ 13 #define ERR_TYPE 0 14 #define INT_TYPE 1 15 #define TIME_TYPE 2 16 #define DATE_TYPE 3 17 #define STR_TYPE 4 18 #define DATETIME_TYPE 5 19 #define SPECIAL_TYPE 6 /* Only for system variables */ 20 21 /* Define stuff for parsing expressions */ 22 #define BEG_OF_EXPR '[' 23 #define END_OF_EXPR ']' 24 #define COMMA ',' 25 26 #define UN_OP 0 /* Unary operator */ 27 #define BIN_OP 1 /* Binary Operator */ 28 #define FUNC 2 /* Function */ 29 30 /* Make the pushing and popping of values and operators in-line code 31 for speed. BEWARE: These macros invoke return if an error happens ! */ 32 33 #define PushOpStack(op) \ 34 if (OpStackPtr >= OP_STACK_SIZE) \ 35 return E_OP_STK_OVER; \ 36 else \ 37 OpStack[OpStackPtr++] = (op) 38 39 #define PopOpStack(op) \ 40 if (OpStackPtr <= 0) \ 41 return E_OP_STK_UNDER; \ 42 else \ 43 (op) = OpStack[--OpStackPtr] 44 45 #define PushValStack(val) \ 46 if (ValStackPtr >= VAL_STACK_SIZE) \ 47 return E_VA_STK_OVER; \ 48 else \ 49 ValStack[ValStackPtr++] = (val) 50 51 #define PopValStack(val) \ 52 if (ValStackPtr <= 0) \ 53 return E_VA_STK_UNDER; \ 54 else \ 55 (val) = ValStack[--ValStackPtr] 56 57 /* These functions are in utils.c and are used to detect overflow 58 in various arithmetic operators. They have to be in separate 59 functions with extern linkage to defeat compiler optimizations 60 that would otherwise break the overflow checks. */ 61 extern int _private_div(int a, int b); 62 extern int _private_add_overflow(int result, int b, int old); 63 extern int _private_sub_overflow(int result, int b, int old); 64 extern int _private_unminus_overflow(int a, int b); 65