Execute a parse tree.
- Todo:
- There is a lot of duplicated code in following cases, could be refactored.
Definition at line 770 of file exec.c.
772 tree_cell *ret = NULL, *ret2 = NULL, *tc1 = NULL, *tc2 = NULL, *tc3 = NULL,
775 char *s1 = NULL, *s2 = NULL, *s3 = NULL, *p = NULL;
780 int i, lint_mode = 0;
783 if (st->line_nb != 0)
784 lexic->line_nb = st->line_nb;
786 if (lexic->ret_val != NULL)
789 return lexic->ret_val;
793 if (lexic->break_flag || lexic->cont_flag)
811 #ifdef STOP_AT_FIRST_ERROR
817 else if (st->link[2] != NULL)
826 if (st->link[1] == NULL || lexic->break_flag || lexic->cont_flag)
835 #ifdef STOP_AT_FIRST_ERROR
843 if (lexic->ret_val != NULL)
846 return lexic->ret_val;
850 if ((ret =
nasl_exec (lexic, st->link[1])) == NULL)
858 #ifdef STOP_AT_FIRST_ERROR
865 if (lexic->break_flag)
867 lexic->break_flag = 0;
871 lexic->cont_flag = 0;
875 #ifdef STOP_AT_FIRST_ERROR
888 if (lexic->ret_val != NULL)
891 return lexic->ret_val;
894 if ((ret =
nasl_exec (lexic, st->link[0])) == NULL)
902 #ifdef STOP_AT_FIRST_ERROR
909 if (lexic->break_flag)
911 lexic->break_flag = 0;
914 lexic->cont_flag = 0;
923 if (lexic->ret_val != NULL)
926 return lexic->ret_val;
930 #ifdef STOP_AT_FIRST_ERROR
937 if (lexic->break_flag)
939 lexic->break_flag = 0;
942 lexic->cont_flag = 0;
946 #ifdef STOP_AT_FIRST_ERROR
974 #ifdef STOP_AT_FIRST_ERROR
981 if (lexic->ret_val != NULL)
984 if (lexic->break_flag)
986 lexic->break_flag = 0;
989 lexic->cont_flag = 0;
1008 nasl_perror (lexic,
"Undefined function '%s'\n", st->x.str_val);
1020 #ifdef STOP_AT_FIRST_ERROR
1021 for (tc1 = NULL, i = 1; i <= n; i++)
1024 if ((tc1 =
nasl_exec (lexic, st->link[0])) == NULL)
1029 for (i = 1; i <= n; i++)
1057 lexic->break_flag = 1;
1061 lexic->cont_flag = 1;
1196 if (st->link[0] == NULL)
1216 #ifdef STOP_AT_FIRST_ERROR
1223 #ifdef STOP_AT_FIRST_ERROR
1263 len1 = (s1 == NULL ? 0 : strlen (s1));
1271 len2 = (s2 == NULL ? 0 : strlen (s2));
1275 s3 = g_malloc0 (sz + 1);
1277 memcpy (s3, s1 != NULL ? s1 : tc1->x.str_val, len1);
1279 memcpy (s3 + len1, s2 != NULL ? s2 : tc2->x.str_val, len2);
1298 #ifdef STOP_AT_FIRST_ERROR
1305 #ifdef STOP_AT_FIRST_ERROR
1351 p1 = tc1->x.str_val;
1357 len1 = (s1 == NULL ? 0 : strlen (s1));
1362 p2 = tc2->x.str_val;
1368 len2 = (s2 == NULL ? 0 : strlen (s2));
1373 if (len2 == 0 || len1 < len2
1374 || (p1 != NULL && (p = memmem (p1, len1, p2, len2)) == NULL))
1376 s3 = g_malloc0 (len1 + 1);
1378 memcpy (s3, p1, len1);
1385 long sz = len1 - len2;
1393 s3 = g_malloc0 (sz + 1);
1395 memcpy (s3, p1, p - p1);
1396 if (p != NULL && sz > p - p1)
1397 memcpy (s3 + (p - p1), p + len2, sz - (p - p1));
1476 if (x < 0 && z >= 0)
1477 z |= (~0) << (
sizeof (x) * 8 - y);
1484 z = (unsigned) x >> (
unsigned) y;
1486 if (x < 0 && z <= 0)
1487 z &= ~((~0) << (
sizeof (x) * 8 - y));
1504 p1 = tc1->x.str_val;
1520 p2 = tc2->x.str_val;
1530 flag = (memmem (p2, len2, p1, len1) != NULL);
1545 if (st->x.ref_val == NULL)
1547 nasl_perror (lexic,
"nasl_exec: bad regex at or near line %d\n",
1551 s1 =
cell2str (lexic, st->link[0]);
1554 flag = regexec (st->x.ref_val, s1, 0, NULL, 0);
1592 nasl_perror (lexic,
"nasl_exec: unhandled node type %d\n", st->type);
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().