Skip to content

MacroBody

INCLUDE FILE
#include "Body/MacroBody.h"

class MacroBody

Represents a macro call: macro_name(arg1, arg2, ...).

DEFINITION
class MacroBody;

constructor MacroBody

DEFINITION
MacroBody ( Location  location,
Symbol  name,
std::vector< Expression >  arguments,
Macro * macro = {} );
PARAMETERDESCRIPTION
location
name
arguments
macro

method cloneconst virtual

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

method createstatic

DEFINITION
static Body  create ( const Location & location,
Symbol  name,
std::vector< Expression >  arguments,
Macro * macro = {} );
PARAMETERDESCRIPTION
location
name
arguments
macro
RETURNSDESCRIPTION
Body

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 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 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;
PARAMETERDESCRIPTION
stream

The stream to serialize to.

prefix

The prefix for each line of the serialized output.

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 arguments

The arguments passed to the macro.

DEFINITION
std::vector< Expression >  arguments;

member macro

The macro being called.

DEFINITION
Macro * macro;

member name

The name of the macro being called.

DEFINITION
Symbol  name;