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