From: erikb Date: Fri, 4 Apr 1986 11:31:03 +0000 (+0000) Subject: corrected the treatment of PREDEF-ed macros X-Git-Tag: release-5-5~5320 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b5e1097890d5d143ed50574c483c393101d8ecd9;p=ack.git corrected the treatment of PREDEF-ed macros --- diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index 220137467..a1182d914 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -274,15 +274,9 @@ go_on: /* rescan, the following character has been read */ *tg++ = '\0'; /* mark the end of the identifier */ idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash); #ifndef NOPP - if (idef->id_macro && ReplaceMacros) { + if (idef->id_macro && ReplaceMacros && replace(idef)) /* macro replacement should be performed */ - if (replace(idef)) - goto again; - /* arrived here: something went wrong in - replace, don't substitute in this case - */ - } - else + goto again; if (UnknownIdIsZero) { ptok->tk_ival = (arith)0; ptok->tk_fund = INT; diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index fcfe547b8..c5cf19cd8 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -81,8 +81,6 @@ init_pp() containing a number of identifiers to be predefined at the host machine (for example -DPREDEFINE="vax,unix,pmds"). - Note that PREDEF causes the identifier not - to be substituted. */ register char *s = PREDEFINE; register char *id; @@ -96,7 +94,7 @@ init_pp() while (in_idf(*s++)); c = *--s; *s = '\0'; - macro_def(str2idf(id), "", -1, 0, PREDEF); + macro_def(str2idf(id), "1", -1, 1, PREDEF); *s = c; } else diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 0b0f73029..8738fa0ec 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -43,29 +43,22 @@ replace(idef) if (idef->id_macro->mc_nps != -1) { /* with parameter list */ LoadChar(c); c = skipspaces(c); - if (c != '(') { /* no replacement if no () */ lexerror("(warning) macro %s needs arguments", idef->id_text); PushBack(); return 0; } - actpars = getactuals(idef); /* get act.param. list */ } - - if (flags & PREDEF) { /* don't replace this one... */ - return 0; - } - - if (flags & FUNC) { /* this macro leads to special action */ + if ((flags & PREDEF) && (UnknownIdIsZero == 0)) + /* don't replace this one... */ + return 0; + if (flags & FUNC) /* this macro leads to special action */ macro_func(idef); - } - /* create and input buffer */ reptext = macro2buffer(idef, actpars, &size); InsertText(reptext, size); - return 1; } @@ -82,7 +75,6 @@ macro_func(idef) /* This switch is very blunt... */ switch (idef->id_text[2]) { - case 'F' : /* __FILE__ */ FilNamBuf[0] = '"'; strcpy(&FilNamBuf[1], FileName); @@ -90,15 +82,12 @@ macro_func(idef) idef->id_macro->mc_text = FilNamBuf; idef->id_macro->mc_length = strlen(FilNamBuf); break; - case 'L' : /* __LINE__ */ idef->id_macro->mc_text = long2str((long)LineNumber, 10); idef->id_macro->mc_length = 1; break; - default : - crash("(macro_func) illegal macro %s\n", idef->id_text); - + crash("(macro_func)"); } } @@ -115,7 +104,6 @@ macro2buffer(idef, actpars, siztext) parameter list actpars. A pointer to the beginning of the constructed text is returned, while *siztext is filled with its length. - If there are no parameters, this function behaves the same as strcpy(). */ @@ -125,35 +113,28 @@ macro2buffer(idef, actpars, siztext) register char *ptr = idef->id_macro->mc_text; text[pos++] = '\0'; /* allow pushback */ - while (*ptr) { if (*ptr & FORMALP) { /* non-asc formal param. mark */ register int n = *ptr++ & 0177; register char *p; ASSERT(n != 0); - /* copy the text of the actual parameter into the replacement text */ for (p = actpars[n - 1]; *p; p++) { text[pos++] = *p; - - if (pos == size) { + if (pos == size) text = Srealloc(text, size += RSTRSIZE); - } } } else { text[pos++] = *ptr++; - - if (pos == size) { + if (pos == size) text = Srealloc(text, size += RSTRSIZE); - } } } - text[pos] = '\0'; *siztext = pos; return text;