From b6f4e10438f7d01df2ac22646244762a1c27b1dc Mon Sep 17 00:00:00 2001 From: Don Williamson Date: Fri, 10 Mar 2017 12:33:43 +0000 Subject: [PATCH] Support number##identifier token pasting. Example: #define K_DOUBLE(x) x##l K_DOUBLE(0.5) --- src/fcpp.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/fcpp.c b/src/fcpp.c index 1b8ea0d..9ad50d7 100644 --- a/src/fcpp.c +++ b/src/fcpp.c @@ -940,7 +940,7 @@ void Putstring(struct Global *, char *); void Putint(struct Global *, int); char *savestring(struct Global *, char *); ReturnCode addfile(struct Global *, FILE *, char *); -int catenate(struct Global *, ReturnCode *); +int catenate(struct Global *, int lhs_number, ReturnCode *); void cerror(struct Global *, ErrorCode, ...); ReturnCode control(struct Global *, int *); ReturnCode dodefine(struct Global *); @@ -1265,7 +1265,7 @@ ReturnCode cppmain(struct Global *global) } if((ret=macroid(global, &c))) /* Grab the token */ return(ret); - } while (type[c] == LET && catenate(global, &ret) && !ret); + } while (type[c] == LET && catenate(global, 0, &ret) && !ret); if(ret) /* If the loop was broken because of a fatal error! */ return(ret); @@ -1291,6 +1291,9 @@ ReturnCode cppmain(struct Global *global) ret=scannumber(global, c, (ReturnCode(*)(struct Global *, int))output); if(ret) return(ret); + catenate(gloabl, 1, &ret); /* Check to see if the number is the lhs of a macro concat */ + if (ret) + return(ret); break; case QUO: /* char or string const */ go = 0; @@ -3691,7 +3694,7 @@ ReturnCode evallex(struct Global *global, *op=OP_EOE; /* End of expression */ return(FPP_OK); } - } while ((t = type[c]) == LET && catenate(global, &ret) && !ret); + } while ((t = type[c]) == LET && catenate(global, 0, &ret) && !ret); if(ret) /* If the loop was broken because of a fatal error! */ return(ret); @@ -3852,7 +3855,7 @@ ReturnCode dosizeof(struct Global *global, int *result) } else if (type[c] != LET) /* Exit if not a type */ break; - else if (!catenate(global, &ret) && !ret) { /* Maybe combine tokens */ + else if (!catenate(global, 0, &ret) && !ret) { /* Maybe combine tokens */ /* * Look for this unexpandable token in basic_types. * The code accepts "int long" as well as "long int" @@ -4368,7 +4371,7 @@ ReturnCode macroid(struct Global *global, int *c) return(FPP_OK); } -int catenate(struct Global *global, ReturnCode *ret) +int catenate(struct Global *global, int lhs_number, ReturnCode *ret) { /* * A token was just read (via macroid). @@ -4380,7 +4383,7 @@ int catenate(struct Global *global, ReturnCode *ret) #if OK_CONCAT int c; - char *token1; + char *token1 = ""; #endif #if OK_CONCAT @@ -4389,7 +4392,8 @@ int catenate(struct Global *global, ReturnCode *ret) return (FALSE); } else { - token1 = savestring(global, global->tokenbuf); /* Save first token */ + if (lhs_number == 0) /* The lhs number has already been emit */ + token1 = savestring(global, global->tokenbuf); /* Save first token */ c=get(global); if(global->rightconcat) { *ret=macroid(global, &c); /* Scan next token */ @@ -4432,7 +4436,8 @@ int catenate(struct Global *global, ReturnCode *ret) * new (concatenated) token after freeing token1. * Finally, setup to read the new token. */ - free(token1); /* Free up memory */ + if (lhs_number == 0) + free(token1); /* Free up memory */ *ret=ungetstring(global, global->work); /* Unget the new thing, */ if(*ret) return(FALSE);