Skip to content

NameExpression

INCLUDE FILE
#include "Expression/NameExpression.h"

class NameExpression

Expression node representing a variable.

DEFINITION
class NameExpression;

constructor NameExpression

Create a variable expression.

DEFINITION
NameExpression ( const Location & location,
Symbol  symbol,
std::optional< Expression >  expression = {} );
PARAMETERDESCRIPTION
location

The location of the expression.

symbol

The name of the variable.

expression

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.

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

A shared pointer to the cloned expression.

method createstatic

Create a variable expression.

DEFINITION
static Expression  create ( const Location & location,
Symbol  symbol );
PARAMETERDESCRIPTION
location

The location of the expression.

symbol

The name of the variable.

RETURNSDESCRIPTION
Expression

method evaluatevirtual protected

Evaluate the expression in the given context.

The default implementation calls evaluate() on all sub-expressions using traverse(), and then calls evaluate_process().

Errors during evaluation should either be reported via DiagnosticOutput and result in the expression being marked as invalid, or an exception should be thrown.

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

The evaluation context.

RETURNSDESCRIPTION
std::optional< Expression >

The Expression to replace this expression with, {} if no replacement is needed.

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.

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

DEFINITION
virtual void  serialize_sub ( std::ostream & stream ) const;
PARAMETERDESCRIPTION
stream

The stream to serialize to.

method variableconst

Get the name of the variable.

DEFINITION
Symbol  variable ( ) const;
RETURNSDESCRIPTION
Symbol

The name of the variable.

member expressionprivate

The expression representing the value of the variable.

DEFINITION
std::optional< Expression >  expression;

member symbolprivate

The name of the variable.

DEFINITION
Symbol  symbol;