ScopeExpression
class ScopeExpression
Represents an expression that introduces a new scope for its contained expression.
constructor ScopeExpression
Construct a new ScopeExpression.
| ScopeExpression | ( | const std::shared_ptr< Scope > & inner_scope, | |
| Expression expression | ); |
| PARAMETER | DESCRIPTION |
|---|---|
inner_scope |
|
expression |
The expression to wrap. |
method add
| void add | ( | std::shared_ptr< Constant > constant | ); |
| PARAMETER | DESCRIPTION |
|---|---|
constant |
method cloneconst virtual
Create a deep copy of the expression.
A subclass must override this method if it can occur in a macro or function definition, .repeat body, or instruction encoding.
| virtual Expression clone | ( | const CloneContext & context | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
context |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
A shared pointer to the cloned expression. |
method createstatic
Create a new ScopeExpression.
| static Expression create | ( | const std::shared_ptr< Scope > & containing_scope, | |
| Expression expression | ); |
| PARAMETER | DESCRIPTION |
|---|---|
containing_scope |
The scope containing the ScopeExpression. |
expression |
The expression to wrap. |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
The ScopeExpression. |
method evaluate_processvirtual protected
Process the evaluation of the expression.
This method is called by the default implementation of evaluate() after calling evaluate() on all sub-expressions.
| virtual std::optional< Expression > evaluate_process | ( | const EvaluationContext & context | ); |
| PARAMETER | DESCRIPTION |
|---|---|
context |
The evaluation context. |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Expression > |
If the expression changed, returns the new expression, otherwise {}. |
method has_valueconst virtual
Check if the value of the expression is known.
The default implementation returns true if value() returns a value, false otherwise. If the value is expensive to compute, subclasses may override this method to provide a more efficient implementation.
| virtual bool has_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
bool |
|
method inner_scopeconst
Get the inner scope of the ScopeExpression.
| std::shared_ptr< Scope > inner_scope | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::shared_ptr< Scope > |
The inner_scope. |
method maximum_valueconst virtual
Get the minimum possible value of the expression.
The default implementation returns the value of the expression if it is known, or {} otherwise. Subclasses should override this method if they can determine a minimum value without knowing the exact value of the expression.
| virtual std::optional< Value > maximum_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The minimum possible value of the expression. if it can be determined, {} otherwise. |
method minimum_valueconst virtual
Get the maximum possible value of the expression.
The default implementation returns the value of the expression if it is known, or {} otherwise. Subclasses should override this method if they can determine a maximum value without knowing the exact value of the expression.
| virtual std::optional< Value > minimum_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The maximum possible value of the expression if it can be determined, {} otherwise. |
method resolvevirtual protected
Resolve all names in the expression.
The default implementation calls resolve() on all sub-expressions using traverse().
If a name cannot be resolved, either an error should be reported via DiagnosticOutput and the expression marked as invalid, or an exception should be thrown.
| virtual 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 serialize_subconst virtual protected
Serialize the expression to a stream.
This method must be implemented by derived classes.
| virtual void serialize_sub | ( | std::ostream & stream | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
stream |
The stream to serialize to. |
method traversevirtual protected
Call a method on all sub-expressions of this expression.
It is used by the default implementations of resolve() and expand_calls(). Unless a subclass has no sub-expressions or overrides both of these methods, it should override traverse().
| virtual void traverse | ( | std::function< void(Expression &)> callable | ); |
| PARAMETER | DESCRIPTION |
|---|---|
callable |
A callable to apply to each sub-expression. |
method typeconst virtual
Get the type of the expression's value.
The default implementation returns the type of the value of the expression if it is known, or {} otherwise. Subclasses should override this method if they can determine the type of the expression without knowing the exact value of the expression.
| virtual 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 valueconst virtual
Get the value of the expression if it is known.
Subclasses should override this method. The default implementation returns {}.
| virtual std::optional< Value > value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The value of the expression, if it is known. |
member constantsprotected
member expressionprotected
The expression contained within the ScopeExpression.
member inner_scope_protected
The scope introduced by the ScopeExpression.