aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2015-12-12 02:34:09 -0700
committerAndrew Kelley <superjoe30@gmail.com>2015-12-12 02:34:09 -0700
commit38f12adbda5d3b0114232fdccdbcc0b4179f9115 (patch)
tree5016bcd2cccea018738aa30c9bb7e91b2aaa9c2b /src/analyze.cpp
parentac630d354d51488d895bc14e26a069ae954ac5c6 (diff)
downloadzig-38f12adbda5d3b0114232fdccdbcc0b4179f9115.tar.gz
zig-38f12adbda5d3b0114232fdccdbcc0b4179f9115.zip
progress on struct support
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 923e340c05..89e5e109b8 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -422,6 +422,9 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
type_entry->data.structure.fields = allocate<TypeStructField>(field_count);
LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count);
+ LLVMZigDIType **di_element_types = allocate<LLVMZigDIType*>(field_count);
+
+ uint64_t total_size_in_bits = 0;
for (int i = 0; i < field_count; i += 1) {
AstNode *field_node = node->data.struct_decl.fields.at(i);
@@ -429,12 +432,22 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
type_struct_field->name = &field_node->data.struct_field.name;
type_struct_field->type_entry = resolve_type(g, field_node->data.struct_field.type);
+ total_size_in_bits = type_struct_field->type_entry->size_in_bits;
+ di_element_types[i] = type_struct_field->type_entry->di_type;
+
element_types[i] = type_struct_field->type_entry->type_ref;
}
- // TODO align_in_bits and size_in_bits
- // TODO set up ditype for the struct
LLVMStructSetBody(type_entry->type_ref, element_types, field_count, false);
+ // TODO re-evaluate this align in bits and size in bits
+ type_entry->align_in_bits = 0;
+ type_entry->size_in_bits = total_size_in_bits;
+ type_entry->di_type = LLVMZigCreateDebugStructType(g->dbuilder,
+ LLVMZigFileToScope(import->di_file),
+ buf_ptr(&node->data.struct_decl.name),
+ import->di_file, node->line + 1, type_entry->size_in_bits, type_entry->align_in_bits, 0,
+ nullptr, di_element_types, field_count, 0, nullptr, "");
+
break;
}
case NodeTypeUse:
@@ -621,7 +634,9 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i
TypeTableEntry *return_type;
if (struct_type->id == TypeTableEntryIdStruct) {
+ assert(node->codegen_node);
FieldAccessNode *codegen_field_access = &node->codegen_node->data.field_access_node;
+ assert(codegen_field_access);
Buf *field_name = &node->data.field_access_expr.field_name;
@@ -847,6 +862,7 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import,
} else if (lhs_node->type == NodeTypeArrayAccessExpr) {
expected_rhs_type = analyze_array_access_expr(g, import, context, lhs_node);
} else if (lhs_node->type == NodeTypeFieldAccessExpr) {
+ alloc_codegen_node(lhs_node);
expected_rhs_type = analyze_field_access_expr(g, import, context, lhs_node);
} else {
add_node_error(g, lhs_node,