Return unique_ptr from language_defn::get_compile_context
This changes language_defn::get_compile_context to return a unique_ptr. This makes the ownership transfer clear. gdb/ChangeLog 2021-02-05 Tom Tromey <tom@tromey.com> * compile/compile-c-support.c (get_compile_context) (c_get_compile_context, cplus_get_compile_context): Change return type. * language.c (language_defn::get_compile_instance): New method. * language.h (language_defn::get_compile_instance): Change return type. No longer inline. * c-lang.c (c_language::get_compile_instance): Change return type. (cplus_language::get_compile_instance): Change return type. * c-lang.h (c_get_compile_context, cplus_get_compile_context): Change return type. * compile/compile.c (compile_to_object): Update.
This commit is contained in:
parent
1b30f42106
commit
bdfea17ea9
@ -1,3 +1,17 @@
|
|||||||
|
2021-02-05 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* compile/compile-c-support.c (get_compile_context)
|
||||||
|
(c_get_compile_context, cplus_get_compile_context): Change return
|
||||||
|
type.
|
||||||
|
* language.c (language_defn::get_compile_instance): New method.
|
||||||
|
* language.h (language_defn::get_compile_instance): Change return
|
||||||
|
type. No longer inline.
|
||||||
|
* c-lang.c (c_language::get_compile_instance): Change return type.
|
||||||
|
(cplus_language::get_compile_instance): Change return type.
|
||||||
|
* c-lang.h (c_get_compile_context, cplus_get_compile_context):
|
||||||
|
Change return type.
|
||||||
|
* compile/compile.c (compile_to_object): Update.
|
||||||
|
|
||||||
2021-02-05 Tom Tromey <tom@tromey.com>
|
2021-02-05 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* parser-defs.h (write_exp_symbol_reference): Declare.
|
* parser-defs.h (write_exp_symbol_reference): Declare.
|
||||||
|
@ -36,8 +36,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "gdbcore.h"
|
#include "gdbcore.h"
|
||||||
#include "gdbarch.h"
|
#include "gdbarch.h"
|
||||||
|
#include "compile/compile-internal.h"
|
||||||
class compile_instance;
|
|
||||||
|
|
||||||
/* Given a C string type, STR_TYPE, return the corresponding target
|
/* Given a C string type, STR_TYPE, return the corresponding target
|
||||||
character set name. */
|
character set name. */
|
||||||
@ -888,7 +887,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* See language.h. */
|
/* See language.h. */
|
||||||
compile_instance *get_compile_instance () const override
|
std::unique_ptr<compile_instance> get_compile_instance () const override
|
||||||
{
|
{
|
||||||
return c_get_compile_context ();
|
return c_get_compile_context ();
|
||||||
}
|
}
|
||||||
@ -1021,7 +1020,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* See language.h. */
|
/* See language.h. */
|
||||||
compile_instance *get_compile_instance () const override
|
std::unique_ptr<compile_instance> get_compile_instance () const override
|
||||||
{
|
{
|
||||||
return cplus_get_compile_context ();
|
return cplus_get_compile_context ();
|
||||||
}
|
}
|
||||||
|
18
gdb/c-lang.h
18
gdb/c-lang.h
@ -147,21 +147,19 @@ extern bool c_is_string_type_p (struct type *type);
|
|||||||
|
|
||||||
extern int c_textual_element_type (struct type *, char);
|
extern int c_textual_element_type (struct type *, char);
|
||||||
|
|
||||||
/* Create a new instance of the C compiler and return it. The new
|
/* Create a new instance of the C compiler and return it. This
|
||||||
compiler is owned by the caller and must be freed using the destroy
|
function never returns NULL, but rather throws an exception on
|
||||||
method. This function never returns NULL, but rather throws an
|
failure. This is suitable for use as the
|
||||||
exception on failure. This is suitable for use as the
|
|
||||||
language_defn::get_compile_instance method. */
|
language_defn::get_compile_instance method. */
|
||||||
|
|
||||||
extern compile_instance *c_get_compile_context (void);
|
extern std::unique_ptr<compile_instance> c_get_compile_context ();
|
||||||
|
|
||||||
/* Create a new instance of the C++ compiler and return it. The new
|
/* Create a new instance of the C++ compiler and return it. This
|
||||||
compiler is owned by the caller and must be freed using the destroy
|
function never returns NULL, but rather throws an exception on
|
||||||
method. This function never returns NULL, but rather throws an
|
failure. This is suitable for use as the
|
||||||
exception on failure. This is suitable for use as the
|
|
||||||
language_defn::get_compile_instance method. */
|
language_defn::get_compile_instance method. */
|
||||||
|
|
||||||
extern compile_instance *cplus_get_compile_context ();
|
extern std::unique_ptr<compile_instance> cplus_get_compile_context ();
|
||||||
|
|
||||||
/* This takes the user-supplied text and returns a new bit of code to
|
/* This takes the user-supplied text and returns a new bit of code to
|
||||||
compile.
|
compile.
|
||||||
|
@ -99,7 +99,7 @@ load_libcompile (const char *fe_libcc, const char *fe_context)
|
|||||||
|
|
||||||
template <typename INSTTYPE, typename FUNCTYPE, typename CTXTYPE,
|
template <typename INSTTYPE, typename FUNCTYPE, typename CTXTYPE,
|
||||||
typename BASE_VERSION_TYPE, typename API_VERSION_TYPE>
|
typename BASE_VERSION_TYPE, typename API_VERSION_TYPE>
|
||||||
compile_instance *
|
std::unique_ptr<compile_instance>
|
||||||
get_compile_context (const char *fe_libcc, const char *fe_context,
|
get_compile_context (const char *fe_libcc, const char *fe_context,
|
||||||
BASE_VERSION_TYPE base_version,
|
BASE_VERSION_TYPE base_version,
|
||||||
API_VERSION_TYPE api_version)
|
API_VERSION_TYPE api_version)
|
||||||
@ -118,12 +118,12 @@ get_compile_context (const char *fe_libcc, const char *fe_context,
|
|||||||
error (_("The loaded version of GCC does not support the required version "
|
error (_("The loaded version of GCC does not support the required version "
|
||||||
"of the API."));
|
"of the API."));
|
||||||
|
|
||||||
return new INSTTYPE (context);
|
return std::unique_ptr<compile_instance> (new INSTTYPE (context));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A C-language implementation of get_compile_context. */
|
/* A C-language implementation of get_compile_context. */
|
||||||
|
|
||||||
compile_instance *
|
std::unique_ptr<compile_instance>
|
||||||
c_get_compile_context ()
|
c_get_compile_context ()
|
||||||
{
|
{
|
||||||
return get_compile_context
|
return get_compile_context
|
||||||
@ -135,7 +135,7 @@ c_get_compile_context ()
|
|||||||
|
|
||||||
/* A C++-language implementation of get_compile_context. */
|
/* A C++-language implementation of get_compile_context. */
|
||||||
|
|
||||||
compile_instance *
|
std::unique_ptr<compile_instance>
|
||||||
cplus_get_compile_context ()
|
cplus_get_compile_context ()
|
||||||
{
|
{
|
||||||
return get_compile_context
|
return get_compile_context
|
||||||
|
@ -649,8 +649,8 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
|
|||||||
expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
|
expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
|
||||||
|
|
||||||
/* Set up instance and context for the compiler. */
|
/* Set up instance and context for the compiler. */
|
||||||
std::unique_ptr <compile_instance> compiler
|
std::unique_ptr<compile_instance> compiler
|
||||||
(current_language->get_compile_instance ());
|
= current_language->get_compile_instance ();
|
||||||
if (compiler == nullptr)
|
if (compiler == nullptr)
|
||||||
error (_("No compiler support for language %s."),
|
error (_("No compiler support for language %s."),
|
||||||
current_language->name ());
|
current_language->name ());
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include "c-lang.h"
|
#include "c-lang.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "gdbarch.h"
|
#include "gdbarch.h"
|
||||||
|
#include "compile/compile-internal.h"
|
||||||
|
|
||||||
static void set_range_case (void);
|
static void set_range_case (void);
|
||||||
|
|
||||||
@ -704,6 +705,14 @@ language_defn::is_string_type_p (struct type *type) const
|
|||||||
return c_is_string_type_p (type);
|
return c_is_string_type_p (type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* See language.h. */
|
||||||
|
|
||||||
|
std::unique_ptr<compile_instance>
|
||||||
|
language_defn::get_compile_instance () const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
/* The default implementation of the get_symbol_name_matcher_inner method
|
/* The default implementation of the get_symbol_name_matcher_inner method
|
||||||
from the language_defn class. Matches with strncmp_iw. */
|
from the language_defn class. Matches with strncmp_iw. */
|
||||||
|
|
||||||
|
@ -374,18 +374,14 @@ struct language_defn
|
|||||||
symbol_name_matcher_ftype *get_symbol_name_matcher
|
symbol_name_matcher_ftype *get_symbol_name_matcher
|
||||||
(const lookup_name_info &lookup_name) const;
|
(const lookup_name_info &lookup_name) const;
|
||||||
|
|
||||||
/* If this language allows compilation from the gdb command line, then
|
/* If this language allows compilation from the gdb command line,
|
||||||
this method will return an instance of struct gcc_context appropriate
|
then this method will return an instance of struct gcc_context
|
||||||
to the language. If compilation for this language is generally
|
appropriate to the language. If compilation for this language is
|
||||||
supported, but something goes wrong then an exception is thrown. The
|
generally supported, but something goes wrong then an exception
|
||||||
returned compiler instance is owned by its caller and must be
|
is thrown. If compilation is not supported for this language
|
||||||
deallocated by the caller. If compilation is not supported for this
|
then this method returns NULL. */
|
||||||
language then this method returns NULL. */
|
|
||||||
|
|
||||||
virtual compile_instance *get_compile_instance () const
|
virtual std::unique_ptr<compile_instance> get_compile_instance () const;
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This method must be overridden if 'get_compile_instance' is
|
/* This method must be overridden if 'get_compile_instance' is
|
||||||
overridden.
|
overridden.
|
||||||
|
Loading…
Reference in New Issue
Block a user