Skip to content

Commit

Permalink
type of sizeof fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Mar 4, 2024
1 parent 75a810d commit 503a798
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
Binary file added source - Shortcut.lnk
Binary file not shown.
2 changes: 1 addition & 1 deletion src/expressions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ struct expression* owner unary_expression(struct parser_ctx* ctx)
parser_match_tk(ctx, '(');
new_expression->type_name = type_name(ctx);

new_expression->type = type_make_int();
new_expression->type = make_size_t_type();

parser_match_tk(ctx, ')');

Expand Down
11 changes: 1 addition & 10 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
static_assert(_Generic(typeof(-*""), int : 1));
#pragma cake diagnostic check "-Warray-indirection"

static_assert(_Generic(typeof(~false), int : 1));
static_assert(_Generic(typeof(~0ULL), unsigned long long: 1));
static_assert(_Generic(typeof(~*""), int : 1));
#pragma cake diagnostic check "-Warray-indirection"

static_assert(_Generic(typeof(~(unsigned char)0), int : 1));
static_assert(_Generic(typeof(~(unsigned int)0), unsigned int : 1));
typeof(sizeof 1) i;
8 changes: 8 additions & 0 deletions src/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,14 @@ struct type type_make_int_bool_like()
return t;
}

struct type make_size_t_type()
{
struct type t = { 0 };
t.type_specifier_flags = CAKE_SIZE_T_TYPE_SPECIFIER;
t.category = TYPE_CATEGORY_ITSELF;
return t;
}

struct type type_make_int()
{
struct type t = { 0 };
Expand Down
27 changes: 23 additions & 4 deletions src/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,29 @@ enum type_specifier_flags


};

#ifdef _WIN32
//Windows
#define CAKE_WCHAR_T_TYPE_SPECIFIER (TYPE_SPECIFIER_UNSIGNED | TYPE_SPECIFIER_SHORT)
#else
#define CAKE_WCHAR_T_TYPE_SPECIFIER (TYPE_SPECIFIER_INT)

#define CAKE_WCHAR_T_TYPE_SPECIFIER (TYPE_SPECIFIER_UNSIGNED | TYPE_SPECIFIER_SHORT)

#ifdef _WIN64
#define CAKE_SIZE_T_TYPE_SPECIFIER (TYPE_SPECIFIER_UNSIGNED | TYPE_SPECIFIER_INT64)
#else
#define CAKE_SIZE_T_TYPE_SPECIFIER (TYPE_SPECIFIER_UNSIGNED | TYPE_SPECIFIER_INT)
#endif

#else

#define CAKE_WCHAR_T_TYPE_SPECIFIER (TYPE_SPECIFIER_INT)

#if __x86_64__
/* 64-bit */
#define CAKE_SIZE_T_TYPE_SPECIFIER (TYPE_SPECIFIER_UNSIGNED | TYPE_SPECIFIER_LONG_LONG)
#else
#define CAKE_SIZE_T_TYPE_SPECIFIER (TYPE_SPECIFIER_UNSIGNED | TYPE_SPECIFIER_INT)
#endif


#endif


Expand Down Expand Up @@ -265,6 +283,7 @@ struct type type_make_size_t();
struct type type_make_enumerator(const struct enum_specifier* enum_specifier);
struct type make_void_type();
struct type make_void_ptr_type();
struct type make_size_t_type();

struct type get_function_return_type(const struct type* p_type);

Expand Down

0 comments on commit 503a798

Please sign in to comment.