summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-01-07 23:37:02 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-01-07 23:37:02 -0500
commitb045c8fb62686fb7ffbc1074bc1dda09dda5fe1c (patch)
treef4abad0433169212a755e89d081d749be7a508a5
parent8b57eeb9ea69fdd581f34f77e0a1c1bec425d6d3 (diff)
naming consistency
-rw-r--r--cgen.c42
-rw-r--r--decls_cgen.c2
-rw-r--r--typedefs_cgen.c42
-rw-r--r--types.h2
4 files changed, 45 insertions, 43 deletions
diff --git a/cgen.c b/cgen.c
index 0a4cdbe..cf3f8d4 100644
--- a/cgen.c
+++ b/cgen.c
@@ -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;
}
diff --git a/types.h b/types.h
index 7cc3cc2..d83e0c7 100644
--- a/types.h
+++ b/types.h
@@ -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 */