Add AssertPos() macro that provides rough source location in error

It can sometimes be useful to know the general place we were in the program
when an assertion hit; when the position is available / applicable, this
macro is now used.

Issue #268.
This commit is contained in:
Matt Pharr
2012-05-25 10:59:45 -07:00
parent d943455e10
commit 64807dfb3b
7 changed files with 380 additions and 353 deletions

View File

@@ -231,7 +231,7 @@ Declarator::InitFromDeclSpecs(DeclSpecs *ds) {
InitFromType(baseType, ds);
if (type == NULL) {
Assert(m->errorCount > 0);
AssertPos(pos, m->errorCount > 0);
return;
}
@@ -319,8 +319,8 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
if (kind == DK_BASE) {
// All of the type qualifiers should be in the DeclSpecs for the
// base declarator
Assert(typeQualifiers == 0);
Assert(child == NULL);
AssertPos(pos, typeQualifiers == 0);
AssertPos(pos, child == NULL);
type = baseType;
}
else if (kind == DK_POINTER) {
@@ -398,7 +398,7 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
Declaration *d = functionParams[i];
if (d == NULL) {
Assert(m->errorCount > 0);
AssertPos(pos, m->errorCount > 0);
continue;
}
if (d->declarators.size() == 0) {
@@ -408,10 +408,10 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
d->declarators[0]->InitFromDeclSpecs(d->declSpecs);
}
Assert(d->declarators.size() == 1);
AssertPos(pos, d->declarators.size() == 1);
Declarator *decl = d->declarators[0];
if (decl == NULL || decl->type == NULL) {
Assert(m->errorCount > 0);
AssertPos(pos, m->errorCount > 0);
continue;
}
@@ -446,7 +446,7 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
// significant problem.)
const Type *targetType = at->GetElementType();
if (targetType == NULL) {
Assert(m->errorCount > 0);
AssertPos(pos, m->errorCount > 0);
return;
}
@@ -525,7 +525,7 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
}
if (child == NULL) {
Assert(m->errorCount > 0);
AssertPos(pos, m->errorCount > 0);
return;
}