Replace int lines with file-associated SourceLocations (#779)

Most interesting changes should be ast/source_location.h and syntax/parse_and_lex_context.h
This commit is contained in:
Jon Meow
2021-08-26 10:07:16 -07:00
committed by GitHub
parent 33daf64329
commit 3ec550a85f
46 changed files with 607 additions and 518 deletions
@@ -18,11 +18,15 @@ class ParseAndLexContext {
public:
// Creates an instance analyzing the given input file.
ParseAndLexContext(const std::string& input_file)
: input_file_name(input_file) {}
: input_file_name(global_arena->New<std::string>(input_file)) {}
// Writes a syntax error diagnostic, containing message, for the input file at
// the given line, to standard error.
auto PrintDiagnostic(const std::string& message, int line_number) -> void;
// Writes a syntax error diagnostic containing message to standard error.
auto PrintDiagnostic(const std::string& message) -> void;
auto SourceLoc() -> SourceLocation {
return SourceLocation(input_file_name,
static_cast<int>(current_token_position.begin.line));
}
// The source range of the token being (or just) lex'd.
location current_token_position;
@@ -30,7 +34,7 @@ class ParseAndLexContext {
private:
// A path to the file processed, relative to the current working directory
// when *this is called.
const std::string input_file_name;
Ptr<const std::string> input_file_name;
};
} // namespace Carbon