simple-symbol.c 4.15 KB
Newer Older
Maxim Ermilov's avatar
Maxim Ermilov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
    Copyright (C) 2009 Maxim Ermilov   <zaspire@rambler.ru>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "simple-symbol.h"

static void simple_symbol_interface_init (IJsSymbolIface *iface);
static GList* simple_symbol_get_arg_list (IJsSymbol *obj);
static gint simple_symbol_get_base_type (IJsSymbol *obj);
static GList* simple_symbol_get_func_ret_type (IJsSymbol *obj);
static IJsSymbol* simple_symbol_get_member (IJsSymbol *obj, const gchar * name);
static const gchar * simple_symbol_get_name (IJsSymbol *obj);
static GList* simple_symbol_list_member (IJsSymbol *obj);

G_DEFINE_TYPE_WITH_CODE (SimpleSymbol, simple_symbol, G_TYPE_OBJECT,
			G_IMPLEMENT_INTERFACE (IJS_TYPE_SYMBOL,
						simple_symbol_interface_init));

static void
simple_symbol_init (SimpleSymbol *object)
{
	object->name = NULL;
	object->member = NULL;
	object->ret_type = NULL;
	object->args = NULL;
}

static void
simple_symbol_finalize (GObject *obj)
{
	SimpleSymbol *self = SIMPLE_SYMBOL (obj);
	g_free (self->name);

	g_list_foreach (self->member, (GFunc)g_object_unref, NULL);
	g_list_free (self->member);
	
	g_list_foreach (self->ret_type, (GFunc)g_free, NULL);
	g_list_free (self->ret_type);

	g_list_foreach (self->args, (GFunc)g_free, NULL);
	g_list_free (self->args);

	G_OBJECT_CLASS (simple_symbol_parent_class)->finalize (obj);
}

static void
simple_symbol_class_init (SimpleSymbolClass *klass)
{
	GObjectClass* object_class = G_OBJECT_CLASS (klass);
	/*GObjectClass* parent_class = G_OBJECT_CLASS (klass);*/

	object_class->finalize = simple_symbol_finalize;
}


SimpleSymbol*
simple_symbol_new (void)
{
	return g_object_new (SIMPLE_TYPE_SYMBOL, NULL);
}

static void
simple_symbol_interface_init (IJsSymbolIface *iface)
{
	iface->get_arg_list = simple_symbol_get_arg_list;
	iface->get_base_type = simple_symbol_get_base_type;
	iface->get_func_ret_type = simple_symbol_get_func_ret_type;
	iface->get_member = simple_symbol_get_member;
	iface->get_name = simple_symbol_get_name;
	iface->list_member = simple_symbol_list_member;
}

static GList*
simple_symbol_get_arg_list (IJsSymbol *obj)
{
	SimpleSymbol *symbol = SIMPLE_SYMBOL (obj);
	GList* ret = NULL;
	GList* i;
	for (i = symbol->args; i; i = g_list_next (i))
	{
		ret = g_list_append (ret, g_strdup ((gchar*)i->data));
	}
	return ret;
}

static gint
simple_symbol_get_base_type (IJsSymbol *obj)
{
	SimpleSymbol *symbol = SIMPLE_SYMBOL (obj);
	return symbol->type;
}

static GList*
simple_symbol_get_func_ret_type (IJsSymbol *obj)
{
	SimpleSymbol *symbol = SIMPLE_SYMBOL (obj);
	GList* ret = NULL;
	GList* i;
	for (i = symbol->ret_type; i; i = g_list_next (i))
	{
		ret = g_list_append (ret, g_strdup ((gchar*)i->data));
	}
	return ret;
}

static IJsSymbol*
simple_symbol_get_member (IJsSymbol *obj, const gchar * name)
{
	GList *i;
	SimpleSymbol *symbol = SIMPLE_SYMBOL (obj);
	for (i = symbol->member; i; i = g_list_next (i))
	{
		IJsSymbol* t = IJS_SYMBOL (i->data);
		if (g_strcmp0 (name, ijs_symbol_get_name (t)) == 0 )
		{
			g_object_ref (t);
			return t;
		}
	}
	return NULL;
}

static const gchar *
simple_symbol_get_name (IJsSymbol *obj)
{
	SimpleSymbol *symbol = SIMPLE_SYMBOL (obj);
	return symbol->name;
}

static GList*
simple_symbol_list_member (IJsSymbol *obj)
{
	GList *i;
	SimpleSymbol *symbol = SIMPLE_SYMBOL (obj);
	GList *ret = NULL;
	for (i = symbol->member; i; i = g_list_next (i))
	{
		IJsSymbol* t = IJS_SYMBOL (i->data);
		ret = g_list_append (ret, g_strdup (ijs_symbol_get_name (t)));
	}
	return ret;
}