summaryrefslogtreecommitdiffstats
path: root/grammar
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-07-08 19:00:23 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-07-08 19:00:23 +0200
commitf2ef6cd10699ab9f91b9e3e53726512cd290ea68 (patch)
treebfd523b0adce631dfd0914b60c4e66d101d9fd37 /grammar
parentd649820ee508a9de3bcf37a9e3b71ff11ca3a8ea (diff)
downloadrsyslog-f2ef6cd10699ab9f91b9e3e53726512cd290ea68.tar.gz
rsyslog-f2ef6cd10699ab9f91b9e3e53726512cd290ea68.tar.xz
rsyslog-f2ef6cd10699ab9f91b9e3e53726512cd290ea68.zip
optimized function representation
Diffstat (limited to 'grammar')
-rw-r--r--grammar/rainerscript.c36
-rw-r--r--grammar/rainerscript.h4
2 files changed, 31 insertions, 9 deletions
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index 91e71e97..de15d5f3 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -685,6 +685,9 @@ void
cnfexprPrint(struct cnfexpr *expr, int indent)
{
struct cnffparamlst *param;
+ struct cnffunc *func;
+ int i;
+
//dbgprintf("expr %p, indent %d, type '%c'\n", expr, indent, expr->nodetype);
switch(expr->nodetype) {
case CMP_EQ:
@@ -779,12 +782,11 @@ cnfexprPrint(struct cnfexpr *expr, int indent)
break;
case 'F':
doIndent(indent);
- cstrPrint("function '", ((struct cnffunc*)expr)->fname);
- dbgprintf("'\n");
- for( param = ((struct cnffunc*)expr)->paramlst
- ; param != NULL
- ; param = param->next) {
- cnfexprPrint(param->expr, indent+1);
+ func = (struct cnffunc*) expr;
+ cstrPrint("function '", func->fname);
+ dbgprintf("' (%u params)\n", (unsigned) func->nParams);
+ for(i = 0 ; i < func->nParams ; ++i) {
+ cnfexprPrint(func->expr[i], indent+1);
}
break;
case '+':
@@ -888,10 +890,28 @@ struct cnffunc *
cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst)
{
struct cnffunc* func;
- if((func = malloc(sizeof(struct cnffunc))) != NULL) {
+ struct cnffparamlst *param, *toDel;
+ unsigned short i;
+ unsigned short nParams;
+
+ /* we first need to find out how many params we have */
+ nParams = 0;
+ for(param = paramlst ; param != NULL ; param = param->next)
+ ++nParams;
+ if((func = malloc(sizeof(struct cnffunc) + (nParams * sizeof(struct cnfexp*))))
+ != NULL) {
func->nodetype = 'F';
func->fname = fname;
- func->paramlst = paramlst;
+ func->nParams = nParams;
+ func->fID = 0; /* use name */
+ /* shuffle params over to array (access speed!) */
+ param = paramlst;
+ for(i = 0 ; i < nParams ; ++i) {
+ func->expr[i] = param->expr;
+ toDel = param;
+ param = param->next;
+ free(toDel);
+ }
}
return func;
}
diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h
index 8b5c36de..b7abf153 100644
--- a/grammar/rainerscript.h
+++ b/grammar/rainerscript.h
@@ -128,7 +128,9 @@ struct cnffparamlst {
struct cnffunc {
unsigned nodetype;
es_str_t *fname;
- struct cnffparamlst *paramlst;
+ unsigned short nParams;
+ unsigned short *fID; /* function ID for built-ins, 0 means use name */
+ struct cnfexpr *expr[];
};
/* future extensions