harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e5a9ac58067aae5138409540afd8bbfc5802efe0
parent 86b659a0e56ff966da7c5376636cb95efb67c955
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Thu,  8 Apr 2021 17:43:26 -0400

Remove trace

Diffstat:
Mconfigure | 1-
Minclude/scope.h | 5++---
Dinclude/trace.h | 17-----------------
Msrc/check.c | 93+++++++++++--------------------------------------------------------------------
Msrc/gen.c | 3---
Msrc/parse.c | 211+++++--------------------------------------------------------------------------
Msrc/scope.c | 11++---------
Dsrc/trace.c | 71-----------------------------------------------------------------------
Msrc/type_store.c | 5++---
9 files changed, 32 insertions(+), 385 deletions(-)

diff --git a/configure b/configure @@ -19,7 +19,6 @@ harec() { src/qtype.c \ src/scope.c \ src/tags.c \ - src/trace.c \ src/type_store.c \ src/typedef.c \ src/types.c \ diff --git a/include/scope.h b/include/scope.h @@ -2,7 +2,6 @@ #define HAREC_SCOPE_H #include "expr.h" #include "identifier.h" -#include "trace.h" #define SCOPE_BUCKETS 4096 @@ -46,8 +45,8 @@ struct scopes { struct scopes *next; }; -struct scope *scope_push(struct scope **stack, enum trace_sys sys); -struct scope *scope_pop(struct scope **stack, enum trace_sys sys); +struct scope *scope_push(struct scope **stack); +struct scope *scope_pop(struct scope **stack); void scope_free(struct scope *scope); void scope_free_all(struct scopes *scopes); diff --git a/include/trace.h b/include/trace.h @@ -1,17 +0,0 @@ -#ifndef HARE_TRACE_H -#define HARE_TRACE_H - -enum trace_sys { - TR_LEX, - TR_PARSE, - TR_SCAN, - TR_CHECK, - TR_GEN, - TR_MAX, -}; - -void trace(enum trace_sys sys, const char *fmt, ...); -void trenter(enum trace_sys sys, const char *fmt, ...); -void trleave(enum trace_sys sys, const char *fmt, ...); - -#endif diff --git a/src/check.c b/src/check.c @@ -10,7 +10,6 @@ #include "mod.h" #include "scope.h" #include "tags.h" -#include "trace.h" #include "type_store.h" #include "types.h" #include "util.h" @@ -121,7 +120,6 @@ check_expr_access(struct context *ctx, const struct type *hint, struct errors *errors) { - trace(TR_CHECK, "access"); expr->type = EXPR_ACCESS; expr->access.type = aexpr->access.type; @@ -255,7 +253,6 @@ check_expr_alloc(struct context *ctx, struct errors *errors) { assert(aexpr->type == EXPR_ALLOC); - trace(TR_CHECK, "alloc"); expr->type = EXPR_ALLOC; expr->alloc.expr = xcalloc(sizeof(struct expression), 1); const struct type *inittype = NULL; @@ -334,7 +331,6 @@ check_expr_append(struct context *ctx, struct errors *errors) { assert(aexpr->type == EXPR_APPEND); - trace(TR_CHECK, "append"); expr->type = EXPR_APPEND; expr->result = &builtin_type_void; expr->append.expr = xcalloc(sizeof(struct expression), 1); @@ -394,7 +390,6 @@ check_expr_assert(struct context *ctx, const struct type *hint, struct errors *errors) { - trace(TR_CHECK, "assert"); expr->type = EXPR_ASSERT; expr->result = &builtin_type_void; expr->assert.is_static = aexpr->assert.is_static; @@ -473,7 +468,6 @@ check_expr_assign(struct context *ctx, const struct type *hint, struct errors *errors) { - trace(TR_CHECK, "assign"); expr->type = EXPR_ASSIGN; expr->result = &builtin_type_void; expr->assign.indirect = aexpr->assign.indirect; @@ -656,7 +650,6 @@ check_expr_binarithm(struct context *ctx, const struct type *hint, struct errors *errors) { - trace(TR_CHECK, "binarithm"); expr->type = EXPR_BINARITHM; expr->binarithm.op = aexpr->binarithm.op; @@ -778,7 +771,6 @@ check_expr_binding(struct context *ctx, const struct type *hint, struct errors *errors) { - trace(TR_CHECK, "binding"); expr->type = EXPR_BINDING; expr->result = &builtin_type_void; @@ -944,7 +936,6 @@ check_expr_call(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "call"); expr->type = EXPR_CALL; struct expression *lvalue = xcalloc(1, sizeof(struct expression)); @@ -970,7 +961,6 @@ check_expr_call(struct context *ctx, struct ast_call_argument *aarg = aexpr->call.args; struct type_func_param *param = fntype->func.params; while (param && aarg) { - trenter(TR_CHECK, "arg"); arg = *next = xcalloc(1, sizeof(struct call_argument)); arg->value = xcalloc(1, sizeof(struct expression)); @@ -981,7 +971,6 @@ check_expr_call(struct context *ctx, arg->value = lower_implicit_cast(param->type, arg->value); param = NULL; aarg = NULL; - trleave(TR_CHECK, NULL); break; } @@ -997,7 +986,6 @@ check_expr_call(struct context *ctx, aarg = aarg->next; param = param->next; next = &arg->next; - trleave(TR_CHECK, NULL); } if (param && fntype->func.variadism == VARIADISM_HARE) { @@ -1019,7 +1007,6 @@ check_expr_call(struct context *ctx, "Not enough parameters for function call"); } - trleave(TR_CHECK, NULL); return errors; } @@ -1030,7 +1017,6 @@ check_expr_cast(struct context *ctx, const struct type *hint, struct errors *errors) { - trace(TR_CHECK, "cast"); expr->type = EXPR_CAST; expr->cast.kind = aexpr->cast.kind; struct expression *value = expr->cast.value = @@ -1252,7 +1238,6 @@ check_expr_constant(struct context *ctx, const struct type *hint, struct errors *errors) { - trace(TR_CHECK, "constant"); expr->type = EXPR_CONSTANT; expr->result = builtin_type_for_storage(aexpr->constant.storage, false); @@ -1413,7 +1398,6 @@ check_expr_control(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "control"); expr->type = aexpr->type; expr->result = &builtin_type_void; expr->terminates = true; @@ -1435,7 +1419,6 @@ check_expr_control(struct context *ctx, return error(aexpr->loc, expr, errors, "Unknown label %s", expr->control.label); } - trleave(TR_CHECK, NULL); return errors; } @@ -1446,7 +1429,6 @@ check_expr_for(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "if"); expr->type = EXPR_FOR; expr->result = &builtin_type_void; @@ -1454,7 +1436,7 @@ check_expr_for(struct context *ctx, expr->_for.label = strdup(aexpr->_for.label); } - struct scope *scope = scope_push(&ctx->scope, TR_CHECK); + struct scope *scope = scope_push(&ctx->scope); expr->_for.scope = scope; scope->type = expr->type; scope->label = expr->_for.label; @@ -1500,8 +1482,7 @@ check_expr_for(struct context *ctx, errors = check_expression(ctx, aexpr->_for.body, body, NULL, errors); expr->_for.body = body; - scope_pop(&ctx->scope, TR_CHECK); - trleave(TR_CHECK, NULL); + scope_pop(&ctx->scope); return errors; } @@ -1514,7 +1495,6 @@ check_expr_free(struct context *ctx, { assert(aexpr->type == EXPR_FREE); expr->type = EXPR_FREE; - trace(TR_CHECK, "free"); expr->free.expr = xcalloc(sizeof(struct expression), 1); errors = check_expression(ctx, aexpr->free.expr, expr->free.expr, NULL, errors); @@ -1535,7 +1515,6 @@ check_expr_if(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "if"); expr->type = EXPR_IF; struct expression *cond, *true_branch, *false_branch = NULL; @@ -1591,8 +1570,6 @@ check_expr_if(struct context *ctx, expr->_if.cond = cond; expr->_if.true_branch = true_branch; expr->_if.false_branch = false_branch; - - trleave(TR_CHECK, NULL); return errors; } @@ -1603,10 +1580,9 @@ check_expr_list(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "expression-list"); expr->type = EXPR_LIST; - struct scope *scope = scope_push(&ctx->scope, TR_CHECK); + struct scope *scope = scope_push(&ctx->scope); expr->list.scope = scope; scope->type = expr->type; @@ -1631,8 +1607,7 @@ check_expr_list(struct context *ctx, } } - scope_pop(&ctx->scope, TR_CHECK); - trleave(TR_CHECK, NULL); + scope_pop(&ctx->scope); return errors; } @@ -1643,7 +1618,6 @@ check_expr_match(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "match"); expr->type = EXPR_MATCH; struct expression *value = xcalloc(1, sizeof(struct expression)); @@ -1700,7 +1674,7 @@ check_expr_match(struct context *ctx, struct identifier ident = { .name = acase->name, }; - struct scope *scope = scope_push(&ctx->scope, TR_CHECK); + struct scope *scope = scope_push(&ctx->scope); scope->type = EXPR_MATCH; _case->object = scope_insert(scope, O_BIND, &ident, &ident, ctype, NULL); @@ -1712,7 +1686,7 @@ check_expr_match(struct context *ctx, hint, errors); if (acase->name) { - scope_pop(&ctx->scope, TR_CHECK); + scope_pop(&ctx->scope); } if (_case->value->terminates) { @@ -1764,8 +1738,6 @@ check_expr_match(struct context *ctx, tu = next; } } - - trleave(TR_CHECK, NULL); return errors; } @@ -1776,7 +1748,6 @@ check_expr_measure(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "measure"); expr->type = EXPR_MEASURE; expr->result = &builtin_type_size; expr->measure.op = aexpr->measure.op; @@ -1815,7 +1786,6 @@ check_expr_propagate(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "propagate"); struct expression *lvalue = xcalloc(1, sizeof(struct expression)); errors = check_expression(ctx, aexpr->propagate.value, lvalue, hint, errors); @@ -1897,7 +1867,7 @@ check_expr_propagate(struct context *ctx, expr->type = EXPR_MATCH; expr->match.value = lvalue; - struct scope *scope = scope_push(&ctx->scope, TR_CHECK); + struct scope *scope = scope_push(&ctx->scope); scope->type = EXPR_MATCH; struct match_case *case_ok = xcalloc(1, sizeof(struct match_case)); struct match_case *case_err = xcalloc(1, sizeof(struct match_case)); @@ -1943,7 +1913,7 @@ check_expr_propagate(struct context *ctx, expr->match.cases = case_ok; case_ok->next = case_err; - scope_pop(&ctx->scope, TR_CHECK); + scope_pop(&ctx->scope); expr->result = result_type; return errors; } @@ -1955,7 +1925,6 @@ check_expr_return(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "return"); if (ctx->deferring) { return error(aexpr->loc, expr, errors, "Cannot return inside a defer expression"); @@ -1987,8 +1956,6 @@ check_expr_return(struct context *ctx, ctx->fntype->func.result, rval); } expr->_return.value = rval; - - trleave(TR_CHECK, NULL); return errors; } @@ -1999,7 +1966,6 @@ check_expr_slice(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "slice"); expr->type = EXPR_SLICE; expr->slice.object = xcalloc(1, sizeof(struct expression)); @@ -2049,8 +2015,6 @@ check_expr_slice(struct context *ctx, } expr->result = type_store_lookup_slice(ctx->store, atype->array.members); - - trleave(TR_CHECK, NULL); return errors; } @@ -2061,7 +2025,6 @@ check_expr_struct(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "struct"); expr->type = EXPR_STRUCT; const struct type *stype = NULL; @@ -2184,8 +2147,6 @@ check_expr_struct(struct context *ctx, sexpr = sexpr->next; } } - - trleave(TR_CHECK, NULL); return errors; } @@ -2196,7 +2157,6 @@ check_expr_switch(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "switch"); expr->type = EXPR_SWITCH; struct expression *value = xcalloc(1, sizeof(struct expression)); @@ -2305,7 +2265,6 @@ check_expr_tuple(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "tuple"); expr->type = EXPR_TUPLE; const struct type_tuple *ttuple = NULL; @@ -2386,8 +2345,6 @@ check_expr_tuple(struct context *ctx, atuple = atuple->next; ttuple = ttuple->next; } - - trleave(TR_CHECK, NULL); return errors; } @@ -2398,7 +2355,6 @@ check_expr_unarithm(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "unarithm"); expr->type = EXPR_UNARITHM; struct expression *operand = xcalloc(1, sizeof(struct expression)); @@ -2455,8 +2411,6 @@ check_expr_unarithm(struct context *ctx, expr->result = type_dealias(operand->result)->pointer.referent; break; } - - trleave(TR_CHECK, NULL); return errors; } @@ -2467,7 +2421,6 @@ check_expression(struct context *ctx, const struct type *hint, struct errors *errors) { - trenter(TR_CHECK, "expression"); expr->loc = aexpr->loc; switch (aexpr->type) { @@ -2551,8 +2504,6 @@ check_expression(struct context *ctx, errors = check_expr_unarithm(ctx, aexpr, expr, hint, errors); break; } - - trleave(TR_CHECK, NULL); assert(expr->result); return errors; } @@ -2587,7 +2538,6 @@ check_function(struct context *ctx, return NULL; } - trenter(TR_CHECK, "function"); const struct ast_type fn_atype = { .storage = STORAGE_FUNCTION, .flags = TYPE_CONST, @@ -2612,7 +2562,7 @@ check_function(struct context *ctx, } mkident(ctx, &decl->ident, &afndecl->ident); - decl->func.scope = scope_push(&ctx->scope, TR_CHECK); + decl->func.scope = scope_push(&ctx->scope); struct ast_function_parameters *params = afndecl->prototype.params; while (params) { expect(&params->loc, params->name, @@ -2656,9 +2606,8 @@ check_function(struct context *ctx, "%s function cannot be exported", flags); } - scope_pop(&ctx->scope, TR_CHECK); + scope_pop(&ctx->scope); ctx->fntype = NULL; - trleave(TR_CHECK, NULL); return decl; } @@ -2726,7 +2675,6 @@ check_declarations(struct context *ctx, const struct ast_decls *adecls, struct declarations **next) { - trenter(TR_CHECK, "declarations"); while (adecls) { struct declaration *decl = NULL; const struct ast_decl *adecl = &adecls->decl; @@ -2755,7 +2703,6 @@ check_declarations(struct context *ctx, adecls = adecls->next; } - trleave(TR_CHECK, NULL); return next; } @@ -3062,7 +3009,6 @@ scan_const(struct context *ctx, const struct ast_global_decl *decl) return false; } } - trenter(TR_SCAN, "constant"); assert(!decl->symbol); // Invariant const struct type *type = type_store_lookup_atype( @@ -3095,8 +3041,6 @@ scan_const(struct context *ctx, const struct ast_global_decl *decl) struct identifier ident = {0}; mkident(ctx, &ident, &decl->ident); scope_insert(ctx->unit, O_CONST, &ident, &decl->ident, type, value); - - trleave(TR_SCAN, NULL); return true; } @@ -3116,7 +3060,6 @@ scan_function(struct context *ctx, const struct ast_function_decl *decl) if (!type_is_specified(ctx, &fn_atype)) { return false; } - trenter(TR_SCAN, "function"); const struct type *fntype = type_store_lookup_atype( ctx->store, &fn_atype); assert(fntype); @@ -3135,7 +3078,6 @@ scan_function(struct context *ctx, const struct ast_function_decl *decl) char buf[1024]; identifier_unparse_static(&decl->ident, buf, sizeof(buf)); - trleave(TR_SCAN, "func %s", buf); return true; } @@ -3149,7 +3091,6 @@ scan_global(struct context *ctx, const struct ast_global_decl *decl) return false; } } - trenter(TR_SCAN, "global"); const struct type *type = type_store_lookup_atype( ctx->store, decl->type); @@ -3181,8 +3122,6 @@ scan_global(struct context *ctx, const struct ast_global_decl *decl) mkident(ctx, &ident, &decl->ident); } scope_insert(ctx->unit, O_DECL, &ident, &decl->ident, type, NULL); - - trleave(TR_SCAN, NULL); return true; } @@ -3193,7 +3132,6 @@ scan_type(struct context *ctx, const struct ast_type_decl *decl) if (!type_is_specified(ctx, decl->type)) { return false; } - trenter(TR_SCAN, "type"); const struct type *type = type_store_lookup_atype(ctx->store, decl->type); @@ -3242,7 +3180,6 @@ scan_type(struct context *ctx, const struct ast_type_decl *decl) scope_insert(ctx->unit, O_CONST, &name, &vident, alias, expr); } } - trleave(TR_SCAN, NULL); return true; } @@ -3265,7 +3202,6 @@ scan_declaration(struct context *ctx, const struct ast_decl *decl) static struct ast_decls * scan_declarations(struct context *ctx, const struct ast_decls *decls) { - trenter(TR_SCAN, "declarations"); struct ast_decls *next = NULL; bool found = false; while (decls || next) { @@ -3289,7 +3225,6 @@ scan_declarations(struct context *ctx, const struct ast_decls *decls) } decls = decls->next; } - trleave(TR_SCAN, NULL); return next; } @@ -3411,7 +3346,7 @@ check_internal(struct type_store *ts, // // Further down the call frame, subsequent functions will create // sub-scopes for each declaration, expression-list, etc. - ctx.unit = scope_push(&ctx.scope, TR_MAX); + ctx.unit = scope_push(&ctx.scope); // Install defines (-D on the command line) // XXX: This duplicates a lot of code with scan_const @@ -3454,7 +3389,7 @@ check_internal(struct type_store *ts, // First pass populates the imports for (const struct ast_subunit *su = &aunit->subunits; su; su = su->next) { - scope_push(&ctx.scope, TR_SCAN); + scope_push(&ctx.scope); for (struct ast_imports *imports = su->imports; imports; imports = imports->next) { @@ -3483,7 +3418,7 @@ check_internal(struct type_store *ts, cur = new; *next = xcalloc(1, sizeof(struct scopes)); - new->scope = (*next)->scope = scope_pop(&ctx.scope, TR_SCAN); + new->scope = (*next)->scope = scope_pop(&ctx.scope); next = &(*next)->next; @@ -3547,9 +3482,7 @@ check_internal(struct type_store *ts, for (const struct ast_subunit *su = &aunit->subunits; su; su = su->next) { ctx.scope = scope->scope; - trenter(TR_CHECK, "scope %p", ctx.scope); next_decl = check_declarations(&ctx, su->decls, next_decl); - trleave(TR_CHECK, NULL); scope = scope->next; } diff --git a/src/gen.c b/src/gen.c @@ -10,7 +10,6 @@ #include "identifier.h" #include "qbe.h" #include "scope.h" -#include "trace.h" #include "typedef.h" #include "types.h" #include "util.h" @@ -3090,10 +3089,8 @@ gen(const struct unit *unit, struct qbe_program *out) }; ctx.out->next = &ctx.out->defs; const struct declarations *decls = unit->declarations; - trenter(TR_GEN, "gen"); while (decls) { gen_decl(&ctx, decls->decl); decls = decls->next; } - trleave(TR_GEN, NULL); } diff --git a/src/parse.c b/src/parse.c @@ -10,7 +10,6 @@ #include "identifier.h" #include "lex.h" #include "parse.h" -#include "trace.h" #include "types.h" #include "utf8.h" #include "util.h" @@ -110,8 +109,6 @@ parse_identifier(struct lexer *lexer, struct identifier *ident, bool trailing) struct token tok = {0}; struct identifier *i = ident; bool found_trailing = false; - trenter(TR_PARSE, "identifier"); - while (!i->name) { switch (lex(lexer, &tok)) { case T_NAME: @@ -141,17 +138,12 @@ parse_identifier(struct lexer *lexer, struct identifier *ident, bool trailing) break; } } - - char buf[1024]; - identifier_unparse_static(ident, buf, sizeof(buf)); - trleave(TR_PARSE, "%s", buf); return found_trailing; } static void parse_name_list(struct lexer *lexer, struct ast_imports *name) { - trenter(TR_PARSE, "name_list"); bool more = true; struct ast_imports **next = &name->next; while (more) { @@ -182,13 +174,11 @@ parse_name_list(struct lexer *lexer, struct ast_imports *name) break; } } - trleave(TR_PARSE, NULL); } static void parse_import(struct lexer *lexer, struct ast_imports *imports) { - trenter(TR_PARSE, "import"); struct identifier ident = {0}; bool trailing_colon = parse_identifier(lexer, &ident, true); @@ -220,14 +210,11 @@ parse_import(struct lexer *lexer, struct ast_imports *imports) synassert(trailing_colon, &tok, T_NAME, T_LBRACE, T_EOF); break; } - - trleave(TR_PARSE, NULL); } static void parse_imports(struct lexer *lexer, struct ast_subunit *subunit) { - trenter(TR_PARSE, "imports"); struct token tok = {0}; struct ast_imports **next = &subunit->imports; @@ -247,19 +234,11 @@ parse_imports(struct lexer *lexer, struct ast_subunit *subunit) break; } } - - for (struct ast_imports *i = subunit->imports; i; i = i->next) { - char buf[1024]; - identifier_unparse_static(&i->ident, buf, sizeof(buf)); - trace(TR_PARSE, "use %s", buf); - } - trleave(TR_PARSE, NULL); } static void parse_parameter_list(struct lexer *lexer, struct ast_function_type *type) { - trenter(TR_PARSE, "parameter-list"); struct token tok = {0}; bool more = true; type->params = mkfuncparams(&lexer->loc); @@ -277,7 +256,6 @@ parse_parameter_list(struct lexer *lexer, struct ast_function_type *type) want(lexer, T_COLON, NULL); next->type = parse_type(lexer); - trace(TR_PARSE, "%s: [type]", next->name); switch (lex(lexer, &tok)) { case T_COMMA: switch (lex(lexer, &tok)) { @@ -287,7 +265,6 @@ parse_parameter_list(struct lexer *lexer, struct ast_function_type *type) unlex(lexer, &tok); } more = false; - trace(TR_PARSE, ", ... (C style)"); break; case T_RPAREN: more = false; @@ -306,7 +283,6 @@ parse_parameter_list(struct lexer *lexer, struct ast_function_type *type) unlex(lexer, &tok); } more = false; - trace(TR_PARSE, "... (Hare style)"); break; default: more = false; @@ -314,13 +290,11 @@ parse_parameter_list(struct lexer *lexer, struct ast_function_type *type) break; } } - trleave(TR_PARSE, NULL); } static void parse_prototype(struct lexer *lexer, struct ast_function_type *type) { - trenter(TR_PARSE, "prototype"); want(lexer, T_LPAREN, NULL); struct token tok = {0}; if (lex(lexer, &tok) != T_RPAREN) { @@ -329,72 +303,47 @@ parse_prototype(struct lexer *lexer, struct ast_function_type *type) want(lexer, T_RPAREN, NULL); } type->result = parse_type(lexer); - size_t ctr = 0; - for (struct ast_function_parameters *param = type->params; - param; param = param->next) { - ctr++; - } - trace(TR_PARSE, "[%zu parameters] [type]", ctr); - trleave(TR_PARSE, NULL); } static enum type_storage parse_integer_type(struct lexer *lexer) { - trenter(TR_PARSE, "integer"); - enum type_storage storage; struct token tok = {0}; switch (lex(lexer, &tok)) { case T_I8: - storage = STORAGE_I8; - break; + return STORAGE_I8; case T_I16: - storage = STORAGE_I16; - break; + return STORAGE_I16; case T_I32: - storage = STORAGE_I32; - break; + return STORAGE_I32; case T_I64: - storage = STORAGE_I64; - break; + return STORAGE_I64; case T_U8: - storage = STORAGE_U8; - break; + return STORAGE_U8; case T_U16: - storage = STORAGE_U16; - break; + return STORAGE_U16; case T_U32: - storage = STORAGE_U32; - break; + return STORAGE_U32; case T_U64: - storage = STORAGE_U64; - break; + return STORAGE_U64; case T_INT: - storage = STORAGE_INT; - break; + return STORAGE_INT; case T_UINT: - storage = STORAGE_UINT; - break; + return STORAGE_UINT; case T_SIZE: - storage = STORAGE_SIZE; - break; + return STORAGE_SIZE; case T_UINTPTR: - storage = STORAGE_UINTPTR; - break; + return STORAGE_UINTPTR; case T_CHAR: - storage = STORAGE_CHAR; - break; + return STORAGE_CHAR; default: assert(0); } - trleave(TR_PARSE, "%s", type_storage_unparse(storage)); - return storage; } static struct ast_type * parse_primitive_type(struct lexer *lexer) { - trenter(TR_PARSE, "primitive"); struct token tok = {0}; struct ast_type *type = mktype(&lexer->loc); switch (lex(lexer, &tok)) { @@ -438,7 +387,6 @@ parse_primitive_type(struct lexer *lexer) default: assert(0); } - trleave(TR_PARSE, "%s", type_storage_unparse(type->storage)); return type; } @@ -448,7 +396,6 @@ static struct ast_expression *parse_binding_list( static struct ast_type * parse_enum_type(struct lexer *lexer) { - trenter(TR_PARSE, "enum"); struct token tok = {0}; struct ast_type *type = mktype(&lexer->loc); type->storage = STORAGE_ENUM; @@ -470,10 +417,8 @@ parse_enum_type(struct lexer *lexer) (*next)->name = tok.name; if (lex(lexer, &tok) == T_EQUAL) { (*next)->value = parse_expression(lexer); - trace(TR_PARSE, "%s = [expr]", (*next)->name); } else { unlex(lexer, &tok); - trace(TR_PARSE, "%s = [generated]", (*next)->name); } next = &(*next)->next; switch (lex(lexer, &tok)) { @@ -488,7 +433,6 @@ parse_enum_type(struct lexer *lexer) synassert(false, &tok, T_COMMA, T_RBRACE, T_EOF); } } - trleave(TR_PARSE, NULL); return type; } @@ -500,11 +444,9 @@ parse_struct_union_type(struct lexer *lexer) struct ast_struct_union_type *next = &type->struct_union; switch (lex(lexer, &tok)) { case T_STRUCT: - trenter(TR_PARSE, "struct"); type->storage = STORAGE_STRUCT; break; case T_UNION: - trenter(TR_PARSE, "union"); type->storage = STORAGE_UNION; break; default: @@ -531,7 +473,6 @@ parse_struct_union_type(struct lexer *lexer) next->member_type = MEMBER_TYPE_FIELD; next->field.name = name; next->field.type = parse_type(lexer); - trace(TR_PARSE, "%s: [type]", name); break; case T_DOUBLE_COLON: next->member_type = MEMBER_TYPE_ALIAS; @@ -542,14 +483,11 @@ parse_struct_union_type(struct lexer *lexer) } i->ns = xcalloc(sizeof(struct identifier), 1); i->ns->name = name; - trace(TR_PARSE, "[embedded alias %s]", - identifier_unparse(&next->alias)); break; default: unlex(lexer, &tok); next->member_type = MEMBER_TYPE_ALIAS; next->alias.name = name; - trace(TR_PARSE, "[embedded alias %s]", name); break; } break; @@ -558,7 +496,6 @@ parse_struct_union_type(struct lexer *lexer) next->member_type = MEMBER_TYPE_EMBEDDED; unlex(lexer, &tok); next->embedded = parse_struct_union_type(lexer); - trace(TR_PARSE, "[embedded struct/union]"); break; default: synassert(false, &tok, T_NAME, T_STRUCT, T_UNION, T_EOF); @@ -578,14 +515,12 @@ parse_struct_union_type(struct lexer *lexer) synassert(false, &tok, T_COMMA, T_RBRACE, T_EOF); } } - trleave(TR_PARSE, NULL); return type; } static struct ast_type * parse_tagged_type(struct lexer *lexer, struct ast_type *first) { - trenter(TR_PARSE, "tagged union"); struct ast_type *type = mktype(&first->loc); type->storage = STORAGE_TAGGED; struct ast_tagged_union_type *next = &type->tagged_union; @@ -607,14 +542,12 @@ parse_tagged_type(struct lexer *lexer, struct ast_type *first) synassert(false, &tok, T_BOR, T_RPAREN, T_EOF); } } - trleave(TR_PARSE, NULL); return type; } static struct ast_type * parse_tuple_type(struct lexer *lexer, struct ast_type *first) { - trenter(TR_PARSE, "tuple"); struct ast_type *type = mktype(&first->loc); type->storage = STORAGE_TUPLE; struct ast_tuple_type *next = &type->tuple; @@ -636,7 +569,6 @@ parse_tuple_type(struct lexer *lexer, struct ast_type *first) synassert(false, &tok, T_COMMA, T_RPAREN, T_EOF); } } - trleave(TR_PARSE, NULL); return type; } @@ -659,7 +591,6 @@ parse_tagged_or_tuple_type(struct lexer *lexer) struct ast_type * parse_type(struct lexer *lexer) { - trenter(TR_PARSE, "type"); struct token tok = {0}; uint32_t flags = 0; switch (lex(lexer, &tok)) { @@ -702,7 +633,6 @@ parse_type(struct lexer *lexer) case T_NULLABLE: nullable = true; want(lexer, T_TIMES, NULL); - trace(TR_PARSE, "nullable"); /* fallthrough */ case T_TIMES: type = mktype(&lexer->loc); @@ -777,8 +707,6 @@ parse_type(struct lexer *lexer) break; } type->flags |= flags; - trleave(TR_PARSE, "%s%s", type->flags & TYPE_CONST ? "const " : "", - type_storage_unparse(type->storage)); if (lex(lexer, &tok) == T_LNOT) { type->flags |= TYPE_ERROR; @@ -792,7 +720,6 @@ parse_type(struct lexer *lexer) static struct ast_expression * parse_access(struct lexer *lexer, struct identifier ident) { - trace(TR_PARSE, "access"); struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_ACCESS; exp->access.type = ACCESS_IDENTIFIER; @@ -803,8 +730,6 @@ parse_access(struct lexer *lexer, struct identifier ident) static struct ast_expression * parse_constant(struct lexer *lexer) { - trenter(TR_PARSE, "constant"); - struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_CONSTANT; @@ -891,16 +816,12 @@ parse_constant(struct lexer *lexer) case STORAGE_UNION: assert(0); // Handled in a different nonterminal } - - trleave(TR_PARSE, "%s", token_str(&tok)); return exp; } static struct ast_expression * parse_array_literal(struct lexer *lexer) { - trenter(TR_PARSE, "array-literal"); - struct token tok; want(lexer, T_LBRACKET, &tok); @@ -940,8 +861,6 @@ parse_array_literal(struct lexer *lexer) synassert(false, &tok, T_ELLIPSIS, T_COMMA, T_RBRACKET, T_EOF); } } - - trleave(TR_PARSE, NULL); return exp; } @@ -965,13 +884,11 @@ parse_field_value(struct lexer *lexer) exp->field.type = parse_type(lexer); want(lexer, T_EQUAL, NULL); exp->field.initializer = parse_expression(lexer); - trace(TR_PARSE, "%s: [type] = [expr]", name); break; case T_EQUAL: exp->is_embedded = false; exp->field.name = name; exp->field.initializer = parse_expression(lexer); - trace(TR_PARSE, "%s = [expr]", name); break; case T_DOUBLE_COLON: exp->is_embedded = true; @@ -984,8 +901,6 @@ parse_field_value(struct lexer *lexer) i->ns = xcalloc(sizeof(struct identifier), 1); i->ns->name = name; exp->embedded = parse_struct_literal(lexer, ident); - trace(TR_PARSE, "[embedded struct %s]", - identifier_unparse(&ident)); break; default: unlex(lexer, &tok); @@ -993,7 +908,6 @@ parse_field_value(struct lexer *lexer) ident.name = name; ident.ns = NULL; exp->embedded = parse_struct_literal(lexer, ident); - trace(TR_PARSE, "[embedded struct %s]", name); break; } break; @@ -1001,7 +915,6 @@ parse_field_value(struct lexer *lexer) exp->is_embedded = true; struct identifier id = {0}; exp->embedded = parse_struct_literal(lexer, id); - trace(TR_PARSE, "[embedded anonymous struct]"); break; default: assert(0); @@ -1012,7 +925,6 @@ parse_field_value(struct lexer *lexer) static struct ast_expression * parse_struct_literal(struct lexer *lexer, struct identifier ident) { - trenter(TR_PARSE, "struct-literal"); want(lexer, T_LBRACE, NULL); struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_STRUCT; @@ -1022,7 +934,6 @@ parse_struct_literal(struct lexer *lexer, struct identifier ident) while (tok.token != T_RBRACE) { switch (lex(lexer, &tok)) { case T_ELLIPSIS: - trace(TR_PARSE, "..."); synassert(ident.name != NULL, &tok, T_RBRACE, T_EOF); exp->_struct.autofill = true; if (lex(lexer, &tok) != T_COMMA) { @@ -1054,7 +965,6 @@ parse_struct_literal(struct lexer *lexer, struct identifier ident) synassert(false, &tok, T_COMMA, T_RBRACE, T_EOF); } } - trleave(TR_PARSE, NULL); return exp; } @@ -1099,8 +1009,6 @@ parse_tuple_expression(struct lexer *lexer, struct ast_expression *first) static struct ast_expression * parse_plain_expression(struct lexer *lexer) { - trace(TR_PARSE, "plain"); - struct token tok = {0}; struct ast_expression *exp; switch (lex(lexer, &tok)) { @@ -1154,8 +1062,6 @@ parse_plain_expression(struct lexer *lexer) static struct ast_expression * parse_assertion_expression(struct lexer *lexer, bool is_static) { - trace(TR_PARSE, is_static ? "static assertion" : "assertion"); - struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_ASSERT; exp->assert.is_static = is_static; @@ -1201,8 +1107,6 @@ parse_assertion_expression(struct lexer *lexer, bool is_static) static struct ast_expression * parse_measurement_expression(struct lexer *lexer) { - trace(TR_PARSE, "measurement"); - struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_MEASURE; @@ -1233,8 +1137,6 @@ parse_measurement_expression(struct lexer *lexer) static struct ast_expression * parse_call_expression(struct lexer *lexer, struct ast_expression *lvalue) { - trenter(TR_PARSE, "call"); - struct token tok; want(lexer, T_LPAREN, &tok); @@ -1245,8 +1147,6 @@ parse_call_expression(struct lexer *lexer, struct ast_expression *lvalue) struct ast_call_argument *arg, **next = &expr->call.args; while (lex(lexer, &tok) != T_RPAREN) { unlex(lexer, &tok); - trenter(TR_PARSE, "arg"); - arg = *next = xcalloc(1, sizeof(struct ast_call_argument)); arg->value = parse_expression(lexer); @@ -1267,18 +1167,13 @@ parse_call_expression(struct lexer *lexer, struct ast_expression *lvalue) } next = &arg->next; - trleave(TR_PARSE, NULL); } - - trleave(TR_PARSE, NULL); return expr; } static struct ast_expression * parse_index_slice_expression(struct lexer *lexer, struct ast_expression *lvalue) { - trenter(TR_PARSE, "slice-index"); - struct ast_expression *exp = mkexpr(&lexer->loc); struct ast_expression *start = NULL, *end = NULL; struct token tok; @@ -1315,7 +1210,6 @@ parse_index_slice_expression(struct lexer *lexer, struct ast_expression *lvalue) exp->access.type = ACCESS_INDEX; exp->access.array = lvalue; exp->access.index = start; - trleave(TR_PARSE, "slice-index (index)"); return exp; } else if (tok.token == T_RBRACKET) { unlex(lexer, &tok); @@ -1335,19 +1229,16 @@ parse_index_slice_expression(struct lexer *lexer, struct ast_expression *lvalue) exp->slice.object = lvalue; exp->slice.start = start; exp->slice.end = end; - trleave(TR_PARSE, "slice-index (slice)"); return exp; } static struct ast_expression * parse_allocation_expression(struct lexer *lexer) { - trenter(TR_PARSE, "allocation"); struct ast_expression *exp = NULL; struct token tok = {0}; switch (lex(lexer, &tok)) { case T_ALLOC: - trace(TR_PARSE, "alloc"); exp = mkexpr(&tok.loc); exp->type = EXPR_ALLOC; want(lexer, T_LPAREN, NULL); @@ -1364,7 +1255,6 @@ parse_allocation_expression(struct lexer *lexer) } break; case T_APPEND: - trace(TR_PARSE, "append"); exp = mkexpr(&tok.loc); exp->type = EXPR_APPEND; want(lexer, T_LPAREN, NULL); @@ -1394,7 +1284,6 @@ parse_allocation_expression(struct lexer *lexer) } break; case T_FREE: - trace(TR_PARSE, "free"); exp = mkexpr(&tok.loc); exp->type = EXPR_FREE; want(lexer, T_LPAREN, NULL); @@ -1402,7 +1291,6 @@ parse_allocation_expression(struct lexer *lexer) want(lexer, T_RPAREN, NULL); break; case T_DELETE: - trace(TR_PARSE, "delete"); exp = mkexpr(&tok.loc); exp->type = EXPR_DELETE; want(lexer, T_LPAREN, NULL); @@ -1412,15 +1300,12 @@ parse_allocation_expression(struct lexer *lexer) default: assert(0); } - trleave(TR_PARSE, NULL); return exp; } static struct ast_expression * parse_postfix_expression(struct lexer *lexer, struct ast_expression *lvalue) { - trace(TR_PARSE, "postfix"); - if (lvalue == NULL) { lvalue = parse_plain_expression(lexer); } @@ -1433,7 +1318,6 @@ parse_postfix_expression(struct lexer *lexer, struct ast_expression *lvalue) lvalue = parse_call_expression(lexer, lvalue); break; case T_DOT: - trenter(TR_PARSE, "field-access"); exp = mkexpr(&lexer->loc); exp->type = EXPR_ACCESS; @@ -1454,7 +1338,6 @@ parse_postfix_expression(struct lexer *lexer, struct ast_expression *lvalue) } lvalue = exp; - trleave(TR_PARSE, NULL); break; case T_LBRACKET: unlex(lexer, &tok); @@ -1499,7 +1382,6 @@ unop_for_token(enum lexical_token tok) static struct ast_expression * parse_object_selector(struct lexer *lexer) { - trace(TR_PARSE, "object-selector"); struct token tok; lex(lexer, &tok); unlex(lexer, &tok); @@ -1543,8 +1425,6 @@ parse_builtin_expression(struct lexer *lexer) static struct ast_expression * parse_unary_expression(struct lexer *lexer) { - trace(TR_PARSE, "unary-arithmetic"); - struct token tok; struct ast_expression *exp; switch (lex(lexer, &tok)) { @@ -1572,7 +1452,6 @@ parse_unary_expression(struct lexer *lexer) static struct ast_expression * parse_cast_expression(struct lexer *lexer, struct ast_expression *value) { - trace(TR_PARSE, "cast"); if (value == NULL) { value = parse_unary_expression(lexer); } @@ -1692,7 +1571,6 @@ binop_for_token(enum lexical_token tok) static struct ast_expression * parse_bin_expression(struct lexer *lexer, struct ast_expression *lvalue, int i) { - trace(TR_PARSE, "bin-arithm"); if (!lvalue) { lvalue = parse_cast_expression(lexer, NULL); } @@ -1730,7 +1608,6 @@ parse_bin_expression(struct lexer *lexer, struct ast_expression *lvalue, int i) static struct ast_expression * parse_if_expression(struct lexer *lexer) { - trenter(TR_PARSE, "if"); struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_IF; @@ -1755,15 +1632,12 @@ parse_if_expression(struct lexer *lexer) unlex(lexer, &tok); break; } - - trleave(TR_PARSE, NULL); return exp; } static struct ast_expression * parse_for_expression(struct lexer *lexer) { - trenter(TR_PARSE, "for"); struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_FOR; @@ -1807,8 +1681,6 @@ parse_for_expression(struct lexer *lexer) } exp->_for.body = parse_expression(lexer); - - trleave(TR_PARSE, NULL); return exp; } @@ -1860,7 +1732,6 @@ parse_case_options(struct lexer *lexer) static struct ast_expression * parse_switch_expression(struct lexer *lexer) { - trenter(TR_PARSE, "switch"); struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_SWITCH; @@ -1906,7 +1777,6 @@ parse_switch_expression(struct lexer *lexer) static struct ast_expression * parse_match_expression(struct lexer *lexer) { - trenter(TR_PARSE, "match"); struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_MATCH; @@ -1995,15 +1865,12 @@ parse_match_expression(struct lexer *lexer) next_case = &_case->next; } - - trleave(TR_PARSE, NULL); return exp; } static struct ast_expression * parse_binding_list(struct lexer *lexer, bool is_static) { - trenter(TR_PARSE, "binding-list"); struct ast_expression *exp = mkexpr(&lexer->loc); exp->type = EXPR_BINDING; unsigned int flags = 0; @@ -2057,8 +1924,6 @@ parse_binding_list(struct lexer *lexer, bool is_static) break; } } - - trleave(TR_PARSE, NULL); return exp; } @@ -2066,7 +1931,6 @@ static struct ast_expression * parse_assignment(struct lexer *lexer, struct ast_expression *object, bool indirect, enum binarithm_operator op) { - trenter(TR_PARSE, "assign"); struct ast_expression *value = parse_expression(lexer); struct ast_expression *expr = mkexpr(&lexer->loc); expr->type = EXPR_ASSIGN; @@ -2074,7 +1938,6 @@ parse_assignment(struct lexer *lexer, struct ast_expression *object, expr->assign.object = object; expr->assign.value = value; expr->assign.indirect = indirect; - trleave(TR_PARSE, NULL); return expr; } @@ -2090,15 +1953,12 @@ parse_deferred_expression(struct lexer *lexer) static struct ast_expression * parse_control_statement(struct lexer *lexer) { - trenter(TR_PARSE, "control-expression"); - struct ast_expression *exp = mkexpr(&lexer->loc); struct token tok; switch (lex(lexer, &tok)) { case T_BREAK: case T_CONTINUE: - trace(TR_PARSE, tok.token == T_BREAK ? "break" : "continue"); exp->type = tok.token == T_BREAK ? EXPR_BREAK : EXPR_CONTINUE; exp->control.label = NULL; switch (lex(lexer, &tok)) { @@ -2111,7 +1971,6 @@ parse_control_statement(struct lexer *lexer) } break; case T_RETURN: - trace(TR_PARSE, "return"); exp->type = EXPR_RETURN; exp->_return.value = NULL; struct token tok; @@ -2129,15 +1988,12 @@ parse_control_statement(struct lexer *lexer) default: synassert(false, &tok, T_BREAK, T_CONTINUE, T_RETURN, T_EOF); } - - trleave(TR_PARSE, NULL); return exp; } static struct ast_expression * parse_expression_list(struct lexer *lexer) { - trenter(TR_PARSE, "expression-list"); struct ast_expression *exp = mkexpr(&lexer->loc); struct ast_expression_list *cur = &exp->list; struct ast_expression_list **next = &cur->next; @@ -2176,8 +2032,6 @@ parse_expression_list(struct lexer *lexer) want(lexer, T_RBRACE, &tok); } } - - trleave(TR_PARSE, NULL); return exp; } @@ -2336,7 +2190,6 @@ static void parse_global_decl(struct lexer *lexer, enum lexical_token mode, struct ast_global_decl *decl) { - trenter(TR_PARSE, "global"); struct token tok = {0}; struct ast_global_decl *i = decl; assert(mode == T_LET || mode == T_CONST || mode == T_DEF); @@ -2381,25 +2234,11 @@ parse_global_decl(struct lexer *lexer, enum lexical_token mode, break; } } - - for (struct ast_global_decl *i = decl; i; i = i->next) { - char buf[1024]; - identifier_unparse_static(&i->ident, buf, sizeof(buf)); - if (decl->symbol) { - trace(TR_PARSE, "%s @symbol(\"%s\") %s: [type] = [expr]", - lexical_token_str(mode), decl->symbol, buf); - } else { - trace(TR_PARSE, "%s %s: [type] = [expr]", - lexical_token_str(mode), buf); - } - } - trleave(TR_PARSE, NULL); } static void parse_type_decl(struct lexer *lexer, struct ast_type_decl *decl) { - trenter(TR_PARSE, "typedef"); struct token tok = {0}; struct ast_type_decl *i = decl; bool more = true; @@ -2422,19 +2261,11 @@ parse_type_decl(struct lexer *lexer, struct ast_type_decl *decl) break; } } - - for (struct ast_type_decl *i = decl; i; i = i->next) { - char ibuf[1024]; - identifier_unparse_static(&i->ident, ibuf, sizeof(ibuf)); - trace(TR_PARSE, "def %s = [type]", ibuf); - } - trleave(TR_PARSE, NULL); } static void parse_fn_decl(struct lexer *lexer, struct ast_function_decl *decl) { - trenter(TR_PARSE, "fn"); struct token tok = {0}; bool more = true; bool noreturn = false; @@ -2479,19 +2310,6 @@ parse_fn_decl(struct lexer *lexer, struct ast_function_decl *decl) default: synassert(false, &tok, T_EQUAL, T_SEMICOLON, T_EOF); } - - char symbol[1024], buf[1024]; - if (decl->symbol) { - snprintf(symbol, sizeof(symbol), "@symbol(\"%s\") ", decl->symbol); - } - identifier_unparse_static(&decl->ident, buf, sizeof(buf)); - trace(TR_PARSE, "%s%s%s%s%sfn %s [prototype] = [expr]", - decl->flags & FN_FINI ? "@fini " : "", - decl->flags & FN_INIT ? "@init " : "", - decl->prototype.flags & FN_NORETURN ? "@noreturn " : "", - decl->flags & FN_TEST ? "@test " : "", - decl->symbol ? symbol : "", buf); - trleave(TR_PARSE, NULL); } static void @@ -2526,7 +2344,6 @@ parse_decl(struct lexer *lexer, struct ast_decl *decl) static void parse_decls(struct lexer *lexer, struct ast_decls **decls) { - trenter(TR_PARSE, "decls"); struct token tok = {0}; struct ast_decls **next = decls; while (tok.token != T_EOF) { @@ -2535,7 +2352,6 @@ parse_decls(struct lexer *lexer, struct ast_decls **decls) switch (lex(lexer, &tok)) { case T_EXPORT: decl->decl.exported = true; - trace(TR_PARSE, "export"); break; default: unlex(lexer, &tok); @@ -2553,7 +2369,6 @@ parse_decls(struct lexer *lexer, struct ast_decls **decls) } free(*next); *next = 0; - trleave(TR_PARSE, NULL); } void diff --git a/src/scope.c b/src/scope.c @@ -3,7 +3,6 @@ #include "expr.h" #include "identifier.h" #include "scope.h" -#include "trace.h" #include "util.h" static uint32_t @@ -13,7 +12,7 @@ name_hash(uint32_t init, const struct identifier *ident) } struct scope * -scope_push(struct scope **stack, enum trace_sys sys) +scope_push(struct scope **stack) { struct scope *new = xcalloc(1, sizeof(struct scope)); new->next = &new->objects; @@ -21,21 +20,15 @@ scope_push(struct scope **stack, enum trace_sys sys) new->parent = *stack; } *stack = new; - if (sys != TR_MAX) { - trenter(sys, "scope %p", new); - } return new; } struct scope * -scope_pop(struct scope **stack, enum trace_sys sys) +scope_pop(struct scope **stack) { struct scope *prev = *stack; assert(prev); *stack = prev->parent; - if (sys != TR_MAX) { - trleave(sys, NULL); - } return prev; } diff --git a/src/trace.c b/src/trace.c @@ -1,71 +0,0 @@ -#include <assert.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "trace.h" - -static const char *sysname[] = { - [TR_LEX] = "lex", - [TR_PARSE] = "parse", - [TR_SCAN] = "scan", - [TR_CHECK] = "check", - [TR_GEN] = "gen", -}; - -static int depth[] = { - [TR_LEX] = 0, - [TR_PARSE] = 0, - [TR_SCAN] = 0, - [TR_CHECK] = 0, - [TR_GEN] = 0, -}; - -static void -va_trace(enum trace_sys sys, const char *fmt, va_list ap) -{ - assert(sys < TR_MAX); - char *t = getenv("HA_TRACE"); - if (!t || !strstr(t, sysname[sys])) { - return; - } - fprintf(stderr, "[%10s] ", sysname[sys]); - for (int i = 0; i < depth[sys]; ++i) { - fprintf(stderr, " "); - } - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); -} - -void -trace(enum trace_sys sys, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - va_trace(sys, fmt, ap); - va_end(ap); -} - -void -trenter(enum trace_sys sys, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - va_trace(sys, fmt, ap); - va_end(ap); - ++depth[sys]; -} - -void -trleave(enum trace_sys sys, const char *fmt, ...) -{ - --depth[sys]; - if (fmt == NULL) { - return; - } - - va_list ap; - va_start(ap, fmt); - va_trace(sys, fmt, ap); - va_end(ap); -} diff --git a/src/type_store.c b/src/type_store.c @@ -531,8 +531,7 @@ type_init_from_atype(struct type_store *store, type->size = storage->size; type->align = storage->size; - struct scope *scope = scope_push( - &store->check_context->scope, TR_CHECK); + struct scope *scope = scope_push(&store->check_context->scope); // TODO: Check for duplicates struct ast_enum_field *avalue = atype->_enum.values; struct type_enum_value **values = &type->_enum.values; @@ -580,7 +579,7 @@ type_init_from_atype(struct type_store *store, values = &value->next; avalue = avalue->next; } - scope_pop(&store->check_context->scope, TR_CHECK); + scope_pop(&store->check_context->scope); scope_free(scope); break; case STORAGE_FUNCTION: