aboutsummaryrefslogtreecommitdiff
path: root/libcc1/libcp1.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libcc1/libcp1.cc')
-rw-r--r--libcc1/libcp1.cc113
1 files changed, 22 insertions, 91 deletions
diff --git a/libcc1/libcp1.cc b/libcc1/libcp1.cc
index c57ac8c..6fb9fb4 100644
--- a/libcc1/libcp1.cc
+++ b/libcc1/libcp1.cc
@@ -36,75 +36,23 @@ along with GCC; see the file COPYING3. If not see
#include "libiberty.h"
#include "compiler-name.hh"
#include "compiler.hh"
-
-struct libcp1;
-
-class libcp1_connection;
+#include "gdbctx.hh"
// The C compiler context that we hand back to our caller.
-struct libcp1 : public gcc_cp_context
+struct libcp1 : public cc1_plugin::base_gdb_plugin<gcc_cp_context>
{
libcp1 (const gcc_base_vtable *, const gcc_cp_fe_vtable *);
- // A convenience function to print something.
- void print (const char *str)
- {
- this->print_function (this->print_datum, str);
- }
-
- std::unique_ptr<libcp1_connection> connection;
-
- gcc_cp_oracle_function *binding_oracle;
- gcc_cp_symbol_address_function *address_oracle;
- gcc_cp_enter_leave_user_expr_scope_function *enter_scope;
- gcc_cp_enter_leave_user_expr_scope_function *leave_scope;
- void *oracle_datum;
-
- void (*print_function) (void *datum, const char *message);
- void *print_datum;
-
- std::vector<std::string> args;
- std::string source_file;
-
- /* Non-zero as an equivalent to gcc driver option "-v". */
- bool verbose;
-
- std::unique_ptr<cc1_plugin::compiler> compilerp;
+ gcc_cp_oracle_function *binding_oracle = nullptr;
+ gcc_cp_symbol_address_function *address_oracle = nullptr;
+ gcc_cp_enter_leave_user_expr_scope_function *enter_scope = nullptr;
+ gcc_cp_enter_leave_user_expr_scope_function *leave_scope = nullptr;
+ void *oracle_datum = nullptr;
};
-// A local subclass of connection that holds a back-pointer to the
-// gcc_c_context object that we provide to our caller.
-class libcp1_connection : public cc1_plugin::connection
+libcp1::libcp1 (const gcc_base_vtable *v, const gcc_cp_fe_vtable *cv)
+ : cc1_plugin::base_gdb_plugin<gcc_cp_context> (v)
{
-public:
-
- libcp1_connection (int fd, int aux_fd, libcp1 *b)
- : connection (fd, aux_fd),
- back_ptr (b)
- {
- }
-
- void print (const char *buf) override
- {
- back_ptr->print (buf);
- }
-
- libcp1 *back_ptr;
-};
-
-libcp1::libcp1 (const gcc_base_vtable *v,
- const gcc_cp_fe_vtable *cv)
- : binding_oracle (NULL),
- address_oracle (NULL),
- oracle_datum (NULL),
- print_function (NULL),
- print_datum (NULL),
- args (),
- source_file (),
- verbose (false),
- compilerp (new cc1_plugin::compiler (verbose))
-{
- base.ops = v;
cp_ops = cv;
}
@@ -123,7 +71,7 @@ namespace {
enum gcc_cp_oracle_request request,
const char *identifier)
{
- libcp1 *self = ((libcp1_connection *) conn)->back_ptr;
+ libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr);
self->binding_oracle (self->oracle_datum, self, request, identifier);
return 1;
@@ -134,7 +82,7 @@ namespace {
gcc_address
cp_call_symbol_address (cc1_plugin::connection *conn, const char *identifier)
{
- libcp1 *self = ((libcp1_connection *) conn)->back_ptr;
+ libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr);
return self->address_oracle (self->oracle_datum, self, identifier);
}
@@ -142,7 +90,7 @@ namespace {
int
cp_call_enter_scope (cc1_plugin::connection *conn)
{
- libcp1 *self = ((libcp1_connection *) conn)->back_ptr;
+ libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr);
self->enter_scope (self->oracle_datum, self);
return 1;
@@ -151,7 +99,7 @@ namespace {
int
cp_call_leave_scope (cc1_plugin::connection *conn)
{
- libcp1 *self = ((libcp1_connection *) conn)->back_ptr;
+ libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr);
self->leave_scope (self->oracle_datum, self);
return 1;
@@ -177,40 +125,25 @@ set_callbacks (struct gcc_cp_context *s,
self->oracle_datum = datum;
}
-// Instances of this rpc<> template function are installed into the
-// "cp_vtable". These functions are parameterized by type and method
-// name and forward the call via the connection.
-
-template<typename R, const char *&NAME, typename... Arg>
-R rpc (struct gcc_cp_context *s, Arg... rest)
-{
- libcp1 *self = (libcp1 *) s;
- R result;
-
- if (!cc1_plugin::call (self->connection.get (), NAME, &result, rest...))
- return 0;
- return result;
-}
-
static const struct gcc_cp_fe_vtable cp_vtable =
{
GCC_CP_FE_VERSION_0,
set_callbacks,
#define GCC_METHOD0(R, N) \
- rpc<R, cc1_plugin::cp::N>,
+ cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N>,
#define GCC_METHOD1(R, N, A) \
- rpc<R, cc1_plugin::cp::N, A>,
+ cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A>,
#define GCC_METHOD2(R, N, A, B) \
- rpc<R, cc1_plugin::cp::N, A, B>,
+ cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B>,
#define GCC_METHOD3(R, N, A, B, C) \
- rpc<R, cc1_plugin::cp::N, A, B, C>,
+ cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C>,
#define GCC_METHOD4(R, N, A, B, C, D) \
- rpc<R, cc1_plugin::cp::N, A, B, C, D>,
+ cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D>,
#define GCC_METHOD5(R, N, A, B, C, D, E) \
- rpc<R, cc1_plugin::cp::N, A, B, C, D, E>,
+ cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D, E>,
#define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
- rpc<R, cc1_plugin::cp::N, A, B, C, D, E, F, G>,
+ cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D, E, F, G>,
#include "gcc-cp-fe.def"
@@ -230,9 +163,7 @@ libcp1_set_verbose (struct gcc_base_context *s, int /* bool */ verbose)
{
libcp1 *self = (libcp1 *) s;
- self->verbose = verbose != 0;
- if (self->compilerp != nullptr)
- self->compilerp->set_verbose (self->verbose);
+ self->set_verbose (verbose != 0);
}
static char *
@@ -409,7 +340,7 @@ libcp1_compile (struct gcc_base_context *s,
if (self->verbose)
self->args.push_back ("-v");
- self->connection.reset (new libcp1_connection (fds[0], stderr_fds[0], self));
+ self->set_connection (fds[0], stderr_fds[0]);
cc1_plugin::callback_ftype *fun
= cc1_plugin::callback<int,