Page MenuHomePhabricator

[clang-format] Parse Verilog if statements
AcceptedPublic

Authored by sstwcw on Apr 9 2022, 3:47 AM.

Details

Summary

This patch mainly handles treating begin as block openers.

While and for statements will be handled in another patch.

Diff Detail

Unit TestsFailed

TimeTest
700 msx64 debian > SanitizerCommon-tsan-x86_64-Linux.Linux::decorate_proc_maps.cpp
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=thread -m64 -funwind-tables -ldl -g /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/decorate_proc_maps.cpp -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/sanitizer_common/tsan-x86_64-Linux/Linux/Output/decorate_proc_maps.cpp.tmp

Event Timeline

sstwcw created this revision.Apr 9 2022, 3:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2022, 3:47 AM
Herald added a subscriber: mgorny. · View Herald Transcript
sstwcw requested review of this revision.Apr 9 2022, 3:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2022, 3:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sstwcw added inline comments.Apr 9 2022, 3:55 AM
clang/lib/Format/FormatToken.h
1122

Does anyone know why this part gets aligned unlike the two lists above?

clang/lib/Format/FormatToken.h
373

Can't we do that with a type?

I'm not very happy about the alias, because you can still call Tok.getKind().

1122

Have you reformatted the other lines with the same config and revision?
If yes, my guess would be the missing comment.

1499

So you have a blacklist what is not a keyword? Seems a bit non future proof, new C++ keywords would have to be added here.

1561

For consistency reasons add the comment like above.

sstwcw marked 3 inline comments as done.Apr 11 2022, 3:20 PM
sstwcw added inline comments.
clang/lib/Format/FormatToken.h
373

The main problem I seek to solve with the alias thing is with tok::hash. In Verilog they use a backtick instead of a hash. At first I modified all places in the code to recognize the backtick. MyDeveloperDay said "year really not nice.. its like we can never use tok::hash again!" Using a type also requires modifying all instances of tok::hash if I get you right. How do I please everyone?

1122

It was the missing comment.

1499

This is a whitelist of what is a keyword.

sstwcw updated this revision to Diff 422049.Apr 11 2022, 3:22 PM
sstwcw marked 2 inline comments as done.

add comment

clang/lib/Format/FormatToken.h
373

Then you must hide Tok in the private part, so that no one can ever access Tok.getKind() accidentally.

1499

My bad. Go on.

sstwcw updated this revision to Diff 422496.Apr 13 2022, 6:06 AM
sstwcw edited the summary of this revision. (Show Details)

abandon alias

sstwcw marked an inline comment as done.Apr 13 2022, 6:12 AM
sstwcw added inline comments.
clang/lib/Format/FormatToken.h
373

In the new version the type of Tok itself gets changed instead. So an alias is not needed.

clang/lib/Format/FormatToken.h
1549

Shouldn't we add TT_MacroBlockBegin?

As first passes for adding a new language I think this looks pretty good.

`if (Keywords.isBlockBegin(*FormatTok, Style)) {`

I'm not a massive fan of handling l_brace and begin and end as the same thing, I might be tempted to handle them separately, as then its clear what is happening, but I don't think I'd block it for that.

sstwcw updated this revision to Diff 435771.Thu, Jun 9, 7:34 PM
sstwcw marked 2 inline comments as done.

add MacroBlockBegin

sstwcw marked an inline comment as done.Thu, Jun 9, 7:34 PM
sstwcw updated this revision to Diff 435773.Thu, Jun 9, 7:38 PM

use isVerilog

sstwcw updated this revision to Diff 435774.Thu, Jun 9, 7:53 PM
sstwcw updated this revision to Diff 435777.Thu, Jun 9, 8:11 PM
  • add brace
This revision is now accepted and ready to land.Mon, Jun 13, 3:42 AM