introduce a new frontend to npval for the very common case

of creating an object for a tring value PV_WORD.
Start using it.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@23640 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Luigi Rizzo
2006-04-30 13:57:08 +00:00
parent 44c5e823e6
commit f239ec2080
3 changed files with 351 additions and 387 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -115,7 +115,7 @@
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 53 "ael.y" #line 49 "ael.y"
typedef union YYSTYPE { typedef union YYSTYPE {
int intval; /* integer value, typically flags */ int intval; /* integer value, typically flags */
char *str; /* strings */ char *str; /* strings */

View File

@@ -28,10 +28,6 @@
#include "asterisk/utils.h" /* ast_calloc() */ #include "asterisk/utils.h" /* ast_calloc() */
#include "asterisk/ael_structs.h" #include "asterisk/ael_structs.h"
/* create a new object with start-end marker */
static pval *npval(pvaltype type, int first_line, int last_line,
int first_column, int last_column);
static pval * linku1(pval *head, pval *tail); static pval * linku1(pval *head, pval *tail);
void reset_parencount(yyscan_t yyscanner); void reset_parencount(yyscan_t yyscanner);
@@ -61,11 +57,18 @@ static char *ael_token_subst(char *mess);
void yyerror(YYLTYPE *locp, struct parse_io *parseio, char const *s); void yyerror(YYLTYPE *locp, struct parse_io *parseio, char const *s);
int ael_yylex (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , void * yyscanner); int ael_yylex (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , void * yyscanner);
/* create a new object with start-end marker */
static pval *npval(pvaltype type, int first_line, int last_line,
int first_column, int last_column);
/* create a new object with start-end marker, simplified interface. /* create a new object with start-end marker, simplified interface.
* Must be declared here because YYLTYPE is not known before * Must be declared here because YYLTYPE is not known before
*/ */
static pval *npval2(pvaltype type, YYLTYPE *first, YYLTYPE *last); static pval *npval2(pvaltype type, YYLTYPE *first, YYLTYPE *last);
/* another frontend for npval, this time for a string */
static pval *nword(char *string, YYLTYPE *pos);
/* update end position of an object, return the object */ /* update end position of an object, return the object */
static pval *update_last(pval *, YYLTYPE *); static pval *update_last(pval *, YYLTYPE *);
%} %}
@@ -244,9 +247,7 @@ global_statement : word EQ { reset_semicount(parseio->scanner); } word SEMI {
$$->u2.val = $4; } $$->u2.val = $4; }
; ;
arglist : word { arglist : word { $$= nword($1, &@1); }
$$= npval2(PV_WORD, &@1, &@1);
$$->u1.str = $1; }
| arglist COMMA word { | arglist COMMA word {
pval *z = npval2(PV_WORD, &@1, &@3); pval *z = npval2(PV_WORD, &@1, &@3);
z->u1.str = $3; z->u1.str = $3;
@@ -332,24 +333,17 @@ iftime_head : KW_IFTIME LP word3_list COLON word3_list COLON word3_list
free($3); free($3);
free($5); free($5);
free($7); free($7);
$$->u1.list->next = npval2(PV_WORD, &@9, &@9); $$->u1.list->next = nword($9, &@9);
$$->u1.list->next->u1.str = $9; $$->u1.list->next->next = nword($11, &@11);
$$->u1.list->next->next = npval2(PV_WORD, &@11, &@11); $$->u1.list->next->next->next = nword($13, &@13);
$$->u1.list->next->next->u1.str = $11;
$$->u1.list->next->next->next = npval2(PV_WORD, &@13, &@13);
$$->u1.list->next->next->next->u1.str = $13;
prev_word = 0; prev_word = 0;
} }
| KW_IFTIME LP word BAR word3_list BAR word3_list BAR word3_list RP { | KW_IFTIME LP word BAR word3_list BAR word3_list BAR word3_list RP {
$$ = npval2(PV_IFTIME, &@1, &@5); /* XXX @5 or greater ? */ $$ = npval2(PV_IFTIME, &@1, &@5); /* XXX @5 or greater ? */
$$->u1.list = npval2(PV_WORD, &@3, &@3); $$->u1.list = nword($3, &@3);
$$->u1.list->u1.str = $3; $$->u1.list->next = nword($5, &@5);
$$->u1.list->next = npval2(PV_WORD, &@5, &@5); $$->u1.list->next->next = nword($7, &@7);
$$->u1.list->next->u1.str = $5; $$->u1.list->next->next->next = nword($9, &@9);
$$->u1.list->next->next = npval2(PV_WORD, &@7, &@7);
$$->u1.list->next->next->u1.str = $7;
$$->u1.list->next->next->next = npval2(PV_WORD, &@9, &@9);
$$->u1.list->next->next->next->u1.str = $9;
prev_word = 0; prev_word = 0;
} }
@@ -498,58 +492,37 @@ opt_else : KW_ELSE statement { $$ = $2; }
/* XXX unused */ /* XXX unused */
bar_or_comma: BAR | COMMA ; bar_or_comma: BAR | COMMA ;
target : goto_word { $$ = npval2(PV_WORD, &@1, &@1); target : goto_word { $$ = nword($1, &@1); }
$$->u1.str = $1;}
| goto_word BAR goto_word { | goto_word BAR goto_word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = nword($1, &@1);
$$->u1.str = $1; $$->next = nword($3, &@3); }
$$->next = npval2(PV_WORD, &@3, &@3);
$$->next->u1.str = $3;}
| goto_word COMMA goto_word { | goto_word COMMA goto_word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = nword($1, &@1);
$$->u1.str = $1; $$->next = nword($3, &@3); }
$$->next = npval2(PV_WORD, &@3, &@3);
$$->next->u1.str = $3;}
| goto_word BAR goto_word BAR goto_word { | goto_word BAR goto_word BAR goto_word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = nword($1, &@1);
$$->u1.str = $1; $$->next = nword($3, &@3);
$$->next = npval2(PV_WORD, &@3, &@3); $$->next->next = nword($5, &@5); }
$$->next->u1.str = $3;
$$->next->next = npval2(PV_WORD, &@5, &@5);
$$->next->next->u1.str = $5; }
| goto_word COMMA goto_word COMMA goto_word { | goto_word COMMA goto_word COMMA goto_word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = nword($1, &@1);
$$->u1.str = $1; $$->next = nword($3, &@3);
$$->next = npval2(PV_WORD, &@3, &@3); $$->next->next = nword($5, &@5); }
$$->next->u1.str = $3;
$$->next->next = npval2(PV_WORD, &@5, &@5);
$$->next->next->u1.str = $5; }
| KW_DEFAULT BAR goto_word BAR goto_word { | KW_DEFAULT BAR goto_word BAR goto_word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = nword(strdup("default"), &@1);
$$->u1.str = strdup("default"); $$->next = nword($3, &@3);
$$->next = npval2(PV_WORD, &@3, &@3); $$->next->next = nword($5, &@5); }
$$->next->u1.str = $3;
$$->next->next = npval2(PV_WORD, &@5, &@5);
$$->next->next->u1.str = $5; }
| KW_DEFAULT COMMA goto_word COMMA goto_word { | KW_DEFAULT COMMA goto_word COMMA goto_word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = nword(strdup("default"), &@1);
$$->u1.str = strdup("default"); $$->next = nword($3, &@3);
$$->next = npval2(PV_WORD, &@3, &@3); $$->next->next = nword($5, &@5); }
$$->next->u1.str = $3;
$$->next->next = npval2(PV_WORD, &@5, &@5);
$$->next->next->u1.str = $5; }
; ;
jumptarget : goto_word { jumptarget : goto_word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = nword($1, &@1);
$$->u1.str = $1; $$->next = nword(strdup("1"), &@1); } /* jump extension[,priority][@context] */
$$->next = npval2(PV_WORD, &@1, &@1); /* XXX not really @1 */
$$->next->u1.str = strdup("1");} /* jump extension[,priority][@context] */
| goto_word COMMA goto_word { | goto_word COMMA goto_word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = nword($1, &@1);
$$->u1.str = $1; $$->next = nword($3, &@3); }
$$->next = npval2(PV_WORD, &@3, &@3);
$$->next->u1.str = $3;}
| goto_word COMMA word AT word { | goto_word COMMA word AT word {
$$ = npval2(PV_WORD, &@1, &@1); $$ = npval2(PV_WORD, &@1, &@1);
$$->u1.str = $5; $$->u1.str = $5;
@@ -945,6 +918,15 @@ static struct pval *update_last(pval *obj, YYLTYPE *last)
return obj; return obj;
} }
/* frontend for npval to create a PV_WORD string from the given token */
static pval *nword(char *string, YYLTYPE *pos)
{
pval *p = npval2(PV_WORD, pos, pos);
if (p)
p->u1.str = string;
return p;
}
/* append second element to the list in the first one */ /* append second element to the list in the first one */
static pval * linku1(pval *head, pval *tail) static pval * linku1(pval *head, pval *tail)
{ {