]> git.sur5r.net Git - cc65/blobdiff - src/cc65/compile.c
Fixed a bug
[cc65] / src / cc65 / compile.c
index 77abffb4344d0252d95e4d03ae0b30e346ab1169..7edd3ae1786df2d5ca7212a4329af3af498adfab 100644 (file)
@@ -6,9 +6,9 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
+/* (C) 2000-2004 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
@@ -51,7 +51,6 @@
 #include "expr.h"
 #include "function.h"
 #include "global.h"
-#include "incpath.h"
 #include "input.h"
 #include "litpool.h"
 #include "macrotab.h"
@@ -80,9 +79,9 @@ static void Parse (void)
     /* Parse until end of input */
     while (CurTok.Tok != TOK_CEOF) {
 
-       DeclSpec        Spec;
+       DeclSpec        Spec;
        Declaration     Decl;
-       int             NeedStorage;
+       int             NeedStorage;
 
        /* Check for empty statements */
        if (CurTok.Tok == TOK_SEMI) {
@@ -107,11 +106,13 @@ static void Parse (void)
        ParseDeclSpec (&Spec, SC_EXTERN | SC_STATIC, T_INT);
 
        /* Don't accept illegal storage classes */
-               if ((Spec.StorageClass & SC_AUTO) != 0 || 
-            (Spec.StorageClass & SC_REGISTER) != 0) {
-           Error ("Illegal storage class");
-           Spec.StorageClass = SC_EXTERN | SC_STATIC;
-       }
+        if ((Spec.StorageClass & SC_TYPE) == 0) {
+            if ((Spec.StorageClass & SC_AUTO) != 0 ||
+                (Spec.StorageClass & SC_REGISTER) != 0) {
+                Error ("Illegal storage class");
+                Spec.StorageClass = SC_EXTERN | SC_STATIC;
+            }
+        }
 
        /* Check if this is only a type declaration */
        if (CurTok.Tok == TOK_SEMI) {
@@ -173,7 +174,7 @@ static void Parse (void)
                            if (Size == 0) {
                        if (!IsTypeVoid (Decl.Type)) {
                            if (!IsTypeArray (Decl.Type)) {
-                               /* Size is unknown and not an array */
+                               /* Size is unknown and not an array */
                                Error ("Variable `%s' has unknown size", Decl.Ident);
                            }
                        } else if (ANSI) {
@@ -202,19 +203,27 @@ static void Parse (void)
                    if (IsTypeVoid (Decl.Type)) {
                        /* We cannot declare variables of type void */
                        Error ("Illegal type for variable `%s'", Decl.Ident);
-                   } else if (Size == 0) {
-                       /* Size is unknown */
-                       Error ("Variable `%s' has unknown size", Decl.Ident);
+                        Entry->Flags &= ~(SC_STORAGE | SC_DEF);
+                    } else if (Size == 0) {
+                       /* Size is unknown. Is it an array? */
+                        if (!IsTypeArray (Decl.Type)) {
+                            Error ("Variable `%s' has unknown size", Decl.Ident);
+                        }
+                        Entry->Flags &= ~(SC_STORAGE | SC_DEF);
                    }
 
-                   /* Switch to the BSS segment */
-                   g_usebss ();
+                    /* Allocate storage if it is still needed */
+                    if (Entry->Flags & SC_STORAGE) {
 
-                   /* Define a label */
-                   g_defgloblabel (Entry->Name);
+                        /* Switch to the BSS segment */
+                        g_usebss ();
 
-                   /* Allocate space for uninitialized variable */
-                   g_res (SizeOf (Entry->Type));
+                        /* Define a label */
+                        g_defgloblabel (Entry->Name);
+
+                        /* Allocate space for uninitialized variable */
+                        g_res (Size);
+                    }
                }
 
            }
@@ -260,7 +269,6 @@ static void Parse (void)
 void Compile (const char* FileName)
 /* Top level compile routine. Will setup things and call the parser. */
 {
-    char*       Path;
     char        Buf[20];
     char        DateStr[20];
     char        TimeStr[20];
@@ -275,37 +283,27 @@ void Compile (const char* FileName)
         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
     };
 
-    /* Add some standard paths to the include search path */
-    AddIncludePath ("", INC_USER);             /* Current directory */
-    AddIncludePath ("include", INC_SYS);
-#ifdef CC65_INC
-    AddIncludePath (CC65_INC, INC_SYS);
-#else
-    AddIncludePath ("/usr/lib/cc65/include", INC_SYS);
-#endif
-    Path = getenv ("CC65_INC");
-    if (Path) {
-       AddIncludePath (Path, INC_SYS | INC_USER);
-    }
-
     /* Add macros that are always defined */
-    DefineNumericMacro ("__CC65__", (VER_MAJOR * 0x100) + (VER_MINOR * 0x10) + VER_PATCH);
+    DefineNumericMacro ("__CC65__", VERSION);
 
     /* Strict ANSI macro */
     if (ANSI) {
        DefineNumericMacro ("__STRICT_ANSI__", 1);
     }
 
-    /* Optimization macros */
+    /* Optimization macros. Since no source code has been parsed for now, the
+     * IS_Get functions access the values in effect now, regardless of any
+     * changes using #pragma later.
+     */
     if (Optimize) {
        DefineNumericMacro ("__OPT__", 1);
        if (FavourSize == 0) {
            DefineNumericMacro ("__OPT_i__", 1);
        }
-       if (EnableRegVars) {
+       if (IS_Get (&EnableRegVars)) {
            DefineNumericMacro ("__OPT_r__", 1);
        }
-       if (InlineStdFuncs) {
+               if (IS_Get (&InlineStdFuncs)) {
            DefineNumericMacro ("__OPT_s__", 1);
        }
     }
@@ -354,3 +352,4 @@ void Compile (const char* FileName)
 
 
 
+