]> git.sur5r.net Git - cc65/blobdiff - src/ca65/asserts.c
Finished implemenation of commands to delete macros. Added the new commands to
[cc65] / src / ca65 / asserts.c
index 24810e2c8a7cea30f72fd758256fc1aab1993ff5..d70f8f6023e230ff3dc33aa2270479ddd0ce1589 100644 (file)
@@ -6,8 +6,8 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003-2005, Ullrich von Bassewitz                                      */
-/*                Römerstraße 52                                             */
+/* (C) 2003-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
 /*                                                                           */
@@ -34,7 +34,6 @@
 
 
 /* common */
-#include "assertdefs.h"
 #include "coll.h"
 #include "xmalloc.h"
 
@@ -42,8 +41,8 @@
 #include "asserts.h"
 #include "error.h"
 #include "expr.h"
+#include "lineinfo.h"
 #include "objfile.h"
-#include "scanner.h"
 #include "spool.h"
 
 
 /* An assertion entry */
 typedef struct Assertion Assertion;
 struct Assertion {
-    ExprNode*   Expr;           /* Expression to evaluate */
-    unsigned    Action;         /* Action to take */
-    unsigned    Msg;            /* Message to print (if any) */
-    FilePos     Pos;            /* File position of assertion */
+    ExprNode*       Expr;       /* Expression to evaluate */
+    AssertAction    Action;     /* Action to take */
+    unsigned        Msg;        /* Message to print (if any) */
+    Collection      LI;         /* Line infos for the assertion */
 };
 
 /* Collection with all assertions for a module */
@@ -74,7 +73,7 @@ static Collection Assertions = STATIC_COLLECTION_INITIALIZER;
 
 
 
-static Assertion* NewAssertion (ExprNode* Expr, unsigned Action, unsigned Msg)
+static Assertion* NewAssertion (ExprNode* Expr, AssertAction Action, unsigned Msg)
 /* Create a new Assertion struct and return it */
 {
     /* Allocate memory */
@@ -84,7 +83,8 @@ static Assertion* NewAssertion (ExprNode* Expr, unsigned Action, unsigned Msg)
     A->Expr     = Expr;
     A->Action   = Action;
     A->Msg      = Msg;
-    A->Pos      = CurPos;
+    A->LI       = EmptyCollection;
+    GetFullLineInfo (&A->LI, 1);
 
     /* Return the new struct */
     return A;
@@ -92,7 +92,7 @@ static Assertion* NewAssertion (ExprNode* Expr, unsigned Action, unsigned Msg)
 
 
 
-void AddAssertion (ExprNode* Expr, unsigned Action, unsigned Msg)
+void AddAssertion (ExprNode* Expr, AssertAction Action, unsigned Msg)
 /* Add an assertion to the assertion table */
 {
     /* Add an assertion object to the table */
@@ -112,22 +112,28 @@ void CheckAssertions (void)
     /* Check the assertions */
     for (I = 0; I < Count; ++I) {
 
+        long Val;
+
         /* Get the next assertion */
         Assertion* A = CollAtUnchecked (&Assertions, I);
 
+        /* Ignore it, if it should only be evaluated by the linker */
+        if (!AssertAtAsmTime (A->Action)) {
+            continue;
+        }
+
         /* 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);
+                    LIWarning (&A->LI, 0, "%s", Msg);
                     break;
 
                 case ASSERT_ACT_ERROR:
-                    PError (&A->Pos, "%s", Msg);
+                    LIError (&A->LI, "%s", Msg);
                     break;
 
                 default:
@@ -162,9 +168,9 @@ void WriteAssertions (void)
 
         /* Write it to the file */
         WriteExpr (A->Expr);
-        ObjWriteVar (A->Action);
+        ObjWriteVar ((unsigned) A->Action);
         ObjWriteVar (A->Msg);
-        ObjWritePos (&A->Pos);
+        WriteLineInfo (&A->LI);
     }
 
     /* Done writing the assertions */
@@ -174,3 +180,4 @@ void WriteAssertions (void)
 
 
 
+