This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[commit] Changes for architecture type vector in Ada
- From: Paul Hilfinger <hilfingr at gnat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sat, 18 Sep 2004 18:37:38 -0400 (EDT)
- Subject: [commit] Changes for architecture type vector in Ada
The following patch is intended to bring the Ada sources in line with the
C sources in their handling of language-specific types. (When I checked
this is, I also revised my last ChangeLog entry to give the right, i.e.,
official, e-mail address).
Andrew, at some point I asked you a question relevant to this patch
for which I seem to have mislaid any answer you may have given: If at
some point in a language-specific file, one needs to refer to a
language-specific type, what is the MC (methodologically correct)
method for accessing that type? By name, as by
language_lookup_primitive_type_by_name (seems a bit wasteful to have
to do a search), or by some other means? Thanks.
Paul Hilfinger
2004-09-18 Paul N. Hilfinger <hilfinger@gnat.com>
* ada-exp.y (type_int): New function to add layer of abstraction
around references to expression types.
(type_long): Ditto.
(type_long_long): Ditto.
(type_float): Ditto.
(type_double): Ditto.
(type_long_double): Ditto.
(type_char): Ditto.
(type_system_address): Ditto.
(simple_exp): Use type_* functions in place of builtin_*
variables.
(exp): Ditto.
(write_var_from_name): Ditto.
(write_object_renaming): Ditto.
* ada-lang.c (ada_create_fundamental_type): Remove redundant
declaration.
(build_ada_types): Remove, replacing with...
(ada_language_arch_info): New function to initialize primitive
type vector in language_arch_info.
(ada_array_length): Remove use of builtin_type_ada_int.
(value_pos_atr): Ditto.
(ada_evaluate_subexp): Ditto.
(builtin_type_ada_int, builtin_type_ada_short, builtin_type_ada_long,
builtin_type_ada_long_long, builtin_type_ada_char,
builtin_type_ada_float, builtin_type_ada_double,
builtin_type_ada_long_double, builtin_type_ada_natural,
builtin_type_ada_positive, builtin_type_ada_system_address): Remove.
(ada_builtin_types): Remove.
(ada_language_defn): Remove entries for la_builtin_type_vector and
string_char_type and use ada_language_arch_info.
(_initialize_ada_language): Do type-vector initialization along
the lines of c-lang.c.
(ada_create_fundamental_type): Break up line.
(ada_dump_symtab): Remove unused function.
(enum ada_primitive_types): Define.
* ada-lang.h (builtin_type_ada_int, builtin_type_ada_short,
builtin_type_ada_long,builtin_type_ada_long_long,builtin_type_ada_char,
builtin_type_ada_float, builtin_type_ada_double,
builtin_type_ada_long_double, builtin_type_ada_natural,
builtin_type_ada_positive, builtin_type_ada_system_address): Remove.
* ada-lex.l: Use type_* functions in place of builtin_* variables.
(processInt): Ditto.
(processReal): Ditto.
(name_lookup): Ditto.
* ada-typeprint.c (print_range): Use builtin_type_int, not
builtin_type_ada_int.
Index: gdb/ada-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/ada-exp.y,v
retrieving revision 1.11
diff -u -p -r1.11 ada-exp.y
--- gdb/ada-exp.y 9 Jul 2004 19:29:56 -0000 1.11
+++ gdb/ada-exp.y 18 Sep 2004 22:04:52 -0000
@@ -126,6 +126,22 @@ static void write_object_renaming (struc
static void write_var_from_name (struct block *, struct name_info);
static LONGEST convert_char_literal (struct type *, LONGEST);
+
+static struct type *type_int (void);
+
+static struct type *type_long (void);
+
+static struct type *type_long_long (void);
+
+static struct type *type_float (void);
+
+static struct type *type_double (void);
+
+static struct type *type_long_double (void);
+
+static struct type *type_char (void);
+
+static struct type *type_system_address (void);
%}
%union
@@ -426,17 +442,17 @@ simple_exp : simple_exp TICK_ACCESS
| simple_exp TICK_ADDRESS
{ write_exp_elt_opcode (UNOP_ADDR);
write_exp_elt_opcode (UNOP_CAST);
- write_exp_elt_type (builtin_type_ada_system_address);
+ write_exp_elt_type (type_system_address ());
write_exp_elt_opcode (UNOP_CAST);
}
| simple_exp TICK_FIRST tick_arglist
- { write_int ($3, builtin_type_int);
+ { write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_FIRST); }
| simple_exp TICK_LAST tick_arglist
- { write_int ($3, builtin_type_int);
+ { write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_LAST); }
| simple_exp TICK_LENGTH tick_arglist
- { write_int ($3, builtin_type_int);
+ { write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_LENGTH); }
| simple_exp TICK_SIZE
{ write_exp_elt_opcode (OP_ATR_SIZE); }
@@ -449,13 +465,13 @@ simple_exp : simple_exp TICK_ACCESS
| opt_type_prefix TICK_POS '(' exp ')'
{ write_exp_elt_opcode (OP_ATR_POS); }
| type_prefix TICK_FIRST tick_arglist
- { write_int ($3, builtin_type_int);
+ { write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_FIRST); }
| type_prefix TICK_LAST tick_arglist
- { write_int ($3, builtin_type_int);
+ { write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_LAST); }
| type_prefix TICK_LENGTH tick_arglist
- { write_int ($3, builtin_type_int);
+ { write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_LENGTH); }
| type_prefix TICK_VAL '(' exp ')'
{ write_exp_elt_opcode (OP_ATR_VAL); }
@@ -505,7 +521,7 @@ exp : FLOAT
;
exp : NULL_PTR
- { write_int (0, builtin_type_int); }
+ { write_int (0, type_int ()); }
;
exp : STRING
@@ -666,8 +682,8 @@ write_var_from_name (struct block *orig_
if (name.msym != NULL)
{
write_exp_msymbol (name.msym,
- lookup_function_type (builtin_type_int),
- builtin_type_int);
+ lookup_function_type (type_int ()),
+ type_int ());
}
else if (name.sym == NULL)
{
@@ -779,7 +795,7 @@ write_object_renaming (struct block *ori
goto BadEncoding;
suffix = next;
write_exp_elt_opcode (OP_LONG);
- write_exp_elt_type (builtin_type_ada_int);
+ write_exp_elt_type (type_int ());
write_exp_elt_longcst ((LONGEST) val);
write_exp_elt_opcode (OP_LONG);
}
@@ -879,6 +895,58 @@ convert_char_literal (struct type *type,
return val;
}
+static struct type *
+type_int (void)
+{
+ return builtin_type (current_gdbarch)->builtin_int;
+}
+
+static struct type *
+type_long (void)
+{
+ return builtin_type (current_gdbarch)->builtin_long;
+}
+
+static struct type *
+type_long_long (void)
+{
+ return builtin_type (current_gdbarch)->builtin_long_long;
+}
+
+static struct type *
+type_float (void)
+{
+ return builtin_type (current_gdbarch)->builtin_float;
+}
+
+static struct type *
+type_double (void)
+{
+ return builtin_type (current_gdbarch)->builtin_double;
+}
+
+static struct type *
+type_long_double (void)
+{
+ return builtin_type (current_gdbarch)->builtin_long_double;
+}
+
+static struct type *
+type_char (void)
+{
+ return language_string_char_type (current_language, current_gdbarch);
+}
+
+static struct type *
+type_system_address (void)
+{
+ struct type *type
+ = language_lookup_primitive_type_by_name (current_language,
+ current_gdbarch,
+ "system__address");
+ return type != NULL ? type : lookup_pointer_type (builtin_type_void);
+}
+
void
_initialize_ada_exp (void)
{
Index: gdb/ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.53
diff -u -p -r1.53 ada-lang.c
--- gdb/ada-lang.c 18 Sep 2004 10:11:06 -0000 1.53
+++ gdb/ada-lang.c 18 Sep 2004 22:04:54 -0000
@@ -192,8 +192,6 @@ static struct value *evaluate_subexp (st
static struct value *evaluate_subexp_type (struct expression *, int *);
-static struct type *ada_create_fundamental_type (struct objfile *, int);
-
static int is_dynamic_field (struct type *, int);
static struct type *to_fixed_variant_branch_type (struct type *, char *,
@@ -281,6 +279,11 @@ static int ada_is_direct_array_type (str
static void error_breakpoint_runtime_sym_not_found (const char *err_desc);
static int is_runtime_sym_defined (const char *name, int allow_tramp);
+
+static void ada_language_arch_info (struct gdbarch *,
+ struct language_arch_info *);
+
+static void check_size (const struct type *);
@@ -2440,7 +2443,7 @@ ada_array_length (struct value *arr, int
}
else
return
- value_from_longest (builtin_type_ada_int,
+ value_from_longest (builtin_type_int,
value_as_long (desc_one_bound (desc_bounds (arr),
n, 1))
- value_as_long (desc_one_bound (desc_bounds (arr),
@@ -8343,7 +8346,7 @@ pos_atr (struct value *arg)
static struct value *
value_pos_atr (struct value *arg)
{
- return value_from_longest (builtin_type_ada_int, pos_atr (arg));
+ return value_from_longest (builtin_type_int, pos_atr (arg));
}
/* Evaluate the TYPE'VAL attribute applied to ARG. */
@@ -9320,7 +9323,7 @@ ada_evaluate_subexp (struct type *expect
if (noside == EVAL_SKIP)
goto nosideret;
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (builtin_type_ada_int, not_lval);
+ return value_zero (builtin_type_int, not_lval);
else
return value_pos_atr (arg1);
@@ -9329,9 +9332,9 @@ ada_evaluate_subexp (struct type *expect
if (noside == EVAL_SKIP)
goto nosideret;
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (builtin_type_ada_int, not_lval);
+ return value_zero (builtin_type_int, not_lval);
else
- return value_from_longest (builtin_type_ada_int,
+ return value_from_longest (builtin_type_int,
TARGET_CHAR_BIT
* TYPE_LENGTH (VALUE_TYPE (arg1)));
@@ -10167,7 +10170,9 @@ ada_create_fundamental_type (struct objf
0, "integer", objfile);
break;
case FT_SIGNED_INTEGER:
- type = init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 0, "integer", objfile); /* FIXME -fnf */
+ type = init_type (TYPE_CODE_INT, TARGET_INT_BIT /
+ TARGET_CHAR_BIT,
+ 0, "integer", objfile); /* FIXME -fnf */
break;
case FT_UNSIGNED_INTEGER:
type = init_type (TYPE_CODE_INT,
@@ -10223,88 +10228,69 @@ ada_create_fundamental_type (struct objf
return (type);
}
-struct type *builtin_type_ada_int;
-struct type *builtin_type_ada_short;
-struct type *builtin_type_ada_long;
-struct type *builtin_type_ada_long_long;
-struct type *builtin_type_ada_char;
-struct type *builtin_type_ada_float;
-struct type *builtin_type_ada_double;
-struct type *builtin_type_ada_long_double;
-struct type *builtin_type_ada_natural;
-struct type *builtin_type_ada_positive;
-struct type *builtin_type_ada_system_address;
-
-struct type **const (ada_builtin_types[]) =
-{
- &builtin_type_ada_int,
- &builtin_type_ada_long,
- &builtin_type_ada_short,
- &builtin_type_ada_char,
- &builtin_type_ada_float,
- &builtin_type_ada_double,
- &builtin_type_ada_long_long,
- &builtin_type_ada_long_double,
- &builtin_type_ada_natural, &builtin_type_ada_positive,
- /* The following types are carried over from C for convenience. */
-&builtin_type_int,
- &builtin_type_long,
- &builtin_type_short,
- &builtin_type_char,
- &builtin_type_float,
- &builtin_type_double,
- &builtin_type_long_long,
- &builtin_type_void,
- &builtin_type_signed_char,
- &builtin_type_unsigned_char,
- &builtin_type_unsigned_short,
- &builtin_type_unsigned_int,
- &builtin_type_unsigned_long,
- &builtin_type_unsigned_long_long,
- &builtin_type_long_double,
- &builtin_type_complex, &builtin_type_double_complex, 0};
+enum ada_primitive_types {
+ ada_primitive_type_int,
+ ada_primitive_type_long,
+ ada_primitive_type_short,
+ ada_primitive_type_char,
+ ada_primitive_type_float,
+ ada_primitive_type_double,
+ ada_primitive_type_void,
+ ada_primitive_type_long_long,
+ ada_primitive_type_long_double,
+ ada_primitive_type_natural,
+ ada_primitive_type_positive,
+ ada_primitive_type_system_address,
+ nr_ada_primitive_types
+};
static void
-build_ada_types (struct gdbarch *current_gdbarch)
+ada_language_arch_info (struct gdbarch *current_gdbarch,
+ struct language_arch_info *lai)
{
- builtin_type_ada_int =
+ const struct builtin_type *builtin = builtin_type (current_gdbarch);
+ lai->primitive_type_vector
+ = GDBARCH_OBSTACK_CALLOC (current_gdbarch, nr_ada_primitive_types + 1,
+ struct type *);
+ lai->primitive_type_vector [ada_primitive_type_int] =
init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
0, "integer", (struct objfile *) NULL);
- builtin_type_ada_long =
+ lai->primitive_type_vector [ada_primitive_type_long] =
init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
0, "long_integer", (struct objfile *) NULL);
- builtin_type_ada_short =
+ lai->primitive_type_vector [ada_primitive_type_short] =
init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
0, "short_integer", (struct objfile *) NULL);
- builtin_type_ada_char =
+ lai->primitive_type_vector [ada_primitive_type_char] =
init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
0, "character", (struct objfile *) NULL);
- builtin_type_ada_float =
+ lai->string_char_type = builtin->builtin_char;
+ lai->primitive_type_vector [ada_primitive_type_float] =
init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
0, "float", (struct objfile *) NULL);
- builtin_type_ada_double =
+ lai->primitive_type_vector [ada_primitive_type_double] =
init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
0, "long_float", (struct objfile *) NULL);
- builtin_type_ada_long_long =
+ lai->primitive_type_vector [ada_primitive_type_long_long] =
init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
0, "long_long_integer", (struct objfile *) NULL);
- builtin_type_ada_long_double =
+ lai->primitive_type_vector [ada_primitive_type_long_double] =
init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
0, "long_long_float", (struct objfile *) NULL);
- builtin_type_ada_natural =
+ lai->primitive_type_vector [ada_primitive_type_natural] =
init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
0, "natural", (struct objfile *) NULL);
- builtin_type_ada_positive =
+ lai->primitive_type_vector [ada_primitive_type_positive] =
init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
0, "positive", (struct objfile *) NULL);
+ lai->primitive_type_vector [ada_primitive_type_void] = builtin->builtin_void;
-
- builtin_type_ada_system_address =
+ lai->primitive_type_vector [ada_primitive_type_system_address] =
lookup_pointer_type (init_type (TYPE_CODE_VOID, 1, 0, "void",
(struct objfile *) NULL));
- TYPE_NAME (builtin_type_ada_system_address) = "system__address";
+ TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
+ = "system__address";
}
-
/* Language vector */
@@ -10334,7 +10320,7 @@ static const struct exp_descriptor ada_e
const struct language_defn ada_language_defn = {
"ada", /* Language name */
language_ada,
- ada_builtin_types,
+ NULL,
range_check_off,
type_check_off,
case_sensitive_on, /* Yes, Ada is case-insensitive, but
@@ -10364,8 +10350,9 @@ const struct language_defn ada_language_
ada_op_print_tab, /* expression operators for printing */
0, /* c-style arrays */
1, /* String lower bound */
- &builtin_type_ada_char,
+ NULL,
ada_get_gdb_completer_word_break_characters,
+ ada_language_arch_info,
#ifdef GNAT_GDB
ada_translate_error_message, /* Substitute Ada-specific terminology
in errors and warnings. */
@@ -10376,9 +10363,6 @@ const struct language_defn ada_language_
void
_initialize_ada_language (void)
{
-
- build_ada_types (current_gdbarch);
- gdbarch_data_register_post_init (build_ada_types);
add_language (&ada_language_defn);
varsize_limit = 65536;
Index: gdb/ada-lang.h
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.h,v
retrieving revision 1.10
diff -u -p -r1.10 ada-lang.h
--- gdb/ada-lang.h 1 Jul 2004 10:11:11 -0000 1.10
+++ gdb/ada-lang.h 18 Sep 2004 22:04:54 -0000
@@ -160,18 +160,6 @@ struct task_entry
int stack_per;
};
-extern struct type *builtin_type_ada_int;
-extern struct type *builtin_type_ada_short;
-extern struct type *builtin_type_ada_long;
-extern struct type *builtin_type_ada_long_long;
-extern struct type *builtin_type_ada_char;
-extern struct type *builtin_type_ada_float;
-extern struct type *builtin_type_ada_double;
-extern struct type *builtin_type_ada_long_double;
-extern struct type *builtin_type_ada_natural;
-extern struct type *builtin_type_ada_positive;
-extern struct type *builtin_type_ada_system_address;
-
/* The maximum number of tasks known to the Ada runtime. */
extern const int MAX_NUMBER_OF_KNOWN_TASKS;
Index: gdb/ada-lex.l
===================================================================
RCS file: /cvs/src/src/gdb/ada-lex.l,v
retrieving revision 1.6
diff -u -p -r1.6 ada-lex.l
--- gdb/ada-lex.l 28 Jul 2004 15:49:03 -0000 1.6
+++ gdb/ada-lex.l 18 Sep 2004 22:04:54 -0000
@@ -144,14 +144,14 @@ static int find_dot_all (const char *);
}
<INITIAL>"'"({GRAPHIC}|\")"'" {
- yylval.typed_val.type = builtin_type_ada_char;
+ yylval.typed_val.type = type_char ();
yylval.typed_val.val = yytext[1];
return CHARLIT;
}
<INITIAL>"'[\""{HEXDIG}{2}"\"]'" {
int v;
- yylval.typed_val.type = builtin_type_ada_char;
+ yylval.typed_val.type = type_char ();
sscanf (yytext+3, "%2x", &v);
yylval.typed_val.val = v;
return CHARLIT;
@@ -478,9 +478,9 @@ processInt (const char *base0, const cha
}
if ((result >> (TARGET_INT_BIT-1)) == 0)
- yylval.typed_val.type = builtin_type_ada_int;
+ yylval.typed_val.type = type_int ();
else if ((result >> (TARGET_LONG_BIT-1)) == 0)
- yylval.typed_val.type = builtin_type_ada_long;
+ yylval.typed_val.type = type_long ();
else if (((result >> (TARGET_LONG_BIT-1)) >> 1) == 0)
{
/* We have a number representable as an unsigned integer quantity.
@@ -500,7 +500,7 @@ processInt (const char *base0, const cha
return INT;
}
else
- yylval.typed_val.type = builtin_type_ada_long_long;
+ yylval.typed_val.type = type_long_long ();
yylval.typed_val.val = (LONGEST) result;
return INT;
@@ -527,11 +527,11 @@ processReal (const char *num0)
yylval.typed_val_float.dval = temp;
}
- yylval.typed_val_float.type = builtin_type_ada_float;
+ yylval.typed_val_float.type = type_float ();
if (sizeof(DOUBLEST) >= TARGET_DOUBLE_BIT / TARGET_CHAR_BIT)
- yylval.typed_val_float.type = builtin_type_ada_double;
+ yylval.typed_val_float.type = type_double ();
if (sizeof(DOUBLEST) >= TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT)
- yylval.typed_val_float.type = builtin_type_ada_long_double;
+ yylval.typed_val_float.type = type_long_double ();
return FLOAT;
}
@@ -745,7 +745,7 @@ name_lookup (char *name0, char *err_name
current_gdbarch,
name);
if (type == NULL && strcmp ("system__address", name) == 0)
- type = builtin_type_ada_system_address;
+ type = type_system_address ();
if (type != NULL)
{
/* First check to see if we have a regular definition of this
Index: gdb/ada-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-typeprint.c,v
retrieving revision 1.7
diff -u -p -r1.7 ada-typeprint.c
--- gdb/ada-typeprint.c 2 Jun 2004 09:55:36 -0000 1.7
+++ gdb/ada-typeprint.c 18 Sep 2004 22:04:54 -0000
@@ -149,7 +149,7 @@ print_range (struct type *type, struct u
case TYPE_CODE_ENUM:
break;
default:
- target_type = builtin_type_ada_int;
+ target_type = builtin_type_int;
break;
}