<commit_before>/* /% C %/ */
/***********************************************************************
 * cint (C/C++ interpreter)
 ************************************************************************
 * Source file bc_item.cxx
 ************************************************************************
 * Description:
 *  item expression compiler
 *   object
 *   function
 *   object.member
 *   ::member
 *   object.member
 *   pointer->member
 *   object->member      (object.operator->())->member
 *   pointer[expr]
 *   array[expr][expr][expr]
 *   object[expr]
 *   (type)expr
 *   (expr)
 *   object(expr,expr)
 *   function(expr,expr)
 ************************************************************************
 * Copyright(c) 2004~2005  <NAME>
 *
 * For the licensing terms see the file COPYING
 *
 ************************************************************************/

#include <cmath>
#include <deque>
#include <string>

using namespace std;

#include "bc_item.h"

//______________________________________________________________________________
G__blockscope_expr::G__blockscope_expr(G__blockscope* blockscope)
{
   m_blockscope = blockscope;
   m_pinst = &blockscope->GetInst();
   m_isfixed = 0;
   m_isobject = 0;
   m_localscope.Init(-1);
}

//______________________________________________________________________________
G__value G__blockscope_expr::getitem(const string& item_string)
{
   int i = 0;
   int c;
   const char *item = item_string.c_str();
   while ((c = item[i])) {
      switch (c) {
         case ':':
            if (':' == item[i+1]) {
               return scope_operator(item, i);
            }
            else {
               //error
            }
            break;

         case '.':
            return member_operator(item, i);
            break;

         case '-':
            if ('>' == item[i+1]) {
               return pointer_operator(item, i);
            }
            else {
               //error
            }
            break;

         case '[':
            return index_operator(item, i);
            break;

         case '(':
            return fcall_operator(item, i);
            break;

         default:
            break;
      }
      ++i;
   }
   return getobject(item);
}

//______________________________________________________________________________
G__value G__blockscope_expr::scope_operator(const string& item, int& i)
{
   //class_name::member
   //::member
   if (i == 0) {
      //::member
      m_isfixed = 1;
      m_localscope.Init();
      return(getitem(item, i + 2));
   }
   else {
      string scopename = item.substr(0, i);
      G__ClassInfo scope = getscope(scopename);
      if (scope.IsValid()) {
         m_isfixed = 1;
         m_localscope.Init(scope.Tagnum());
         return(getitem(item, i + 2));
      }
      // error
      G__fprinterr(G__serr, "Error: undefined scope name '%s'", scopename.c_str());
      G__genericerror((char*)NULL);
   }
   return(G__null);
}

//______________________________________________________________________________
G__value G__blockscope_expr::member_operator(const string& item, int& i)
{
   //object.member
   //  G__getexpr(object)
   //  PUSHSTROS
   //  SETSTROS
   //  -> member
   //  POPSTROS

   string name = item.substr(0, i);
   G__value obj = getobject(name);
   m_localscope.Init(obj.tagnum);
   m_isobject = 1;
   m_isfixed = 0;

   m_pinst->PUSHSTROS();
   m_pinst->SETSTROS();

   G__value result = getitem(item, i + 1);

   m_pinst->POPSTROS();

   m_localscope.Init(-1);
   m_isobject = 0;

   return(result);
}

//______________________________________________________________________________
G__value G__blockscope_expr::pointer_operator(const string& item, int& i)
{
   //pointer->member
   //  G__getexpr(pointer)
   //  PUSHSTROS
   //  SETSTROS
   //  -> member
   //  POPSTROS
   //object->member      (object.operator->())->member
   //  G__getexpr(object)
   //  PUSHSTROS
   //  SETSTROS
   //  operator->
   //  PUSHSTROS
   //  SETSTROS
   //  -> member
   //  POPSTROS
   //  POPSTROS

   string name = item.substr(0, i);
   G__value obj = getobject(name);
   m_isfixed = 0;
   G__TypeReader ty(obj);

   if (ty.Ispointer() && -1 != ty.Tagnum()) {
      //pointer->member
      //  G__getexpr(pointer)
      //  PUSHSTROS
      //  SETSTROS
      //  -> member
      //  POPSTROS<commit_msg>quiet cov 34177,34178,34179<commit_after>/* /% C %/ */
/***********************************************************************
 * cint (C/C++ interpreter)
 ************************************************************************
 * Source file bc_item.cxx
 ************************************************************************
 * Description:
 *  item expression compiler
 *   object
 *   function
 *   object.member
 *   ::member
 *   object.member
 *   pointer->member
 *   object->member      (object.operator->())->member
 *   pointer[expr]
 *   array[expr][expr][expr]
 *   object[expr]
 *   (type)expr
 *   (expr)
 *   object(expr,expr)
 *   function(expr,expr)
 ************************************************************************
 * Copyright(c) 2004~2005  <NAME>
 *
 * For the licensing terms see the file COPYING
 *
 ************************************************************************/

#include <cmath>
#include <deque>
#include <string>

using namespace std;

#include "bc_item.h"

//______________________________________________________________________________
G__blockscope_expr::G__blockscope_expr(G__blockscope* blockscope)
{
   m_blockscope = blockscope;
   m_pinst = &blockscope->GetInst();
   m_isfixed = 0;
   m_isobject = 0;
   m_localscope.Init(-1);
}

//______________________________________________________________________________
G__value G__blockscope_expr::getitem(const string& item_string)
{
   int i = 0;
   int c;
   const char *item = item_string.c_str();
   while ((c = item[i])) {
      switch (c) {
         case ':':
            if (':' == item[i+1]) {
               return scope_operator(item, i);
            }
            else {
               //error
            }
            break;

         case '.':
            return member_operator(item, i);
            break;

         case '-':
            if ('>' == item[i+1]) {
               return pointer_operator(item, i);
            }
            else {
               //error
            }
            break;

         case '[':
            return index_operator(item, i);
            break;

         case '(':
            return fcall_operator(item, i);
            break;

         default:
            break;
      }
      ++i;
   }
   G__object_id objid;
   return getobject(item,&objid);
}

//______________________________________________________________________________
G__value G__blockscope_expr::scope_operator(const string& item, int& i)
{
   //class_name::member
   //::member
   if (i == 0) {
      //::member
      m_isfixed = 1;
      m_localscope.Init();
      return(getitem(item, i + 2));
   }
   else {
      string scopename = item.substr(0, i);
      G__ClassInfo scope = getscope(scopename);
      if (scope.IsValid()) {
         m_isfixed = 1;
         m_localscope.Init(scope.Tagnum());
         return(getitem(item, i + 2));
      }
      // error
      G__fprinterr(G__serr, "Error: undefined scope name '%s'", scopename.c_str());
      G__genericerror((char*)NULL);
   }
   return(G__null);
}

//______________________________________________________________________________
G__value G__blockscope_expr::member_operator(const string& item, int& i)
{
   //object.member
   //  G__getexpr(object)
   //  PUSHSTROS
   //  SETSTROS
   //  -> member
   //  POPSTROS

   string name = item.substr(0, i);
   G__object_id objid;
   G__value obj = getobject(name,&objid);
   m_localscope.Init(obj.tagnum);
   m_isobject = 1;
   m_isfixed = 0;

   m_pinst->PUSHSTROS();
   m_pinst->SETSTROS();

   G__value result = getitem(item, i + 1);

   m_pinst->POPSTROS();

   m_localscope.Init(-1);
   m_isobject = 0;

   return(result);
}

//______________________________________________________________________________
G__value G__blockscope_expr::pointer_operator(const string& item, int& i)
{
   //pointer->member
   //  G__getexpr(pointer)
   //  PUSHSTROS
   //  SETSTROS
   //  -> member
   //  POPSTROS
   //object->member      (object.operator->())->member
   //  G__getexpr(object)
   //  PUSHSTROS
   //  SETSTROS
   //  operator->
   //  PUSHSTROS
   //  SETSTROS
   //  -> member
   //  POPSTROS
   //  POPSTROS

   string name = item.substr(0, i);
   G__object_id objid;
   G__value obj = getobject(name,&objid);
   m_isfixed = 0;
   G__TypeReader ty(obj);

   if (ty.Ispointer() && -1 != ty.Tagnum()) {
      //pointer->member
      //  G__getexpr(pointer)
      //  PUSHSTROS
      //  SETSTROS
      //  -> member
      //  POPSTROS
{'fraction_non_alphanumeric': 0.20323822463768115, 'fraction_numerical': 0.008265398550724638, 'mean_word_length': 2.527555910543131, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2327452', 'n_tokens_mistral': 2790, 'n_tokens_neox': 2680, 'n_words': 487}