Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
asl committed May 27, 2024
1 parent c2f0149 commit 4f8e5ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
8 changes: 2 additions & 6 deletions ir/visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,13 @@ class Visitor {
/// Static version of the above function, which can be called
/// even if not directly in a visitor
static bool warning_enabled(const Visitor *visitor, int warning_kind);
template <class T,
typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void warn(const int kind, const char *format, const T *node, Args &&...args) {
if (warning_enabled(kind)) ::warning(kind, format, node, std::forward<Args>(args)...);
}

/// The const ref variant of the above
template <class T,
typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void warn(const int kind, const char *format, const T &node, Args &&...args) {
if (warning_enabled(kind)) ::warning(kind, format, node, std::forward<Args>(args)...);
}
Expand Down
27 changes: 9 additions & 18 deletions lib/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,15 @@ inline void error(const char *format, Args &&...args) {

/// Report errors of type kind. Requires that the node argument have source info.
/// The message format is declared in the error catalog.
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void error(const int kind, const char *format, const T *node, Args &&...args) {
auto &context = BaseCompileContext::get();
auto action = context.getDefaultErrorDiagnosticAction();
context.errorReporter().diagnose(action, kind, format, "", node, std::forward<Args>(args)...);
}

/// This is similar to the above method, but also has a suffix
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void errorWithSuffix(const int kind, const char *format, const char *suffix, const T *node,
Args &&...args) {
auto &context = BaseCompileContext::get();
Expand All @@ -73,8 +71,7 @@ void errorWithSuffix(const int kind, const char *format, const char *suffix, con
}

/// The const ref variant of the above
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void error(const int kind, const char *format, const T &node, Args &&...args) {
error(kind, format, &node, std::forward<Args>(args)...);
}
Expand All @@ -84,16 +81,14 @@ void error(const int kind, const char *format, const T &node, Args &&...args) {
/// This allows incremental migration toward minimizing the number of errors and warnings
/// reported when passes are repeated, as typed errors are filtered.
// LEGACY: once we transition to error types, this should be deprecated
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void error(const char *format, const T *node, Args &&...args) {
error(ErrorType::LEGACY_ERROR, format, node, std::forward<Args>(args)...);
}

/// The const ref variant of the above
// LEGACY: once we transition to error types, this should be deprecated
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void error(const char *format, const T &node, Args &&...args) {
error(ErrorType::LEGACY_ERROR, format, node, std::forward<Args>(args)...);
}
Expand All @@ -119,17 +114,15 @@ inline void warning(const char *format, Args &&...args) {
#endif

/// Report warnings of type kind. Requires that the node argument have source info.
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void warning(const int kind, const char *format, const T *node, Args &&...args) {
auto &context = BaseCompileContext::get();
auto action = context.getDefaultWarningDiagnosticAction();
context.errorReporter().diagnose(action, kind, format, "", node, std::forward<Args>(args)...);
}

/// The const ref variant of the above
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void warning(const int kind, const char *format, const T &node, Args &&...args) {
::warning(kind, format, &node, std::forward<Args>(args)...);
}
Expand All @@ -144,17 +137,15 @@ void warning(const int kind, const char *format, Args &&...args) {
}

/// Report info messages of type kind. Requires that the node argument have source info.
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void info(const int kind, const char *format, const T *node, Args &&...args) {
auto &context = BaseCompileContext::get();
auto action = context.getDefaultInfoDiagnosticAction();
context.errorReporter().diagnose(action, kind, format, "", node, std::forward<Args>(args)...);
}

/// The const ref variant of the above
template <class T, typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
class... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void info(const int kind, const char *format, const T &node, Args &&...args) {
::info(kind, format, &node, std::forward<Args>(args)...);
}
Expand Down
9 changes: 2 additions & 7 deletions lib/error_reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ limitations under the License.
#include <boost/format.hpp>

#include "absl/strings/str_format.h"

#include "bug_helper.h"
#include "error_catalog.h"
#include "error_helper.h"
Expand Down Expand Up @@ -109,9 +108,7 @@ class ErrorReporter {
return ::error_helper(fmt, std::forward<Args>(args)...).toString();
}

template <class T,
typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
typename... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, typename... Args>
void diagnose(DiagnosticAction action, const int errorCode, const char *format,
const char *suffix, const T *node, Args &&...args) {
if (node && !error_reported(errorCode, node->getSourceInfo())) {
Expand All @@ -124,9 +121,7 @@ class ErrorReporter {
}
}

template <class T,
typename = typename std::enable_if_t<std::is_base_of_v<Util::IHasSourceInfo, T>>,
typename... Args>
template <class T, typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, typename... Args>
void diagnose(DiagnosticAction action, const int errorCode, const char *format,
const char *suffix, const T &node, Args &&...args) {
diagnose(action, errorCode, format, suffix, &node, std::forward<Args>(args)...);
Expand Down

0 comments on commit 4f8e5ac

Please sign in to comment.