OpenVAS Libraries  9.0.3
nasl_lex_ctxt.c File Reference
#include <glib.h>
#include "nasl_func.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include "nasl_global_ctxt.h"
#include "nasl_lex_ctxt.h"
Include dependency graph for nasl_lex_ctxt.c:

Go to the source code of this file.

Functions

lex_ctxtinit_empty_lex_ctxt ()
 
void free_lex_ctxt (lex_ctxt *c)
 
void dump_ctxt (lex_ctxt *c)
 

Function Documentation

◆ dump_ctxt()

void dump_ctxt ( lex_ctxt c)

Definition at line 64 of file nasl_lex_ctxt.c.

References struct_lex_ctxt::ctx_vars, struct_lex_ctxt::fct_ctxt, st_nasl_func::func_name, FUNC_NAME_HASH, struct_lex_ctxt::functions, st_nasl_array::hash_elt, nasl_dump_tree(), st_nasl_func::next_func, st_n_nasl_var::next_var, struct_lex_ctxt::ret_val, struct_lex_ctxt::up_ctxt, st_n_nasl_var::var_name, and VAR_NAME_HASH.

Referenced by nasl_dump_ctxt().

65 {
66  int i;
67  named_nasl_var *v;
68  nasl_func *f;
69 
70  printf ("--------<CTXT>--------\n");
71  if (c->fct_ctxt)
72  printf ("Is a function context\n");
73  if (c->up_ctxt == NULL)
74  printf ("Is the top level context\n");
75  if (c->ret_val)
76  {
77  printf ("Return value\n");
79  }
80 
81  printf ("Variables:\n");
82  for (i = 0; i < VAR_NAME_HASH; i++)
83  for (v = c->ctx_vars.hash_elt[i]; v != NULL; v = v->next_var)
84  printf ("%s\t", v->var_name);
85  putchar ('\n');
86 
87  printf ("Functions:\n");
88  for (i = 0; i < FUNC_NAME_HASH; i++)
89  for (f = c->functions[i]; f != NULL; f = f->next_func)
90  printf ("%s\t", f->func_name);
91  putchar ('\n');
92 
93  printf ("----------------------\n");
94 }
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
struct st_n_nasl_var * next_var
Definition: nasl_var.h:74
char * var_name
Definition: nasl_var.h:70
void nasl_dump_tree(const tree_cell *c)
Definition: nasl_tree.c:439
#define FUNC_NAME_HASH
Definition: nasl_func.h:22
char * func_name
Definition: nasl_func.h:32
struct st_nasl_func * next_func
Definition: nasl_func.h:38
nasl_func * functions[FUNC_NAME_HASH]
Definition: nasl_lex_ctxt.h:46
#define VAR_NAME_HASH
Definition: nasl_var.h:31
unsigned fct_ctxt
Definition: nasl_lex_ctxt.h:35
tree_cell * ret_val
Definition: nasl_lex_ctxt.h:34
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:45
struct struct_lex_ctxt * up_ctxt
Definition: nasl_lex_ctxt.h:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_lex_ctxt()

void free_lex_ctxt ( lex_ctxt c)

Definition at line 46 of file nasl_lex_ctxt.c.

References struct_lex_ctxt::ctx_vars, deref_cell(), free_array(), free_func_chain(), FUNC_NAME_HASH, struct_lex_ctxt::functions, struct_lex_ctxt::ret_val, and struct_lex_ctxt::up_ctxt.

Referenced by exec_nasl_script().

47 {
48  int i;
49 
50 #if 0
51  if (c->exit_flag && c->up_ctxt != NULL)
52  ((lex_ctxt *) c->up_ctxt)->exit_flag = 1;
53 #endif
54  deref_cell (c->ret_val);
55  free_array (&c->ctx_vars);
56  for (i = 0; i < FUNC_NAME_HASH; i++)
57  {
58  free_func_chain (c->functions[i]);
59  }
60  g_free (c);
61 }
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:202
#define FUNC_NAME_HASH
Definition: nasl_func.h:22
nasl_func * functions[FUNC_NAME_HASH]
Definition: nasl_lex_ctxt.h:46
void free_func_chain(nasl_func *f)
Definition: nasl_func.c:375
tree_cell * ret_val
Definition: nasl_lex_ctxt.h:34
void free_array(nasl_array *a)
Definition: nasl_var.c:366
struct struct_lex_ctxt * up_ctxt
Definition: nasl_lex_ctxt.h:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_empty_lex_ctxt()

lex_ctxt* init_empty_lex_ctxt ( void  )

Definition at line 29 of file nasl_lex_ctxt.c.

References struct_lex_ctxt::ctx_vars, struct_lex_ctxt::fct_ctxt, FUNC_NAME_HASH, struct_lex_ctxt::functions, st_nasl_array::hash_elt, st_nasl_array::max_idx, st_nasl_array::num_elt, struct_lex_ctxt::oid, struct_lex_ctxt::ret_val, and VAR_NAME_HASH.

Referenced by exec_nasl_script(), and nasl_func_call().

30 {
31  lex_ctxt *c = g_malloc0 (sizeof (lex_ctxt));
32  int i;
33 
34  c->ctx_vars.hash_elt = g_malloc0 (sizeof (named_nasl_var) * VAR_NAME_HASH);
35  c->ctx_vars.num_elt = NULL;
36  c->ctx_vars.max_idx = 0;
37  for (i = 0; i < FUNC_NAME_HASH; i++)
38  c->functions[i] = NULL;
39  c->oid = NULL;
40  c->ret_val = NULL;
41  c->fct_ctxt = 0;
42  return c;
43 }
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
#define FUNC_NAME_HASH
Definition: nasl_func.h:22
nasl_func * functions[FUNC_NAME_HASH]
Definition: nasl_lex_ctxt.h:46
#define VAR_NAME_HASH
Definition: nasl_var.h:31
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:44
unsigned fct_ctxt
Definition: nasl_lex_ctxt.h:35
tree_cell * ret_val
Definition: nasl_lex_ctxt.h:34
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:45
const char * oid
Definition: nasl_lex_ctxt.h:40
Here is the caller graph for this function: