From 29e128ed9434620b4f7d50979918667c705b0049 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 21 Mar 2026 18:14:01 +0000 Subject: [PATCH] Only warn about declaration after use once for each data object. --- net_scope.cc | 10 +++++++++- netlist.h | 1 + symbol_search.cc | 14 ++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/net_scope.cc b/net_scope.cc index 1efc464e6..d90b49b82 100644 --- a/net_scope.cc +++ b/net_scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2025 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com) * Copyright (c) 2016 CERN Michele Castellana (michele.castellana@cern.ch) * * This source code is free software; you can redistribute it @@ -462,6 +462,14 @@ unsigned NetScope::get_parameter_lexical_pos(perm_string key) const return 0; } +void NetScope::set_parameter_lexical_pos(perm_string key, unsigned lexical_pos) +{ + map::iterator idx; + + idx = parameters.find(key); + if (idx != parameters.end()) idx->second.lexical_pos = lexical_pos; +} + void NetScope::print_type(ostream&stream) const { switch (type_) { diff --git a/netlist.h b/netlist.h index 57b69959c..d1eb80764 100644 --- a/netlist.h +++ b/netlist.h @@ -1274,6 +1274,7 @@ class NetScope : public Definitions, public Attrib { LineInfo get_parameter_line_info(perm_string name) const; unsigned get_parameter_lexical_pos(perm_string name) const; + void set_parameter_lexical_pos(perm_string name, unsigned lexical_pos); /* Module instance arrays are collected here for access during the multiple elaboration passes. */ diff --git a/symbol_search.cc b/symbol_search.cc index 8e5d8b40a..91f34c22d 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2026 Stephen Williams (steve@icarus.com) * Copyright CERN 2012 / Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it @@ -175,6 +175,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, cerr << li->get_fileline() << ": warning: net `" << path_tail.name << "` used before declaration." << endl; + // suppress further warnings for this net + net->lexical_pos(lexical_pos); } return true; } else if (!res->decl_after_use) { @@ -193,6 +195,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, cerr << li->get_fileline() << ": warning: event `" << path_tail.name << "` used before declaration." << endl; + // suppress further warnings for this event + eve->lexical_pos(lexical_pos); } return true; } else if (!res->decl_after_use) { @@ -209,9 +213,11 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, res->par_val = par; res->path_head = path; if (warn_decl_after_use && decl_after_use) { - cerr << li->get_fileline() - << ": warning: parameter `" << path_tail.name - << "` used before declaration." << endl; + cerr << li->get_fileline() + << ": warning: parameter `" << path_tail.name + << "` used before declaration." << endl; + // suppress further warnings for this parameter + scope->set_parameter_lexical_pos(path_tail.name, lexical_pos); } return true; } else if (!res->decl_after_use) {