Expression
class Expression
Represents an expression. This is the class other parts of the program interact with. It is a wrapper around the BaseExpression hierarchy.
constructor Expression
Construct a void Expression.
| Expression | ( | ); |
constructor Expression
Construct an Expression from a BaseExpression.
| Expression | ( | std::shared_ptr< BaseExpression > expression | ); |
| PARAMETER | DESCRIPTION |
|---|---|
expression |
The BaseExpression to wrap. |
constructor Expression
Construct an Expression by parsing it from a Tokenizer.
| Expression | ( | Tokenizer & tokenizer | ); |
| PARAMETER | DESCRIPTION |
|---|---|
tokenizer |
The Tokenizer to use for parsing the expression. |
method asconst
Get the expression as a specific type.
| const T * as | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
const T * |
A pointer to the expression as type T, or nullptr if it is not of that type. |
method as
| T * as | ( | ); |
| RETURNS | DESCRIPTION |
|---|---|
T * |
method cloneconst
Create a deep copy of the expression.
If the expression does not change during evaluation, it may be reused instead of cloned.
| Expression clone | ( | const CloneContext & context | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
context |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
A new Expression that is a deep copy of this one. |
method createstatic
| static Expression create | ( | const Token & token | ); |
| PARAMETER | DESCRIPTION |
|---|---|
token |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
method evaluate
Evaluate the expression in a given context.
| void evaluate | ( | const EvaluationContext & context | ); |
| PARAMETER | DESCRIPTION |
|---|---|
context |
The evaluation context. |
method expand_calls
Expand function calls in the expression.
If a function call cannot be expanded, either an error should be reported via DiagnosticOutput and the expression marked as invalid, or an exception should be thrown.
| std::optional< Expression > expand_calls | ( | ); |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Expression > |
The Expression to replace this Expression with, {} if no replacement is needed. |
method has_typeconst
Check if the expression has a specific type.
If type is an aggregate type (like Value::INTEGER), this method will return true if the expression's type is a subtype of it.
| std::optional< bool > has_type | ( | Value::Type type | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
type |
The type to check against. |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< bool > |
|
method has_valueconst
Check if the value of the expression is known.
| bool has_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
bool |
|
method isconst
Check if the expression is of a specific type.
| bool is | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
bool |
|
method locationconst
Get the location in the source code where the expression was defined.
| const Location & location | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
const Location & |
method maximum_valueconst
Get the maximum possible value of the expression.
| std::optional< Value > maximum_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The maximum possible value of the expression if it can be determined, {} otherwise. |
method minimum_valueconst
Get the minimum possible value of the expression.
| std::optional< Value > minimum_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The minimum possible value of the expression. if it can be determined, {} otherwise. |
method resolve
Resolve all names in the expression.
| void resolve | ( | Scope * scope, | |
| Entity * containing_entity | ); |
| PARAMETER | DESCRIPTION |
|---|---|
scope |
The scope to resolve names in. |
containing_entity |
The entity that contains the expression. |
method serializeconst
Serialize the expression to a stream.
| void serialize | ( | std::ostream & stream | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
stream |
The output stream to serialize the expression to. |
method typeconst
Get the type of the expression's value.
| std::optional< Value::Type > type | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value::Type > |
The type of the expression's value if it can be determined, {} otherwise. |
method type_nameconst
| std::string_view type_name | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::string_view |
method validconst
Check if the expression is valid.
If a translation error occurred while translating the expression, it is considered invalid. This allows the expression to be used in further evaluations without causing additional errors.
| bool valid | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
bool |
True if the expression is valid, false otherwise. |
method valueconst
Get the value of the expression.
| std::optional< Value > value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The value of the expression if it is known, {} otherwise. |
method variable_nameconst
If it is a variable expression, return the variable name.
| Symbol variable_name | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
Symbol |
The variable name, or the empty Symbol if it isn't a variable expression. |
member expressionprivate
A shared pointer to the BaseExpression that this Expression wraps.
member void_expressionstatic private
A shared pointer to a void expression, used for constructing void expressions.