Implemented two new symbol handling functions:
o cf_define_symbol() -- it assigns a meaning to a symbol, bailing out if it already has one. o cf_find_symbol() -- finds symbol by name and creates it if not found. Also modified filter/config.Y to make use of the first function.
This commit is contained in:
parent
b23c5e0ff4
commit
4107df1d1b
3 changed files with 23 additions and 8 deletions
|
@ -182,6 +182,12 @@ cf_find_sym(byte *c, unsigned int h0)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct symbol *
|
||||||
|
cf_find_symbol(byte *c)
|
||||||
|
{
|
||||||
|
return cf_find_sym(c, cf_hash(c));
|
||||||
|
}
|
||||||
|
|
||||||
struct symbol *
|
struct symbol *
|
||||||
cf_default_name(char *prefix, int *counter)
|
cf_default_name(char *prefix, int *counter)
|
||||||
{
|
{
|
||||||
|
@ -198,6 +204,15 @@ cf_default_name(char *prefix, int *counter)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cf_define_symbol(struct symbol *sym, int type, void *def)
|
||||||
|
{
|
||||||
|
if (sym->class)
|
||||||
|
cf_error("Symbol already defined");
|
||||||
|
sym->class = type;
|
||||||
|
sym->def = def;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cf_lex_init(int flag)
|
cf_lex_init(int flag)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,6 +17,8 @@ struct config {
|
||||||
pool *pool; /* Pool the configuration is stored in */
|
pool *pool; /* Pool the configuration is stored in */
|
||||||
linpool *mem; /* Linear pool containing configuration data */
|
linpool *mem; /* Linear pool containing configuration data */
|
||||||
list protos; /* Configured protocol instances (struct proto_config) */
|
list protos; /* Configured protocol instances (struct proto_config) */
|
||||||
|
list tables; /* Configured routing tables (struct rtable_config) */
|
||||||
|
struct rtable_config *master_rtc; /* Configuration of master routing table */
|
||||||
u32 router_id; /* Our Router ID */
|
u32 router_id; /* Our Router ID */
|
||||||
char *err_msg; /* Parser error message */
|
char *err_msg; /* Parser error message */
|
||||||
int err_lino; /* Line containing error */
|
int err_lino; /* Line containing error */
|
||||||
|
@ -60,6 +62,7 @@ struct symbol {
|
||||||
#define SYM_STAT 3 /* statement */
|
#define SYM_STAT 3 /* statement */
|
||||||
#define SYM_FUNCTION 5
|
#define SYM_FUNCTION 5
|
||||||
#define SYM_FILTER 6
|
#define SYM_FILTER 6
|
||||||
|
#define SYM_TABLE 7
|
||||||
|
|
||||||
#define SYM_VARIABLE 0x100 /* Reserved 0x100..0x1ff */
|
#define SYM_VARIABLE 0x100 /* Reserved 0x100..0x1ff */
|
||||||
|
|
||||||
|
@ -68,7 +71,9 @@ extern int conf_lino;
|
||||||
void cf_lex_init_tables(void);
|
void cf_lex_init_tables(void);
|
||||||
int cf_lex(void);
|
int cf_lex(void);
|
||||||
void cf_lex_init(int flag);
|
void cf_lex_init(int flag);
|
||||||
|
struct symbol *cf_find_symbol(byte *c);
|
||||||
struct symbol *cf_default_name(char *prefix, int *counter);
|
struct symbol *cf_default_name(char *prefix, int *counter);
|
||||||
|
void cf_define_symbol(struct symbol *symbol, int type, void *def);
|
||||||
|
|
||||||
/* Parser */
|
/* Parser */
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,7 @@ CF_GRAMMAR
|
||||||
CF_ADDTO(conf, filter_def)
|
CF_ADDTO(conf, filter_def)
|
||||||
filter_def:
|
filter_def:
|
||||||
FILTER SYM filter_body {
|
FILTER SYM filter_body {
|
||||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
cf_define_symbol($2, SYM_FILTER, $3);
|
||||||
$2->class = SYM_FILTER;
|
|
||||||
$2->def = $3;
|
|
||||||
$3->name = $2->name;
|
$3->name = $2->name;
|
||||||
printf( "We have new filter defined (%s)\n", $2->name )
|
printf( "We have new filter defined (%s)\n", $2->name )
|
||||||
}
|
}
|
||||||
|
@ -67,8 +65,7 @@ type:
|
||||||
|
|
||||||
decls: /* EMPTY */
|
decls: /* EMPTY */
|
||||||
| type SYM ';' decls {
|
| type SYM ';' decls {
|
||||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined, can not use as variable\n" );
|
cf_define_symbol($2, SYM_VARIABLE | $1, NULL);
|
||||||
$2->class = SYM_VARIABLE | $1;
|
|
||||||
printf( "New variable %s type %x\n", $2->name, $1 );
|
printf( "New variable %s type %x\n", $2->name, $1 );
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -104,9 +101,7 @@ CF_ADDTO(conf, function_def)
|
||||||
function_def:
|
function_def:
|
||||||
FUNCTION SYM function_params function_body {
|
FUNCTION SYM function_params function_body {
|
||||||
extern struct f_inst *startup_func;
|
extern struct f_inst *startup_func;
|
||||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
cf_define_symbol($2, SYM_FUNCTION, $4);
|
||||||
$2->class = SYM_FUNCTION;
|
|
||||||
$2->def = $4;
|
|
||||||
if (!strcasecmp($2->name, "startup"))
|
if (!strcasecmp($2->name, "startup"))
|
||||||
startup_func = $4;
|
startup_func = $4;
|
||||||
printf("Hmm, we've got one function here - %s\n", $2->name);
|
printf("Hmm, we've got one function here - %s\n", $2->name);
|
||||||
|
|
Loading…
Reference in a new issue