Switch from llvm::errs()+exit() to FATAL_USER_ERROR() stream-based handling. (#670)

This is intended to:

- Standardize use of line_num (and highlight where no line_num is available).
- Standardize indications of runtime/compilation errors.
- Make it incrementally easier to write new errors.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
Jon Meow
2021-07-28 10:47:33 -07:00
committed by GitHub
co-authored by Chandler Carruth
parent dcc694c2e0
commit f0af3cb795
24 changed files with 206 additions and 170 deletions
+5 -5
View File
@@ -4,6 +4,7 @@
#include "executable_semantics/interpreter/heap.h"
#include "executable_semantics/common/error.h"
#include "llvm/ADT/StringExtras.h"
namespace Carbon {
@@ -33,9 +34,9 @@ void Heap::Write(const Address& a, const Value* v, int line_num) {
void Heap::CheckAlive(const Address& address, int line_num) {
if (!alive_[address.index]) {
llvm::errs() << line_num << ": undefined behavior: access to dead value "
<< *values_[address.index] << "\n";
exit(-1);
FATAL_RUNTIME_ERROR(line_num)
<< ": undefined behavior: access to dead value "
<< *values_[address.index];
}
}
@@ -44,8 +45,7 @@ void Heap::Deallocate(const Address& address) {
if (alive_[address.index]) {
alive_[address.index] = false;
} else {
llvm::errs() << "runtime error, deallocating an already dead value\n";
exit(-1);
FATAL_RUNTIME_ERROR_NO_LINE() << "deallocating an already dead value";
}
}