Accessor renames on diagnostics+source buffer (#1133)

This commit is contained in:
Jon Meow
2022-03-15 15:43:53 -07:00
committed by GitHub
parent ad9c10da16
commit 7bbf4fbba3
7 changed files with 50 additions and 49 deletions
+12 -12
View File
@@ -573,7 +573,7 @@ auto TokenizedBuffer::Lex(SourceBuffer& source, DiagnosticConsumer& consumer)
ErrorTrackingDiagnosticConsumer error_tracking_consumer(consumer);
Lexer lexer(buffer, error_tracking_consumer);
llvm::StringRef source_text = source.Text();
llvm::StringRef source_text = source.text();
while (lexer.SkipWhitespace(source_text)) {
// Each time we find non-whitespace characters, try each kind of token we
// support lexing, from simplest to most complex.
@@ -599,7 +599,7 @@ auto TokenizedBuffer::Lex(SourceBuffer& source, DiagnosticConsumer& consumer)
lexer.CloseInvalidOpenGroups(TokenKind::Error());
lexer.AddEndOfFileToken();
if (error_tracking_consumer.SeenError()) {
if (error_tracking_consumer.seen_error()) {
buffer.has_errors_ = true;
}
@@ -632,7 +632,7 @@ auto TokenizedBuffer::GetTokenText(Token token) const -> llvm::StringRef {
if (token_info.kind == TokenKind::Error()) {
auto& line_info = GetLineInfo(token_info.token_line);
int64_t token_start = line_info.start + token_info.column;
return source_->Text().substr(token_start, token_info.error_length);
return source_->text().substr(token_start, token_info.error_length);
}
// Refer back to the source text to preserve oddities like radix or digit
@@ -642,7 +642,7 @@ auto TokenizedBuffer::GetTokenText(Token token) const -> llvm::StringRef {
auto& line_info = GetLineInfo(token_info.token_line);
int64_t token_start = line_info.start + token_info.column;
llvm::Optional<LexedNumericLiteral> relexed_token =
LexedNumericLiteral::Lex(source_->Text().substr(token_start));
LexedNumericLiteral::Lex(source_->text().substr(token_start));
CHECK(relexed_token) << "Could not reform numeric literal token.";
return relexed_token->text();
}
@@ -653,7 +653,7 @@ auto TokenizedBuffer::GetTokenText(Token token) const -> llvm::StringRef {
auto& line_info = GetLineInfo(token_info.token_line);
int64_t token_start = line_info.start + token_info.column;
llvm::Optional<LexedStringLiteral> relexed_token =
LexedStringLiteral::Lex(source_->Text().substr(token_start));
LexedStringLiteral::Lex(source_->text().substr(token_start));
CHECK(relexed_token) << "Could not reform string literal token.";
return relexed_token->text();
}
@@ -664,7 +664,7 @@ auto TokenizedBuffer::GetTokenText(Token token) const -> llvm::StringRef {
auto& line_info = GetLineInfo(token_info.token_line);
int64_t token_start = line_info.start + token_info.column;
llvm::StringRef suffix =
source_->Text().substr(token_start + 1).take_while(IsDecimalDigit);
source_->text().substr(token_start + 1).take_while(IsDecimalDigit);
return llvm::StringRef(suffix.data() - 1, suffix.size() + 1);
}
@@ -702,7 +702,7 @@ auto TokenizedBuffer::GetRealLiteral(Token token) const -> RealLiteralValue {
// decimal or hexadecimal literal.
auto& line_info = GetLineInfo(token_info.token_line);
int64_t token_start = line_info.start + token_info.column;
char second_char = source_->Text()[token_start + 1];
char second_char = source_->text()[token_start + 1];
bool is_decimal = second_char != 'x' && second_char != 'b';
return RealLiteralValue(this, token_info.literal_index, is_decimal);
@@ -910,9 +910,9 @@ auto TokenizedBuffer::TokenIterator::Print(llvm::raw_ostream& output) const
auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
const char* loc) -> Diagnostic::Location {
CHECK(StringRefContainsPointer(buffer_->source_->Text(), loc))
CHECK(StringRefContainsPointer(buffer_->source_->text(), loc))
<< "location not within buffer";
int64_t offset = loc - buffer_->source_->Text().begin();
int64_t offset = loc - buffer_->source_->text().begin();
// Find the first line starting after the given location. Note that we can't
// inspect `line.length` here because it is not necessarily correct for the
@@ -937,7 +937,7 @@ auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
column_number = *last_line_lexed_to_column_;
for (int64_t i = line_it->start + *last_line_lexed_to_column_; i != offset;
++i) {
if (buffer_->source_->Text()[i] == '\n') {
if (buffer_->source_->text()[i] == '\n') {
++line_number;
column_number = 0;
} else {
@@ -946,7 +946,7 @@ auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
}
}
return {.file_name = buffer_->source_->Filename().str(),
return {.file_name = buffer_->source_->filename().str(),
.line_number = line_number + 1,
.column_number = column_number + 1};
}
@@ -957,7 +957,7 @@ auto TokenizedBuffer::TokenLocationTranslator::GetLocation(Token token)
auto& token_info = buffer_->GetTokenInfo(token);
auto& line_info = buffer_->GetLineInfo(token_info.token_line);
const char* token_start =
buffer_->source_->Text().begin() + line_info.start + token_info.column;
buffer_->source_->text().begin() + line_info.start + token_info.column;
// Find the corresponding file location.
// TODO: Should we somehow indicate in the diagnostic location if this token