Mercurial > ~dholland > hg > tradcpp > index.cgi
changeset 172:3e7e696fe558
Clean up the mess Joerg made of apply_builtin_macros().
author | David A. Holland |
---|---|
date | Fri, 12 Jun 2015 02:14:45 -0400 |
parents | 5922e6ca6b80 |
children | 6ff17ab68b16 |
files | macro.c macro.h main.c |
diffstat | 3 files changed, 38 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/macro.c Fri Jun 12 02:05:29 2015 -0400 +++ b/macro.c Fri Jun 12 02:14:45 2015 -0400 @@ -602,30 +602,6 @@ } void -macro_define_file(struct place *p) -{ - struct macro *m; - struct expansionitem *ei; - - m = macro_define_common_start(p, "__FILE__", p); - ei = expansionitem_create_file(); - expansionitemarray_add(&m->expansion, ei, NULL); - macro_define_common_end(m); -} - -void -macro_define_line(struct place *p) -{ - struct macro *m; - struct expansionitem *ei; - - m = macro_define_common_start(p, "__LINE__", p); - ei = expansionitem_create_line(); - expansionitemarray_add(&m->expansion, ei, NULL); - macro_define_common_end(m); -} - -void macro_define_params(struct place *p1, const char *macro, struct place *p2, const char *params, struct place *p3, const char *expansion) @@ -640,6 +616,24 @@ } void +macro_define_magic(struct place *p, const char *macro) +{ + struct macro *m; + struct expansionitem *ei; + + m = macro_define_common_start(p, macro, p); + if (!strcmp(macro, "__FILE__")) { + ei = expansionitem_create_file(); + } + else { + assert(!strcmp(macro, "__LINE__")); + ei = expansionitem_create_line(); + } + expansionitemarray_add(&m->expansion, ei, NULL); + macro_define_common_end(m); +} + +void macro_undef(const char *macro) { struct macro *m;
--- a/macro.h Fri Jun 12 02:05:29 2015 -0400 +++ b/macro.h Fri Jun 12 02:14:45 2015 -0400 @@ -35,13 +35,12 @@ void macros_init(void); void macros_cleanup(void); -void macro_define_file(struct place *); -void macro_define_line(struct place *); void macro_define_plain(struct place *, const char *macro, struct place *, const char *expansion); void macro_define_params(struct place *, const char *macro, struct place *, const char *params, struct place *, const char *expansion); +void macro_define_magic(struct place *, const char *macro); void macro_undef(const char *macro); bool macro_isdefined(const char *macro);
--- a/main.c Fri Jun 12 02:05:29 2015 -0400 +++ b/main.c Fri Jun 12 02:14:45 2015 -0400 @@ -195,14 +195,12 @@ static void -apply_special_macros(unsigned *builtin_counter) +apply_magic_macro(unsigned num, const char *name) { struct place p; - place_setbuiltin(&p, ++(*builtin_counter)); - macro_define_file(&p); - place_setbuiltin(&p, ++(*builtin_counter)); - macro_define_line(&p); + place_setbuiltin(&p, num); + macro_define_magic(&p, name); } static @@ -217,35 +215,38 @@ static void -apply_builtin_macros(unsigned *builtin_counter) +apply_builtin_macros(void) { + unsigned n = 1; + + apply_magic_macro(n++, "__FILE__"); + apply_magic_macro(n++, "__LINE__"); + #ifdef CONFIG_OS - apply_builtin_macro(++(*builtin_counter), CONFIG_OS, "1"); + apply_builtin_macro(n++, CONFIG_OS, "1"); #endif #ifdef CONFIG_OS_2 - apply_builtin_macro(++(*builtin_counter), CONFIG_OS_2, "1"); + apply_builtin_macro(n++, CONFIG_OS_2, "1"); #endif #ifdef CONFIG_CPU - apply_builtin_macro(++(*builtin_counter), CONFIG_CPU, "1"); + apply_builtin_macro(n++, CONFIG_CPU, "1"); #endif #ifdef CONFIG_CPU_2 - apply_builtin_macro(++(*builtin_counter), CONFIG_CPU_2, "1"); + apply_builtin_macro(n++, CONFIG_CPU_2, "1"); #endif #ifdef CONFIG_SIZE - apply_builtin_macro(++(*builtin_counter), CONFIG_SIZE, "1"); + apply_builtin_macro(n++, CONFIG_SIZE, "1"); #endif #ifdef CONFIG_BINFMT - apply_builtin_macro(++(*builtin_counter), CONFIG_BINFMT, "1"); + apply_builtin_macro(n++, CONFIG_BINFMT, "1"); #endif #ifdef CONFIG_COMPILER - apply_builtin_macro(++(*builtin_counter), CONFIG_COMPILER, - VERSION_MAJOR); - apply_builtin_macro(++(*builtin_counter), CONFIG_COMPILER_MINOR, - VERSION_MINOR); - apply_builtin_macro(++(*builtin_counter), "__VERSION__", VERSION_LONG); + apply_builtin_macro(n++, CONFIG_COMPILER, VERSION_MAJOR); + apply_builtin_macro(n++, CONFIG_COMPILER_MINOR, VERSION_MINOR); + apply_builtin_macro(n++, "__VERSION__", VERSION_LONG); #endif } @@ -1043,7 +1044,6 @@ const char *inputfile = NULL; const char *outputfile = NULL; struct place cmdplace; - unsigned builtin_counter; int i; progname = strrchr(argv[0], '/'); @@ -1089,11 +1089,7 @@ mode.output_file = outputfile; loadincludepath(); - - builtin_counter = 0; - apply_special_macros(&builtin_counter); - apply_builtin_macros(&builtin_counter); - + apply_builtin_macros(); apply_commandline_macros(); read_commandline_files(); place_setnowhere(&cmdplace);