#include "sl_pp_process.h"
-static void
-skip_whitespace(const struct sl_pp_token_info *input,
- unsigned int *pi)
+struct sl_pp_macro *
+sl_pp_macro_new(void)
{
- while (input[*pi].token == SL_PP_WHITESPACE) {
- (*pi)++;
+ struct sl_pp_macro *macro;
+
+ macro = calloc(1, sizeof(struct sl_pp_macro));
+ if (macro) {
+ macro->name = -1;
+ macro->num_args = -1;
}
+ return macro;
}
void
}
}
+static void
+skip_whitespace(const struct sl_pp_token_info *input,
+ unsigned int *pi)
+{
+ while (input[*pi].token == SL_PP_WHITESPACE) {
+ (*pi)++;
+ }
+}
+
int
sl_pp_macro_expand(struct sl_pp_context *context,
const struct sl_pp_token_info *input,
unsigned int paren_nesting = 0;
unsigned int k;
- *pmacro = malloc(sizeof(struct sl_pp_macro));
+ *pmacro = sl_pp_macro_new();
if (!*pmacro) {
return -1;
}
(**pmacro).name = formal_arg->name;
- (**pmacro).num_args = -1;
- (**pmacro).arg = NULL;
- (**pmacro).body = NULL;
- (**pmacro).next = NULL;
body_len = 1;
for (i = *pi; !done; i++) {
struct sl_pp_macro {
int name;
- int num_args;
+ int num_args; /* -1 means no args, 0 means `()' */
struct sl_pp_macro_formal_arg *arg;
struct sl_pp_token_info *body;
struct sl_pp_macro *next;
};
+struct sl_pp_macro *
+sl_pp_macro_new(void);
+
void
sl_pp_macro_free(struct sl_pp_macro *macro);