diff options
| author | Jack Palevich <jackpal@google.com> | 2009-07-31 15:25:53 -0700 |
|---|---|---|
| committer | Jack Palevich <jackpal@google.com> | 2009-07-31 15:25:53 -0700 |
| commit | 47cbea9c696c8fbeb67c66387b85f59b73d32e6d (patch) | |
| tree | 7432b7d2eb971aedb65dc82c6198bb7dbad876b7 /libacc/acc.cpp | |
| parent | 5b65909f93f7c35fc1e7aaf7dccc2198e30d17d1 (diff) | |
| download | system_core-47cbea9c696c8fbeb67c66387b85f59b73d32e6d.tar.gz system_core-47cbea9c696c8fbeb67c66387b85f59b73d32e6d.tar.bz2 system_core-47cbea9c696c8fbeb67c66387b85f59b73d32e6d.zip | |
Support brackets for accessing array values.
Don't yet support allocating arrays.
Diffstat (limited to 'libacc/acc.cpp')
| -rw-r--r-- | libacc/acc.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp index 436f0812..f70c7a13 100644 --- a/libacc/acc.cpp +++ b/libacc/acc.cpp @@ -3630,7 +3630,7 @@ class Compiler : public ErrorSink { /* check for op=, valid for * / % + - << >> & ^ | */ if (ch == '=' && ((tokl >= 1 && tokl <= 3) - || tokl >=6 && tokl <= 8) ) { + || (tokl >=6 && tokl <= 8)) ) { inp(); tok = TOK_OP_ASSIGNMENT; } @@ -3879,18 +3879,7 @@ class Compiler : public ErrorSink { /* This is a pointer dereference. */ unary(); - pGen->forceR0RVal(); - Type* pR0Type = pGen->getR0Type(); - if (pR0Type->tag != TY_POINTER) { - error("Expected a pointer type."); - } else { - if (pR0Type->pHead->tag == TY_FUNC) { - t = 0; - } - if (t) { - pGen->setR0ExpressionType(ET_LVALUE); - } - } + doPointer(); } else if (t == '&') { VariableInfo* pVI = VI(tok); pGen->leaR0((int) pVI->pAddress, createPtrType(pVI->pType), @@ -3949,6 +3938,15 @@ class Compiler : public ErrorSink { // post inc / post dec doIncDec(tokc == OP_INCREMENT, true); next(); + } else if (accept('[')) { + // Array reference + pGen->forceR0RVal(); + pGen->pushR0(); + commaExpr(); + pGen->forceR0RVal(); + pGen->genOp(OP_PLUS); + doPointer(); + skip(']'); } else if (accept('(')) { /* function call */ Type* pDecl = NULL; @@ -4035,6 +4033,18 @@ class Compiler : public ErrorSink { } } + void doPointer() { + pGen->forceR0RVal(); + Type* pR0Type = pGen->getR0Type(); + if (pR0Type->tag != TY_POINTER) { + error("Expected a pointer type."); + } else { + if (pR0Type->pHead->tag != TY_FUNC) { + pGen->setR0ExpressionType(ET_LVALUE); + } + } + } + /* Recursive descent parser for binary operations. */ void binaryOp(int level) { |
