sstwcw updated this revision to Diff 443611. sstwcw added a comment. - don't check peeked token for null
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128709/new/ https://reviews.llvm.org/D128709 Files: clang/lib/Format/TokenAnnotator.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTestVerilog.cpp Index: clang/unittests/Format/FormatTestVerilog.cpp =================================================================== --- clang/unittests/Format/FormatTestVerilog.cpp +++ clang/unittests/Format/FormatTestVerilog.cpp @@ -71,6 +71,12 @@ TEST_F(FormatTestVerilog, If) { verifyFormat("if (x)\n" " x = x;"); + verifyFormat("unique if (x)\n" + " x = x;"); + verifyFormat("unique0 if (x)\n" + " x = x;"); + verifyFormat("priority if (x)\n" + " x = x;"); verifyFormat("if (x)\n" " x = x;\n" "x = x;"); @@ -137,6 +143,14 @@ " x = {x};\n" "else\n" " {x} = {x};"); + + // With attributes. + verifyFormat("(* x *) if (x)\n" + " x = x;"); + verifyFormat("(* x = \"x\" *) if (x)\n" + " x = x;"); + verifyFormat("(* x, x = \"x\" *) if (x)\n" + " x = x;"); } TEST_F(FormatTestVerilog, Preprocessor) { Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1457,6 +1457,23 @@ addUnwrappedLine(); return; } + + if (Style.isVerilog()) { + // Skip things that can exist before keywords like 'if' and 'case'. + while (true) { + if (FormatTok->isOneOf(Keywords.kw_priority, Keywords.kw_unique, + Keywords.kw_unique0)) { + nextToken(); + } else if (FormatTok->is(tok::l_paren) && + Tokens->peekNextToken()->is(tok::star)) { + parseParens(); + } else { + break; + } + } + } + + // Tokens that only make sense at the beginning of a line. switch (FormatTok->Tok.getKind()) { case tok::kw_asm: nextToken(); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3982,6 +3982,9 @@ Left.MatchingParen->endsSequence(tok::l_paren, tok::at)))) { return true; } + // Add space in attribute like `(* ASYNC_REG = "TRUE" *)`. + if (Left.endsSequence(tok::star, tok::l_paren) && Right.is(tok::identifier)) + return true; } if (Left.is(TT_ImplicitStringLiteral)) return Right.hasWhitespaceBefore();
Index: clang/unittests/Format/FormatTestVerilog.cpp =================================================================== --- clang/unittests/Format/FormatTestVerilog.cpp +++ clang/unittests/Format/FormatTestVerilog.cpp @@ -71,6 +71,12 @@ TEST_F(FormatTestVerilog, If) { verifyFormat("if (x)\n" " x = x;"); + verifyFormat("unique if (x)\n" + " x = x;"); + verifyFormat("unique0 if (x)\n" + " x = x;"); + verifyFormat("priority if (x)\n" + " x = x;"); verifyFormat("if (x)\n" " x = x;\n" "x = x;"); @@ -137,6 +143,14 @@ " x = {x};\n" "else\n" " {x} = {x};"); + + // With attributes. + verifyFormat("(* x *) if (x)\n" + " x = x;"); + verifyFormat("(* x = \"x\" *) if (x)\n" + " x = x;"); + verifyFormat("(* x, x = \"x\" *) if (x)\n" + " x = x;"); } TEST_F(FormatTestVerilog, Preprocessor) { Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1457,6 +1457,23 @@ addUnwrappedLine(); return; } + + if (Style.isVerilog()) { + // Skip things that can exist before keywords like 'if' and 'case'. + while (true) { + if (FormatTok->isOneOf(Keywords.kw_priority, Keywords.kw_unique, + Keywords.kw_unique0)) { + nextToken(); + } else if (FormatTok->is(tok::l_paren) && + Tokens->peekNextToken()->is(tok::star)) { + parseParens(); + } else { + break; + } + } + } + + // Tokens that only make sense at the beginning of a line. switch (FormatTok->Tok.getKind()) { case tok::kw_asm: nextToken(); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3982,6 +3982,9 @@ Left.MatchingParen->endsSequence(tok::l_paren, tok::at)))) { return true; } + // Add space in attribute like `(* ASYNC_REG = "TRUE" *)`. + if (Left.endsSequence(tok::star, tok::l_paren) && Right.is(tok::identifier)) + return true; } if (Left.is(TT_ImplicitStringLiteral)) return Right.hasWhitespaceBefore();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits