Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison macro.c @ 155:e6eb15635a48
Don't shortcut macro expansion of non-parameter macros.
It won't work once we have more kinds of expansion items than strings
and arguments, viz., magic tokens for __FILE__ and __LINE__ and so on.
author | David A. Holland |
---|---|
date | Fri, 12 Jun 2015 01:53:42 -0400 (2015-06-12) |
parents | e787bd67bf88 |
children | 8d8a4bfd4684 |
comparison
equal
deleted
inserted
replaced
154:a2c2fe8dbea3 | 155:e6eb15635a48 |
---|---|
869 static | 869 static |
870 void | 870 void |
871 expand_got_word(struct expstate *es, struct place *p, char *buf, size_t len) | 871 expand_got_word(struct expstate *es, struct place *p, char *buf, size_t len) |
872 { | 872 { |
873 struct macro *m; | 873 struct macro *m; |
874 struct expansionitem *ei; | |
875 char *newbuf; | |
876 | 874 |
877 switch (es->state) { | 875 switch (es->state) { |
878 case ES_NORMAL: | 876 case ES_NORMAL: |
879 if (es->honordefined && | 877 if (es->honordefined && |
880 len == 7 && !memcmp(buf, "defined", 7)) { | 878 len == 7 && !memcmp(buf, "defined", 7)) { |
884 } | 882 } |
885 m = macrotable_findlen(buf, len, false); | 883 m = macrotable_findlen(buf, len, false); |
886 if (m == NULL || m->inuse) { | 884 if (m == NULL || m->inuse) { |
887 expand_send(es, p, buf, len); | 885 expand_send(es, p, buf, len); |
888 } else if (!m->hasparams) { | 886 } else if (!m->hasparams) { |
889 m->inuse = true; | 887 es->curmacro = m; |
890 assert(expansionitemarray_num(&m->expansion) == 1); | 888 expand_domacro(es, p); |
891 ei = expansionitemarray_get(&m->expansion, 0); | 889 es->curmacro = NULL; |
892 assert(ei->isstring); | |
893 newbuf = macroexpand(p, ei->string, | |
894 strlen(ei->string), false); | |
895 doexpand(es, p, newbuf, strlen(newbuf)); | |
896 dostrfree(newbuf); | |
897 m->inuse = false; | |
898 } else { | 890 } else { |
899 es->curmacro = m; | 891 es->curmacro = m; |
900 es->state = ES_WANTLPAREN; | 892 es->state = ES_WANTLPAREN; |
901 } | 893 } |
902 break; | 894 break; |