================ @@ -0,0 +1,197 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ConstantOperandOrderCheck.h" +#include "clang/AST/Decl.h" +#include "clang/AST/Expr.h" +#include "clang/AST/OperationKinds.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Lexer.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +/// Out-of-line ctor so vtable is emitted. +ConstantOperandOrderCheck::ConstantOperandOrderCheck(StringRef Name, + ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) { + // Read options (StringRef -> std::string). + PreferredSide = Options.get(PreferredSideOption, "Right").str(); + + // Parse BinaryOperators option (comma-separated). + std::string OpsCSV = + Options.get(BinaryOperatorsOption, "==,!=,<,<=,>,>=").str(); + + llvm::SmallVector<llvm::StringRef, 8> Tokens; + llvm::StringRef(OpsCSV).split(Tokens, ','); + Operators.clear(); + for (auto Tok : Tokens) { + llvm::StringRef Trim = Tok.trim(); + if (!Trim.empty()) + Operators.emplace_back(Trim.str()); + } +} + +ConstantOperandOrderCheck::~ConstantOperandOrderCheck() = default; + +void ConstantOperandOrderCheck::storeOptions( + ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, PreferredSideOption, PreferredSide); + Options.store(Opts, BinaryOperatorsOption, + llvm::join(Operators.begin(), Operators.end(), ",")); +} + +// ------------------------ helpers ------------------------ + +namespace { ---------------- EugeneZelenko wrote:
```suggestion ``` https://github.com/llvm/llvm-project/pull/167158 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
