00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "cr-pseudo.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 CRPseudo *
00039 cr_pseudo_new (void)
00040 {
00041 CRPseudo *result = NULL;
00042
00043 result = g_malloc0 (sizeof (CRPseudo));
00044
00045 return result;
00046 }
00047
00048 guchar *
00049 cr_pseudo_to_string (CRPseudo * a_this)
00050 {
00051 guchar *result = NULL;
00052 GString *str_buf = NULL;
00053
00054 g_return_val_if_fail (a_this, NULL);
00055
00056 str_buf = g_string_new (NULL);
00057
00058 if (a_this->type == IDENT_PSEUDO) {
00059 guchar *name = NULL;
00060
00061 if (a_this->name == NULL) {
00062 goto error;
00063 }
00064
00065 name = g_strndup (a_this->name->str, a_this->name->len);
00066
00067 if (name) {
00068 g_string_append_printf (str_buf, "%s", name);
00069 g_free (name);
00070 name = NULL;
00071 }
00072 } else if (a_this->type == FUNCTION_PSEUDO) {
00073 guchar *name = NULL,
00074 *arg = NULL;
00075
00076 if (a_this->name == NULL)
00077 goto error;
00078
00079 name = g_strndup (a_this->name->str, a_this->name->len);
00080
00081 if (a_this->extra) {
00082 arg = g_strndup (a_this->extra->str,
00083 a_this->extra->len);
00084 }
00085
00086 if (name) {
00087 g_string_append_printf (str_buf, "%s(", name);
00088 g_free (name);
00089 name = NULL;
00090
00091 if (arg) {
00092 g_string_append_printf (str_buf, "%s", arg);
00093 g_free (arg);
00094 arg = NULL;
00095 }
00096
00097 g_string_append_printf (str_buf, ")");
00098 }
00099 }
00100
00101 if (str_buf) {
00102 result = str_buf->str;
00103 g_string_free (str_buf, FALSE);
00104 str_buf = NULL;
00105 }
00106
00107 return result;
00108
00109 error:
00110 g_string_free (str_buf, TRUE);
00111 return NULL;
00112 }
00113
00114
00115
00116
00117
00118
00119 void
00120 cr_pseudo_dump (CRPseudo * a_this, FILE * a_fp)
00121 {
00122 guchar *tmp_str = NULL;
00123
00124 if (a_this) {
00125 tmp_str = cr_pseudo_to_string (a_this);
00126 if (tmp_str) {
00127 fprintf (a_fp, "%s", tmp_str);
00128 g_free (tmp_str);
00129 tmp_str = NULL;
00130 }
00131 }
00132 }
00133
00134
00135
00136
00137
00138 void
00139 cr_pseudo_destroy (CRPseudo * a_this)
00140 {
00141 g_return_if_fail (a_this);
00142
00143 if (a_this->name) {
00144 g_string_free (a_this->name, TRUE);
00145 a_this->name = NULL;
00146 }
00147
00148 if (a_this->extra) {
00149 g_string_free (a_this->extra, TRUE);
00150 a_this->extra = NULL;
00151 }
00152
00153 g_free (a_this);
00154 }