| 1 | /* tolext.cpp: Methods definition for BTolExtension class. |
|---|
| 2 | |
|---|
| 3 | Copyright (C) 2006 - Bayes Decision, SL (Spain [EU]) |
|---|
| 4 | author: Daniel Rus <danirus@tol-project.org> |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | This program is distributed in the hope that it will be useful, |
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | You should have received a copy of the GNU General Public License |
|---|
| 17 | along with this program; if not, write to the Free Software |
|---|
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|---|
| 19 | USA. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #if defined(_MSC_VER) |
|---|
| 23 | # include <win_tolinc.h> |
|---|
| 24 | #endif |
|---|
| 25 | |
|---|
| 26 | #include <tol/tol_bext.h> |
|---|
| 27 | #include <tol/tol_bgrammar.h> |
|---|
| 28 | #include <tol/tol_bsymboltable.h> |
|---|
| 29 | |
|---|
| 30 | //-------------------------------------------------------------------- |
|---|
| 31 | BExtension::~BExtension() |
|---|
| 32 | { |
|---|
| 33 | boperator_list* aux_list = op_list_; |
|---|
| 34 | |
|---|
| 35 | while(aux_list) |
|---|
| 36 | { |
|---|
| 37 | op_list_ = aux_list->next; |
|---|
| 38 | free(aux_list); |
|---|
| 39 | aux_list = op_list_; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | delete name_; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | //-------------------------------------------------------------------- |
|---|
| 46 | bool BExtension::addOperator(BOperator* oper) |
|---|
| 47 | { |
|---|
| 48 | void* vp = malloc(sizeof(boperator_list)); |
|---|
| 49 | if(!vp) |
|---|
| 50 | { |
|---|
| 51 | Error("Memory exhausted!"); |
|---|
| 52 | return false; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | boperator_list* entry = (boperator_list*) vp; |
|---|
| 56 | entry->next = NULL; |
|---|
| 57 | entry->op = oper; |
|---|
| 58 | |
|---|
| 59 | if(op_list_) |
|---|
| 60 | entry->next = op_list_; |
|---|
| 61 | |
|---|
| 62 | op_list_ = entry; |
|---|
| 63 | |
|---|
| 64 | return true; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | //-------------------------------------------------------------------- |
|---|
| 68 | BOperator* BExtension::findOperator(const BText& name, |
|---|
| 69 | const BGrammar* gra) const |
|---|
| 70 | { |
|---|
| 71 | BOperator* oper = NULL; |
|---|
| 72 | boperator_list* aux_list = op_list_; |
|---|
| 73 | |
|---|
| 74 | while(aux_list && !oper) |
|---|
| 75 | { |
|---|
| 76 | if(aux_list && aux_list->op && |
|---|
| 77 | (aux_list->op->Name()==name) && |
|---|
| 78 | (aux_list->op->Grammar()==gra)) |
|---|
| 79 | { |
|---|
| 80 | oper = aux_list->op; |
|---|
| 81 | } |
|---|
| 82 | else { aux_list = aux_list->next; } |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | return oper; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | //-------------------------------------------------------------------- |
|---|
| 89 | void BExtension::removeOperators() |
|---|
| 90 | { |
|---|
| 91 | |
|---|
| 92 | boperator_list* cur_list = op_list_; |
|---|
| 93 | |
|---|
| 94 | while(cur_list) |
|---|
| 95 | { |
|---|
| 96 | BObjClassify oc(cur_list->op->Grammar(), BBUILTINFUNMODE); |
|---|
| 97 | BSyntaxObject* oper = |
|---|
| 98 | BGrammar::SymbolTable().Search(oc, cur_list->op->Name()); |
|---|
| 99 | if(oper) BGrammar::SymbolTable().Kill(oper); |
|---|
| 100 | cur_list = cur_list->next; |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | |
|---|