[Mlir-commits] [mlir] 26a61db - [mlir][ods] NFC fix compilation error on clang-8
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 15 11:41:24 PST 2022
Author: Mogball
Date: 2022-02-15T19:41:16Z
New Revision: 26a61db93f9c83251b59be12c8a56c3a3ddcda94
URL: https://github.com/llvm/llvm-project/commit/26a61db93f9c83251b59be12c8a56c3a3ddcda94
DIFF: https://github.com/llvm/llvm-project/commit/26a61db93f9c83251b59be12c8a56c3a3ddcda94.diff
LOG: [mlir][ods] NFC fix compilation error on clang-8
Added:
Modified:
mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
Removed:
################################################################################
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
index 35ab19942ba1..f8b3b2b007a8 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
@@ -57,20 +57,17 @@ class ParameterElement
StringRef getName() const { return param.getName(); }
/// Generate the code to check whether the parameter should be printed.
- auto genPrintGuard(FmtContext &ctx) const {
- return [&](raw_ostream &os) -> raw_ostream & {
- std::string self = getParameterAccessorName(getName()) + "()";
- ctx.withSelf(self);
- os << tgfmt("($_self", &ctx);
- if (llvm::Optional<StringRef> defaultValue =
- getParam().getDefaultValue()) {
- // Use the `comparator` field if it exists, else the equality operator.
- std::string valueStr = tgfmt(*defaultValue, &ctx).str();
- ctx.addSubst("_lhs", self).addSubst("_rhs", valueStr);
- os << " && !(" << tgfmt(getParam().getComparator(), &ctx) << ")";
- }
- return os << ")";
- };
+ MethodBody &genPrintGuard(FmtContext &ctx, MethodBody &os) const {
+ std::string self = getParameterAccessorName(getName()) + "()";
+ ctx.withSelf(self);
+ os << tgfmt("($_self", &ctx);
+ if (llvm::Optional<StringRef> defaultValue = getParam().getDefaultValue()) {
+ // Use the `comparator` field if it exists, else the equality operator.
+ std::string valueStr = tgfmt(*defaultValue, &ctx).str();
+ ctx.addSubst("_lhs", self).addSubst("_rhs", valueStr);
+ os << " && !(" << tgfmt(getParam().getComparator(), &ctx) << ")";
+ }
+ return os << ")";
}
private:
@@ -82,12 +79,6 @@ class ParameterElement
static bool paramIsOptional(ParameterElement *el) { return el->isOptional(); }
static bool paramNotOptional(ParameterElement *el) { return !el->isOptional(); }
-/// raw_ostream doesn't have an overload for stream functors. Declare one here.
-template <typename StreamFunctor>
-static raw_ostream &operator<<(raw_ostream &os, StreamFunctor &&fcn) {
- return fcn(os);
-}
-
/// Base class for a directive that contains references to multiple variables.
template <DirectiveElement::Kind DirectiveKind>
class ParamsDirectiveBase : public DirectiveElementBase<DirectiveKind> {
@@ -675,7 +666,7 @@ void DefFormat::genVariablePrinter(ParameterElement *el, FmtContext &ctx,
// Guard the printer on the presence of optional parameters and that they
// aren't equal to their default values (if they have one).
if (el->isOptional() && !skipGuard) {
- os << "if (" << el->genPrintGuard(ctx) << ") {\n";
+ el->genPrintGuard(ctx, os << "if (") << ") {\n";
os.indent();
}
@@ -703,8 +694,7 @@ static void guardOnAny(FmtContext &ctx, MethodBody &os,
os << "if (";
llvm::interleave(
params, os,
- [&](ParameterElement *param) { os << param->genPrintGuard(ctx); },
- " || ");
+ [&](ParameterElement *param) { param->genPrintGuard(ctx, os); }, " || ");
os << ") {\n";
os.indent();
}
@@ -727,7 +717,7 @@ void DefFormat::genCommaSeparatedPrinter(
os.indent() << "bool _firstPrinted = true;\n";
for (ParameterElement *param : params) {
if (param->isOptional()) {
- os << "if (" << param->genPrintGuard(ctx) << ") {\n";
+ param->genPrintGuard(ctx, os << "if (") << ") {\n";
os.indent();
}
os << tgfmt("if (!_firstPrinted) $_printer << \", \";\n", &ctx);
More information about the Mlir-commits
mailing list