# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

constraint_find_run.cpp

Go to the documentation of this file.
00001 
00006 /* Copyright, 2000 Nevrax Ltd.
00007  *
00008  * This file is part of NEVRAX NEL.
00009  * NEVRAX NEL is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013 
00014  * NEVRAX NEL is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * General Public License for more details.
00018 
00019  * You should have received a copy of the GNU General Public License
00020  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00022  * MA 02111-1307, USA.
00023  */
00024 #include "nel/ai/script/compilateur.h"
00025 #include "nel/ai/script/constraint.h"
00026 #include "nel/ai/script/constraint_find_run.h"
00027 #include "nel/ai/script/object_load.h"
00028 
00029 namespace NLAISCRIPT
00030 {       
00031 
00032         CConstraintFindRun::CConstraintFindRun( CConstraintMethode::TCallTypeOpCode callType,
00033                                                                                         int posHeap,IConstraint *baseClass,     NLAIAGENT::IBaseGroupType *methodName,CParam *param,int lin,int col):
00034                                                                                         CConstraintMethode(searchCall,posHeap,baseClass,methodName,param,lin,col),_TypeOfCallType(callType)                                             
00035         {               
00036         }
00037 
00038         const IConstraint *CConstraintFindRun::clone() const
00039         {
00040                 if(_BaseClass) _BaseClass->incRef();
00041                 _MethodName->incRef();
00042                 _Param->incRef();
00043                 IConstraint *x = new CConstraintFindRun(_TypeOfCallType,_PosHeap,_BaseClass,_MethodName,_Param,_Lin,_Col);              
00044                 return x;
00045         }
00046 
00047         void CConstraintFindRun::run(CCompilateur &c)
00048         {               
00049 #ifdef NL_DEBUG
00050                 std::string mtxt;
00051                 std::string ptxt;
00052                 std::string txt;
00053                 
00054                 _MethodName->getDebugString(mtxt);
00055                 _Param->getDebugString(ptxt);
00056                 txt += mtxt + ptxt;
00057 #endif
00058 
00059                 if(_BaseClass)
00060                 {
00061                         if(!_BaseClass->satisfied()) _BaseClass->run(c);
00062                         if(_BaseClass->satisfied())
00063                         {
00064                                 const NLAIAGENT::IObjectIA *cl = (const NLAIAGENT::IObjectIA *)(_BaseClass->getConstraintTypeOf()->getFactory())->getClass();
00065                                 CFunctionTag method;                            
00066                                 NLAIAGENT::IBaseGroupType *m = (NLAIAGENT::IBaseGroupType *)_MethodName->clone();                                                               
00067                                 const NLAIAGENT::IObjectIA *b = c.validateHierarchyMethode(method.Member,method.Inheritance,cl,*m);
00068                                 m->release();
00069                                 //const NLAIAGENT::IObjectIA *b = c.validateHierarchyMethode(method.Member,method.Inheritance,cl,*_MethodName);
00070                                 if(b)
00071                                 {                                       
00072                                         if(!(( (const NLAIC::CTypeOfObject &)b->getType() ) & NLAIC::CTypeOfObject::tInterpret))
00073                                         {
00074                                                 _Satisfied = true;
00075                                                 _MethodName->incRef();
00076                                                 _Param->incRef();
00077                                                 _BaseClass->incRef();
00078                                                 const CFunctionTag &m = getfunctionTag();
00079                                                 ILoadObject *o=0;
00080                                                 switch(_TypeOfCallType)
00081                                                 {
00082                                                 case normalCall:
00083                                                         o = new CLoadSelfObject(method.Member);
00084                                                         break;
00085 
00086                                                 case stackCall:
00087                                                         o = new CLoadStackObject(m.Member);
00088                                                         break;
00089 
00090                                                 case heapCall:
00091                                                         o = new CLoadHeapObject(m.Member,_PosHeap);
00092                                                         break;
00093         
00094                                                 case newCall:
00095                                                         o = NULL;
00096                                                         break;
00097 
00098                                                 case searchCall:
00099                                                         o = NULL;
00100                                                         break;
00101                                                         
00102                                                 }
00103                                                 IOpCode *x = new CFindRunMsg(_MethodName,_Param,(IOpType *)_BaseClass,o);
00104                                                 setOpCode(x);
00105                                                 return;
00106                                         }
00107                                 }
00108                         }
00109 
00110                 }               
00111                 CConstraintMethode::run(c);
00112         }               
00113 
00114         void CConstraintFindRun::setOpCode(CCompilateur &comp,IOpCode *,IConstraint *cType,bool del)
00115         {
00116                 const CFunctionTag &m = getfunctionTag();
00117                 IOpCode *x = new CMarkMsg(m.Inheritance, m.MethodNum);
00118                 while(_Code.size())
00119                 {                       
00120                         std::pair<int, CCodeBrancheRun *> &p = _Code.back();
00121                         IOpCode *op = (*p.second)[p.first];
00122                         op->release();
00123                         (*p.second)[p.first] = x;
00124                         _Code.pop_back();                       
00125                         if(_Code.size()) x->incRef();
00126                 }
00127                 _Type = cType;
00128                 _Type->run(comp);
00129                 _DelCType = del;
00130                 runConnexcion();
00131         }
00132         void CConstraintFindRun::setOpCode(IOpCode *x)
00133         {
00134                 while(_Code.size())
00135                 {                       
00136                         std::pair<int, CCodeBrancheRun *> &p = _Code.back();
00137                         IOpCode *op = (*p.second)[p.first];
00138                         op->release();
00139                         (*p.second)[p.first] = x;
00140                         _Code.pop_back();                       
00141                         if(_Code.size()) x->incRef();
00142                 }
00143                 _Type = _BaseClass;
00144                 runConnexcion();
00145         }
00146         
00147         CConstraintFindRun::~CConstraintFindRun()
00148         {                                                                       
00149         }
00150 }