summaryrefslogtreecommitdiffstats
path: root/libacc
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-07-30 19:38:55 -0700
committerJack Palevich <jackpal@google.com>2009-07-30 19:38:55 -0700
commit29daf577a110ab19ad333993f178483e747278f1 (patch)
tree4d664acf8f8f3f9e3743ed0e45e0dc8f61d1e1bd /libacc
parentb5e33311593e8b6d52ccb1eb5d5453a6cdd2d9e0 (diff)
downloadsystem_core-29daf577a110ab19ad333993f178483e747278f1.zip
system_core-29daf577a110ab19ad333993f178483e747278f1.tar.gz
system_core-29daf577a110ab19ad333993f178483e747278f1.tar.bz2
Assignment in ordinary expressions is now handled using lvals and rvals.
Diffstat (limited to 'libacc')
-rw-r--r--libacc/acc.cpp42
1 files changed, 19 insertions, 23 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index f5b5923..a74f51d 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -3789,10 +3789,20 @@ class Compiler : public ErrorSink {
pVI->pAddress = n;
}
+ void unaryOrAssignment() {
+ unary();
+ if (accept('=')) {
+ checkLVal();
+ pGen->pushR0();
+ expr();
+ pGen->forceR0RVal();
+ pGen->storeR0ToTOS();
+ }
+ }
+
/* Parse and evaluate a unary expression.
- * allowAssignment is true if '=' parsing wanted (quick hack)
*/
- void unary(bool allowAssignment) {
+ void unary() {
tokenid_t t;
intptr_t n, a;
t = 0;
@@ -3821,7 +3831,7 @@ class Compiler : public ErrorSink {
glo += 8;
} else if (c == 2) {
/* -, +, !, ~ */
- unary(false);
+ unary();
pGen->forceR0RVal();
if (t == '!')
pGen->gUnaryCmp(a);
@@ -3835,7 +3845,7 @@ class Compiler : public ErrorSink {
Type* pCast = acceptCastTypeDeclaration();
if (pCast) {
skip(')');
- unary(false);
+ unary();
pGen->forceR0RVal();
pGen->convertR0(pCast);
} else {
@@ -3845,7 +3855,7 @@ class Compiler : public ErrorSink {
} else if (t == '*') {
/* This is a pointer dereference.
*/
- unary(false);
+ unary();
pGen->forceR0RVal();
Type* pR0Type = pGen->getR0Type();
if (pR0Type->tag != TY_POINTER) {
@@ -3854,13 +3864,8 @@ class Compiler : public ErrorSink {
if (pR0Type->pHead->tag == TY_FUNC) {
t = 0;
}
- if (accept('=')) {
- pGen->pushR0();
- expr();
- pGen->forceR0RVal();
- pGen->storeR0ToTOS();
- } else if (t) {
- pGen->loadR0FromR0();
+ if (t) {
+ pGen->setR0ExpressionType(ET_LVALUE);
}
}
// Else we fall through to the function call below, with
@@ -3892,16 +3897,7 @@ class Compiler : public ErrorSink {
error("Undeclared variable %s\n", nameof(t));
}
}
- if ((tok == '=') & allowAssignment) {
- /* assignment */
- next();
- pGen->leaR0(n, createPtrType(pVI->pType), ET_LVALUE);
- checkLVal();
- pGen->pushR0();
- expr();
- pGen->forceR0RVal();
- pGen->storeR0ToTOS();
- } else if (tok != '(') {
+ if (tok != '(') {
/* variable */
if (!n) {
linkGlobal(t, false);
@@ -4020,7 +4016,7 @@ class Compiler : public ErrorSink {
intptr_t t, a;
t = 0;
if (level-- == 1)
- unary(true);
+ unaryOrAssignment();
else {
binaryOp(level);
a = 0;