aboutsummaryrefslogtreecommitdiff
path: root/src/types.h
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-03 21:01:03 -0500
committerMustafa Quraish <[email protected]>2022-02-03 21:01:03 -0500
commit9f3edcbeea51dd8841b9d89fa7ef98f11682a1c7 (patch)
treeb2a4b6fa51ad558b36facde2cf952a6af5a25669 /src/types.h
parentAdd automatic type inference for initialized variable declarations (diff)
downloadcup-9f3edcbeea51dd8841b9d89fa7ef98f11682a1c7.tar.xz
cup-9f3edcbeea51dd8841b9d89fa7ef98f11682a1c7.zip
Add support for basic structs
Structs for now (and probably for the near future) are not allowed to be passed by value, and instead you just pass a pointer to it. Nested structs can also be defined, and they can be either anonymous, or named (in which case only the members can access the type).
Diffstat (limited to 'src/types.h')
-rw-r--r--src/types.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/types.h b/src/types.h
index 73b5b63..e8b9488 100644
--- a/src/types.h
+++ b/src/types.h
@@ -10,12 +10,21 @@ typedef enum {
TYPE_CHAR,
TYPE_PTR,
TYPE_ARRAY,
+ TYPE_STRUCT,
} DataType;
typedef struct data_type_node {
DataType type;
struct data_type_node *ptr;
i64 array_size;
+ char *struct_name;
+ struct {
+ char **name;
+ struct data_type_node **type;
+ i64 *offset;
+ i64 num_fields;
+ i64 size;
+ } fields;
} Type;
Type *type_new(DataType type);
@@ -28,6 +37,11 @@ bool type_equals(Type *a, Type *b);
bool is_int_type(Type *type);
bool is_string_type(Type *type);
bool is_convertible(Type *from, Type *to);
+bool is_struct_or_struct_ptr(Type *type);
+
+// Returns the offset of the field in the struct.
+i64 push_field(Type *type, char *field_name, Type *field_type);
+i64 find_field_index(Type *type, char *field_name);
// Type checking / casting expressions to right types
typedef struct ast_node Node;