From 699ca4b18ae3b9058a796caed8abb6c566e9c8b7 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Tue, 14 Jun 2022 12:07:04 +0200 Subject: [PATCH] Generating proper slice name when rewriting tree --- ccodegen.cpp | 16 +++++++++------- typechecking.cpp | 7 +++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ccodegen.cpp b/ccodegen.cpp index 3690e71..a14ff94 100644 --- a/ccodegen.cpp +++ b/ccodegen.cpp @@ -131,6 +131,14 @@ gen_simple_decl(Ast_Type *ast, Intern_String name = {}, Ast_Scope *scope = 0, bo gen("%.*s", (int)string.len, string.str); } +function String +gen_string_simple_decl(Allocator *a, Ast_Type *ast, String name, Ast_Scope *scope, bool scope_names){ + Scratch scratch; + String string = string_simple_decl(scratch, ast, pctx->intern(name), scope, scope_names); + String result = string_copy(a, string); + return result; +} + function B32 gen_value(Value a){ B32 result = true; @@ -672,13 +680,7 @@ typedef struct String{ #endif For(pctx->ordered_decls){ if(it->kind == AST_STRUCT){ - if(it->type && it->type->kind == TYPE_TYPE && is_slice(it->type_val)){ - genln("typedef struct struct "); - gen_simple_decl(it->type_val); - gen(";"); - } else{ - genln("typedef struct struct %s;", it->name.str); - } + genln("typedef struct struct %s;", it->name.str); } else if(it->kind == AST_LAMBDA){ genln(""); gen_lambda(it->name, it->lambda, false); diff --git a/typechecking.cpp b/typechecking.cpp index 3440902..d25be83 100644 --- a/typechecking.cpp +++ b/typechecking.cpp @@ -1,5 +1,6 @@ #define CASE(kind,type) case AST_##kind: { Ast_##type *node = (Ast_##type *)ast; #define BREAK() } break +function String gen_string_simple_decl(Allocator *a, Ast_Type *ast, String name = {}, Ast_Scope *scope = 0, bool scope_names = true); //----------------------------------------------------------------------------- // Evaluating constant expressions @@ -716,11 +717,13 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){ scope->decls.add(len_var); Ast_Decl *pointer_var = ast_var(0, 0, pctx->intern("data"_s), 0); - pointer_var->type = type.type_val; + pointer_var->type = type_pointer(type.type_val); scope->decls.add(pointer_var); Ast_Decl *struct_decl = ast_struct(0, scope); - struct_decl->name = pctx->intern("SliceOf"_s); + + String name = gen_string_simple_decl(pctx->perm, node->type); + struct_decl->name = pctx->intern(name); struct_decl->type = type_type; struct_decl->type_val = node->type; pctx->ordered_decls.add(struct_decl);