]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* language.h (struct language_arch_info): New members
authorUlrich Weigand <uweigand@de.ibm.com>
Thu, 11 Sep 2008 14:11:40 +0000 (14:11 +0000)
committerUlrich Weigand <uweigand@de.ibm.com>
Thu, 11 Sep 2008 14:11:40 +0000 (14:11 +0000)
bool_type_default and bool_type_symbol.
(lang_bool_type): Remove prototype.
(LA_BOOL_TYPE): Remove macro.
(language_bool_type): Add prototype.
* language.c (lang_bool_type): Remove.
(language_bool_type): New function.

* value.h (value_in): Change return value to int.
* value.c (value_in): Return int instead of struct value *.

* eval.c (evaluate_subexp_standard): Call language_bool_type instead
of using LA_BOOL_TYPE.  Update call to value_in.
* ada-lang.c (ada_evaluate_subexp): Call language_bool_type instead
of using LA_BOOL_TYPE or builtin_type_int for boolean values.

* language.c (unknown_language_arch_info): Set bool_type_default member
of struct language_arch_info.
* ada-lang.c (ada_language_arch_info): Set bool_type_symbol and
bool_type_default members of struct language_arch_info.
* c-lang.c (c_language_arch_info): Set bool_type_default member
of struct language_arch_info.
(cplus_language_arch_info): Set bool_type_symbol and bool_type_default
members of struct language_arch_info.
* f-lang.c (f_language_arch_info): Set bool_type_symbol and
bool_type_default members of struct language_arch_info.
* jv-lang.c (java_language_arch_info): Set bool_type_symbol and
bool_type_default members of struct language_arch_info.
* m2-lang.c (m2_language_arch_info): Set bool_type_symbol and
bool_type_default members of struct language_arch_info.
* p-lang.c (p_language_arch_info): Set bool_type_symbol and
bool_type_default members of struct language_arch_info.

12 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/c-lang.c
gdb/eval.c
gdb/f-lang.c
gdb/jv-lang.c
gdb/language.c
gdb/language.h
gdb/m2-lang.c
gdb/p-lang.c
gdb/valarith.c
gdb/value.h

index 0ba2e95afd525d6d7c1b4b81c69223b5ee35c833..91869e43ca388f446079037135629465e5efe68f 100644 (file)
@@ -1,3 +1,38 @@
+2008-09-11  Ulrich Weigand  <uweigand@de.ibm.com>
+
+       * language.h (struct language_arch_info): New members
+       bool_type_default and bool_type_symbol.
+       (lang_bool_type): Remove prototype.
+       (LA_BOOL_TYPE): Remove macro.
+       (language_bool_type): Add prototype.
+       * language.c (lang_bool_type): Remove.
+       (language_bool_type): New function.
+
+       * value.h (value_in): Change return value to int.
+       * value.c (value_in): Return int instead of struct value *.
+
+       * eval.c (evaluate_subexp_standard): Call language_bool_type instead
+       of using LA_BOOL_TYPE.  Update call to value_in.
+       * ada-lang.c (ada_evaluate_subexp): Call language_bool_type instead
+       of using LA_BOOL_TYPE or builtin_type_int for boolean values.
+
+       * language.c (unknown_language_arch_info): Set bool_type_default member
+       of struct language_arch_info.
+       * ada-lang.c (ada_language_arch_info): Set bool_type_symbol and
+       bool_type_default members of struct language_arch_info.
+       * c-lang.c (c_language_arch_info): Set bool_type_default member
+       of struct language_arch_info.
+       (cplus_language_arch_info): Set bool_type_symbol and bool_type_default
+       members of struct language_arch_info.
+       * f-lang.c (f_language_arch_info): Set bool_type_symbol and
+       bool_type_default members of struct language_arch_info.
+       * jv-lang.c (java_language_arch_info): Set bool_type_symbol and
+       bool_type_default members of struct language_arch_info.
+       * m2-lang.c (m2_language_arch_info): Set bool_type_symbol and
+       bool_type_default members of struct language_arch_info.
+       * p-lang.c (p_language_arch_info): Set bool_type_symbol and
+       bool_type_default members of struct language_arch_info.
+
 2008-09-11  Ulrich Weigand  <uweigand@de.ibm.com>
 
        * jv-lang.c (enum java_primitive_types): New type.
index 50fd5eb739a56dc49de63ba4fc3cb78ad07e8f8f..d7dddd05ab3ca4a598f13d2b11586e3b372e2c35 100644 (file)
@@ -8525,7 +8525,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         tem = ada_value_equal (arg1, arg2);
       if (op == BINOP_NOTEQUAL)
         tem = !tem;
-      return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
+      type = language_bool_type (exp->language_defn, exp->gdbarch);
+      return value_from_longest (type, (LONGEST) tem);
 
     case UNOP_NEG:
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
@@ -8544,7 +8545,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 
         *pos -= 1;
         val = evaluate_subexp_standard (expect_type, exp, pos, noside);
-        return value_cast (LA_BOOL_TYPE, val);
+       type = language_bool_type (exp->language_defn, exp->gdbarch);
+        return value_cast (type, val);
       }
 
     case BINOP_BITWISE_AND:
@@ -8812,13 +8814,15 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         default:
           lim_warning (_("Membership test incompletely implemented; "
                         "always returns true"));
-          return value_from_longest (builtin_type_int, (LONGEST) 1);
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type, (LONGEST) 1);
 
         case TYPE_CODE_RANGE:
          arg2 = value_from_longest (type, TYPE_LOW_BOUND (type));
          arg3 = value_from_longest (type, TYPE_HIGH_BOUND (type));
-          return
-            value_from_longest (builtin_type_int,
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return
+           value_from_longest (type,
                                 (value_less (arg1, arg3)
                                  || value_equal (arg1, arg3))
                                 && (value_less (arg2, arg1)
@@ -8834,7 +8838,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         goto nosideret;
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        return value_zero (builtin_type_int, not_lval);
+       {
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_zero (type, not_lval);
+       }
 
       tem = longest_to_int (exp->elts[pc + 1].longconst);
 
@@ -8844,8 +8851,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       arg3 = ada_array_bound (arg2, tem, 1);
       arg2 = ada_array_bound (arg2, tem, 0);
 
+      type = language_bool_type (exp->language_defn, exp->gdbarch);
       return
-        value_from_longest (builtin_type_int,
+        value_from_longest (type,
                             (value_less (arg1, arg3)
                              || value_equal (arg1, arg3))
                             && (value_less (arg2, arg1)
@@ -8859,8 +8867,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (noside == EVAL_SKIP)
         goto nosideret;
 
+      type = language_bool_type (exp->language_defn, exp->gdbarch);
       return
-        value_from_longest (builtin_type_int,
+        value_from_longest (type,
                             (value_less (arg1, arg3)
                              || value_equal (arg1, arg3))
                             && (value_less (arg2, arg1)
@@ -10872,6 +10881,9 @@ ada_language_arch_info (struct gdbarch *gdbarch,
                                     (struct objfile *) NULL));
   TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
     = "system__address";
+
+  lai->bool_type_symbol = "boolean";
+  lai->bool_type_default = builtin->builtin_bool;
 }
 \f
                                /* Language vector */
index 9ce4bb9f4e1be4b33624715ff2f7ad836f0c5bf7..ebe781b3796297d7261149b65af8a3530022a10d 100644 (file)
@@ -380,6 +380,8 @@ c_language_arch_info (struct gdbarch *gdbarch,
   lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat;
   lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble;
   lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong;
+
+  lai->bool_type_default = builtin->builtin_int;
 }
 
 const struct language_defn c_language_defn =
@@ -493,6 +495,9 @@ cplus_language_arch_info (struct gdbarch *gdbarch,
     = builtin->builtin_decdouble;
   lai->primitive_type_vector [cplus_primitive_type_declong]
     = builtin->builtin_declong;
+
+  lai->bool_type_symbol = "bool";
+  lai->bool_type_default = builtin->builtin_bool;
 }
 
 const struct language_defn cplus_language_defn =
index 9400ef4b368e6cb679c2afb477eded1e9bd70893..9086e1b6b95558855092cc3d68e1c474f6146756 100644 (file)
@@ -562,8 +562,8 @@ evaluate_subexp_standard (struct type *expect_type,
       }
     case OP_BOOL:
       (*pos) += 2;
-      return value_from_longest (LA_BOOL_TYPE,
-                                exp->elts[pc + 1].longconst);
+      type = language_bool_type (exp->language_defn, exp->gdbarch);
+      return value_from_longest (type, exp->elts[pc + 1].longconst);
 
     case OP_INTERNALVAR:
       (*pos) += 2;
@@ -1618,7 +1618,8 @@ evaluate_subexp_standard (struct type *expect_type,
       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
       if (noside == EVAL_SKIP)
        goto nosideret;
-      return value_in (arg1, arg2);
+      type = language_bool_type (exp->language_defn, exp->gdbarch);
+      return value_from_longest (type, (LONGEST) value_in (arg1, arg2));
 
     case MULTI_SUBSCRIPT:
       (*pos) += 2;
@@ -1678,7 +1679,8 @@ evaluate_subexp_standard (struct type *expect_type,
                  break;
 
                case TYPE_CODE_BITSTRING:
-                 arg1 = value_bitstring_subscript (LA_BOOL_TYPE, arg1, arg2);
+                 type = language_bool_type (exp->language_defn, exp->gdbarch);
+                 arg1 = value_bitstring_subscript (type, arg1, arg2);
                  break;
 
                default:
@@ -1798,7 +1800,8 @@ evaluate_subexp_standard (struct type *expect_type,
          tem = value_logical_not (arg1);
          arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
                                  (tem ? EVAL_SKIP : noside));
-         return value_from_longest (LA_BOOL_TYPE,
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type,
                             (LONGEST) (!tem && !value_logical_not (arg2)));
        }
 
@@ -1824,7 +1827,8 @@ evaluate_subexp_standard (struct type *expect_type,
          tem = value_logical_not (arg1);
          arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
                                  (!tem ? EVAL_SKIP : noside));
-         return value_from_longest (LA_BOOL_TYPE,
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type,
                             (LONGEST) (!tem || !value_logical_not (arg2)));
        }
 
@@ -1840,7 +1844,8 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          tem = value_equal (arg1, arg2);
-         return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type, (LONGEST) tem);
        }
 
     case BINOP_NOTEQUAL:
@@ -1855,7 +1860,8 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          tem = value_equal (arg1, arg2);
-         return value_from_longest (LA_BOOL_TYPE, (LONGEST) ! tem);
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type, (LONGEST) ! tem);
        }
 
     case BINOP_LESS:
@@ -1870,7 +1876,8 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          tem = value_less (arg1, arg2);
-         return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type, (LONGEST) tem);
        }
 
     case BINOP_GTR:
@@ -1885,7 +1892,8 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          tem = value_less (arg2, arg1);
-         return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type, (LONGEST) tem);
        }
 
     case BINOP_GEQ:
@@ -1900,7 +1908,8 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
-         return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type, (LONGEST) tem);
        }
 
     case BINOP_LEQ:
@@ -1915,7 +1924,8 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
-         return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type, (LONGEST) tem);
        }
 
     case BINOP_REPEAT:
@@ -1975,8 +1985,10 @@ evaluate_subexp_standard (struct type *expect_type,
       if (unop_user_defined_p (op, arg1))
        return value_x_unop (arg1, op, noside);
       else
-       return value_from_longest (LA_BOOL_TYPE,
-                                  (LONGEST) value_logical_not (arg1));
+       {
+         type = language_bool_type (exp->language_defn, exp->gdbarch);
+         return value_from_longest (type, (LONGEST) value_logical_not (arg1));
+       }
 
     case UNOP_IND:
       if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
index 5dcbd33de633725f58d8bff1f452580d6af35fc8..8ae7775ad42536cb8bd720764330d9f26be547ec 100644 (file)
@@ -298,6 +298,9 @@ f_language_arch_info (struct gdbarch *gdbarch,
     = builtin->builtin_complex_s16;
   lai->primitive_type_vector [f_primitive_type_void]
     = builtin->builtin_void;
+
+  lai->bool_type_symbol = "logical";
+  lai->bool_type_default = builtin->builtin_logical_s2;
 }
 
 /* This is declared in c-lang.h but it is silly to import that file for what
index 342829218c3214c371a77300ccffd29634eca49b..e74b72da4a211065c3ab3e3774db6d5427c4ae03 100644 (file)
@@ -1080,6 +1080,9 @@ java_language_arch_info (struct gdbarch *gdbarch,
     = java_double_type;
   lai->primitive_type_vector [java_primitive_type_void]
     = java_void_type;
+
+  lai->bool_type_symbol = "boolean";
+  lai->bool_type_default = java_boolean_type;
 }
 
 const struct exp_descriptor exp_descriptor_java = 
index 66e554204b0afc1fd614a7934b5a5c07bbb9405b..7b0b44a6b1b19eba2936e31cec4a1491c64263b2 100644 (file)
@@ -787,51 +787,6 @@ structured_type (struct type *type)
 }
 #endif
 \f
-struct type *
-lang_bool_type (void)
-{
-  struct symbol *sym;
-  struct type *type;
-  switch (current_language->la_language)
-    {
-    case language_fortran:
-      sym = lookup_symbol ("logical", NULL, VAR_DOMAIN, NULL);
-      if (sym)
-       {
-         type = SYMBOL_TYPE (sym);
-         if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
-           return type;
-       }
-      return builtin_type_f_logical_s2;
-    case language_cplus:
-    case language_pascal:
-    case language_ada:
-      if (current_language->la_language==language_cplus)
-        {sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL);}
-      else
-        {sym = lookup_symbol ("boolean", NULL, VAR_DOMAIN, NULL);}
-      if (sym)
-       {
-         type = SYMBOL_TYPE (sym);
-         if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
-           return type;
-       }
-      return builtin_type_bool;
-    case language_java:
-      sym = lookup_symbol ("boolean", NULL, VAR_DOMAIN, NULL);
-      if (sym)
-       {
-         type = SYMBOL_TYPE (sym);
-         if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
-           return type;
-       }
-      return java_boolean_type;
-      
-    default:
-      return builtin_type_int;
-    }
-}
-\f
 /* This page contains functions that return info about
    (struct value) values used in GDB. */
 
@@ -1169,6 +1124,7 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
                            struct language_arch_info *lai)
 {
   lai->string_char_type = builtin_type (gdbarch)->builtin_char;
+  lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
   lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
                                                       struct type *);
 }
@@ -1316,6 +1272,29 @@ language_string_char_type (const struct language_defn *la,
   return ld->arch_info[la->la_language].string_char_type;
 }
 
+struct type *
+language_bool_type (const struct language_defn *la,
+                   struct gdbarch *gdbarch)
+{
+  struct language_gdbarch *ld = gdbarch_data (gdbarch,
+                                             language_gdbarch_data);
+
+  if (ld->arch_info[la->la_language].bool_type_symbol)
+    {
+      struct symbol *sym;
+      sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
+                          NULL, VAR_DOMAIN, NULL);
+      if (sym)
+       {
+         struct type *type = SYMBOL_TYPE (sym);
+         if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
+           return type;
+       }
+    }
+
+  return ld->arch_info[la->la_language].bool_type_default;
+}
+
 struct type *
 language_lookup_primitive_type_by_name (const struct language_defn *la,
                                        struct gdbarch *gdbarch,
index 8bdc212a81df331fdb6a9d61204ccb5cbd38d351..04d4da2604bcf2d37a167b43dca40155541bdaa8 100644 (file)
@@ -125,6 +125,11 @@ struct language_arch_info
   struct type **primitive_type_vector;
   /* Type of elements of strings. */
   struct type *string_char_type;
+
+  /* Symbol name of type to use as boolean type, if defined.  */
+  const char *bool_type_symbol;
+  /* Otherwise, this is the default boolean builtin type.  */
+  struct type *bool_type_default;
 };
 
 /* Structure tying together assorted information about a language.  */
@@ -306,6 +311,9 @@ extern enum language_mode
   }
 language_mode;
 
+struct type *language_bool_type (const struct language_defn *l,
+                                struct gdbarch *gdbarch);
+
 struct type *language_string_char_type (const struct language_defn *l,
                                        struct gdbarch *gdbarch);
 
@@ -416,11 +424,6 @@ extern void range_error (const char *, ...) ATTR_FORMAT (printf, 1, 2);
 
 extern int value_true (struct value *);
 
-extern struct type *lang_bool_type (void);
-
-/* The type used for Boolean values in the current language. */
-#define LA_BOOL_TYPE lang_bool_type ()
-
 /* Misc:  The string representing a particular enum language.  */
 
 extern enum language language_enum (char *str);
index bb205ad29f4c40347909ddb4c30f84f54e5e5bd7..793ae03a64debfa54e621ea11f8f2c42a84315f0 100644 (file)
@@ -345,6 +345,9 @@ m2_language_arch_info (struct gdbarch *gdbarch,
     = builtin->builtin_real;
   lai->primitive_type_vector [m2_primitive_type_bool]
     = builtin->builtin_bool;
+
+  lai->bool_type_symbol = "BOOLEAN";
+  lai->bool_type_default = builtin->builtin_bool;
 }
 
 const struct exp_descriptor exp_descriptor_modula2 = 
index 2accf35f60e27aeb7d4142a675a195eed015473e..b763e04900dbab53e825732a3f46a115a19981ce 100644 (file)
@@ -393,6 +393,9 @@ pascal_language_arch_info (struct gdbarch *gdbarch,
     = builtin->builtin_complex;
   lai->primitive_type_vector [pascal_primitive_type_double_complex]
     = builtin->builtin_double_complex;
+
+  lai->bool_type_symbol = "boolean";
+  lai->bool_type_default = builtin->builtin_bool;
 }
 
 const struct language_defn pascal_language_defn =
index 909c1a08957f53a79978f6e6dc453591d17a5f46..c13c39303284929e6d6a472a76c6e1a9ce44a2e1 100644 (file)
@@ -1851,7 +1851,7 @@ value_bit_index (struct type *type, const gdb_byte *valaddr, int index)
   return (word >> rel_index) & 1;
 }
 
-struct value *
+int
 value_in (struct value *element, struct value *set)
 {
   int member;
@@ -1870,7 +1870,7 @@ value_in (struct value *element, struct value *set)
                            value_as_long (element));
   if (member < 0)
     error (_("First argument of 'IN' not in range"));
-  return value_from_longest (LA_BOOL_TYPE, member);
+  return member;
 }
 
 void
index 77de9814ece28093e3a20a06e67a5c072aa5edfb..d0545e20d14b1228296a86161f28c5dc5a38edf1 100644 (file)
@@ -412,7 +412,7 @@ extern struct value *value_bitstring_subscript (struct type *type,
 extern struct value *register_value_being_returned (struct type *valtype,
                                                    struct regcache *retbuf);
 
-extern struct value *value_in (struct value *element, struct value *set);
+extern int value_in (struct value *element, struct value *set);
 
 extern int value_bit_index (struct type *type, const gdb_byte *addr,
                            int index);