Page MenuHomePhabricator

[clang-format] Handle C# generic type constraints

Authored by jbcoe on Mar 18 2020, 8:24 AM.



Treat each C# generic type constraint, where T: ..., as a line.

Add C# keyword: where

Add Token Types: CSharpGenericTypeConstraint, CSharpGenericTypeConstraintColon, CSharpGenericTypeConstraintComma.

This patch does not wrap generic type constraints well, that will be addressed in a follow up patch.

Diff Detail

Event Timeline

jbcoe created this revision.Mar 18 2020, 8:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2020, 8:24 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
krasimir requested changes to this revision.Mar 19 2020, 2:50 AM
krasimir added inline comments.

If you remove the reference from parseRecored (see comment there), consider removing the ConsumeBrace argument -- all other references set it to false.
We can add this later when we need it.


No tests fail if I remove this if.
Consider adding a test case for this or removing.
As this is the first in a series of patches, maybe we can add this in a later patch.


consider moving this test case to the new CSharpGenericTypeConstraints, re-formatted (as I understand it, this patch forces a newline before the while).

This revision now requires changes to proceed.Mar 19 2020, 2:50 AM
jbcoe updated this revision to Diff 251349.Mar 19 2020, 5:20 AM

Address review comments to move deleted test and remove redundant code.

Redundant call to parseCSharpGenericTypeConstraint was used for free functions which are not legal in C#.

jbcoe edited the summary of this revision. (Show Details)Mar 19 2020, 5:21 AM
jbcoe marked 3 inline comments as done.
krasimir accepted this revision.Mar 19 2020, 5:37 AM

Thank you!

This revision is now accepted and ready to land.Mar 19 2020, 5:37 AM
Closed by commit rGdcbcec4822f4: [clang-format] Handle C# generic type constraints (authored by Jonathan Coe <>). · Explain WhyMar 19 2020, 6:27 AM
This revision was automatically updated to reflect the committed changes.