mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 21:21:04 +01:00
Add import context for locations. (#3807)
As discussed around #3792, identify the import a diagnostic message came from prior to the diagnostic message itself. This occurs during location translation so that the logic can be central. I'd considered associating the parse node with ImportRef instructions, but I realized about halfway through that because I need to store the ImportDirectiveId on the ImportIR for cross-package imports, it's there for use in location translation without extra work. That saves a fair amount of stringing it through declarations, as well as an oddity where ImportRef instructions would have a node that didn't really represent them.
This commit is contained in:
@@ -346,7 +346,7 @@ auto TokenIterator::Print(llvm::raw_ostream& output) const -> void {
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::SourceBufferDiagnosticConverter::ConvertLocation(
|
||||
const char* loc) const -> DiagnosticLocation {
|
||||
const char* loc, ContextFnT /*context_fn*/) const -> DiagnosticLocation {
|
||||
CARBON_CHECK(StringRefContainsPointer(buffer_->source_->text(), loc))
|
||||
<< "location not within buffer";
|
||||
int64_t offset = loc - buffer_->source_->text().begin();
|
||||
@@ -390,7 +390,8 @@ auto TokenizedBuffer::SourceBufferDiagnosticConverter::ConvertLocation(
|
||||
.column_number = column_number + 1};
|
||||
}
|
||||
|
||||
auto TokenDiagnosticConverter::ConvertLocation(TokenIndex token) const
|
||||
auto TokenDiagnosticConverter::ConvertLocation(TokenIndex token,
|
||||
ContextFnT context_fn) const
|
||||
-> DiagnosticLocation {
|
||||
// Map the token location into a position within the source buffer.
|
||||
const auto& token_info = buffer_->GetTokenInfo(token);
|
||||
@@ -403,7 +404,7 @@ auto TokenDiagnosticConverter::ConvertLocation(TokenIndex token) const
|
||||
// is a recovery token that doesn't correspond to the original source?
|
||||
DiagnosticLocation loc =
|
||||
TokenizedBuffer::SourceBufferDiagnosticConverter(buffer_).ConvertLocation(
|
||||
token_start);
|
||||
token_start, context_fn);
|
||||
loc.length = buffer_->GetTokenText(token).size();
|
||||
return loc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user