/// TKS_ScriptConstraint.cpp 
///  
/// (c) 2001-2005 Bastian Spiegel <bs@tkscript.de>  
///     - distributed under terms of the GNU general public license (GPL).  
///  
 
 
#include "tks.h" 
#include "PTN_Node.h" 
#include "PTN_Expr.h" 
#include "PTN_Statement.h" 
 
#include "tks_inc_compiler.h" 
 
#include "PTN_ConstraintVarExpr.h" 
#include "TKS_ScriptConstraint.h" 
 
 
 
TKS_ScriptConstraint::TKS_ScriptConstraint(void) { 
   constraint_expr = 0; 
   cval            = 0; 
} 
 
TKS_ScriptConstraint::~TKS_ScriptConstraint() { 
   if(constraint_expr) 
   { 
      delete constraint_expr; constraint_expr=0; 
   } 
} 
 
sBool TKS_ScriptConstraint::checkConstraintExpr(PTN_Env *_env, YAC_Value *_currentValue) { 
   cval=_currentValue; 
   YAC_Value r; 
   constraint_expr->eval(_env, &r); 
   sBool b=0; 
   switch(r.type) 
   { 
   case YAC_TYPE_VOID: 
      break; 
       
   case YAC_TYPE_INT: 
      b=(r.value.int_val!=0); 
      break; 
       
   case YAC_TYPE_FLOAT: 
      b=((sSI)r.value.float_val)!=0; 
      break; 
       
   default: 
      if(YAC_VALID(r.value.object_val)) 
      { 
         b=(r.value.object_val->class_ID!=YAC_CLID_OBJECT); // not null object 
      } 
      break; 
   } 
    
   // ---- xxx raise constraint failed "exception" 
    
   r.unsetFast(); 
   return b; 
} 
 
