mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:10:13 +01:00
Protobufs code hits a warning with the latest system headers on macOS. I figured this may have been fixed so I updated protobufs and Bazel to the latest releases. This generally cleaned things up. However, it actually added *more* warnings. This clearly isn't a really well tested path. In fact, we already have a disabled warning that we'd like for Carbon code because LLVM isn't clean for that warning. So I've switched our warning strategy to a more durable approach of suppressing all warnings for external repository headers and source files. This lets us re-enable the missing warning and should fix the protobuf warning that started me down this twisty path. Sadly, we *have* to update to Bazel 6 in order to have the necessary flag to use this approach to suppressing warnings, so I couldn't do this as two PRs cleanly. =/ That's why I've bundled both the Bazel (and protobuf) updates with the warning strategy change. Last but not least, I've fixed several unused parameters in Carbon's code that our warnings now catch.
67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_EXPLORER_SYNTAX_PARSE_AND_LEX_CONTEXT_H_
|
|
#define CARBON_EXPLORER_SYNTAX_PARSE_AND_LEX_CONTEXT_H_
|
|
|
|
#include <variant>
|
|
|
|
#include "explorer/ast/ast.h"
|
|
#include "explorer/syntax/parser.h" // from parser.ypp
|
|
|
|
namespace Carbon {
|
|
|
|
// The state and functionality that is threaded "globally" through the
|
|
// lexing/parsing process.
|
|
class ParseAndLexContext {
|
|
public:
|
|
// Creates an instance analyzing the given input file.
|
|
ParseAndLexContext(Nonnull<const std::string*> input_file_name,
|
|
bool parser_debug)
|
|
: input_file_name_(input_file_name), parser_debug_(parser_debug) {}
|
|
|
|
// Formats ands records a lexing oor parsing error. Returns an error token as
|
|
// a convenience.
|
|
auto RecordSyntaxError(Error error) -> Parser::symbol_type;
|
|
auto RecordSyntaxError(const std::string& message) -> Parser::symbol_type;
|
|
|
|
auto source_loc() const -> SourceLocation {
|
|
return SourceLocation(input_file_name_,
|
|
static_cast<int>(current_token_position.begin.line));
|
|
}
|
|
|
|
auto parser_debug() const -> bool { return parser_debug_; }
|
|
|
|
// The source range of the token being (or just) lex'd.
|
|
location current_token_position;
|
|
|
|
auto take_errors() -> std::vector<Error> {
|
|
std::vector<Error> errors = std::move(errors_);
|
|
errors_.clear();
|
|
return errors;
|
|
}
|
|
|
|
private:
|
|
// A path to the file processed, relative to the current working directory
|
|
// when *this is called.
|
|
Nonnull<const std::string*> input_file_name_;
|
|
|
|
bool parser_debug_;
|
|
|
|
std::vector<Error> errors_;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
// Gives flex the yylex prototype we want.
|
|
#define YY_DECL \
|
|
auto yylex(Carbon::Nonnull<Carbon::Arena*> /*arena*/, yyscan_t yyscanner, \
|
|
Carbon::ParseAndLexContext& context) \
|
|
->Carbon::Parser::symbol_type
|
|
|
|
// Declares yylex for the parser's sake.
|
|
YY_DECL;
|
|
|
|
#endif // CARBON_EXPLORER_SYNTAX_PARSE_AND_LEX_CONTEXT_H_
|