diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-10-02 21:47:44 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-10-02 21:47:44 +0300 |
commit | be7310823e55650143e2873c6d3118db38afdf75 (patch) | |
tree | 02abe4ddc7f0a725f788db0ddd2b73c9b418d739 | |
parent | 26f33cd3d334c4ac8044dfb49785414ed59cc254 (diff) | |
download | mailfromd-be7310823e55650143e2873c6d3118db38afdf75.tar.gz mailfromd-be7310823e55650143e2873c6d3118db38afdf75.tar.bz2 |
Minor changes.
* mfd/gram.y: Improve module ending rules.
* mfd/lex.l: Add more comments.
(lex_buffer_push): Rename to inctx_push.
(lex_buffer_pop): Rename to inctx_pop.
* mfd/mailfromd.h (module_push): Remove.
* mfd/symbols.c: Mark module_ functions
as statics.
-rw-r--r-- | mfd/gram.y | 12 | ||||
-rw-r--r-- | mfd/lex.l | 67 | ||||
-rw-r--r-- | mfd/mailfromd.h | 1 | ||||
-rw-r--r-- | mfd/symbols.c | 16 |
4 files changed, 58 insertions, 38 deletions
@@ -490,11 +490,7 @@ input : program ; program : decllist - | moddecl decllist modend - { - $$ = $2; - } - | moddecl decllist + | moddecl decllist bye { $$ = $2; } @@ -533,7 +529,7 @@ modcntl : require { $$.head = $$.tail = NULL; } - | require T_MODBEG opt_moddecl decllist modend + | require T_MODBEG opt_moddecl decllist bye T_MODEND { $$ = $4; pop_top_module(); @@ -581,11 +577,11 @@ require : T_REQUIRE literal } ; -modend : T_BYE +bye : /* empty */ + | T_BYE { lex_bye(); } - | T_MODEND ; imports : literal @@ -67,26 +67,34 @@ get_locus() #define keyword(kw) (yylval.locus = locus,(kw)) -#define INCTX_MODULE 0x1 -#define INCTX_HADINPUT 0x2 - -/* Input stack support */ -struct inctx { /* input context structure */ - struct inctx *parent; - struct locus locus; - struct input_file_ident id; - FILE *file; - pid_t pp_pid; /* Preprocessor pid, if used */ - int inctx_flags; - YY_BUFFER_STATE buf; /* Lex buffer state */ +/* Input context flags */ +#define INCTX_MODULE 0x1 /* current input is a MFL module */ +#define INCTX_HADINPUT 0x2 /* some statements has already been processed */ + +/* Input context stack */ +struct inctx { /* input context structure */ + struct inctx *parent; /* parent context */ + struct locus locus; /* locus where the context was pushed */ + struct input_file_ident id;/* file id structure to prevent recursion */ + FILE *file; /* saved yyin */ + pid_t pp_pid; /* preprocessor pid, if used */ + int inctx_flags; /* input context flags */ + YY_BUFFER_STATE buf; /* lex buffer state */ }; -struct inctx *inctx_tos; -static pid_t pp_pid; /* Preprocessor pid */ +struct inctx *inctx_tos; /* stack of input contexts */ + +/* Current input context: */ +static pid_t pp_pid; /* preprocessor pid */ static struct input_file_ident input_file_id; -static int inctx_flags; +static int inctx_flags; /* input context flags */ + +/* If not 0, emit_token keeps a token that yylex must return on the + next call. See YY_USER_ACTION below. */ static int emit_token; +/* Find on stack an input context that matches the given file id. + Return pointer to the context. */ struct inctx * inctx_locate(struct input_file_ident *id) { @@ -99,9 +107,9 @@ inctx_locate(struct input_file_ident *id) return ctx; } - +/* Push input context */ static void -lex_buffer_push() +inctx_push() { struct inctx *ctx = xmalloc(sizeof(*ctx)); @@ -115,8 +123,10 @@ lex_buffer_push() inctx_tos = ctx; } +/* Pop input context from the top of the stack into the current + input context. Return 1 if there are no more contexts left. */ int -lex_buffer_pop() +inctx_pop() { struct inctx *ctx = inctx_tos; @@ -136,6 +146,8 @@ lex_buffer_pop() return 0; } +/* Setup the scanner for input from the file NAME. Return 0 on success, + and an appropriate EX_ code on error. See lex_new_source below. */ static int lex_new_source_0(const char *name) { @@ -162,6 +174,9 @@ lex_new_source_0(const char *name) return EX_OK; } +/* Save the current input context on stack and set up the scanner for + input from the file NAME. Return 0 on success, + and an appropriate EX_ code on error. */ int lex_new_source(const char *name, int flag) { @@ -196,10 +211,10 @@ lex_new_source(const char *name, int flag) return 0; if (yyin) - lex_buffer_push(); + inctx_push(); rc = lex_new_source_0(name); if (rc) - lex_buffer_pop(); + inctx_pop(); else { input_file_id = id; if (flag == LEX_MODULE) { @@ -212,6 +227,8 @@ lex_new_source(const char *name, int flag) } +/* Return constant or variable token corresponding to the current + value of yylval.literal->text. */ static int variable_or_const() { @@ -245,14 +262,19 @@ variable_or_const() return T_VARIABLE; } +/* Advance locus to the next line */ void advance_line() { ++locus.line; } +/* Same as BEGIN, but also saves the current locus. It is then used + to report unclosed constructs at the end of file. */ #define BEGIN_X(s) do { BEGIN(s); start_locus = locus; } while(0) +/* If emit_token is not 0, push back current input and return the value + of emit_token. Clear emit_token before returning. */ #define YY_USER_ACTION \ if (emit_token) { \ int tok = emit_token; \ @@ -264,6 +286,7 @@ advance_line() return tok; \ } \ +/* Read next input chunk. */ #define YY_INPUT(buf,result,max_size) \ if (yyin == NULL) \ result = YY_NULL; \ @@ -271,6 +294,8 @@ advance_line() && ferror(yyin)) \ YY_FATAL_ERROR("input in flex scanner failed"); +/* Redeclare main entry point. Actual yylex is defined in the code section + below. */ #define YY_DECL static int lexscan(void) %} @@ -937,7 +962,7 @@ lex_close_source() case QML: parse_error_locus(&start_locus, _("end of file in string")); } - return lex_buffer_pop(); + return inctx_pop(); } void diff --git a/mfd/mailfromd.h b/mfd/mailfromd.h index 5cdb34f0..965bfd94 100644 --- a/mfd/mailfromd.h +++ b/mfd/mailfromd.h @@ -757,7 +757,6 @@ int set_top_module(const char *name, const char *file, struct import_rule *import_rules, const struct locus *locus); void pop_top_module(void); -void module_push(struct module *mod); void collect_modules(struct module ***pmodv, size_t *pmodc); diff --git a/mfd/symbols.c b/mfd/symbols.c index e4b61f84..75c81484 100644 --- a/mfd/symbols.c +++ b/mfd/symbols.c @@ -447,7 +447,7 @@ module_import_symbols(struct module *dst, struct module *src, struct module *top_module; struct module_list *module_stack; -void +static void module_init(struct module *mod, const char *name, const char *file) { mod->name = mf_strdup(name); @@ -468,7 +468,7 @@ module_init(struct module *mod, const char *name, const char *file) mod->incl_sources = NULL; } -struct module * +static struct module * module_create(const char *name, const char *file) { struct module *mod = alloc_entry(sizeof(*mod)); @@ -476,7 +476,7 @@ module_create(const char *name, const char *file) return mod; } -void +static void module_free(struct module *mod) { int i; @@ -487,7 +487,7 @@ module_free(struct module *mod) mu_list_destroy(&mod->incl_sources); } -void +static void module_add_submodule(struct module *mod, struct module *submod) { struct module_list *p = alloc_entry(sizeof(*p)); @@ -500,7 +500,7 @@ module_add_submodule(struct module *mod, struct module *submod) mod->submodule_tail = p; } -int +static int module_has_submodule(struct module *mod, struct module *submod) { struct module_list *p; @@ -510,7 +510,7 @@ module_has_submodule(struct module *mod, struct module *submod) return 0; } -void +static void module_push(struct module *mod) { struct module_list *p = alloc_entry(sizeof(*p)); @@ -519,7 +519,7 @@ module_push(struct module *mod) module_stack = p; } -struct module * +static struct module * module_pop() { struct module_list *p = module_stack; @@ -609,7 +609,7 @@ collect_modules(struct module ***pmodv, size_t *pmodc) } -void +static void free_module_entry(void *ptr) { module_free((struct module *)ptr); |