BodyElement
class BodyElement
Abstract base class for all Body types.
class NotFullyEvaluatedExceptionprivate
method whatconst
| const char * what | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
const char * |
constructor BodyElement
Construct a BodyElement with unknown location and size.
| BodyElement | ( | ); |
constructor BodyElement
Construct a BodyElement with a specified size range.
| BodyElement | ( | const Location & location, | |
| const SizeRange & size_range = {} | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
|
size_range |
The size range of the BodyElement. |
destructor ~BodyElementvirtual
Destroy the BodyElement.
| virtual ~BodyElement | ( | ); |
method append_subvirtual
Append a BodyElement to this body directly, if supported.
If appending is supported, this method returns the resulting body. Otherwise, it returns an empty optional.
The default implementation does not support appending. If a subclass supports appending, it should override this method.
| virtual std::pair< bool, std::optional< Body > > append_sub | ( | const Body & body, | |
| const Body & element | ); |
| PARAMETER | DESCRIPTION |
|---|---|
body |
The body to append to. |
element |
The element to append. |
| RETURNS | DESCRIPTION |
|---|---|
std::pair< bool, std::optional< Body > > |
The resulting body, or {} if not supported. |
method cloneconst virtual
| virtual Body clone | ( | const CloneContext & context | ) const | = 0; |
| PARAMETER | DESCRIPTION |
|---|---|
context |
| RETURNS | DESCRIPTION |
|---|---|
Body |
method collect_objectsconst virtual
| virtual void collect_objects | ( | std::unordered_set< Object * > & objects | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
objects |
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 enter_namesvirtual
Enter names defined by the BodyElement in the given scope.
This method is used to enter names into the given scope.
The default implementation calls enter_names() on all sub-body-elements using traverse(). Subclasses that define names should override this method.
| virtual void enter_names | ( | Scope * scope, | |
| Entity * containing_entity | ); |
| PARAMETER | DESCRIPTION |
|---|---|
scope |
The scope to enter names into. |
containing_entity |
The entity that contains the BodyElement. |
method evaluatevirtual
Evaluate the BodyElement in a given context.
Subclasses must implement this method.
If an error occurs during evaluation, either an error should be reported via DiagnosticOutput and the BodyElement marked as invalid, or an exception should be thrown.
| virtual std::optional< Body > evaluate | ( | 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 evaluate_processvirtual
Evaluate the body element after all sub-body-elements and sub-expressions have been evaluated.
The default implementation does nothing.
| 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 expand_callsvirtual
Expand macro and function calls in the BodyElement.
The default implementation calls expand_calls() on all sub-body-elements and sub-expressions using traverse().
If a macro or function call cannot be expanded, either an error should be reported via DiagnosticOutput and the BodyElement marked as invalid, or an exception should be thrown.
| virtual std::optional< Body > expand_calls | ( | ); |
| 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 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 | = 0; |
| PARAMETER | DESCRIPTION |
|---|---|
stream |
The stream to serialize to. |
prefix |
The prefix for each line of the serialized output. |
method sizeconst
Get the size of the BodyElement, if it is known.
| std::optional< uint64_t > size | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< uint64_t > |
The size of the BodyElement, {} if it is unknown. |
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 location
The location of the BodyElement in the source code.
member offset_protected
The offset of the BodyElement within its entity.
member size_range_protected
The size range of the BodyElement.
member valid
Indicates whether the BodyElement is valid.
If an error occurs during evaluation, this flag should be set to false. This allows the BodyElement to be used in further evaluations without causing additional errors.
class NotFullyEvaluatedExceptionprivate
method whatconst
| const char * what | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
const char * |