Commit 0472f8c1 authored by Hans Wennborg's avatar Hans Wennborg Committed by Commit Bot

[base] Move NOTREACHED() and NOTIMPLEMENTED() to notreached.h

This removes the dependency on the large logging.h header for code
that just wants to use these macros.

Bug: 1031540
Change-Id: Iead12cd42ab634abc0ca442a0716999536d83ad6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161035Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762055}
parent ca3e0258
...@@ -431,6 +431,8 @@ jumbo_component("base") { ...@@ -431,6 +431,8 @@ jumbo_component("base") {
"native_library.cc", "native_library.cc",
"native_library.h", "native_library.h",
"no_destructor.h", "no_destructor.h",
"notreached.cc",
"notreached.h",
"observer_list.h", "observer_list.h",
"observer_list_internal.cc", "observer_list_internal.cc",
"observer_list_internal.h", "observer_list_internal.h",
......
...@@ -84,6 +84,18 @@ CheckError CheckError::DPCheck(const char* file, ...@@ -84,6 +84,18 @@ CheckError CheckError::DPCheck(const char* file,
return check_error; return check_error;
} }
CheckError CheckError::NotImplemented(const char* file,
int line,
const char* function) {
CheckError check_error(new LogMessage(file, line, LOG_ERROR));
if (function) {
check_error.stream() << "Not implemented reached in " << function;
} else {
check_error.stream() << "NOT IMPLEMENTED";
}
return check_error;
}
std::ostream& CheckError::stream() { std::ostream& CheckError::stream() {
return log_message_->stream(); return log_message_->stream();
} }
......
...@@ -77,6 +77,10 @@ class BASE_EXPORT CheckError { ...@@ -77,6 +77,10 @@ class BASE_EXPORT CheckError {
static CheckError DPCheck(const char* file, int line, const char* condition); static CheckError DPCheck(const char* file, int line, const char* condition);
static CheckError NotImplemented(const char* file,
int line,
const char* function);
// Stream for adding optional details to the error message. // Stream for adding optional details to the error message.
std::ostream& stream(); std::ostream& stream();
......
...@@ -1139,11 +1139,6 @@ std::wstring GetLogFileFullPath() { ...@@ -1139,11 +1139,6 @@ std::wstring GetLogFileFullPath() {
} }
#endif #endif
BASE_EXPORT void LogErrorNotReached(const char* file, int line) {
LogMessage(file, line, LOG_ERROR).stream()
<< "NOTREACHED() hit.";
}
} // namespace logging } // namespace logging
std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) {
......
...@@ -17,11 +17,10 @@ ...@@ -17,11 +17,10 @@
#include "base/check.h" #include "base/check.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/logging_buildflags.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/notreached.h"
#include "base/scoped_clear_last_error.h" #include "base/scoped_clear_last_error.h"
#include "base/strings/string_piece_forward.h" #include "base/strings/string_piece_forward.h"
#include "build/build_config.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include <cstdio> #include <cstdio>
...@@ -545,17 +544,6 @@ const LogSeverity LOG_DCHECK = LOG_FATAL; ...@@ -545,17 +544,6 @@ const LogSeverity LOG_DCHECK = LOG_FATAL;
#endif // DCHECK_IS_ON() #endif // DCHECK_IS_ON()
#if BUILDFLAG(ENABLE_LOG_ERROR_NOT_REACHED)
// Implement logging of NOTREACHED() as a dedicated function to get function
// call overhead down to a minimum.
void LogErrorNotReached(const char* file, int line);
#define NOTREACHED() \
true ? ::logging::LogErrorNotReached(__FILE__, __LINE__) \
: EAT_STREAM_PARAMETERS
#else
#define NOTREACHED() DCHECK(false)
#endif
// Redefine the standard assert to use our nice log files // Redefine the standard assert to use our nice log files
#undef assert #undef assert
#define assert(x) DLOG_ASSERT(x) #define assert(x) DLOG_ASSERT(x)
...@@ -713,25 +701,4 @@ inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) { ...@@ -713,25 +701,4 @@ inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) {
} }
} // namespace std } // namespace std
// The NOTIMPLEMENTED() macro annotates codepaths which have not been
// implemented yet. If output spam is a serious concern,
// NOTIMPLEMENTED_LOG_ONCE can be used.
#if defined(COMPILER_GCC)
// On Linux, with GCC, we can use __PRETTY_FUNCTION__ to get the demangled name
// of the current function in the NOTIMPLEMENTED message.
#define NOTIMPLEMENTED_MSG "Not implemented reached in " << __PRETTY_FUNCTION__
#else
#define NOTIMPLEMENTED_MSG "NOT IMPLEMENTED"
#endif
#define NOTIMPLEMENTED() DLOG(ERROR) << NOTIMPLEMENTED_MSG
#define NOTIMPLEMENTED_LOG_ONCE() \
do { \
static bool logged_once = false; \
DLOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG; \
logged_once = true; \
} while (0); \
EAT_STREAM_PARAMETERS
#endif // BASE_LOGGING_H_ #endif // BASE_LOGGING_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/notreached.h"
// This is a widely included header and its size has significant impact on
// build time. Try not to raise this limit unless absolutely necessary. See
// https://chromium.googlesource.com/chromium/src/+/HEAD/docs/wmax_tokens.md
#ifndef NACL_TC_REV
#pragma clang max_tokens_here 17000
#endif
#include "base/logging.h"
namespace logging {
BASE_EXPORT void LogErrorNotReached(const char* file, int line) {
LogMessage(file, line, LOG_ERROR).stream() << "NOTREACHED() hit.";
}
} // namespace logging
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_NOTREACHED_H_
#define BASE_NOTREACHED_H_
#include "base/check.h"
#include "base/logging_buildflags.h"
#include "build/build_config.h"
namespace logging {
#if BUILDFLAG(ENABLE_LOG_ERROR_NOT_REACHED)
void BASE_EXPORT LogErrorNotReached(const char* file, int line);
#define NOTREACHED() \
true ? ::logging::LogErrorNotReached(__FILE__, __LINE__) \
: EAT_CHECK_STREAM_PARAMS()
#else
#define NOTREACHED() DCHECK(false)
#endif
// The NOTIMPLEMENTED() macro annotates codepaths which have not been
// implemented yet. If output spam is a serious concern,
// NOTIMPLEMENTED_LOG_ONCE can be used.
#if DCHECK_IS_ON()
#if defined(COMPILER_GCC)
#define NOTIMPLEMENTED() \
::logging::CheckError::NotImplemented(__FILE__, __LINE__, \
__PRETTY_FUNCTION__) \
.stream()
#else
#define NOTIMPLEMENTED() \
::logging::CheckError::NotImplemented(__FILE__, __LINE__, nullptr).stream()
#endif
#else
#define NOTIMPLEMENTED() EAT_CHECK_STREAM_PARAMS()
#endif
#define NOTIMPLEMENTED_LOG_ONCE() \
{ \
static bool logged_once = false; \
if (!logged_once) { \
NOTIMPLEMENTED(); \
logged_once = true; \
} \
} \
EAT_CHECK_STREAM_PARAMS()
} // namespace logging
#endif // BASE_NOTREACHED_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment