1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 Copyright (C) 2009 Maxim Ermilov <zaspire@rambler.ru>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "ijs-symbol.h"
21 #include "import-symbol.h"
23 #include "gi-symbol.h"
24 #include "dir-symbol.h"
26 static void import_symbol_interface_init (IJsSymbolIface
*iface
);
27 static GList
* import_symbol_get_arg_list (IJsSymbol
*obj
);
28 static gint
import_symbol_get_base_type (IJsSymbol
*obj
);
29 static GList
* import_symbol_get_func_ret_type (IJsSymbol
*obj
);
30 static IJsSymbol
* import_symbol_get_member (IJsSymbol
*obj
, const gchar
* name
);
31 static const gchar
* import_symbol_get_name (IJsSymbol
*obj
);
32 static GList
* import_symbol_list_member (IJsSymbol
*obj
);
34 typedef struct _ImportSymbolPrivate ImportSymbolPrivate
;
35 struct _ImportSymbolPrivate
41 #define IMPORT_SYMBOL_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IMPORT_TYPE_SYMBOL, ImportSymbolPrivate))
43 G_DEFINE_TYPE_WITH_CODE (ImportSymbol
, import_symbol
, G_TYPE_OBJECT
,
44 G_IMPLEMENT_INTERFACE (IJS_TYPE_SYMBOL
,
45 import_symbol_interface_init
));
48 import_symbol_init (ImportSymbol
*object
)
50 ImportSymbolPrivate
*priv
= IMPORT_SYMBOL_PRIVATE(object
);
56 import_symbol_finalize (GObject
*object
)
58 ImportSymbolPrivate
*priv
= IMPORT_SYMBOL_PRIVATE(object
);
60 g_list_foreach (priv
->member
, (GFunc
)g_object_unref
, NULL
);
61 g_list_foreach (priv
->dirs
, (GFunc
)g_object_unref
, NULL
);
62 g_list_free (priv
->member
);
63 g_list_free (priv
->dirs
);
64 G_OBJECT_CLASS (import_symbol_parent_class
)->finalize (object
);
68 import_symbol_class_init (ImportSymbolClass
*klass
)
70 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
71 /*GObjectClass* parent_class = G_OBJECT_CLASS (klass);*/
73 g_type_class_add_private (klass
, sizeof (ImportSymbolPrivate
));
75 object_class
->finalize
= import_symbol_finalize
;
82 ImportSymbol
* ret
= IMPORT_SYMBOL (g_object_new (IMPORT_TYPE_SYMBOL
, NULL
));
83 ImportSymbolPrivate
*priv
= IMPORT_SYMBOL_PRIVATE(ret
);
85 priv
->member
= g_list_append (NULL
, gi_symbol_new ());
92 import_symbol_interface_init (IJsSymbolIface
*iface
)
94 iface
->get_arg_list
= import_symbol_get_arg_list
;
95 iface
->get_base_type
= import_symbol_get_base_type
;
96 iface
->get_func_ret_type
= import_symbol_get_func_ret_type
;
98 iface
->get_member
= import_symbol_get_member
;
99 iface
->get_name
= import_symbol_get_name
;
100 iface
->list_member
= import_symbol_list_member
;
104 post_init (ImportSymbol
*symbol
)
106 ImportSymbolPrivate
*priv
= IMPORT_SYMBOL_PRIVATE (symbol
);
107 GList
*paths
= get_import_include_paths ();
110 for (i
= priv
->dirs
; i
; )
113 gchar
*path
= dir_symbol_get_path (DIR_SYMBOL (i
->data
));
114 gboolean has_path
= FALSE
;
115 g_assert (path
!= NULL
);
116 for (k
= paths
; k
; k
= g_list_next (k
))
118 if (g_strcmp0 (path
, (gchar
*)k
->data
) != 0)
121 paths
= g_list_delete_link (paths
, k
);
127 g_object_unref (i
->data
);
128 priv
->dirs
= g_list_remove_link (priv
->dirs
, i
);
135 for (i
= paths
; i
; i
= g_list_next (i
))
137 gchar
*path
= (gchar
*)i
->data
;
138 g_assert (path
!= NULL
);
139 DirSymbol
*sym
= dir_symbol_new (path
);
141 priv
->dirs
= g_list_append (priv
->dirs
, sym
);
143 g_list_foreach (paths
, (GFunc
)g_free
, NULL
);
148 import_symbol_get_arg_list (IJsSymbol
*obj
)
150 g_assert_not_reached ();
155 import_symbol_get_base_type (IJsSymbol
*obj
)
161 import_symbol_get_func_ret_type (IJsSymbol
*obj
)
163 g_assert_not_reached ();
168 import_symbol_get_member (IJsSymbol
*obj
, const gchar
* name
)
170 ImportSymbol
* self
= IMPORT_SYMBOL (obj
);
171 ImportSymbolPrivate
*priv
= IMPORT_SYMBOL_PRIVATE(self
);
177 for (i
= priv
->member
; i
; i
= g_list_next (i
))
179 IJsSymbol
*t
= IJS_SYMBOL (i
->data
);
180 if (g_strcmp0 (name
, ijs_symbol_get_name (t
)) == 0 )
186 for (i
= priv
->dirs
; i
; i
= g_list_next (i
))
188 IJsSymbol
*t
= IJS_SYMBOL (i
->data
);
189 IJsSymbol
* ret
= ijs_symbol_get_member (t
, name
);
199 import_symbol_get_name (IJsSymbol
*obj
)
205 import_symbol_list_member (IJsSymbol
*obj
)
207 ImportSymbol
* self
= IMPORT_SYMBOL (obj
);
208 ImportSymbolPrivate
*priv
= IMPORT_SYMBOL_PRIVATE(self
);
215 for (i
= priv
->member
; i
; i
= g_list_next (i
))
217 IJsSymbol
*t
= IJS_SYMBOL (i
->data
);
218 ret
= g_list_append (ret
, g_strdup (ijs_symbol_get_name (t
)));
220 for (i
= priv
->dirs
; i
; i
= g_list_next (i
))
222 IJsSymbol
*t
= IJS_SYMBOL (i
->data
);
223 ret
= g_list_concat (ret
, ijs_symbol_list_member (t
));