Execute a parse tree.
- Todo:
- There is a lot of duplicated code in following cases, could be refactored.
Definition at line 781 of file exec.c.
References nasl_iterator::a, alloc_expr_cell(), alloc_typed_cell(), bool2cell(), struct_lex_ctxt::break_flag, cell2atom(), cell2bool(), cell2int(), cell2intW(), cell2str(), cell_cmp(), COMP_EQ, COMP_GE, COMP_GT, COMP_LE, COMP_LT, COMP_MATCH, COMP_NE, COMP_NOMATCH, COMP_RE_MATCH, COMP_RE_NOMATCH, CONST_DATA, CONST_INT, CONST_STR, struct_lex_ctxt::cont_flag, decl_global_variables(), decl_local_variables(), decl_nasl_func(), deref_cell(), DYN_ARRAY, expo(), EXPR_AND, EXPR_BIT_AND, EXPR_BIT_NOT, EXPR_BIT_OR, EXPR_BIT_XOR, EXPR_DECR, EXPR_DIV, EXPR_EXPO, EXPR_INCR, EXPR_L_SHIFT, EXPR_MINUS, EXPR_MODULO, EXPR_MULT, EXPR_NOT, EXPR_OR, EXPR_PLUS, EXPR_R_SHIFT, EXPR_R_USHIFT, EXPR_U_MINUS, FAKE_CELL, free_array(), get_array_elem(), get_func_ref_by_name(), get_variable_by_name(), int2cell(), struct_lex_ctxt::line_nb, TC::line_nb, TC::link, nasl_affect(), nasl_array_iterator(), nasl_exec(), nasl_func_call(), nasl_incr_variable(), nasl_iterate_array(), nasl_perror(), nasl_read_var_ref(), nasl_return(), nasl_short_dump(), nasl_trace_fp, NODE_AFF, NODE_ARG, NODE_ARRAY_EL, NODE_BREAK, NODE_CONTINUE, NODE_DECL, NODE_DIV_EQ, NODE_EMPTY, NODE_FOR, NODE_FOREACH, NODE_FUN_CALL, NODE_FUN_DEF, NODE_GLOBAL, NODE_IF_ELSE, NODE_INSTR_L, NODE_L_SHIFT_EQ, NODE_LOCAL, NODE_MINUS_EQ, NODE_MODULO_EQ, NODE_MULT_EQ, NODE_PLUS_EQ, NODE_R_SHIFT_EQ, NODE_R_USHIFT_EQ, NODE_REPEAT_UNTIL, NODE_REPEATED, NODE_RETURN, NODE_VAR, NODE_WHILE, REF_ARRAY, ref_cell(), TC::ref_val, REF_VAR, struct_lex_ctxt::ret_val, TC::size, TC::str_val, TC::type, val, and TC::x.
Referenced by cell2atom(), cell2bool(), cell2int3(), cell2str(), exec_nasl_script(), nasl_exec(), and nasl_func_call().
783 tree_cell *ret = NULL, *ret2 = NULL, *tc1 = NULL, *tc2 = NULL, *tc3 = NULL,
786 char *s1 = NULL, *s2 = NULL, *s3 = NULL, *p = NULL;
791 int i, lint_mode = 0;
794 if (st->line_nb != 0)
795 lexic->line_nb = st->line_nb;
797 if (lexic->ret_val != NULL)
800 return lexic->ret_val;
804 if (lexic->break_flag || lexic->cont_flag)
822 #ifdef STOP_AT_FIRST_ERROR 828 else if (st->link[2] != NULL)
837 if (st->link[1] == NULL || lexic->break_flag || lexic->cont_flag)
846 #ifdef STOP_AT_FIRST_ERROR 854 if (lexic->ret_val != NULL)
857 return lexic->ret_val;
861 if ((ret =
nasl_exec (lexic, st->link[1])) == NULL)
869 #ifdef STOP_AT_FIRST_ERROR 876 if (lexic->break_flag)
878 lexic->break_flag = 0;
882 lexic->cont_flag = 0;
886 #ifdef STOP_AT_FIRST_ERROR 899 if (lexic->ret_val != NULL)
902 return lexic->ret_val;
905 if ((ret =
nasl_exec (lexic, st->link[0])) == NULL)
913 #ifdef STOP_AT_FIRST_ERROR 920 if (lexic->break_flag)
922 lexic->break_flag = 0;
925 lexic->cont_flag = 0;
934 if (lexic->ret_val != NULL)
937 return lexic->ret_val;
941 #ifdef STOP_AT_FIRST_ERROR 948 if (lexic->break_flag)
950 lexic->break_flag = 0;
953 lexic->cont_flag = 0;
957 #ifdef STOP_AT_FIRST_ERROR 985 #ifdef STOP_AT_FIRST_ERROR 992 if (lexic->ret_val != NULL)
995 if (lexic->break_flag)
997 lexic->break_flag = 0;
1000 lexic->cont_flag = 0;
1019 nasl_perror (lexic,
"Undefined function '%s'\n", st->x.str_val);
1031 #ifdef STOP_AT_FIRST_ERROR 1032 for (tc1 = NULL, i = 1; i <= n; i++)
1035 if ((tc1 =
nasl_exec (lexic, st->link[0])) == NULL)
1040 for (i = 1; i <= n; i++)
1068 lexic->break_flag = 1;
1072 lexic->cont_flag = 1;
1207 if (st->link[0] == NULL)
1227 #ifdef STOP_AT_FIRST_ERROR 1234 #ifdef STOP_AT_FIRST_ERROR 1274 len1 = (s1 == NULL ? 0 : strlen (s1));
1282 len2 = (s2 == NULL ? 0 : strlen (s2));
1286 s3 = g_malloc0 (sz + 1);
1288 memcpy (s3, s1 != NULL ? s1 : tc1->x.str_val, len1);
1290 memcpy (s3 + len1, s2 != NULL ? s2 : tc2->x.str_val, len2);
1309 #ifdef STOP_AT_FIRST_ERROR 1316 #ifdef STOP_AT_FIRST_ERROR 1362 p1 = tc1->x.str_val;
1368 len1 = (s1 == NULL ? 0 : strlen (s1));
1373 p2 = tc2->x.str_val;
1379 len2 = (s2 == NULL ? 0 : strlen (s2));
1382 if (len2 == 0 || len1 < len2
1383 || (p = memmem (p1, len1, p2, len2)) == NULL)
1385 s3 = g_malloc0 (len1 + 1);
1386 memcpy (s3, p1, len1);
1393 long sz = len1 - len2;
1401 s3 = g_malloc0 (sz + 1);
1403 memcpy (s3, p1, p - p1);
1405 memcpy (s3 + (p - p1), p + len2, sz - (p - p1));
1484 if (x < 0 && z >= 0)
1485 z |= (~0) << (
sizeof (x) * 8 - y);
1492 z = (unsigned) x >> (
unsigned) y;
1494 if (x < 0 && z <= 0)
1495 z &= ~((~0) << (
sizeof (x) * 8 - y));
1512 p1 = tc1->x.str_val;
1528 p2 = tc2->x.str_val;
1538 flag = (memmem (p2, len2, p1, len1) != NULL);
1553 if (st->x.ref_val == NULL)
1555 nasl_perror (lexic,
"nasl_exec: bad regex at or near line %d\n",
1559 s1 =
cell2str (lexic, st->link[0]);
1562 flag = regexec (st->x.ref_val, s1, 0, NULL, 0);
1600 nasl_perror (lexic,
"nasl_exec: unhandled node type %d\n", st->type);
tree_cell * nasl_return(lex_ctxt *ctxt, tree_cell *retv)
static long int expo(long int x, long int y)
void ref_cell(tree_cell *c)
static long int cell2int(lex_ctxt *lexic, tree_cell *c)
static tree_cell * bool2cell(long int x)
static int cell2bool(lex_ctxt *lexic, tree_cell *c)
tree_cell * cell2atom(lex_ctxt *lexic, tree_cell *c1)
void deref_cell(tree_cell *c)
tree_cell * alloc_typed_cell(int typ)
tree_cell * nasl_incr_variable(lex_ctxt *, tree_cell *, int, int)
static void nasl_short_dump(FILE *fp, const tree_cell *c)
tree_cell * decl_local_variables(lex_ctxt *, tree_cell *)
tree_cell * get_variable_by_name(lex_ctxt *, const char *)
long int cell_cmp(lex_ctxt *lexic, tree_cell *c1, tree_cell *c2)
void nasl_perror(lex_ctxt *lexic, char *msg,...)
static char * cell2str(lex_ctxt *lexic, tree_cell *c)
tree_cell * nasl_func_call(lex_ctxt *lexic, const nasl_func *f, tree_cell *arg_list)
tree_cell * get_array_elem(lex_ctxt *, const char *, tree_cell *)
nasl_iterator nasl_array_iterator(void *ctxt, tree_cell *c)
tree_cell * nasl_iterate_array(nasl_iterator *it)
static tree_cell * int2cell(long int x)
tree_cell * nasl_read_var_ref(lex_ctxt *, tree_cell *)
void free_array(nasl_array *a)
tree_cell * alloc_expr_cell(int lnb, int t, tree_cell *l, tree_cell *r)
tree_cell * decl_global_variables(lex_ctxt *, tree_cell *)
tree_cell * nasl_affect(tree_cell *lval, tree_cell *rval)
tree_cell * decl_nasl_func(lex_ctxt *lexic, tree_cell *decl_node, int lint_mode)
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
tree_cell * nasl_exec(lex_ctxt *lexic, tree_cell *st)
Execute a parse tree.
static long int cell2intW(lex_ctxt *lexic, tree_cell *c)