Skip to content

Commit

Permalink
PR review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Churkin committed Sep 18, 2024
1 parent 1ee209a commit f59af6a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
27 changes: 7 additions & 20 deletions source/parsing/Parser_members.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2152,32 +2152,23 @@ ConstraintItemSyntax* Parser::parseConstraintItem(bool allowBlock, bool isTopLev
case TokenKind::ForeachKeyword: {
auto keyword = consume();
auto& vars = parseForeachLoopVariables();
auto constraints = parseConstraintItem(true, false);
if (constraints)
return &factory.loopConstraint(keyword, vars, *constraints);
else
return nullptr;
return &factory.loopConstraint(keyword, vars, *parseConstraintItem(true, false));
}
case TokenKind::IfKeyword: {
auto ifKeyword = consume();
auto openParen = expect(TokenKind::OpenParenthesis);
auto& condition = parseExpression();
auto closeParen = expect(TokenKind::CloseParenthesis);
auto constraints = parseConstraintItem(true, false);
if (!constraints)
return nullptr;
auto& constraints = *parseConstraintItem(true, false);

ElseConstraintClauseSyntax* elseClause = nullptr;
if (peek(TokenKind::ElseKeyword)) {
auto elseKeyword = consume();
auto elseConstraints = parseConstraintItem(true, false);
if (!elseConstraints)
return nullptr;

elseClause = &factory.elseConstraintClause(elseKeyword, *elseConstraints);
elseClause = &factory.elseConstraintClause(elseKeyword,
*parseConstraintItem(true, false));
}
return &factory.conditionalConstraint(ifKeyword, openParen, condition, closeParen,
*constraints, elseClause);
constraints, elseClause);
}
case TokenKind::UniqueKeyword: {
auto keyword = consume();
Expand Down Expand Up @@ -2221,16 +2212,12 @@ ConstraintItemSyntax* Parser::parseConstraintItem(bool allowBlock, bool isTopLev
auto expr =
&parseSubExpression(ExpressionOptions::ConstraintContext | ExpressionOptions::AllowDist, 0);
// checking that tokens were extracted during expression parsing
if (curr == peek())
if (curr == peek() && !allowBlock)
return nullptr;

if (peek(TokenKind::MinusArrow)) {
auto arrow = consume();
auto constraints = parseConstraintItem(true, false);
if (constraints)
return &factory.implicationConstraint(*expr, arrow, *constraints);
else
return nullptr;
return &factory.implicationConstraint(*expr, arrow, *parseConstraintItem(true, false));
}

return &factory.expressionConstraint(Token(), *expr, expect(TokenKind::Semicolon));
Expand Down
12 changes: 4 additions & 8 deletions source/parsing/Parser_statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,16 +765,12 @@ RandCaseStatementSyntax& Parser::parseRandCaseStatement(NamedLabelSyntax* label,
Token curr = peek();
auto& expr = parseExpression();
auto colon = expect(TokenKind::Colon);
const auto loc = peek().location();
auto& stmt = parseStatement();
if (stmt.kind == SyntaxKind::EmptyStatement &&
stmt.as<EmptyStatementSyntax>().semicolon.isMissing() && loc == peek().location()) {
// If there is no consumed tokens then expression and statement were not parsed
if (curr == peek())
skipToken(std::nullopt);
}

itemBuffer.push_back(&factory.randCaseItem(expr, colon, stmt));
// If there is no consumed tokens then expression was not parsed
if (curr == peek())
break;
}

auto endcase = expect(TokenKind::EndCaseKeyword);
Expand Down Expand Up @@ -1004,7 +1000,7 @@ StatementSyntax& Parser::parseRandSequenceStatement(NamedLabelSyntax* label, Att
productions.push_back(&parseProduction());
// If there is no consumed tokens then production was not parsed
if (curr == peek())
break;
skipToken(std::nullopt);
}

if (productions.empty())
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/parsing/MemberParsingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,5 +1506,5 @@ program A ; final randcase 0 : matches A = # 0 0 ; endcase endprogram
)";
parseCompilationUnit(text);

REQUIRE(diagnostics.size() == 18);
REQUIRE(diagnostics.size() == 16);
}

0 comments on commit f59af6a

Please sign in to comment.