Skip to content

FunctionExpression

INCLUDE FILE
#include "Expression/FunctionExpression.h"

class FunctionExpression

Expression representing a function call: function_name(arg1, arg2, ...).

DEFINITION
class FunctionExpression;

constructor FunctionExpression

Create a function expression.

DEFINITION
FunctionExpression ( const Location & location,
Symbol  name,
std::vector< Expression >  arguments );
PARAMETERDESCRIPTION
location

The location of the expression in the source code.

name

The name of the function.

arguments

The arguments to the function.

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 function expression.

DEFINITION
static Expression  create ( const Location & location,
Symbol  name,
const std::vector< Expression > & arguments );
PARAMETERDESCRIPTION
location

The location of the expression in the source code.

name

The name of the function.

arguments

The arguments to the function.

RETURNSDESCRIPTION
Expression

The created expression.

method expand_callsvirtual protected

Expand function calls in the expression.

The default implementation calls expand_calls() on all sub-expressions using traverse() and returns {}.

If a function call cannot be expanded, either an error should be reported via DiagnosticOutput and the expression marked as invalid, or an exception should be thrown.

DEFINITION
virtual std::optional< Expression >  expand_calls ( );
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 setupstatic

Set up tokenizer for parsing function expressions.

DEFINITION
static void  setup ( FileTokenizer & tokenizer );
PARAMETERDESCRIPTION
tokenizer

The tokenizer to set up.

method traversevirtual protected

Call a method on all sub-expressions of this expression.

It is used by the default implementations of resolve() and expand_calls(). Unless a subclass has no sub-expressions or overrides both of these methods, it should override traverse().

DEFINITION
virtual void  traverse ( std::function< void(Expression &)>  callable );
PARAMETERDESCRIPTION
callable

A callable to apply to each sub-expression.

member argumentsprivate

The arguments to the function.

DEFINITION
std::vector< Expression >  arguments;

member builtin_functionsstatic private

The built-in functions implemented in C++.

DEFINITION
static const std::unordered_map< Symbol, Expression(*)(const Location &location, const std::vector< Expression > &)>  builtin_functions;

member functionprivate

The function being called, if it is a user-defined function.

DEFINITION
const Function * function;

member nameprivate

The name of the function being called.

DEFINITION
Symbol  name;