slang::ast::CaseStatement class final

Represents a case statement.

Base classes

class Statement
The base class for all statements in SystemVerilog.

Public types

struct ItemGroup
A group of items in a case statement.
struct ItemAnalysis
The results of analyzing the item expressions of a case statement or other case-like construct.
using ItemDiagFunc = function_ref<Diagnostic&(DiagCode, SourceRange)>
A callback used to issue diagnostics found while analyzing case items.
using ItemDupFilter = function_ref<bool(const Expression&, const ConstantValue&)>
A callback used to filter whether a duplicate item should be diagnosed.

Public static functions

static void analyzeItems(EvalContext& evalContext, CaseStatementCondition condition, const Expression& caseExpr, std::span<const Expression*const> items, bool hasDefault, bool isStatement, ItemAnalysis& result, ItemDiagFunc addDiag = {}, ItemDupFilter dupFilter = {})
Analyzes the item expressions of a case statement or other case-like construct (case generate, property case, randsequence case), collecting their constant values and optionally issuing lint diagnostics for duplicate items, missing enum values, and literals with unknown bits that don't act as wildcards.

Public functions

std::pair<const Statement*, bool> getKnownBranch(EvalContext& context) const
If the case expression and all items are constant, this returns the branch that will be taken, if any.

Public variables

const Expression& expr
The controlling case condition.
std::span<ItemGroup const > items
A list of items to match against.
const Statement* defaultCase
An optional default case item that applies if no items match.
CaseStatementCondition condition
The kind of case condition to evaluate.
UniquePriorityCheck check
An optional unique or priority check that should be applied to the condition.

Function documentation

static void slang::ast::CaseStatement::analyzeItems(EvalContext& evalContext, CaseStatementCondition condition, const Expression& caseExpr, std::span<const Expression*const> items, bool hasDefault, bool isStatement, ItemAnalysis& result, ItemDiagFunc addDiag = {}, ItemDupFilter dupFilter = {})

Analyzes the item expressions of a case statement or other case-like construct (case generate, property case, randsequence case), collecting their constant values and optionally issuing lint diagnostics for duplicate items, missing enum values, and literals with unknown bits that don't act as wildcards.

Parameters
evalContext The context to use for evaluating item expressions
condition The kind of case comparison performed
caseExpr The controlling case expression
items All of the item expressions, in declaration order
hasDefault True if the construct has a default item
isStatement True if this is an actual case statement, which means it could be turned into a wildcard case if desired
result The results of the analysis
addDiag If provided, used to issue lint diagnostics
dupFilter If provided, used to decide whether to diagnose a given duplicate

std::pair<const Statement*, bool> slang::ast::CaseStatement::getKnownBranch(EvalContext& context) const

If the case expression and all items are constant, this returns the branch that will be taken, if any.

Otherwise returns a nullptr statement and false for the second item in the pair.