@@ -104,7 +104,6 @@ static enum preproc_opt ppopt;
104
104
105
105
typedef struct SMacro SMacro ;
106
106
typedef struct MMacro MMacro ;
107
- typedef struct MMacroInvocation MMacroInvocation ;
108
107
typedef struct Context Context ;
109
108
typedef struct Token Token ;
110
109
typedef struct Line Line ;
@@ -226,9 +225,10 @@ struct SMacro {
226
225
intorptr expandpvt ;
227
226
struct smac_param * params ;
228
227
int nparam ;
228
+ int in_progress ;
229
+ bool recursive ;
229
230
bool varadic ; /* greedy or supports > nparam arguments */
230
231
bool casesense ;
231
- bool in_progress ;
232
232
bool alias ; /* This is an alias macro */
233
233
};
234
234
@@ -3059,10 +3059,10 @@ static SMacro *define_smacro(const char *mname, bool casesense,
3059
3059
/* It is an alias macro; follow the alias link */
3060
3060
SMacro * s ;
3061
3061
3062
- smac -> in_progress = true ;
3062
+ smac -> in_progress ++ ;
3063
3063
s = define_smacro (tok_text (smac -> expansion ), casesense ,
3064
3064
expansion , tmpl );
3065
- smac -> in_progress = false ;
3065
+ smac -> in_progress -- ;
3066
3066
return s ;
3067
3067
}
3068
3068
}
@@ -3147,6 +3147,7 @@ static SMacro *define_smacro(const char *mname, bool casesense,
3147
3147
if (tmpl ) {
3148
3148
smac -> params = tmpl -> params ;
3149
3149
smac -> alias = tmpl -> alias ;
3150
+ smac -> recursive = tmpl -> recursive ;
3150
3151
if (tmpl -> expand ) {
3151
3152
smac -> expand = tmpl -> expand ;
3152
3153
smac -> expandpvt = tmpl -> expandpvt ;
@@ -5605,11 +5606,11 @@ static SMacro *expand_one_smacro(Token ***tpp)
5605
5606
}
5606
5607
}
5607
5608
5608
- if (m -> in_progress )
5609
+ if (m -> in_progress && ! m -> recursive )
5609
5610
goto not_a_macro ;
5610
5611
5611
5612
/* Expand the macro */
5612
- m -> in_progress = true ;
5613
+ m -> in_progress ++ ;
5613
5614
5614
5615
if (nparam ) {
5615
5616
/* Extract parameters */
@@ -5874,7 +5875,8 @@ static SMacro *expand_one_smacro(Token ***tpp)
5874
5875
for (t = tline ; t && t != tafter ; t = t -> next )
5875
5876
* tpp = & t -> next ;
5876
5877
5877
- m -> in_progress = false;
5878
+ /* Expansion complete */
5879
+ m -> in_progress -- ;
5878
5880
5879
5881
/* Don't do this until after expansion or we will clobber mname */
5880
5882
free_tlist (mstart );
@@ -6997,11 +6999,16 @@ static void pp_add_magic_stdmac(void)
6997
6999
enum preproc_token pt ;
6998
7000
char name_buf [PP_TOKLEN_MAX + 1 ];
6999
7001
7000
- /* Simple standard magic macros */
7002
+ /*
7003
+ * Simple standard magic macros and functions.
7004
+ * Note that preprocessor functions are allowed to recurse.
7005
+ */
7001
7006
nasm_zero (tmpl );
7002
7007
for (m = magic_macros ; m -> name ; m ++ ) {
7003
7008
tmpl .nparam = m -> nparam ;
7004
7009
tmpl .expand = m -> func ;
7010
+ tmpl .recursive = m -> nparam && m -> name [0 ] == '%' ;
7011
+
7005
7012
if (m -> nparam ) {
7006
7013
int i ;
7007
7014
enum sparmflags flags = m -> flags ;
@@ -7024,6 +7031,7 @@ static void pp_add_magic_stdmac(void)
7024
7031
tmpl .nparam = 1 ;
7025
7032
tmpl .varadic = true;
7026
7033
tmpl .expand = stdmac_is ;
7034
+ tmpl .recursive = true;
7027
7035
name_buf [0 ] = '%' ;
7028
7036
name_buf [1 ] = 'i' ;
7029
7037
name_buf [2 ] = 's' ;
0 commit comments