Пример #1
0
int main(void) {
    type_t tau;

    init_type_table(&types, 0);
    init_variables();
    init_types();

    // pair(A) = (tuple A A)
    tau = pair_type(var[0], var[0]);
    test_macro("pair", 1, var, tau);

    // triple(B) = (tuple B B B)
    tau = triple_type(var[1], var[1], var[1]);
    test_macro("triple", 1, var+1, tau);

    // test(C, D) = bool
    test_macro("test", 2, var+2, base[0]);

    // fun(E, F) = (-> (tuple E E) F)
    tau = pair_type(var[4], var[4]);
    tau = function_type(&types, var[5], 1, &tau);
    test_macro("fun", 2, var+4, tau);

    // two constructors
    test_constructor("mk_type2", 2);
    test_constructor("mk_type3", 3);

    printf("\n====== TYPES ========\n");
    print_type_table(stdout, &types);
    printf("\n===== MACROS ========\n");
    print_type_macros(stdout, &types);
    printf("===\n\n");

    // creation after remove
    // vector[G] = (-> int G)
    tau = int_type(&types);
    tau = function_type(&types, var[6], 1, &tau);
    test_macro("vector", 1, var+6, tau);

    // matrix[H] = (-> int int H)
    tau = int_type(&types);
    tau = binary_ftype(tau, tau, var[7]);
    test_macro("matrix", 1, var+7, tau);

    printf("\n====== TYPES ========\n");
    print_type_table(stdout, &types);
    printf("\n===== MACROS ========\n");
    print_type_macros(stdout, &types);
    printf("===\n\n");

    delete_type_table(&types);

    return 0;
}
Пример #2
0
void CDatabaseItem::refreshWidget(bool b)
{
#ifdef DEBUG
  qDebug("CDatabaseItem::refreshWidget(%s)", debug_string(booltostr(b)));
#endif

  if (isBlocked())
    return;
  setBlocked(true);

  if (widget_id == int_type())
  {
    CShowDatabaseGroupProperties * w = (CShowDatabaseGroupProperties *) widgetStack()->widget(int_type());
    w->setMySQL(mysql());
    w->setTitle(mysql()->connectionName());
    if (b || widgetData.isEmpty())
    {
      w->refresh();
      w->saveData(&widgetData);
    }
    else
      w->loadData(widgetData);
  }
  else
    ((CDatabaseListViewItem *) QListViewItem::parent())->refreshWidget(b);
  widgetStack()->raiseWidget(widget_id);
  setBlocked(false);
}
Пример #3
0
static void init_base_types(void) {
  base[0] = bool_type(&types);               // bool
  base[1] = bv_type(&types, 5);              // bv5
  base[2] = new_scalar_type(&types, 3);      // scalar3
  base[3] = new_scalar_type(&types, 1);      // scalar1
  base[4] = pair_type(base[0], base[2]);     // bool x scalar3
  base[5] = pair_type(base[3], base[0]);     // scalar1 x bool
  base[6] = fun_type1(base[0], base[2]);     // [bool -> scalar3]
  base[7] = fun_type1(base[0], base[3]);     // [bool -> scalar1]
  base[8] = fun_type1(base[2], base[0]);     // [scalar3 -> bool]
  base[9] = fun_type1(base[3], base[0]);     // [scalar1 -> bool]
  base[10] = fun_type1(base[0], base[0]);    // [bool -> bool]
  base[11] = fun_type1(base[10], base[0]);   // [[bool -> bool] -> bool]

  // some infinite types
  base[12] = new_uninterpreted_type(&types);
  base[13] = real_type(&types);
  base[14] = int_type(&types);
  base[15] = fun_type1(base[14], base[0]);          // [int -> bool]
  base[16] = fun_type2(base[0], base[0], base[14]); // [bool, bool -> int]

  // larger finite types
  base[17] = pair_type(base[1], base[1]);   // bv5 x bv5
  base[18] = bv_type(&types, 40);           // bv40

  // infinite domain, unit range
  base[19] = fun_type1(base[13], base[3]);  // [real -> scalar1]
}
Пример #4
0
void c_typecastt::implicit_typecast_arithmetic(
  exprt &expr,
  c_typet c_type)
{
  typet new_type;
  
  const typet &expr_type=ns.follow(expr.type());
  
  switch(c_type)
  {
  case PTR:
    if(expr_type.id()==ID_array)
    {
      new_type.id(ID_pointer);
      new_type.subtype()=expr_type.subtype();
      break;
    }
    return;

  case BOOL:       new_type=bool_typet(); break;
  case CHAR:       assert(false); // should always be promoted to int
  case UCHAR:      assert(false); // should always be promoted to int
  case SHORT:      assert(false); // should always be promoted to int
  case USHORT:     assert(false); // should always be promoted to int
  case INT:        new_type=int_type(); break;
  case UINT:       new_type=uint_type(); break;
  case LONG:       new_type=long_int_type(); break;
  case ULONG:      new_type=long_uint_type(); break;
  case LONGLONG:   new_type=long_long_int_type(); break;
  case ULONGLONG:  new_type=long_long_uint_type(); break;
  case SINGLE:     new_type=float_type(); break;
  case DOUBLE:     new_type=double_type(); break;
  case LONGDOUBLE: new_type=long_double_type(); break;
  case RATIONAL:   new_type=rational_typet(); break;
  case REAL:       new_type=real_typet(); break;
  case INTEGER:    new_type=integer_typet(); break;
  case COMPLEX: return; // do nothing
  default: return;
  }

  if(new_type!=expr_type)
  {
    if(new_type.id()==ID_pointer &&
       expr_type.id()==ID_array)
    {
      exprt index_expr(ID_index, expr_type.subtype());
      index_expr.reserve_operands(2);
      index_expr.move_to_operands(expr);
      index_expr.copy_to_operands(gen_zero(index_type()));
      expr=exprt(ID_address_of, new_type);
      expr.move_to_operands(index_expr);
    }
    else
      do_typecast(expr, new_type);
  }
}
Пример #5
0
hdf5_iprimitive::read_hdf5_dataset
(
    unsigned int* t,
    std::size_t data_count,
    std::size_t object_number
)
{
    hdf5_datatype int_type(H5T_NATIVE_UINT);
    read_dataset_basic(t, data_count, int_type, object_number);
}
Пример #6
0
strstreambuf::int_type
strstreambuf::overflow(int_type __c)
{
    if (__c == EOF)
        return int_type(0);
    if (pptr() == epptr())
    {
        if ((__strmode_ & __dynamic) == 0 || (__strmode_ & __frozen) != 0)
            return int_type(EOF);
        size_t old_size = static_cast<size_t> ((epptr() ? epptr() : egptr()) - eback());
        size_t new_size = max<size_t>(static_cast<size_t>(__alsize_), 2*old_size);
        if (new_size == 0)
            new_size = __default_alsize;
        char* buf = nullptr;
        if (__palloc_)
            buf = static_cast<char*>(__palloc_(new_size));
        else
            buf = new char[new_size];
        if (buf == nullptr)
            return int_type(EOF);
        if (old_size != 0) {
            _LIBCPP_ASSERT(eback(), "overflow copying from NULL");
            memcpy(buf, eback(), static_cast<size_t>(old_size));
        }
        ptrdiff_t ninp = gptr()  - eback();
        ptrdiff_t einp = egptr() - eback();
        ptrdiff_t nout = pptr()  - pbase();
        if (__strmode_ & __allocated)
        {
            if (__pfree_)
                __pfree_(eback());
            else
                delete [] eback();
        }
        setg(buf, buf + ninp, buf + einp);
        setp(buf + einp, buf + new_size);
        pbump(static_cast<int>(nout));
        __strmode_ |= __allocated;
    }
    *pptr() = static_cast<char>(__c);
    pbump(1);
    return int_type(static_cast<unsigned char>(__c));
}
Пример #7
0
hdf5_oprimitive::write_hdf5_dataset
(
    unsigned int const* t,
    std::size_t data_count,
    std::size_t object_number
)
{
    hdf5_datatype int_type(H5T_NATIVE_UINT);
    write_dataset_basic(t, data_count, int_type, object_number);
}
Пример #8
0
 IntLiteral (Token _token, std::string _value) : Expression(_token, nullptr, Kind::IntLit, nullptr) {
     // TODO: parse prefix, suffix, set value and type
     toupper(_value);
     bool positive = num_is_positive(_value);
     int base = int_base(_value);
     type = std::unique_ptr<Type>(new BaseType(_token, int_type(_value)));
     value = int_value(base, _value);
     if (!positive) {
         value = -value;
     }
 }
strstreambuf::int_type
strstreambuf::underflow()
{
    if (gptr() == egptr())
    {
        if (egptr() >= pptr())
            return EOF;
        setg(eback(), gptr(), pptr());
    }
    return int_type(static_cast<unsigned char>(*gptr()));
}
Пример #10
0
BOOST_ARCHIVE_OR_WARCHIVE_DECL void
hdf5_oprimitive::write_hdf5_dataset
(
    int const* t,
    std::size_t data_count,
    std::size_t object_number
)
{
    hdf5_datatype int_type(H5T_NATIVE_INT);
    write_dataset_basic(t, data_count, int_type, object_number);
}
Пример #11
0
/*
 * Create some types: this must be called after init_variables
 */
static void init_types(void) {
    base[0] = bool_type(&types);
    base[1] = int_type(&types);
    base[2] = real_type(&types);
    base[3] = var[0];
    base[4] = var[1];
    base[5] = var[2];
    base[6] = pair_type(base[1], base[1]);
    base[7] = triple_type(var[3], base[0], var[3]);
    base[8] = binary_ftype(base[2], base[2], base[0]);
    base[9] = binary_ftype(var[4], var[5], base[0]);
    base[10] = ternary_ftype(base[1], base[1], base[1], base[2]);
    base[11] = ternary_ftype(base[2], base[2], base[2], base[0]);
}
Пример #12
0
//--------------------------------------------------------------------------
// Function:	CommonFG::openIntType
///\brief	Opens the named integer datatype at this location.
///\param	name  - IN: Name of the integer datatype to open
///\return	IntType instance
///\exception	H5::FileIException or H5::GroupIException
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
IntType CommonFG::openIntType( const char* name ) const
{
   // Call C function H5Topen2 to open the named datatype in this group,
   // given either the file or group id
   hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

   // If the datatype's opening failed, throw an exception
   if( type_id < 0 )
      throwException("openIntType", "H5Topen2 failed");

   // No failure, create and return the IntType object
   IntType int_type(type_id);
   return(int_type);
}
Пример #13
0
int set_unistate(const char *name, int *val, int count)
{
	int sidx = get_unistate_index(name);
	if(sidx < 0) {
		StType type = int_type(count);
		if(type == ST_UNKNOWN) {
			error_log("invalid element count (%d) while setting previously unknown unistate item \"%s\"\n",
					count, name);
			return -1;
		}

		sidx = add_unistate(name, type);
	}
	set_unistate(sidx, val);
	return sidx;
}
Пример #14
0
CDatabaseItem::CDatabaseItem(CDatabaseListView * parent, const QString &dbname, bool isconnected, const QString &connection_name, CMySQLServer *m)
: CDatabaseListViewItem(parent, m, DATABASE, "CDatabaseItem")
{
#ifdef DEBUG
  qDebug("CDatabaseItem::CDatabaseItem(CDatabaseListView *, '%s', bool, const QString &, CMySQLServer *)", debug_string(dbname));
#endif

  if (m == 0)
  {
    m_mysql = new CMySQLServer(connection_name, messagePanel());
    mysql()->connect();
    deletemysql = true;
  }
  is_connected = isconnected;
  init(dbname);
  widget_id = int_type();
}
Пример #15
0
flt_type tk::spline::operator() (flt_type x) const {
   size_t n=m_x.size();
   // find the closest point m_x[idx] < x, idx=0 even if x<m_x[0]
   std::vector<flt_type>::const_iterator it;
   it=std::lower_bound(m_x.begin(),m_x.end(),x);
   int_type idx=std::max( int_type(it-m_x.begin())-1, 0);

   flt_type h=x-m_x[idx];
   flt_type interpol;
   if(x<m_x[0]) {
      // extrapolation to the left
      interpol=((m_b[0])*h + m_c[0])*h + m_y[0];
   } else if(x>m_x[n-1]) {
      // extrapolation to the right
      interpol=((m_b[n-1])*h + m_c[n-1])*h + m_y[n-1];
   } else {
      // interpolation
      interpol=((m_a[idx]*h + m_b[idx])*h + m_c[idx])*h + m_y[idx];
   }
   return interpol;
}
void cpp_declarator_convertert::main_function_rules(
  const symbolt &symbol)
{
  if(symbol.name=="c::main")
  {
    if(symbol.type.id()!=ID_code)
    {
      cpp_typecheck.err_location(symbol.location);
      throw "main must be function";
    }

    const typet &return_type=
      static_cast<const typet &>(
        symbol.type.find(ID_return_type));

    if(return_type!=int_type())
    {
      cpp_typecheck.err_location(symbol.location);
      throw "main must return int";
    }
  }
}
Пример #17
0
int
main (int argc, char *argv[])
{
  const struct discrete_t *dtype;
  size_t index;

  if (argc < 2) {
    (void) fprintf (stderr, "usage: type\n");
    exit (EXIT_FAILURE);
  }

  for (index = 0; index < type_table_size; ++index) {
    dtype = &type_table [index];
    if (strcmp (argv[1], dtype->name_ada) == 0) {
      switch (dtype->kind) {
        case DISCRETE_RANGED:
          int_type
           (dtype->name_ada,
            dtype->bound_low,
            dtype->bound_high,
            dtype->bound_base,
            dtype->size);
          exit (EXIT_SUCCESS);
        case DISCRETE_MOD:
          mod_type (dtype->name_ada, dtype->size);
          exit (EXIT_SUCCESS);
        default:
          (void) fprintf (stderr, "fatal: unknown discrete type kind\n");
          exit (EXIT_FAILURE); 
      }
    }
  }

  (void) fprintf (stderr, "fatal: unknown type %s\n", argv[1]);
  exit (EXIT_FAILURE); 

  /*@notreached@*/
  return 0;
}
strstreambuf::int_type
strstreambuf::pbackfail(int_type __c)
{
    if (eback() == gptr())
        return EOF;
    if (__c == EOF)
    {
        gbump(-1);
        return int_type(0);
    }
    if (__strmode_ & __constant)
    {
        if (gptr()[-1] == static_cast<char>(__c))
        {
            gbump(-1);
            return __c;
        }
        return EOF;
    }
    gbump(-1);
    *gptr() = static_cast<char>(__c);
    return __c;
}
Пример #19
0
bare_expr_type::bare_expr_type(const int_type& x)
    : bare_type_(int_type(x.is_data_)) {}
Пример #20
0
bool bare_expr_type::is_primitive() const {
  return order_id() == int_type().oid() || order_id() == double_type().oid();
}
Пример #21
0
bool bare_expr_type::is_int_type() const {
  return order_id() == int_type().oid();
}
Пример #22
0
bool simplify_exprt::simplify_address_of_arg(exprt &expr)
{
    if(expr.id()==ID_index)
    {
        if(expr.operands().size()==2)
        {
            bool result=true;
            if(!simplify_address_of_arg(expr.op0())) result=false;
            if(!simplify_rec(expr.op1())) result=false;

            // rewrite (*(type *)int) [index] by
            // pushing the index inside

            mp_integer address;
            if(is_dereference_integer_object(expr.op0(), address))
            {
                // push index into address

                mp_integer step_size, index;

                step_size=pointer_offset_size(expr.type(), ns);

                if(!to_integer(expr.op1(), index) &&
                        step_size!=-1)
                {
                    unsignedbv_typet int_type(config.ansi_c.pointer_width);
                    pointer_typet pointer_type;
                    pointer_type.subtype()=expr.type();
                    typecast_exprt typecast_expr(
                        from_integer(step_size*index+address, int_type), pointer_type);
                    exprt new_expr=dereference_exprt(typecast_expr, expr.type());
                    expr=new_expr;
                    result=true;
                }
            }

            return result;
        }
    }
    else if(expr.id()==ID_member)
    {
        if(expr.operands().size()==1)
        {
            bool result=true;
            if(!simplify_address_of_arg(expr.op0())) result=false;

            const typet &op_type=ns.follow(expr.op0().type());

            if(op_type.id()==ID_struct)
            {
                // rewrite NULL -> member by
                // pushing the member inside

                mp_integer address;
                if(is_dereference_integer_object(expr.op0(), address))
                {
                    const struct_typet &struct_type=to_struct_type(op_type);
                    const irep_idt &member=to_member_expr(expr).get_component_name();
                    mp_integer offset=member_offset(struct_type, member, ns);
                    if(offset!=-1)
                    {
                        unsignedbv_typet int_type(config.ansi_c.pointer_width);
                        pointer_typet pointer_type;
                        pointer_type.subtype()=expr.type();
                        typecast_exprt typecast_expr(
                            from_integer(address+offset, int_type), pointer_type);
                        exprt new_expr=dereference_exprt(typecast_expr, expr.type());
                        expr=new_expr;
                        result=true;
                    }
                }
            }

            return result;
        }
    }
    else if(expr.id()==ID_dereference)
    {
        if(expr.operands().size()==1)
            return simplify_rec(expr.op0());
    }
    else if(expr.id()==ID_if)
    {
        if(expr.operands().size()==3)
        {
            bool result=true;
            if(!simplify_rec(expr.op0())) result=false;
            if(!simplify_address_of_arg(expr.op1())) result=false;
            if(!simplify_address_of_arg(expr.op2())) result=false;

            // op0 is a constant?
            if(expr.op0().is_true())
            {
                result=false;
                exprt tmp;
                tmp.swap(expr.op1());
                expr.swap(tmp);
            }
            else if(expr.op0().is_false())
            {
                result=false;
                exprt tmp;
                tmp.swap(expr.op2());
                expr.swap(tmp);
            }

            return result;
        }
    }

    return true;
}
Пример #23
0
inline bool rational<IntType>::test_invariant() const
{
    return ( this->den > int_type(0) ) && ( math::gcd(this->num, this->den) ==
     int_type(1) );
}
Пример #24
0
 void atomic_write(value_type rhs)
 {
     detail::atomic_write<sizeof(value_type)>(&this->value_, int_type(rhs));
 }
Пример #25
0
 static void
 call(Iterator const& first, Iterator const& last, int& attr)
 {
     Iterator first_ = first;
     qi::parse(first_, last, int_type(), attr);
 }
Пример #26
0
/*
 * Test 5: pairs (int x int)
 * - start with pairs [4, 4], [6, 6]
 */
static void test5(void) {
  type_t tau[2];
  particle_t a, b, c, d;
  particle_t q[40], x;
  uint32_t n;

  printf("\n"
         "***********************\n"
	 "*       TEST 5        *\n"
         "***********************\n");

  tau[0] = int_type(&types);
  tau[1] = int_type(&types);

  a = pstore_labeled_particle(&store, 4, tau[0]);
  b = pstore_labeled_particle(&store, 6, tau[1]);

  q[0] = a;
  q[1] = a;
  c = pstore_tuple_particle(&store, 2, q, tau);

  q[0] = b;
  q[1] = b;
  d = pstore_tuple_particle(&store, 2, q, tau);

  printf("\nInitial objects of type tau!%"PRId32"\n", tau[0]);
  print_particle_def(a);
  print_particle_def(b);
  printf("\n");

  printf("Initial objects of type tau!%"PRId32" x tau!%"PRId32"\n", tau[0], tau[1]);
  print_particle_def(c);
  print_particle_def(d);
  printf("\n");

  printf("\nInitial sets\n");
  print_particle_set(pstore_find_set_for_type(&store, tau[0]));
  printf("\n");
  print_particle_set(pstore_find_set_for_types(&store, 2, tau));
  printf("\n\n");


    // Initial array: empty
  printf("Test array: ");
  print_particle_array(q, 0);
  printf("\n");

  // create new tuples until that fails
  for (n = 0; n<40; n++) {
    x = get_distinct_tuple(&store, 2, tau, n, q);
    if (x == null_particle) {
      printf("Saturation\n");
      break;
    }
    printf("New particle:");
    print_particle_def(x);
    q[n] = x;
  }

  printf("\nFinal sets\n");
  print_particle_set(pstore_find_set_for_type(&store, tau[0]));
  printf("\n");
  print_particle_set(pstore_find_set_for_types(&store, 2, tau));
  printf("\n\n");


}
void printf_formattert::process_format(std::ostream &out)
{
  exprt tmp;
  format_constantt format_constant;

  format_constant.precision=6;
  format_constant.min_width=0;
  format_constant.zero_padding=false;

  char ch=next();

  if(ch=='0') // leading zeros
  {
    format_constant.zero_padding=true;
    ch=next();
  }

  while(isdigit(ch)) // width
  {
    format_constant.min_width*=10;
    format_constant.min_width+=ch-'0';
    ch=next();
  }

  if(ch=='.') // precision
  {
    format_constant.precision=0;
    ch=next();

    while(isdigit(ch))
    {
      format_constant.precision*=10;
      format_constant.precision+=ch-'0';
      ch=next();
    }
  }

  switch(ch)
  {
  case '%':
    out << ch;
    break;

  case 'f':
  case 'F':
    if(next_operand==operands.end()) break;
    out << format_constant(
      make_type(*(next_operand++), double_type()));
    break;

  case 'g':
  case 'G':
    if(format_constant.precision==0) format_constant.precision=1;
    if(next_operand==operands.end()) break;
    out << format_constant(
      make_type(*(next_operand++), double_type()));
    break;

  case 's':
    {
      if(next_operand==operands.end()) break;
      // this is the address of a string
      const exprt &op=*(next_operand++);
      if(op.id()==ID_address_of &&
         op.operands().size()==1 &&
         op.op0().id()==ID_index &&
         op.op0().operands().size()==2 &&
         op.op0().op0().id()==ID_string_constant)
        out << format_constant(op.op0().op0());
    }
    break;

  case 'd':
    if(next_operand==operands.end()) break;
    out << format_constant(
      make_type(*(next_operand++), int_type()));
    break;

  case 'D':
    if(next_operand==operands.end()) break;
    out << format_constant(
      make_type(*(next_operand++), long_int_type()));
    break;

  case 'u':
    if(next_operand==operands.end()) break;
    out << format_constant(
      make_type(*(next_operand++), uint_type()));
    break;

  case 'U':
    if(next_operand==operands.end()) break;
    out << format_constant(
      make_type(*(next_operand++), long_uint_type()));
    break;

  default:
    out << '%' << ch;
  }
}
Пример #28
0
 static inline batch_type next(const batch_type& b) noexcept
 {
     batch_type n = bitwise_cast<batch_type>(bitwise_cast<int_batch>(b) + int_type(1));
     return select(b == infinity<batch_type>(), b, n);
 }
Пример #29
0
void string_constantt::set_value(const irep_idt &value)
{
  exprt size_expr=from_integer(value.size()+1, int_type());
  type().add(ID_size).swap(size_expr);
  set(ID_value, value);
}
Пример #30
0
 static inline batch_type prev(const batch_type& b) noexcept
 {
     batch_type p = bitwise_cast<batch_type>(bitwise_cast<int_batch>(b) - int_type(1));
     return select(b == minusinfinity<batch_type>(), b, p);
 }