diff options
-rw-r--r-- | cgen.c | 42 | ||||
-rw-r--r-- | decls_cgen.c | 2 | ||||
-rw-r--r-- | typedefs_cgen.c | 42 | ||||
-rw-r--r-- | types.h | 2 |
4 files changed, 45 insertions, 43 deletions
@@ -154,6 +154,48 @@ static bool cgen_defs_decl(CGenerator *g, Declaration *d); break; \ } + +#define cgen_recurse_subtypes(f, g, type, extra) \ + switch (type->kind) { \ + case TYPE_STRUCT: \ + arr_foreach(type->struc->fields, Field, fl) \ + if (!f(g, fl->type, extra)) \ + return false; \ + break; \ + case TYPE_FN: \ + arr_foreach(type->fn.types, Type, sub) { \ + if (!f(g, sub, extra)) \ + return false; \ + } \ + break; \ + case TYPE_TUPLE: \ + arr_foreach(type->tuple, Type, sub) \ + if (!f(g, sub, extra)) \ + return false; \ + break; \ + case TYPE_ARR: \ + if (!f(g, type->arr.of, extra)) \ + return false; \ + break; \ + case TYPE_SLICE: \ + if (!f(g, type->slice, extra)) \ + return false; \ + break; \ + case TYPE_PTR: \ + if (!f(g, type->ptr, extra)) \ + return false; \ + break; \ + case TYPE_VOID: \ + case TYPE_BUILTIN: \ + case TYPE_PKG: \ + case TYPE_TYPE: \ + case TYPE_UNKNOWN: \ + break; \ + case TYPE_EXPR: assert(0); \ + } + + + static bool cgen_block_enter(CGenerator *g, Block *b) { g->block = b; Statement *stmts; diff --git a/decls_cgen.c b/decls_cgen.c index b6e7e8b..728d83e 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -38,7 +38,7 @@ static bool cgen_decls_type(CGenerator *g, Type *type, Location where) { sdef->flags |= STRUCT_DEF_CGENERATED; } } - cgen_recurse_into_type(cgen_decls_type, g, type, where); + cgen_recurse_subtypes(cgen_decls_type, g, type, where); return true; } diff --git a/typedefs_cgen.c b/typedefs_cgen.c index 531fb0d..884d61e 100644 --- a/typedefs_cgen.c +++ b/typedefs_cgen.c @@ -7,46 +7,6 @@ static bool typedefs_stmt(CGenerator *g, Statement *s); static bool typedefs_decl(CGenerator *g, Declaration *d); static bool typedefs_expr(CGenerator *g, Expression *e); -#define cgen_recurse_into_type(f, g, type, extra) \ - switch (type->kind) { \ - case TYPE_STRUCT: \ - arr_foreach(type->struc->fields, Field, fl) \ - if (!f(g, fl->type, extra)) \ - return false; \ - break; \ - case TYPE_FN: \ - arr_foreach(type->fn.types, Type, sub) { \ - if (!f(g, sub, extra)) \ - return false; \ - } \ - break; \ - case TYPE_TUPLE: \ - arr_foreach(type->tuple, Type, sub) \ - if (!f(g, sub, extra)) \ - return false; \ - break; \ - case TYPE_ARR: \ - if (!f(g, type->arr.of, extra)) \ - return false; \ - break; \ - case TYPE_SLICE: \ - if (!f(g, type->slice, extra)) \ - return false; \ - break; \ - case TYPE_PTR: \ - if (!f(g, type->ptr, extra)) \ - return false; \ - break; \ - case TYPE_VOID: \ - case TYPE_BUILTIN: \ - case TYPE_PKG: \ - case TYPE_TYPE: \ - case TYPE_UNKNOWN: \ - break; \ - case TYPE_EXPR: assert(0); \ - } - - /* i is the name for this type, NULL if not available */ /* ALWAYS RETURNS TRUE. it just returns a bool for cgen_recurse_into_type to work */ static bool typedefs_type(CGenerator *g, Type *type, Identifier i) { @@ -72,7 +32,7 @@ static bool typedefs_type(CGenerator *g, Type *type, Identifier i) { cgen_nl(g); } } - cgen_recurse_into_type(typedefs_type, g, type, NULL); + cgen_recurse_subtypes(typedefs_type, g, type, NULL); return true; } @@ -3,7 +3,7 @@ This file is part of toc. toc is distributed under version 3 of the GNU General Public License, without any warranty whatsoever. You should have received a copy of the GNU General Public License along with toc. If not, see <https://www.gnu.org/licenses/>. */ -/* NOTE: make sure you edit copy.c when you make a change to expression-related types or type-related types in this file! */ +/* NOTE: make sure you edit copy.c and package.c and cgen_recurse_subexprs when you make a change to expression-related types or type-related types in this file! */ typedef long double Floating; /* OPTIM: Switch to double, but make sure floating-point literals are right */ |