Skip to content

Commit

Permalink
fixed source_location
Browse files Browse the repository at this point in the history
  • Loading branch information
lamarrr committed Dec 26, 2023
1 parent 80be9bf commit bed3acd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 48 deletions.
8 changes: 4 additions & 4 deletions include/stx/panic/default.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ inline void panic_default(std::string_view info, std::string_view error_report,

std::fputs("' at function: '", stderr);

std::fputs(location.function_name(), stderr);
std::fputs(location.function, stderr);

std::fputs("' [", stderr);

std::fputs(location.file_name(), stderr);
std::fputs(location.file, stderr);

std::fputc(':', stderr);

auto line = location.line();
auto line = location.line;

if (line != 0)
{
Expand All @@ -104,7 +104,7 @@ inline void panic_default(std::string_view info, std::string_view error_report,

std::fputc(':', stderr);

auto column = location.column();
auto column = location.column;

if (column != 0)
{
Expand Down
58 changes: 14 additions & 44 deletions include/stx/source_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,73 +34,43 @@ struct [[nodiscard]] SourceLocation
#if STX_HAS_BUILTIN(FILE) || (defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L)
char const *file = __builtin_FILE(),
#elif defined(__FILE__)
char const *file = __FILE__,
char const *file = __FILE__,
#else
char const *file = "unknown",
char const *file = "unknown",
#endif

#if STX_HAS_BUILTIN(FUNCTION) || (defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L)
char const *function = __builtin_FUNCTION(),
#else
char const *function = "unknown",
char const *function = "unknown",
#endif

#if STX_HAS_BUILTIN(LINE) || (defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L)
uint_least32_t line = __builtin_LINE(),
#elif defined(__LINE__)
uint_least32_t line = __LINE__,
uint_least32_t line = __LINE__,
#else
uint_least32_t line = 0,
#endif

#if STX_HAS_BUILTIN(COLUMN) || (defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L)
uint_least32_t column = __builtin_COLUMN()
#else
uint_least32_t column = 0
uint_least32_t column = 0
#endif
)
{
SourceLocation loc{};
loc.line_ = line;
loc.column_ = column;
loc.file_ = file;
loc.function_ = function;
return loc;
return SourceLocation{
file,
function,
line,
column};
}

constexpr SourceLocation() :
line_{0}, column_{0}, file_{""}, function_{""}
{}

/// return the column number represented by this object
constexpr uint_least32_t column() const
{
return column_;
}

/// return the line number represented by this object
constexpr uint_least32_t line() const
{
return line_;
}

/// return the file name represented by this object
constexpr char const *file_name() const
{
return file_;
}

/// return the name of the function represented by this object, if any
constexpr char const *function_name() const
{
return function_;
}

private:
uint_least32_t line_;
uint_least32_t column_;
char const *file_;
char const *function_;
char const *file = "";
char const *function = "";
uint_least32_t line = 0;
uint_least32_t column = 0;
};

STX_END_NAMESPACE

0 comments on commit bed3acd

Please sign in to comment.