3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-16 13:58:47 +00:00

log_help: Better location tracking

Assign root location in call to `PrettyHelp::get_current()`.
Set default `source_file` to `"unknown"`, since that appears to be the default value rather than `nullptr`.
This commit is contained in:
Krystine Sherwin 2025-03-21 10:26:10 +13:00
parent 4e88f86414
commit a0da79981b
No known key found for this signature in database
2 changed files with 13 additions and 10 deletions

View file

@ -25,7 +25,7 @@ Json ContentListing::to_json() {
Json::object object;
object["type"] = type;
if (body.length()) object["body"] = body;
if (source_file != nullptr) object["source_file"] = source_file;
if (strcmp(source_file, "unknown") != 0) object["source_file"] = source_file;
if (source_line != 0) object["source_line"] = source_line;
Json::array content_array;
for (auto child : content) content_array.push_back(child->to_json());
@ -84,12 +84,13 @@ PrettyHelp::~PrettyHelp()
current_help = _prior;
}
PrettyHelp *PrettyHelp::get_current()
PrettyHelp *PrettyHelp::get_current(source_location location)
{
if (current_help != nullptr)
return current_help;
else
return new PrettyHelp();
if (current_help == nullptr)
new PrettyHelp();
current_help->_root_listing.source_file = location.file_name();
current_help->_root_listing.source_line = location.line();
return current_help;
}
void PrettyHelp::usage(const string &usage,

View file

@ -30,8 +30,8 @@ using std::experimental::source_location;
struct source_location { // dummy placeholder
int line() const { return 0; }
int column() const { return 0; }
const char* file_name() const { return nullptr; }
const char* function_name() const { return nullptr; }
const char* file_name() const { return "unknown"; }
const char* function_name() const { return "unknown"; }
static const source_location current(...) { return source_location(); }
};
#endif
@ -41,7 +41,7 @@ YOSYS_NAMESPACE_BEGIN
struct ContentListing {
string type = "root";
string body = "";
const char* source_file = nullptr;
const char* source_file = "unknown";
int source_line = 0;
vector<ContentListing *> content = {};
ContentListing *parent = nullptr;
@ -94,7 +94,7 @@ public:
PrettyHelp(Mode mode = LOG);
~PrettyHelp();
static PrettyHelp *get_current();
static PrettyHelp *get_current(source_location location = source_location::current());
bool has_content() { return _root_listing.content.size();}
const vector<ContentListing *> get_content() {
@ -102,6 +102,8 @@ public:
return content;
}
const char* source_file() const { return _root_listing.source_file; }
void usage(
const string &usage,
const source_location location = source_location::current()