Create a function to ease param list building.

This is especially useful for QuakePascal, but it will mean I'll be able to
get rid of the parameter reversals in Ruamoko later on.
This commit is contained in:
Bill Currie 2011-01-13 14:45:53 +09:00
parent 258c896e4d
commit ac14db7b1b
2 changed files with 28 additions and 2 deletions

View file

@ -69,14 +69,18 @@ typedef struct param_s {
// method.h
struct param_s *next;
const char *selector;
struct type_s *type;
const char *name;
struct type_s *type; //FIXME redundant
const char *name; //FIXME redundant
struct symbol_s *symbol;
} param_t;
struct expr_s;
struct symbol_s;
param_t *new_param (const char *selector, struct type_s *type,
const char *name);
param_t *param_append_identifiers (param_t *params, struct symbol_s *idents,
struct type_s *type);
param_t *_reverse_params (param_t *params, param_t *next);
param_t *reverse_params (param_t *params);
param_t *copy_params (param_t *params);

View file

@ -58,6 +58,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "opcodes.h"
#include "options.h"
#include "reloc.h"
#include "symtab.h"
#include "type.h"
static param_t *free_params;
@ -93,6 +94,27 @@ new_param (const char *selector, type_t *type, const char *name)
return param;
}
param_t *
param_append_identifiers (param_t *params, symbol_t *idents, type_t *type)
{
param_t **p = &params;
while (*p)
p = &(*p)->next;
if (!idents) {
*p = new_param (0, 0, 0);
p = &(*p)->next;
}
while (idents) {
idents->type = type;
*p = new_param (0, type, idents->name);
(*p)->symbol = idents;
p = &(*p)->next;
idents = idents->next;
}
return params;
}
param_t *
_reverse_params (param_t *params, param_t *next)
{