This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Indent Verilog struct literal on new line
ClosedPublic

Authored by sstwcw on Jun 10 2023, 8:47 AM.

Details

Summary

Before:

c = //
'{default: 0};

After:

c = //
    '{default: 0};

If the line has to be broken, the continuation part should be
indented. Before this fix, it was not the case if the continuation
part was a struct literal. The rule that caused the problem was added
in 783bac6b. It was intended for aligning the field labels in
ProtoBuf. The type TT_DictLiteral was only for colons back then, so
the program didn't have to check whether the token was a colon when it
was already type TT_DictLiteral. Now the type applies to more
things including the braces enclosing a dictionary literal. In
Verilog, struct literals start with a quote. The quote is regarded as
an identifier by the program. So the rule for aligning the fields in
ProtoBuf applied to this situation by mistake.

Diff Detail

Event Timeline

sstwcw created this revision.Jun 10 2023, 8:47 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptJun 10 2023, 8:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sstwcw requested review of this revision.Jun 10 2023, 8:47 AM

So I assume your ' is a 'DictLiteral`? Does it have to be one? I don't know what else maybe a DictLiteral in what language and am not so comfortable with this change.

So I assume your ' is a 'DictLiteral`?

The brace following the quote is a DictLiteral. The quote is a tok::identifier and TT_Unknown.

Does it have to be one?

The brace is set to this type when used this way in all other languages. I don't want to make an exception.

I don't know what else maybe a DictLiteral in what language and am not so comfortable with this change.

I changed the patch to use the new behavior only for Verilog.

The DictLiteral type gets set on the braces and colons in literals where the field names and values are separated by colons in all languages that have them. In addition, because the protocol buffer text format allows angular brackets as braces, the type is also set on those angular brackets for that language.

sstwcw updated this revision to Diff 533617.Jun 22 2023, 8:08 AM
  • limit change to Verilog
This revision is now accepted and ready to land.Jun 22 2023, 12:35 PM
This revision was automatically updated to reflect the committed changes.