mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Pass the flag instead of using a global. (#893)
Arguably missed in #769 Note, this is reminding me we have more class members to rename for `_`, but I felt it's best to use the new naming instead of adding more to clean up.
This commit is contained in:
@@ -43,7 +43,6 @@ cc_library(
|
||||
"//executable_semantics/ast:paren_contents",
|
||||
"//executable_semantics/common:arena",
|
||||
"//executable_semantics/common:error",
|
||||
"//executable_semantics/common:tracing_flag",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "common/check.h"
|
||||
#include "common/string_helpers.h"
|
||||
#include "executable_semantics/common/tracing_flag.h"
|
||||
#include "executable_semantics/syntax/parse_and_lex_context.h"
|
||||
#include "executable_semantics/syntax/parser.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
@@ -246,8 +245,8 @@ string_literal \"([^\\\"\n\v\f\r]|\\.)*\"
|
||||
CHECK(str.consume_front("\"") && str.consume_back("\""));
|
||||
std::optional<std::string> unescaped = Carbon::UnescapeStringLiteral(str);
|
||||
if (unescaped == std::nullopt) {
|
||||
if (Carbon::tracing_output) {
|
||||
// Print a newline because tracing prints an incomplete line
|
||||
if (context.trace()) {
|
||||
// Print a newline because trace prints an incomplete line
|
||||
// "Reading a token: ".
|
||||
llvm::errs() << "\n";
|
||||
}
|
||||
@@ -279,8 +278,8 @@ string_literal \"([^\\\"\n\v\f\r]|\\.)*\"
|
||||
}
|
||||
|
||||
. {
|
||||
if (Carbon::tracing_output) {
|
||||
// Print a newline because tracing prints an incomplete line
|
||||
if (context.trace()) {
|
||||
// Print a newline because trace prints an incomplete line
|
||||
// "Reading a token: ".
|
||||
llvm::errs() << "\n";
|
||||
}
|
||||
|
||||
@@ -6,15 +6,14 @@
|
||||
|
||||
#include "common/check.h"
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "executable_semantics/common/tracing_flag.h"
|
||||
#include "executable_semantics/syntax/lexer.h"
|
||||
#include "executable_semantics/syntax/parse_and_lex_context.h"
|
||||
#include "executable_semantics/syntax/parser.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto Parse(Nonnull<Arena*> arena, const std::string& input_file_name)
|
||||
-> std::variant<AST, SyntaxErrorCode> {
|
||||
auto Parse(Nonnull<Arena*> arena, const std::string& input_file_name,
|
||||
bool trace) -> std::variant<AST, SyntaxErrorCode> {
|
||||
FILE* input_file = fopen(input_file_name.c_str(), "r");
|
||||
if (input_file == nullptr) {
|
||||
FATAL_PROGRAM_ERROR_NO_LINE() << "Error opening '" << input_file_name
|
||||
@@ -28,11 +27,11 @@ auto Parse(Nonnull<Arena*> arena, const std::string& input_file_name)
|
||||
|
||||
// Prepare other parser arguments.
|
||||
std::optional<AST> ast = std::nullopt;
|
||||
ParseAndLexContext context(arena->New<std::string>(input_file_name));
|
||||
ParseAndLexContext context(arena->New<std::string>(input_file_name), trace);
|
||||
|
||||
// Do the parse.
|
||||
auto parser = Parser(arena, scanner, context, &ast);
|
||||
if (tracing_output) {
|
||||
if (trace) {
|
||||
parser.set_debug_level(1);
|
||||
}
|
||||
auto syntax_error_code = parser();
|
||||
|
||||
@@ -18,8 +18,8 @@ using SyntaxErrorCode = int;
|
||||
|
||||
// Returns the AST representing the contents of the named file, or an error code
|
||||
// if parsing fails. Allocations go into the provided arena.
|
||||
auto Parse(Nonnull<Arena*> arena, const std::string& input_file_name)
|
||||
-> std::variant<Carbon::AST, SyntaxErrorCode>;
|
||||
auto Parse(Nonnull<Arena*> arena, const std::string& input_file_name,
|
||||
bool trace) -> std::variant<Carbon::AST, SyntaxErrorCode>;
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Carbon {
|
||||
class ParseAndLexContext {
|
||||
public:
|
||||
// Creates an instance analyzing the given input file.
|
||||
ParseAndLexContext(Nonnull<const std::string*> input_file_name)
|
||||
: input_file_name(input_file_name) {}
|
||||
ParseAndLexContext(Nonnull<const std::string*> input_file_name, bool trace)
|
||||
: input_file_name(input_file_name), trace_(trace) {}
|
||||
|
||||
// Writes a syntax error diagnostic containing message to standard error.
|
||||
auto PrintDiagnostic(const std::string& message) -> void;
|
||||
@@ -28,6 +28,8 @@ class ParseAndLexContext {
|
||||
static_cast<int>(current_token_position.begin.line));
|
||||
}
|
||||
|
||||
auto trace() -> bool { return trace_; }
|
||||
|
||||
// The source range of the token being (or just) lex'd.
|
||||
location current_token_position;
|
||||
|
||||
@@ -35,6 +37,8 @@ class ParseAndLexContext {
|
||||
// A path to the file processed, relative to the current working directory
|
||||
// when *this is called.
|
||||
Nonnull<const std::string*> input_file_name;
|
||||
|
||||
bool trace_;
|
||||
};
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user