Generating proper slice name when rewriting tree

This commit is contained in:
Krzosa Karol
2022-06-14 12:07:04 +02:00
parent 946e4082cc
commit 699ca4b18a
2 changed files with 14 additions and 9 deletions

View File

@@ -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);

View File

@@ -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);