56 |
struct expression *); |
struct expression *); |
57 |
static bool type_check (struct expression *, union any_node **, |
static bool type_check (struct expression *, union any_node **, |
58 |
enum expr_type expected_type); |
enum expr_type expected_type); |
59 |
|
static union any_node *allocate_unary_variable (struct expression *, |
60 |
|
struct variable *); |
61 |
|
|
62 |
/* Public functions. */ |
/* Public functions. */ |
63 |
|
|
404 |
atom_type required_type, union any_node **node, |
atom_type required_type, union any_node **node, |
405 |
const char *operator_name) |
const char *operator_name) |
406 |
{ |
{ |
407 |
return type_coercion_core (e, required_type, node, operator_name, 1); |
return type_coercion_core (e, required_type, node, operator_name, true); |
408 |
} |
} |
409 |
|
|
410 |
/* Coerces *NODE to type REQUIRED_TYPE. |
/* Coerces *NODE to type REQUIRED_TYPE. |
413 |
type_coercion_assert (struct expression *e, |
type_coercion_assert (struct expression *e, |
414 |
atom_type required_type, union any_node **node) |
atom_type required_type, union any_node **node) |
415 |
{ |
{ |
416 |
int success = type_coercion_core (e, required_type, node, NULL, 1); |
int success = type_coercion_core (e, required_type, node, NULL, true); |
417 |
assert (success); |
assert (success); |
418 |
} |
} |
419 |
|
|
423 |
is_coercible (atom_type required_type, union any_node *const *node) |
is_coercible (atom_type required_type, union any_node *const *node) |
424 |
{ |
{ |
425 |
return type_coercion_core (NULL, required_type, |
return type_coercion_core (NULL, required_type, |
426 |
(union any_node **) node, NULL, 0); |
(union any_node **) node, NULL, false); |
427 |
} |
} |
428 |
|
|
429 |
/* How to parse an operator. */ |
/* How to parse an operator. */ |
785 |
/* It looks like a user variable. |
/* It looks like a user variable. |
786 |
(It could be a format specifier, but we'll assume |
(It could be a format specifier, but we'll assume |
787 |
it's a variable unless proven otherwise. */ |
it's a variable unless proven otherwise. */ |
788 |
struct variable *v = parse_dict_variable (e->dict); |
return allocate_unary_variable (e, parse_dict_variable (e->dict)); |
|
assert (v != NULL); |
|
|
return expr_allocate_unary (e, |
|
|
(v->type == NUMERIC |
|
|
? OP_NUM_VAR : OP_STR_VAR), |
|
|
expr_allocate_variable (e, v)); |
|
789 |
} |
} |
790 |
else |
else |
791 |
{ |
{ |
1156 |
goto fail; |
goto fail; |
1157 |
for (i = 0; i < var_cnt; i++) |
for (i = 0; i < var_cnt; i++) |
1158 |
add_arg (&args, &arg_cnt, &arg_cap, |
add_arg (&args, &arg_cnt, &arg_cap, |
1159 |
expr_allocate_variable (e, vars[i])); |
allocate_unary_variable (e, vars[i])); |
1160 |
free (vars); |
free (vars); |
1161 |
} |
} |
1162 |
else |
else |
1419 |
n->format.f = *format; |
n->format.f = *format; |
1420 |
return n; |
return n; |
1421 |
} |
} |
1422 |
|
|
1423 |
|
/* Allocates a unary composite node that represents the value of |
1424 |
|
variable V in expression E. */ |
1425 |
|
static union any_node * |
1426 |
|
allocate_unary_variable (struct expression *e, struct variable *v) |
1427 |
|
{ |
1428 |
|
assert (v != NULL); |
1429 |
|
return expr_allocate_unary (e, v->type == NUMERIC ? OP_NUM_VAR : OP_STR_VAR, |
1430 |
|
expr_allocate_variable (e, v)); |
1431 |
|
} |