* doc/gdb.texinfo (appendix "Installing GDB"): changes in configure.
[deliverable/binutils-gdb.git] / gdb / expprint.c
index b7adc2980d9193a4c1b8468e7e6550050e80b81f..e96dc7fe94f755cac7823a6f5adccfdc3b5363d5 100644 (file)
@@ -1,28 +1,29 @@
 /* Print in infix form a struct expression.
-   Copyright (C) 1986 Free Software Foundation, Inc.
+   Copyright (C) 1986, 1989 Free Software Foundation, Inc.
 
-GDB is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY.  No author or distributor accepts responsibility to anyone
-for the consequences of using it or for whether it serves any
-particular purpose or works at all, unless he says so in writing.
-Refer to the GDB General Public License for full details.
+This file is part of GDB.
 
-Everyone is granted permission to copy, modify and redistribute GDB,
-but only under the conditions described in the GDB General Public
-License.  A copy of this license is supposed to have been given to you
-along with GDB so you can know your rights and responsibilities.  It
-should be in a file named COPYING.  Among other things, the copyright
-notice and this notice must be preserved on all copies.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-In other words, go ahead and share GDB, but don't try to stop
-anyone else from sharing it farther.  Help stamp out software hoarding!
-*/
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+#include <stdio.h>
 #include "defs.h"
 #include "symtab.h"
+#include "param.h"
 #include "expression.h"
+#include "value.h"
 
-#include <stdio.h>
 \f
 /* These codes indicate operator precedences, least tightly binding first.  */
 /* Adding 1 to a precedence value is done for binary operators,
@@ -49,7 +50,7 @@ struct op_print
   int right_assoc;
 };
 
-static struct op_print op_print_tab[] =
+const static struct op_print op_print_tab[] =
   {
     {",", BINOP_COMMA, PREC_COMMA, 0},
     {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
@@ -79,7 +80,9 @@ static struct op_print op_print_tab[] =
     {"&", UNOP_ADDR, PREC_PREFIX, 0},
     {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
     {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
-    {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0}
+    {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
+    /* C++  */
+    {"::", BINOP_SCOPE, PREC_PREFIX, 0},
   };
 \f
 static void print_subexp ();
@@ -105,9 +108,9 @@ print_subexp (exp, pos, stream, prec)
      FILE *stream;
      enum precedence prec;
 {
-  register int tem;
+  register unsigned tem;
   register int pc;
-  int nargs;
+  unsigned nargs;
   register char *op_str;
   int assign_modify = 0;
   enum exp_opcode opcode;
@@ -119,133 +122,150 @@ print_subexp (exp, pos, stream, prec)
   opcode = exp->elts[pc].opcode;
   switch (opcode)
     {
+    case OP_SCOPE:
+      myprec = PREC_PREFIX;
+      assoc = 0;
+      (*pos) += 2;
+      print_subexp (exp, pos, stream,
+                   (enum precedence) ((int) myprec + assoc));
+      fputs_filtered (" :: ", stream);
+      nargs = strlen (&exp->elts[pc + 2].string);
+      (*pos) += 1 + (nargs + sizeof (union exp_element)) / sizeof (union exp_element);
+
+      fputs_filtered (&exp->elts[pc + 2].string, stream);
+      return;
+
     case OP_LONG:
       (*pos) += 3;
       value_print (value_from_long (exp->elts[pc + 1].type,
                                    exp->elts[pc + 2].longconst),
-                  stream, 0);
+                  stream, 0, Val_no_prettyprint);
       return;
 
     case OP_DOUBLE:
       (*pos) += 3;
       value_print (value_from_double (exp->elts[pc + 1].type,
                                      exp->elts[pc + 2].doubleconst),
-                  stream, 0);
+                  stream, 0, Val_no_prettyprint);
       return;
 
     case OP_VAR_VALUE:
       (*pos) += 2;
-      fprintf (stream, "%s", SYMBOL_NAME (exp->elts[pc + 1].symbol));
+      fputs_filtered (SYMBOL_NAME (exp->elts[pc + 1].symbol), stream);
       return;
 
     case OP_LAST:
       (*pos) += 2;
-      fprintf (stream, "$%d", exp->elts[pc + 1].longconst);
+      fprintf_filtered (stream, "$%d",
+                       longest_to_int (exp->elts[pc + 1].longconst));
       return;
 
     case OP_REGISTER:
       (*pos) += 2;
-      fprintf (stream, "$%s", reg_names[exp->elts[pc + 1].longconst]);
+      fprintf_filtered (stream, "$%s",
+              longest_to_int (reg_names[exp->elts[pc + 1].longconst]));
       return;
 
     case OP_INTERNALVAR:
       (*pos) += 2;
-      fprintf (stream, "$%s",
+      fprintf_filtered (stream, "$%s",
               internalvar_name (exp->elts[pc + 1].internalvar));
       return;
 
     case OP_FUNCALL:
       (*pos) += 2;
-      nargs = exp->elts[pc + 1].longconst;
+      nargs = longest_to_int (exp->elts[pc + 1].longconst);
       print_subexp (exp, pos, stream, PREC_SUFFIX);
-      fprintf (stream, " (");
+      fputs_filtered (" (", stream);
       for (tem = 0; tem < nargs; tem++)
        {
-         if (tem > 0)
-           fprintf (stream, ", ");
+         if (tem != 0)
+           fputs_filtered (", ", stream);
          print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
        }
-      fprintf (stream, ")");
+      fputs_filtered (")", stream);
       return;
 
     case OP_STRING:
       nargs = strlen (&exp->elts[pc + 1].string);
       (*pos) += 2 + (nargs + sizeof (union exp_element)) / sizeof (union exp_element);
-      fprintf (stream, "\"");
+      fputs_filtered ("\"", stream);
       for (tem = 0; tem < nargs; tem++)
        printchar ((&exp->elts[pc + 1].string)[tem], stream, '"');
-      fprintf (stream, "\"");
+      fputs_filtered ("\"", stream);
       return;
 
     case TERNOP_COND:
       if ((int) prec > (int) PREC_COMMA)
-       fprintf (stream, "(");
+       fputs_filtered ("(", stream);
       /* Print the subexpressions, forcing parentheses
         around any binary operations within them.
         This is more parentheses than are strictly necessary,
         but it looks clearer.  */
       print_subexp (exp, pos, stream, PREC_HYPER);
-      fprintf (stream, " ? ");
+      fputs_filtered (" ? ", stream);
       print_subexp (exp, pos, stream, PREC_HYPER);
-      fprintf (stream, " : ");
+      fputs_filtered (" : ", stream);
       print_subexp (exp, pos, stream, PREC_HYPER);
       if ((int) prec > (int) PREC_COMMA)
-       fprintf (stream, ")");
+       fputs_filtered (")", stream);
       return;
 
     case STRUCTOP_STRUCT:
       tem = strlen (&exp->elts[pc + 1].string);
       (*pos) += 2 + (tem + sizeof (union exp_element)) / sizeof (union exp_element);
       print_subexp (exp, pos, stream, PREC_SUFFIX);
-      fprintf (stream, ".%s", &exp->elts[pc + 1].string);
+      fputs_filtered (".", stream);
+      fputs_filtered (&exp->elts[pc + 1].string, stream);
       return;
 
     case STRUCTOP_PTR:
       tem = strlen (&exp->elts[pc + 1].string);
       (*pos) += 2 + (tem + sizeof (union exp_element)) / sizeof (union exp_element);
       print_subexp (exp, pos, stream, PREC_SUFFIX);
-      fprintf (stream, "->%s", &exp->elts[pc + 1].string);
+      fputs_filtered ("->", stream);
+      fputs_filtered (&exp->elts[pc + 1].string, stream);
       return;
 
     case BINOP_SUBSCRIPT:
       print_subexp (exp, pos, stream, PREC_SUFFIX);
-      fprintf (stream, "[");
+      fputs_filtered ("[", stream);
       print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
-      fprintf (stream, "]");
+      fputs_filtered ("]", stream);
       return;
 
     case UNOP_POSTINCREMENT:
       print_subexp (exp, pos, stream, PREC_SUFFIX);
-      fprintf (stream, "++");
+      fputs_filtered ("++", stream);
       return;
 
     case UNOP_POSTDECREMENT:
       print_subexp (exp, pos, stream, PREC_SUFFIX);
-      fprintf (stream, "--");
+      fputs_filtered ("--", stream);
       return;
 
     case UNOP_CAST:
       (*pos) += 2;
       if ((int) prec > (int) PREC_PREFIX)
-       fprintf (stream, "(");
-      fprintf (stream, "(");
+        fputs_filtered ("(", stream);
+      fputs_filtered ("(", stream);
       type_print (exp->elts[pc + 1].type, "", stream, 0);
-      fprintf (stream, ") ");
+      fputs_filtered (") ", stream);
       print_subexp (exp, pos, stream, PREC_PREFIX);
       if ((int) prec > (int) PREC_PREFIX)
-       fprintf (stream, ")");
+        fputs_filtered (")", stream);
       return;
 
     case UNOP_MEMVAL:
       (*pos) += 2;
       if ((int) prec > (int) PREC_PREFIX)
-       fprintf (stream, "(");
-      fprintf (stream, "{");
+        fputs_filtered ("(", stream);
+      fputs_filtered ("{", stream);
       type_print (exp->elts[pc + 1].type, "", stream, 0);
-      fprintf (stream, "} ");
+      fputs_filtered ("} ", stream);
       print_subexp (exp, pos, stream, PREC_PREFIX);
       if ((int) prec > (int) PREC_PREFIX)
-       fprintf (stream, ")");
+        fputs_filtered (")", stream);
       return;
 
     case BINOP_ASSIGN_MODIFY:
@@ -260,6 +280,12 @@ print_subexp (exp, pos, stream, prec)
            op_str = op_print_tab[tem].string;
            break;
          }
+      break;
+
+    case OP_THIS:
+      ++(*pos);
+      fputs_filtered ("this", stream);
+      return;
 
     default:
       for (tem = 0; tem < sizeof op_print_tab / sizeof op_print_tab[0]; tem++)
@@ -273,11 +299,11 @@ print_subexp (exp, pos, stream, prec)
     }
 
   if ((int) myprec < (int) prec)
-    fprintf (stream, "(");
+    fputs_filtered ("(", stream);
   if ((int) opcode > (int) BINOP_END)
     {
       /* Unary prefix operator.  */
-      fprintf (stream, "%s", op_str);
+      fputs_filtered (op_str, stream);
       print_subexp (exp, pos, stream, PREC_PREFIX);
     }
   else
@@ -286,19 +312,21 @@ print_subexp (exp, pos, stream, prec)
       /* Print left operand.
         If operator is right-associative,
         increment precedence for this operand.  */
-      print_subexp (exp, pos, stream, (int) myprec + assoc);
+      print_subexp (exp, pos, stream,
+                   (enum precedence) ((int) myprec + assoc));
       /* Print the operator itself.  */
       if (assign_modify)
-       fprintf (stream, " %s= ", op_str);
+       fprintf_filtered (stream, " %s= ", op_str);
       else if (op_str[0] == ',')
-       fprintf (stream, "%s ", op_str);
+       fprintf_filtered (stream, "%s ", op_str);
       else
-       fprintf (stream, " %s ", op_str);
+       fprintf_filtered (stream, " %s ", op_str);
       /* Print right operand.
         If operator is left-associative,
         increment precedence for this operand.  */
-      print_subexp (exp, pos, stream, (int) myprec + !assoc);
+      print_subexp (exp, pos, stream,
+                   (enum precedence) ((int) myprec + !assoc));
     }
   if ((int) myprec < (int) prec)
-    fprintf (stream, ")");
+    fputs_filtered (")", stream);
 }
This page took 0.027702 seconds and 4 git commands to generate.