aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer/analyzer-language.cc
diff options
context:
space:
mode:
authorEric Feng <ef2648@columbia.edu>2023-08-02 16:54:55 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2023-08-02 16:58:58 -0400
commitfafe2d18f791c6b97b49af7c84b1b5703681c3af (patch)
tree2024b0d26ed3b846b9b6958004081dcb5a7459ed /gcc/analyzer/analyzer-language.cc
parent41ef5a34161356817807be3a2e51fbdbe575ae85 (diff)
downloadgcc-fafe2d18f791c6b97b49af7c84b1b5703681c3af.zip
gcc-fafe2d18f791c6b97b49af7c84b1b5703681c3af.tar.gz
gcc-fafe2d18f791c6b97b49af7c84b1b5703681c3af.tar.bz2
analyzer: stash values for CPython plugin [PR107646]
This patch adds a hook to the end of ana::on_finish_translation_unit which calls relevant stashing-related callbacks registered during plugin initialization. This feature is used to stash named types and global variables for a CPython analyzer plugin [PR107646]. gcc/analyzer/ChangeLog: PR analyzer/107646 * analyzer-language.cc (run_callbacks): New function. (on_finish_translation_unit): New function. * analyzer-language.h (GCC_ANALYZER_LANGUAGE_H): New include. (class translation_unit): New vfuncs. gcc/c/ChangeLog: PR analyzer/107646 * c-parser.cc: New functions on stashing values for the analyzer. gcc/testsuite/ChangeLog: PR analyzer/107646 * gcc.dg/plugin/plugin.exp: Add new plugin and test. * gcc.dg/plugin/analyzer_cpython_plugin.c: New plugin. * gcc.dg/plugin/cpython-plugin-test-1.c: New test. Signed-off-by: Eric Feng <ef2648@columbia.edu>
Diffstat (limited to 'gcc/analyzer/analyzer-language.cc')
-rw-r--r--gcc/analyzer/analyzer-language.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/gcc/analyzer/analyzer-language.cc b/gcc/analyzer/analyzer-language.cc
index 2c891090..8540028 100644
--- a/gcc/analyzer/analyzer-language.cc
+++ b/gcc/analyzer/analyzer-language.cc
@@ -35,6 +35,26 @@ static GTY (()) hash_map <tree, tree> *analyzer_stashed_constants;
#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. */
@@ -102,6 +122,8 @@ on_finish_translation_unit (const translation_unit &tu)
the_logger.set_logger (new logger (logfile, 0, 0,
*global_dc->printer));
stash_named_constants (the_logger.get_logger (), tu);
+
+ run_callbacks (the_logger.get_logger (), tu);
}
/* Lookup NAME in the named constants stashed when the frontend TU finished.