OpenVAS Libraries  4.0+rc3.SVN
nasl/nasl_tree.h
00001 /* Nessus Attack Scripting Language 
00002  *
00003  * Copyright (C) 2002 - 2003 Michel Arboi and Renaud Deraison
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2,
00007  * as published by the Free Software Foundation
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #ifndef NASLTREE_H_INCLUDED
00020 #define NASLTREE_H_INCLUDED
00021 
00022 
00023 enum node_type
00024 {
00025   NODE_EMPTY = 0,
00026   NODE_IF_ELSE,                 /* [0] = cond, [1] = if_block, [2] = else_block */
00027   NODE_INSTR_L,                 /* Block. [0] = first instr, [1] = tail */
00028   NODE_FOR,                     /* [0] = start expr, [1] = cond, [2] = end_expr, [3] = block */
00029   NODE_WHILE,                   /* [0] = cond, [1] = block */
00030   NODE_FOREACH,
00031   NODE_REPEAT_UNTIL,
00032   NODE_REPEATED,                /* [0] = func call, [1] = repeat nb */
00033   NODE_FUN_DEF,                 /* [0] = argdecl, [1] = block */
00034   NODE_FUN_CALL,                /* [0] = arglist */
00035   NODE_DECL,                    /* [0] = next arg in list */
00036   NODE_ARG,                     /* val = name can be NULL, [0] = val, [1] = next arg */
00037   NODE_RETURN,                  /* ret val */
00038   NODE_BREAK,
00039   NODE_CONTINUE,
00040 
00041   NODE_ARRAY_EL,                /* val = array name, [0] = index */
00042   NODE_AFF,                     /* [0] = lvalue, [1] = rvalue */
00043   NODE_VAR,                     /* val = variable name */
00044   NODE_LOCAL,                   /* [0] = argdecl */
00045   NODE_GLOBAL,
00046 
00047   NODE_PLUS_EQ,
00048   NODE_MINUS_EQ,
00049   NODE_MULT_EQ,
00050   NODE_DIV_EQ,
00051   NODE_MODULO_EQ,
00052 
00053   NODE_L_SHIFT_EQ,
00054   NODE_R_SHIFT_EQ,
00055   NODE_R_USHIFT_EQ,
00056 
00057   EXPR_AND,
00058   EXPR_OR,
00059   EXPR_NOT,
00060 
00061   EXPR_PLUS,
00062   EXPR_MINUS,
00063   EXPR_U_MINUS,
00064   EXPR_MULT,
00065   EXPR_DIV,
00066   EXPR_MODULO,
00067   EXPR_EXPO,
00068 
00069   EXPR_BIT_AND,
00070   EXPR_BIT_OR,
00071   EXPR_BIT_XOR,
00072   EXPR_BIT_NOT,
00073   EXPR_INCR,
00074   EXPR_DECR,
00075   EXPR_L_SHIFT,
00076   EXPR_R_SHIFT,
00077   EXPR_R_USHIFT,
00078 
00079   COMP_MATCH,
00080   COMP_NOMATCH,
00081   COMP_RE_MATCH,
00082   COMP_RE_NOMATCH,
00083 
00084   COMP_LT,
00085   COMP_LE,
00086   COMP_EQ,
00087   COMP_NE,
00088   COMP_GT,
00089   COMP_GE,
00090 
00091   CONST_INT,
00092   CONST_STR,                    /* "impure" string */
00093 
00094   CONST_DATA,                   /* binary data / "pure" string */
00095   CONST_REGEX,                  /* Compiled regex */
00096 
00097   ARRAY_ELEM,                   /* val = char index or NULL if integer,
00098                                  * [0] = value, [1] = next element */
00099   /* For exec only */
00100   REF_VAR,
00101   REF_ARRAY,
00102   DYN_ARRAY
00103 };
00104 
00105 typedef struct TC
00106 {
00107   short type;
00108   short line_nb;
00109   short ref_count;              /* Cell is freed when count reaches zero */
00110   int size;
00111   union
00112   {
00113     char *str_val;
00114     int i_val;
00115     void *ref_val;              /* internal reference */
00116   } x;
00117   struct TC *link[4];
00118 } tree_cell;
00119 
00120 #define FAKE_CELL ((void*)1)
00121 #define EXIT_CELL ((void*)2)
00122 
00123 tree_cell *alloc_tree_cell (int, char *);
00124 tree_cell *alloc_expr_cell (int, int, tree_cell *, tree_cell *);
00125 tree_cell *alloc_RE_cell (int, int, tree_cell *, char *);
00126 tree_cell *alloc_typed_cell (int);
00127 int nasl_is_leaf (const tree_cell *);
00128 char *get_line_nb (const tree_cell *);
00129 tree_cell *dup_cell (const tree_cell *);
00130 void nasl_dump_tree (const tree_cell *);
00131 void ref_cell (tree_cell *);
00132 void deref_cell (tree_cell *);
00133 const char *nasl_type_name (int);
00134 int cell_type (const tree_cell *);
00135 
00136 char *dump_cell_val (const tree_cell *);
00137 
00138 
00139 #endif