Fix typo last entry
[deliverable/binutils-gdb.git] / gas / cond.c
index 034796b2e3d7f4a05250a1ed5010e5d417d93775..b7a4082c52846a17036354081e834b383d593f7b 100644 (file)
@@ -60,15 +60,19 @@ static char *get_mri_string PARAMS ((int, int *));
 
 static struct conditional_frame *current_cframe = NULL;
 
+/* Performs the .ifdef (test_defined == 1) and
+   the .ifndef (test_defined == 0) pseudo op.  */
+
 void
-s_ifdef (arg)
-     int arg;
+s_ifdef (test_defined)
+     int test_defined;
 {
   /* Points to name of symbol.  */
-  register char *name;
+  char *name;
   /* Points to symbol.  */
-  register symbolS *symbolP;
+  symbolS *symbolP;
   struct conditional_frame cframe;
+  char c;
 
   /* Leading whitespace is part of operand.  */
   SKIP_WHITESPACE ();
@@ -79,29 +83,43 @@ s_ifdef (arg)
       as_bad (_("invalid identifier for \".ifdef\""));
       obstack_1grow (&cond_obstack, 0);
       ignore_rest_of_line ();
+      return;
     }
+
+  c = get_symbol_end ();
+  symbolP = symbol_find (name);
+  *input_line_pointer = c;
+
+  initialize_cframe (&cframe);
+  
+  if (cframe.dead_tree)
+    cframe.ignoring = 1;
   else
     {
-      char c;
+      int is_defined;
 
-      c = get_symbol_end ();
-      symbolP = symbol_find (name);
-      *input_line_pointer = c;
+      /* Use the same definition of 'defined' as .equiv so that a symbol
+        which has been referenced but not yet given a value/address is
+        considered to be undefined.  */
+      is_defined =
+       symbolP != NULL
+       && S_IS_DEFINED (symbolP)
+       && S_GET_SEGMENT (symbolP) != reg_section;
 
-      initialize_cframe (&cframe);
-      cframe.ignoring = cframe.dead_tree || !((symbolP != 0) ^ arg);
-      current_cframe = ((struct conditional_frame *)
-                       obstack_copy (&cond_obstack, &cframe,
-                                     sizeof (cframe)));
+      cframe.ignoring = ! (test_defined ^ is_defined);
+    }
 
-      if (LISTING_SKIP_COND ()
-         && cframe.ignoring
-         && (cframe.previous_cframe == NULL
-             || ! cframe.previous_cframe->ignoring))
-       listing_list (2);
+  current_cframe = ((struct conditional_frame *)
+                   obstack_copy (&cond_obstack, &cframe,
+                                 sizeof (cframe)));
+
+  if (LISTING_SKIP_COND ()
+      && cframe.ignoring
+      && (cframe.previous_cframe == NULL
+         || ! cframe.previous_cframe->ignoring))
+    listing_list (2);
 
-      demand_empty_rest_of_line ();
-    }                          /* if a valid identifyer name */
+  demand_empty_rest_of_line ();
 }
 
 void
@@ -255,16 +273,13 @@ void
 s_elseif (arg)
      int arg;
 {
-  expressionS operand;
-  int t;
-
   if (current_cframe == NULL)
     {
-      as_bad (_("\".elseif\" without matching \".if\" - ignored"));
+      as_bad (_("\".elseif\" without matching \".if\""));
     }
   else if (current_cframe->else_seen)
     {
-      as_bad (_("\".elseif\" after \".else\" - ignored"));
+      as_bad (_("\".elseif\" after \".else\""));
       as_bad_where (current_cframe->else_file_line.file,
                    current_cframe->else_file_line.line,
                    _("here is the previous \"else\""));
@@ -277,54 +292,55 @@ s_elseif (arg)
       as_where (&current_cframe->else_file_line.file,
                &current_cframe->else_file_line.line);
 
-      if (!current_cframe->dead_tree)
-       {
-         current_cframe->dead_tree = !current_cframe->ignoring;
-         current_cframe->ignoring = !current_cframe->ignoring;
-         if (LISTING_SKIP_COND ())
-           {
-             if (! current_cframe->ignoring)
-               listing_list (1);
-             else
-               listing_list (2);
-           }
-       }                       /* if not a dead tree */
-    }                          /* if error else do it */
+      current_cframe->dead_tree |= !current_cframe->ignoring;
+      current_cframe->ignoring = current_cframe->dead_tree;
+    }
 
   if (current_cframe == NULL || current_cframe->ignoring)
     {
       while (! is_end_of_line[(unsigned char) *input_line_pointer])
        ++input_line_pointer;
-      return;
+
+      if (current_cframe == NULL)
+       return;
     }
+  else
+    {
+      expressionS operand;
+      int t;
 
-  /* Leading whitespace is part of operand.  */
-  SKIP_WHITESPACE ();
+      /* Leading whitespace is part of operand.  */
+      SKIP_WHITESPACE ();
 
-  expression (&operand);
-  if (operand.X_op != O_constant)
-    as_bad (_("non-constant expression in \".elseif\" statement"));
+      expression (&operand);
+      if (operand.X_op != O_constant)
+       as_bad (_("non-constant expression in \".elseif\" statement"));
 
-  switch ((operatorT) arg)
-    {
-    case O_eq: t = operand.X_add_number == 0; break;
-    case O_ne: t = operand.X_add_number != 0; break;
-    case O_lt: t = operand.X_add_number < 0; break;
-    case O_le: t = operand.X_add_number <= 0; break;
-    case O_ge: t = operand.X_add_number >= 0; break;
-    case O_gt: t = operand.X_add_number > 0; break;
-    default:
-      abort ();
-      return;
-    }
+      switch ((operatorT) arg)
+       {
+       case O_eq: t = operand.X_add_number == 0; break;
+       case O_ne: t = operand.X_add_number != 0; break;
+       case O_lt: t = operand.X_add_number < 0; break;
+       case O_le: t = operand.X_add_number <= 0; break;
+       case O_ge: t = operand.X_add_number >= 0; break;
+       case O_gt: t = operand.X_add_number > 0; break;
+       default:
+         abort ();
+         return;
+       }
 
-  current_cframe->ignoring = current_cframe->dead_tree || ! t;
+      current_cframe->ignoring = current_cframe->dead_tree || ! t;
+    }
 
   if (LISTING_SKIP_COND ()
-      && current_cframe->ignoring
       && (current_cframe->previous_cframe == NULL
          || ! current_cframe->previous_cframe->ignoring))
-    listing_list (2);
+    {
+      if (! current_cframe->ignoring)
+       listing_list (1);
+      else
+       listing_list (2);
+    }
 
   demand_empty_rest_of_line ();
 }
@@ -367,12 +383,11 @@ s_else (arg)
 {
   if (current_cframe == NULL)
     {
-      as_bad (_(".else without matching .if - ignored"));
-
+      as_bad (_("\".else\" without matching \".if\""));
     }
   else if (current_cframe->else_seen)
     {
-      as_bad (_("duplicate \"else\" - ignored"));
+      as_bad (_("duplicate \"else\""));
       as_bad_where (current_cframe->else_file_line.file,
                    current_cframe->else_file_line.line,
                    _("here is the previous \"else\""));
@@ -385,20 +400,21 @@ s_else (arg)
       as_where (&current_cframe->else_file_line.file,
                &current_cframe->else_file_line.line);
 
-      if (!current_cframe->dead_tree)
+      current_cframe->ignoring =
+       current_cframe->dead_tree | !current_cframe->ignoring;
+
+      if (LISTING_SKIP_COND ()
+         && (current_cframe->previous_cframe == NULL
+             || ! current_cframe->previous_cframe->ignoring))
        {
-         current_cframe->ignoring = !current_cframe->ignoring;
-         if (LISTING_SKIP_COND ())
-           {
-             if (! current_cframe->ignoring)
-               listing_list (1);
-             else
-               listing_list (2);
-           }
-       }                       /* if not a dead tree */
+         if (! current_cframe->ignoring)
+           listing_list (1);
+         else
+           listing_list (2);
+       }
 
       current_cframe->else_seen = 1;
-    }                          /* if error else do it */
+    }
 
   if (flag_mri)
     {
This page took 0.031451 seconds and 4 git commands to generate.