From 45531c73d9f28a2430b98958b45c4aab85f66261 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 2 Oct 2025 11:49:50 -0400 Subject: [PATCH 27/30] FIXME: C++ AST --- gcc/cp/name-lookup.cc | 1 + gcc/cp/parser.cc | 57 +++++++++++++++++++++++++++++++++++++++++++ gcc/cp/parser.h | 5 ++++ 3 files changed, 63 insertions(+) diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index b7fc43391cf..cbaedea9413 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ +#define INCLUDE_LIST #include "config.h" #include "system.h" #include "coretypes.h" diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 53fbb75b15a..cb1ce9276f6 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -20,7 +20,9 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "omp-selectors.h" +#define INCLUDE_LIST #define INCLUDE_STRING +#define INCLUDE_VECTOR #include "system.h" #include "coretypes.h" #include "cp-tree.h" @@ -51,6 +53,8 @@ along with GCC; see the file COPYING3. If not see #include "builtins.h" #include "contracts.h" #include "analyzer/analyzer-language.h" +#include "channels.h" +#include "topics/ast-events.h" /* The lexer. */ @@ -4791,6 +4795,9 @@ cp_parser_new (cp_lexer *lexer) /* We haven't yet seen an 'extern "C"'. */ parser->innermost_linkage_specification_location = UNKNOWN_LOCATION; + parser->ast_events_channel + = g->get_channels ().ast_events_channel.get_if_active (); + return parser; } @@ -5482,6 +5489,48 @@ finish_userdef_string_literal (tree literal) return error_mark_node; } +class auto_notify_ast_node +{ +public: + auto_notify_ast_node (cp_parser *parser, const char *kind) + : m_parser (parser), + m_kind (kind) + { + // FIXME: unlikely + // gengtype doesn't understand [[unlikely]] , and is it legal + // in c++14 anyway? + if (parser->ast_events_channel) + parser->ast_events_channel->publish + (gcc::topics::ast_events::begin_node {kind, get_next_loc ()}); + } + + ~auto_notify_ast_node () + { + // FIXME: unlikely + if (m_parser->ast_events_channel) + m_parser->ast_events_channel->publish + (gcc::topics::ast_events::end_node {m_kind, get_prev_loc ()}); + } + + location_t + get_next_loc () const + { + return cp_lexer_peek_token (m_parser->lexer)->location; + } + + location_t + get_prev_loc () const + { + if (const cp_token *tok = cp_lexer_safe_previous_token (m_parser->lexer)) + return tok->location; + return UNKNOWN_LOCATION; + } + +private: + cp_parser *const m_parser; + const char *const m_kind; +}; + /* Basic concepts [gram.basic] */ @@ -5515,6 +5564,10 @@ cp_parser_translation_unit (cp_parser* parser) bool implicit_extern_c = false; /* Parse until EOF. */ + // FIXME + { + auto_notify_ast_node sentinel (parser, "translation-unit"); + for (;;) { cp_token *token = cp_lexer_peek_token (parser->lexer); @@ -5611,6 +5664,7 @@ cp_parser_translation_unit (cp_parser* parser) false, true); parser->omp_begin_declare_variant_map = NULL; } + } #if ENABLE_ANALYZER if (flag_analyzer) @@ -22280,6 +22334,8 @@ cp_parser_type_specifier (cp_parser* parser, int* declares_class_or_enum, bool* is_cv_qualifier) { + auto_notify_ast_node sentinel (parser, "type-specifier"); + tree type_spec = NULL_TREE; cp_token *token; enum rid keyword; @@ -23747,6 +23803,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, static tree cp_parser_enum_specifier (cp_parser* parser) { + auto_notify_ast_node sentinel (parser, "enum-specifier"); tree identifier; tree type = NULL_TREE; tree prev_scope; diff --git a/gcc/cp/parser.h b/gcc/cp/parser.h index ddef98d900a..046ae03dc64 100644 --- a/gcc/cp/parser.h +++ b/gcc/cp/parser.h @@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "cp/cp-tree.h" #include "c-family/c-pragma.h" +#include "topics/ast-events.h" /* A token's value and its associated deferred access checks and qualifying scope. */ @@ -470,6 +471,10 @@ struct GTY(()) cp_parser { constructs that still need to be registered with their base functions. */ vec * omp_begin_declare_variant_map; + + // FIXME + const pub_sub::channel * GTY((skip)) + ast_events_channel; }; /* In parser.cc */ -- 2.49.0