summaryrefslogtreecommitdiff
path: root/src/ast
diff options
context:
space:
mode:
authorZuhaitz <zuhaitz.zechhub@gmail.com>2026-01-31 17:22:17 +0000
committerGitHub <noreply@github.com>2026-01-31 17:22:17 +0000
commit962d659c61212b1a23acfe56dda7cb92b721feda (patch)
treeba1637d3885213095b312f81a477c33b1ebca6aa /src/ast
parente521ee7d175393ef37579ebd61ccb7e8d56a397f (diff)
parent91ed9fdd65e09bd6cd32e44dd07c390f2cf79c22 (diff)
Merge branch 'main' into main
Diffstat (limited to 'src/ast')
-rw-r--r--src/ast/ast.c42
-rw-r--r--src/ast/ast.h16
2 files changed, 57 insertions, 1 deletions
diff --git a/src/ast/ast.c b/src/ast/ast.c
index 0799845..439a9f5 100644
--- a/src/ast/ast.c
+++ b/src/ast/ast.c
@@ -100,6 +100,7 @@ int is_integer_type(Type *t)
t->kind == TYPE_I64 || t->kind == TYPE_U64 || t->kind == TYPE_USIZE ||
t->kind == TYPE_ISIZE || t->kind == TYPE_BYTE || t->kind == TYPE_RUNE ||
t->kind == TYPE_UINT || t->kind == TYPE_I128 || t->kind == TYPE_U128 ||
+ t->kind == TYPE_BITINT || t->kind == TYPE_UBITINT ||
(t->kind == TYPE_STRUCT && t->name &&
(0 == strcmp(t->name, "int8_t") || 0 == strcmp(t->name, "uint8_t") ||
0 == strcmp(t->name, "int16_t") || 0 == strcmp(t->name, "uint16_t") ||
@@ -168,6 +169,18 @@ int type_eq(Type *a, Type *b)
{
return 0 == strcmp(a->name, b->name);
}
+ if (a->kind == TYPE_ALIAS)
+ {
+ if (a->alias.is_opaque_alias)
+ {
+ if (b->kind != TYPE_ALIAS || !b->alias.is_opaque_alias)
+ {
+ return 0;
+ }
+ return 0 == strcmp(a->name, b->name);
+ }
+ return type_eq(a->inner, b);
+ }
if (a->kind == TYPE_POINTER || a->kind == TYPE_ARRAY)
{
return type_eq(a->inner, b->inner);
@@ -250,6 +263,18 @@ static char *type_to_string_impl(Type *t)
return xstrdup("int");
case TYPE_FLOAT:
return xstrdup("float");
+ case TYPE_BITINT:
+ {
+ char *res = xmalloc(32);
+ sprintf(res, "i%d", t->array_size);
+ return res;
+ }
+ case TYPE_UBITINT:
+ {
+ char *res = xmalloc(32);
+ sprintf(res, "u%d", t->array_size);
+ return res;
+ }
case TYPE_POINTER:
{
@@ -340,6 +365,8 @@ static char *type_to_string_impl(Type *t)
}
return xstrdup(t->name);
}
+ case TYPE_ALIAS:
+ return xstrdup(t->name);
default:
return xstrdup("unknown");
@@ -438,6 +465,18 @@ static char *type_to_c_string_impl(Type *t)
return xstrdup("int");
case TYPE_FLOAT:
return xstrdup("float");
+ case TYPE_BITINT:
+ {
+ char *res = xmalloc(32);
+ sprintf(res, "_BitInt(%d)", t->array_size);
+ return res;
+ }
+ case TYPE_UBITINT:
+ {
+ char *res = xmalloc(40);
+ sprintf(res, "unsigned _BitInt(%d)", t->array_size);
+ return res;
+ }
case TYPE_POINTER:
{
@@ -524,6 +563,9 @@ static char *type_to_c_string_impl(Type *t)
case TYPE_GENERIC:
return xstrdup(t->name);
+ case TYPE_ALIAS:
+ return type_to_c_string(t->inner);
+
case TYPE_ENUM:
return xstrdup(t->name);
diff --git a/src/ast/ast.h b/src/ast/ast.h
index b272cae..4498d7c 100644
--- a/src/ast/ast.h
+++ b/src/ast/ast.h
@@ -58,6 +58,9 @@ typedef enum
TYPE_ARRAY, ///< Fixed size array [N].
TYPE_FUNCTION, ///< Function pointer or reference.
TYPE_GENERIC, ///< Generic type parameter (T).
+ TYPE_ALIAS, ///< Opaque type alias.
+ TYPE_BITINT, ///< C23 _BitInt(N).
+ TYPE_UBITINT, ///< C23 unsigned _BitInt(N).
TYPE_UNKNOWN ///< Unknown/unresolved type.
} TypeKind;
@@ -74,7 +77,7 @@ typedef struct Type
int is_const; ///< 1 if const-qualified.
int is_explicit_struct; ///< 1 if defined with "struct" keyword explicitly.
int is_raw; // Raw function pointer (fn*)
- int array_size; ///< Size for fixed-size arrays.
+ int array_size; ///< Size for fixed-size arrays. For TYPE_BITINT, this is the bit width.
union
{
int is_varargs; ///< 1 if function type is variadic.
@@ -84,6 +87,11 @@ typedef struct Type
int has_drop; ///< 1 if type implements Drop trait (RAII).
int has_iterable; ///< 1 if type implements Iterable trait.
} traits;
+ struct
+ {
+ int is_opaque_alias;
+ char *alias_defined_in_file;
+ } alias;
};
} Type;
@@ -221,6 +229,8 @@ struct ASTNode
int cuda_device; // @device -> __device__
int cuda_host; // @host -> __host__
+ char **c_type_overrides; // @ctype("...") per parameter
+
Attribute *attributes; // Custom attributes
} func;
@@ -263,6 +273,8 @@ struct ASTNode
{
char *alias;
char *original_type;
+ int is_opaque;
+ char *defined_in_file;
} type_alias;
struct
@@ -436,6 +448,8 @@ struct ASTNode
Attribute *attributes; // Custom attributes
char **used_structs; // Names of structs used/mixed-in
int used_struct_count;
+ int is_opaque;
+ char *defined_in_file; // File where the struct is defined (for privacy check)
} strct;
struct