*/
struct MMacro {
MMacro *next;
- MMacroInvocation *prev; /* previous invocation */
+ MMacroInvocation *prev; /* previous invocation */
char *name;
int nparam_min, nparam_max;
bool casesense;
bool plus; /* is the last parameter greedy? */
bool nolist; /* is this macro listing-inhibited? */
int64_t in_progress; /* is this macro currently being expanded? */
- int32_t max_depth; /* maximum number of recursive expansions allowed */
+ int32_t max_depth; /* maximum number of recursive expansions allowed */
Token *dlist; /* All defaults as one list */
Token **defaults; /* Parameter default pointers */
int ndefs; /* number of default parameters */
* previous recursive macro expansion.
*/
struct MMacroInvocation {
- MMacroInvocation *prev; /* previous invocation */
- Token **params; /* actual parameters */
- Token *iline; /* invocation line */
+ MMacroInvocation *prev; /* previous invocation */
+ Token **params; /* actual parameters */
+ Token *iline; /* invocation line */
unsigned int nparam, rotate;
int *paramlen;
uint64_t unique;
/* Handling unterminated string by UNV */
/*if (type == -1)
- {
- *tail = t = new_Token(NULL, TOK_STRING, line, p-line+1);
- t->text[p-line] = *line;
- tail = &t->next;
- }
- else */
+ {
+ *tail = t = new_Token(NULL, TOK_STRING, line, p-line+1);
+ t->text[p-line] = *line;
+ tail = &t->next;
+ }
+ else */
if (type != TOK_COMMENT) {
*tail = t = new_Token(NULL, type, line, p - line);
tail = &t->next;
Token *t;
int i;
- if (freeTokens == NULL) {
+ if (!freeTokens) {
freeTokens = (Token *) new_Block(TOKEN_BLOCKSIZE * sizeof(Token));
for (i = 0; i < TOKEN_BLOCKSIZE - 1; i++)
freeTokens[i].next = &freeTokens[i + 1];
t->next = next;
t->a.mac = NULL;
t->type = type;
- if (type == TOK_WHITESPACE || text == NULL) {
+ if (type == TOK_WHITESPACE || !text) {
t->text = NULL;
} else {
if (txtlen == 0)
break;
case PPC_IFMACRO:
- {
- bool found = false;
- MMacro searching, *mmac;
+ {
+ bool found = false;
+ MMacro searching, *mmac;
- skip_white_(tline);
- tline = expand_id(tline);
- if (!tok_type_(tline, TOK_ID)) {
- error(ERR_NONFATAL,
- "`%s' expects a macro name", pp_directives[ct]);
- goto fail;
- }
- searching.name = nasm_strdup(tline->text);
- searching.casesense = true;
- searching.plus = false;
- searching.nolist = false;
- searching.in_progress = 0;
- searching.max_depth = 0;
- searching.rep_nest = NULL;
- searching.nparam_min = 0;
- searching.nparam_max = INT_MAX;
- tline = expand_smacro(tline->next);
- skip_white_(tline);
- if (!tline) {
- } else if (!tok_type_(tline, TOK_NUMBER)) {
- error(ERR_NONFATAL,
- "`%s' expects a parameter count or nothing",
- pp_directives[ct]);
- } else {
- searching.nparam_min = searching.nparam_max =
- readnum(tline->text, &j);
- if (j)
- error(ERR_NONFATAL,
- "unable to parse parameter count `%s'",
- tline->text);
- }
- if (tline && tok_is_(tline->next, "-")) {
- tline = tline->next->next;
- if (tok_is_(tline, "*"))
- searching.nparam_max = INT_MAX;
- else if (!tok_type_(tline, TOK_NUMBER))
- error(ERR_NONFATAL,
- "`%s' expects a parameter count after `-'",
- pp_directives[ct]);
- else {
- searching.nparam_max = readnum(tline->text, &j);
- if (j)
- error(ERR_NONFATAL,
- "unable to parse parameter count `%s'",
- tline->text);
- if (searching.nparam_min > searching.nparam_max)
- error(ERR_NONFATAL,
- "minimum parameter count exceeds maximum");
- }
- }
- if (tline && tok_is_(tline->next, "+")) {
- tline = tline->next;
- searching.plus = true;
- }
- mmac = (MMacro *) hash_findix(&mmacros, searching.name);
- while (mmac) {
- if (!strcmp(mmac->name, searching.name) &&
- (mmac->nparam_min <= searching.nparam_max
- || searching.plus)
- && (searching.nparam_min <= mmac->nparam_max
- || mmac->plus)) {
- found = true;
- break;
- }
- mmac = mmac->next;
+ skip_white_(tline);
+ tline = expand_id(tline);
+ if (!tok_type_(tline, TOK_ID)) {
+ error(ERR_NONFATAL,
+ "`%s' expects a macro name", pp_directives[ct]);
+ goto fail;
+ }
+ searching.name = nasm_strdup(tline->text);
+ searching.casesense = true;
+ searching.plus = false;
+ searching.nolist = false;
+ searching.in_progress = 0;
+ searching.max_depth = 0;
+ searching.rep_nest = NULL;
+ searching.nparam_min = 0;
+ searching.nparam_max = INT_MAX;
+ tline = expand_smacro(tline->next);
+ skip_white_(tline);
+ if (!tline) {
+ } else if (!tok_type_(tline, TOK_NUMBER)) {
+ error(ERR_NONFATAL,
+ "`%s' expects a parameter count or nothing",
+ pp_directives[ct]);
+ } else {
+ searching.nparam_min = searching.nparam_max =
+ readnum(tline->text, &j);
+ if (j)
+ error(ERR_NONFATAL,
+ "unable to parse parameter count `%s'",
+ tline->text);
+ }
+ if (tline && tok_is_(tline->next, "-")) {
+ tline = tline->next->next;
+ if (tok_is_(tline, "*"))
+ searching.nparam_max = INT_MAX;
+ else if (!tok_type_(tline, TOK_NUMBER))
+ error(ERR_NONFATAL,
+ "`%s' expects a parameter count after `-'",
+ pp_directives[ct]);
+ else {
+ searching.nparam_max = readnum(tline->text, &j);
+ if (j)
+ error(ERR_NONFATAL,
+ "unable to parse parameter count `%s'",
+ tline->text);
+ if (searching.nparam_min > searching.nparam_max)
+ error(ERR_NONFATAL,
+ "minimum parameter count exceeds maximum");
}
- if(tline && tline->next)
- error(ERR_WARNING|ERR_PASS1,
- "trailing garbage after %%ifmacro ignored");
- nasm_free(searching.name);
- j = found;
- break;
- }
+ }
+ if (tline && tok_is_(tline->next, "+")) {
+ tline = tline->next;
+ searching.plus = true;
+ }
+ mmac = (MMacro *) hash_findix(&mmacros, searching.name);
+ while (mmac) {
+ if (!strcmp(mmac->name, searching.name) &&
+ (mmac->nparam_min <= searching.nparam_max
+ || searching.plus)
+ && (searching.nparam_min <= mmac->nparam_max
+ || mmac->plus)) {
+ found = true;
+ break;
+ }
+ mmac = mmac->next;
+ }
+ if (tline && tline->next)
+ error(ERR_WARNING|ERR_PASS1,
+ "trailing garbage after %%ifmacro ignored");
+ nasm_free(searching.name);
+ j = found;
+ break;
+ }
case PPC_IFID:
needtype = TOK_ID;
return false;
}
- def->prev = NULL;
+ def->prev = NULL;
def->name = nasm_strdup(tline->text);
def->plus = false;
def->nolist = false;
}
def->expansion = NULL;
- if(def->defaults &&
- def->ndefs > def->nparam_max - def->nparam_min &&
- !def->plus)
- error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP,
- "too many default macro parameters");
+ if (def->defaults && def->ndefs > def->nparam_max - def->nparam_min &&
+ !def->plus)
+ error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP,
+ "too many default macro parameters");
return true;
}
t = tline->next = expand_smacro(tline->next);
skip_white_(t);
if (!t || (t->type != TOK_STRING &&
- t->type != TOK_INTERNAL_STRING)) {
+ t->type != TOK_INTERNAL_STRING)) {
error(ERR_NONFATAL, "`%%depend' expects a file name");
free_tlist(origline);
return DIRECTIVE_FOUND; /* but we did _something_ */
skip_white_(t);
if (!t || (t->type != TOK_STRING &&
- t->type != TOK_INTERNAL_STRING)) {
+ t->type != TOK_INTERNAL_STRING)) {
error(ERR_NONFATAL, "`%%include' expects a file name");
free_tlist(origline);
return DIRECTIVE_FOUND; /* but we did _something_ */
/* Only error out if this is the final pass */
if (pass != 2 && i != PP_FATAL)
return DIRECTIVE_FOUND;
-
- tline->next = expand_smacro(tline->next);
- tline = tline->next;
- skip_white_(tline);
+
+ tline->next = expand_smacro(tline->next);
+ tline = tline->next;
+ skip_white_(tline);
t = tline ? tline->next : NULL;
skip_white_(t);
- if (tok_type_(tline, TOK_STRING) && !t) {
+ if (tok_type_(tline, TOK_STRING) && !t) {
/* The line contains only a quoted string */
p = tline->text;
nasm_unquote(p, NULL); /* Ignore NUL character truncation */
error(severity, "%s", p);
} else {
/* Not a quoted string, or more than a quoted string */
- p = detoken(tline, false);
+ p = detoken(tline, false);
error(severity, "%s", p);
nasm_free(p);
}
- free_tlist(origline);
+ free_tlist(origline);
return DIRECTIVE_FOUND;
}
if (!istk->conds)
error(ERR_FATAL, "`%s': no matching `%%if'", pp_directives[i]);
switch(istk->conds->state) {
- case COND_IF_TRUE:
- istk->conds->state = COND_DONE;
- break;
+ case COND_IF_TRUE:
+ istk->conds->state = COND_DONE;
+ break;
- case COND_DONE:
- case COND_NEVER:
- break;
+ case COND_DONE:
+ case COND_NEVER:
+ break;
- case COND_ELSE_TRUE:
- case COND_ELSE_FALSE:
- error_precond(ERR_WARNING|ERR_PASS1,
- "`%%elif' after `%%else' ignored");
- istk->conds->state = COND_NEVER;
- break;
+ case COND_ELSE_TRUE:
+ case COND_ELSE_FALSE:
+ error_precond(ERR_WARNING|ERR_PASS1,
+ "`%%elif' after `%%else' ignored");
+ istk->conds->state = COND_NEVER;
+ break;
- case COND_IF_FALSE:
- /*
- * IMPORTANT: In the case of %if, we will already have
- * called expand_mmac_params(); however, if we're
- * processing an %elif we must have been in a
- * non-emitting mode, which would have inhibited
- * the normal invocation of expand_mmac_params().
- * Therefore, we have to do it explicitly here.
- */
- j = if_condition(expand_mmac_params(tline->next), i);
- tline->next = NULL; /* it got freed */
- istk->conds->state =
- j < 0 ? COND_NEVER : j ? COND_IF_TRUE : COND_IF_FALSE;
- break;
+ case COND_IF_FALSE:
+ /*
+ * IMPORTANT: In the case of %if, we will already have
+ * called expand_mmac_params(); however, if we're
+ * processing an %elif we must have been in a
+ * non-emitting mode, which would have inhibited
+ * the normal invocation of expand_mmac_params().
+ * Therefore, we have to do it explicitly here.
+ */
+ j = if_condition(expand_mmac_params(tline->next), i);
+ tline->next = NULL; /* it got freed */
+ istk->conds->state =
+ j < 0 ? COND_NEVER : j ? COND_IF_TRUE : COND_IF_FALSE;
+ break;
}
free_tlist(origline);
return DIRECTIVE_FOUND;
if (!istk->conds)
error(ERR_FATAL, "`%%else': no matching `%%if'");
switch(istk->conds->state) {
- case COND_IF_TRUE:
- case COND_DONE:
- istk->conds->state = COND_ELSE_FALSE;
- break;
+ case COND_IF_TRUE:
+ case COND_DONE:
+ istk->conds->state = COND_ELSE_FALSE;
+ break;
- case COND_NEVER:
- break;
+ case COND_NEVER:
+ break;
- case COND_IF_FALSE:
- istk->conds->state = COND_ELSE_TRUE;
- break;
+ case COND_IF_FALSE:
+ istk->conds->state = COND_ELSE_TRUE;
+ break;
- case COND_ELSE_TRUE:
- case COND_ELSE_FALSE:
- error_precond(ERR_WARNING|ERR_PASS1,
- "`%%else' after `%%else' ignored.");
- istk->conds->state = COND_NEVER;
- break;
+ case COND_ELSE_TRUE:
+ case COND_ELSE_FALSE:
+ error_precond(ERR_WARNING|ERR_PASS1,
+ "`%%else' after `%%else' ignored.");
+ istk->conds->state = COND_NEVER;
+ break;
}
free_tlist(origline);
return DIRECTIVE_FOUND;
free_tlist(origline);
return DIRECTIVE_FOUND;
- case PP_EXITMACRO:
+ case PP_EXITMACRO:
/*
* We must search along istk->expansion until we hit a
* macro-end marker for a macro with a name. Then we set
* its `in_progress' flag to 0.
*/
- for (l = istk->expansion; l; l = l->next)
+ for (l = istk->expansion; l; l = l->next)
if (l->finishes && l->finishes->name)
break;
if (l) {
- l->finishes->in_progress = 0;
+ l->finishes->in_progress = 0;
} else {
error(ERR_NONFATAL, "`%%exitmacro' not within `%%macro' block");
- }
+ }
free_tlist(origline);
return DIRECTIVE_FOUND;
case PP_ROTATE:
if (tline->next && tline->next->type == TOK_WHITESPACE)
tline = tline->next;
- if (tline->next == NULL) {
+ if (!tline->next) {
free_tlist(origline);
error(ERR_NONFATAL, "`%%rotate' missing rotate count");
return DIRECTIVE_FOUND;
tmp_defining = defining;
defining = nasm_malloc(sizeof(MMacro));
- defining->prev = NULL;
+ defining->prev = NULL;
defining->name = NULL; /* flags this macro as a %rep block */
defining->casesense = false;
defining->plus = false;
defining->nolist = nolist;
defining->in_progress = count;
- defining->max_depth = 0;
+ defining->max_depth = 0;
defining->nparam_min = defining->nparam_max = 0;
defining->defaults = NULL;
defining->dlist = NULL;
case PP_DEFTOK:
case PP_IDEFTOK:
casesense = (i == PP_DEFTOK);
-
+
tline = tline->next;
skip_white_(tline);
tline = expand_id(tline);
tline->text[1] != '$'))) {
error(ERR_NONFATAL,
"`%s' expects a macro identifier as first parameter",
- pp_directives[i]);
+ pp_directives[i]);
free_tlist(origline);
return DIRECTIVE_FOUND;
}
if (t->type != TOK_STRING) {
error(ERR_NONFATAL,
"`%s` requires string as second parameter",
- pp_directives[i]);
+ pp_directives[i]);
free_tlist(tline);
free_tlist(origline);
return DIRECTIVE_FOUND;
nasm_unquote_cstr(t->text, i);
macro_start = tokenize(t->text);
-
+
/*
* We now have a macro name, an implicit parameter count of
* zero, and a numeric token to use as an expansion. Create
int i, j, k, m;
if (!t)
- return -1; /* Probably a %+ without a space */
+ return -1; /* Probably a %+ without a space */
skip_white_(t);
if (t->type != TOK_ID)
* pain.
*/
/*tline = tline->next;
- skip_white_(tline); */
+ skip_white_(tline); */
do {
t = tline->next;
while (tok_type_(t, TOK_SMAC_END)) {
* This one is right. Just check if cycle removal
* prohibits us using it before we actually celebrate...
*/
- if (m->in_progress > m->max_depth) {
- if (m->max_depth > 0) {
- error(ERR_WARNING,
- "reached maximum recursion depth of %i",
- m->max_depth);
- }
- nasm_free(params);
- return NULL;
- }
+ if (m->in_progress > m->max_depth) {
+ if (m->max_depth > 0) {
+ error(ERR_WARNING,
+ "reached maximum recursion depth of %i",
+ m->max_depth);
+ }
+ nasm_free(params);
+ return NULL;
+ }
/*
* It's right, and we can use it. Add its default
* parameters to the end of our list if necessary.
{
MMacroInvocation *i;
- i = nasm_malloc(sizeof(MMacroInvocation));
- i->prev = m->prev;
- i->params = m->params;
- i->iline = m->iline;
- i->nparam = m->nparam;
- i->rotate = m->rotate;
- i->paramlen = m->paramlen;
- i->unique = m->unique;
- m->prev = i;
+ i = nasm_malloc(sizeof(MMacroInvocation));
+ i->prev = m->prev;
+ i->params = m->params;
+ i->iline = m->iline;
+ i->nparam = m->nparam;
+ i->rotate = m->rotate;
+ i->paramlen = m->paramlen;
+ i->unique = m->unique;
+ m->prev = i;
}
{
MMacroInvocation *i;
- if(m->prev != NULL){
- i = m->prev;
- m->prev = i->prev;
- m->params = i->params;
- m->iline = i->iline;
- m->nparam = i->nparam;
- m->rotate = i->rotate;
- m->paramlen = i->paramlen;
- m->unique = i->unique;
- nasm_free(i);
- }
+ if (m->prev) {
+ i = m->prev;
+ m->prev = i->prev;
+ m->params = i->params;
+ m->iline = i->iline;
+ m->nparam = i->nparam;
+ m->rotate = i->rotate;
+ m->paramlen = i->paramlen;
+ m->unique = i->unique;
+ nasm_free(i);
+ }
}
if (tok_type_(t, TOK_WHITESPACE))
last = t, t = t->next;
}
- if (!tok_type_(t, TOK_ID) || (m = is_mmacro(t, ¶ms)) == NULL)
+ if (!tok_type_(t, TOK_ID) || !(m = is_mmacro(t, ¶ms)))
return 0;
last->next = NULL;
mname = t->text;
ll->first = NULL;
istk->expansion = ll;
- /*
- * Save the previous MMacro expansion in the case of
- * macro recursion
- */
- if (m->max_depth && m->in_progress)
- push_mmacro(m);
+ /*
+ * Save the previous MMacro expansion in the case of
+ * macro recursion
+ */
+ if (m->max_depth && m->in_progress)
+ push_mmacro(m);
m->in_progress ++;
m->params = params;
* therefore the parameter information needs to
* be freed.
*/
- if (m->prev != NULL) {
- pop_mmacro(m);
- l->finishes->in_progress --;
- } else {
+ if (m->prev) {
+ pop_mmacro(m);
+ l->finishes->in_progress --;
+ } else {
nasm_free(m->params);
free_tlist(m->iline);
- nasm_free(m->paramlen);
- l->finishes->in_progress = 0;
- }
+ nasm_free(m->paramlen);
+ l->finishes->in_progress = 0;
+ }
} else
free_mmacro(m);
}
static void pp_cleanup(int pass)
{
if (defining) {
- if(defining->name) {
+ if (defining->name) {
error(ERR_NONFATAL,
"end of file while still defining macro `%s'",
defining->name);
i->path = path ? nasm_strdup(path) : NULL;
i->next = NULL;
- if (ipath != NULL) {
+ if (ipath) {
IncPath *j = ipath;
- while (j->next != NULL)
+ while (j->next)
j = j->next;
j->next = i;
} else {
Token *def;
def = tokenize(definition);
- if(do_directive(def) == NO_DIRECTIVE_FOUND)
+ if (do_directive(def) == NO_DIRECTIVE_FOUND)
free_tlist(def);
}