@@ -141,6 +141,15 @@ class StructDirective
141141
142142} // namespace
143143
144+ // / Return true if the provided parameter should always be printed in qualified
145+ // / form (i.e., with dialect/type prefixes). Attribute and type parameters fall
146+ // / into this category to avoid ambiguity when nested within structured
147+ // / properties.
148+ static bool shouldPrintQualified (ParameterElement *param) {
149+ StringRef cppType = param->getParam ().getCppType ();
150+ return cppType.contains (" Attr" ) || cppType.contains (" Type" );
151+ }
152+
144153// ===----------------------------------------------------------------------===//
145154// Format Strings
146155// ===----------------------------------------------------------------------===//
@@ -155,7 +164,8 @@ static const char *const defaultParameterPrinter =
155164
156165// / Qualified printer for attribute or type parameters: it does not elide
157166// / dialect and mnemonic.
158- static const char *const qualifiedParameterPrinter = " $_printer << $_self" ;
167+ static const char *const qualifiedParameterPrinter =
168+ " $_printer.printQualifiedAttrOrType($_self)" ;
159169
160170// / Print an error when failing to parse an element.
161171// /
@@ -849,13 +859,13 @@ static void guardOnAnyOptional(FmtContext &ctx, MethodBody &os,
849859}
850860
851861void DefFormat::genCommaSeparatedPrinter (
852- ArrayRef<FormatElement *> args , FmtContext &ctx, MethodBody &os,
862+ ArrayRef<FormatElement *> params , FmtContext &ctx, MethodBody &os,
853863 function_ref<void (FormatElement *)> extra) {
854864 // Emit a space if necessary, but only if the struct is present.
855865 if (shouldEmitSpace || !lastWasPunctuation) {
856- bool allOptional = llvm::all_of (args , formatIsOptional);
866+ bool allOptional = llvm::all_of (params , formatIsOptional);
857867 if (allOptional)
858- guardOnAnyOptional (ctx, os, args );
868+ guardOnAnyOptional (ctx, os, params );
859869 os << tgfmt (" $_printer << ' ';\n " , &ctx);
860870 if (allOptional)
861871 os.unindent () << " }\n " ;
@@ -864,14 +874,16 @@ void DefFormat::genCommaSeparatedPrinter(
864874 // The first printed element does not need to emit a comma.
865875 os << " {\n " ;
866876 os.indent () << " bool _firstPrinted = true;\n " ;
867- for (FormatElement *arg : args ) {
877+ for (FormatElement *arg : params ) {
868878 ParameterElement *param = getEncapsulatedParameterElement (arg);
869879 if (param->isOptional ()) {
870880 param->genPrintGuard (ctx, os << " if (" ) << " ) {\n " ;
871881 os.indent ();
872882 }
873883 os << tgfmt (" if (!_firstPrinted) $_printer << \" , \" ;\n " , &ctx);
874884 os << " _firstPrinted = false;\n " ;
885+ if (param && shouldPrintQualified (param))
886+ param->setShouldBeQualified ();
875887 extra (arg);
876888 shouldEmitSpace = false ;
877889 lastWasPunctuation = true ;
0 commit comments