46#include <mlir/TableGen/AttrOrTypeDef.h>
47#include <mlir/TableGen/Dialect.h>
49#include <llvm/ADT/StringExtras.h>
50#include <llvm/Support/FormatVariadic.h>
51#include <llvm/Support/raw_ostream.h>
79 using TestGenerator::TestGenerator;
95 static constexpr char fmt[] = R
"(
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
"(
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}{6});
132 assert(!
paramName.empty() &&
"paramName must be set");
141 static constexpr char fmt[] = R
"(
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
"(
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 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< std::string > & getFunctionPrefix()
Return the FunctionPrefix option, registering it on first access.
llvm::cl::opt< std::string > & getDialectName()
Return the DialectName option, registering it on first access.
llvm::cl::opt< bool > & getGenExtraClassMethods()
Return the GenExtraClassMethods option, registering it on first access.
llvm::cl::opt< bool > & getGenTypeOrAttrParamGetters()
Return the GenTypeOrAttrParamGetters option, registering it on first access.
llvm::cl::opt< bool > & getGenIsA()
Return the GenIsA option, registering it on first access.
llvm::cl::opt< bool > & getGenTypeOrAttrGet()
Return the GenTypeOrAttrGet option, registering it on first access.
bool isDynamicAPIntType(mlir::StringRef cppType)
Whether a parameter represents an arbitrary-precision mathematical integer.
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.
Base class for attribute and type test generators.
virtual void genArrayRefParamCountTest() const
Generate ArrayRef parameter count getter test.
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.
virtual void genParamGetterTest(bool isInteger=false) const
Generate parameter getter test.
~AttrOrTypeTestGenerator() override=default
virtual void genArrayRefParamAtTest() const
Generate ArrayRef parameter element getter test.
void genCompleteRecord(const mlir::tblgen::AttrOrTypeDef &def, bool isType)
mlir::StringRef paramName
std::string paramNameCapitalized
mlir::StringRef className
virtual void genExtraMethods(mlir::StringRef extraDecl) const
Generate code for extra methods from an extraClassDeclaration.
virtual void setNamespaceAndClassName(const mlir::tblgen::Dialect &d, mlir::StringRef cppClassName)
Set the dialect and class name for code generation.
std::string dialectNameCapitalized
Generator for common test implementation file elements.
virtual void genIsATest() const
Generate IsA test for a class.