// 'Parameters' should be subclasses of this or simple strings (which is a
// shorthand for AttrOrTypeParameter<"C++Type">).
-class AttrOrTypeParameter<string type, string desc> {
+class AttrOrTypeParameter<string type, string desc, string accessorType = ""> {
// Custom memory allocation code for storage constructor.
code allocator = ?;
// Custom comparator used to compare two instances for equality.
code comparator = ?;
// The C++ type of this parameter.
string cppType = type;
+ // The C++ type of the accessor for this parameter.
+ string cppAccessorType = !if(!empty(accessorType), type, accessorType);
// One-line human-readable description of the argument.
string summary = desc;
// The format string for the asm syntax (documentation only).
string syntax = ?;
}
-class AttrParameter<string type, string desc> : AttrOrTypeParameter<type, desc>;
-class TypeParameter<string type, string desc> : AttrOrTypeParameter<type, desc>;
+class AttrParameter<string type, string desc, string accessorType = "">
+ : AttrOrTypeParameter<type, desc, accessorType>;
+class TypeParameter<string type, string desc, string accessorType = "">
+ : AttrOrTypeParameter<type, desc, accessorType>;
// For StringRefs, which require allocation.
class StringRefParameter<string desc = ""> :
// Get the C++ type of this parameter.
StringRef getCppType() const;
+ // Get the C++ accessor type of this parameter.
+ StringRef getCppAccessorType() const;
+
// Get a description of this parameter for documentation purposes.
Optional<StringRef> getSummary() const;
"which inherit from AttrOrTypeParameter\n");
}
+StringRef AttrOrTypeParameter::getCppAccessorType() const {
+ if (auto *param = dyn_cast<llvm::DefInit>(def->getArg(index))) {
+ if (Optional<StringRef> type =
+ param->getDef()->getValueAsOptionalString("cppAccessorType"))
+ return *type;
+ }
+ return getCppType();
+}
+
Optional<StringRef> AttrOrTypeParameter::getSummary() const {
auto *parameterType = def->getArg(index);
if (auto *param = dyn_cast<llvm::DefInit>(parameterType)) {
// DEF-LABEL: struct AttrWithTypeBuilderAttrStorage
// DEF: AttrWithTypeBuilderAttrStorage (::mlir::IntegerAttr attr)
// DEF-NEXT: : ::mlir::AttributeStorage(attr.getType()), attr(attr)
+
+def F_ParamWithAccessorTypeAttr : TestAttr<"ParamWithAccessorType"> {
+ let parameters = (ins AttrParameter<"std::string", "", "StringRef">:$param);
+}
+
+// DECL-LABEL: class ParamWithAccessorTypeAttr
+// DECL: StringRef getParam()
+// DEF: ParamWithAccessorTypeAttrStorage
+// DEF-NEXT: ParamWithAccessorTypeAttrStorage (std::string param)
+// DEF: StringRef ParamWithAccessorTypeAttr::getParam()
+
for (AttrOrTypeParameter ¶meter : parameters) {
SmallString<16> name = parameter.getName();
name[0] = llvm::toUpper(name[0]);
- os << formatv(" {0} get{1}() const;\n", parameter.getCppType(), name);
+ os << formatv(" {0} get{1}() const;\n", parameter.getCppAccessorType(),
+ name);
}
}
SmallString<16> name = param.getName();
name[0] = llvm::toUpper(name[0]);
os << formatv("{0} {3}::get{1}() const {{ return getImpl()->{2}; }\n",
- param.getCppType(), name, paramStorageName,
+ param.getCppAccessorType(), name, paramStorageName,
def.getCppClassName());
}
}