ScopeBody
class ScopeBody
Represents a body that introduces a new scope for its contained body.
constructor ScopeBody
Construct a new ScopeBody.
| ScopeBody | ( | const std::shared_ptr< Scope > & inner_scope, | |
| Body body | ); |
| PARAMETER | DESCRIPTION |
|---|---|
inner_scope |
|
body |
The body to wrap. |
method add
| void add | ( | std::shared_ptr< Constant > constant | ); |
| PARAMETER | DESCRIPTION |
|---|---|
constant |
method append
Append a body to the contained body.
| void append | ( | Body inner_body | ); |
| PARAMETER | DESCRIPTION |
|---|---|
inner_body |
The body to append. |
method cloneconst virtual
| virtual Body clone | ( | const CloneContext & context | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
context |
| RETURNS | DESCRIPTION |
|---|---|
Body |
method createstatic
Create a new ScopeBody.
| static Body create | ( | const std::shared_ptr< Scope > & containing_scope, | |
| Body body | ); |
| PARAMETER | DESCRIPTION |
|---|---|
containing_scope |
The scope containing the ScopeBody. |
body |
The body to wrap. |
| RETURNS | DESCRIPTION |
|---|---|
Body |
The ScopeBody. |
method encodevirtual
Encode the BodyElement into a byte string.
The default implementation does nothing. Subclasses that represent data or instructions should override this method.
| virtual void encode | ( | std::string & bytes, | |
| const Memory * memory | ); |
| PARAMETER | DESCRIPTION |
|---|---|
bytes |
The byte string to encode into. |
memory |
The memory context for encoding. |
method evaluate_processvirtual
Evaluate the body element after all sub-body-elements and sub-expressions have been evaluated.
Returns the contained body if it is fully evaluated, {} otherwise. Sub-classes should override this method if the scope cannot be discarded once the contained body is fully evaluated.
| virtual std::optional< Body > evaluate_process | ( | const EvaluationContext & context | ); |
| PARAMETER | DESCRIPTION |
|---|---|
context |
The evaluation context. |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Body > |
The Body to replace this BodyElement with, {} if no replacement is needed. |
method fully_evaluatedvirtual
Check if the body and all sub-body-elements and sub-expressions have been fully evaluated.
The default implementation uses traverse() to check all sub-body-elements and sub-expressions and returns true if they are all fully evaluated.
| virtual bool fully_evaluated | ( | ); |
| RETURNS | DESCRIPTION |
|---|---|
bool |
|
method inner_scopeconst
Get the inner scope of the ScopeBody.
| std::shared_ptr< Scope > inner_scope | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::shared_ptr< Scope > |
The inner_scope. |
method offsetconst virtual
Get the offset of the BodyElement within its entity.
| virtual SizeRange offset | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
SizeRange |
The offset of the BodyElement. |
method resolvevirtual
Resolve all names in the BodyElement.
If a name cannot be resolved, an error should be reported via DiagnosticOutput and the BodyElement marked as invalid, or an exception should be thrown.
The default implementation calls resolve() on all sub-body-elements and sub-expressions using traverse().
| virtual void resolve | ( | Scope * scope, | |
| Entity * containing_entity | ); |
| PARAMETER | DESCRIPTION |
|---|---|
scope |
The scope to resolve names in. |
containing_entity |
The entity that contains the BodyElement. |
method serializeconst virtual
Serialize the BodyElement to a stream.
Subclasses must implement this method.
| virtual void serialize | ( | std::ostream & stream, | |
| const std::string & prefix | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
stream |
The stream to serialize to. |
prefix |
The prefix for each line of the serialized output. |
method size_rangeconst virtual
Get the size range of the BodyElement.
| virtual SizeRange size_range | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
SizeRange |
The size range of the BodyElement. |
method traversevirtual
Traverse the BodyElement.
This function is used by the default implementations of resolve() and expand_calls(). Unless a subclass overrides both of these methods, it should override traverse().
| virtual void traverse | ( | std::function< void(Body &)> body_callable, | |
| std::function< void(Expression &)> expression_callable | ); |
| PARAMETER | DESCRIPTION |
|---|---|
body_callable |
A callable to apply to each sub-body-element. |
expression_callable |
A callable to apply to each sub-expression. |
member bodyprotected
The body contained within the ScopeBody.
member constantsprotected
member inner_scope_protected
The scope introduced by the ScopeBody.