]> git.sur5r.net Git - cc65/blobdiff - src/cc65/locals.c
In a function call for all parameters not covered by a prototype, convert
[cc65] / src / cc65 / locals.c
index 00d15d1bcefeb4d6d6c0c3d1b87783903332c36a..80f27cd71f29ad47a54a578078fd42b470adb9b5 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2003 Ullrich von Bassewitz                                       */
+/* (C) 2000-2004 Ullrich von Bassewitz                                       */
 /*               Römerstrasse 52                                             */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -46,7 +46,9 @@
 #include "expr.h"
 #include "function.h"
 #include "global.h"
+#include "loadexpr.h"
 #include "locals.h"
+#include "stackptr.h"
 #include "symtab.h"
 #include "typeconv.h"
 
@@ -78,7 +80,7 @@ static unsigned ParseRegisterDecl (Declaration* Decl, unsigned* SC, int Reg)
     /* Check for an optional initialization */
     if (CurTok.Tok == TOK_ASSIGN) {
 
-        ExprDesc lval;
+        ExprDesc Expr;
 
         /* Skip the '=' */
         NextToken ();
@@ -111,13 +113,13 @@ static unsigned ParseRegisterDecl (Declaration* Decl, unsigned* SC, int Reg)
         } else {
 
             /* Parse the expression */
-            int k = hie1 (InitExprDesc (&lval));
+            hie1 (&Expr);
 
             /* Convert it to the target type */
-            k = TypeConversion (&lval, k, Decl->Type);
+            TypeConversion (&Expr, Decl->Type);
 
             /* Load the value into the primary */
-            exprhs (CF_NONE, k, &lval);
+            LoadExpr (CF_NONE, &Expr);
 
             /* Store the value into the variable */
             g_putstatic (CF_REGVAR | TypeOf (Decl->Type), Reg, 0);
@@ -156,12 +158,12 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
     unsigned Size = SizeOf (Decl->Type);
 
     /* Check if this is a variable on the stack or in static memory */
-    if (StaticLocals == 0) {
+    if (IS_Get (&StaticLocals) == 0) {
 
         /* Check for an optional initialization */
         if (CurTok.Tok == TOK_ASSIGN) {
 
-            ExprDesc lval;
+            ExprDesc Expr;
 
             /* Skip the '=' */
             NextToken ();
@@ -200,8 +202,6 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
 
             } else {
 
-                int k;
-
                 /* Allocate previously reserved local space */
                 F_AllocLocalSpace (CurrentFunc);
 
@@ -209,23 +209,23 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
                 Flags = (Size == SIZEOF_CHAR)? CF_FORCECHAR : CF_NONE;
 
                 /* Parse the expression */
-                k = hie1 (InitExprDesc (&lval));
+                hie1 (&Expr);
 
                 /* Convert it to the target type */
-                k = TypeConversion (&lval, k, Decl->Type);
+                TypeConversion (&Expr, Decl->Type);
 
                 /* If the value is not const, load it into the primary.
                  * Otherwise pass the information to the code generator.
                  */
-                if (k != 0 || lval.Flags != E_MCONST) {
-                    exprhs (CF_NONE, k, &lval);
-                    k = 0;
-                } else {
+                if (ED_IsConstAbsInt (&Expr)) {
                     Flags |= CF_CONST;
+                } else {
+                    LoadExpr (CF_NONE, &Expr);
+                    ED_MakeRVal (&Expr);
                 }
 
                 /* Push the value */
-                g_push (Flags | TypeOf (Decl->Type), lval.ConstVal);
+                g_push (Flags | TypeOf (Decl->Type), Expr.IVal);
 
             }
 
@@ -233,7 +233,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
             *SC |= SC_REF;
 
             /* Variable is located at the current SP */
-            SymData = oursp;
+            SymData = StackPtr;
 
         } else {
             /* Non-initialized local variable. Just keep track of
@@ -260,7 +260,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
         /* Allow assignments */
         if (CurTok.Tok == TOK_ASSIGN) {
 
-            ExprDesc lval;
+            ExprDesc Expr;
 
             /* Skip the '=' */
             NextToken ();
@@ -285,13 +285,13 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
             } else {
 
                 /* Parse the expression */
-                int k = hie1 (InitExprDesc (&lval));
+                hie1 (&Expr);
 
                 /* Convert it to the target type */
-                k = TypeConversion (&lval, k, Decl->Type);
+                TypeConversion (&Expr, Decl->Type);
 
                 /* Load the value into the primary */
-                exprhs (CF_NONE, k, &lval);
+                LoadExpr (CF_NONE, &Expr);
 
                 /* Store the value into the variable */
                 g_putstatic (TypeOf (Decl->Type), SymData, 0);
@@ -449,7 +449,7 @@ void DeclareLocals (void)
 /* Declare local variables and types. */
 {
     /* Remember the current stack pointer */
-    int InitialStack = oursp;
+    int InitialStack = StackPtr;
 
     /* Loop until we don't find any more variables */
     while (1) {
@@ -503,7 +503,7 @@ void DeclareLocals (void)
     /* In case we've allocated local variables in this block, emit a call to
      * the stack checking routine if stack checks are enabled.
      */
-    if (CheckStack && InitialStack != oursp) {
+    if (IS_Get (&CheckStack) && InitialStack != StackPtr) {
                g_cstackcheck ();
     }
 }