diff options
author | Jack Palevich <jackpal@google.com> | 2009-07-16 19:05:07 -0700 |
---|---|---|
committer | Jack Palevich <jackpal@google.com> | 2009-07-16 19:05:07 -0700 |
commit | 3377bfd8451b33877318ddfef657e82fe7ed4c9c (patch) | |
tree | 8d11f4b3be6209e1b2d2613422d760c0547a39e1 | |
parent | 8148c5be54f12dcefcb5415adee709f40772589f (diff) | |
download | system_core-3377bfd8451b33877318ddfef657e82fe7ed4c9c.tar.gz system_core-3377bfd8451b33877318ddfef657e82fe7ed4c9c.tar.bz2 system_core-3377bfd8451b33877318ddfef657e82fe7ed4c9c.zip |
Report error (rather than crashing) when a declaration name is missing.
Repo case:
void main()
{
int );
}
-rw-r--r-- | libacc/acc.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp index 3232de6b0..2a7d66ec5 100644 --- a/libacc/acc.cpp +++ b/libacc/acc.cpp @@ -4348,8 +4348,9 @@ class Compiler : public ErrorSink { Type* acceptDeclaration(Type* pType, bool nameAllowed, bool nameRequired, Arena& arena) { tokenid_t declName = 0; + bool reportFailure = false; pType = acceptDecl2(pType, declName, nameAllowed, - nameRequired, arena); + nameRequired, arena, reportFailure); if (declName) { // Clone the parent type so we can set a unique ID pType = createType(pType->tag, pType->pHead, @@ -4359,6 +4360,9 @@ class Compiler : public ErrorSink { } // fprintf(stderr, "Parsed a declaration: "); // printType(pType); + if (reportFailure) { + return NULL; + } return pType; } @@ -4388,12 +4392,14 @@ class Compiler : public ErrorSink { } Type* acceptDecl2(Type* pType, tokenid_t& declName, - bool nameAllowed, bool nameRequired, Arena& arena) { + bool nameAllowed, bool nameRequired, Arena& arena, + bool& reportFailure) { int ptrCounter = 0; while (accept('*')) { ptrCounter++; } - pType = acceptDecl3(pType, declName, nameAllowed, nameRequired, arena); + pType = acceptDecl3(pType, declName, nameAllowed, nameRequired, arena, + reportFailure); while (ptrCounter-- > 0) { pType = createType(TY_POINTER, pType, NULL, arena); } @@ -4401,7 +4407,8 @@ class Compiler : public ErrorSink { } Type* acceptDecl3(Type* pType, tokenid_t& declName, - bool nameAllowed, bool nameRequired, Arena& arena) { + bool nameAllowed, bool nameRequired, Arena& arena, + bool& reportFailure) { // direct-dcl : // name // (dcl) @@ -4410,16 +4417,18 @@ class Compiler : public ErrorSink { Type* pNewHead = NULL; if (accept('(')) { pNewHead = acceptDecl2(pNewHead, declName, nameAllowed, - nameRequired, arena); + nameRequired, arena, reportFailure); skip(')'); } else if ((declName = acceptSymbol()) != 0) { if (nameAllowed == false && declName) { error("Symbol %s not allowed here", nameof(declName)); - } else if (nameRequired && ! declName) { - String temp; - decodeToken(temp, tok, true); - error("Expected symbol. Got %s", temp.getUnwrapped()); + reportFailure = true; } + } else if (nameRequired && ! declName) { + String temp; + decodeToken(temp, tok, true); + error("Expected name. Got %s", temp.getUnwrapped()); + reportFailure = true; } while (accept('(')) { // Function declaration |