00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_CONSTRAINT_H
00027 #define NL_CONSTRAINT_H
00028
00029 #include "nel/ai/script/interpret_methodes.h"
00030
00031 namespace NLAISCRIPT
00032 {
00033 class CCompilateur;
00034 class CCodeBrancheRun;
00035 class CMethodeName;
00036 class IClassInterpret;
00037 class IOpCode;
00038
00049 struct CFunctionTag
00050 {
00052 sint32 Inheritance;
00054 sint32 MethodNum;
00056 CMethodeName *Method;
00058 const NLAIAGENT::IObjectIA *Object;
00060 const NLAIAGENT::IVarName *MethodName;
00062 std::list<sint32> Member;
00064 NLAIAGENT::IObjectIA *ReturnType;
00065
00067 CFunctionTag()
00068 {
00069 Method = NULL;
00070 Object = NULL;
00071 ReturnType = NULL;
00072 MethodName = NULL;
00073 }
00074
00076 CFunctionTag(const CFunctionTag &c)
00077 {
00078 Inheritance = c.Inheritance;
00079 MethodNum = c.MethodNum;
00080 Method = c.Method;
00081 Object = c.Object;
00082 MethodName = c.MethodName;
00083 Member = c.Member;
00084 ReturnType = c.ReturnType;
00085 if(ReturnType) ReturnType->incRef();
00086 }
00087
00089 const CFunctionTag &operator = (const CFunctionTag &c)
00090 {
00091 Inheritance = c.Inheritance;
00092 MethodNum = c.MethodNum;
00093 Method = c.Method;
00094 Object = c.Object;
00095 MethodName = c.MethodName;
00096 Member = c.Member;
00097 if(ReturnType) ReturnType->release();
00098 ReturnType = c.ReturnType;
00099 if(ReturnType) ReturnType->incRef();
00100 return *this;
00101 }
00102
00103
00105 void setTypeObject(NLAIAGENT::IObjectIA *o)
00106 {
00107 if(ReturnType) ReturnType->release();
00108 ReturnType = o;
00109 ReturnType->incRef();
00110 }
00111
00112 virtual ~CFunctionTag()
00113 {
00114 if(ReturnType) ReturnType->release();
00115 }
00116
00117 };
00118
00129 class IConstraint : public NLAIC::IPointerGestion
00130 {
00131 public:
00138 enum ConstraintTypeEnum
00139 {
00141 constraintMethode,
00143 constraintChkMethodeType,
00145 operandSimple,
00147 operandSimpleListOr,
00149 operandAnyObject,
00151 operandVoid,
00153 operandUnknown,
00155 operationType,
00157 operationTypeGD,
00159 operandListType,
00161 constraintStackComp,
00163 constraintDebug,
00165 constraintFindRun
00166 };
00167
00168 private:
00170 std::list<IConstraint *> _ConstraintList;
00171
00172 public:
00173 IConstraint() {}
00174
00176 virtual void run(CCompilateur &) = 0;
00178 virtual void run(IConstraint *) = 0;
00180 virtual bool satisfied() = 0;
00184 virtual void addIndex(int n,CCodeBrancheRun *opcodePtr) = 0;
00186 virtual ConstraintTypeEnum getTypeOfClass() const = 0;
00188 virtual void getError(char *) const = 0;
00189
00191 virtual int getLine() const = 0;
00193 virtual int getColone() const = 0;
00194
00195 virtual bool operator == (const IConstraint &) const = 0;
00196
00198 virtual const NLAIC::CIdentType *getConstraintTypeOf() = 0;
00200 virtual const IConstraint *clone() const = 0;
00202 virtual const char *getInfo() = 0;
00204 virtual bool dependOn(const IConstraint *) const = 0;
00205
00207 void addConstraint(IConstraint *c)
00208 {
00209 _ConstraintList.push_back(c);
00210 }
00212 void popConstraint(IConstraint *c);
00214 void runConnexcion()
00215 {
00216 while(_ConstraintList.size())
00217 {
00218 IConstraint *a = _ConstraintList.back();
00219 _ConstraintList.pop_back();
00220 a->run(this);
00221 }
00222 }
00223
00224 virtual ~IConstraint()
00225 {
00226 }
00227
00228 };
00229 class IClassInterpret;
00230
00231
00241 class CConstraintMethode: public IConstraint
00242 {
00243
00244 public:
00249 enum TCallTypeOpCode{
00251 normalCall,
00253 stackCall,
00255 heapCall,
00257 newCall,
00259 searchCall
00260 };
00261 protected:
00263 TCallTypeOpCode _CallType;
00265 IConstraint *_BaseClass;
00267 NLAIAGENT::IBaseGroupType *_MethodName;
00269 CParam *_Param;
00270 bool _Satisfied;
00271 int _Lin;
00272 int _Col;
00273 std::list<std::pair<int, CCodeBrancheRun *> > _Code;
00274 char *_Txt;
00275 IConstraint *_Type;
00276 char *_TxtInfo;
00277 int _PosHeap;
00278 bool _DelCType;
00279 CFunctionTag _M;
00280
00281 public:
00282 CConstraintMethode(TCallTypeOpCode callType,int posHeap,IConstraint *baseClass,NLAIAGENT::IBaseGroupType *methodName,CParam *param,int lin,int col):
00283 _CallType(callType),_BaseClass(baseClass),_MethodName(methodName),_Param(param),_Satisfied(false),_Lin(lin),_Col(col),_PosHeap(posHeap)
00284 {
00285 _Txt = NULL;
00286 _Type = NULL;
00287 std::string txt;
00288 std::string m;
00289 std::string p;
00290 _MethodName->getDebugString(m);
00291 _Param->getDebugString(p);
00292 txt = "constraint<CConstraintMethode> for";
00293 txt += m;
00294 txt += p;
00295 txt += NLAIC::stringGetBuild(" at line %d",_Lin);
00296 _TxtInfo = new char [strlen(txt.c_str()) + 1];
00297 strcpy(_TxtInfo,txt.c_str());
00298 _DelCType = false;
00299 }
00301
00302
00303 const char *getInfo()
00304 {
00305 return _TxtInfo;
00306 }
00307
00308 virtual void run(CCompilateur &);
00309 virtual void run(IConstraint *);
00310
00311 bool satisfied()
00312 {
00313 return _Satisfied;
00314 }
00315
00316 bool dependOn(const IConstraint *c) const
00317 {
00318 if( c == _Type || c == _BaseClass || c == this) return true;
00319 return false;
00320 }
00321
00322 bool operator == (const IConstraint &c) const
00323 {
00324 if(getTypeOfClass() == c.getTypeOfClass() &&
00325 ((const CConstraintMethode &)c)._CallType == _CallType &&
00326 ((const CConstraintMethode &)c)._BaseClass == _BaseClass &&
00327 ((const CConstraintMethode &)c).isEqual(*_MethodName,*_Param))
00328 {
00329 return true;
00330 }
00331 return false;
00332 }
00333
00334 void addIndex(int i,CCodeBrancheRun *c)
00335 {
00336 _Code.push_back(std::pair<sint32, CCodeBrancheRun *>(i,c));
00337 }
00338
00339 void getError(char *) const;
00340
00341 const IConstraint *clone() const;
00342
00343 bool isEqual(const NLAIAGENT::IBaseGroupType &,const CParam &) const;
00344
00345 virtual void setOpCode(CCompilateur &comp,IOpCode *x,IConstraint *cType,bool del);
00346
00347 const NLAIC::CIdentType *getConstraintTypeOf()
00348 {
00349 return _Type == NULL ? NULL : _Type->getConstraintTypeOf();
00350 }
00351
00352 virtual ConstraintTypeEnum getTypeOfClass() const
00353 {
00354 return constraintMethode;
00355 }
00356
00357 const CFunctionTag &getfunctionTag() const
00358 {
00359 return _M;
00360 }
00361
00362 int getLine() const
00363 {
00364 return _Lin;
00365 }
00366 int getColone() const
00367 {
00368 return _Col;
00369 }
00371
00372 virtual ~CConstraintMethode()
00373 {
00374 _MethodName->release();
00375 _Param->release();
00376 if(_BaseClass)_BaseClass->release();
00377 if(_Txt != NULL) delete _Txt;
00378 delete _TxtInfo;
00379 if(_DelCType) _Type->release();
00380 }
00381
00382 };
00383 }
00384 #include "nel/ai/script/constraint_type.h"
00385 #endif