aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/fwd/ast.h7
-rw-r--r--include/fwd/debug.h5
-rw-r--r--src/analyze.c103
-rw-r--r--src/debug.c2
4 files changed, 76 insertions, 41 deletions
diff --git a/include/fwd/ast.h b/include/fwd/ast.h
index 62766fb..bcf4171 100644
--- a/include/fwd/ast.h
+++ b/include/fwd/ast.h
@@ -31,7 +31,8 @@ struct src_loc {
struct ast;
enum type_kind {
- TYPE_ID = 1, TYPE_CONSTRUCT, TYPE_REF, TYPE_PTR, TYPE_CALLABLE, TYPE_VOID
+ TYPE_ID = 1, TYPE_CONSTRUCT, TYPE_REF, TYPE_PTR, TYPE_CALLABLE,
+ TYPE_VOID
};
struct type {
@@ -117,8 +118,8 @@ enum ast_kind {
};
enum ast_flag {
- AST_FLAG_ANALYZED = (1 << 0),
- AST_FLAG_PREANALYZIS = (1 << 1),
+ AST_FLAG_ANALYZED = (1 << 0),
+ AST_FLAG_PREANALYZIS = (1 << 1),
};
struct ast {
diff --git a/include/fwd/debug.h b/include/fwd/debug.h
index cc20c83..0794650 100644
--- a/include/fwd/debug.h
+++ b/include/fwd/debug.h
@@ -93,7 +93,8 @@ void semantic_warn(struct scope *scope, struct ast *node, const char *fmt, ...);
* @param node AST node to print message with.
* @param fmt Format string. Follows standard printf() formatting.
*/
-void semantic_error(struct scope *scope, struct ast *node, const char *fmt, ...);
+void semantic_error(struct scope *scope, struct ast *node, const char *fmt,
+ ...);
void loc_error(struct scope *scope, struct src_loc loc, const char *fmt, ...);
@@ -135,7 +136,7 @@ struct src_issue {
void src_issue(struct src_issue issue, const char *err_msg, ...);
void type_mismatch(struct scope *scope, struct ast *node,
- struct type *l, struct type *r);
+ struct type *l, struct type *r);
const char *type_str(struct type *t);
diff --git a/src/analyze.c b/src/analyze.c
index 10e1f0b..37b2e65 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -9,12 +9,16 @@ struct state {
};
static int analyze(struct state *state, struct scope *scope, struct ast *node);
-static int analyze_list(struct state *state, struct scope *scope, struct ast *nodes);
+static int analyze_list(struct state *state, struct scope *scope,
+ struct ast *nodes);
-static int analyze_type(struct state *state, struct scope *scope, struct type *type);
-static int analyze_type_list(struct state *state, struct scope *scope, struct type *types);
+static int analyze_type(struct state *state, struct scope *scope,
+ struct type *type);
+static int analyze_type_list(struct state *state, struct scope *scope,
+ struct type *types);
-static int analyze_proc(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_proc(struct state *state, struct scope *scope,
+ struct ast *node)
{
(void)state;
(void)scope;
@@ -46,7 +50,8 @@ static int analyze_proc(struct state *state, struct scope *scope, struct ast *no
return analyze(&proc_state, proc_scope, proc_body(node));
}
-static int analyze_unop(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_unop(struct state *state, struct scope *scope,
+ struct ast *node)
{
/** @todo check expr is some primitive type */
struct ast *expr = unop_expr(node);
@@ -57,7 +62,8 @@ static int analyze_unop(struct state *state, struct scope *scope, struct ast *no
return 0;
}
-static int analyze_binop(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_binop(struct state *state, struct scope *scope,
+ struct ast *node)
{
struct ast *lhs = binop_left(node);
struct ast *rhs = binop_right(node);
@@ -79,7 +85,8 @@ static int analyze_binop(struct state *state, struct scope *scope, struct ast *n
return 0;
}
-static int analyze_comparison(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_comparison(struct state *state, struct scope *scope,
+ struct ast *node)
{
struct ast *lhs = comparison_left(node);
struct ast *rhs = comparison_right(node);
@@ -112,7 +119,8 @@ static int analyze_comparison(struct state *state, struct scope *scope, struct a
return 0;
}
-static int analyze_block(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_block(struct state *state, struct scope *scope,
+ struct ast *node)
{
struct scope *block_scope = create_scope();
if (!block_scope) {
@@ -128,7 +136,8 @@ static int analyze_block(struct state *state, struct scope *scope, struct ast *n
return 0;
}
-static int analyze_var(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_var(struct state *state, struct scope *scope,
+ struct ast *node)
{
if (analyze_type(state, scope, var_type(node)))
return -1;
@@ -137,7 +146,8 @@ static int analyze_var(struct state *state, struct scope *scope, struct ast *nod
return scope_add_var(scope, node);
}
-static int analyze_let(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_let(struct state *state, struct scope *scope,
+ struct ast *node)
{
if (analyze(state, scope, let_var(node)))
return -1;
@@ -157,7 +167,8 @@ static int analyze_let(struct state *state, struct scope *scope, struct ast *nod
return 0;
}
-static int analyze_init(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_init(struct state *state, struct scope *scope,
+ struct ast *node)
{
if (analyze_type_list(state, scope, init_args(node)))
return -1;
@@ -177,7 +188,8 @@ static int analyze_init(struct state *state, struct scope *scope, struct ast *no
return 0;
}
-static int analyze_call(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_call(struct state *state, struct scope *scope,
+ struct ast *node)
{
struct ast *expr = call_expr(node);
if (analyze(state, scope, expr))
@@ -196,7 +208,8 @@ static int analyze_call(struct state *state, struct scope *scope, struct ast *no
size_t expected = type_list_len(types);
size_t got = ast_list_len(args);
if (expected != got) {
- semantic_error(scope, node, "expected %d params, got %d", expected, got);
+ semantic_error(scope, node, "expected %d params, got %d",
+ expected, got);
return -1;
}
@@ -220,11 +233,13 @@ static int analyze_call(struct state *state, struct scope *scope, struct ast *no
return 0;
}
-static int analyze_id(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_id(struct state *state, struct scope *scope,
+ struct ast *node)
{
struct ast *found = file_scope_find_symbol(scope, id_str(node));
if (!found) {
- semantic_error(scope, node, "no symbol named \"%s\"", id_str(node));
+ semantic_error(scope, node, "no symbol named \"%s\"",
+ id_str(node));
return -1;
}
@@ -243,7 +258,8 @@ static int analyze_id(struct state *state, struct scope *scope, struct ast *node
return 0;
}
-static int analyze_closure(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_closure(struct state *state, struct scope *scope,
+ struct ast *node)
{
struct scope *closure_scope = create_scope();
if (!closure_scope) {
@@ -276,7 +292,8 @@ static int analyze_closure(struct state *state, struct scope *scope, struct ast
return 0;
}
-static int analyze_int(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_int(struct state *state, struct scope *scope,
+ struct ast *node)
{
/** @todo do this properly, very hacky, bad bad bad */
char *i = strdup("int");
@@ -294,7 +311,8 @@ static int analyze_int(struct state *state, struct scope *scope, struct ast *nod
return 0;
}
-static int analyze_str(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_str(struct state *state, struct scope *scope,
+ struct ast *node)
{
/** @todo do this properly, very hacky, bad bad bad */
char *i = strdup("char");
@@ -319,7 +337,8 @@ static int analyze_str(struct state *state, struct scope *scope, struct ast *nod
return 0;
}
-static int analyze_if(struct state *state, struct scope *scope, struct ast *node)
+static int analyze_if(struct state *state, struct scope *scope,
+ struct ast *node)
{
if (analyze(state, scope, if_cond(node)))
return -1;
@@ -376,20 +395,31 @@ static int analyze(struct state *state, struct scope *scope, struct ast *node)
}
switch (node->k) {
- case AST_PROC_DEF: ret = analyze_proc (state, scope, node); break;
- case AST_VAR_DEF: ret = analyze_var (state, scope, node); break;
- case AST_BLOCK: ret = analyze_block (state, scope, node); break;
- case AST_LET: ret = analyze_let (state, scope, node); break;
- case AST_INIT: ret = analyze_init (state, scope, node); break;
- case AST_CALL: ret = analyze_call (state, scope, node); break;
- case AST_ID: ret = analyze_id (state, scope, node); break;
- case AST_IF: ret = analyze_if (state, scope, node); break;
- case AST_CLOSURE: ret = analyze_closure (state, scope, node); break;
- case AST_CONST_INT: ret = analyze_int (state, scope, node); break;
- case AST_CONST_STR: ret = analyze_str (state, scope, node); break;
+ case AST_PROC_DEF: ret = analyze_proc (state, scope, node);
+ break;
+ case AST_VAR_DEF: ret = analyze_var (state, scope, node);
+ break;
+ case AST_BLOCK: ret = analyze_block (state, scope, node);
+ break;
+ case AST_LET: ret = analyze_let (state, scope, node);
+ break;
+ case AST_INIT: ret = analyze_init (state, scope, node);
+ break;
+ case AST_CALL: ret = analyze_call (state, scope, node);
+ break;
+ case AST_ID: ret = analyze_id (state, scope, node);
+ break;
+ case AST_IF: ret = analyze_if (state, scope, node);
+ break;
+ case AST_CLOSURE: ret = analyze_closure (state, scope, node);
+ break;
+ case AST_CONST_INT: ret = analyze_int (state, scope, node);
+ break;
+ case AST_CONST_STR: ret = analyze_str (state, scope, node);
+ break;
default:
- internal_error("missing ast analysis");
- return -1;
+ internal_error("missing ast analysis");
+ return -1;
}
out:
@@ -402,7 +432,8 @@ out:
return 0;
}
-static int analyze_list(struct state *state, struct scope *scope, struct ast *nodes)
+static int analyze_list(struct state *state, struct scope *scope,
+ struct ast *nodes)
{
foreach_node(node, nodes) {
if (analyze(state, scope, node))
@@ -412,7 +443,8 @@ static int analyze_list(struct state *state, struct scope *scope, struct ast *no
return 0;
}
-static int analyze_type(struct state *state, struct scope *scope, struct type *type)
+static int analyze_type(struct state *state, struct scope *scope,
+ struct type *type)
{
/* for now, let's just say all types are fine as they are, specified by
* the user. */
@@ -422,7 +454,8 @@ static int analyze_type(struct state *state, struct scope *scope, struct type *t
return 0;
}
-static int analyze_type_list(struct state *state, struct scope *scope, struct type *types)
+static int analyze_type_list(struct state *state, struct scope *scope,
+ struct type *types)
{
foreach_type(type, types) {
if (analyze_type(state, scope, type))
diff --git a/src/debug.c b/src/debug.c
index ecb03e3..cd0b8eb 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -135,7 +135,7 @@ void semantic_error(struct scope *scope, struct ast *node,
}
void type_mismatch(struct scope *scope, struct ast *node,
- struct type *l, struct type *r)
+ struct type *l, struct type *r)
{
const char *ls = type_str(l);
const char *rs = type_str(r);