[clang] [clang][NFC] Use switch in LoopHintAttr::getValueString (PR #147119)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 4 16:05:46 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Bogdan Vetrenko (bv2k4)
<details>
<summary>Changes</summary>
Replace if-else chain with switch over enum.
---
Full diff: https://github.com/llvm/llvm-project/pull/147119.diff
1 Files Affected:
- (modified) clang/lib/AST/AttrImpl.cpp (+25-12)
``````````diff
diff --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp
index 5875a925d3fb0..c7618e1483e6f 100644
--- a/clang/lib/AST/AttrImpl.cpp
+++ b/clang/lib/AST/AttrImpl.cpp
@@ -41,25 +41,38 @@ std::string LoopHintAttr::getValueString(const PrintingPolicy &Policy) const {
std::string ValueName;
llvm::raw_string_ostream OS(ValueName);
OS << "(";
- if (state == Numeric)
+ switch (state) {
+ case Numeric:
value->printPretty(OS, nullptr, Policy);
- else if (state == FixedWidth || state == ScalableWidth) {
+ break;
+ case FixedWidth:
if (value) {
value->printPretty(OS, nullptr, Policy);
- if (state == ScalableWidth)
- OS << ", scalable";
- } else if (state == ScalableWidth)
- OS << "scalable";
- else
+ } else {
OS << "fixed";
- } else if (state == Enable)
+ }
+ break;
+ case ScalableWidth:
+ if (value) {
+ value->printPretty(OS, nullptr, Policy);
+ OS << ", scalable";
+ } else {
+ OS << "scalable";
+ }
+ break;
+ case Enable:
OS << "enable";
- else if (state == Full)
+ break;
+ case Full:
OS << "full";
- else if (state == AssumeSafety)
+ break;
+ case AssumeSafety:
OS << "assume_safety";
- else
+ break;
+ case Disable:
OS << "disable";
+ break;
+ }
OS << ")";
return ValueName;
}
@@ -195,7 +208,7 @@ OMPDeclareTargetDeclAttr::getLocation(const ValueDecl *VD) {
namespace clang {
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
-}
+} // namespace clang
void OMPDeclareVariantAttr::printPrettyPragma(
raw_ostream &OS, const PrintingPolicy &Policy) const {
``````````
</details>
https://github.com/llvm/llvm-project/pull/147119
More information about the cfe-commits
mailing list