aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/symbol.c
diff options
Diffstat (limited to 'symbol.c')
-rw-r--r--symbol.c160
1 files changed, 1 insertions, 159 deletions
diff --git a/symbol.c b/symbol.c
index a65ad17b..08c85f40 100644
--- a/symbol.c
+++ b/symbol.c
@@ -646,155 +646,6 @@ struct symbol *create_symbol(int stream, const char *name, int type, int namespa
return sym;
}
-static int evaluate_to_integer(struct expression *expr)
-{
- expr->ctype = &int_ctype;
- return 1;
-}
-
-static int evaluate_expect(struct expression *expr)
-{
- /* Should we evaluate it to return the type of the first argument? */
- expr->ctype = &int_ctype;
- return 1;
-}
-
-static int arguments_choose(struct expression *expr)
-{
- struct expression_list *arglist = expr->args;
- struct expression *arg;
- int i = 0;
-
- FOR_EACH_PTR (arglist, arg) {
- if (!evaluate_expression(arg))
- return 0;
- i++;
- } END_FOR_EACH_PTR(arg);
- if (i < 3) {
- sparse_error(expr->pos,
- "not enough arguments for __builtin_choose_expr");
- return 0;
- } if (i > 3) {
- sparse_error(expr->pos,
- "too many arguments for __builtin_choose_expr");
- return 0;
- }
- return 1;
-}
-
-static int evaluate_choose(struct expression *expr)
-{
- struct expression_list *list = expr->args;
- struct expression *arg, *args[3];
- int n = 0;
-
- /* there will be exactly 3; we'd already verified that */
- FOR_EACH_PTR(list, arg) {
- args[n++] = arg;
- } END_FOR_EACH_PTR(arg);
-
- *expr = get_expression_value(args[0]) ? *args[1] : *args[2];
-
- return 1;
-}
-
-static int expand_expect(struct expression *expr, int cost)
-{
- struct expression *arg = first_ptr_list((struct ptr_list *) expr->args);
-
- if (arg)
- *expr = *arg;
- return 0;
-}
-
-/*
- * __builtin_warning() has type "int" and always returns 1,
- * so that you can use it in conditionals or whatever
- */
-static int expand_warning(struct expression *expr, int cost)
-{
- struct expression *arg;
- struct expression_list *arglist = expr->args;
-
- FOR_EACH_PTR (arglist, arg) {
- /*
- * Constant strings get printed out as a warning. By the
- * time we get here, the EXPR_STRING has been fully
- * evaluated, so by now it's an anonymous symbol with a
- * string initializer.
- *
- * Just for the heck of it, allow any constant string
- * symbol.
- */
- if (arg->type == EXPR_SYMBOL) {
- struct symbol *sym = arg->symbol;
- if (sym->initializer && sym->initializer->type == EXPR_STRING) {
- struct string *string = sym->initializer->string;
- warning(expr->pos, "%*s", string->length-1, string->data);
- }
- continue;
- }
-
- /*
- * Any other argument is a conditional. If it's
- * non-constant, or it is false, we exit and do
- * not print any warning.
- */
- if (arg->type != EXPR_VALUE)
- goto out;
- if (!arg->value)
- goto out;
- } END_FOR_EACH_PTR(arg);
-out:
- expr->type = EXPR_VALUE;
- expr->value = 1;
- expr->taint = 0;
- return 0;
-}
-
-static struct symbol_op constant_p_op = {
- .evaluate = evaluate_to_integer,
- .expand = expand_constant_p
-};
-
-static struct symbol_op safe_p_op = {
- .evaluate = evaluate_to_integer,
- .expand = expand_safe_p
-};
-
-static struct symbol_op warning_op = {
- .evaluate = evaluate_to_integer,
- .expand = expand_warning
-};
-
-static struct symbol_op expect_op = {
- .evaluate = evaluate_expect,
- .expand = expand_expect
-};
-
-static struct symbol_op choose_op = {
- .evaluate = evaluate_choose,
- .args = arguments_choose,
-};
-
-/*
- * Builtin functions
- */
-static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ };
-static struct sym_init {
- const char *name;
- struct symbol *base_type;
- unsigned int modifiers;
- struct symbol_op *op;
-} eval_init_table[] = {
- { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op },
- { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op },
- { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
- { "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op },
- { "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op },
- { NULL, NULL, 0 }
-};
-
/*
* Abstract types
@@ -829,22 +680,13 @@ struct symbol zero_int;
void init_symbols(void)
{
int stream = init_stream("builtin", -1, includepath);
- struct sym_init *ptr;
#define __IDENT(n,str,res) \
hash_ident(&n)
#include "ident-list.h"
init_parser(stream);
-
- builtin_fn_type.variadic = 1;
- for (ptr = eval_init_table; ptr->name; ptr++) {
- struct symbol *sym;
- sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL);
- sym->ctype.base_type = ptr->base_type;
- sym->ctype.modifiers = ptr->modifiers;
- sym->op = ptr->op;
- }
+ init_builtins(stream);
}
#define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)