CWB
Functions | Variables
builtins.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "../cl/globals.h"
#include "../cl/macros.h"
#include "../cl/attributes.h"
#include "../cl/cdaccess.h"
#include "builtins.h"
#include "eval.h"
#include "options.h"
#include "output.h"

Functions

char * attat_name (int type)
 Gets a string containing the name of the specified argument type. More...
 
int find_predefined (char *name)
 Gets the identifier of a specified predefined function (index into the global array of info about the "builtins"). More...
 
int is_predefined_function (char *name)
 Checks whether a string is the name of a predefined function. More...
 
int common_prefix_length (char *s, char *t)
 Calculates the length of a prefix shared by two strings. More...
 
int call_predefined_function (int bf_id, DynCallResult *apl, int nr_args, Constrainttree ctptr, DynCallResult *result)
 Calls a predefined function from the builtin_function array. More...
 

Variables

int f_args [] = {ATTAT_STRING}
 Argument types for builtin function f. More...
 
int distance_args [] = {ATTAT_POS, ATTAT_POS}
 Argument types for builtin function distance (or dist) More...
 
int distabs_args [] = {ATTAT_POS, ATTAT_POS}
 Argument types for builtin function distabs. More...
 
int bound_args [] = {ATTAT_INT}
 Argument types for builtin functions lbound and rbound. More...
 
int unify_args [] = {ATTAT_STRING, ATTAT_STRING}
 Argument types for builtin functions unify, prefix, is_prefix, minus. More...
 
int ambiguity_args [] = {ATTAT_STRING}
 Argument types for builtin function ambiguity. More...
 
int string_arg [] = {ATTAT_STRING}
 Argument types for builtin functions taking a single string argument. More...
 
int arith_args [] = {ATTAT_INT, ATTAT_INT}
 Argument types for builtin arithemtical functions. More...
 
int ignore_args [] = {ATTAT_POS}
 Argument types for builtin function ignore. More...
 
BuiltinF builtin_function []
 Global array of built-in functions. More...
 

Function Documentation

char* attat_name ( int  type)

Gets a string containing the name of the specified argument type.

Parameters
typeOne of the ATTAT_x constants (an argument type).
Returns
The name of the argument type.

References ATTAT_FLOAT, ATTAT_INT, ATTAT_NONE, ATTAT_PAREF, ATTAT_POS, ATTAT_STRING, and ATTAT_VAR.

Referenced by call_predefined_function().

int call_predefined_function ( int  bf_id,
DynCallResult apl,
int  nr_args,
Constrainttree  ctptr,
DynCallResult result 
)

Calls a predefined function from the builtin_function array.

See also
builtin_function
Parameters
bf_idThe function to call, identified as an index to the builtin_function array.
aplContains the arguments to this function.
nr_argsThe number of arguments the function takes.
ctptrA constraint tree used in some (but not all) of the builtin functions.
resultWhere to put the result of calling the function.
Returns
boolean: true on success, otherwise false.

References c_tree::args, ATTAT_INT, attat_name(), ATTAT_NONE, ATTAT_PAREF, ATTAT_POS, ATTAT_STRING, c_tree::attr, CDA_OK, cderrno, _DCR::charres, CL_DYN_STRING_SIZE, cl_set_intersection(), cl_set_size(), common_prefix_length(), cqpmessage(), _DCR::dynamic_string_buffer, Error, False, c_tree::func, get_id_frequency, get_id_of_string, get_string_of_id, _DCR::intres, pa_ref, c_tree::pa_ref, _ActualParamList::param, _DCR::parefres, sa_ref, c_tree::sa_ref, True, c_tree::type, _DCR::type, and _DCR::value.

Referenced by get_leaf_value().

int common_prefix_length ( char *  s,
char *  t 
)

Calculates the length of a prefix shared by two strings.

Parameters
sThe first string.
tThe second string.
Returns
The number of characters from the start of the two strings, that are identical between them. (Or, to put it another way, the index of the first non-identical character.)

Referenced by call_predefined_function().

int find_predefined ( char *  name)

Gets the identifier of a specified predefined function (index into the global array of info about the "builtins").

Returns -1 if the function is not found.

See also
builtin_function
Parameters
nameThe name of the function to search for.
Returns
An index into the builtin_function array (or -1 for not found)

References _builtinf::name.

Referenced by FunctionCall(), and is_predefined_function().

int is_predefined_function ( char *  name)

Checks whether a string is the name of a predefined function.

Parameters
nameThe name of the function to search for.
Returns
Boolean.

References find_predefined().

Variable Documentation

int ambiguity_args[] = {ATTAT_STRING}

Argument types for builtin function ambiguity.

int arith_args[] = {ATTAT_INT, ATTAT_INT}

Argument types for builtin arithemtical functions.

int bound_args[] = {ATTAT_INT}

Argument types for builtin functions lbound and rbound.

BuiltinF builtin_function[]
Initial value:
= {
{ 0, "f", 1, f_args, ATTAT_INT },
{ 1, "distance", 2, distance_args, ATTAT_INT },
{ 2, "dist", 2, distance_args, ATTAT_INT },
{ 3, "distabs", 2, distabs_args, ATTAT_INT },
{ 4, "int", 1, string_arg, ATTAT_INT },
{ 5, "lbound", 1, bound_args, ATTAT_INT },
{ 6, "rbound", 1, bound_args, ATTAT_INT },
{ 7, "unify", 2, unify_args, ATTAT_STRING },
{ 8, "ambiguity",1, ambiguity_args,ATTAT_INT },
{ 9, "add", 2, arith_args, ATTAT_INT },
{ 10, "sub", 2, arith_args, ATTAT_INT },
{ 11, "mul", 2, arith_args, ATTAT_INT },
{ 12, "prefix", 2, unify_args, ATTAT_STRING },
{ 13, "is_prefix",2, unify_args, ATTAT_INT },
{ 14, "minus", 2, unify_args, ATTAT_STRING },
{ 15, "ignore", 1, ignore_args, ATTAT_INT },
{ -1, NULL, 0, NULL, ATTAT_NONE }
}
int unify_args[]
Argument types for builtin functions unify, prefix, is_prefix, minus.
Definition: builtins.c:40
int arith_args[]
Argument types for builtin arithemtical functions.
Definition: builtins.c:43
int distance_args[]
Argument types for builtin function distance (or dist)
Definition: builtins.c:37
#define ATTAT_NONE
Dynamic att argument type: none.
Definition: cl.h:761
int distabs_args[]
Argument types for builtin function distabs.
Definition: builtins.c:38
int ambiguity_args[]
Argument types for builtin function ambiguity.
Definition: builtins.c:41
int ignore_args[]
Argument types for builtin function ignore.
Definition: builtins.c:44
#define ATTAT_INT
Dynamic att argument type: integer.
Definition: cl.h:764
int string_arg[]
Argument types for builtin functions taking a single string argument.
Definition: builtins.c:42
#define ATTAT_STRING
Dynamic att argument type: string.
Definition: cl.h:763
int f_args[]
Argument types for builtin function f.
Definition: builtins.c:36
int bound_args[]
Argument types for builtin functions lbound and rbound.
Definition: builtins.c:39

Global array of built-in functions.

Referenced by FunctionCall(), and print_booltree().

int distabs_args[] = {ATTAT_POS, ATTAT_POS}

Argument types for builtin function distabs.

int distance_args[] = {ATTAT_POS, ATTAT_POS}

Argument types for builtin function distance (or dist)

int f_args[] = {ATTAT_STRING}

Argument types for builtin function f.

int ignore_args[] = {ATTAT_POS}

Argument types for builtin function ignore.

int string_arg[] = {ATTAT_STRING}

Argument types for builtin functions taking a single string argument.

int unify_args[] = {ATTAT_STRING, ATTAT_STRING}

Argument types for builtin functions unify, prefix, is_prefix, minus.