/// TKS_ClassDeclMember.cpp
///
/// (c) 2001-2009 Bastian Spiegel <bs@tkscript.de>
///     - distributed under the terms of the GNU general public license (GPL).
///


#include "tks.h" 
#include "tks_inc_class.h"
#include "tks_inc_compiler.h" 
#include "TKS_ClassDeclMember.h" 


TKS_ClassDeclMember::TKS_ClassDeclMember(void) {
    offset                   = 0;
    rtti                     = 0;
    value.any                = 0;
    b_delete_template_object = 0;
    protection_flags         = TKS_PROT_NONE; 
    init_expr                = 0; 
    deref_init_expr          = 0; 
    b_static                 = 0; 
    co_static                = 0;
    b_noinit                 = 0;
}

TKS_ClassDeclMember::~TKS_ClassDeclMember() {
   if(b_delete_template_object) 
   {
      YAC_DELETE(value.object_val);
      value.object_val = 0; 
   }
   offset = 0;
   rtti = 0;
   value.any = 0;
   if(init_expr) 
   { 
      delete init_expr; 
      init_expr = 0;
   } 
   if(co_static) 
   { 
      co_static->unset();
      delete co_static; 
      co_static = 0;
   }
}
 
void TKS_ClassDeclMember::createStaticInstance(void) { 
   switch(rtti) 
   { 
   case YAC_TYPE_VARIANT: 
      break; 
   case YAC_TYPE_INT: 
      co_static->initInt(0); 
      break; 
   case YAC_TYPE_FLOAT: 
      co_static->initFloat(0.0f); 
      break; 
   default: 
      createStaticObjectInstance(); 
      break; 
   } 
} 
 
// ---- instantiate static class member 
void TKS_ClassDeclMember::createStaticObjectInstance(void) { 
   if(rtti==TKS_CLASSDECL_RTTI_CLASS) 
   { 
      if(b_noinit)
      {
         co_static->initNull();
      }
      else
      {
         if(value.sobject_val) 
         { 
            co_static->value.object_val = YAC_CLONE_POOLED(NULL, value.object_val); 
            co_static->deleteme=1; 
         } 
      }
   } 
   else 
   { 
      if(value.object_val) 
      { 
         if(b_delete_template_object) 
         { 
            co_static->value.object_val=value.object_val; 
            co_static->deleteme=0; 
            // ---- template object is deleted when class is deleted 
         } 
         else 
         { 
            // ---- create object instance 
            if(b_noinit)
            {
               co_static->initNull();
            }
            else
            {
               co_static->value.object_val = YAC_CLONE_POOLED(NULL, value.object_val); 
               co_static->deleteme=1; 
            }
         } 
      } 
   } 
} 
