diff options
author | Eric Feng <ef2648@columbia.edu> | 2023-08-02 16:54:55 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2023-08-02 16:58:58 -0400 |
commit | fafe2d18f791c6b97b49af7c84b1b5703681c3af (patch) | |
tree | 2024b0d26ed3b846b9b6958004081dcb5a7459ed /gcc/c/c-parser.cc | |
parent | 41ef5a34161356817807be3a2e51fbdbe575ae85 (diff) | |
download | gcc-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/c/c-parser.cc')
-rw-r--r-- | gcc/c/c-parser.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index cf82b03..025817f 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -1695,6 +1695,30 @@ public: return NULL_TREE; } + tree + lookup_type_by_id (tree id) const final override + { + if (tree type_decl = lookup_name (id)) + if (TREE_CODE (type_decl) == TYPE_DECL) + { + tree record_type = TREE_TYPE (type_decl); + if (TREE_CODE (record_type) == RECORD_TYPE) + return record_type; + } + + return NULL_TREE; + } + + tree + lookup_global_var_by_id (tree id) const final override + { + if (tree var_decl = lookup_name (id)) + if (TREE_CODE (var_decl) == VAR_DECL) + return var_decl; + + return NULL_TREE; + } + private: /* Attempt to get an INTEGER_CST from MACRO. Only handle the simplest cases: where MACRO's definition is a single |