X-Git-Url: http://git.annexia.org/?p=portablexdr.git;a=blobdiff_plain;f=rpcgen_ast.c;fp=rpcgen_ast.c;h=e1caa99402aee26b37831a48cc7b8f266a6b025c;hp=0000000000000000000000000000000000000000;hb=1b9cc11ece64ac12f63e6c96e32b404b32fb0f32;hpb=e9558f1dd242f2eb6a528c5509f1f8911fffe5d7 diff --git a/rpcgen_ast.c b/rpcgen_ast.c new file mode 100644 index 0000000..e1caa99 --- /dev/null +++ b/rpcgen_ast.c @@ -0,0 +1,147 @@ +/* -*- C -*- + * rpcgen - Generate XDR bindings automatically. + * Copyright (C) 2008 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include + +#include "rpcgen_int.h" + +struct type * +new_type (enum type_enum type, int sgn, char *ident, char *len) +{ + struct type *r = malloc (sizeof *r); + r->type = type; + r->sgn = sgn; + r->ident = ident; + r->len = len; + return r; +} + +void +free_type (struct type *t) +{ + if (t) { + free (t->ident); + free (t->len); + free (t); + } +} + +struct decl * +new_decl (enum decl_type decl_type, struct type *type, + char *ident, char *len) +{ + struct decl *r = malloc (sizeof *r); + r->decl_type = decl_type; + r->type = type; + r->ident = ident; + r->len = len; + return r; +} + +void +free_decl (struct decl *d) +{ + if (d) { + free_type (d->type); + free (d->ident); + free (d->len); + free (d); + } +} + +struct enum_value * +new_enum_value (char *ident, char *value) +{ + struct enum_value *r = malloc (sizeof *r); + r->ident = ident; + r->value = value; + return r; +} + +void +free_enum_value (struct enum_value *v) +{ + if (v) { + free (v->ident); + free (v->value); + free (v); + } +} + +struct union_case * +new_union_case (enum union_case_type type, char *const_, struct decl *decl) +{ + struct union_case *r = malloc (sizeof *r); + r->type = type; + r->const_ = const_; + r->decl = decl; + return r; +} + +void +free_union_case (struct union_case *c) +{ + if (c) { + free (c->const_); + free_decl (c->decl); + free (c); + } +} + +struct cons * +new_cons (struct cons *next, void *ptr, free_fn free) +{ + struct cons *r = malloc (sizeof *r); + r->next = next; + r->ptr = ptr; + r->free = free; + return r; +} + +static struct cons * +list_rev_append (struct cons *xs1, struct cons *xs2) +{ + if (!xs1) return xs2; + else { + struct cons *tail = xs1->next; + xs1->next = xs2; + return list_rev_append (tail, xs1); + } +} + +struct cons * +list_rev (struct cons *xs) +{ + return list_rev_append (xs, NULL); +} + +void +list_free (struct cons *xs) +{ + if (xs) { + struct cons *next = xs->next; + if (xs->free) xs->free (xs->ptr); + free (xs); + list_free (next); + } +}