X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fgrammar.git;a=blobdiff_plain;f=grammar.c;h=4ad1ba61127085177724164460788bd3ee41e9fd;hp=d716065a6396c5e2d51aabc64d05d777d7996d38;hb=HEAD;hpb=59aa417f29c790c64bc4501a8b08dd457d587e24 diff --git a/grammar.c b/grammar.c index d716065..4ad1ba6 100644 --- a/grammar.c +++ b/grammar.c @@ -1,3 +1,23 @@ +/* + * Copyright (C) 2005 Thadeu Lima de Souza Cascardo + * + * 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 struct _rule @@ -155,55 +175,23 @@ void rules_delete (GList** list) g_free (list); } -static void grammar_init (GTypeInstance* instance, gpointer g_class) -{ - Grammar* self = GRAMMAR(instance); - self->grammar = g_hash_table_new_full (symbol_hash, symbol_equal, - g_free, - (GDestroyNotify) rules_delete); -} - -static void grammar_finalize (GObject* obj) +grammar_t* grammar_new () { - GrammarClass* klass; - GObject* parent_class; - Grammar* self; - self = GRAMMAR(obj); - g_hash_table_destroy (self->grammar); - klass = GRAMMAR_GET_CLASS(obj); - parent_class = g_type_class_peek_parent (klass); - G_OBJECT_CLASS(parent_class)->finalize (obj); + grammar_t* grammar; + grammar = g_malloc (sizeof (grammar_t*)); + grammar->grammar = g_hash_table_new_full (symbol_hash, symbol_equal, + g_free, + (GDestroyNotify) rules_delete); + return grammar; } -static void grammar_class_init (GrammarClass* klass) +void grammar_delete (grammar_t* grammar) { - GObjectClass* gobj_class = G_OBJECT_CLASS(klass); - gobj_class->finalize = grammar_finalize; -} - -GType grammar_get_type () -{ - static GType type = 0; - if (type == 0) - { - static const GTypeInfo info = - { - sizeof (GrammarClass), - NULL, - NULL, - (GClassInitFunc)grammar_class_init, - NULL, - NULL, - sizeof (Grammar), - 0, - grammar_init - }; - type = g_type_register_static (G_TYPE_OBJECT, "GrammarType", &info, 0); - } - return type; + g_hash_table_destroy (grammar->grammar); + g_free (grammar); } -rule_t* grammar_rule_new (Grammar* grammar, symbol_t* left) +rule_t* grammar_rule_new (grammar_t* grammar, symbol_t* left) { GList** l; @@ -225,7 +213,7 @@ rule_t* grammar_rule_new (Grammar* grammar, symbol_t* left) } -GList* grammar_get_rules (Grammar* grammar, symbol_t* left) +GList* grammar_get_rules (grammar_t* grammar, symbol_t* left) { GList** l; if (!g_hash_table_lookup_extended (grammar->grammar,