mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Improve the assertion check
git-svn-id: svn://svn.cc65.org/cc65/trunk@3472 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
05ab8714d2
commit
3a22d6c1c3
@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2003 Ullrich von Bassewitz */
|
/* (C) 2003-2005, Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@ -34,14 +34,17 @@
|
|||||||
|
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
|
#include "assertdefs.h"
|
||||||
#include "coll.h"
|
#include "coll.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
/* ca65 */
|
/* ca65 */
|
||||||
#include "asserts.h"
|
#include "asserts.h"
|
||||||
|
#include "error.h"
|
||||||
#include "expr.h"
|
#include "expr.h"
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
|
#include "spool.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -98,12 +101,51 @@ void AddAssertion (ExprNode* Expr, unsigned Action, unsigned Msg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void CheckAssertions (void)
|
||||||
|
/* Check all assertions and evaluate the ones we can evaluate here. */
|
||||||
|
{
|
||||||
|
unsigned I;
|
||||||
|
|
||||||
|
/* Get the number of assertions */
|
||||||
|
unsigned Count = CollCount (&Assertions);
|
||||||
|
|
||||||
|
/* Check the assertions */
|
||||||
|
for (I = 0; I < Count; ++I) {
|
||||||
|
|
||||||
|
/* Get the next assertion */
|
||||||
|
Assertion* A = CollAtUnchecked (&Assertions, I);
|
||||||
|
|
||||||
|
/* Can we evaluate the expression? */
|
||||||
|
long Val;
|
||||||
|
if (IsConstExpr (A->Expr, &Val) && Val == 0) {
|
||||||
|
/* Apply the action */
|
||||||
|
const char* Msg = GetString (A->Msg);
|
||||||
|
switch (A->Action) {
|
||||||
|
|
||||||
|
case ASSERT_ACT_WARN:
|
||||||
|
PWarning (&A->Pos, 0, "%s", Msg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ASSERT_ACT_ERROR:
|
||||||
|
PError (&A->Pos, "%s", Msg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Internal ("Illegal assert action specifier");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void WriteAssertions (void)
|
void WriteAssertions (void)
|
||||||
/* Write the assertion table to the object file */
|
/* Write the assertion table to the object file */
|
||||||
{
|
{
|
||||||
unsigned I;
|
unsigned I;
|
||||||
|
|
||||||
/* Get the number of strings in the string pool */
|
/* Get the number of assertions */
|
||||||
unsigned Count = CollCount (&Assertions);
|
unsigned Count = CollCount (&Assertions);
|
||||||
|
|
||||||
/* Tell the object file module that we're about to start the assertions */
|
/* Tell the object file module that we're about to start the assertions */
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2003 Ullrich von Bassewitz */
|
/* (C) 2003-2005, Ullrich von Bassewitz */
|
||||||
/* Römerstrasse 52 */
|
/* Römerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@ -58,6 +58,9 @@ struct ExprNode;
|
|||||||
void AddAssertion (struct ExprNode* Expr, unsigned Action, unsigned Msg);
|
void AddAssertion (struct ExprNode* Expr, unsigned Action, unsigned Msg);
|
||||||
/* Add an assertion to the assertion table */
|
/* Add an assertion to the assertion table */
|
||||||
|
|
||||||
|
void CheckAssertions (void);
|
||||||
|
/* Check all assertions and evaluate the ones we can evaluate here. */
|
||||||
|
|
||||||
void WriteAssertions (void);
|
void WriteAssertions (void);
|
||||||
/* Write the assertion table to the object file */
|
/* Write the assertion table to the object file */
|
||||||
|
|
||||||
|
@ -894,6 +894,11 @@ int main (int argc, char* argv [])
|
|||||||
SegCheck ();
|
SegCheck ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we didn't have any errors, check the assertions */
|
||||||
|
if (ErrorCount == 0) {
|
||||||
|
CheckAssertions ();
|
||||||
|
}
|
||||||
|
|
||||||
/* If we didn't have an errors, index the line infos */
|
/* If we didn't have an errors, index the line infos */
|
||||||
MakeLineInfoIndex ();
|
MakeLineInfoIndex ();
|
||||||
|
|
||||||
|
@ -422,29 +422,8 @@ static void DoAssert (void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we can evaluate the assertion now, there's no need to pass it to the
|
/* Remember the assertion */
|
||||||
* linker.
|
AddAssertion (Expr, Action, GetStringId (SVal));
|
||||||
*/
|
|
||||||
if (IsConstExpr (Expr, &Val)) {
|
|
||||||
/* We can evaluate the expression, so handle it in the assembler */
|
|
||||||
switch (Action) {
|
|
||||||
|
|
||||||
case ASSERT_ACT_WARN:
|
|
||||||
Warning (0, "%s", SVal);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ASSERT_ACT_ERROR:
|
|
||||||
Error ("%s", SVal);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Internal ("Illegal assert action specifier");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Cannot evaluate, add it to the object file */
|
|
||||||
AddAssertion (Expr, Action, GetStringId (SVal));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Skip the message */
|
/* Skip the message */
|
||||||
NextTok ();
|
NextTok ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user