# 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  

hierarchy.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 
00027 namespace NLAISCRIPT
00028 {       
00029         const IClassInterpret *CCompilateur::getInheritanceRange(sint32 &h,const IClassInterpret *classType,NLAIAGENT::IBaseGroupType &listName) const
00030         {               
00031 
00032                 NLAIAGENT::CIteratorContener it = listName.getIterator();
00033                 sint32 i = listName.size() - 1;
00034                 const IClassInterpret *bassClass = NULL;                
00035                 while(i --)
00036                 {
00037                         const NLAIAGENT::IVarName &className = ((const NLAIAGENT::CStringType *)it++)->getStr();                        
00038                         bool find = false;
00039                         for(sint32 k = classType->sizeVTable() - 1; k >= 0 ;k--)
00040                         {
00041                                 bassClass = classType->getInheritance(k);
00042                                 h = k;
00043                                 if(*bassClass->getClassName() == className)
00044                                 {
00045                                         /*h  = -1;
00046                                         return NULL;*/
00047                                         find = true;
00048                                         break;
00049                                 }
00050                                 
00051                         }
00052                         if(!find)
00053                         {
00054                                 h  = -1;
00055                                 return NULL;
00056                         }
00057                 }               
00058                 return bassClass;
00059         }
00060 
00061         const IClassInterpret *CCompilateur::getInheritanceRange(sint32 &h,const IClassInterpret *classType,const NLAIAGENT::IVarName &className ) const
00062         {                               
00063                 const IClassInterpret *bassClass = NULL;
00064                 bool find = false;
00065                 for(sint32 k = classType->sizeVTable() - 1; k > 0 ;k--)
00066                 {
00067                         bassClass = classType->getInheritance(k);
00068                         h = k;
00069                         if(*bassClass->getClassName() == className)
00070                         {
00071                                 /*h  = -1;
00072                                 return NULL;*/
00073                                 find = true;
00074                                 return bassClass;
00075                         }
00076                         
00077                 }
00078                 if(!find)
00079                 {
00080                         h  = -1;
00081                         return NULL;
00082                 }
00083                 
00084                 return NULL;
00085         }
00086 
00087         /*sint32 CCompilateur::getCompementShift(IClassInterpret *classType)
00088         {
00089                 sint32 i = 0;           
00090                 classType = (IClassInterpret *)classType->getBaseClass();
00091                 while(classType != NULL)
00092                 {
00093                         i += classType->getStaticMemberSize();
00094                         classType = (IClassInterpret *)classType->getBaseClass();
00095                 }
00096                 return 0;
00097         }*/
00098 
00099         const NLAIAGENT::IObjectIA *CCompilateur::getValidateHierarchyBase(std::list<sint32> &ref,sint32 &h,std::list<NLAISCRIPT::CStringType> &listName)
00100         {
00101                 return getValidateHierarchyBase((IClassInterpret *)_SelfClass.get(),ref,h,listName);
00102         }
00103 
00104         const NLAIAGENT::IObjectIA *CCompilateur::getValidateHierarchyBase(const NLAIAGENT::IObjectIA *base,std::list<sint32> &ref,sint32 &h,std::list<NLAISCRIPT::CStringType> &listName)
00105         {               
00106                 std::list<NLAISCRIPT::CStringType> classHName;
00107                 std::list<NLAISCRIPT::CStringType> varHName;
00108                 const NLAIAGENT::IObjectIA *baseClass = base;           
00109 
00110                 ref.clear();
00111                 
00112                 h = 0;
00113                 NLAIAGENT::CStringVarName baseClassName("");
00114                 
00115                 while(listName.size())
00116                 {
00117                         NLAIAGENT::CStringVarName lastClassName(listName.back().data());
00118                         listName.pop_back();                    
00119                         try
00120                         {
00121                                 NLAIC::CIdentType id = getTypeOfClass(lastClassName);                           
00122                                 if(baseClass->isClassInheritedFrom(NLAIAGENT::CStringVarName(lastClassName.getString()))>=0)
00123                                 {
00124                                         classHName.push_front(lastClassName.getString());
00125                                 }                                                       
00126                                 else
00127                                 {
00128                                         /*char text[4096*4];
00129                                         sprintf(text,"you try to access to '%s' and this class is not define in the hierarchy of '%s' class",lastClassName.getString(),(const char *)baseClass->getType());
00130                                         yyerror(text);*/
00131                                         return NULL;
00132                                 }
00133                         }
00134                         catch(NLAIE::IException &)
00135                         {
00136                                 while(classHName.size())
00137                                 {
00138                                         varHName.push_front(classHName.front());
00139                                         classHName.pop_front();
00140                                 }
00141                                 varHName.push_front(lastClassName.getString());                                 
00142                         }                       
00143                 }
00144 
00145                 if(classHName.size())
00146                 {
00147                         std::list<NLAISCRIPT::CStringType>::iterator i = classHName.begin();                    
00148                         while(i != classHName.end())
00149                         {
00150                                 NLAIAGENT::CStringVarName str( NLAIAGENT::CStringVarName((*i++).data()));
00151                                 try
00152                                 {
00153                                         NLAIC::CIdentType id(str.getString());
00154                                         const NLAIAGENT::IObjectIA *b = (const NLAIAGENT::IObjectIA *)(id.getFactory())->getClass();                                    
00155                                         
00156                                         if((h = baseClass->isClassInheritedFrom(str)) >= 0)
00157                                         {                                               
00158                                                 baseClass = b;
00159                                         }
00160                                 }                               
00161                                 catch(NLAIE::IException &)
00162                                 {
00163                                         std::string text;
00164                                         text = NLAIC::stringGetBuild("you try to access to '%s' and this class is not define in the hierarchy of '%s' class",str.getString(),(const char *)baseClass->getType());
00165                                         yyerror((char *)text.c_str());
00166                                         return NULL;
00167                                 }
00168                         }       
00169 
00170                 }                               
00171                 if(varHName.size())
00172                 {
00173                         sint32 i;
00174                         NLAIAGENT::CStringVarName oldLastClassName("");
00175 
00176                         while(varHName.size())
00177                         {
00178                         
00179                                 NLAIAGENT::CStringVarName lastClassName(varHName.front().data());
00180                                 varHName.pop_front();
00181                                 
00182                                 i = baseClass->getStaticMemberIndex(lastClassName);
00183                                 if(i>=0)
00184                                 {                                                                                                               
00185                                         const NLAIAGENT::IObjectIA *c = baseClass->getStaticMember(i);
00186                                         /*if((const NLAIC::CTypeOfObject &)baseClass->getType() & NLAIC::CTypeOfObject::tAgentInterpret) 
00187                                         {
00188                                                 i += getCompementShift((IClassInterpret *)baseClass);
00189                                         }*/
00190                                         ref.push_back(i);                                       
00191                                         h = 0;                                  
00192                                         if(c != NULL)
00193                                         {
00194                                                 baseClass = c;
00195                                         }
00196                                         else
00197                                         {
00198                                                 std::string text;
00199                                                 text = NLAIC::stringGetBuild("you try to access to an indefined object in the '%s' class",(const char *)baseClass->getType());
00200                                                 yyerror((char *)text.c_str());
00201                                                 return NULL;
00202 
00203                                         }
00204                                                                                 
00205                                 }
00206                                 else
00207                                 {
00208                                         if((const NLAIC::CTypeOfObject &)baseClass->getType() & NLAIC::CTypeOfObject::tInterpret) 
00209                                         {
00210                                                 baseClass = getInheritanceRange(h,(const IClassInterpret *)baseClass,lastClassName);    
00211                                         }
00212                                         else
00213                                         {
00214                                                 h = baseClass->isClassInheritedFrom(lastClassName);
00215                                         }
00216                                         
00217                                         if(baseClass == NULL)
00218                                         {
00219                                                 std::string text;
00220                                                 text = NLAIC::stringGetBuild("you try to access to '%s' and this class is not define in the hierarchy of '%s' class",lastClassName.getString(),oldLastClassName.getString());
00221                                                 yyerror((char *)text.c_str());
00222                                                 return NULL;
00223                                         }                                       
00224                                 }                               
00225                         }                       
00226                 }
00227                 return baseClass;
00228         }
00229 }