44#include <mlir/TableGen/AttrOrTypeDef.h>
45#include <mlir/TableGen/Dialect.h>
47#include <llvm/ADT/StringExtras.h>
48#include <llvm/Support/FormatVariadic.h>
49#include <llvm/Support/raw_ostream.h>
79 using TestGenerator::TestGenerator;
95 static constexpr char fmt[] = R
"(
96// This test ensures {0}{2}{3}Get links properly.
97TEST_F({2}{1}LinkTests, Get_{3}) {{
98 auto test{1} = createIndex{1}();
100 // We only verify the function compiles and links, wrapped in an unreachable condition
101 if ({0}{1}IsA{2}{3}(test{1})) {{
103 (void){0}{2}{3}Get(context{5});
107 assert(!className.empty() && "className must be set");
121 static constexpr char fmt[] = R
"(
122// This test ensures {0}{2}{3}Get{5} links properly.
123TEST_F({2}{1}LinkTests, Get_{3}_{4}) {{
124 auto test{1} = createIndex{1}();
126 if ({0}{1}IsA{2}{3}(test{1})) {{
127 (void){0}{2}{3}Get{5}(test{1});
132 assert(!
paramName.empty() &&
"paramName must be set");
141 static constexpr char fmt[] = R
"(
142// This test ensures {0}{2}{3}Get{5}Count links properly.
143TEST_F({2}{1}LinkTests, Get_{3}_{4}Count) {{
144 auto test{1} = createIndex{1}();
146 if ({0}{1}IsA{2}{3}(test{1})) {{
147 (void){0}{2}{3}Get{5}Count(test{1});
151 assert(!className.empty() && "className must be set");
152 assert(!
paramName.empty() &&
"paramName must be set");
161 static constexpr char fmt[] = R
"(
162// This test ensures {0}{2}{3}Get{5}At links properly.
163TEST_F({2}{1}LinkTests, Get_{3}_{4}At) {{
164 auto test{1} = createIndex{1}();
166 if ({0}{1}IsA{2}{3}(test{1})) {{
167 (void){0}{2}{3}Get{5}At(test{1}, 0);
171 assert(!className.empty() && "className must be set");
172 assert(!
paramName.empty() &&
"paramName must be set");
180 const mlir::tblgen::Dialect &defDialect = def.getDialect();
203 for (
const auto ¶m : def.getParameters()) {
205 mlir::StringRef cppType = param.getCppType();
217 std::optional<mlir::StringRef> extraDecls = def.getExtraDecls();
218 if (extraDecls.has_value()) {
std::string generateDummyParamsForAttrOrTypeGet(const mlir::tblgen::AttrOrTypeDef &def, bool isType)
Generate dummy parameters for Get builder (used by both Attr and Type)
std::string generateParamListForAttrOrTypeGet(const mlir::tblgen::AttrOrTypeDef &def)
Generate parameter list for Get builder call (used by both Attr and Type)
llvm::cl::opt< bool > GenTypeOrAttrParamGetters
llvm::cl::opt< bool > GenTypeOrAttrGet
llvm::cl::opt< bool > GenIsA
llvm::cl::opt< std::string > DialectName
llvm::cl::opt< std::string > FunctionPrefix
bool isArrayRefType(mlir::StringRef cppType)
Check if a C++ type is an ArrayRef type.
std::string toPascalCase(mlir::StringRef str)
Convert names separated by underscore or colon to PascalCase.
llvm::cl::opt< bool > GenExtraClassMethods
Base class for attribute and type test generators.
virtual void genArrayRefParamCountTest() const
Generate ArrayRef parameter count getter test.
virtual ~AttrOrTypeTestGenerator()=default
void setParamName(mlir::StringRef name)
Set the parameter name for code generation.
virtual void genGetBuilderTest(const std::string &dummyParams, const std::string ¶mList) const
Generate Get builder test for a definition.
void genCompleteRecord(const mlir::tblgen::AttrOrTypeDef def, bool isType)
virtual void genArrayRefParamAtTest() const
Generate ArrayRef parameter element getter test.
mlir::StringRef paramName
virtual void genParamGetterTest() const
Generate parameter getter test.
std::string paramNameCapitalized
virtual void setDialectAndClassName(const mlir::tblgen::Dialect *d, mlir::StringRef cppClassName)
Set the dialect and class name for code generation.
mlir::StringRef className
virtual void genExtraMethods(mlir::StringRef extraDecl) const
Generate code for extra methods from an extraClassDeclaration
std::string dialectNameCapitalized
Generator for common test implementation file elements.
virtual void genIsATest() const
Generate IsA test for a class.