c_language_arch_info (gdbarch, lai);
}
- /* See language.h. */
- std::unique_ptr<compile_instance> get_compile_instance () const override
- {
- return c_get_compile_context ();
- }
-
- /* See language.h. */
- std::string compute_program (compile_instance *inst,
- const char *input,
- struct gdbarch *gdbarch,
- const struct block *expr_block,
- CORE_ADDR expr_pc) const override
- {
- return c_compute_program (inst, input, gdbarch, expr_block, expr_pc);
- }
-
/* See language.h. */
bool can_print_type_offsets () const override
return cp_lookup_transparent_type (name, flags);
}
- /* See language.h. */
- std::unique_ptr<compile_instance> get_compile_instance () const override
- {
- return cplus_get_compile_context ();
- }
-
- /* See language.h. */
- std::string compute_program (compile_instance *inst,
- const char *input,
- struct gdbarch *gdbarch,
- const struct block *expr_block,
- CORE_ADDR expr_pc) const override
- {
- return cplus_compute_program (inst, input, gdbarch, expr_block, expr_pc);
- }
-
/* See language.h. */
unsigned int search_name_hash (const char *name) const override
{
struct language_arch_info;
struct type_print_options;
struct parser_state;
-struct compile_instance;
#include "compile/compile.h"
#include "value.h"
extern int c_textual_element_type (struct type *, char);
-/* Create a new instance of the C compiler and return it. This
- function never returns NULL, but rather throws an exception on
- failure. This is suitable for use as the
- language_defn::get_compile_instance method. */
-
-extern std::unique_ptr<compile_instance> c_get_compile_context ();
-
-/* Create a new instance of the C++ compiler and return it. This
- function never returns NULL, but rather throws an exception on
- failure. This is suitable for use as the
- language_defn::get_compile_instance method. */
-
-extern std::unique_ptr<compile_instance> cplus_get_compile_context ();
-
-/* This takes the user-supplied text and returns a new bit of code to
- compile.
-
- This is used as the compute_program language method; see that
- for a description of the arguments. */
-
-extern std::string c_compute_program (compile_instance *inst,
- const char *input,
- struct gdbarch *gdbarch,
- const struct block *expr_block,
- CORE_ADDR expr_pc);
-
-/* This takes the user-supplied text and returns a new bit of code to compile.
-
- This is used as the compute_program language method; see that
- for a description of the arguments. */
-
-extern std::string cplus_compute_program (compile_instance *inst,
- const char *input,
- struct gdbarch *gdbarch,
- const struct block *expr_block,
- CORE_ADDR expr_pc);
-
/* Return the canonical form of the C symbol NAME. If NAME is already
canonical, return nullptr. */
std::string m_object_file;
};
+struct compile_instance;
+
+/* Create a new instance of the C compiler and return it. This
+ function never returns NULL, but rather throws an exception on
+ failure. This is suitable for use as the
+ language_defn::get_compile_instance method. */
+
+extern std::unique_ptr<compile_instance> c_get_compile_context ();
+
+/* Create a new instance of the C++ compiler and return it. This
+ function never returns NULL, but rather throws an exception on
+ failure. This is suitable for use as the
+ language_defn::get_compile_instance method. */
+
+extern std::unique_ptr<compile_instance> cplus_get_compile_context ();
+
+/* This takes the user-supplied text and returns a new bit of code to
+ compile.
+
+ This is used as the compute_program language method; see that
+ for a description of the arguments. */
+
+extern std::string c_compute_program (compile_instance *inst,
+ const char *input,
+ struct gdbarch *gdbarch,
+ const struct block *expr_block,
+ CORE_ADDR expr_pc);
+
+/* This takes the user-supplied text and returns a new bit of code to compile.
+
+ This is used as the compute_program language method; see that
+ for a description of the arguments. */
+
+extern std::string cplus_compute_program (compile_instance *inst,
+ const char *input,
+ struct gdbarch *gdbarch,
+ const struct block *expr_block,
+ CORE_ADDR expr_pc);
+
#endif /* GDB_COMPILE_COMPILE_INTERNAL_H */
gdb_puts (message, gdb_stderr);
}
+/* Helper for compile_to_object, to find the compile context
+ based on the current language. */
+static std::unique_ptr<compile_instance>
+get_language_compile_context ()
+{
+ switch (current_language->la_language)
+ {
+ case language_c:
+ return c_get_compile_context ();
+ case language_cplus:
+ return cplus_get_compile_context ();
+ default:
+ return {};
+ }
+}
+
+/* Helper for compile_to_object, to call the correct
+ compute_program based on the current language. */
+static std::string
+compute_program_language (compile_instance *inst, const char *input,
+ struct gdbarch *gdbarch,
+ const struct block *block,
+ CORE_ADDR pc)
+{
+ switch (current_language->la_language)
+ {
+ case language_c:
+ return c_compute_program (inst, input, gdbarch, block, pc);
+ case language_cplus:
+ return cplus_compute_program (inst, input, gdbarch, block, pc);
+ default:
+ gdb_assert_not_reached ("Unsupported language");
+ }
+}
+
/* Process the compilation request. On success it returns the object
and source file names. On an error condition, error () is
called. */
/* Set up instance and context for the compiler. */
std::unique_ptr<compile_instance> compiler
- = current_language->get_compile_instance ();
+ = get_language_compile_context ();
+
if (compiler == nullptr)
error (_("No compiler support for language %s."),
current_language->name ());
error (_("Neither a simple expression, or a multi-line specified."));
std::string code
- = current_language->compute_program (compiler.get (), input, gdbarch,
- expr_block, expr_pc);
+ = compute_program_language (compiler.get (), input, gdbarch,
+ expr_block, expr_pc);
if (compile_debug)
gdb_printf (gdb_stdlog, "debug output:\n\n%s", code.c_str ());
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
from the language_defn class. Matches with strncmp_iw. */
struct type_print_options;
struct lang_varobj_ops;
struct parser_state;
-class compile_instance;
struct completion_match_for_lcd;
class innermost_block_tracker;
symbol_name_matcher_ftype *get_symbol_name_matcher
(const lookup_name_info &lookup_name) const;
- /* If this language allows compilation from the gdb command line,
- then this method will return an instance of struct gcc_context
- appropriate to the language. If compilation for this language is
- generally supported, but something goes wrong then an exception
- is thrown. If compilation is not supported for this language
- then this method returns NULL. */
-
- virtual std::unique_ptr<compile_instance> get_compile_instance () const;
-
- /* This method must be overridden if 'get_compile_instance' is
- overridden.
-
- This takes the user-supplied text and returns a new bit of code
- to compile.
-
- INST is the compiler instance being used.
- INPUT is the user's input text.
- GDBARCH is the architecture to use.
- EXPR_BLOCK is the block in which the expression is being
- parsed.
- EXPR_PC is the PC at which the expression is being parsed. */
-
- virtual std::string compute_program (compile_instance *inst,
- const char *input,
- struct gdbarch *gdbarch,
- const struct block *expr_block,
- CORE_ADDR expr_pc) const
- {
- gdb_assert_not_reached ("language_defn::compute_program");
- }
-
/* Hash the given symbol search name. */
virtual unsigned int search_name_hash (const char *name) const;