File indexing completed on 2025-02-21 10:05:26
0001
0002
0003
0004
0005 #ifndef INCLUDE_SOURCE_LOCATION_H_
0006 #define INCLUDE_SOURCE_LOCATION_H_
0007
0008 #include <cstddef>
0009 #include <string>
0010
0011 #include "v8config.h" // NOLINT(build/include_directory)
0012
0013 #if defined(__has_builtin)
0014 #define V8_SUPPORTS_SOURCE_LOCATION \
0015 (__has_builtin(__builtin_FUNCTION) && __has_builtin(__builtin_FILE) && \
0016 __has_builtin(__builtin_LINE))
0017 #elif defined(V8_CC_GNU) && __GNUC__ >= 7
0018 #define V8_SUPPORTS_SOURCE_LOCATION 1
0019 #elif defined(V8_CC_INTEL) && __ICC >= 1800
0020 #define V8_SUPPORTS_SOURCE_LOCATION 1
0021 #else
0022 #define V8_SUPPORTS_SOURCE_LOCATION 0
0023 #endif
0024
0025 namespace v8 {
0026
0027
0028
0029
0030
0031 class V8_EXPORT SourceLocation final {
0032 public:
0033
0034
0035
0036
0037 #if V8_SUPPORTS_SOURCE_LOCATION
0038 static constexpr SourceLocation Current(
0039 const char* function = __builtin_FUNCTION(),
0040 const char* file = __builtin_FILE(), size_t line = __builtin_LINE()) {
0041 return SourceLocation(function, file, line);
0042 }
0043 #else
0044 static constexpr SourceLocation Current() { return SourceLocation(); }
0045 #endif
0046
0047
0048
0049
0050 constexpr SourceLocation() = default;
0051
0052
0053
0054
0055
0056
0057
0058 constexpr const char* Function() const { return function_; }
0059
0060
0061
0062
0063
0064
0065 constexpr const char* FileName() const { return file_; }
0066
0067
0068
0069
0070
0071
0072 constexpr size_t Line() const { return line_; }
0073
0074
0075
0076
0077
0078
0079 std::string ToString() const;
0080
0081 private:
0082 constexpr SourceLocation(const char* function, const char* file, size_t line)
0083 : function_(function), file_(file), line_(line) {}
0084
0085 const char* function_ = nullptr;
0086 const char* file_ = nullptr;
0087 size_t line_ = 0u;
0088 };
0089
0090 }
0091
0092 #endif