Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run clang-format on all files that are not currently open in PRs. #1963

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions common/analysis/command_file_lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ namespace verible {
CommandFileLexer::CommandFileLexer(absl::string_view config)
: parent_lexer_type(config) {
const auto lex_status = MakeTokenSequence(
this, config, &tokens_, [&](const TokenInfo& error_token) {
this, config, &tokens_, [&](const TokenInfo &error_token) {
LOG(ERROR) << "erroneous token: " << error_token;
});

// Pre-process all tokens where its needed
for (auto& t : tokens_) {
for (auto &t : tokens_) {
switch (t.token_enum()) {
case ConfigToken::kFlag:
// Skip -- prefix
Expand All @@ -45,7 +45,7 @@ CommandFileLexer::CommandFileLexer(absl::string_view config)
Restart(config);
}

bool CommandFileLexer::TokenIsError(const verible::TokenInfo& token) const {
bool CommandFileLexer::TokenIsError(const verible::TokenInfo &token) const {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion common/analysis/command_file_lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CommandFileLexer : public FlexLexerAdapter<veribleCommandFileFlexLexer> {
explicit CommandFileLexer(absl::string_view config);

// Returns true if token is invalid.
bool TokenIsError(const verible::TokenInfo&) const final;
bool TokenIsError(const verible::TokenInfo &) const final;

// Runs the Lexer and attached command handlers
std::vector<TokenRange> GetCommandsTokenRanges();
Expand Down
8 changes: 4 additions & 4 deletions common/analysis/command_file_lexer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FilteredCommandFileLexer : public CommandFileLexer {
explicit FilteredCommandFileLexer(absl::string_view code)
: CommandFileLexer(code) {}

bool KeepSyntaxTreeTokens(const verible::TokenInfo& t) {
bool KeepSyntaxTreeTokens(const verible::TokenInfo &t) {
switch (t.token_enum()) {
case ConfigToken::kNewline:
return false;
Expand All @@ -40,7 +40,7 @@ class FilteredCommandFileLexer : public CommandFileLexer {
}
}

const verible::TokenInfo& DoNextToken() final {
const verible::TokenInfo &DoNextToken() final {
do {
CommandFileLexer::DoNextToken();
} while (!KeepSyntaxTreeTokens(GetLastToken()));
Expand All @@ -52,13 +52,13 @@ using LexerTestData = verible::SynthesizedLexerTestData;

// Forwarding function to the template test driver function.
template <typename... Args>
static void TestLexer(Args&&... args) {
static void TestLexer(Args &&...args) {
verible::TestLexer<CommandFileLexer>(std::forward<Args>(args)...);
}

// Forwarding function to the template test driver function.
template <typename... Args>
static void TestFilteredLexer(Args&&... args) {
static void TestFilteredLexer(Args &&...args) {
verible::TestLexer<FilteredCommandFileLexer>(std::forward<Args>(args)...);
}

Expand Down
38 changes: 19 additions & 19 deletions common/analysis/file_analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
namespace verible {

// Translates phase enum into string for diagnostic messages.
const char* AnalysisPhaseName(const AnalysisPhase& phase) {
const char *AnalysisPhaseName(const AnalysisPhase &phase) {
switch (phase) {
case AnalysisPhase::kLexPhase:
return "lexical";
Expand All @@ -47,11 +47,11 @@ const char* AnalysisPhaseName(const AnalysisPhase& phase) {
}
return "UNKNOWN";
}
std::ostream& operator<<(std::ostream& stream, const AnalysisPhase& phase) {
std::ostream &operator<<(std::ostream &stream, const AnalysisPhase &phase) {
return stream << AnalysisPhaseName(phase);
}

const char* ErrorSeverityDescription(const ErrorSeverity& severity) {
const char *ErrorSeverityDescription(const ErrorSeverity &severity) {
switch (severity) {
case ErrorSeverity::kError:
return "error";
Expand All @@ -60,23 +60,23 @@ const char* ErrorSeverityDescription(const ErrorSeverity& severity) {
}
return "UNKNOWN";
}
std::ostream& operator<<(std::ostream& stream, const ErrorSeverity& severity) {
std::ostream &operator<<(std::ostream &stream, const ErrorSeverity &severity) {
return stream << ErrorSeverityDescription(severity);
}

std::ostream& operator<<(std::ostream& stream, const RejectedToken& r) {
std::ostream &operator<<(std::ostream &stream, const RejectedToken &r) {
return stream << r.token_info << " (" << r.phase << " " << r.severity
<< "): " << r.explanation;
}

// Grab tokens until EOF, and initialize a stream view with all tokens.
absl::Status FileAnalyzer::Tokenize(Lexer* lexer) {
absl::Status FileAnalyzer::Tokenize(Lexer *lexer) {
const auto buffer = Data().Contents();
TokenSequence& tokens = MutableData().MutableTokenStream();
TokenSequence &tokens = MutableData().MutableTokenStream();

if (auto lex_status = MakeTokenSequence(
lexer, buffer, &tokens,
[&](const TokenInfo& error_token) {
[&](const TokenInfo &error_token) {
VLOG(1) << "Lexical error with token: " << error_token;
// Save error details in rejected_tokens_.
rejected_tokens_.push_back(
Expand All @@ -96,7 +96,7 @@ absl::Status FileAnalyzer::Tokenize(Lexer* lexer) {
}

// Runs the parser on the current TokenStreamView.
absl::Status FileAnalyzer::Parse(Parser* parser) {
absl::Status FileAnalyzer::Parse(Parser *parser) {
absl::Status status = parser->Parse();
// Transfer syntax tree root, even if there were (recovered) syntax errors,
// because the partial tree can still be useful to analyze.
Expand All @@ -105,7 +105,7 @@ absl::Status FileAnalyzer::Parse(Parser* parser) {
CHECK(Data().SyntaxTree().get()) << "Expected syntax tree from parsing \""
<< filename_ << "\", but got none.";
} else {
for (const auto& token : parser->RejectedTokens()) {
for (const auto &token : parser->RejectedTokens()) {
rejected_tokens_.push_back(RejectedToken{
token, AnalysisPhase::kParsePhase, "" /* no detailed explanation */});
}
Expand All @@ -115,7 +115,7 @@ absl::Status FileAnalyzer::Parse(Parser* parser) {

// Reports human-readable token error.
std::string FileAnalyzer::TokenErrorMessage(
const TokenInfo& error_token) const {
const TokenInfo &error_token) const {
// TODO(fangism): accept a RejectedToken to get an explanation message.
std::ostringstream output_stream;
if (!error_token.isEOF()) {
Expand All @@ -131,18 +131,18 @@ std::string FileAnalyzer::TokenErrorMessage(
std::vector<std::string> FileAnalyzer::TokenErrorMessages() const {
std::vector<std::string> messages;
messages.reserve(rejected_tokens_.size());
for (const auto& rejected_token : rejected_tokens_) {
for (const auto &rejected_token : rejected_tokens_) {
messages.push_back(TokenErrorMessage(rejected_token.token_info));
}
return messages;
}

void FileAnalyzer::ExtractLinterTokenErrorDetail(
const RejectedToken& error_token,
const ReportLinterErrorFunction& error_report) const {
const RejectedToken &error_token,
const ReportLinterErrorFunction &error_report) const {
const LineColumnRange range = Data().GetRangeForToken(error_token.token_info);
absl::string_view context_line = "";
const auto& lines = Data().Lines();
const auto &lines = Data().Lines();
if (range.start.line < static_cast<int>(lines.size())) {
context_line = lines[range.start.line];
}
Expand All @@ -154,14 +154,14 @@ void FileAnalyzer::ExtractLinterTokenErrorDetail(
}

std::string FileAnalyzer::LinterTokenErrorMessage(
const RejectedToken& error_token, bool diagnostic_context) const {
const RejectedToken &error_token, bool diagnostic_context) const {
std::ostringstream out;
ExtractLinterTokenErrorDetail(
error_token,
[&](const std::string& filename, LineColumnRange range,
[&](const std::string &filename, LineColumnRange range,
ErrorSeverity severity, AnalysisPhase phase,
absl::string_view token_text, absl::string_view context_line,
const std::string& message) {
const std::string &message) {
out << filename_ << ':' << range << " " << phase << " " << severity;
if (error_token.token_info.isEOF()) {
out << " (unexpected EOF)";
Expand All @@ -186,7 +186,7 @@ std::vector<std::string> FileAnalyzer::LinterTokenErrorMessages(
bool diagnostic_context) const {
std::vector<std::string> messages;
messages.reserve(rejected_tokens_.size());
for (const auto& rejected_token : rejected_tokens_) {
for (const auto &rejected_token : rejected_tokens_) {
messages.push_back(
LinterTokenErrorMessage(rejected_token, diagnostic_context));
}
Expand Down
34 changes: 17 additions & 17 deletions common/analysis/file_analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ enum class AnalysisPhase {
};

// String representation of phase (needed for CHECK).
const char* AnalysisPhaseName(const AnalysisPhase& phase);
std::ostream& operator<<(std::ostream&, const AnalysisPhase&);
const char *AnalysisPhaseName(const AnalysisPhase &phase);
std::ostream &operator<<(std::ostream &, const AnalysisPhase &);

enum class ErrorSeverity {
kError,
kWarning,
};
const char* ErrorSeverityDescription(const ErrorSeverity& severity);
std::ostream& operator<<(std::ostream&, const ErrorSeverity&);
const char *ErrorSeverityDescription(const ErrorSeverity &severity);
std::ostream &operator<<(std::ostream &, const ErrorSeverity &);

// RejectedToken is a categorized warning/error token.
// TODO(hzeller): In the presence of warnings, this probably needs to be
Expand All @@ -82,7 +82,7 @@ struct RejectedToken {
ErrorSeverity severity = ErrorSeverity::kError;
};

std::ostream& operator<<(std::ostream&, const RejectedToken&);
std::ostream &operator<<(std::ostream &, const RejectedToken &);

// FileAnalyzer holds the results of lexing and parsing.
class FileAnalyzer {
Expand All @@ -100,13 +100,13 @@ class FileAnalyzer {
virtual absl::Status Tokenize() = 0;

// Break file contents (string) into tokens.
absl::Status Tokenize(Lexer* lexer);
absl::Status Tokenize(Lexer *lexer);

// Construct ConcreteSyntaxTree from TokenStreamView.
absl::Status Parse(Parser* parser);
absl::Status Parse(Parser *parser);

// Diagnostic message for one rejected token.
std::string TokenErrorMessage(const TokenInfo&) const;
std::string TokenErrorMessage(const TokenInfo &) const;

// Collect diagnostic messages for rejected tokens.
std::vector<std::string> TokenErrorMessages() const;
Expand All @@ -124,40 +124,40 @@ class FileAnalyzer {
// The "message" finally is a human-readable error message
// TODO(hzeller): these are a lot of parameters, maybe a struct would be good.
using ReportLinterErrorFunction = std::function<void(
const std::string& filename, LineColumnRange range,
const std::string &filename, LineColumnRange range,
ErrorSeverity severity, AnalysisPhase phase, absl::string_view token_text,
absl::string_view context_line, const std::string& message)>;
absl::string_view context_line, const std::string &message)>;

// Extract detailed diagnostic information for rejected token.
void ExtractLinterTokenErrorDetail(
const RejectedToken& error_token,
const ReportLinterErrorFunction& error_report) const;
const RejectedToken &error_token,
const ReportLinterErrorFunction &error_report) const;

// -- convenience functions using the above

// Diagnostic message for rejected tokens for linter.
// Second argument is the show_context option. When enabled
// additional diagnostic line is concatenated to an error message
// with marker that points to vulnerable token
std::string LinterTokenErrorMessage(const RejectedToken&, bool) const;
std::string LinterTokenErrorMessage(const RejectedToken &, bool) const;

// First argument is the show_context option. When enabled
// additional diagnostic line is concatenated to an error message
// with marker that points to vulnerable token
std::vector<std::string> LinterTokenErrorMessages(bool) const;

const std::vector<RejectedToken>& GetRejectedTokens() const {
const std::vector<RejectedToken> &GetRejectedTokens() const {
return rejected_tokens_;
}

// Convenience methods to access text structure view.
const ConcreteSyntaxTree& SyntaxTree() const {
const ConcreteSyntaxTree &SyntaxTree() const {
return ABSL_DIE_IF_NULL(text_structure_)->SyntaxTree();
}
const TextStructureView& Data() const {
const TextStructureView &Data() const {
return ABSL_DIE_IF_NULL(text_structure_)->Data();
}
TextStructureView& MutableData() {
TextStructureView &MutableData() {
return ABSL_DIE_IF_NULL(text_structure_)->MutableData();
}

Expand Down
22 changes: 11 additions & 11 deletions common/analysis/file_analyzer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TEST(RejectedTokenStreamTest, StringRepresentation) {
// Subclass for the purpose of testing FileAnalyzer.
class FakeFileAnalyzer : public FileAnalyzer {
public:
FakeFileAnalyzer(const std::string& text, const std::string& filename)
FakeFileAnalyzer(const std::string &text, const std::string &filename)
: FileAnalyzer(text, filename) {}

absl::Status Tokenize() final {
Expand Down Expand Up @@ -73,10 +73,10 @@ TEST(FileAnalyzerTest, TokenErrorMessageSameLine) {
{
analyzer.ExtractLinterTokenErrorDetail(
{error_token, AnalysisPhase::kParsePhase},
[](const std::string& filename, LineColumnRange range,
[](const std::string &filename, LineColumnRange range,
ErrorSeverity severity, AnalysisPhase phase,
absl::string_view token_text, absl::string_view context_line,
const std::string& message) {
const std::string &message) {
EXPECT_EQ(filename, "hello.txt");
EXPECT_EQ(range.start.line, 1);
EXPECT_EQ(range.start.column, 4);
Expand Down Expand Up @@ -111,10 +111,10 @@ TEST(FileAnalyzerTest, TokenErrorMessageSameLineWithContext) {
{
analyzer.ExtractLinterTokenErrorDetail(
{error_token, AnalysisPhase::kParsePhase},
[](const std::string& filename, LineColumnRange range,
[](const std::string &filename, LineColumnRange range,
ErrorSeverity severity, AnalysisPhase phase,
absl::string_view token_text, absl::string_view context_line,
const std::string& message) {
const std::string &message) {
EXPECT_EQ(filename, "hello.txt");
EXPECT_EQ(range.start.line, 1);
EXPECT_EQ(range.start.column, 4);
Expand Down Expand Up @@ -147,10 +147,10 @@ TEST(FileAnalyzerTest, TokenErrorMessageOneChar) {
{
analyzer.ExtractLinterTokenErrorDetail(
{error_token, AnalysisPhase::kParsePhase},
[](const std::string& filename, LineColumnRange range,
[](const std::string &filename, LineColumnRange range,
ErrorSeverity severity, AnalysisPhase phase,
absl::string_view token_text, absl::string_view context_line,
const std::string& message) {
const std::string &message) {
EXPECT_EQ(filename, "hello.txt");
EXPECT_EQ(range.start.line, 0);
EXPECT_EQ(range.start.column, 5);
Expand Down Expand Up @@ -204,10 +204,10 @@ TEST(FileAnalyzerTest, TokenErrorMessageDifferentLine) {
{
analyzer.ExtractLinterTokenErrorDetail(
{error_token, AnalysisPhase::kParsePhase},
[](const std::string& filename, LineColumnRange range,
[](const std::string &filename, LineColumnRange range,
ErrorSeverity severity, AnalysisPhase phase,
absl::string_view token_text, absl::string_view context_line,
const std::string& message) {
const std::string &message) {
EXPECT_EQ(filename, "hello.txt");
EXPECT_EQ(range.start.line, 0);
EXPECT_EQ(range.start.column, 7);
Expand Down Expand Up @@ -282,10 +282,10 @@ TEST(FileAnalyzerTest, TokenErrorMessageEOFWithContext) {
{
analyzer.ExtractLinterTokenErrorDetail(
{error_token, AnalysisPhase::kParsePhase},
[](const std::string& filename, LineColumnRange range,
[](const std::string &filename, LineColumnRange range,
ErrorSeverity severity, AnalysisPhase phase,
absl::string_view token_text, absl::string_view context_line,
const std::string& message) {
const std::string &message) {
EXPECT_EQ(filename, "unbalanced.txt");
EXPECT_EQ(range.start.line, 2);
EXPECT_EQ(range.start.column, 7);
Expand Down
10 changes: 5 additions & 5 deletions common/analysis/line_linter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@

namespace verible {

void LineLinter::Lint(const std::vector<absl::string_view>& lines) {
void LineLinter::Lint(const std::vector<absl::string_view> &lines) {
VLOG(1) << "LineLinter analyzing lines with " << rules_.size() << " rules.";
for (const auto& line : lines) {
for (const auto& rule : rules_) {
for (const auto &line : lines) {
for (const auto &rule : rules_) {
ABSL_DIE_IF_NULL(rule)->HandleLine(line);
}
}
for (const auto& rule : rules_) {
for (const auto &rule : rules_) {
rule->Finalize();
}
}

std::vector<LintRuleStatus> LineLinter::ReportStatus() const {
std::vector<LintRuleStatus> status;
status.reserve(rules_.size());
for (const auto& rule : rules_) {
for (const auto &rule : rules_) {
status.push_back(ABSL_DIE_IF_NULL(rule)->Report());
}
return status;
Expand Down
Loading