]> git.sur5r.net Git - cc65/commitdiff
Allow conditional directives within .STRUCT7:UNION and .ENUM
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 17 Nov 2003 18:49:50 +0000 (18:49 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 17 Nov 2003 18:49:50 +0000 (18:49 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@2672 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ca65/condasm.c
src/ca65/condasm.h
src/ca65/enum.c
src/ca65/struct.c

index 88d7716f70bc3ffebec45c5c22fc8416a0c5be37..5b2bf8ef09e42dbd728547977d640aa44e0c5292 100644 (file)
@@ -321,7 +321,7 @@ void DoConditionals (void)
                        SetIfCond (D, 1);
                         SkipUntilSep ();
                     }
-               }
+               }
                IfCond = GetCurrentIfCond ();
                break;
 
@@ -367,7 +367,7 @@ void DoConditionals (void)
 
            case TOK_IFP816:
                D = AllocIf (".IFP816", 1);
-               NextTok ();
+               NextTok ();
                if (IfCond) {
                            SetIfCond (D, GetCPU() == CPU_65816);
                }
@@ -413,6 +413,39 @@ void DoConditionals (void)
 
 
 
+int CheckConditionals (void)
+/* Check if the current token is one that starts a conditional directive, and
+ * call DoConditionals if so. Return true if a conditional directive was found,
+ * return false otherwise.
+ */
+{
+    switch (Tok) {
+        case TOK_ELSE:
+        case TOK_ELSEIF:
+        case TOK_ENDIF:
+        case TOK_IF:
+        case TOK_IFBLANK:
+        case TOK_IFCONST:
+        case TOK_IFDEF:
+        case TOK_IFNBLANK:
+        case TOK_IFNCONST:
+        case TOK_IFNDEF:
+        case TOK_IFNREF:
+        case TOK_IFP02:
+        case TOK_IFP816:
+        case TOK_IFPC02:
+        case TOK_IFPSC02:
+        case TOK_IFREF:
+            DoConditionals ();
+            return 1;
+
+        default:
+            return 0;
+    }
+}
+
+
+
 void CheckOpenIfs (void)
 /* Called from the scanner before closing an input file. Will check for any
  * open .ifs in this file.
index 84a2ac02603ea7c6e0ce5752fd7e1533345952c5..6718c268f8c7d6b1099096f40bd2076d728ddc59 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2000-2003 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       */
 void DoConditionals (void);
 /* Catch all for conditional directives */
 
+int CheckConditionals (void);
+/* Check if the current token is one that starts a conditional directive, and
+ * call DoConditionals if so. Return true if a conditional directive was found,
+ * return false otherwise.
+ */
+
 void CheckOpenIfs (void);
 /* Called from the scanner before closing an input file. Will check for any
  * open .ifs in this file.
index 8d9da86f66d12b5125a61a4368e1023851842146..f226e4433f125652ecaa2b648bd0461a0755bd42 100644 (file)
@@ -37,6 +37,7 @@
 #include "addrsize.h"
 
 /* ca65 */
+#include "condasm.h"
 #include "enum.h"
 #include "error.h"
 #include "expr.h"
@@ -75,11 +76,19 @@ void DoEnum (void)
 
         SymEntry* Sym;
         ExprNode* EnumExpr;
-        
+
+        /* Skip empty lines */
+        if (Tok == TOK_SEP) {
+            NextTok ();
+            continue;
+        }
 
         /* The format is "identifier [ = value ]" */
         if (Tok != TOK_IDENT) {
-            ErrorSkip ("Identifier expected");
+            /* Maybe it's a conditional? */
+            if (!CheckConditionals ()) {
+                ErrorSkip ("Identifier expected");
+            }
             continue;
         }
 
index a737e36147eef87f96e21d13aca38580a3486e97..0ee0752fb5474e0b3aae11850dda4b907cdc6e9f 100644 (file)
@@ -37,6 +37,7 @@
 #include "addrsize.h"
 
 /* ca65 */
+#include "condasm.h"
 #include "error.h"
 #include "expr.h"
 #include "nexttok.h"
@@ -187,8 +188,10 @@ static long DoStructInternal (long Offs, unsigned Type)
                 break;
 
             default:
-                Error ("Invalid storage allocator in struct/union");
-                SkipUntilSep ();
+                if (!CheckConditionals ()) {
+                    /* Not a conditional directive */
+                    ErrorSkip ("Invalid storage allocator in struct/union");
+                }
         }
 
         /* Next member */