diff options
| author | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-31 12:05:22 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-31 12:05:22 -0700 |
| commit | 460675eb9174a75d3325fbf57b289e4059a1b379 (patch) | |
| tree | a6416511b8d4d482598af5804fc795cebbdeb3ef | |
| parent | bb75dcc1e6151e53d0edc48a70a558ba081ccadb (diff) | |
| parent | 29daf577a110ab19ad333993f178483e747278f1 (diff) | |
| download | system_core-460675eb9174a75d3325fbf57b289e4059a1b379.tar.gz system_core-460675eb9174a75d3325fbf57b289e4059a1b379.tar.bz2 system_core-460675eb9174a75d3325fbf57b289e4059a1b379.zip | |
Merge change 9364
* changes:
Assignment in ordinary expressions is now handled using lvals and rvals.
| -rw-r--r-- | libacc/acc.cpp | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp index f5b59230..a74f51de 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; |
