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 guchar *
00054 cr_pseudo_to_string (CRPseudo * a_this)
00055 {
00056 guchar *result = NULL;
00057 GString *str_buf = NULL;
00058
00059 g_return_val_if_fail (a_this, NULL);
00060
00061 str_buf = g_string_new (NULL);
00062
00063 if (a_this->type == IDENT_PSEUDO) {
00064 guchar *name = NULL;
00065
00066 if (a_this->name == NULL) {
00067 goto error;
00068 }
00069
00070 name = g_strndup (a_this->name->stryng->str,
00071 a_this->name->stryng->len);
00072
00073 if (name) {
00074 g_string_append (str_buf, name);
00075 g_free (name);
00076 name = NULL;
00077 }
00078 } else if (a_this->type == FUNCTION_PSEUDO) {
00079 guchar *name = NULL,
00080 *arg = NULL;
00081
00082 if (a_this->name == NULL)
00083 goto error;
00084
00085 name = g_strndup (a_this->name->stryng->str,
00086 a_this->name->stryng->len);
00087
00088 if (a_this->extra) {
00089 arg = g_strndup (a_this->extra->stryng->str,
00090 a_this->extra->stryng->len);
00091 }
00092
00093 if (name) {
00094 g_string_append_printf (str_buf, "%s(", name);
00095 g_free (name);
00096 name = NULL;
00097
00098 if (arg) {
00099 g_string_append (str_buf, arg);
00100 g_free (arg);
00101 arg = NULL;
00102 }
00103
00104 g_string_append_c (str_buf, ')');
00105 }
00106 }
00107
00108 if (str_buf) {
00109 result = str_buf->str;
00110 g_string_free (str_buf, FALSE);
00111 str_buf = NULL;
00112 }
00113
00114 return result;
00115
00116 error:
00117 g_string_free (str_buf, TRUE);
00118 return NULL;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 void
00130 cr_pseudo_dump (CRPseudo * a_this, FILE * a_fp)
00131 {
00132 guchar *tmp_str = NULL;
00133
00134 if (a_this) {
00135 tmp_str = cr_pseudo_to_string (a_this);
00136 if (tmp_str) {
00137 fprintf (a_fp, "%s", tmp_str);
00138 g_free (tmp_str);
00139 tmp_str = NULL;
00140 }
00141 }
00142 }
00143
00144
00145
00146
00147
00148
00149
00150 void
00151 cr_pseudo_destroy (CRPseudo * a_this)
00152 {
00153 g_return_if_fail (a_this);
00154
00155 if (a_this->name) {
00156 cr_string_destroy (a_this->name);
00157 a_this->name = NULL;
00158 }
00159
00160 if (a_this->extra) {
00161 cr_string_destroy (a_this->extra);
00162 a_this->extra = NULL;
00163 }
00164
00165 g_free (a_this);
00166 }