mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-25 20:51:10 +00:00
Add tracking of lexed comments, with skeletal formatting. (#4385)
In order to format comments, it's helpful if they're tracked. This tracks them separately from tokens in order to avoid interfering with parse; it'd be inconvenient if comment tokens could show up in arbitrary locations, albeit possible to support. This additionally extracts out the TokenIterator support into a template in order to generally have it available for IndexBase types. I'm only adding it for CommentInfo, not sure if we'll want it elsewhere, but this structure still felt like a good fit.
This commit is contained in:
1 parent
efb5d6d25a
commit
1338f9e0ad
8 files changed
+197
-50
No files matched your search
@@ -345,15 +345,24 @@ auto TokenizedBuffer::AddLine(LineInfo info) -> LineIndex {
|
||||
return LineIndex(static_cast<int>(line_infos_.size()) - 1);
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::IsAfterComment(TokenIndex token,
|
||||
CommentIndex comment_index) const -> bool {
|
||||
const auto& comment_data = comments_[comment_index.index];
|
||||
return GetTokenInfo(token).byte_offset() > comment_data.start;
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetCommentText(CommentIndex comment_index) const
|
||||
-> llvm::StringRef {
|
||||
const auto& comment_data = comments_[comment_index.index];
|
||||
return source_->text().substr(comment_data.start, comment_data.length);
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::CollectMemUsage(MemUsage& mem_usage,
|
||||
llvm::StringRef label) const -> void {
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "allocator_"), allocator_);
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "token_infos_"), token_infos_);
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "line_infos_"), line_infos_);
|
||||
}
|
||||
|
||||
auto TokenIterator::Print(llvm::raw_ostream& output) const -> void {
|
||||
output << token_.index;
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "comments_"), comments_);
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::SourceBufferDiagnosticConverter::ConvertLoc(
|
||||
|
||||
Reference in new issue
Block a user