ref: 60170fa8ff5a4d0ffc73cf069eb190ea99386cc0
parent: d128d9dd0113d32df0ede231e1d945684b9fab29
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Apr 3 17:34:44 EDT 2014
Add post increment and pre increment
--- a/cc.h
+++ b/cc.h
@@ -213,7 +213,8 @@
typedef void (*Inst)(Node *);
enum {
- OCAST, OPTR, OADD, OARY, OSIZE, OMUL, OSUB
+ OCAST, OPTR, OADD, OARY, OSIZE, OMUL, OSUB,
+ OINC, ODEC, OPINC, OPDEC
};
extern void
--- a/code.c
+++ b/code.c
@@ -8,6 +8,10 @@
[OADD] = "+",
[OMUL] = "*",
[OARY] = "'",
+ [OINC] = ":+",
+ [ODEC] = ":-",
+ [OPINC] = ";+",
+ [OPDEC] = ";=",
[OSIZE] = "#",
[OPTR] = "@"
};
--- a/expr.c
+++ b/expr.c
@@ -139,6 +139,7 @@
postfix(void)
{
Node *np1, *np2;
+ char op;
np1 = primary();
for (;;) {
@@ -148,6 +149,12 @@
np2 = expr();
np1 = array(np1, np2);
expect(']');
+ break;
+ case DEC: case INC:
+ op = (yytoken == INC) ? OPINC : OPDEC;
+ /* TODO: check that the the base type is a complete type */
+ np1 = unarycode(op, np1->type, np1);
+ next();
break;
default:
return np1;