|
| 1 | +/* Copyright 2023 The TensorFlow Authors. All Rights Reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +==============================================================================*/ |
| 15 | +#ifndef TENSORFLOW_TSL_PLATFORM_DEFAULT_STATUS_H_ |
| 16 | +#define TENSORFLOW_TSL_PLATFORM_DEFAULT_STATUS_H_ |
| 17 | + |
| 18 | +#include "absl/status/status.h" |
| 19 | +#include "absl/strings/string_view.h" |
| 20 | +#include "absl/types/span.h" |
| 21 | +#include "tsl/platform/types.h" |
| 22 | +#include "tsl/protobuf/error_codes.pb.h" |
| 23 | + |
| 24 | +namespace tsl { |
| 25 | +#if ABSL_HAVE_BUILTIN(__builtin_LINE) && ABSL_HAVE_BUILTIN(__builtin_FILE) |
| 26 | +#define TF_INTERNAL_HAVE_BUILTIN_LINE_FILE 1 |
| 27 | +#endif |
| 28 | + |
| 29 | +class SourceLocationImpl { |
| 30 | + public: |
| 31 | + uint32_t line() const { return line_; } |
| 32 | + const char* file_name() const { return file_name_; } |
| 33 | + |
| 34 | +#ifdef TF_INTERNAL_HAVE_BUILTIN_LINE_FILE |
| 35 | + static SourceLocationImpl current(uint32_t line = __builtin_LINE(), |
| 36 | + const char* file_name = __builtin_FILE()) { |
| 37 | + return SourceLocationImpl(line, file_name); |
| 38 | + } |
| 39 | +#else |
| 40 | + static SourceLocationImpl current(uint32_t line = 0, |
| 41 | + const char* file_name = nullptr) { |
| 42 | + return SourceLocationImpl(line, file_name); |
| 43 | + } |
| 44 | +#endif |
| 45 | + private: |
| 46 | + SourceLocationImpl(uint32_t line, const char* file_name) |
| 47 | + : line_(line), file_name_(file_name) {} |
| 48 | + uint32_t line_; |
| 49 | + const char* file_name_; |
| 50 | +}; |
| 51 | + |
| 52 | +namespace internal { |
| 53 | + |
| 54 | +inline absl::Status MakeAbslStatus( |
| 55 | + ::tensorflow::error::Code code, absl::string_view message, |
| 56 | + absl::Span<const SourceLocationImpl>, |
| 57 | + SourceLocationImpl loc = SourceLocationImpl::current()) { |
| 58 | + return absl::Status(static_cast<absl::StatusCode>(code), message); |
| 59 | +} |
| 60 | + |
| 61 | +inline absl::Span<const SourceLocationImpl> GetSourceLocations( |
| 62 | + const absl::Status& status) { |
| 63 | + return {}; |
| 64 | +} |
| 65 | + |
| 66 | +} // namespace internal |
| 67 | + |
| 68 | +} // namespace tsl |
| 69 | + |
| 70 | +#endif // TENSORFLOW_TSL_PLATFORM_DEFAULT_STATUS_H_ |
0 commit comments