Ejemplo n.º 1
0
MemMappedFile::MemMappedFile(cf_const std::string & name, size_t size,
                             cf_int prot, bool lock,bool autoUnmap)
    :_pShm(NULL),
     _size(size),
     _isLocked(lock),
     _autoUnmap(autoUnmap)
{
    if (size<=0)
        _THROW(ValueError, "size !");

    cf_int fd =cf_open(name.c_str(), ipcdefs::FLAG_CREATE, ipcdefs::MODE_DEFAULT);
    if(0!=fd)
        _THROW(SyscallExecuteError, "Failed to execute cf_open !");

    struct stat st_buf = {0};
    if(0!=cf_fstat(fd,&st_buf))
        _THROW(SyscallExecuteError, "Failed to execute cf_fstat !");

    if (st_buf.st_size < _size)
    {
        if(0!=cf_ftruncate(fd,size))
            _THROW(SyscallExecuteError, "Failed to execute cf_ftruncate !");
    }

    if (size == 0)
        _size = st_buf.st_size;
    _pShm = Mmap(fd, prot);
    if (lock && 0!=cf_mlock(_pShm, _size))
        _THROW(SyscallExecuteError, "Failed to execute cf_mlock !");
}
Ejemplo n.º 2
0
    cf_void WritePid()
    {
        char p [MAX_SIZE];
        GetPathByPathNameExt(_filePathName.c_str(), _filePathName.size() , p);
        if(0==IsFileExist(p))
        {
            if(-1==mkdir(p, S_IRWXU | S_IRWXG | S_IROTH))
            {
                _THROW(SyscallExecuteError, "Failed to execute mkdir !");
            }
        }

        _fd =cf_open(_filePathName.c_str(),O_RDWR|O_CREAT|O_TRUNC,
                     S_IRWXU | S_IRWXG | S_IROTH);
        if(-1==_fd)
        {
            _THROW(SyscallExecuteError, "Failed to execute cf_open !");
        }
        char buf[8] = {0};
        int n =snprintf(buf,sizeof(buf),"%u",unsigned(getpid()));
        ssize_t nw =cf_write(_fd,buf,n);
        if(nw!=n)
        {
            _THROW_FMT(ValueError, "nw{%d}!=n{%d} !",int(nw),int(n));
        }
    }
Ejemplo n.º 3
0
SysVMsgQ::SysVMsgQ(cf_const std::string & name, cf_int flag,bool autoRemove):
    _name(name),_key(cf_ftok(_name.c_str(),1)),
    _autoRemove(autoRemove)
{
    if(_key == -1)
        _THROW(SyscallExecuteError, "Failed to execute cf_ftok !");
    _msgId = cf_msgget(_key, flag);
    if(_msgId == -1)
        _THROW(SyscallExecuteError, "Failed to execute cf_msgget !");
}
Ejemplo n.º 4
0
int printer_anon_map_entry_print_node(PrinterBase_ptr self,
                                      node_ptr n,
                                      int priority)
{
  const NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(self));
  const ErrorMgr_ptr errmgr =
    ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));

  if (Nil == n) return 1;
  
  switch(node_get_type(n)) {
  case DOT:
    {
      /* since "." is also a separator, we can skip print the "," if
         immediately followed by "." */
      return
        _PRINT(NODE_ANONYMIZER_DOT_STR) &&
        _THROW(car(n)) &&
        ((Nil != cdr(n) && DOT == node_get_type(cdr(n))) || _PRINT(NODE_ANONYMIZER_SEPARATOR_STR)) &&
        _THROW(cdr(n));
    }

  case ATOM:
    /* Here ideally we would let the PrinterWffCore handle it. We can't because
       PrinterWffCore and this printer both handle DOT nodes. So we are
       duplicating the PrinterWffCore code for ATOM and NUMBER */
    if (!_PRINT(UStringMgr_get_string_text((string_ptr) car(n)))) return 0;
    if (cdr(n)) {
      char buf[20];
      int chars = snprintf(buf, 20, "_%d", NODE_TO_INT(cdr(n)));
      SNPRINTF_CHECK(chars, 20);

      return _PRINT(buf);
    }
    return 1;

  case NUMBER:
    {
      char buf[20];
      int c = snprintf(buf, 20, "%d", NODE_TO_INT(car(n)));
      SNPRINTF_CHECK(c, 20);

      return _PRINT(buf);
    }
    /* end of code duplication */

  default:
    ErrorMgr_internal_error(errmgr, "%s: not supported type = %d",
                            __func__,
                            node_get_type(n));
  }
}
Ejemplo n.º 5
0
SysVShM::SysVShM(key_t key, size_t size, cf_int shmFlag,bool autoRemove,
                 bool autoDetach)
    :_key(key),
     _shmid(-1),
     _pShmAddr(NULL),
     _autoRemove(autoRemove),
     _autoDetach(autoDetach)
{
    if ( -1==(_shmid = cf_shmget(_key, size, shmFlag)) )
        _THROW(SyscallExecuteError, "Failed to execute cf_shmget !");
    if ( (cf_void *)(-1)==(_pShmAddr=cf_shmat(_shmid, NULL, 0)) )
        _THROW(SyscallExecuteError, "Failed to execute cf_shmat !");
}
Ejemplo n.º 6
0
PosixShM::PosixShM(cf_cpstr name, size_t size, cf_int oflag, cf_int prot ,
                   mode_t mode,
                   bool autoUnlink,bool autoClose):
    _name(name),
    _size(size),
    _autoUnlink(autoUnlink),
    _autoClose(autoClose)
{
    if (size<=0)
        _THROW(ValueError, "size !")
        if( -1==(_fd=cf_shm_open(_name.c_str(), oflag, mode)) )
            _THROW(SyscallExecuteError, "Failed to execute cf_shm_open !");
    Ftruncate(_size);
    _pShm =Mmap(_fd, prot);
}
Ejemplo n.º 7
0
ssize_t PosixMsgQ::Recv(cf_char * msg_ptr,size_t msg_len, cf_uint  * msg_prio,
                        cf_const struct timespec * abs_timeout)
{
    ssize_t rt =0;
    if( -1==(rt=cf_mq_timedreceive(_fd, msg_ptr,msg_len, msg_prio,abs_timeout)) )
        _THROW(SyscallExecuteError, "Failed to execute cf_mq_timedreceive !");
    return rt;
}
Ejemplo n.º 8
0
cf_pvoid PosixShM::Mmap(cf_int fd, cf_int prot)
{
    cf_pvoid pShm = cf_mmap(NULL,_size, prot,
                            ipcdefs::MMAPFLAG_DEFAULT, fd, 0);
    if ( MAP_FAILED==pShm )
        _THROW(SyscallExecuteError, "Failed to execute cf_mmap !");
    return pShm;
}
Ejemplo n.º 9
0
locale::locale(const char *_S, category _C)
        : _Ptr(new _Locimp)
        {       // construct a locale with named facets
        _Init();
        _Locinfo _Lobj(_C, _S);
        if (_Lobj._Getname().compare("*") == 0)
                _THROW(runtime_error, "bad locale name");
        _Locimp::_Makeloc(_Lobj, _C, _Ptr, 0);
        }
Ejemplo n.º 10
0
locale::locale(const locale& _X, const char *_S, category _C)
        : _Ptr(new _Locimp(*_X._Ptr))
        {       // construct a locale by copying, replacing named facets
        _Locinfo _Lobj(_C, _S);
        if (_Lobj._Getname().compare("*") == 0)
                _THROW(runtime_error, "bad locale name");
        _Locimp::_Makeloc(_Lobj._Addcats(_Ptr->_Cat,
                _Ptr->_Name.c_str()), _C, _Ptr, 0);
        }
Ejemplo n.º 11
0
cf_void MemMappedFile::Msync(size_t fromIndex, size_t len, cf_int flag)
{
    if(fromIndex+len>size_t(_size))
        _THROW_FMT(ValueError, "fromIndex{%lld}+len{%lld}>size_t(_size) {%lld}!",
                   (cf_llong)fromIndex,(cf_llong)len,(cf_llong)_size);
    cf_char * p =(cf_char *)_pShm;
    p +=fromIndex;
    if (  0!=cf_msync( (cf_pvoid)p, len, flag )  )
        _THROW(SyscallExecuteError, "Failed to execute cf_msync !");
}
Ejemplo n.º 12
0
bool bu_hci::check_dev_state()
{
    if(_chekingdev){
        return true;
    }
    static int everysec=0;

    _chekingdev=true;
    if(everysec==0)
    {
        bool is_up = _socket->is_up();
        if (_isDevUp != is_up)
        {
            if (is_up)
            {
                try{
                    reset();
                    ::usleep(512000);
                    _reconfigure();
                }catch(...)
                {
                    is_up=false;
                }
            }
            _pev->on_dev_status(is_up);
            _isDevUp = is_up;
        }

        if(_isDevUp==false)
        {
            if(!_recreate_sock())
            {
                _THROW("");
            }
        }
    }
    if(++everysec>400)everysec=0;
    _chekingdev=false;
    return _isDevUp;
}
Ejemplo n.º 13
0
    cf_uint32 ReadPid()
    {
        char p [MAX_SIZE];
        GetPathByPathNameExt(_filePathName.c_str(), _filePathName.size() , p);
        if(0==IsFileExist(p))
        {
            _THROW_FMT(RuntimeWarning, "Failed access file %s !",p);
        }

        _fd =cf_open(_filePathName.c_str(),O_RDWR,S_IRWXU | S_IRWXG | S_IROTH);
        if(-1==_fd)
        {
            _THROW(SyscallExecuteError, "Failed to execute cf_open !");
        }
        char buf[8] = {0};
        ssize_t nr =cf_read(_fd,buf,sizeof(buf));
        if(nr<=0)
        {
            _THROW_FMT(ValueError, "Failed cf_read ! nr=%d ",int(nr));
        }
        return cf_uint32(atoi(buf));
    }
Ejemplo n.º 14
0
cf_void  SysVShM::Detach()
{
    if ((_pShmAddr != NULL) && 0!=(cf_shmdt(_pShmAddr)))
        _THROW(SyscallExecuteError, "Failed to execute cf_shmdt !");
    _pShmAddr = NULL;
}
Ejemplo n.º 15
0
cf_void PosixShM::Ftruncate(off_t length)
{
    if( 0!=cf_ftruncate(_fd, length) )
        _THROW(SyscallExecuteError, "Failed to execute cf_ftruncate !");
    _size =length;
}
Ejemplo n.º 16
0
cf_void PosixShM::Fstat(struct stat * buf)
{
    if( 0!=cf_fstat(_fd, buf) )
        _THROW(SyscallExecuteError, "Failed to execute cf_fstat !");
}
Ejemplo n.º 17
0
cf_void PosixShM::Unlink()
{
    if( 0!=cf_shm_unlink(_name.c_str()) )
        _THROW(SyscallExecuteError, "Failed to execute cf_shm_unlink !");
}
Ejemplo n.º 18
0
cf_void PosixShM::Close()
{
    if( 0!=cf_close(_fd) )
        _THROW(SyscallExecuteError, "Failed to execute cf_close !");
}
Ejemplo n.º 19
0
cf_void PosixMsgQ::Notify(cf_const struct sigevent * sevp)
{
    if( 0!=cf_mq_notify(_fd,sevp) )
        _THROW(SyscallExecuteError, "Failed to execute cf_mq_notify !");
}
Ejemplo n.º 20
0
int printer_psl_print_node(PrinterBase_ptr self, node_ptr n, int priority)
{
  const NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(self));
  const ErrorMgr_ptr errmgr =
    ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));

  PslNode_ptr psl = PslNode_convert_from_node_ptr(n);

  switch (psl_node_get_op(psl)) {

  case PSL_INF: return _PRINT("inf");

  case PSL_SERE:
    {
      int retval;

      if (!psl_node_is_sere(psl_node_get_left(psl))) retval = _PRINT("{");
      else retval = 1;

      retval = retval && _THROW(psl_node_get_left(psl));

      if (!psl_node_is_sere(psl_node_get_left(psl))) retval = _PRINT("}");
      return retval;
    }

  case PSL_SERECONCAT:
    return _PRINT("{") && \
      _THROW(psl_node_get_left(psl)) && _PRINT("; ") &&
      _THROW(psl_node_get_right(psl)) && _PRINT("}");

  case PSL_SEREFUSION:
    return _PRINT("{") && \
      _THROW(psl_node_get_left(psl)) && _PRINT(" : ") &&
      _THROW(psl_node_get_right(psl)) && _PRINT("}");

  case PSL_SERECOMPOUND:
    {
      int retval;
      PslNode_ptr op = psl_node_get_left(psl);
      nusmv_assert(op != PSL_NULL);

      /* left operand */
      retval = _PRINT("{") && _THROW(psl_node_get_left(op));

      switch (psl_node_get_op(op)) {
      case AND: retval = retval && _PRINT(" & "); break;
      case OR: retval = retval && _PRINT(" | "); break;
      case PSL_AMPERSANDAMPERSAND: retval = retval && _PRINT(" && "); break;
      default:
        ErrorMgr_internal_error(errmgr, "printer_psl_print_node: Unsupported sere "\
                       "compound operator");
      }

      /* right operand */
      return _THROW(psl_node_get_right(op)) && _PRINT("}");
    }

  case PSL_SEREREPEATED:
    {
      int retval;
      PslNode_ptr sere, count;

      nusmv_assert(psl_node_get_left(psl) != PSL_NULL);
      sere = psl_node_get_left(psl_node_get_left(psl));
      count = psl_node_get_right(psl);

      retval = _PRINT("{");
      if (sere != PSL_NULL) retval = retval && _THROW(sere);
      retval = retval && _PRINT("[");

      switch (psl_node_get_op(psl_node_get_left(psl))) {
      case PSL_LBSPLAT: retval = retval && _PRINT("*"); break;
      case PSL_LBPLUSRB: retval = retval && _PRINT("+"); break;
      case PSL_LBEQ: retval = retval && _PRINT("="); break;
      case PSL_LBMINUSGT: retval = retval && _PRINT("->"); break;
      default:
        ErrorMgr_internal_error(errmgr, "printer_psl_print_node: Unsupported sere "\
                       "repeated operator");
      }

      if (count != PSL_NULL) retval = retval && _THROW(count);
      return retval && _PRINT("]}");
    }

  case PSL_CONCATENATION:
    return _PRINT("{") && \
      _THROW(psl_node_get_left(psl)) && _PRINT("}");

  case PSL_REPLPROP:
    return _PRINT("( ") &&
      _THROW(psl_node_get_left(psl)) && /* replicator */
      _PRINT(" : ") &&
      _THROW(psl_node_get_right(psl)) && /* property */
      _PRINT(" )");

  case PSL_FORALL: /* replicator */
  case PSL_FORANY:
    {
      PslNode_ptr rvs = psl_node_get_replicator_value_set(psl);
      PslNode_ptr rr = psl_node_get_replicator_range(psl);
      int res;

      if (psl_node_get_op(psl) == PSL_FORALL) res = _PRINT("forall ");
      else res = _PRINT("forany ");
      res = res && _THROW(psl_node_get_replicator_id(psl));

      if (rr != PSL_NULL) {
        res = res && _PRINT(" [") && _THROW(rr) && _PRINT("]");
      }

      res = res && _PRINT(" in ");
      if (psl_node_is_boolean_type(rvs)) res = res && _THROW(rvs);
      else {
        res = res && _PRINT("{") && _THROW(rvs) && _PRINT("}");
      }
      return res;
    }


  case PSL_PIPEMINUSGT:
    {
      int res = _PRINT("(") &&
        _THROW(psl_node_get_left(psl_node_get_left(psl))) &&
        _PRINT(" |-> ") && _THROW(psl_node_get_right(psl_node_get_left(psl)));
      /* is it strong? */
      if (psl_node_get_right(psl) != PSL_NULL) res = res && _PRINT("!");
      return res && _PRINT(")");
    }

  case PSL_DIAMONDMINUSGT:
    {
      int res = _PRINT("(") &&
        _THROW(psl_node_get_left(psl_node_get_left(psl))) &&
        _PRINT(" <>-> ") && _THROW(psl_node_get_right(psl_node_get_left(psl)));
      /* is it strong? */
      if (psl_node_get_right(psl) != PSL_NULL) res = res && _PRINT("!");
      return res && _PRINT(")");
    }

  case PSL_PIPEEQGT:
    {
      int res = _PRINT("(") &&
        _THROW(psl_node_get_left(psl_node_get_left(psl))) &&
        _PRINT(" |=> ") && _THROW(psl_node_get_right(psl_node_get_left(psl)));
      /* is it strong? */
      if (psl_node_get_right(psl) != PSL_NULL) res = res && _PRINT("!");
      return res && _PRINT(")");
    }

  case PSL_ALWAYS:
  case PSL_NEVER:
  case PSL_EVENTUALLYBANG:
    {
      int res;
      switch (psl_node_get_op(psl)) {
      case PSL_ALWAYS: res = _PRINT("always "); break;
      case PSL_NEVER: res = _PRINT("never "); break;
      case PSL_EVENTUALLYBANG: res = _PRINT("eventually! "); break;
      default: error_unreachable_code(); /* no other cases */
      }

      if (!psl_node_is_sere(psl_node_get_left(psl))) res = res && _PRINT("(");

      res = res && _THROW(psl_node_get_left(psl));

      if (!psl_node_is_sere(psl_node_get_left(psl))) res = res && _PRINT(")");
      return res;
    }

  case PSL_WITHINBANG:
  case PSL_WITHIN:
  case PSL_WITHINBANG_:
  case PSL_WITHIN_:
    {
      int res;
      switch (psl_node_get_op(psl)) {
      case PSL_WITHINBANG: res = _PRINT("within!"); break;
      case PSL_WITHIN: res = _PRINT("within"); break;
      case PSL_WITHINBANG_: res = _PRINT("within!_"); break;
      case PSL_WITHIN_: res = _PRINT("within_"); break;
      default: error_unreachable_code(); /* no other cases here */
      }

    return res && _PRINT(" (") &&
      _THROW(psl_node_get_left(psl_node_get_left(psl))) &&
      _PRINT(", ") &&
      _THROW(psl_node_get_right(psl_node_get_left(psl))) &&
      _PRINT(") ") && _THROW(psl_node_get_right(psl));
    }

  case PSL_WHILENOTBANG:
  case PSL_WHILENOT:
  case PSL_WHILENOTBANG_:
  case PSL_WHILENOT_:
    {
      int res;
      switch (psl_node_get_op(psl)) {
      case PSL_WHILENOTBANG: res = _PRINT("whilenot!"); break;
      case PSL_WHILENOT: res = _PRINT("whilenot"); break;
      case PSL_WHILENOTBANG_: res = _PRINT("whilenot!_"); break;
      case PSL_WHILENOT_: res = _PRINT("whilenot_"); break;
      default: error_unreachable_code(); /* no other cases here */
      }

    return res && _PRINT(" (") &&
      _THROW(psl_node_get_left(psl)) && _PRINT(") ") &&
      _THROW(psl_node_get_right(psl));

    }

  case PSL_NEXT_EVENT_ABANG:
  case PSL_NEXT_EVENT_A:
  case PSL_NEXT_EVENT_EBANG:
  case PSL_NEXT_EVENT_E:
    {
      int res;
      switch (psl_node_get_op(psl)) {
      case PSL_NEXT_EVENT_ABANG: res = _PRINT("next_event_a!"); break;
      case PSL_NEXT_EVENT_A: res = _PRINT("next_event_a"); break;
      case PSL_NEXT_EVENT_EBANG: res = _PRINT("next_event_e!"); break;
      case PSL_NEXT_EVENT_E: res = _PRINT("next_event_e"); break;
      default: error_unreachable_code(); /* no other cases here */
      }

    return res && _PRINT(" (") &&
      _THROW(psl_node_get_right(psl_node_get_right(psl))) &&
      _PRINT(")") && _PRINT(" [") &&
      _THROW(psl_node_get_left(psl_node_get_right(psl))) &&
      _PRINT("]") && _PRINT(" (") &&
      _THROW(psl_node_get_left(psl)) && _PRINT(")");
    }


  case PSL_NEXT_EVENTBANG:
  case PSL_NEXT_EVENT:
    {
      int res;
      switch (psl_node_get_op(psl)) {
      case PSL_NEXT_EVENTBANG: res = _PRINT("next_event!"); break;
      case PSL_NEXT_EVENT: res = _PRINT("next_event"); break;
      default: error_unreachable_code(); /* no other cases here */
      }

      res = res && _PRINT(" (") &&
        _THROW(psl_node_get_right(psl_node_get_right(psl))) &&
        _PRINT(")");

      if (psl_node_get_left(psl_node_get_right(psl)) != PSL_NULL) {
        res = res && _PRINT(" [") &&
          _THROW(psl_node_get_left(psl_node_get_right(psl))) &&
          _PRINT("]");
      }

      return res && _PRINT(" (") &&
        _THROW(psl_node_get_left(psl)) && _PRINT(")");
    }

  case PSL_NEXT_ABANG:
  case PSL_NEXT_EBANG:
  case PSL_NEXT_A:
  case PSL_NEXT_E:
  case PSL_NEXTBANG:
  case PSL_NEXT:
    {
      int res;
      switch (psl_node_get_op(psl)) {
      case PSL_NEXT_ABANG: res = _PRINT("next_a!"); break;
      case PSL_NEXT_EBANG: res = _PRINT("next_e!"); break;
      case PSL_NEXT_A: res = _PRINT("next_a"); break;
      case PSL_NEXT_E: res = _PRINT("next_e"); break;
      case PSL_NEXTBANG: res = _PRINT("next!"); break;
      case PSL_NEXT: res = _PRINT("next"); break;
      default: error_unreachable_code(); /* no other cases here */
      }

      if (psl_node_get_right(psl) != PSL_NULL &&
          psl_node_get_left(psl_node_get_right(psl)) != PSL_NULL) {
        res = res && _PRINT(" [") &&
          _THROW(psl_node_get_left(psl_node_get_right(psl))) &&
          _PRINT("]");
      }

      return res && _PRINT(" (") &&
        _THROW(psl_node_get_left(psl)) && _PRINT(")");
    }

  case PSL_RANGE:
    return _THROW(psl_node_get_left(psl)) && _PRINT(":") &&
      _THROW(psl_node_get_right(psl));

    /* binary operators */
  case PSL_BEFOREBANG:
  case PSL_BEFORE:
  case PSL_BEFOREBANG_:
  case PSL_BEFORE_:
  case PSL_UNTILBANG:
  case PSL_UNTIL:
  case PSL_UNTILBANG_:
  case PSL_UNTIL_:
  case PSL_ABORT:
  case PSL_W:
  case PSL_OR:
  case PSL_CARET:
  case PSL_TILDE:
  case PSL_EQEQ:
  case PSL_PIPEPIPE:
  case PSL_AMPERSANDAMPERSAND:
    {
      int res;

      res = _PRINT("(") && _THROW(psl_node_get_left(psl)) && _PRINT(" ");

      switch (psl_node_get_op(psl)) {
      case PSL_BEFOREBANG: res = res && _PRINT("before!"); break;
      case PSL_BEFORE: res = res && _PRINT("before"); break;
      case PSL_BEFOREBANG_: res = res && _PRINT("before!_"); break;
      case PSL_BEFORE_: res = res && _PRINT("before_"); break;
      case PSL_UNTILBANG: res = res && _PRINT("until!"); break;
      case PSL_UNTIL: res = res && _PRINT("until"); break;
      case PSL_UNTILBANG_: res = res && _PRINT("until!_"); break;
      case PSL_UNTIL_: res = res && _PRINT("until_"); break;
      case PSL_ABORT:  res = res && _PRINT("abort"); break;
      case PSL_W: res = res && _PRINT("W"); break;
      case PSL_OR: res = res && _PRINT("or"); break;
      case PSL_CARET: res = res && _PRINT("^"); break;
      case PSL_TILDE: res = res && _PRINT("~"); break;
      case PSL_EQEQ: res = res && _PRINT("=="); break;
      case PSL_PIPEPIPE: res = res && _PRINT("||"); break;
      case PSL_AMPERSANDAMPERSAND: res = res && _PRINT("&&"); break;
      default: error_unreachable_code(); /* no other cases here */
      }

      return _PRINT(" ") && _THROW(psl_node_get_right(psl)) && _PRINT(")");
    }

  case PSL_X:
  case PSL_XBANG:
    {
      int res;

      switch (psl_node_get_op(psl)) {
      case PSL_X: res = _PRINT("X"); break;
      case PSL_XBANG: res = _PRINT("X!"); break;
      default: error_unreachable_code(); /* no other cases here */
      }

      if (psl_node_get_right(psl) != PSL_NULL) { /* simple next expression */
        res = res && _PRINT(" [") &&
          _THROW(psl_node_get_left(psl_node_get_right(psl))) && _PRINT("] ");
      }

      return res && _PRINT("(") &&
        _THROW(psl_node_get_left(psl)) && _PRINT(")");
    }

  case PSL_ITE:
      return _THROW(psl_node_get_ite_cond(psl)) &&
        _PRINT(" ? ") &&
        _THROW(psl_node_get_ite_then(psl)) && _PRINT(" : ") &&
        _THROW(psl_node_get_ite_else(psl));

  case PSL_WSELECT:
    return _PRINT("select(") &&
      _THROW(psl_node_get_left(psl)) &&
      _PRINT(", ") &&
      _THROW(psl_node_get_left(psl_node_get_right(psl))) &&
      _PRINT(", ") &&
      _THROW(psl_node_get_right(psl_node_get_right(psl))) &&
      _PRINT(")");
  default:
    ErrorMgr_internal_error(errmgr, "printer_psl_print_node: not supported type");
  }

  return 0;
}
Ejemplo n.º 21
0
cf_void  SysVShM::Remove()
{
    if(-1==cf_shmctl(_shmid, IPC_RMID, NULL))
        _THROW(SyscallExecuteError, "Failed to execute cf_shmctl !");
}
Ejemplo n.º 22
0
/**Function********************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
static SymbType_ptr checker_psl_check_expr(CheckerBase_ptr self,
                                           node_ptr e, node_ptr ctx)
{
  /* converts and operates on PslNodes, not node_ptr: */
  PslNode_ptr expr = PslNode_convert_from_node_ptr(e);
  PslNode_ptr context = PslNode_convert_from_node_ptr(ctx);

  PslNode_ptr ctx_expr;

  /* wrap expr into the context. This is required by
     the facilities which remembers the type of expressions
     and by the violation handler. */
  if (context != PSL_NULL) {
    ctx_expr = PslNode_new_context(psl_node_context_to_main_context(context),
                                   expr);
  }
  else ctx_expr = expr;

  { /* checks memoizing */
    SymbType_ptr tmp = _GET_TYPE(ctx_expr);
    if (nullType != tmp) return tmp;
  }

  switch (psl_node_get_op(expr)) {
  case PSL_INF: return _SET_TYPE(ctx_expr, SymbTablePkg_integer_set_type());

  case PSL_SERE:
  case PSL_SERECOMPOUND:
    {
      SymbType_ptr type = _THROW(psl_node_get_left(expr), context);

      if (SymbType_is_error(type)) {
        /* earlier error */
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      if (SymbType_is_boolean(type)) return _SET_TYPE(ctx_expr, type);

      /* there is violation */
      if (_VIOLATION(SymbType_is_back_comp(type) ?
                     TC_VIOLATION_TYPE_BACK_COMP : TC_VIOLATION_TYPE_MANDATORY,
                     ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }


      /* keeps the current type */
      return _SET_TYPE(ctx_expr, type);
    }

    /* concatenation and multiple concatenation */
  case PSL_CONCATENATION:
    {
      PslNode_ptr iter;
      SymbType_ptr left = SYMB_TYPE(NULL);
      SymbType_ptr right = SYMB_TYPE(NULL);
      boolean is_ok = true;

      if (psl_node_get_right(expr) != PSL_NULL) {
        /* multiple concatenation */
        right = _THROW(psl_node_get_right(expr), context);
        if (SymbType_is_error(right)) {
          return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
        }

        if (!SymbType_is_boolean(right)) {
          if (_VIOLATION(SymbType_is_back_comp(right) ?
                         TC_VIOLATION_TYPE_BACK_COMP :
                         TC_VIOLATION_TYPE_MANDATORY,
                         ctx_expr)) {
            return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
          }
        }
      }

      /* checks all the list's elements */
      iter = psl_node_get_left(expr);
      while (is_ok && iter != PSL_NULL) {
        left = _THROW(psl_node_get_left(iter), context);
        if (SymbType_is_error(left)) {
          return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
        }

        is_ok = SymbType_is_boolean(left);
        iter = psl_node_get_right(iter);
      }

      if (!is_ok && _VIOLATION(SymbType_is_back_comp(left) ?
                               TC_VIOLATION_TYPE_BACK_COMP :
                               TC_VIOLATION_TYPE_MANDATORY,
                               ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }

  case PSL_SERECONCAT:
  case PSL_SEREFUSION:
    {
      SymbType_ptr type1 = _THROW(psl_node_get_left(expr), context);
      SymbType_ptr type2 = _THROW(psl_node_get_right(expr), context);


      if (SymbType_is_error(type1) || SymbType_is_error(type2)) {
        /* earlier error */
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      if (SymbType_is_boolean(type1) && SymbType_is_boolean(type2)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
      }

      /* there is violation */
      if (_VIOLATION(SymbType_is_back_comp(type1) &&
                     SymbType_is_back_comp(type2)?
                     TC_VIOLATION_TYPE_BACK_COMP : TC_VIOLATION_TYPE_MANDATORY,
                     ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }


  case PSL_SEREREPEATED:
    {
      PslNode_ptr sere, count;
      boolean is_ok = true;
      SymbType_ptr tcount = SYMB_TYPE(NULL);
      SymbType_ptr tsere;

      nusmv_assert(psl_node_get_left(expr) != PSL_NULL);
      sere = psl_node_sere_repeated_get_expr(expr);
      count = psl_node_sere_repeated_get_count(expr);

      /* checks the count at first: */
      if (count != PSL_NULL) {
        tcount = _THROW(count, context);

        if (SymbType_is_error(tcount)) return _SET_TYPE(ctx_expr, tcount);
        if (tcount != SymbTablePkg_integer_type() &&
            tcount != SymbTablePkg_boolean_type()) {
          is_ok = false;
        }
      }

      /* checks the sere now: */
      if (sere != PSL_NULL && is_ok) {
        tsere = _THROW(sere, context);
        if (SymbType_is_error(tsere)) {
          return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
        }

        if (SymbType_is_boolean(tsere)) {
          /* ok */
          return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
        }
      }
      else tsere = SymbTablePkg_error_type();

      /* is this a type error ? */
      if (!is_ok && _VIOLATION(SymbType_is_back_comp(tcount) &&
                               SymbType_is_back_comp(tsere) ?
                               TC_VIOLATION_TYPE_BACK_COMP :
                               TC_VIOLATION_TYPE_MANDATORY,
                               ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }


  case PSL_REPLPROP:
    {
      SymbTable_ptr symb_table =
        TypeChecker_get_symb_table(TYPE_CHECKER(NODE_WALKER(self)->master));

      PslNode_ptr repl = psl_node_repl_prop_get_replicator(expr);
      PslNode_ptr prop = psl_node_repl_prop_get_property(expr);
      PslNode_ptr value_set = psl_node_get_replicator_value_set(repl);
      PslNode_ptr evalue_set =
        psl_node_get_replicator_normalized_value_set(repl);
      PslNode_ptr id = psl_node_get_replicator_id(repl);
      boolean first_loop = true;
      ResolveSymbol_ptr rs;
      node_ptr id_ctx;

      rs = SymbTable_resolve_symbol(symb_table,
                            PslNode_convert_to_node_ptr(id), ctx);
      id_ctx = ResolveSymbol_get_resolved_name(rs);

      /* Prepares the forall value set */
      if (!psl_node_is_boolean_type(value_set)) {
        /* not boolean checks the value_set content */
        SymbType_ptr tvs = SymbType_create(SYMB_TYPE_ENUM, evalue_set);
        if (!TypeChecker_is_type_wellformed(
                                    TYPE_CHECKER(NODE_WALKER(self)->master),
                                    tvs, id_ctx)) {
          return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
        }
      }

      /* loops over the set of possible values of the ID, and defines
         a new define for each value. Then checks the replicated
         property */
      while (evalue_set != PSL_NULL) {
        SymbType_ptr prop_type;
        boolean is_ok = true;

        /* creates a new temporary layer to contain the id as input var */
        SymbLayer_ptr layer =
          SymbTable_create_layer(symb_table, NULL, SYMB_LAYER_POS_DEFAULT);

        /* checks the forall identifier: */
        if (!SymbLayer_can_declare_define(layer, id_ctx)) {
          _VIOLATION(TC_VIOLATION_AMBIGUOUS_IDENTIFIER, id);
          return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
        }

        /* declares a new temporary define to represent the id */
        SymbLayer_declare_define(layer, id_ctx, ctx,
                         PslNode_convert_to_node_ptr(
                             psl_node_cons_get_element(evalue_set)));


        /* now checks the replicated property: */
        prop_type = _THROW(prop, context);
        if (SymbType_is_error(prop_type)) {
          return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
        }

        is_ok = SymbType_is_boolean(prop_type);

        /* handle violation */
        if (!is_ok && _VIOLATION(SymbType_is_back_comp(prop_type) ?
                                 TC_VIOLATION_TYPE_BACK_COMP :
                                 TC_VIOLATION_TYPE_MANDATORY,
                                 ctx_expr)) {
          return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
        }

        /* gets rid of the temporary layer: */
        SymbTable_remove_layer(symb_table, layer);

        /* Disables memoizing, to force checking of the property event
           if already checked, as the property that is going to be
           checked at next iteration is grammatically identically to
           the one that is being checked, but contain different value
           for the forall ID */
        if (first_loop) {
          type_checker_enable_memoizing(
                TYPE_CHECKER(NODE_WALKER(self)->master), false);
          first_loop = false;
        }

        evalue_set = psl_node_cons_get_next(evalue_set); /* iterates on */
      } /* loop over forall range */

      /* re-enables memoizing. The property has already been memoized
         during the first loop iteration */
      type_checker_enable_memoizing(TYPE_CHECKER(NODE_WALKER(self)->master),
                                    true);

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }

    case PSL_WSELECT:
      {
        SymbTable_ptr symb_table =
          TypeChecker_get_symb_table(TYPE_CHECKER(NODE_WALKER(self)->master));

        PslNode_ptr left = psl_node_get_left(expr);
        PslNode_ptr right = psl_node_get_right(expr);
        /* get the operand' type */
        SymbType_ptr type = _THROW(left, context);

        node_ptr hbit, lbit;
        int width;
        int highBound;
        int lowBound;

        if (SymbType_is_error(type)) { /* earlier error */
          return _SET_TYPE(ctx_expr, type);
        }

        hbit = PslNode_convert_to_node_ptr(psl_node_get_left(right));
        lbit = PslNode_convert_to_node_ptr(psl_node_get_right(right));

        hbit = CompileFlatten_resolve_number(symb_table, hbit, context);
        lbit = CompileFlatten_resolve_number(symb_table, lbit, context);

        nusmv_assert(COLON == psl_node_get_op(right));

        /* Non constant expressions for range */
        if ((Nil == hbit || Nil == lbit) ||
            (NUMBER != node_get_type(hbit) || NUMBER != node_get_type(lbit))) {
          if (_VIOLATION(TC_VIOLATION_UNCONSTANT_EXPRESSION, ctx_expr)) {
            return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
          }
          else { /* return arbitrary Word type */
            return _SET_TYPE(ctx_expr, SymbTablePkg_unsigned_word_type(1));
          }
        }

        /* check the first operand type */
        if (!SymbType_is_word(type)) { /* ERROR */
          if (_VIOLATION(TC_VIOLATION_TYPE_MANDATORY, ctx_expr)) {
            return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
          }
          else { /* return arbitrary Word type */
            return _SET_TYPE(ctx_expr, SymbTablePkg_unsigned_word_type(1));
          }
        }
        width = SymbType_get_word_width(type);
        highBound = NODE_TO_INT(car(hbit));
        lowBound  = NODE_TO_INT(car(lbit));

        /* checks the bit width */
        if (width <= highBound || highBound < lowBound || lowBound < 0) {
          /* ERROR */
          if (_VIOLATION(TC_VIOLATION_OUT_OF_WORD_WIDTH, ctx_expr)) {
            return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
          }
          else { /* give some realistic bit specifiers */
            highBound = 0;
            lowBound = 0;
          }
        }
        /* everything is OK */
        return _SET_TYPE(ctx_expr,
                         SymbTablePkg_unsigned_word_type(highBound - lowBound + 1));
      }

  case PSL_PIPEMINUSGT:
  case PSL_PIPEEQGT:
    {
      PslNode_ptr pre = psl_node_suffix_implication_get_premise(expr);
      PslNode_ptr con = psl_node_suffix_implication_get_consequence(expr);
      SymbType_ptr type1 = _THROW(pre, context);
      SymbType_ptr type2 = _THROW(con, context);

      if (SymbType_is_error(type1) || SymbType_is_error(type2)) {
        /* earlier error */
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      if (SymbType_is_boolean(type1) && SymbType_is_boolean(type2)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
      }

      /* there is violation */
      if (_VIOLATION(SymbType_is_back_comp(type1) &&
                     SymbType_is_back_comp(type2)?
                     TC_VIOLATION_TYPE_BACK_COMP : TC_VIOLATION_TYPE_MANDATORY,
                     ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }


  case PSL_ALWAYS:
  case PSL_NEVER:
  case PSL_EVENTUALLYBANG:
    {
      SymbType_ptr type = _THROW(psl_node_get_left(expr), context);

      if (SymbType_is_error(type)) {
        /* earlier error */
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      if (SymbType_is_boolean(type)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
      }

      /* there is violation */
      if (_VIOLATION(SymbType_is_back_comp(type) ?
                     TC_VIOLATION_TYPE_BACK_COMP : TC_VIOLATION_TYPE_MANDATORY,
                     ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }


  case PSL_WITHINBANG:
  case PSL_WITHIN:
  case PSL_WITHINBANG_:
  case PSL_WITHIN_:
    {
      PslNode_ptr n1 = psl_node_get_left(psl_node_get_left(expr));
      PslNode_ptr n2 = psl_node_get_right(psl_node_get_left(expr));
      PslNode_ptr n3 = psl_node_get_right(expr);

      SymbType_ptr t1 = _THROW(n1, context);
      SymbType_ptr t2 = _THROW(n2, context);
      SymbType_ptr t3 = _THROW(n3, context);

      if (SymbType_is_error(t1) || SymbType_is_error(t2) ||
          SymbType_is_error(t3) ) {
        /* earlier error */
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      if (SymbType_is_boolean(t1) && SymbType_is_boolean(t2) &&
          SymbType_is_boolean(t3)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
      }

      /* there is violation */
      if (_VIOLATION(SymbType_is_back_comp(t1) &&
                     SymbType_is_back_comp(t2) && SymbType_is_back_comp(t3) ?
                     TC_VIOLATION_TYPE_BACK_COMP : TC_VIOLATION_TYPE_MANDATORY,
                     ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }


  case PSL_NEXT_EVENT_ABANG:
  case PSL_NEXT_EVENT_A:
  case PSL_NEXT_EVENT_EBANG:
  case PSL_NEXT_EVENT_E:
  case PSL_NEXT_EVENTBANG:
  case PSL_NEXT_EVENT:
  case PSL_NEXT_ABANG:
  case PSL_NEXT_EBANG:
  case PSL_NEXT_A:
  case PSL_NEXT_E:
  case PSL_NEXTBANG:
  case PSL_NEXT:
  case PSL_X:
  case PSL_XBANG:
    {
      PslNode_ptr n1 = psl_node_extended_next_get_expr(expr);
      PslNode_ptr n2 = psl_node_extended_next_get_when(expr);
      PslNode_ptr n3 = psl_node_extended_next_get_condition(expr);

      SymbType_ptr t1 = _THROW(n1, context);

      SymbType_ptr t2 =
        (n2 != PSL_NULL) ? _THROW(n2, context) : SYMB_TYPE(NULL);

      SymbType_ptr t3 =
        (n3 != PSL_NULL) ? _THROW(n3, context) : SYMB_TYPE(NULL);

      if (SymbType_is_error(t1) ||
          (t2 != SYMB_TYPE(NULL) && SymbType_is_error(t2)) ||
          (t3 != SYMB_TYPE(NULL) && SymbType_is_error(t3))) {
        /* earlier error */
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      if (SymbType_is_boolean(t1) &&
          (t3 == SYMB_TYPE(NULL) || SymbType_is_boolean(t3))) {
        switch (psl_node_get_op(expr)) {
        case PSL_NEXTBANG:
        case PSL_NEXT:
        case PSL_X:
        case PSL_XBANG:
          /* number */
          if ((t2 == SYMB_TYPE(NULL)) ||
              ((SymbType_get_tag(t2) == SYMB_TYPE_INTEGER ||
                SymbType_is_pure_int_enum(t2) ||
                SymbType_is_boolean(t2)) &&
               psl_node_number_get_value(n2) >= 0)) {
            return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
          }
          break;

        case PSL_NEXT_ABANG:
        case PSL_NEXT_EBANG:
        case PSL_NEXT_A:
        case PSL_NEXT_E:
          /* finite range */
          if (t2 == SYMB_TYPE(NULL)) {
            return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
          }

          if (SymbType_get_tag(t2) == SYMB_TYPE_SET_INT) {
            PslNode_ptr low = psl_node_range_get_low(n2);
            PslNode_ptr high = psl_node_range_get_high(n2);
            if (!psl_node_is_infinite(high) &&
                psl_node_number_get_value(low) >= 0 &&
                psl_node_number_get_value(low) <= psl_node_number_get_value(high)) {
              return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
            }
          }
          break;


        case PSL_NEXT_EVENT_ABANG:
        case PSL_NEXT_EVENT_A:
        case PSL_NEXT_EVENT_EBANG:
        case PSL_NEXT_EVENT_E:
          /* finite positive range */
          if (t2 == SYMB_TYPE(NULL)) {
            return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
          }

          if (SymbType_get_tag(t2) == SYMB_TYPE_SET_INT) {
            PslNode_ptr low = psl_node_range_get_low(n2);
            PslNode_ptr high = psl_node_range_get_high(n2);
            if (!psl_node_is_infinite(high) &&
                psl_node_number_get_value(low) > 0 &&
                psl_node_number_get_value(low) <= psl_node_number_get_value(high)) {
              return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
            }
          }
          break;

        case PSL_NEXT_EVENTBANG:
        case PSL_NEXT_EVENT:
          /* positive number */
          if ((t2 == SYMB_TYPE(NULL)) ||
              ((SymbType_get_tag(t2) == SYMB_TYPE_INTEGER ||
                SymbType_is_pure_int_enum(t2) ||
                SymbType_is_boolean(t2)) &&
               psl_node_number_get_value(n2) > 0)) {
            return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
          }
          break;

        default:
          error_unreachable_code(); /* no other cases */
        }
      }

      /* there is violation */
      if (_VIOLATION(SymbType_is_back_comp(t1) &&
                     (t2 == SYMB_TYPE(NULL) || SymbType_is_back_comp(t2)) &&
                     (t3 == SYMB_TYPE(NULL) || SymbType_is_back_comp(t3)) ?
                     TC_VIOLATION_TYPE_BACK_COMP : TC_VIOLATION_TYPE_MANDATORY,
                     ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }


  case PSL_RANGE:
    /* colon is used only for index ranges */
    return _SET_TYPE(ctx_expr, SymbTablePkg_integer_set_type());


    /* binary operators */
  case PSL_BEFOREBANG:
  case PSL_BEFORE:
  case PSL_BEFOREBANG_:
  case PSL_BEFORE_:
  case PSL_UNTILBANG:
  case PSL_UNTIL:
  case PSL_UNTILBANG_:
  case PSL_UNTIL_:
  case PSL_ABORT:
  case PSL_W:
  case PSL_OR:
  case PSL_CARET:
  case PSL_TILDE:
  case PSL_EQEQ:
  case PSL_PIPEPIPE:
  case PSL_AMPERSANDAMPERSAND:
  case PSL_WHILENOTBANG:
  case PSL_WHILENOT:
  case PSL_WHILENOTBANG_:
  case PSL_WHILENOT_:
    {
      SymbType_ptr type1 = _THROW(psl_node_get_left(expr), context);
      SymbType_ptr type2 = _THROW(psl_node_get_right(expr), context);


      if (SymbType_is_error(type1) || SymbType_is_error(type2)) {
        /* earlier error */
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      if (SymbType_is_boolean(type1) && SymbType_is_boolean(type2)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
      }

      /* there is violation */
      if (_VIOLATION(SymbType_is_back_comp(type1) &&
                     SymbType_is_back_comp(type2)?
                     TC_VIOLATION_TYPE_BACK_COMP : TC_VIOLATION_TYPE_MANDATORY,
                     ctx_expr)) {
        return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
      }

      /* this is not an error after all -> return boolean type */
      return _SET_TYPE(ctx_expr, SymbTablePkg_boolean_type());
    }


  case PSL_ITE:
  {
    /* get the operands' type */
    SymbType_ptr returnType;
    SymbType_ptr condType = _THROW(psl_node_get_ite_cond(expr), context);
    SymbType_ptr thenType = _THROW(psl_node_get_ite_then(expr), context);
    SymbType_ptr elseType = _THROW(psl_node_get_ite_else(expr), context);

    if (SymbType_is_error(condType) ||
        SymbType_is_error(thenType) || SymbType_is_error(elseType)) {
      /* earlier error */
      return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
    }

   /* condition should be boolean */
    if ( (!SymbType_is_boolean(condType)) &&
         _VIOLATION(SymbType_is_back_comp(condType) ?
                    TC_VIOLATION_TYPE_BACK_COMP :
                    TC_VIOLATION_TYPE_MANDATORY,
                    expr) ) {
      return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
    }

    /* both ITE expressions should be convertable to a common type.
       If one of the expressions is of a set-type then before implicit
       convertion the other expression is converted to a corresponding
       set-type.
    */
    {
      SymbType_ptr tmp1 = SymbType_is_set(elseType) ?
        SymbType_make_set_type(thenType) : thenType;

      SymbType_ptr tmp2 = SymbType_is_set(thenType) ?
        SymbType_make_set_type(elseType) : elseType;

      if (nullType != tmp1 && nullType != tmp2) {
        returnType = SymbType_get_minimal_common(tmp1, tmp2);
      }
      else returnType = nullType;
    }

    /* we do not care which type exactly is obtained, since only
       correct type could pass the above code
    */
    if (nullType != returnType) {
      return _SET_TYPE(ctx_expr, returnType);
    }

    /* is this a type error ? */
    if (_VIOLATION(SymbType_is_back_comp(thenType) &&
                   SymbType_is_back_comp(elseType) ?
                   TC_VIOLATION_TYPE_BACK_COMP :
                   TC_VIOLATION_TYPE_MANDATORY,
                   expr)) {
      return _SET_TYPE(ctx_expr, SymbTablePkg_error_type());
    }

    /* this is not an error after all -> return one of the types  */
    return _SET_TYPE(ctx_expr, thenType);
  }

  default:
    internal_error("checker_psl_check_expr: not supported type");
  }

  return nullType;
}
Ejemplo n.º 23
0
    cf_void OnReadComplete(cf::T_SESSION session,
                           std::shared_ptr < cl::ReadBuffer > readBuffer)
    {
        CF_PRINT_FUNC;
#if 1
        fprintf (stderr, "OnReadComplete,fd=%d,addr=%s,total()=%d,buf=%s \n",
                 session->Fd(),session->Addr().c_str(),readBuffer->GetTotal(),
                 (cf_char *)(readBuffer->GetBuffer()));
#endif
        TYPE_TID_CLIENTFD::const_iterator it =g_tid_fd.begin();
        bool found =false;
        for(;it!=g_tid_fd.end();it++)
        {
            printf( "for,tid=%u,fd=%d g_tid_fd.size()=%u\n",(cf_uint32)(it->first),it->second, (cf_uint32)(g_tid_fd.size()) );
            if(it->second==session->Fd())
            {
                found =true;
                break;
            }
        }
        if(found)
        {
            printf( "is db query. \n" );
            QueueElement qeOut =g_outQueue[_tid].Get();
            int clientfd =qeOut.fd;
            std::string output_data =qeOut.pack;
            
            AsyncWrite(clientfd, output_data.c_str(), output_data.size());           
            return;
        }
        printf( "recv query request \n" );
        
        cf_uint32 totalLen =readBuffer->GetTotal();
        if(_recvHeader[session->Fd()])
        {
            if(_headLen!=totalLen)
            {
                fprintf (stderr, "OnReadComplete,fd=%d,_headLen{%u}!=totalLen{%u} \n",
                        session->Fd(),_headLen,totalLen);
            }
            else
            {
                cf_uint32 * p =(cf_uint32 *)(readBuffer->GetBuffer());
                cf_uint32 size =ntohl(*p);
                _recvHeader[session->Fd()] =false;
                if(size>0)
                    AsyncRead(session->Fd(), size);
                else
                    _THROW(cf::ValueError, "size==0 !");
            }
        }
        else
        {
            _recvHeader[session->Fd()] =true;
            //AsyncWrite(session->Fd(), readBuffer->GetBuffer(), totalLen);
            std::string packet((const char*)(readBuffer->GetBuffer()), size_t(totalLen));
            QueueElement qe;
            qe.fd =session->Fd();
            qe.pack =packet;
            g_inQueue[g_tid_pipe[_tid]].Put(qe);
            AsyncRead(session->Fd(), _headLen);
        }
    }