Migrate remaining exits to FATAL_*_ERROR calls (#704)

Adds FATAL for things that are most likely programming errors in executable_semantics.
This commit is contained in:
Jon Meow
2021-08-06 13:06:25 -07:00
committed by GitHub
parent 5749413b28
commit 2e9e4f4cb3
23 changed files with 99 additions and 150 deletions
+12 -33
View File
@@ -5,56 +5,35 @@
#ifndef EXECUTABLE_SEMANTICS_COMMON_ERROR_H_
#define EXECUTABLE_SEMANTICS_COMMON_ERROR_H_
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
#include "common/check.h"
namespace Carbon {
namespace ErrorInternal {
// An error-printing stream that exits on destruction.
class ExitingStream {
public:
// Ends the error with a newline and exits.
LLVM_ATTRIBUTE_NORETURN virtual ~ExitingStream() {
llvm::errs() << "\n";
exit(-1);
}
// Forward output to llvm::errs.
template <typename T>
ExitingStream& operator<<(const T& message) {
llvm::errs() << message;
return *this;
}
};
} // namespace ErrorInternal
// Prints an error and exits. This should be used for non-recoverable errors
// with user input.
//
// For example:
// FATAL_USER_ERROR(line_num) << "Line is bad!";
// FATAL_USER_ERROR_NO_LINE() << "Application is bad!";
// FATAL_PROGRAM_ERROR(line_num) << "Line is bad!";
// FATAL_PROGRAM_ERROR_NO_LINE() << "Application is bad!";
//
// Where possible, try to identify the error as a compilation error or runtime
// error. The generic user error option is provided as a fallback for cases that
// don't fit either of those classifications.
// Where possible, try to identify the error as a compilation or
// runtime error. Use CHECK/FATAL for internal errors. The generic program error
// option is provided as a fallback for cases that don't fit those
// classifications.
#define FATAL_USER_ERROR_NO_LINE() ErrorInternal::ExitingStream() << "ERROR: "
#define FATAL_PROGRAM_ERROR_NO_LINE() \
Carbon::ExitingStream() << "PROGRAM ERROR: "
#define FATAL_USER_ERROR(line) FATAL_USER_ERROR_NO_LINE() << line << ": "
#define FATAL_PROGRAM_ERROR(line) FATAL_PROGRAM_ERROR_NO_LINE() << line << ": "
#define FATAL_COMPILATION_ERROR_NO_LINE() \
ErrorInternal::ExitingStream() << "COMPILATION ERROR: "
Carbon::ExitingStream() << "COMPILATION ERROR: "
#define FATAL_COMPILATION_ERROR(line) \
FATAL_COMPILATION_ERROR_NO_LINE() << line << ": "
#define FATAL_RUNTIME_ERROR_NO_LINE() \
ErrorInternal::ExitingStream() << "RUNTIME ERROR: "
Carbon::ExitingStream() << "RUNTIME ERROR: "
#define FATAL_RUNTIME_ERROR(line) FATAL_RUNTIME_ERROR_NO_LINE() << line << ": "