aboutsummaryrefslogtreecommitdiffstats
path: root/libacc
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-07-31 15:58:19 -0700
committerJack Palevich <jackpal@google.com>2009-07-31 15:58:19 -0700
commit96138992ac98f8962dc2345d9ba3e99006af80b2 (patch)
treead971dbd93aaef59e3fafa48fa447bb81612a1a9 /libacc
parent47cbea9c696c8fbeb67c66387b85f59b73d32e6d (diff)
downloadsystem_core-96138992ac98f8962dc2345d9ba3e99006af80b2.tar.gz
system_core-96138992ac98f8962dc2345d9ba3e99006af80b2.tar.bz2
system_core-96138992ac98f8962dc2345d9ba3e99006af80b2.zip
Fix parsing of function declarations that return pointers.
Check that <op>= only evaluates the left-hand-side once.
Diffstat (limited to 'libacc')
-rw-r--r--libacc/acc.cpp6
-rw-r--r--libacc/tests/data/assignmentop.c8
-rw-r--r--libacc/tests/test.py7
3 files changed, 10 insertions, 11 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index f70c7a13..676947e2 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -4409,15 +4409,11 @@ class Compiler : public ErrorSink {
Type* acceptDecl2(Type* pType, tokenid_t& declName,
bool nameAllowed, bool nameRequired,
bool& reportFailure) {
- int ptrCounter = 0;
while (accept('*')) {
- ptrCounter++;
+ pType = createType(TY_POINTER, pType, NULL);
}
pType = acceptDecl3(pType, declName, nameAllowed, nameRequired,
reportFailure);
- while (ptrCounter-- > 0) {
- pType = createType(TY_POINTER, pType, NULL);
- }
return pType;
}
diff --git a/libacc/tests/data/assignmentop.c b/libacc/tests/data/assignmentop.c
index 10b46376..649edf9b 100644
--- a/libacc/tests/data/assignmentop.c
+++ b/libacc/tests/data/assignmentop.c
@@ -33,7 +33,6 @@ void testAssignment() {
printf("16|= 1 %d\n", a);
}
-/* Can't use because int* f() is not parsed as a function decl.
int a;
int* f() {
@@ -43,24 +42,21 @@ int* f() {
void testEval() {
a = 0;
- printf("*f() = *f() + 10;");
+ printf("*f() = *f() + 10;\n");
*f() = *f() + 10;
printf("a = %d\n", a);
}
void testOpEval() {
a = 0;
- printf("*f() += 10;");
+ printf("*f() += 10;\n");
*f() += 10;
printf("a = %d\n", a);
}
-*/
int main() {
testAssignment();
- /*
testEval();
testOpEval();
- */
return 0;
}
diff --git a/libacc/tests/test.py b/libacc/tests/test.py
index 4be1f4b7..7bcbdd4d 100644
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -356,6 +356,13 @@ result: 0""", """2 *= 5 10
17&= 1 1
17^= 1 16
16|= 1 17
+*f() = *f() + 10;
+f()
+f()
+a = 10
+*f() += 10;
+f()
+a = 10
""")
def testcomma(self):