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
+3 -5
View File
@@ -6,7 +6,6 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
%{
#include <cstdlib>
#include <iostream>
#include "common/check.h"
#include "executable_semantics/common/tracing_flag.h"
@@ -215,11 +214,10 @@ operator and its operand, leading to three more cases:
if (Carbon::tracing_output) {
// Print a newline because tracing prints an incomplete line
// "Reading a token: ".
std::cerr << std::endl;
llvm::errs() << "\n";
}
std::cerr << context.current_token_position << ": invalid character '\\x"
<< llvm::toHex(llvm::StringRef(yytext, 1)) << "' in source file." << std::endl;
std::exit(1);
FATAL_COMPILATION_ERROR(yylineno) << "invalid character '\\x"
<< llvm::toHex(llvm::StringRef(yytext, 1)) << "' in source file.";
}
<<EOF>> {
+1 -1
View File
@@ -71,7 +71,7 @@ auto ParenContents<Term>::TupleElements(int line_num) const
result.push_back(TupleElement(*element.name, element.term));
} else {
if (seen_named_member) {
FATAL_USER_ERROR(line_num)
FATAL_PROGRAM_ERROR(line_num)
<< "positional members must come before named members";
}
result.push_back(TupleElement(std::to_string(i), element.term));
+2 -4
View File
@@ -4,8 +4,6 @@
#include "executable_semantics/syntax/parse.h"
#include <iostream>
#include "common/check.h"
#include "executable_semantics/common/error.h"
#include "executable_semantics/common/tracing_flag.h"
@@ -23,8 +21,8 @@ auto parse(const std::string& input_file_name)
-> std::variant<AST, SyntaxErrorCode> {
yyin = fopen(input_file_name.c_str(), "r");
if (yyin == nullptr) {
FATAL_USER_ERROR_NO_LINE() << "Error opening '" << input_file_name
<< "': " << std::strerror(errno);
FATAL_PROGRAM_ERROR_NO_LINE() << "Error opening '" << input_file_name
<< "': " << std::strerror(errno);
}
std::optional<AST> parsed_input = std::nullopt;
@@ -4,9 +4,6 @@
#include "executable_semantics/syntax/parse_and_lex_context.h"
#include <cstring>
#include <iostream>
// Writes a syntax error diagnostic, containing message, for the input file at
// the given line, to standard error.
auto Carbon::ParseAndLexContext::PrintDiagnostic(const std::string& message,
@@ -14,7 +11,5 @@ auto Carbon::ParseAndLexContext::PrintDiagnostic(const std::string& message,
// TODO: Do we really want this to be fatal? It makes the comment and the
// name a lie, and renders some of the other yyparse() result propagation code
// moot.
std::cerr << input_file_name << ":" << line_num << ": " << message
<< std::endl;
exit(-1);
FATAL_COMPILATION_ERROR(line_num) << message;
}
-1
View File
@@ -51,7 +51,6 @@
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <vector>