mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 15:21:04 +01:00
Enable most relevant clang-tidy checks and fix uncovered issues. (#220)
Most of these were fixed automatically (including things like adding `[[nodiscard]]` and such). A number of others required manual edits. I think all of them were pretty nice improvements. There were a few places where the issues really stem from external constraints and I've disabled the checks: GoogleTest macros or the specific LibFuzzer entry points. The only other places I disabled are the implicit conversions to a private `enum` in the classes wrapping those `enum`s. These implicit conversions are necessarily implicit to serve their only purpose: enabling their use in `switch` statements and `case` labels. When these were highlighted, it showed that one of these was actually converting to an *`int`*. I've switched that to use the private `enum` instead as doing so is important to enable warnings on non-covering `switch` statements over than `enum`. And indeed, there is a `switch` that was was implicitly relying on falling through in this way, so I've added the explicit documentation of the intentional pattern to address that warning. Sorry this is so large, all of this somewhat fell out of enabling the `clang-tidy` checks. If it is too difficult to review as lump, I can work on breaking it apart as needed. Just let me know.
This commit is contained in:
+22
-12
@@ -322,9 +322,7 @@ class TokenizedBuffer::Lexer {
|
||||
}
|
||||
switch (c) {
|
||||
case '_':
|
||||
return false;
|
||||
case '\t':
|
||||
return false;
|
||||
case '\n':
|
||||
return false;
|
||||
}
|
||||
@@ -487,16 +485,28 @@ auto TokenizedBuffer::PrintWidths::Widen(const PrintWidths& widths) -> void {
|
||||
indent = std::max(widths.indent, indent);
|
||||
}
|
||||
|
||||
// Compute the printed width of a number. When numbers are printed in decimal,
|
||||
// the number of digits needed is is one more than the log-base-10 of the value.
|
||||
// We handle a value of `zero` explicitly.
|
||||
//
|
||||
// This routine requires its argument to be *non-negative*.
|
||||
static auto ComputeDecimalPrintedWidth(int number) -> int {
|
||||
assert(number >= 0 && "Negative numbers are not supported.");
|
||||
if (number == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return static_cast<int>(std::log10(number)) + 1;
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetTokenPrintWidths(Token token) const -> PrintWidths {
|
||||
PrintWidths widths = {};
|
||||
// Compute the printed width of the various token information. When numbers
|
||||
// here are printed in decimal, the number of digits needed is is one more
|
||||
// than the log-base-10 of the value.
|
||||
widths.index = std::log10(token_infos.size()) + 1;
|
||||
widths.index = ComputeDecimalPrintedWidth(token_infos.size());
|
||||
widths.kind = GetKind(token).Name().size();
|
||||
widths.line = std::log10(GetLineNumber(token)) + 1;
|
||||
widths.column = std::log10(GetColumnNumber(token)) + 1;
|
||||
widths.indent = std::log10(GetIndentColumnNumber(GetLine(token))) + 1;
|
||||
widths.line = ComputeDecimalPrintedWidth(GetLineNumber(token));
|
||||
widths.column = ComputeDecimalPrintedWidth(GetColumnNumber(token));
|
||||
widths.indent =
|
||||
ComputeDecimalPrintedWidth(GetIndentColumnNumber(GetLine(token)));
|
||||
return widths;
|
||||
}
|
||||
|
||||
@@ -506,7 +516,7 @@ auto TokenizedBuffer::Print(llvm::raw_ostream& output_stream) const -> void {
|
||||
}
|
||||
|
||||
PrintWidths widths = {};
|
||||
widths.index = std::log10(token_infos.size()) + 1;
|
||||
widths.index = ComputeDecimalPrintedWidth((token_infos.size()));
|
||||
for (Token token : Tokens()) {
|
||||
widths.Widen(GetTokenPrintWidths(token));
|
||||
}
|
||||
@@ -570,7 +580,7 @@ auto TokenizedBuffer::GetLineInfo(Line line) const -> const LineInfo& {
|
||||
|
||||
auto TokenizedBuffer::AddLine(LineInfo info) -> Line {
|
||||
line_infos.push_back(info);
|
||||
return Line(line_infos.size() - 1);
|
||||
return Line(static_cast<int>(line_infos.size()) - 1);
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::GetTokenInfo(Token token) -> TokenInfo& {
|
||||
@@ -583,7 +593,7 @@ auto TokenizedBuffer::GetTokenInfo(Token token) const -> const TokenInfo& {
|
||||
|
||||
auto TokenizedBuffer::AddToken(TokenInfo info) -> Token {
|
||||
token_infos.push_back(info);
|
||||
return Token(token_infos.size() - 1);
|
||||
return Token(static_cast<int>(token_infos.size()) - 1);
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user