Skip to content
Snippets Groups Projects
Commit 39dc6c27 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

varargs macros now implemented (same syntax as GCC varargs macros)

Rev: src/cpp.c:1.65
Rev: src/preprocessor.h:1.24
parent cc82fbb2
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
\*/ \*/
/* /*
* $Id: cpp.c,v 1.64 2000/06/06 22:51:55 hubbe Exp $ * $Id: cpp.c,v 1.65 2000/06/13 21:39:34 hubbe Exp $
*/ */
#include "global.h" #include "global.h"
#include "stralloc.h" #include "stralloc.h"
...@@ -84,7 +84,8 @@ struct define ...@@ -84,7 +84,8 @@ struct define
magic_define_fun magic; magic_define_fun magic;
int args; int args;
int num_parts; int num_parts;
int inside; short inside;
short varargs;
struct pike_string *first; struct pike_string *first;
struct define_part parts[1]; struct define_part parts[1];
}; };
...@@ -138,6 +139,7 @@ static struct define *alloc_empty_define(struct pike_string *name, INT32 parts) ...@@ -138,6 +139,7 @@ static struct define *alloc_empty_define(struct pike_string *name, INT32 parts)
def->magic=0; def->magic=0;
def->args=-1; def->args=-1;
def->inside=0; def->inside=0;
def->varargs=0;
def->num_parts=parts; def->num_parts=parts;
def->first=0; def->first=0;
def->link.s=name; def->link.s=name;
......
/* /*
* $Id: preprocessor.h,v 1.23 2000/04/01 07:26:29 hubbe Exp $ * $Id: preprocessor.h,v 1.24 2000/06/13 21:39:34 hubbe Exp $
* *
* Preprocessor template. * Preprocessor template.
* Based on cpp.c 1.45 * Based on cpp.c 1.45
...@@ -891,6 +891,12 @@ static INT32 lower_cpp(struct cpp *this, ...@@ -891,6 +891,12 @@ static INT32 lower_cpp(struct cpp *this,
if(data[pos]==')') if(data[pos]==')')
{ {
char buffer[1024]; char buffer[1024];
if(d->varargs && arg + 1 == d->args)
{
arguments[arg].arg = MKPCHARP(data + pos, SHIFT);
arguments[arg].len=0;
continue;
}
sprintf(buffer, sprintf(buffer,
"Too few arguments to macro %.950s, expected %d.", "Too few arguments to macro %.950s, expected %d.",
d->link.s->str, d->args); d->link.s->str, d->args);
...@@ -928,8 +934,11 @@ static INT32 lower_cpp(struct cpp *this, ...@@ -928,8 +934,11 @@ static INT32 lower_cpp(struct cpp *this,
pos=find_end_parenthesis(this, data, len, pos); pos=find_end_parenthesis(this, data, len, pos);
continue; continue;
case ',':
if(d->varargs && arg+1 == d->args) continue;
case ')': case ')':
case ',': pos--; pos--;
break; break;
} }
break; break;
...@@ -1584,6 +1593,7 @@ static INT32 lower_cpp(struct cpp *this, ...@@ -1584,6 +1593,7 @@ static INT32 lower_cpp(struct cpp *this,
INT32 namestart, tmp3, nameend, argno=-1; INT32 namestart, tmp3, nameend, argno=-1;
struct define *def; struct define *def;
struct svalue *partbase,*argbase=Pike_sp; struct svalue *partbase,*argbase=Pike_sp;
int varargs=0;
SKIPSPACE(); SKIPSPACE();
...@@ -1615,6 +1625,8 @@ static INT32 lower_cpp(struct cpp *this, ...@@ -1615,6 +1625,8 @@ static INT32 lower_cpp(struct cpp *this,
"Expecting comma in macro definition."); "Expecting comma in macro definition.");
SKIPWHITE(); SKIPWHITE();
} }
if(varargs)
cpp_error(this,"Expected ) after ...");
tmp2=pos; tmp2=pos;
if(!WC_ISIDCHAR(data[pos])) if(!WC_ISIDCHAR(data[pos]))
...@@ -1645,6 +1657,13 @@ static INT32 lower_cpp(struct cpp *this, ...@@ -1645,6 +1657,13 @@ static INT32 lower_cpp(struct cpp *this,
pop_stack(); pop_stack();
argno--; argno--;
} }
if(data[pos]=='.' && data[pos+1]=='.' && data[pos+2]=='.')
{
varargs=1;
pos+=3;
SKIPWHITE();
}
} }
if(!GOBBLE(')')) if(!GOBBLE(')'))
...@@ -1798,6 +1817,7 @@ static INT32 lower_cpp(struct cpp *this, ...@@ -1798,6 +1817,7 @@ static INT32 lower_cpp(struct cpp *this,
#endif /* SHIFT == 0 */ #endif /* SHIFT == 0 */
copy_shared_string(def->first, partbase->u.string); copy_shared_string(def->first, partbase->u.string);
def->args=argno; def->args=argno;
def->varargs=varargs;
for(e=0;e<def->num_parts;e++) for(e=0;e<def->num_parts;e++)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment