diff --git a/include/absyn.h b/include/absyn.h index d208b4a2..d2ab1c97 100644 --- a/include/absyn.h +++ b/include/absyn.h @@ -649,7 +649,7 @@ enum ae_pp_type { }; #define MK_STMT_PP(_type, _pos, ...) (struct Stmt_){ .stmt_type = ae_stmt_pp, \ - .d = { .stmt_pp = { __VA_ARGS__, .pp_type = ae_pp_##_type, }}, .pos = _pos } + .d = { .stmt_pp = { __VA_ARGS__, .pp_type = ae_pp_##_type, }}, .loc = _pos } struct Stmt_PP_ { m_str data; Exp exp; @@ -677,8 +677,8 @@ struct Stmt_ { struct Stmt_Defer_ stmt_defer; struct Spread_Def_ stmt_spread; } d; - loc_t pos; ///< position - ae_stmt_t stmt_type; + loc_t loc; ///< position + ae_stmt_t stmt_type; }; static inline Stmt stmt_self(const void *data) { diff --git a/src/ast_cpy.c b/src/ast_cpy.c index e4891c5b..2abed376 100644 --- a/src/ast_cpy.c +++ b/src/ast_cpy.c @@ -502,7 +502,7 @@ ANN static void cpy_stmt2(MemPool p, const Stmt a, const Stmt src) { break; } a->stmt_type = src->stmt_type; - a->pos = src->pos; + a->loc = src->loc; } ANN Func_Def cpy_func_def(MemPool p, const Func_Def src) { diff --git a/src/ast_new.c b/src/ast_new.c index 6775763c..ddee02bc 100644 --- a/src/ast_new.c +++ b/src/ast_new.c @@ -52,7 +52,7 @@ AST_NEW(Exp, exp_lambda2, const Symbol xid, const Arg_List args, const Exp exp, Func_Base *base = new_func_base(p, NULL, xid, args, ae_flag_none, loc); base->fbflag |= fbflag_lambda; Stmt_List code = new_mp_vector(p, struct Stmt_, 1); - struct Stmt_ stmt = { .d = { .stmt_exp = { .val = exp }}, .stmt_type=ae_stmt_return, .pos = loc }; + struct Stmt_ stmt = { .d = { .stmt_exp = { .val = exp }}, .stmt_type=ae_stmt_return, .loc = loc }; mp_vector_set(code, struct Stmt_, 0, stmt); a->d.exp_lambda.def = new_func_def(p, base, code); return a; @@ -335,7 +335,7 @@ AST_NEW(Stmt, stmt_code, const Stmt_List list, const loc_t loc) { AST_NEW(Stmt, stmt, const ae_stmt_t type, const loc_t loc) { Stmt a = mp_calloc(p, Stmt); a->stmt_type = type; - a->pos = loc; + a->loc = loc; return a; } @@ -376,7 +376,7 @@ AST_NEW(Stmt, stmt_loop, const Exp cond, const Stmt body, } AST_NEW(Stmt, stmt_try, const restrict Stmt stmt, const Handler_List handler) { - Stmt a = new_stmt(p, ae_stmt_try, stmt->pos); + Stmt a = new_stmt(p, ae_stmt_try, stmt->loc); a->d.stmt_try.stmt = cpy_stmt3(p, stmt); a->d.stmt_try.handler = handler; return a; diff --git a/src/defer.c b/src/defer.c index 5dbc2317..c0045434 100644 --- a/src/defer.c +++ b/src/defer.c @@ -67,7 +67,7 @@ static loc_t defer_func(void* arg NUSED) { return (loc_t){}; } #define defer_stmt_exp defer_func ANN static loc_t defer_stmt_return(const Stmt_Exp stmt) { - return stmt_self(stmt)->pos; + return stmt_self(stmt)->loc; } ANN static loc_t defer_stmt_defer(const Stmt_Defer stmt) { diff --git a/src/gwion.y b/src/gwion.y index b36da9f6..d7c88535 100644 --- a/src/gwion.y +++ b/src/gwion.y @@ -391,9 +391,9 @@ fptr_list: fptr_arg { YYLIST_INI(Arg, $$, $1); } code_stmt : "{" "}" { - $$ = (struct Stmt_) { .stmt_type = ae_stmt_code, .pos = @$}; } + $$ = (struct Stmt_) { .stmt_type = ae_stmt_code, .loc = @$}; } | "{" stmt_list "}" { - $$ = (struct Stmt_) { .stmt_type = ae_stmt_code, .d = { .stmt_code = { .stmt_list = $2 }}, .pos = @$}; }; + $$ = (struct Stmt_) { .stmt_type = ae_stmt_code, .d = { .stmt_code = { .stmt_list = $2 }}, .loc = @$}; }; code_list : "{" "}" { $$ = new_mp_vector(mpool(arg), struct Stmt_, 0); } @@ -435,13 +435,13 @@ spread_stmt: "..." ID ":" id_list "{" {lex_spread(((Scanner*)scan));} SPREAD { .list = $4, .data = $7, }; - $$ = (struct Stmt_) { .stmt_type = ae_stmt_spread, .d = { .stmt_spread = spread }, .pos = @2}; + $$ = (struct Stmt_) { .stmt_type = ae_stmt_spread, .d = { .stmt_spread = spread }, .loc = @2}; } retry_stmt: "retry" ";" { if(!arg->handling) { parser_error(&@1, arg, "`retry` outside of `handle` block", 0); YYERROR; } - $$ = (struct Stmt_){ .stmt_type=ae_stmt_retry, .pos=@1}; + $$ = (struct Stmt_){ .stmt_type=ae_stmt_retry, .loc=@1}; }; handler: "handle" { arg->handling = true; } opt_id stmt { $$ = (Handler){ .tag = MK_TAG($3, $3 ? @3 :@1), .stmt = cpy_stmt3(mpool(arg), &$4) }; arg->handling = false; }; handler_list: handler { @@ -466,7 +466,7 @@ mp_vector_add(mpool(arg), &$1.handlers, Handler, $2); } try_stmt: "try" stmt handler_list { $$ = (struct Stmt_){ .stmt_type = ae_stmt_try, .d = { .stmt_try = { .stmt = cpy_stmt3(mpool(arg), &$2), .handler = $3.handlers, }}, - .pos = @1}; + .loc = @1}; }; opt_id: ID | { $$ = NULL; }; @@ -501,7 +501,7 @@ match_case_stmt .when = $3, .list = $5 }}, - .pos = @1 + .loc = @1 }; }; @@ -515,7 +515,7 @@ match_stmt: "match" exp "{" match_list "}" "where" stmt { .list = $4, .where = cpy_stmt3(mpool(arg), &$7) }}, - .pos = @1 + .loc = @1 }; } | @@ -525,7 +525,7 @@ match_stmt: "match" exp "{" match_list "}" "where" stmt { .cond = $2, .list = $4, }}, - .pos = @1 + .loc = @1 }; }; @@ -541,7 +541,7 @@ loop_stmt .cond = $3, .body = cpy_stmt3(mpool(arg), &$5) }}, - .pos = @1 + .loc = @1 }; } | "do" stmt flow exp ";" @@ -551,7 +551,7 @@ loop_stmt .body = cpy_stmt3(mpool(arg), &$2), .is_do = true }}, - .pos = @1 + .loc = @1 }; } | "for" "(" exp_stmt exp_stmt ")" stmt @@ -561,7 +561,7 @@ loop_stmt .c2 = cpy_stmt3(mpool(arg), &$4), .body = cpy_stmt3(mpool(arg), &$6), }}, - .pos = @1 + .loc = @1 }; } | "for" "(" exp_stmt exp_stmt exp ")" stmt @@ -572,7 +572,7 @@ loop_stmt .c3 = $5, .body = cpy_stmt3(mpool(arg), &$7), }}, - .pos = @1 + .loc = @1 }; } | "foreach" "(" ID ":" opt_var binary_exp ")" stmt @@ -582,7 +582,7 @@ loop_stmt .exp = $6, .body = cpy_stmt3(mpool(arg), &$8), }}, - .pos = @1 + .loc = @1 }; // what to do with opt_var? // list rem? @@ -594,7 +594,7 @@ loop_stmt .exp = $8, .body = cpy_stmt3(mpool(arg), &$10), }}, - .pos = @1 + .loc = @1 }; $$.d.stmt_each.idx = mp_malloc(mpool(arg), EachIdx); $$.d.stmt_each.idx->var = (Var_Decl){.tag=MK_TAG($3, @3)}; @@ -608,7 +608,7 @@ loop_stmt .cond = $3, .body = cpy_stmt3(mpool(arg), &$5) }}, - .pos = @1 + .loc = @1 }; } | "repeat" "(" ID "," binary_exp ")" stmt @@ -617,7 +617,7 @@ loop_stmt .cond = $5, .body = cpy_stmt3(mpool(arg), &$7) }}, - .pos = @1 + .loc = @1 }; $$.d.stmt_loop.idx = mp_malloc(mpool(arg), EachIdx); $$.d.stmt_loop.idx->var = (Var_Decl){ .tag = MK_TAG($3, @3) }; @@ -632,7 +632,7 @@ defer_stmt: "defer" stmt { } $$ = (struct Stmt_) { .stmt_type = ae_stmt_defer, .d = { .stmt_defer = { .stmt = cpy_stmt3(mpool(arg), &$2) }}, - .pos = @1 + .loc = @1 }; }; @@ -643,7 +643,7 @@ selection_stmt .cond = $3, .if_body = cpy_stmt3(mpool(arg), &$5) }}, - .pos = @1 + .loc = @1 }; } | "if" "(" exp ")" stmt "else" stmt @@ -653,7 +653,7 @@ selection_stmt .if_body = cpy_stmt3(mpool(arg), &$5), .else_body = cpy_stmt3(mpool(arg), &$7) }}, - .pos = @1 + .loc = @1 }; }; @@ -661,31 +661,31 @@ breaks: "break" { $$ = ae_stmt_break; } | CONTINUE { $$ = ae_stmt_continue; jump_stmt : "return" exp ";" { $$ = (struct Stmt_) { .stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = $2 }}, - .pos = @1 + .loc = @1 }; } | "return" ";" { $$ = (struct Stmt_) { .stmt_type = ae_stmt_return, - .pos = @1 + .loc = @1 }; } | breaks decimal ";" { $$ = (struct Stmt_) { .stmt_type = $1, .d = { .stmt_index = { .idx = $2.num }}, - .pos = @1 + .loc = @1 }; } | breaks ";" { $$ = (struct Stmt_) { .stmt_type = $1, .d = { .stmt_index = { .idx = -1 }}, - .pos = @1 }; + .loc = @1 }; }; exp_stmt : exp ";" { $$ = (struct Stmt_) { .stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = $1 }}, - .pos = @1 + .loc = @1 }; } | ";" { $$ = (struct Stmt_) { .stmt_type = ae_stmt_exp, - .pos = @1 + .loc = @1 }; }; diff --git a/src/parser.c b/src/parser.c index 2c389f91..07d7da5e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -3036,14 +3036,14 @@ YYLTYPE yylloc = yyloc_default; case 66: /* code_stmt: "{" "}" */ #line 393 "src/gwion.y" { - (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_code, .pos = (yyloc)}; } + (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_code, .loc = (yyloc)}; } #line 3041 "src/parser.c" break; case 67: /* code_stmt: "{" stmt_list "}" */ #line 395 "src/gwion.y" { - (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_code, .d = { .stmt_code = { .stmt_list = (yyvsp[-1].stmt_list) }}, .pos = (yyloc)}; } + (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_code, .d = { .stmt_code = { .stmt_list = (yyvsp[-1].stmt_list) }}, .loc = (yyloc)}; } #line 3048 "src/parser.c" break; @@ -3145,7 +3145,7 @@ YYLTYPE yylloc = yyloc_default; .list = (yyvsp[-3].id_list), .data = (yyvsp[0].sval), }; - (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_spread, .d = { .stmt_spread = spread }, .pos = (yylsp[-5])}; + (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_spread, .d = { .stmt_spread = spread }, .loc = (yylsp[-5])}; } #line 3151 "src/parser.c" break; @@ -3155,7 +3155,7 @@ YYLTYPE yylloc = yyloc_default; { if(!arg->handling) { parser_error(&(yylsp[-1]), arg, "`retry` outside of `handle` block", 0); YYERROR; } - (yyval.stmt) = (struct Stmt_){ .stmt_type=ae_stmt_retry, .pos=(yylsp[-1])}; + (yyval.stmt) = (struct Stmt_){ .stmt_type=ae_stmt_retry, .loc=(yylsp[-1])}; } #line 3161 "src/parser.c" break; @@ -3206,7 +3206,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] #line 467 "src/gwion.y" { (yyval.stmt) = (struct Stmt_){ .stmt_type = ae_stmt_try, .d = { .stmt_try = { .stmt = cpy_stmt3(mpool(arg), &(yyvsp[-1].stmt)), .handler = (yyvsp[0].handler_list).handlers, }}, - .pos = (yylsp[-2])}; + .loc = (yylsp[-2])}; } #line 3212 "src/parser.c" break; @@ -3283,7 +3283,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .when = (yyvsp[-2].exp), .list = (yyvsp[0].stmt_list) }}, - .pos = (yylsp[-4]) + .loc = (yylsp[-4]) }; } #line 3290 "src/parser.c" @@ -3310,7 +3310,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .list = (yyvsp[-3].stmt_list), .where = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)) }}, - .pos = (yylsp[-6]) + .loc = (yylsp[-6]) }; } #line 3317 "src/parser.c" @@ -3324,7 +3324,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .cond = (yyvsp[-3].exp), .list = (yyvsp[-1].stmt_list), }}, - .pos = (yylsp[-4]) + .loc = (yylsp[-4]) }; } #line 3331 "src/parser.c" @@ -3349,7 +3349,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .cond = (yyvsp[-2].exp), .body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)) }}, - .pos = (yylsp[-4]) + .loc = (yylsp[-4]) }; } #line 3356 "src/parser.c" @@ -3363,7 +3363,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .body = cpy_stmt3(mpool(arg), &(yyvsp[-3].stmt)), .is_do = true }}, - .pos = (yylsp[-4]) + .loc = (yylsp[-4]) }; } #line 3370 "src/parser.c" @@ -3377,7 +3377,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .c2 = cpy_stmt3(mpool(arg), &(yyvsp[-2].stmt)), .body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)), }}, - .pos = (yylsp[-5]) + .loc = (yylsp[-5]) }; } #line 3384 "src/parser.c" @@ -3392,7 +3392,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .c3 = (yyvsp[-2].exp), .body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)), }}, - .pos = (yylsp[-6]) + .loc = (yylsp[-6]) }; } #line 3399 "src/parser.c" @@ -3406,7 +3406,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .exp = (yyvsp[-2].exp), .body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)), }}, - .pos = (yylsp[-7]) + .loc = (yylsp[-7]) }; // what to do with opt_var? // list rem? @@ -3422,7 +3422,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .exp = (yyvsp[-2].exp), .body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)), }}, - .pos = (yylsp[-9]) + .loc = (yylsp[-9]) }; (yyval.stmt).d.stmt_each.idx = mp_malloc(mpool(arg), EachIdx); (yyval.stmt).d.stmt_each.idx->var = (Var_Decl){.tag=MK_TAG((yyvsp[-7].sym), (yylsp[-7]))}; @@ -3440,7 +3440,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .cond = (yyvsp[-2].exp), .body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)) }}, - .pos = (yylsp[-4]) + .loc = (yylsp[-4]) }; } #line 3447 "src/parser.c" @@ -3453,7 +3453,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .cond = (yyvsp[-2].exp), .body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)) }}, - .pos = (yylsp[-6]) + .loc = (yylsp[-6]) }; (yyval.stmt).d.stmt_loop.idx = mp_malloc(mpool(arg), EachIdx); (yyval.stmt).d.stmt_loop.idx->var = (Var_Decl){ .tag = MK_TAG((yyvsp[-4].sym), (yylsp[-4])) }; @@ -3472,7 +3472,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] } (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_defer, .d = { .stmt_defer = { .stmt = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)) }}, - .pos = (yylsp[-1]) + .loc = (yylsp[-1]) }; } #line 3479 "src/parser.c" @@ -3485,7 +3485,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .cond = (yyvsp[-2].exp), .if_body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)) }}, - .pos = (yylsp[-4]) + .loc = (yylsp[-4]) }; } #line 3492 "src/parser.c" @@ -3499,7 +3499,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] .if_body = cpy_stmt3(mpool(arg), &(yyvsp[-2].stmt)), .else_body = cpy_stmt3(mpool(arg), &(yyvsp[0].stmt)) }}, - .pos = (yylsp[-6]) + .loc = (yylsp[-6]) }; } #line 3506 "src/parser.c" @@ -3521,7 +3521,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] #line 662 "src/gwion.y" { (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = (yyvsp[-1].exp) }}, - .pos = (yylsp[-2]) + .loc = (yylsp[-2]) }; } #line 3528 "src/parser.c" @@ -3530,7 +3530,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] case 133: /* jump_stmt: "return" ";" */ #line 667 "src/gwion.y" { (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_return, - .pos = (yylsp[-1]) + .loc = (yylsp[-1]) }; } #line 3537 "src/parser.c" @@ -3540,7 +3540,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] #line 671 "src/gwion.y" { (yyval.stmt) = (struct Stmt_) { .stmt_type = (yyvsp[-2].stmt_t), .d = { .stmt_index = { .idx = (yyvsp[-1].gwint).num }}, - .pos = (yylsp[-2]) + .loc = (yylsp[-2]) }; } #line 3547 "src/parser.c" @@ -3550,7 +3550,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] #line 676 "src/gwion.y" { (yyval.stmt) = (struct Stmt_) { .stmt_type = (yyvsp[-1].stmt_t), .d = { .stmt_index = { .idx = -1 }}, - .pos = (yylsp[-1]) }; + .loc = (yylsp[-1]) }; } #line 3556 "src/parser.c" break; @@ -3559,7 +3559,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] #line 682 "src/gwion.y" { (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = (yyvsp[-1].exp) }}, - .pos = (yylsp[-1]) + .loc = (yylsp[-1]) }; } #line 3566 "src/parser.c" @@ -3568,7 +3568,7 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] case 137: /* exp_stmt: ";" */ #line 687 "src/gwion.y" { (yyval.stmt) = (struct Stmt_) { .stmt_type = ae_stmt_exp, - .pos = (yylsp[0]) + .loc = (yylsp[0]) }; } #line 3575 "src/parser.c"