This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 2/3] Convert Rust to use discriminated unions


> This patch implements this idea by moving the current Rust enum
> handling code to dwarf2read.  This allows the simplification of some
> parts of rust-lang.c as well.

I'm actually wondering whether it make sense to move the "quirk"
functions to dwarf2read or not. This is just thinking out loud,
rather than a request: What do you think of having those functions
in rust-lang.c, and calling them from dwarf2read.c? Obviously,
the downside is that the function has to be non-static, but then
the rust-specific code rests in rust-lang, which you oversee...
(again, there is no obvious answer, and I am just wondering about
this option, so I will follow your preference).

> 2018-02-19  Tom Tromey  <tom@tromey.com>
> 
> 	* rust-lang.h (rust_last_path_segment): Declare.
> 	* rust-lang.c (rust_last_path_segment): Now public.  Change
> 	contract.
> 	(struct disr_info): Remove.
> 	(RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL)
> 	(RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged)
> 	(rust_get_disr_info, rust_tuple_variant_type_p): Remove.
> 	(rust_enum_p, rust_enum_variant): New function.
> 	(rust_underscore_fields): Remove "offset" parameter.
> 	(rust_print_enum): New function.
> 	(rust_val_print) <TYPE_CODE_UNION>: Remove enum code.
> 	<TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate.
> 	(rust_print_struct_def): Add "for_rust_enum" parameter.  Handle
> 	enums.
> 	(rust_internal_print_type): New function, from rust_print_type.
> 	Remove enum code.
> 	(rust_print_type): Call rust_internal_print_type.
> 	(rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>:
> 	Update enum handling.
> 	* dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field.
> 	(rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum)
> 	(rust_union_quirks): New functions.
> 	(process_full_comp_unit, process_full_type_unit): Call
> 	rust_union_quirks.
> 	(process_structure_scope): Update rust_unions if necessary.

One small suggestion. Otherwise, OK for me.

> +#define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
> +  if (TYPE_NFIELDS (type) == 1
> +      && strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX,
> +		  strlen (RUST_ENUM_PREFIX)) == 0)

I think you can use startswith, here?


-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]