1 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
4 * This file is part of The Croco Library
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2.1 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * Author: Dodji Seketeli
21 * See COPYRIGHTS file for copyright information.
24 #include "cr-pseudo.h"
28 *The definition of the #CRPseudo class.
33 *Constructor of the #CRPseudo class.
35 *Returns the newly build instance.
40 CRPseudo *result = NULL;
42 result = g_malloc0 (sizeof (CRPseudo));
48 * cr_pseudo_to_string:
49 * @a_this: the current instance of #CRPseud.
51 * Returns the serialized pseudo. Caller must free the returned
52 * string using g_free().
55 cr_pseudo_to_string (CRPseudo const * a_this)
57 guchar *result = NULL;
58 GString *str_buf = NULL;
60 g_return_val_if_fail (a_this, NULL);
62 str_buf = g_string_new (NULL);
64 if (a_this->type == IDENT_PSEUDO) {
67 if (a_this->name == NULL) {
71 name = g_strndup (a_this->name->stryng->str,
72 a_this->name->stryng->len);
75 g_string_append (str_buf, name);
79 } else if (a_this->type == FUNCTION_PSEUDO) {
83 if (a_this->name == NULL)
86 name = g_strndup (a_this->name->stryng->str,
87 a_this->name->stryng->len);
90 arg = g_strndup (a_this->extra->stryng->str,
91 a_this->extra->stryng->len);
95 g_string_append_printf (str_buf, "%s(", name);
100 g_string_append (str_buf, arg);
105 g_string_append_c (str_buf, ')');
110 result = str_buf->str;
111 g_string_free (str_buf, FALSE);
118 g_string_free (str_buf, TRUE);
124 *@a_this: the current instance of pseudo
125 *@a_fp: the destination file pointer.
127 *Dumps the pseudo to a file.
131 cr_pseudo_dump (CRPseudo const * a_this, FILE * a_fp)
133 guchar *tmp_str = NULL;
136 tmp_str = cr_pseudo_to_string (a_this);
138 fprintf (a_fp, "%s", tmp_str);
147 *@a_this: the current instance to destroy.
149 *destructor of the #CRPseudo class.
152 cr_pseudo_destroy (CRPseudo * a_this)
154 g_return_if_fail (a_this);
157 cr_string_destroy (a_this->name);
162 cr_string_destroy (a_this->extra);
163 a_this->extra = NULL;