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