This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfc][05/37] Eliminate builtin_type_ macros: Replace LA_BOOL_TYPE macro
- From: uweigand at de dot ibm dot com
- To: gdb-patches at sourceware dot org
- Date: Sun, 31 Aug 2008 19:50:50 +0200
- Subject: [rfc][05/37] Eliminate builtin_type_ macros: Replace LA_BOOL_TYPE macro
- References: <20080831175045.128504000@de.ibm.com>
Hello,
this replaces the LA_BOOL_TYPE macro (which calls lang_bool_type, which
uses current_gdbarch and current_language to determine what type to use
for "boolean" values) by a new language_bool_type function with explicit
language/gdbarch parameters. This new function is implemented by two new
members of the struct language_arch_info. All XXX_language_arch_info
functions are updated to set those values; the overall effect should be
no user-visible changes.
Bye,
Ulrich
ChangeLog:
* 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.
Index: gdb-head/gdb/ada-lang.c
===================================================================
--- gdb-head.orig/gdb/ada-lang.c
+++ gdb-head/gdb/ada-lang.c
@@ -8579,7 +8579,8 @@ ada_evaluate_subexp (struct type *expect
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);
@@ -8598,7 +8599,8 @@ ada_evaluate_subexp (struct type *expect
*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:
@@ -8850,14 +8852,16 @@ ada_evaluate_subexp (struct type *expect
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 (builtin_type_int, TYPE_LOW_BOUND (type));
arg3 = value_from_longest (builtin_type_int,
TYPE_HIGH_BOUND (type));
+ 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)
@@ -8873,7 +8877,10 @@ ada_evaluate_subexp (struct type *expect
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);
@@ -8883,8 +8890,9 @@ ada_evaluate_subexp (struct type *expect
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)
@@ -8898,8 +8906,9 @@ ada_evaluate_subexp (struct type *expect
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)
@@ -10911,6 +10920,9 @@ ada_language_arch_info (struct 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;
}
/* Language vector */
Index: gdb-head/gdb/c-lang.c
===================================================================
--- gdb-head.orig/gdb/c-lang.c
+++ gdb-head/gdb/c-lang.c
@@ -380,6 +380,8 @@ c_language_arch_info (struct gdbarch *gd
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
= 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: gdb-head/gdb/eval.c
===================================================================
--- gdb-head.orig/gdb/eval.c
+++ gdb-head/gdb/eval.c
@@ -562,8 +562,8 @@ evaluate_subexp_standard (struct type *e
}
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 *e
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 *e
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 *e
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 *e
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 *e
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 *e
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 *e
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 *e
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 *e
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 *e
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 *e
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: gdb-head/gdb/f-lang.c
===================================================================
--- gdb-head.orig/gdb/f-lang.c
+++ gdb-head/gdb/f-lang.c
@@ -298,6 +298,9 @@ f_language_arch_info (struct gdbarch *gd
= 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: gdb-head/gdb/jv-lang.c
===================================================================
--- gdb-head.orig/gdb/jv-lang.c
+++ gdb-head/gdb/jv-lang.c
@@ -1080,6 +1080,9 @@ java_language_arch_info (struct 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: gdb-head/gdb/language.c
===================================================================
--- gdb-head.orig/gdb/language.c
+++ gdb-head/gdb/language.c
@@ -787,51 +787,6 @@ structured_type (struct type *type)
}
#endif
-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;
- }
-}
-
/* This page contains functions that return info about
(struct value) values used in GDB. */
@@ -1169,6 +1124,7 @@ unknown_language_arch_info (struct gdbar
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 *);
}
@@ -1317,6 +1273,29 @@ language_string_char_type (const struct
}
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,
const char *name)
Index: gdb-head/gdb/language.h
===================================================================
--- gdb-head.orig/gdb/language.h
+++ gdb-head/gdb/language.h
@@ -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 *, .
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: gdb-head/gdb/m2-lang.c
===================================================================
--- gdb-head.orig/gdb/m2-lang.c
+++ gdb-head/gdb/m2-lang.c
@@ -345,6 +345,9 @@ m2_language_arch_info (struct gdbarch *g
= 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: gdb-head/gdb/p-lang.c
===================================================================
--- gdb-head.orig/gdb/p-lang.c
+++ gdb-head/gdb/p-lang.c
@@ -393,6 +393,9 @@ pascal_language_arch_info (struct gdbarc
= 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: gdb-head/gdb/valarith.c
===================================================================
--- gdb-head.orig/gdb/valarith.c
+++ gdb-head/gdb/valarith.c
@@ -1846,7 +1846,7 @@ value_bit_index (struct type *type, cons
return (word >> rel_index) & 1;
}
-struct value *
+int
value_in (struct value *element, struct value *set)
{
int member;
@@ -1865,7 +1865,7 @@ value_in (struct value *element, struct
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: gdb-head/gdb/value.h
===================================================================
--- gdb-head.orig/gdb/value.h
+++ gdb-head/gdb/value.h
@@ -412,7 +412,7 @@ extern struct value *value_bitstring_sub
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);
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com