Add string literal concatenation using ellipses "..." (bug 4261)

Backported the changes CompuPhase did to the compiler to support string
literal concatenation including all fixes in later commits from r30 on.
http://code.google.com/p/pawnscript/source/detail?r=30

Pawn uses ellipses "..." to concatenate so it looks like this:

#define PROJECT_AUTHOR "Greyscale"
#define PROJECT_COPYRIGHT "Copyright (C) 2010  " ... PROJECT_AUTHOR

This would result in PROJECT_COPYRIGHT being defined as
"Copyright (C) 2010  Greyscale"

While i've been at it, that stringizing a macro parameter feature was
ported too.
From the changelog for version 3.3.4026
(http://www.compuphase.com/pawn/pawnhistory.htm):

The macro substition processor now recognizes the "#" character for
"stringizing" a parameter. For example, if you have the definition
#define log(%1) #%1
Then the expression log(test) will result in "test".
Note that concatenation of literal strings requires an ellipsis in pawn
(which is different than C/C++). So to combine the parameter with
literal strings, use a syntax like:
#define log(%1) "logging: " ... #%1 ... "\n"
The stringize operator is only available in the replacement text of a
macro.

Doing
PrintToServer(log(hello));
would print
logging: hello\n
This commit is contained in:
Peace-Maker
2014-05-27 13:32:59 +02:00
parent 84de0f6b85
commit cf617a4d20
5 changed files with 198 additions and 49 deletions
+33 -15
View File
@@ -146,16 +146,6 @@ void pc_closesrc(void *handle)
fclose((FILE*)handle);
}
/* pc_resetsrc()
* "position" may only hold a pointer that was previously obtained from
* pc_getpossrc()
*/
void pc_resetsrc(void *handle,void *position)
{
assert(handle!=NULL);
fsetpos((FILE*)handle,(fpos_t *)position);
}
/* pc_readsrc()
* Reads a single line from the source file (or up to a maximum number of
* characters if the line in the input file is too long).
@@ -174,12 +164,40 @@ int pc_writesrc(void *handle,unsigned char *source)
return fputs((char*)source,(FILE*)handle) >= 0;
}
void *pc_getpossrc(void *handle)
{
static fpos_t lastpos; /* may need to have a LIFO stack of such positions */
#define MAXPOSITIONS 4
static fpos_t srcpositions[MAXPOSITIONS];
static unsigned char srcposalloc[MAXPOSITIONS];
fgetpos((FILE*)handle,&lastpos);
return &lastpos;
void *pc_getpossrc(void *handle,void *position)
{
if (position==NULL) {
/* allocate a new slot */
int i;
for (i=0; i<MAXPOSITIONS && srcposalloc[i]!=0; i++)
/* nothing */;
assert(i<MAXPOSITIONS); /* if not, there is a queue overrun */
if (i>=MAXPOSITIONS)
return NULL;
position=&srcpositions[i];
srcposalloc[i]=1;
} else {
/* use the gived slot */
assert((fpos_t*)position>=srcpositions && (fpos_t*)position<srcpositions+sizeof(srcpositions));
} /* if */
fgetpos((FILE*)handle,(fpos_t*)position);
return position;
}
/* pc_resetsrc()
* "position" may only hold a pointer that was previously obtained from
* pc_getpossrc()
*/
void pc_resetsrc(void *handle,void *position)
{
assert(handle!=NULL);
assert(position!=NULL);
fsetpos((FILE*)handle,(fpos_t *)position);
/* note: the item is not cleared from the pool */
}
int pc_eofsrc(void *handle)