summaryrefslogtreecommitdiff
path: root/src/parser/parser_type.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-02-01 14:01:51 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-02-01 14:01:51 +0000
commitfbfce63744882d48ea2fc514ab1594000254db80 (patch)
treecc7949dab2149d829d3c04e3d542553ed883593f /src/parser/parser_type.c
parenteafd8c67012ea253436b79f703dc0702046703f8 (diff)
Related to #138
Diffstat (limited to 'src/parser/parser_type.c')
-rw-r--r--src/parser/parser_type.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/src/parser/parser_type.c b/src/parser/parser_type.c
index 49e961c..fcbe12d 100644
--- a/src/parser/parser_type.c
+++ b/src/parser/parser_type.c
@@ -427,13 +427,13 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l)
if (strcmp(name, "uint") == 0)
{
free(name);
- return type_new(TYPE_UINT);
+ return type_new(TYPE_U32); // Strict uint32_t
}
if (strcmp(name, "int") == 0)
{
free(name);
- return type_new(TYPE_INT);
+ return type_new(TYPE_I32); // Strict int32_t
}
if (strcmp(name, "float") == 0)
{
@@ -467,23 +467,31 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l)
}
if (strcmp(name, "long") == 0)
{
+ zwarn_at(t, "'long' is treated as portable 'int64_t' in Zen C. Use 'c_long' for "
+ "platform-dependent C long.");
free(name);
return type_new(TYPE_I64);
}
if (strcmp(name, "short") == 0)
{
+ zwarn_at(t, "'short' is treated as portable 'int16_t' in Zen C. Use 'c_short' for "
+ "platform-dependent C short.");
free(name);
return type_new(TYPE_I16);
}
if (strcmp(name, "unsigned") == 0)
{
+ zwarn_at(t, "'unsigned' is treated as portable 'uint32_t' in Zen C. Use 'c_uint' for "
+ "platform-dependent C unsigned int.");
free(name);
- return type_new(TYPE_UINT);
+ return type_new(TYPE_U32);
}
if (strcmp(name, "signed") == 0)
{
+ zwarn_at(t, "'signed' is treated as portable 'int32_t' in Zen C. Use 'c_int' for "
+ "platform-dependent C int.");
free(name);
- return type_new(TYPE_INT);
+ return type_new(TYPE_I32);
}
if (strcmp(name, "int8_t") == 0)
{
@@ -536,6 +544,48 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l)
return type_new(TYPE_ISIZE);
}
+ // Portable C Types
+ if (strcmp(name, "c_int") == 0)
+ {
+ free(name);
+ return type_new(TYPE_C_INT);
+ }
+ if (strcmp(name, "c_uint") == 0)
+ {
+ free(name);
+ return type_new(TYPE_C_UINT);
+ }
+ if (strcmp(name, "c_long") == 0)
+ {
+ free(name);
+ return type_new(TYPE_C_LONG);
+ }
+ if (strcmp(name, "c_ulong") == 0)
+ {
+ free(name);
+ return type_new(TYPE_C_ULONG);
+ }
+ if (strcmp(name, "c_short") == 0)
+ {
+ free(name);
+ return type_new(TYPE_C_SHORT);
+ }
+ if (strcmp(name, "c_ushort") == 0)
+ {
+ free(name);
+ return type_new(TYPE_C_USHORT);
+ }
+ if (strcmp(name, "c_char") == 0)
+ {
+ free(name);
+ return type_new(TYPE_C_CHAR);
+ }
+ if (strcmp(name, "c_uchar") == 0)
+ {
+ free(name);
+ return type_new(TYPE_C_UCHAR);
+ }
+
// Relaxed Type Check: If explicit 'struct Name', trust the user.
if (explicit_struct)
{
@@ -677,7 +727,7 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l)
zpanic_at(t, "Expected > after generic");
}
- char *unmangled_arg = type_to_c_string(first_arg);
+ char *unmangled_arg = type_to_string(first_arg);
int is_single_dep = 0;
for (int k = 0; k < ctx->known_generics_count; ++k)
@@ -791,7 +841,7 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l)
if (lexer_peek(l).type == TOK_COMMA)
{
lexer_next(l);
- strcat(sig, "_");
+ strcat(sig, "__");
}
else
{