From 50c5956187aa26b9e623f020c5eb6a042e4e1a79 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 8 Aug 2025 13:00:39 +0200 Subject: [PATCH] ast: refactor --- frontends/ast/ast.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc index 92f5fafdd..ec14ed5f9 100644 --- a/frontends/ast/ast.cc +++ b/frontends/ast/ast.cc @@ -190,11 +190,11 @@ bool AstNode::get_bool_attribute(RTLIL::IdString id) if (attributes.count(id) == 0) return false; - AstNode& attr = *(attributes.at(id)); - if (attr.type != AST_CONSTANT) - attr.input_error("Attribute `%s' with non-constant value!\n", id.c_str()); + auto& attr = attributes.at(id); + if (attr->type != AST_CONSTANT) + attr->input_error("Attribute `%s' with non-constant value!\n", id.c_str()); - return attr.integer != 0; + return attr->integer != 0; } // create new node (AstNode constructor) @@ -1093,7 +1093,7 @@ void AST::set_src_attr(RTLIL::AttrObject *obj, const AstNode *ast) obj->attributes[ID::src] = ast->loc_string(); } -static bool param_has_no_default(const std::unique_ptr ¶m) { +static bool param_has_no_default(const AstNode* param) { const auto &children = param->children; log_assert(param->type == AST_PARAMETER); log_assert(children.size() <= 2); @@ -1141,7 +1141,7 @@ static RTLIL::Module *process_module(RTLIL::Design *design, AstNode *ast, bool d if (!defer) { for (auto& node : ast->children) - if (node->type == AST_PARAMETER && param_has_no_default(node)) + if (node->type == AST_PARAMETER && param_has_no_default(node.get())) node->input_error("Parameter `%s' has no default value and has not been overridden!\n", node->str.c_str()); bool blackbox_module = flag_lib; @@ -1429,7 +1429,7 @@ void AST::process(RTLIL::Design *design, AstNode *ast, bool nodisplay, bool dump bool defer_local = defer; if (!defer_local) for (const auto& node : child->children) - if (node->type == AST_PARAMETER && param_has_no_default(node)) + if (node->type == AST_PARAMETER && param_has_no_default(node.get())) { log("Deferring `%s' because it contains parameter(s) without defaults.\n", child->str.c_str()); defer_local = true; @@ -1849,7 +1849,7 @@ std::string AstModule::derive_common(RTLIL::Design *design, const dictchildren.insert(child->children.begin(), nullptr); if ((it->second.flags & RTLIL::CONST_FLAG_REAL) != 0) { child->children[0] = std::make_unique(loc, AST_REALVALUE);