Implemented __VA_COUNT__
authorDale Weiler <killfieldengine@gmail.com>
Fri, 8 Feb 2013 12:30:17 +0000 (12:30 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 8 Feb 2013 12:30:17 +0000 (12:30 +0000)
ftepp.c
lexer.h

diff --git a/ftepp.c b/ftepp.c
index 4734639244ab1f426706dcb8dcc61b0b93ed81f5..a0f110533077bcd4326f1b90a0f934008dfd4350 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -451,8 +451,12 @@ static bool ftepp_define_body(ftepp_t *ftepp, ppmacro *macro)
                 ftepp->token = old;
             }
         }
-        else
-        {
+        else if (macro->variadic && !strcmp(ftepp_tokval(ftepp), "__VA_COUNT__")) {
+            ftepp->token = TOKEN_VA_COUNT;
+            ptok         = pptoken_make(ftepp);
+            vec_push(macro->output, ptok);
+            ftepp_next(ftepp);
+        } else {
             ptok = pptoken_make(ftepp);
             vec_push(macro->output, ptok);
             ftepp_next(ftepp);
@@ -681,6 +685,7 @@ static void ftepp_param_out(ftepp_t *ftepp, macroparam *param)
 static bool ftepp_preprocess(ftepp_t *ftepp);
 static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *params, bool resetline)
 {
+    char     *buffer       = NULL;
     char     *old_string   = ftepp->output_string;
     char     *inner_string;
     lex_file *old_lexer    = ftepp->lex;
@@ -736,6 +741,12 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
                 ftepp_param_out(ftepp, &params[out->constval.i + vararg_start]);
                 break;
 
+            case TOKEN_VA_COUNT:
+                util_asprintf(&buffer, "%d", varargs);
+                ftepp_out(ftepp, buffer, false);
+                mem_d(buffer);
+                break;
+
             case TOKEN_IDENT:
             case TOKEN_TYPENAME:
             case TOKEN_KEYWORD:
diff --git a/lexer.h b/lexer.h
index 15730ee2ebacb035957e09815db7463099d60644..9724a7b90d97c386e1de013a97e08d654e05d280 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -76,6 +76,7 @@ enum {
 
     TOKEN_VA_ARGS, /* for the ftepp only */
     TOKEN_VA_ARGS_ARRAY, /* for the ftepp only */
+    TOKEN_VA_COUNT,     /* to get the count of vaargs */
 
     TOKEN_STRINGCONST, /* not the typename but an actual "string" */
     TOKEN_CHARCONST,