mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 11:21:05 +01:00
Add Dump functions to Check, Parse, and Lex (#4669)
- Provide `Check::Dump(context, arg)` and similar. - gdb and lldb should do contextual lookup, and `call Dump(*this, Lex::TokenIndex::Invalid)` has been tested with gdb. - Since this is only for debug, keeps the functions fully separated from code. - Uses alwayslink to ensure objects are correctly linked, even though there are no calls. - `-Wno-missing-prototypes` is needed when we don't have forward declarations. - Code is not linked in opt builds, using `#ifndef NDEBUG`. - This probably could be doing something in BUILD files with a `select()`, but the `#ifndef` seemed easier. This is based on #4620, but uses free functions instead of member functions. Co-authored-by: Dana Jansens <danakj@orodu.net> --------- Co-authored-by: danakj <danakj@orodu.net>
This commit is contained in:
co-authored by
Dana Jansens
parent
79ba184dab
commit
3ce0df67bb
@@ -25,7 +25,7 @@ auto TokenizedBuffer::GetLine(TokenIndex token) const -> LineIndex {
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetLineNumber(TokenIndex token) const -> int {
|
||||
return GetLineNumber(GetLine(token));
|
||||
return GetLine(token).index + 1;
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetColumnNumber(TokenIndex token) const -> int {
|
||||
@@ -162,10 +162,6 @@ auto TokenizedBuffer::IsRecoveryToken(TokenIndex token) const -> bool {
|
||||
return recovery_tokens_[token.index];
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetLineNumber(LineIndex line) const -> int {
|
||||
return line.index + 1;
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetNextLine(LineIndex line) const -> LineIndex {
|
||||
LineIndex next(line.index + 1);
|
||||
CARBON_DCHECK(static_cast<size_t>(next.index) < line_infos_.size());
|
||||
@@ -262,7 +258,7 @@ auto TokenizedBuffer::PrintToken(llvm::raw_ostream& output_stream,
|
||||
llvm::right_justify(
|
||||
llvm::formatv("'{0}'", token_info.kind().name()).str(),
|
||||
widths.kind + 2),
|
||||
llvm::format_decimal(GetLineNumber(GetLine(token)), widths.line),
|
||||
llvm::format_decimal(GetLineNumber(token), widths.line),
|
||||
llvm::format_decimal(GetColumnNumber(token), widths.column),
|
||||
llvm::format_decimal(GetIndentColumnNumber(line_index), widths.indent),
|
||||
token_text);
|
||||
|
||||
Reference in New Issue
Block a user