commit 258c09122a8b198a6f881306f03680c3612ede87
parent 4b90764e547ea0bb9fdb8d93d9492db3668a033f
Author: m21c <ho*******@gmail.com>
Date: Wed, 6 Oct 2021 00:11:15 +0200
removed redundant ast-kinds
Diffstat:
| M | compiler.c | | | 48 | ++++++++++++++++++++---------------------------- |
1 file changed, 20 insertions(+), 28 deletions(-)
diff --git a/compiler.c b/compiler.c
@@ -90,8 +90,8 @@ enum Kind {
OADDA, OSUBA, OORA, OXORA,
/* Ast */
- ACOMMA, ASTMT, ADO, ADECL, ADECLREF, ALOOP, ALOOPUNTIL, AWHILE, AFOR,
- ACONTINUE, ABREAK, ASCOPE, ARETURN, AGOTO, ALABEL, AIF, ASWITCH, ACASE,
+ ACOMMA, ASTMT, ADECL, ADECLREF, ALOOPUNTIL,
+ ASCOPE, ALABEL, ASWITCH, ACASE,
ACONV,
ADEREF, AADDR,
@@ -479,17 +479,15 @@ const char *const nodestrings[] = {
[OADDA] = "+=", [OSUBA] = "-=",
[OORA] = "|=", [OXORA] = "^=",
/* Ast Nodes */
- [ACOMMA] = ",",
- [ASTMT] = "statement", [ADO] = "do-clause",
- [ADECL] = "declaration", [ADECLREF] = "symbol-reference",
- [ALOOP] = "loop-clause", [ALOOPUNTIL] = "loop-until-clause",
- [AWHILE] = "while-clause", [AFOR] = "for-clause",
- [ACONTINUE] = "continue-statement", [ABREAK] = "break-statement",
- [ASCOPE] = "scope", [ARETURN] = "return-statement",
- [AGOTO] = "goto-statement", [ALABEL] = "label",
- [AIF] = "if-clause", [ASWITCH] = "case-clause",
- [ACASE] = "of-clause",
- [ACONV] = "conversion",
+ [ACOMMA] = ",",
+ [ASTMT] = "statement",
+ [ALOOPUNTIL] = "loop-until-clause",
+ [ADECL] = "declaration", [ADECLREF] = "symbol-reference",
+ [ASCOPE] = "scope",
+ [ALABEL] = "label",
+ [ASWITCH] = "case-clause",
+ [ACASE] = "of-clause",
+ [ACONV] = "conversion",
[MAXKINDS] = NULL
};
@@ -2531,7 +2529,6 @@ readatom(Source *source, int flags)
case KRETURN:
lhs = tokennode(source, NULL);
gettok(source);
- lhs->kind = ARETURN;
if (getkind(source) == ':') {
gettok(source);
@@ -2553,16 +2550,13 @@ readatom(Source *source, int flags)
indent = source->lastindent;
lhs = tokennode(source, NULL);
gettok(source);
- lhs->kind = ADO;
lhs->lhs = stmtlist(source, indent, SDO, NULL, false);
-
break;
case KLOOP:
indent = source->lastindent;
lhs = tokennode(source, NULL);
gettok(source);
- lhs->kind = ALOOP;
lhs->lhs = stmtlist(source, indent, SLOOP, NULL, false);
if (getkind(source) == KUNTIL && source->lastindent >= indent) {
@@ -2571,7 +2565,7 @@ readatom(Source *source, int flags)
lhs->u.payload = readexpr(source, POR);
}
- if (lhs->kind != ALOOP)
+ if (lhs->kind != KLOOP)
goto joinelse;
else
break;
@@ -2580,7 +2574,6 @@ readatom(Source *source, int flags)
indent = source->lastindent;
lhs = tokennode(source, NULL);
gettok(source);
- lhs->kind = AWHILE;
lhs->u.payload = readexpr(source, POR);
lhs->lhs = stmtlist(source, indent, SWHILE, NULL, false);
@@ -2590,7 +2583,6 @@ readatom(Source *source, int flags)
indent = source->lastindent;
lhs = tokennode(source, NULL);
gettok(source);
- lhs->kind = AIF;
lhs->u.payload = readexpr(source, POR);
/* skipnewline(source); */
@@ -3349,7 +3341,7 @@ typecheck(Env *env, Node *expr)
expr->rhs = wrap(expr->type, rhs);
return expr;
- case AIF:
+ case KIF:
lhs = expr->lhs;
rhs = expr->rhs;
@@ -3954,8 +3946,8 @@ isclauseorempty(Node *expr)
return true;
kind = expr->kind;
- return kind == ADO || kind == AIF || kind == AFOR || kind == AGOTO ||
- kind == ARETURN || kind == ABREAK || kind == ACONTINUE;
+ return kind == KDO || kind == KIF || kind == KFOR || kind == KGOTO ||
+ kind == KRETURN || kind == KBREAK || kind == KCONTINUE;
}
static int
@@ -4269,23 +4261,23 @@ printexpr(FILE *out, Node *expr, int indent)
n += printsubexpr(out, expr->rhs, false, indent);
break;
- case ARETURN:
+ case KRETURN:
n += highlight(out, HLKEYWORD);
n += fprintf(out, "return ");
n += printexpr(out, expr->rhs, indent);
break;
- case ABREAK:
+ case KBREAK:
n += highlight(out, HLKEYWORD);
n += fprintf(out, "break");
break;
- case ACONTINUE:
+ case KCONTINUE:
n += highlight(out, HLKEYWORD);
n += fprintf(out, "continue");
break;
- case AIF:
+ case KIF:
n += highlight(out, HLKEYWORD);
n += fprintf(out, "if ");
n += printexpr(out, expr->u.payload, indent);
@@ -4303,7 +4295,7 @@ printexpr(FILE *out, Node *expr, int indent)
break;
- case ADO:
+ case KDO:
n += highlight(out, HLKEYWORD);
n += fprintf(out, "do");
n += printclause(out, expr->lhs, indent);