Generating proper slice name when rewriting tree
This commit is contained in:
14
ccodegen.cpp
14
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);
|
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
|
function B32
|
||||||
gen_value(Value a){
|
gen_value(Value a){
|
||||||
B32 result = true;
|
B32 result = true;
|
||||||
@@ -672,13 +680,7 @@ typedef struct String{
|
|||||||
#endif
|
#endif
|
||||||
For(pctx->ordered_decls){
|
For(pctx->ordered_decls){
|
||||||
if(it->kind == AST_STRUCT){
|
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){
|
} else if(it->kind == AST_LAMBDA){
|
||||||
genln("");
|
genln("");
|
||||||
gen_lambda(it->name, it->lambda, false);
|
gen_lambda(it->name, it->lambda, false);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#define CASE(kind,type) case AST_##kind: { Ast_##type *node = (Ast_##type *)ast;
|
#define CASE(kind,type) case AST_##kind: { Ast_##type *node = (Ast_##type *)ast;
|
||||||
#define BREAK() } break
|
#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
|
// Evaluating constant expressions
|
||||||
@@ -716,11 +717,13 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){
|
|||||||
scope->decls.add(len_var);
|
scope->decls.add(len_var);
|
||||||
|
|
||||||
Ast_Decl *pointer_var = ast_var(0, 0, pctx->intern("data"_s), 0);
|
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);
|
scope->decls.add(pointer_var);
|
||||||
|
|
||||||
Ast_Decl *struct_decl = ast_struct(0, scope);
|
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 = type_type;
|
||||||
struct_decl->type_val = node->type;
|
struct_decl->type_val = node->type;
|
||||||
pctx->ordered_decls.add(struct_decl);
|
pctx->ordered_decls.add(struct_decl);
|
||||||
|
|||||||
Reference in New Issue
Block a user