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