[PATCH] D147895: [clang-format] Handle Verilog assertions and loops

sstwcw via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 9 16:34:20 PDT 2023


sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, owenpan, rymiel.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
sstwcw requested review of this revision.

Assert statements in Verilog can optionally have an else part.  We
handle them like for `if` statements, except that an `if` statement in
the else part of an `assert` statement doesn't get merged with the
`else` keyword.  Like this:

  assert (x)
    $info();
  else
    if (y)
      $info();
    else if (z)
      $info();
    else
      $info();

`foreach` and `repeat` are now handled like for or while loops.

We used the type `TT_ConditionLParen` to mark the condition part so
they are handled in the same way as the condition part of an `if`
statement.  When the code being formatted is not in Verilog, it is
only set for `if` statements, not loops.  It's because loop conditions
are currently handled slightly differently, and existing behavior is
not supposed to change.  We formatted all files ending in `.cpp` and
`.h` in the repository with and without this change.  It showed that
setting the type for `if` statements doesn't change existing behavior.

And we noticed that we forgot to make the program print the list of
tokens when the number is not correct in `TokenAnnotatorTest`.  It's
fixed now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147895

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147895.512044.patch
Type: text/x-patch
Size: 13870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230409/b67dc356/attachment-0001.bin>


More information about the cfe-commits mailing list