class
#include <slang/ast/Patterns.h>
Pattern Base class for "patterns", as used in pattern matching conditional statements and expressions.
Derived classes
- class ConstantPattern final
- Reresents a pattern that matches a given constant expression.
- class InvalidPattern final
- Represents an invalid pattern.
- class StructurePattern final
- Represents a pattern that matches a structure.
- class TaggedPattern final
- Represents a pattern that matches a member of a tagged union.
- class VariablePattern final
- Represents a pattern that stores its match in a pattern variable.
- class WildcardPattern final
- Represents a wildcard pattern that matches anything.
Public functions
- bool bad() const
- Returns true if the pattern had an error and is therefore invalid.
- ConstantValue eval(EvalContext& context, const ConstantValue& value, CaseStatementCondition conditionKind) const
- Evaluates the pattern under the given evaluation context.
-
template<typename T>T& as()
- Casts this pattern to the given concrete derived type.
-
template<typename T>const T& as() const
- Casts this pattern to the given concrete derived type.
-
template<typename T>T* as_if()
- Tries to cast this pattern to the given concrete derived type.
-
template<typename T>const T* as_if() const
- Tries to cast this pattern to the given concrete derived type.
-
template<typename TVisitor, typename... Args>decltype(auto) visit(TVisitor& visitor, Args && ... args) const
- 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.