Skip to content

BodyElement

INCLUDE FILE
#include "Body/BodyElement.h"

class BodyElement

Abstract base class for all Body types.

DEFINITION
class BodyElement;

class NotFullyEvaluatedExceptionprivate

DEFINITION
class NotFullyEvaluatedException;

method whatconst

DEFINITION
const char * what ( ) const;
RETURNSDESCRIPTION
const char *

constructor BodyElement

Construct a BodyElement with unknown location and size.

DEFINITION
BodyElement ( );

constructor BodyElement

Construct a BodyElement with a specified size range.

DEFINITION
BodyElement ( const Location & location,
const SizeRange & size_range = {} );
PARAMETERDESCRIPTION
location
size_range

The size range of the BodyElement.

destructor ~BodyElementvirtual

Destroy the BodyElement.

DEFINITION
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.

DEFINITION
virtual std::pair< bool, std::optional< Body > >  append_sub ( const Body & body,
const Body & element );
PARAMETERDESCRIPTION
body

The body to append to.

element

The element to append.

RETURNSDESCRIPTION
std::pair< bool, std::optional< Body > >

The resulting body, or {} if not supported.

method cloneconst virtual

DEFINITION
virtual Body  clone ( const CloneContext & context ) const = 0;
PARAMETERDESCRIPTION
context
RETURNSDESCRIPTION
Body

method collect_objectsconst virtual

DEFINITION
virtual void  collect_objects ( std::unordered_set< Object * > & objects ) const;
PARAMETERDESCRIPTION
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.

DEFINITION
virtual void  encode ( std::string & bytes,
const Memory * memory );
PARAMETERDESCRIPTION
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.

DEFINITION
virtual void  enter_names ( Scope * scope,
Entity * containing_entity );
PARAMETERDESCRIPTION
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.

DEFINITION
virtual std::optional< Body >  evaluate ( const EvaluationContext & context );
PARAMETERDESCRIPTION
context

The evaluation context.

RETURNSDESCRIPTION
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.

DEFINITION
virtual std::optional< Body >  evaluate_process ( const EvaluationContext & context );
PARAMETERDESCRIPTION
context

The evaluation context.

RETURNSDESCRIPTION
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.

DEFINITION
virtual std::optional< Body >  expand_calls ( );
RETURNSDESCRIPTION
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.

DEFINITION
virtual bool  fully_evaluated ( );
RETURNSDESCRIPTION
bool

true if the BodyElement is fully evaluated, false otherwise.

method offsetconst virtual

Get the offset of the BodyElement within its entity.

DEFINITION
virtual SizeRange  offset ( ) const;
RETURNSDESCRIPTION
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().

DEFINITION
virtual void  resolve ( Scope * scope,
Entity * containing_entity );
PARAMETERDESCRIPTION
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.

DEFINITION
virtual void  serialize ( std::ostream & stream,
const std::string & prefix ) const = 0;
PARAMETERDESCRIPTION
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.

DEFINITION
std::optional< uint64_t >  size ( ) const;
RETURNSDESCRIPTION
std::optional< uint64_t >

The size of the BodyElement, {} if it is unknown.

method size_rangeconst virtual

Get the size range of the BodyElement.

DEFINITION
virtual SizeRange  size_range ( ) const;
RETURNSDESCRIPTION
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().

DEFINITION
virtual void  traverse ( std::function< void(Body &)>  body_callable,
std::function< void(Expression &)>  expression_callable );
PARAMETERDESCRIPTION
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.

DEFINITION
Location  location;

member offset_protected

The offset of the BodyElement within its entity.

DEFINITION
SizeRange  offset_;

member size_range_protected

The size range of the BodyElement.

DEFINITION
SizeRange  size_range_;

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.

DEFINITION
bool  valid;

class NotFullyEvaluatedExceptionprivate

DEFINITION
class NotFullyEvaluatedException;

method whatconst

DEFINITION
const char * what ( ) const;
RETURNSDESCRIPTION
const char *