diff options
-rw-r--r-- | cgen.c | 16 | ||||
-rw-r--r-- | decls_cgen.c | 2 |
2 files changed, 11 insertions, 7 deletions
@@ -280,17 +280,21 @@ static bool cgen_uses_ptr(Type *t) { return false; } +/* used for fields */ +static inline void cgen_ident_simple(CGenerator *g, Identifier i) { + cgen_indent(g); + fprint_ident_reduced_charset(cgen_writing_to(g), i); +} + static void cgen_ident(CGenerator *g, Identifier i) { - if (i->export_id) { + IdentDecl *idecl = ident_decl(i); + if (idecl && idecl->kind == IDECL_DECL && idecl->decl->flags & DECL_EXPORT) cgen_write(g, "%s__", g->pkg_prefix); - } if (i == g->main_ident) { /* don't conflict with C's main! */ cgen_write(g, "main__"); } else { - - cgen_indent(g); - fprint_ident_reduced_charset(cgen_writing_to(g), i); + cgen_ident_simple(g, i); } } @@ -1287,7 +1291,7 @@ static bool cgen_expr(CGenerator *g, Expression *e) { cgen_expr(g, e->binary.lhs); bool is_ptr = e->binary.lhs->type.kind == TYPE_PTR; cgen_write(g, is_ptr ? "->" :"."); - cgen_ident(g, e->binary.dot.field->name); + cgen_ident_simple(g, e->binary.dot.field->name); cgen_write(g, ")"); handled = true; } diff --git a/decls_cgen.c b/decls_cgen.c index b2ff8a3..32bc3f1 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -27,7 +27,7 @@ static bool cgen_decls_type(CGenerator *g, Type *type) { arr_foreach(sdef->fields, Field, f) { if (!cgen_type_pre(g, &f->type, sdef->where)) return false; cgen_write(g, " "); - cgen_ident(g, f->name); + cgen_ident_simple(g, f->name); if (!cgen_type_post(g, &f->type, sdef->where)) return false; cgen_write(g, ";"); cgen_nl(g); |