corrected the treatment of PREDEF-ed macros
This commit is contained in:
parent
bb8d6b5143
commit
b5e1097890
3 changed files with 10 additions and 37 deletions
|
@ -274,15 +274,9 @@ go_on: /* rescan, the following character has been read */
|
||||||
*tg++ = '\0'; /* mark the end of the identifier */
|
*tg++ = '\0'; /* mark the end of the identifier */
|
||||||
idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash);
|
idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash);
|
||||||
#ifndef NOPP
|
#ifndef NOPP
|
||||||
if (idef->id_macro && ReplaceMacros) {
|
if (idef->id_macro && ReplaceMacros && replace(idef))
|
||||||
/* macro replacement should be performed */
|
/* macro replacement should be performed */
|
||||||
if (replace(idef))
|
goto again;
|
||||||
goto again;
|
|
||||||
/* arrived here: something went wrong in
|
|
||||||
replace, don't substitute in this case
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (UnknownIdIsZero) {
|
if (UnknownIdIsZero) {
|
||||||
ptok->tk_ival = (arith)0;
|
ptok->tk_ival = (arith)0;
|
||||||
ptok->tk_fund = INT;
|
ptok->tk_fund = INT;
|
||||||
|
|
|
@ -81,8 +81,6 @@ init_pp()
|
||||||
containing a number of identifiers to be
|
containing a number of identifiers to be
|
||||||
predefined at the host machine (for example
|
predefined at the host machine (for example
|
||||||
-DPREDEFINE="vax,unix,pmds").
|
-DPREDEFINE="vax,unix,pmds").
|
||||||
Note that PREDEF causes the identifier not
|
|
||||||
to be substituted.
|
|
||||||
*/
|
*/
|
||||||
register char *s = PREDEFINE;
|
register char *s = PREDEFINE;
|
||||||
register char *id;
|
register char *id;
|
||||||
|
@ -96,7 +94,7 @@ init_pp()
|
||||||
while (in_idf(*s++));
|
while (in_idf(*s++));
|
||||||
c = *--s;
|
c = *--s;
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
macro_def(str2idf(id), "", -1, 0, PREDEF);
|
macro_def(str2idf(id), "1", -1, 1, PREDEF);
|
||||||
*s = c;
|
*s = c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -43,29 +43,22 @@ replace(idef)
|
||||||
if (idef->id_macro->mc_nps != -1) { /* with parameter list */
|
if (idef->id_macro->mc_nps != -1) { /* with parameter list */
|
||||||
LoadChar(c);
|
LoadChar(c);
|
||||||
c = skipspaces(c);
|
c = skipspaces(c);
|
||||||
|
|
||||||
if (c != '(') { /* no replacement if no () */
|
if (c != '(') { /* no replacement if no () */
|
||||||
lexerror("(warning) macro %s needs arguments",
|
lexerror("(warning) macro %s needs arguments",
|
||||||
idef->id_text);
|
idef->id_text);
|
||||||
PushBack();
|
PushBack();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
actpars = getactuals(idef); /* get act.param. list */
|
actpars = getactuals(idef); /* get act.param. list */
|
||||||
}
|
}
|
||||||
|
if ((flags & PREDEF) && (UnknownIdIsZero == 0))
|
||||||
if (flags & PREDEF) { /* don't replace this one... */
|
/* don't replace this one... */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
if (flags & FUNC) /* this macro leads to special action */
|
||||||
|
|
||||||
if (flags & FUNC) { /* this macro leads to special action */
|
|
||||||
macro_func(idef);
|
macro_func(idef);
|
||||||
}
|
|
||||||
|
|
||||||
/* create and input buffer */
|
/* create and input buffer */
|
||||||
reptext = macro2buffer(idef, actpars, &size);
|
reptext = macro2buffer(idef, actpars, &size);
|
||||||
InsertText(reptext, size);
|
InsertText(reptext, size);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +75,6 @@ macro_func(idef)
|
||||||
|
|
||||||
/* This switch is very blunt... */
|
/* This switch is very blunt... */
|
||||||
switch (idef->id_text[2]) {
|
switch (idef->id_text[2]) {
|
||||||
|
|
||||||
case 'F' : /* __FILE__ */
|
case 'F' : /* __FILE__ */
|
||||||
FilNamBuf[0] = '"';
|
FilNamBuf[0] = '"';
|
||||||
strcpy(&FilNamBuf[1], FileName);
|
strcpy(&FilNamBuf[1], FileName);
|
||||||
|
@ -90,15 +82,12 @@ macro_func(idef)
|
||||||
idef->id_macro->mc_text = FilNamBuf;
|
idef->id_macro->mc_text = FilNamBuf;
|
||||||
idef->id_macro->mc_length = strlen(FilNamBuf);
|
idef->id_macro->mc_length = strlen(FilNamBuf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L' : /* __LINE__ */
|
case 'L' : /* __LINE__ */
|
||||||
idef->id_macro->mc_text = long2str((long)LineNumber, 10);
|
idef->id_macro->mc_text = long2str((long)LineNumber, 10);
|
||||||
idef->id_macro->mc_length = 1;
|
idef->id_macro->mc_length = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
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
|
parameter list actpars. A pointer to the beginning of the
|
||||||
constructed text is returned, while *siztext is filled
|
constructed text is returned, while *siztext is filled
|
||||||
with its length.
|
with its length.
|
||||||
|
|
||||||
If there are no parameters, this function behaves
|
If there are no parameters, this function behaves
|
||||||
the same as strcpy().
|
the same as strcpy().
|
||||||
*/
|
*/
|
||||||
|
@ -125,35 +113,28 @@ macro2buffer(idef, actpars, siztext)
|
||||||
register char *ptr = idef->id_macro->mc_text;
|
register char *ptr = idef->id_macro->mc_text;
|
||||||
|
|
||||||
text[pos++] = '\0'; /* allow pushback */
|
text[pos++] = '\0'; /* allow pushback */
|
||||||
|
|
||||||
while (*ptr) {
|
while (*ptr) {
|
||||||
if (*ptr & FORMALP) { /* non-asc formal param. mark */
|
if (*ptr & FORMALP) { /* non-asc formal param. mark */
|
||||||
register int n = *ptr++ & 0177;
|
register int n = *ptr++ & 0177;
|
||||||
register char *p;
|
register char *p;
|
||||||
|
|
||||||
ASSERT(n != 0);
|
ASSERT(n != 0);
|
||||||
|
|
||||||
/* copy the text of the actual parameter
|
/* copy the text of the actual parameter
|
||||||
into the replacement text
|
into the replacement text
|
||||||
*/
|
*/
|
||||||
for (p = actpars[n - 1]; *p; p++) {
|
for (p = actpars[n - 1]; *p; p++) {
|
||||||
text[pos++] = *p;
|
text[pos++] = *p;
|
||||||
|
if (pos == size)
|
||||||
if (pos == size) {
|
|
||||||
text = Srealloc(text,
|
text = Srealloc(text,
|
||||||
size += RSTRSIZE);
|
size += RSTRSIZE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
text[pos++] = *ptr++;
|
text[pos++] = *ptr++;
|
||||||
|
if (pos == size)
|
||||||
if (pos == size) {
|
|
||||||
text = Srealloc(text, size += RSTRSIZE);
|
text = Srealloc(text, size += RSTRSIZE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
text[pos] = '\0';
|
text[pos] = '\0';
|
||||||
*siztext = pos;
|
*siztext = pos;
|
||||||
return text;
|
return text;
|
||||||
|
|
Loading…
Reference in a new issue