dereferencing function pointers

This commit is contained in:
pommicket 2022-02-03 21:46:36 -05:00
parent 3e6cacfb7c
commit fd02968c23
3 changed files with 15 additions and 8 deletions

View file

@ -216,14 +216,16 @@
#define TYPE_INT 7 #define TYPE_INT 7
#define TYPE_UNSIGNED_INT 8 #define TYPE_UNSIGNED_INT 8
#define TYPE_LONG 9 #define TYPE_LONG 9
#define TYPE_UNSIGNED_LONG 10 #define TYPE_UNSIGNED_LONG 0xa
#define TYPE_FLOAT 11 #define TYPE_FLOAT 0xb
; note that long double is treated the same as double. ; note that long double is treated the same as double.
#define TYPE_DOUBLE 12 #define TYPE_DOUBLE 0xc
#define TYPE_POINTER 13 #define TYPE_POINTER 0xd
#define TYPE_STRUCT 14 #define TYPE_STRUCT 0xe
#define TYPE_ARRAY 16 #define TYPE_ARRAY 0xf
#define TYPE_FUNCTION 17 #define TYPE_FUNCTION 0x10
; reading the first 16 bits of type data as a word will give this if the type refers to a function pointer.
#define TYPE2_FUNCTION_POINTER 0x100d
; types willl be initialized (in main) so that this refers to the type char* ; types willl be initialized (in main) so that this refers to the type char*
#define TYPE_POINTER_TO_CHAR 20 #define TYPE_POINTER_TO_CHAR 20

View file

@ -53,5 +53,7 @@ struct {
typedef int Blah[sizeof((B *)0)->c.y]; typedef int Blah[sizeof((B *)0)->c.y];
unsigned marker = 0xdeadbeef; unsigned marker = 0xdeadbeef;
typedef int (*FUNCTION)(void);
typedef int AAAA[sizeof*****((FUNCTION)0)];
/* typedef int X[sizeof(int)+4]; */ /* typedef int X[sizeof(int)+4]; */

View file

@ -1620,10 +1620,13 @@ function parse_expression
return out return out
:unary_dereference :unary_dereference
type_decay_array_to_pointer(*4a) type_decay_array_to_pointer(*4a)
; @TODO : dereferencing a function (annoyingly, p is the same as *p for function pointers) if *2p == TYPE2_FUNCTION_POINTER goto type_deref_fpointer
if *1p != TYPE_POINTER goto unary_bad_type if *1p != TYPE_POINTER goto unary_bad_type
*4type = *4a + 1 *4type = *4a + 1
return out return out
:type_deref_fpointer
*4type = *4a
return out
:unary_type_logical_not :unary_type_logical_not
type_decay_array_to_pointer(*4a) type_decay_array_to_pointer(*4a)
if *1p > TYPE_POINTER goto unary_bad_type if *1p > TYPE_POINTER goto unary_bad_type