Use ui_file_as_string in gdb/compile/

Using ui_file_as_string would imply changing a few prototypes to pass
around source and object file names as std::string.  Instead of that,
wrap those two in a new class.  This ends up eliminating a small
wrinkle: get_new_file_names and compile_object_load have swapped
parameters.  The former takes "source, objfile", while the latter
takes "objfile, source".

gdb/ChangeLog:
2016-11-08  Pedro Alves  <palves@redhat.com>

	* c-lang.h (c_compute_program): Now returns std::string.
	* compile/compile-internal.h (class compile_file_names): New
	class.
	* compile/compile-object-load.c (compile_object_load): Replace
	object_file and source_file parameters with a compile_file_names
	parameter.  Adjust.
	* compile-object-load.h: Include "compile-internal.h".
	(compile_object_load): Replace object_file and source_file
	parameters with a compile_file_names parameter.
	* compile/compile-c-support.c (c_compute_program): Now returns a
	std::string.  Use ui_file_as_string.
	* compile/compile.c (get_new_file_names): Remove parameters and
	return a compile_file_names instead.
	(compile_to_object): Now returns a compile_file_names.  Use
	ui_file_as_string.
	(eval_compile_command): Use compile_file_names.
	* language.h (struct language_defn) <la_compute_program>: Now
	returns std::string.
This commit is contained in:
Pedro Alves 2016-11-08 15:26:46 +00:00
parent 3d8b0d9483
commit aaee65aea2
8 changed files with 122 additions and 86 deletions

View file

@ -326,7 +326,7 @@ generate_register_struct (struct ui_file *stream, struct gdbarch *gdbarch,
to the inferior when the expression was created, and EXPR_PC
indicates the value of $PC. */
char *
std::string
c_compute_program (struct compile_instance *inst,
const char *input,
struct gdbarch *gdbarch,
@ -334,7 +334,7 @@ c_compute_program (struct compile_instance *inst,
CORE_ADDR expr_pc)
{
struct ui_file *buf, *var_stream = NULL;
char *code;
std::string code;
struct cleanup *cleanup;
struct compile_c_instance *context = (struct compile_c_instance *) inst;
@ -435,7 +435,7 @@ c_compute_program (struct compile_instance *inst,
fputs_unfiltered ("}\n", buf);
add_code_footer (inst->scope, buf);
code = ui_file_xstrdup (buf, NULL);
code = ui_file_as_string (buf);
do_cleanups (cleanup);
return code;
}