xexprtypes

xexprtypes — Types defined in libxexpr

Stability Level

Stable, unless otherwise indicated

Synopsis


#include <libxexpr/xexpr.h>

                    XexprInvocation;
                    XexprFunction;
typedef             XexprConstant;
                    XexprBinding;
enum                XexprType;
                    XexprEnvironment;
                    Xexpr;
                    XexprExtension;
XexprConstant *     xexpr_new_string                    (const char *s,
                                                         gssize len);
XexprConstant *     xexpr_new_string_take_ownership     (char *s);
XexprConstant *     xexpr_new_integer                   (long int integer);
XexprConstant *     xexpr_new_number                    (double number);
XexprConstant *     xexpr_new_invocation                (const char *ns,
                                                         const char *function,
                                                         GSList *bindings,
                                                         GSList *constants);
XexprConstant *     xexpr_new_invocation_take_ownership (char *ns,
                                                         char *function,
                                                         GSList *bindings,
                                                         GSList *constants);
XexprConstant *     xexpr_new_function_take_ownership   (GSList *args,
                                                         GSList *constants);
XexprConstant *     xexpr_new_function                  (GSList *args,
                                                         GSList *constants);
XexprConstant *     xexpr_constant_dup                  (XexprConstant *constant);
void                xexpr_constant_free                 (XexprConstant *constant);
void                xexpr_binding_free                  (XexprBinding *binding);
XexprConstant *     xexpr_bindings_get                  (GSList *bindings,
                                                         const char *id);
gboolean            xexpr_bindings_set                  (GSList *bindings,
                                                         const char *id,
                                                         XexprConstant *value);
GSList *            xexpr_bindings_new                  (GSList *bindings,
                                                         const char *id,
                                                         XexprConstant *value);
GSList *            xexpr_bindings_dup                  (GSList *bindings);
Xexpr *             xexpr_new                           (void);
Xexpr *             xexpr_sub                           (Xexpr *xexpr);
void                xexpr_var_new                       (Xexpr *xexpr,
                                                         const char *id,
                                                         XexprConstant *value);
void                xexpr_var_set                       (Xexpr *xexpr,
                                                         const char *id,
                                                         XexprConstant *value);
XexprConstant *     xexpr_var_get                       (Xexpr *xexpr,
                                                         const char *id);
void                xexpr_start_tracing                 (Xexpr *xexpr,
                                                         const char *id);
gboolean            xexpr_is_tracing                    (Xexpr *xexpr,
                                                         const char *id);
void                xexpr_free                          (Xexpr *xexpr);
XexprEnvironment *  xexpr_get_environment               (Xexpr *xexpr);
void                xexpr_environment_foreach           (XexprEnvironment *environment,
                                                         GTraverseFunc func,
                                                         gpointer user_data);

Description

The various types defined in libxexpr and the functions that support them.

Details

XexprInvocation

typedef struct {
    char *ns;
    char *function;
    GSList *bindings;
    GSList *constants;
} XexprInvocation;

A structure describing the invocation of a function.

char *ns;

the namespace to which function belongs, or NULL

char *function;

the function to be invoked

GSList *bindings;

(element-type XexprBinding): the pre-bound arguments

GSList *constants;

(element-type XexprConstant): the other arguments

XexprFunction

typedef struct {
    GSList *args;
    GSList *constants;
} XexprFunction;

A structure describing the definition of a function.

GSList *args;

(element-type utf8): the parameter names

GSList *constants;

(element-type XexprConstant): the constants which will be evaluated when the function is invoked

XexprConstant

typedef struct xexpr_constant XexprConstant;

A structure describing an XEXPR expression


XexprBinding

typedef struct {
    char *id;
    XexprConstant *value;
} XexprBinding;

A structure describing the binding of a value to a name.

char *id;

the bound name

XexprConstant *value;

the expresion bound to id

enum XexprType

typedef enum {
    XEXPR_TYPE_INVOCATION=1,
    XEXPR_TYPE_FUNCTION,
    XEXPR_TYPE_STRING,
    XEXPR_TYPE_INTEGER,
    XEXPR_TYPE_NUMBER
} XexprType;

Enum values for the type, to specify the type of expression.

XEXPR_TYPE_INVOCATION

a function invocation

XEXPR_TYPE_FUNCTION

a function definition

XEXPR_TYPE_STRING

a string

XEXPR_TYPE_INTEGER

an integer

XEXPR_TYPE_NUMBER

a floating-point number

XexprEnvironment

typedef struct {
    char *function;
    struct xexpr_environment *outer;
    GSList *bindings;
} XexprEnvironment;

A structure describing an XEXPR environment

char *function;

the name of the function to which the environment belongs, or NULL if this is the outermost environment

struct xexpr_environment *outer;

the next environment in the chain from innermost to outermost, or NULL if this is the outermost environment

GSList *bindings;

(element-type XexprBinding): the variables set in this environment

Xexpr

typedef struct {
    GSList *constants;
    XexprEnvironment *environment;
} Xexpr;

A structure describing an XEXPR expression

GSList *constants;

(element-type XexprConstant): the constants that make up this expression

XexprEnvironment *environment;

the innermost environment

XexprExtension

typedef struct {
    char *ns;
    XexprConstant *(*function_evaluate)(Xexpr *xexpr,const char *ns,
      const char *id,GSList *bindings,GSList *args,GError **err);
} XexprExtension;

A structure describing an XEXPR extension

char *ns;

the namespace of the extension

function_evaluate ()

evaluates functions defined in the extension

xexpr_new_string ()

XexprConstant *     xexpr_new_string                    (const char *s,
                                                         gssize len);

Create a new XexprConstant that consists of the given string.

s :

the string. transfer none.

len :

length of s to use, or -1 to treat s as nul-terminated

Returns :

the new XexprConstant. transfer full.

xexpr_new_string_take_ownership ()

XexprConstant *     xexpr_new_string_take_ownership     (char *s);

Create a new XexprConstant that consists of the given string.

s :

the string. transfer full.

Returns :

the new XexprConstant. transfer full.

xexpr_new_integer ()

XexprConstant *     xexpr_new_integer                   (long int integer);

Create a new XexprConstant that consists of the given integer.

integer :

the integer

Returns :

the new XexprConstant. transfer full.

xexpr_new_number ()

XexprConstant *     xexpr_new_number                    (double number);

Create a new XexprConstant that consists of the given floating-point number.

number :

the number

Returns :

the new XexprConstant. transfer full.

xexpr_new_invocation ()

XexprConstant *     xexpr_new_invocation                (const char *ns,
                                                         const char *function,
                                                         GSList *bindings,
                                                         GSList *constants);

Create a new XexprConstant that invokes function with pre-bound arguments bindings and with constants as further arguments. Functions with named parameters will use the pre-bound arguments first if present, otherwise the other arguments will be bound to the unbound parameters as needed.

ns should be NULL, the empty string or XEXPR_NS for XEXPR functions.

ns :

the namespace to which function belongs, or NULL. transfer none.

function :

the name of the function to be invoked. transfer none.

bindings :

transfer none) (element-type XexprBinding. transfer none. element-type XexprBinding.

constants :

transfer none) (element-type XexprConstant. transfer none. element-type XexprConstant.

Returns :

the new XexprConstant. transfer full.

xexpr_new_invocation_take_ownership ()

XexprConstant *     xexpr_new_invocation_take_ownership (char *ns,
                                                         char *function,
                                                         GSList *bindings,
                                                         GSList *constants);

Create a new XexprConstant that invokes function with pre-bound arguments bindings and with constants as further arguments. Functions with named parameters will use the pre-bound arguments first if present, otherwise the other arguments will be bound to the unbound parameters as needed.

ns should be NULL, the empty string or XEXPR_NS for XEXPR functions.

ns :

the namespace to which function belongs, or NULL. transfer full.

function :

the name of the function to be invoked. transfer full.

bindings :

transfer full) (element-type XexprBinding. transfer full. element-type XexprBinding.

constants :

transfer full) (element-type XexprConstant. transfer full. element-type XexprConstant.

Returns :

the new XexprConstant. transfer full.

xexpr_new_function_take_ownership ()

XexprConstant *     xexpr_new_function_take_ownership   (GSList *args,
                                                         GSList *constants);

Create a new XexprConstant that defines an unnamed function. Creating a function definition is the first step in defining a function. The second step is to bind the definition to a name, eg., using xexpr_var_new().

args :

the parameter names. transfer full. element-type utf8.

constants :

transfer full) (element-type XexprConstant. transfer full. element-type XexprConstant.

Returns :

the new XexprConstant. transfer full.

xexpr_new_function ()

XexprConstant *     xexpr_new_function                  (GSList *args,
                                                         GSList *constants);

Create a new XexprConstant that defines an unnamed function. Creating a function definition is the first step in defining a function. The second step is to bind the definition to a name, eg., using xexpr_var_new().

args :

the parameter names. transfer none. element-type utf8.

constants :

transfer none) (element-type XexprConstant. transfer none. element-type XexprConstant.

Returns :

the new XexprConstant. transfer full.

xexpr_constant_dup ()

XexprConstant *     xexpr_constant_dup                  (XexprConstant *constant);

Duplicate constant.

constant :

an XexprConstant to duplicate

Returns :

the new XexprConstant. transfer full.

xexpr_constant_free ()

void                xexpr_constant_free                 (XexprConstant *constant);

Frees the memory allocated for the XexprConstant.

constant :

an XexprConstant

xexpr_binding_free ()

void                xexpr_binding_free                  (XexprBinding *binding);

Frees the memory allocated for the XexprBinding.

binding :

an XexprBinding

xexpr_bindings_get ()

XexprConstant *     xexpr_bindings_get                  (GSList *bindings,
                                                         const char *id);

Look for a binding of symbol id in bindings and return the value if found.

bindings :

transfer none) (element-type XexprBinding. transfer none. element-type XexprBinding.

id :

the symbol to search for

Returns :

the found XexprConstant or NULL. transfer none.

xexpr_bindings_set ()

gboolean            xexpr_bindings_set                  (GSList *bindings,
                                                         const char *id,
                                                         XexprConstant *value);

Update an existing binding of symbol id in bindings with the new value value. If no existing binding is found, return FALSE.

bindings :

transfer none) (element-type XexprBinding. transfer none. element-type XexprBinding.

id :

an existing symbol to set

value :

the new value. transfer none.

Returns :

TRUE if id was found and updated

xexpr_bindings_new ()

GSList *            xexpr_bindings_new                  (GSList *bindings,
                                                         const char *id,
                                                         XexprConstant *value);

Update an existing binding of symbol id or create a new one in bindings with the new value value.

bindings :

transfer full) (element-type XexprBinding. transfer full. element-type XexprBinding.

id :

a symbol to set or create

value :

the new value. transfer none.

Returns :

the new bindings list. transfer full. element-type XexprBinding.

xexpr_bindings_dup ()

GSList *            xexpr_bindings_dup                  (GSList *bindings);

Duplicate bindings.

bindings :

transfer none) (element-type XexprBinding. transfer none. element-type XexprBinding.

Returns :

the new bindings list. transfer full. element-type XexprBinging.

xexpr_new ()

Xexpr *             xexpr_new                           (void);

Creates a new Xexpr.

Returns :

the new Xexpr

xexpr_sub ()

Xexpr *             xexpr_sub                           (Xexpr *xexpr);

Creates a new Xexpr, copying options from xexpr.

xexpr :

an Xexpr to copy the initial options from

Returns :

the new Xexpr

xexpr_var_new ()

void                xexpr_var_new                       (Xexpr *xexpr,
                                                         const char *id,
                                                         XexprConstant *value);

Update an existing binding of symbol id in the innermost environment of xexpr or create a new one with the new value value.

xexpr :

an Xexpr

id :

a symbol to set or create

value :

the new value. transfer none.

xexpr_var_set ()

void                xexpr_var_set                       (Xexpr *xexpr,
                                                         const char *id,
                                                         XexprConstant *value);

Update the active binding of symbol id in xexpr if such exists or create create a new one in the outermost environment with the new value value.

xexpr :

an Xexpr

id :

a symbol to set or create

value :

the new value. transfer none.

xexpr_var_get ()

XexprConstant *     xexpr_var_get                       (Xexpr *xexpr,
                                                         const char *id);

Look for a definition of symbol id in xexpr and return its value. If no definition exists, return NULL.

xexpr :

an Xexpr

id :

a symbol to look up

Returns :

the bound value, or NULL if not found.. transfer none.

xexpr_start_tracing ()

void                xexpr_start_tracing                 (Xexpr *xexpr,
                                                         const char *id);

Adds id to the set of symbols to trace.

When variables with the name of a traced symbol are created or changed, the evaluator will output a suitable tracing message and a stack dump.

Example 1. Example Tracing Output

    Created new variable x in frame #0
    #0  test1 (x = <nil/>)
    #1  eq ()
    #2  if ()
    #3  and ()
    #4  expr ()
    
    Set variable x
    #0  test1 (x = <integer>1</integer>)
    #1  eq ()
    #2  if ()
    #3  and ()
    #4  expr ()
  


xexpr :

an Xexpr

id :

the symbol to trace

xexpr_is_tracing ()

gboolean            xexpr_is_tracing                    (Xexpr *xexpr,
                                                         const char *id);

Checks if a symbol is currently being traced, returning TRUE if it is.

xexpr :

an Xexpr

id :

the symbol to test for

Returns :

TRUE if id is being traced

xexpr_free ()

void                xexpr_free                          (Xexpr *xexpr);

Frees the memory allocated for the Xexpr.

xexpr :

an Xexpr

xexpr_get_environment ()

XexprEnvironment *  xexpr_get_environment               (Xexpr *xexpr);

Gets the XexprEnvironment of the given Xexpr.

xexpr :

an Xexpr

Returns :

the innermost environment. transfer none.

xexpr_environment_foreach ()

void                xexpr_environment_foreach           (XexprEnvironment *environment,
                                                         GTraverseFunc func,
                                                         gpointer user_data);

Calls a function for each active variable in an XexprEnvironment.

environment :

an XexprEnvironment

func :

the function to call with each active variable

user_data :

user data to pass to the function