3#include "slang/ast/Compilation.h"
4#include "slang/text/FormatBuffer.h"
5#include "slang/text/SourceLocation.h"
6#include "slang/text/SourceManager.h"
14#include <fmt/format.h>
22 SourceLocation location) {
23 if (location.buffer() != SourceLocation::NoLocation.buffer()) {
24 auto filename = compilation.getSourceManager()->getFileName(location);
25 auto line = compilation.getSourceManager()->getLineNumber(location);
26 auto column = compilation.getSourceManager()->getColumnNumber(location);
27 return fmt::format(
"{}:{}:{}", filename, line, column);
29 return std::string(
"?");
32 using Row = std::vector<std::string>;
47 const std::size_t cols = header.size();
50 std::vector<std::size_t> widths(cols);
52 for (std::size_t col = 0; col < cols; ++col) {
53 std::size_t max_width = header[col].size();
54 for (
const auto &row : rows) {
55 if (col < row.size()) {
56 max_width = std::max(max_width, row[col].size());
59 widths[col] = max_width;
62 auto appendRow = [&](
const Row &row) {
63 for (std::size_t col = 0; col < cols; ++col) {
64 std::string_view value;
65 if (col < row.size()) {
72 buffer.format(
"{:<{}}", value, widths[col]);
75 if (col + 1 < cols && cfg.padding > 0) {
76 buffer.format(
"{: >{}}",
"", cfg.padding);
83 for (
const auto &row : rows) {
Definition Utilities.hpp:16
Definition Utilities.hpp:18
std::vector< Row > Table
Definition Utilities.hpp:33
static auto locationStr(ast::Compilation const &compilation, SourceLocation location)
Return a string representation of a slang SourceLocation.
Definition Utilities.hpp:21
static auto formatTable(FormatBuffer &buffer, const Row &header, const Table &rows, TableFormatConfig cfg={})
Format a table of data into the given format buffer.
Definition Utilities.hpp:44
std::vector< std::string > Row
Definition Utilities.hpp:32