commit e888ffdaf5a6a7aee73253cc982847e72be0bd94
parent a100cd930fb84e4e0e1d3dc3c24d3bddd28eb4f0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 11 Aug 2014 23:33:45 +0200
Add unary operators '-' and '~'
Diffstat:
3 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/cc2/cc2.h b/cc2/cc2.h
@@ -86,6 +86,8 @@ enum nerrors {
#define ONE '!'
#define OOR 'o'
#define OAND 'y'
+#define ONEG '_'
+#define OCPL '~'
extern void error(unsigned nerror, ...);
extern void genaddable(Node *list[]);
diff --git a/cc2/cgen.c b/cc2/cgen.c
@@ -124,6 +124,7 @@ xcgen(Node *np)
}
switch (np->op) {
+ case ONEG: case OCPL:
case OOR: case OAND:
case OPTR: case OADDR:
case OINC:
@@ -195,6 +196,7 @@ xaddable(Node *np)
case CONST:
np->addable = 20;
break;
+ case ONEG: case OCPL:
case OPTR: case OADDR:
xaddable(lp);
break;
diff --git a/cc2/parser.c b/cc2/parser.c
@@ -302,6 +302,8 @@ static void (*optbl[])(char *) = {
['!'] = operator,
['y'] = operator,
['o'] = operator,
+ ['_'] = unary,
+ ['~'] = unary,
['\177'] = NULL
};