Add WriteTo method to DelimitedSyntaxList<T>, IsPresent property, and WriteDelimitedList overloads to SyntaxWriter#15
Conversation
…teration patterns Agent-Logs-Url: https://github.com/jonathanvdc/MLIR.NET/sessions/6bc7d9d3-59a3-4d9e-a98f-2ed26061d21b Co-authored-by: jonathanvdc <9839946+jonathanvdc@users.noreply.github.com>
WriteTo method to DelimitedSyntaxList<T> to eliminate manual iteration boilerplate
jonathanvdc
left a comment
There was a problem hiding this comment.
Looks great. Can you add overloaded methods to SyntaxWriter for every type of DelimitedSyntaxList that may need to be written? Then have callers invoke those overloads. The idea is to spare callers from having to directly invoke DelimitedSyntaxList.WriteTo with a lambda, creating cleaner code.
…se them Agent-Logs-Url: https://github.com/jonathanvdc/MLIR.NET/sessions/0f179478-69f1-4b5b-b698-33c13ee1012d Co-authored-by: jonathanvdc <9839946+jonathanvdc@users.noreply.github.com>
Done in 03703ff. Added three |
WriteTo method to DelimitedSyntaxList<T> to eliminate manual iteration boilerplateWriteTo method to DelimitedSyntaxList<T> and WriteDelimitedList overloads to SyntaxWriter
jonathanvdc
left a comment
There was a problem hiding this comment.
Nice work. Also add a property to DelimitedSyntaxList that tells us whether the list exists or not (i.e., whether the opening token is null). Use that property instead of directly checking if the opening token is null. Give it an appropriate name.
… checks with it Agent-Logs-Url: https://github.com/jonathanvdc/MLIR.NET/sessions/fed83386-d728-477b-ab0a-091f423d1e9d Co-authored-by: jonathanvdc <9839946+jonathanvdc@users.noreply.github.com>
Done in 298bdb8. Added |
WriteTo method to DelimitedSyntaxList<T> and WriteDelimitedList overloads to SyntaxWriterWriteTo method to DelimitedSyntaxList<T>, IsPresent property, and WriteDelimitedList overloads to SyntaxWriter
The pattern of manually iterating a
DelimitedSyntaxList— null-checkingOpenToken, looping with separator interleaving, writingCloseToken— was duplicated across the runtime and in code emitted by the generator.Changes
DelimitedSyntaxList<T>— NewWriteTo(SyntaxWriter, string openLeadingTrivia, Action<T, SyntaxWriter, string> writeElement)method. No-ops when the list is not present; otherwise writes open/elements/separators/close with correct spacing. NewIsPresentproperty (=> OpenToken.HasValue) that indicates whether the list has delimiters in the source, replacing directOpenToken == nullchecks throughout.SyntaxWriter— NewWriteDelimitedListoverloads for each concrete list type used in the codebase:DelimitedSyntaxList<SyntaxToken>,DelimitedSyntaxList<NamedAttributeSyntax>, andDelimitedSyntaxList<BlockArgumentSyntax>. Each overload delegates toDelimitedSyntaxList<T>.WriteTowith the appropriate element-writing logic, so callers never need to supply a lambda.GenericOperationBodySyntax— Replaced three manual iteration blocks (OperandList,SuccessorList,Attributes) withwriter.WriteDelimitedList(...)calls.BlockSyntax— Replaced manualArgumentsiteration (and now-redundantOpenToken != nullguard) with awriter.WriteDelimitedList(...)call.DialectSourceEmitter—GenerateDelimitedNamedAttributeWriteTo/GenerateDelimitedTokenWriteTonow emit a singlewriter.WriteDelimitedList(...)call instead of a multi-lineif/forblock.Usage
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.