comparison macro.c @ 167:fa9752f194c6

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. (separate version of this applied against Joerg's changes, because we need to revert some of them)
author David A. Holland
date Fri, 12 Jun 2015 01:55:31 -0400
parents f14f5352956c
children 8d8a4bfd4684
comparison
equal deleted inserted replaced
166:4ea0ce804d22 167:fa9752f194c6
946 static 946 static
947 void 947 void
948 expand_got_word(struct expstate *es, struct place *p, char *buf, size_t len) 948 expand_got_word(struct expstate *es, struct place *p, char *buf, size_t len)
949 { 949 {
950 struct macro *m; 950 struct macro *m;
951 struct expansionitem *ei;
952 char *newbuf;
953 951
954 switch (es->state) { 952 switch (es->state) {
955 case ES_NORMAL: 953 case ES_NORMAL:
956 if (es->honordefined && 954 if (es->honordefined &&
957 len == 7 && !memcmp(buf, "defined", 7)) { 955 len == 7 && !memcmp(buf, "defined", 7)) {
960 break; 958 break;
961 } 959 }
962 m = macrotable_findlen(buf, len, false); 960 m = macrotable_findlen(buf, len, false);
963 if (m == NULL || m->inuse) { 961 if (m == NULL || m->inuse) {
964 expand_send(es, p, buf, len); 962 expand_send(es, p, buf, len);
965 } else if (m->isspecial) { 963 } else if (!m->hasparams) {
966 es->curmacro = m; 964 es->curmacro = m;
967 newbuf = expand_substitute(p, es); 965 expand_domacro(es, p);
968 expand_send(es, p, newbuf, strlen(newbuf));
969 dostrfree(newbuf);
970 es->curmacro = NULL; 966 es->curmacro = NULL;
971 m->inuse = false;
972 } else if (!m->hasparams) {
973 m->inuse = true;
974 assert(expansionitemarray_num(&m->expansion) == 1);
975 ei = expansionitemarray_get(&m->expansion, 0);
976 assert(ei->itemtype == EI_STRING);
977 newbuf = macroexpand(p, ei->string,
978 strlen(ei->string), false);
979 doexpand(es, p, newbuf, strlen(newbuf));
980 dostrfree(newbuf);
981 m->inuse = false;
982 } else { 967 } else {
983 es->curmacro = m; 968 es->curmacro = m;
984 es->state = ES_WANTLPAREN; 969 es->state = ES_WANTLPAREN;
985 } 970 }
986 break; 971 break;