[clang] [clang][NFC] Use switch in LoopHintAttr::getValueString (PR #147119)
https://github.com/bv2k4 edited https://github.com/llvm/llvm-project/pull/147119 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Use switch in LoopHintAttr::getValueString (PR #147119)
https://github.com/bv2k4 updated
https://github.com/llvm/llvm-project/pull/147119
>From 9d8f8dcaacadac7d038da4cc6c72f1bbaceab7c0 Mon Sep 17 00:00:00 2001
From: Bogdan Vetrenko
Date: Sat, 5 Jul 2025 01:53:01 +0300
Subject: [PATCH] [clang][NFC] Use switch in LoopHintAttr::getValueString
---
clang/lib/AST/AttrImpl.cpp | 37 +
1 file changed, 25 insertions(+), 12 deletions(-)
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 {
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Use switch in LoopHintAttr::getValueString (PR #147119)
https://github.com/bv2k4 updated
https://github.com/llvm/llvm-project/pull/147119
>From ca25a88e68423559798d75b85be70e00a42313b4 Mon Sep 17 00:00:00 2001
From: Bogdan Vetrenko
Date: Sat, 5 Jul 2025 01:53:01 +0300
Subject: [PATCH] [clang][NFC] Use switch in LoopHintAttr::getValueString
---
clang/lib/AST/AttrImpl.cpp | 37 +
1 file changed, 25 insertions(+), 12 deletions(-)
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 {
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Use switch in LoopHintAttr::getValueString (PR #147119)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Bogdan Vetrenko (bv2k4)
Changes
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 {
``
https://github.com/llvm/llvm-project/pull/147119
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Use switch in LoopHintAttr::getValueString (PR #147119)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/147119 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Use switch in LoopHintAttr::getValueString (PR #147119)
https://github.com/bv2k4 created
https://github.com/llvm/llvm-project/pull/147119
Replace if-else chain with switch over enum.
>From ca25a88e68423559798d75b85be70e00a42313b4 Mon Sep 17 00:00:00 2001
From: Bogdan Vetrenko
Date: Sat, 5 Jul 2025 01:53:01 +0300
Subject: [PATCH] [clang][NFC] Use switch in LoopHintAttr::getValueString
---
clang/lib/AST/AttrImpl.cpp | 37 +
1 file changed, 25 insertions(+), 12 deletions(-)
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 {
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
