slang::ast::Pattern class

Base class for "patterns", as used in pattern matching conditional statements and expressions.

Derived classes

class ConstantPattern
Reresents a pattern that matches a given constant expression.
class InvalidPattern
Represents an invalid pattern.
class StructurePattern
Represents a pattern that matches a structure.
class TaggedPattern
Represents a pattern that matches a member of a tagged union.
class VariablePattern
Represents a pattern that stores its match in a pattern variable.
class WildcardPattern
Represents a wildcard pattern that matches anything.

Public functions

auto bad() const -> bool
Returns true if the pattern had an error and is therefore invalid.
auto eval(EvalContext& context, const ConstantValue& value, CaseStatementCondition conditionKind) const -> ConstantValue
Evaluates the pattern under the given evaluation context.
template<typename T>
auto as() -> T&
Casts this pattern to the given concrete derived type.
template<typename T>
auto as() const -> const T&
Casts this pattern to the given concrete derived type.
template<typename T>
auto as_if() -> T*
Tries to cast this pattern to the given concrete derived type.
template<typename T>
auto as_if() const -> const T*
Tries to cast this pattern to the given concrete derived type.
template<typename TVisitor, typename... Args>
auto visit(TVisitor& visitor, Args && ... args) const -> decltype(auto)
Visits this pattern's concrete derived type via the provided visitor object.

Public variables

PatternKind kind
The kind of pattern represented by this instance.
const syntax::SyntaxNode* syntax
The syntax node used to create the pattern, if it came from source code.
SourceRange sourceRange
The source range where this pattern occurs, if it came from source code.

Function documentation

ConstantValue slang::ast::Pattern::eval(EvalContext& context, const ConstantValue& value, CaseStatementCondition conditionKind) const

Evaluates the pattern under the given evaluation context.

Any errors that occur will be stored in the evaluation context instead of issued to the compilation.

template<typename T>
T& slang::ast::Pattern::as()

Casts this pattern to the given concrete derived type.

Asserts that the type is appropriate given this pattern's kind.

template<typename T>
const T& slang::ast::Pattern::as() const

Casts this pattern to the given concrete derived type.

Asserts that the type is appropriate given this pattern's kind.

template<typename T>
T* slang::ast::Pattern::as_if()

Tries to cast this pattern to the given concrete derived type.

If the type is not appropriate given this pattern's kind, returns nullptr.

template<typename T>
const T* slang::ast::Pattern::as_if() const

Tries to cast this pattern to the given concrete derived type.

If the type is not appropriate given this pattern's kind, returns nullptr.