]> git.sur5r.net Git - cc65/commitdiff
Improve the assertion check
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 20 Apr 2005 09:17:04 +0000 (09:17 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 20 Apr 2005 09:17:04 +0000 (09:17 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3472 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ca65/asserts.c
src/ca65/asserts.h
src/ca65/main.c
src/ca65/pseudo.c

index a5f8af5936ddff6a15719a771cca66beb64bd00c..24810e2c8a7cea30f72fd758256fc1aab1993ff5 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2003-2005, Ullrich von Bassewitz                                      */
+/*                Römerstraße 52                                             */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 /* common */
+#include "assertdefs.h"
 #include "coll.h"
 #include "xmalloc.h"
 
 /* ca65 */
 #include "asserts.h"
+#include "error.h"
 #include "expr.h"
 #include "objfile.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)
 /* Write the assertion table to the object file */
 {
     unsigned I;
 
-    /* Get the number of strings in the string pool */
+    /* Get the number of assertions */
     unsigned Count = CollCount (&Assertions);
 
     /* Tell the object file module that we're about to start the assertions */
index 0aef773a83a073cd84a6253954a531a67b08936d..09824e9afaa4581f2b60ae0e26408741e60919af 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2003-2005, Ullrich von Bassewitz                                      */
+/*                Römerstrasse 52                                            */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* 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);
 /* Add an assertion to the assertion table */
 
+void CheckAssertions (void);
+/* Check all assertions and evaluate the ones we can evaluate here. */
+
 void WriteAssertions (void);
 /* Write the assertion table to the object file */
 
index 26fec98f658a18f7d3fb128d589ab397b88a5e89..157470314b2799fd6cd7eb19894761cf59b03f71 100644 (file)
@@ -894,6 +894,11 @@ int main (int argc, char* argv [])
         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 */
     MakeLineInfoIndex ();
 
index 2522e54c8f945a46f2ebb2f14c9b5012f625e51a..3a9caac6d83b14cccdb40abe46e668f91fe56eae 100644 (file)
@@ -422,29 +422,8 @@ static void DoAssert (void)
         return;
     }
 
-    /* If we can evaluate the assertion now, there's no need to pass it to the
-     * linker.
-     */
-    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));
-    }
+    /* Remember the assertion */
+    AddAssertion (Expr, Action, GetStringId (SVal));
 
     /* Skip the message */
     NextTok ();