#include "diagnostic.h"
#include "stringpool.h"
+#include "context.h"
+#include "channels.h"
#include "analyzer/analyzer-language.h"
#include "analyzer/analyzer-logging.h"
#if ENABLE_ANALYZER
namespace ana {
-static vec<finish_translation_unit_callback>
- *finish_translation_unit_callbacks;
-
-void
-register_finish_translation_unit_callback (
- finish_translation_unit_callback callback)
-{
- if (!finish_translation_unit_callbacks)
- vec_alloc (finish_translation_unit_callbacks, 1);
- finish_translation_unit_callbacks->safe_push (callback);
-}
-
-static void
-run_callbacks (logger *logger, const translation_unit &tu)
-{
- for (auto const &cb : finish_translation_unit_callbacks)
- {
- cb (logger, tu);
- }
-}
/* Call into TU to try to find a value for NAME.
If found, stash its value within analyzer_stashed_constants. */
*global_dc->get_reference_printer ()));
stash_named_constants (the_logger.get_logger (), tu);
- run_callbacks (the_logger.get_logger (), tu);
+ if (auto chan = g->get_channels ().analyzer_events_channel.get_if_active ())
+ {
+ gcc::topics::analyzer_events::on_tu_finished msg {the_logger.get_logger (),
+ tu};
+ chan->publish (msg);
+ }
}
/* Lookup NAME in the named constants stashed when the frontend TU finished.
virtual tree lookup_global_var_by_id (tree id) const = 0;
};
-typedef void (*finish_translation_unit_callback)
- (logger *, const translation_unit &);
-void register_finish_translation_unit_callback (
- finish_translation_unit_callback callback);
-
/* Analyzer hook for frontends to call at the end of the TU. */
void on_finish_translation_unit (const translation_unit &tu);
class builtin_known_function;
class internal_known_function;
+class translation_unit;
+
/* Forward decls of functions. */
extern void dump_tree (pretty_printer *pp, tree t);
namespace analyzer_events {
+/* A message published by the analyzer when the frontend finishes
+ parsing the TU, to allow it to look up pertinent items using the FE's
+ name-resolution logic. */
+
+struct on_tu_finished
+{
+ ana::logger *m_logger;
+ const ana::translation_unit &m_tu;
+};
+
/* A message published by the analyzer as it starts up, intended for
subsystems/plugins that want to register additional functionality
within the analyzer. */
virtual ~subscriber () = default;
- virtual void on_message (const on_ana_init &) = 0;
+ virtual void on_message (const on_tu_finished &) {}
+ virtual void on_message (const on_ana_init &) {}
};
} // namespace gcc::topics::analyzer_events
class cpython_analyzer_events_subscriber : public analyzer_events::subscriber
{
public:
+ void
+ on_message (const analyzer_events::on_tu_finished &msg) final override
+ {
+ LOG_SCOPE (msg.m_logger);
+ stash_named_types (msg.m_logger, msg.m_tu);
+ stash_global_vars (msg.m_logger, msg.m_tu);
+ }
+
void
on_message (const analyzer_events::on_ana_init &m) final override
{
const char *plugin_name = plugin_info->base_name;
if (0)
inform (input_location, "got here; %qs", plugin_name);
- register_finish_translation_unit_callback (&stash_named_types);
- register_finish_translation_unit_callback (&stash_global_vars);
region_model::register_pop_frame_callback(pyobj_refcnt_checker);
g->get_channels ().analyzer_events_channel.add_subscriber (ana::cpython_sub);
#else