Esempio n. 1
0
const EnumValues* EnumCache::getValuesBuiltin(const Class* klass) {
  assert(isEnum(klass));
  if (auto values = klass->getEnumValues()) {
    return values;
  }
  return s_cache.getEnumValues(klass, false);
}
Esempio n. 2
0
bool TypeConstraint::checkTypeAliasNonObj(const TypedValue* tv) const {
  assert(tv->m_type != KindOfObject); // this checks when tv is not an object
  assert(!isSelf() && !isParent());

  auto p = getTypeAliasOrClassWithAutoload(m_namedEntity, m_typeName);
  auto td = p.first;
  auto c = p.second;

  // Common case is that we actually find the alias:
  if (td) {
    if (td->nullable && tv->m_type == KindOfNull) return true;
    return td->any || equivDataTypes(td->kind, tv->m_type);
  }

  // Otherwise, this isn't a proper type alias, but it *might* be a
  // first-class enum. Check if the type is an enum and check the
  // constraint if it is. We only need to do this when the underlying
  // type is not an object, since only int and string can be enums.
  if (c && isEnum(c)) {
    auto dt = c->enumBaseTy();
    // For an enum, if the underlying type is mixed, we still require
    // it is either an int or a string!
    if (dt) {
      return equivDataTypes(*dt, tv->m_type);
    } else {
      return IS_INT_TYPE(tv->m_type) || IS_STRING_TYPE(tv->m_type);
    }
  }
  return false;
}
Esempio n. 3
0
MaybeDataType TypeConstraint::underlyingDataTypeResolved() const {
  assert(!isSelf() && !isParent());
  if (!hasConstraint()) return folly::none;

  auto t = underlyingDataType();

  // If we aren't a class or type alias, nothing special to do.
  if (!isObjectOrTypeAlias()) return t;

  auto p = getTypeAliasOrClassWithAutoload(m_namedEntity, m_typeName);
  auto td = p.first;
  auto c = p.second;

  // See if this is a type alias.
  if (td) {
    if (td->kind != KindOfObject) {
      t = td->kind;
    } else {
      c = td->klass;
    }
  }

  // If the underlying type is a class, see if it is an enum and get that.
  if (c && isEnum(c)) {
    t = c->enumBaseTy();
  }

  return t;
}
Esempio n. 4
0
bool TypeConstraint::checkTypeAliasNonObj(const TypedValue* tv) const {
  assert(tv->m_type != KindOfObject);
  assert(isObject());

  auto p = getTypeAliasOrClassWithAutoload(m_namedEntity, m_typeName);
  auto td = p.first;
  auto c = p.second;

  // Common case is that we actually find the alias:
  if (td) {
    if (td->nullable && tv->m_type == KindOfNull) return true;
    auto result = annotCompat(tv->m_type, td->type,
      td->klass ? td->klass->name() : nullptr);
    switch (result) {
      case AnnotAction::Pass: return true;
      case AnnotAction::Fail: return false;
      case AnnotAction::CallableCheck:
        return is_callable(tvAsCVarRef(tv));
      case AnnotAction::DictCheck:
        return tv->m_data.parr->isDict();
      case AnnotAction::VecCheck:
        return tv->m_data.parr->isVecArray();
      case AnnotAction::ObjectCheck: break;
    }
    assert(result == AnnotAction::ObjectCheck);
    assert(td->type == AnnotType::Object);
    // Fall through to the check below, since this could be a type
    // alias to an enum type
    c = td->klass;
  }

  // Otherwise, this isn't a proper type alias, but it *might* be a
  // first-class enum. Check if the type is an enum and check the
  // constraint if it is. We only need to do this when the underlying
  // type is not an object, since only int and string can be enums.
  if (c && isEnum(c)) {
    auto dt = c->enumBaseTy();
    // For an enum, if the underlying type is mixed, we still require
    // it is either an int or a string!
    if (dt) {
      return equivDataTypes(*dt, tv->m_type);
    } else {
      return isIntType(tv->m_type) || isStringType(tv->m_type);
    }
  }
  return false;
}
Esempio n. 5
0
QVariant Properties::data( const QModelIndex & index, int role ) const
{
    if ( getTarget() == nullptr )
        return QVariant();

    QList< QByteArray > dynamicProperties = getTarget()->dynamicPropertyNames( );
    int staticPropertyCount = getTarget()->metaObject( )->propertyCount( )
                                            - _hiddenStaticPropertiesCount;
    int propertyCount = getTarget()->metaObject( )->propertyCount( ) + dynamicProperties.size( );

    QString propertyName( "" );
    QString propertyType( "" );
    bool    propertyIsEnum( false );

    if ( index.row( ) >= 0 && index.row( ) < staticPropertyCount ) {   // Dealing with static properties
        QMetaProperty staticProperty = getTarget()->metaObject( )->property( _hiddenStaticPropertiesCount + index.row( ) );
        propertyName = ( staticProperty.name( ) != nullptr ? QString( staticProperty.name( ) ) : "" );
        propertyType = ( staticProperty.typeName( ) != nullptr ? QString( staticProperty.typeName( ) ) : "" );
    }
    else if ( index.row( ) >= staticPropertyCount &&    // Dealing with dynamic properties
         index.row( ) < propertyCount ) {
        int dynamicPropertyIndex = index.row( ) - staticPropertyCount;
        propertyName = dynamicProperties.at( dynamicPropertyIndex );
        propertyType = getTarget()->property( propertyName.toLatin1( ) ).typeName( );
        qDebug() << "propertyType=" << propertyType;
        propertyIsEnum = isEnum( propertyName );
    }

    if ( !propertyName.isEmpty( ) && !propertyType.isEmpty( ) )
    {
        if ( role == PropertyNameRole )
            return propertyName;
        else if ( role == PropertyTypeRole )
            return propertyType;
        else if ( role == PropertyIsEnumRole )
            return propertyIsEnum;
        else if ( role == PropertyDataRole )
            return property( propertyName.toLatin1( ) );
        else if ( role == PropertyOptionsRole )
            return QVariant::fromValue< qps::Options* >( const_cast< qps::Properties* >( this )->getPropertyOptions( propertyName ) ); // Return the corresponding options object for the requested property
    }

    return data( index, role );
}
void    Properties::serializeOut( QXmlStreamWriter& stream )
{
    stream.writeStartElement( "properties" );   // <properties>

    // Serialize static properties
    int pCount = metaObject( )->propertyCount( );
    for ( int i = 0; i < pCount; ++i )
    {
        QMetaProperty metaProperty = metaObject( )->property( i );
        QString propertyName = QString( metaProperty.name( ) );
        QVariant v = property( propertyName.toLatin1( ) );

        stream.writeStartElement( "property" );     // <property>
        stream.writeAttribute( "name", propertyName );
        serializeValueOut( v, stream );
        serializeTimeValuesOut( propertyName, stream );

        stream.writeEndElement( );                  // </property>
    }

    // Serialize dynamic properties
    QList< QByteArray > dynamicProperties = dynamicPropertyNames( );
    for ( int d = 0; d < dynamicProperties.size( ); d++ )
    {
        QString propertyName = dynamicProperties.at( d );
        QVariant v = property( propertyName.toLatin1( ) );

        stream.writeStartElement( "property" );     // <property>
        stream.writeAttribute( "name", propertyName );
        serializeValueOut( v, stream );

        if ( isEnum( propertyName ) )
            stream.writeAttribute( "isEnum", getEnumValueLabels( propertyName ).join( ',') );
        serializeTimeValuesOut( propertyName, stream );

        stream.writeEndElement( );                  // </property>
    }

    stream.writeEndElement( );                  // </properties>
}
Esempio n. 7
0
/**
 *  called on "kmixctrl --save" and from the GUI's (currently only on exit)
 */
void MixDevice::write( KConfig *config, const QString& grp )
{
   QString devgrp;
   devgrp.sprintf( "%s.Dev%i", grp.ascii(), _num );
   config->setGroup(devgrp);
   // kdDebug(67100) << "MixDevice::write() of group devgrp=" << devgrp << endl;
   char *nameLeftVolume, *nameRightVolume;
   if ( _volume.isCapture() ) {
		nameLeftVolume = "volumeLCapture";
		nameRightVolume = "volumeRCapture";
   } else {
		nameLeftVolume = "volumeL";
		nameRightVolume = "volumeR";
   }
   config->writeEntry(nameLeftVolume, getVolume( Volume::LEFT ) );
   config->writeEntry(nameRightVolume, getVolume( Volume::RIGHT ) );
   config->writeEntry("is_muted", (int)_volume.isMuted() );
   config->writeEntry("is_recsrc", (int)isRecSource() );
   config->writeEntry("name", _name);
   if ( isEnum() ) {
      config->writeEntry("enum_id", enumId() );
   }
}
Esempio n. 8
0
MaybeDataType TypeConstraint::underlyingDataTypeResolved() const {
  assert(!isSelf() && !isParent() && !isCallable());
  assert(IMPLIES(
    !hasConstraint() || isTypeVar() || isTypeConstant(),
    isMixed()));

  if (!isPrecise()) return folly::none;

  auto t = underlyingDataType();
  assert(t);

  // If we aren't a class or type alias, nothing special to do.
  if (!isObject()) return t;

  assert(t == KindOfObject);
  auto p = getTypeAliasOrClassWithAutoload(m_namedEntity, m_typeName);
  auto td = p.first;
  auto c = p.second;

  // See if this is a type alias.
  if (td) {
    if (td->type != Type::Object) {
      t = (getAnnotMetaType(td->type) != MetaType::Precise)
        ? folly::none : MaybeDataType(getAnnotDataType(td->type));
    } else {
      c = td->klass;
    }
  }

  // If the underlying type is a class, see if it is an enum and get that.
  if (c && isEnum(c)) {
    t = c->enumBaseTy();
  }

  return t;
}
void PropertyPanel::rereadPortProperties()
{
	//kdDebug() << QString("PropertyPanel::rereadPortProperties") << endl;
	if(!port) return; // sanity check

	std::string dataType = port->PortDesc.type().dataType;
	if(isEnum(dataType))
	{
		constantValueEdit->hide();
		constantValueComboBox->show();

		fillEnumChoices(dataType);
	}
	else
	{
		constantValueEdit->show();
		constantValueComboBox->hide();
	}

	if( port->PortDesc.hasValue() )
	{
		pvConstantButton->setChecked( true );

		QString constValue;

		Arts::Any value = port->PortDesc.value();
		Arts::Buffer b;
		b.write(value.value);

		if(isEnum(value.type))
		{
			long v = b.readLong();
			constantValueComboBox->setCurrentItem(findEnumIndex(value.type,v));
		}
		else
		{
			if(value.type == "float")
				constValue.sprintf("%2.4f", b.readFloat());
			else if(value.type == "long")
				constValue.sprintf("%ld", b.readLong());
			else if(value.type == "string")
			{
				std::string s;
				b.readString(s);
				constValue = s.c_str();
			}
			else if(value.type == "boolean")
			{
				if(b.readBool())
					constValue = "true";
				else
					constValue = "false";
			}
			else constValue = ("*unknown type* " + value.type).c_str();

			constantValueEdit->setText( constValue );
		}
	}
	else if( port->PortDesc.isConnected() )
		pvConnectionButton->setChecked( true );
	else
	{
		pvNotSetButton->setChecked( true );
		constantValueEdit->clear();
	}

	pvConnectionButton->setEnabled( port->PortDesc.isConnected() );
}
Esempio n. 10
0
void PropertyPanel::writePortProperties( bool reread )
{
	//kdDebug() << QString("PropertyPanel::writePortProperties") << endl;
	if(!port) return; // sanity check

	bool dirty = false;

	if(!pvConnectionButton->isChecked())
	{
		if(port->PortDesc.isConnected())
		{
			port->PortDesc.disconnectAll();
			dirty = true;
		}
	}

	if(pvNotSetButton->isChecked() &&
		(port->PortDesc.isConnected() || port->PortDesc.hasValue()))
	{
		port->PortDesc.hasValue(false);
		dirty = true;
	}

	if(pvConstantButton->isChecked())
	{
		std::string type = port->PortDesc.type().dataType;
		QString newvalue = constantValueEdit->text();

		Arts::Any a;
		a.type = type;
		Arts::Buffer b;
		if(type == "float")
			b.writeFloat(newvalue.toFloat());
		else if(type == "long")
			b.writeLong(newvalue.toLong());
		else if(type == "string")
			b.writeString(newvalue.local8Bit().data());
		else if(type == "boolean")
		{
			b.writeBool(newvalue.upper() == "TRUE" || newvalue.upper() == "T"
						|| newvalue == "1");
		}
		else if(isEnum(type))
		{
			b.writeLong(selectedEnumValue(type));
		}

		if(b.size() > 0)
		{
			b.read(a.value, b.size());
			port->PortDesc.value(a);
			dirty = true;
		}
	}

	if( dirty )
		emit portPropertiesChanged( port );

	if( reread )
		rereadPortProperties();
}
bool HHVM_FUNCTION(enum_exists, const String& enum_name,
                   bool autoload /* = true */) {
  Class* cls = Unit::getClass(enum_name.get(), autoload);
  return cls && isEnum(cls);
}
Esempio n. 12
0
bool Inst::CastTo(CodeContext& context, RValue& value, SType* type, bool upcast)
{
	auto valueType = value.stype();

	if (type == valueType) {
		// non-assignment and non-comparison operations with enum types
		// must result in an int type to keep enum variables within range.
		if (upcast && valueType->isEnum())
			value.castToSubtype();
		return false;
	} else if (type->isComplex() || valueType->isComplex()) {
		context.addError("can not cast complex types");
		return true;
	} else if (type->isPointer()) {
		if (value.isNullPtr()) {
			// NOTE: discard current null value and create
			// a new one using the right type
			value = RValue::getNullPtr(context, type);
			return false;
		} else if (type->subType()->isVoid()) {
			value = RValue(new BitCastInst(value, *type, "", context), type);
			return false;
		}
		context.addError("can't cast value to pointer type");
		return true;
	} else if (type->isVec()) {
		// unwrap enum type
		if (valueType->isEnum())
			valueType = value.castToSubtype();

		if (valueType->isNumeric()) {
			CastTo(context, value, type->subType(), upcast);

			auto i32 = SType::getInt(context, 32);
			auto mask = RValue::getZero(context, SType::getVec(context, i32, type->size()));
			auto udef = UndefValue::get(*SType::getVec(context, type->subType(), 1));
			auto instEle = InsertElementInst::Create(udef, value, RValue::getZero(context, i32), "", context);
			auto retVal = new ShuffleVectorInst(instEle, udef, mask, "", context);

			value = RValue(retVal, type);
			return false;
		} else if (valueType->isPointer()) {
			context.addError("can not cast pointer to vec type");
			return true;
		} else if (type->size() != valueType->size()) {
			context.addError("can not cast vec types of different sizes");
			return true;
		} else if (type->subType()->isBool()) {
			// cast to bool is value != 0
			auto pred = getPredicate(ParserBase::TT_NEQ, valueType, context);
			auto op = valueType->subType()->isFloating()? Instruction::FCmp : Instruction::ICmp;
			auto val = CmpInst::Create(op, pred, value, RValue::getZero(context, valueType), "", context);
			value = RValue(val, type);
			return false;
		} else {
			auto op = getCastOp(valueType->subType(), type->subType());
			auto val = CastInst::Create(op, value, *type, "", context);
			value = RValue(val, type);
			return false;
		}
	} else if (type->isEnum()) {
		// casting to enum would violate value constraints
		context.addError("can't cast to enum type");
		return true;
	} else if (type->isBool()) {
		if (valueType->isVec()) {
			context.addError("can not cast vec type to bool");
			return true;
		} else if (valueType->isEnum()) {
			valueType = value.castToSubtype();
		}

		// cast to bool is value != 0
		auto pred = getPredicate(ParserBase::TT_NEQ, valueType, context);
		auto op = valueType->isFloating()? Instruction::FCmp : Instruction::ICmp;
		auto val = CmpInst::Create(op, pred, value, RValue::getZero(context, valueType), "", context);
		value = RValue(val, type);
		return false;
	}

	if (valueType->isPointer()) {
		context.addError("can't cast pointer to numeric type");
		return true;
	}

	// unwrap enum type
	if (valueType->isEnum())
		valueType = value.castToSubtype();

	auto op = getCastOp(valueType, type);
	auto val = op != Instruction::AddrSpaceCast? CastInst::Create(op, value, *type, "", context) : value;
	value = RValue(val, type);
	return false;
}
Esempio n. 13
0
// Convert a Python object to a QVariant.
bool Chimera::fromPyObject(PyObject *py, QVariant *var, bool strict) const
{
    // Deal with the simple case of wrapping the Python object rather than
    // converting it.
    if (_type != sipType_QVariant && _metatype == PyQt_PyObject::metatype)
    {
        // If the type was specified by a Python type (as opposed to
        // 'PyQt_PyObject') then check the object is an instance of it.
        if (_py_type && !PyObject_IsInstance(py, _py_type))
            return false;

        *var = keep_as_pyobject(py);
        return true;
    }

    // Let any registered convertors have a go first.
    for (int i = 0; i < _registered_QVariant_convertors.count(); ++i)
    {
        bool ok;

        if (_registered_QVariant_convertors.at(i)(py, var, &ok))
            return ok;
    }

    int iserr = 0, value_class_state;
    void *ptr_class, *value_class = 0;

    // Temporary storage for different types.
    union {
        bool tmp_bool;
        int tmp_int;
        unsigned int tmp_unsigned_int;
        double tmp_double;
        void *tmp_void_ptr;
        long tmp_long;
        qlonglong tmp_qlonglong;
        short tmp_short;
        char tmp_char;
        unsigned long tmp_unsigned_long;
        qulonglong tmp_qulonglong;
        unsigned short tmp_unsigned_short;
        unsigned char tmp_unsigned_char;
        float tmp_float;
    } tmp_storage;

    void *variant_data = &tmp_storage;

    PyErr_Clear();

    QVariant variant;
    int metatype_used = _metatype;

    switch (_metatype)
    {
    case QMetaType::Bool:
        tmp_storage.tmp_bool = PyLong_AsLong(py);
        break;

    case QMetaType::Int:
        if (!_inexact || isEnum() || isFlag())
        {
            // It must fit into a C++ int.
#if PY_MAJOR_VERSION >= 3
            tmp_storage.tmp_int = PyLong_AsLong(py);
#else
            tmp_storage.tmp_int = PyInt_AsLong(py);
#endif
        }
        else
        {
            // Fit it into the smallest C++ type we can.

            qlonglong qll = PyLong_AsLongLong(py);

            if (PyErr_Occurred())
            {
                // Try again in case the value is unsigned and will fit with
                // the extra bit.

                PyErr_Clear();

                qulonglong qull = static_cast<qulonglong>(PyLong_AsUnsignedLongLong(py));

                if (PyErr_Occurred())
                {
                    // It won't fit into any C++ type so pass it as a Python
                    // object.

                    PyErr_Clear();

                    *var = keep_as_pyobject(py);
                    metatype_used = QMetaType::Void;
                }
                else
                {
                    tmp_storage.tmp_qulonglong = qull;
                    metatype_used = QMetaType::ULongLong;
                }
            }
            else if ((qlonglong)(int)qll == qll)
            {
                // It fits in a C++ int.
                tmp_storage.tmp_int = qll;
            }
            else if ((qulonglong)(unsigned int)qll == (qulonglong)qll)
            {
                // The extra bit is enough for it to fit.
                tmp_storage.tmp_unsigned_int = qll;
                metatype_used = QMetaType::UInt;
            }
            else
            {
                // This fits.
                tmp_storage.tmp_qlonglong = qll;
                metatype_used = QMetaType::LongLong;
            }
        }

        break;

    case QMetaType::UInt:
        tmp_storage.tmp_unsigned_int = sipLong_AsUnsignedLong(py);
        break;

    case QMetaType::Double:
        tmp_storage.tmp_double = PyFloat_AsDouble(py);
        break;

    case QMetaType::VoidStar:
        tmp_storage.tmp_void_ptr = sipConvertToVoidPtr(py);
        break;

    case QMetaType::Long:
        tmp_storage.tmp_long = PyLong_AsLong(py);
        break;

    case QMetaType::LongLong:
        tmp_storage.tmp_qlonglong = PyLong_AsLongLong(py);
        break;

    case QMetaType::Short:
        tmp_storage.tmp_short = PyLong_AsLong(py);
        break;

    case QMetaType::Char:
        if (SIPBytes_Check(py) && SIPBytes_GET_SIZE(py) == 1)
            tmp_storage.tmp_char = *SIPBytes_AS_STRING(py);
        else
            iserr = 1;
        break;

    case QMetaType::ULong:
        tmp_storage.tmp_unsigned_long = sipLong_AsUnsignedLong(py);
        break;

    case QMetaType::ULongLong:
        tmp_storage.tmp_qulonglong = static_cast<qulonglong>(PyLong_AsUnsignedLongLong(py));
        break;

    case QMetaType::UShort:
        tmp_storage.tmp_unsigned_short = sipLong_AsUnsignedLong(py);
        break;

    case QMetaType::UChar:
        if (SIPBytes_Check(py) && SIPBytes_GET_SIZE(py) == 1)
            tmp_storage.tmp_unsigned_char = *SIPBytes_AS_STRING(py);
        else
            iserr = 1;
        break;

    case QMetaType::Float:
        tmp_storage.tmp_float = PyFloat_AsDouble(py);
        break;

    case QMetaType::QObjectStar:
        tmp_storage.tmp_void_ptr = sipForceConvertToType(py, sipType_QObject,
                0, SIP_NO_CONVERTORS, 0, &iserr);
        break;

    case QMetaType::QWidgetStar:
        if (sipType_QWidget)
        {
            tmp_storage.tmp_void_ptr = sipForceConvertToType(py,
                    sipType_QWidget, 0, SIP_NO_CONVERTORS, 0, &iserr);
        }
        else
        {
            iserr = 1;
        }

        break;

    case QMetaType::QVariantList:
        {
            QVariantList ql;

            if (to_QVariantList(py, ql))
            {
                *var = QVariant(ql);
                metatype_used = QMetaType::Void;
            }
            else
            {
                iserr = 1;
            }

            break;
        }

    case QMetaType::QVariantMap:
        {
            QVariantMap qm;

            if (to_QVariantMap(py, qm))
            {
                *var = QVariant(qm);
                metatype_used = QMetaType::Void;
            }
            else if (strict)
            {
                iserr = 1;
            }
            else
            {
                // Assume the failure is because the key was the wrong type.
                PyErr_Clear();

                *var = keep_as_pyobject(py);
                metatype_used = QMetaType::Void;
            }

            break;
        }

#if QT_VERSION >= 0x040500
    case QMetaType::QVariantHash:
        {
            QVariantHash qh;

            if (to_QVariantHash(py, qh))
            {
                *var = QVariant(qh);
                metatype_used = QMetaType::Void;
            }
            else
            {
                iserr = 1;
            }

            break;
        }
#endif

    case -1:
        metatype_used = QMetaType::VoidStar;

        if (SIPBytes_Check(py))
            tmp_storage.tmp_void_ptr = SIPBytes_AS_STRING(py);
        else if (py == Py_None)
            tmp_storage.tmp_void_ptr = 0;
        else
            iserr = 1;

        break;

    default:
        if (_type)
        {
            if (_name.endsWith('*'))
            {
                ptr_class = sipForceConvertToType(py, _type, 0,
                        SIP_NO_CONVERTORS, 0, &iserr);

                variant_data = &ptr_class;
            }
            else
            {
                value_class = sipForceConvertToType(py, _type, 0,
                    SIP_NOT_NONE, &value_class_state, &iserr);

                variant_data = value_class;
            }
        }
        else
        {
            // This is a class we don't recognise.
            iserr = 1;
        }
    }

    if (iserr || PyErr_Occurred())
    {
        PyErr_Format(PyExc_TypeError,
                "unable to convert a Python '%s' object to a C++ '%s' instance",
                Py_TYPE(py)->tp_name, _name.constData());

        iserr = 1;
    }
    else if (_type == sipType_QVariant)
    {
        *var = QVariant(*reinterpret_cast<QVariant *>(variant_data));
    }
    else if (metatype_used != QMetaType::Void)
    {
        *var = QVariant(metatype_used, variant_data);
    }

    // Release any temporary value-class instance now that QVariant will have
    // made a copy.
    if (value_class)
        sipReleaseType(value_class, _type, value_class_state);

    return (iserr == 0);
}
Esempio n. 14
0
void DataType::addEnumValue(const QString &reqifID, const EnumValue &enumValue) {
    if(isEnum()) {
        enumValuesList.insert(reqifID, enumValue);
    }
}
Esempio n. 15
0
//----------------------------------------------------------------------
bool outop(op_t &x)
{
  switch ( x.type )
  {

    case o_void:
      return 0;

    case o_reg:
      outreg(x.reg);
      break;

    case o_reglist:
      out_symbol('(');
      out_reglist(x.reg, 8);
      out_symbol(')');
      break;

    case o_imm:
      out_symbol('#');
      OutValue(x, calc_opimm_flags());
      out_sizer(x);
      break;

    case o_mem:
      out_symbol('@');
    case o_near:
    case o_far:
      {
        ea_t ea = calc_mem(x);
        if ( !out_name_expr(x, ea, BADADDR) )
          out_bad_address(x.addr);
        out_sizer(x);
      }
      break;

    case o_phrase:
      if ( x.phtype == ph_normal )
      {
        bool outdisp = isOff(uFlag,x.n)
                    || isStkvar(uFlag,x.n)
                    || isEnum(uFlag,x.n)
                    || isStroff(uFlag,x.n);
        if ( outdisp )
         goto OUTDISP;
      }
      out_symbol('@');
      if ( x.phtype == ph_pre  ) out_symbol('-');
      outreg(x.phrase);
      if ( x.phtype == ph_post ) out_symbol('+');
      break;

    case o_displ:
OUTDISP:
      out_symbol('@');
      out_symbol('(');
      OutValue(x, calc_opdispl_flags());
      out_sizer(x);
      out_symbol(',');
      outreg(x.reg);
      out_symbol(')');
      break;

    default:
      interr("out");
      break;
  }
  return 1;
}
Esempio n. 16
0
bool Type::isScalar() const {
	return isArithmetic() || isEnum() || isPointer() || isMemberPointer();
}
Esempio n. 17
0
const EnumCache::EnumValues* EnumCache::getValuesBuiltin(const Class* klass) {
  assert(isEnum(klass));
  return s_cache.getEnumValues(klass, false);
}
Esempio n. 18
0
// Convert a C++ object at an arbitary address to Python.
PyObject *Chimera::toPyObject(void *cpp) const
{
    if (_metatype == PyQt_PyObject::metatype)
    {
        if (_type)
        {
            // SIP knows the type (therefore it isn't really wrapped in a
            // PyQt_PyObject) but it's not registered with Qt.
            if (_name.endsWith('*'))
                cpp = *reinterpret_cast<void **>(cpp);

            return sipConvertFromType(cpp, _type, 0);
        }
        else
        {
            // Otherwise unwrap the Python object.
            PyQt_PyObject *pyobj_wrapper = reinterpret_cast<PyQt_PyObject *>(cpp);

            if (!pyobj_wrapper->pyobject)
            {
                PyErr_SetString(PyExc_TypeError,
                        "unable to convert a QVariant back to a Python object");

                return 0;
            }

            Py_INCREF(pyobj_wrapper->pyobject);

            return pyobj_wrapper->pyobject;
        }
    }

    PyObject *py = 0;

    switch (_metatype)
    {
    case QMetaType::Bool:
        py = PyBool_FromLong(*reinterpret_cast<bool *>(cpp));
        break;

    case QMetaType::Int:
        if (isFlag())
        {
            py = sipConvertFromType(cpp, _type, 0);
        }
        else if (isEnum())
        {
            py = sipConvertFromEnum(*reinterpret_cast<int *>(cpp), _type);
        }
        else
        {
            py = SIPLong_FromLong(*reinterpret_cast<int *>(cpp));
        }

        break;

    case QMetaType::UInt:
        {
            long ui = *reinterpret_cast<unsigned int *>(cpp);

            if (ui < 0)
                py = PyLong_FromUnsignedLong((unsigned long)ui);
            else
                py = SIPLong_FromLong(ui);

            break;
        }

    case QMetaType::Double:
        py = PyFloat_FromDouble(*reinterpret_cast<double *>(cpp));
        break;

    case QMetaType::VoidStar:
        py = sipConvertFromVoidPtr(*reinterpret_cast<void **>(cpp));
        break;

    case QMetaType::Long:
        py = SIPLong_FromLong(*reinterpret_cast<long *>(cpp));
        break;

    case QMetaType::LongLong:
        py = PyLong_FromLongLong(*reinterpret_cast<qlonglong *>(cpp));
        break;

    case QMetaType::Short:
        py = SIPLong_FromLong(*reinterpret_cast<short *>(cpp));
        break;

    case QMetaType::Char:
    case QMetaType::UChar:
        py = SIPBytes_FromStringAndSize(reinterpret_cast<char *>(cpp), 1);
        break;

    case QMetaType::ULong:
        py = PyLong_FromUnsignedLong(*reinterpret_cast<unsigned long *>(cpp));
        break;

    case QMetaType::ULongLong:
        py = PyLong_FromUnsignedLongLong(*reinterpret_cast<qulonglong *>(cpp));
        break;

    case QMetaType::UShort:
        py = SIPLong_FromLong(*reinterpret_cast<unsigned short *>(cpp));
        break;

    case QMetaType::Float:
        py = PyFloat_FromDouble(*reinterpret_cast<float *>(cpp));
        break;

    case QMetaType::QObjectStar:
        py = sipConvertFromType(*reinterpret_cast<void **>(cpp),
                sipType_QObject, 0);
        break;

    case QMetaType::QWidgetStar:
        if (sipType_QWidget)
            py = sipConvertFromType(*reinterpret_cast<void **>(cpp),
                    sipType_QWidget, 0);

        break;

    case QMetaType::QVariantList:
        {
            QVariantList *ql = reinterpret_cast<QVariantList *>(cpp);

            py = PyList_New(ql->size());

            if (py)
            {
                for (int i = 0; i < ql->size(); ++i)
                {
                    PyObject *val_obj = toAnyPyObject(ql->at(i));

                    if (!val_obj)
                    {
                        Py_DECREF(py);
                        py = 0;

                        break;
                    }

                    PyList_SET_ITEM(py, i, val_obj);
                }
            }

            break;
        }

    case QMetaType::QVariantMap:
        {
            py = PyDict_New();

            if (py)
            {
                QVariantMap *qm = reinterpret_cast<QVariantMap *>(cpp);

                for (QVariantMap::const_iterator it = qm->constBegin(); it != qm->constEnd(); ++it)
                    if (!add_variant_to_dict(py, it.key(), it.value()))
                    {
                        Py_DECREF(py);
                        py = 0;

                        break;
                    }
            }

            break;
        }

#if QT_VERSION >= 0x040500
    case QMetaType::QVariantHash:
        {
            py = PyDict_New();

            if (py)
            {
                QVariantHash *qh = reinterpret_cast<QVariantHash *>(cpp);

                for (QVariantHash::const_iterator it = qh->constBegin(); it != qh->constEnd(); ++it)
                    if (!add_variant_to_dict(py, it.key(), it.value()))
                    {
                        Py_DECREF(py);
                        py = 0;

                        break;
                    }
            }

            break;
        }
#endif

    case -1:
        {
            char *s = *reinterpret_cast<char **>(cpp);

            if (s)
            {
                py = SIPBytes_FromString(s);
            }
            else
            {
                Py_INCREF(Py_None);
                py = Py_None;
            }

            break;
        }

    default:
        if (_type)
        {
            if (_name.endsWith('*'))
            {
                py = sipConvertFromType(*reinterpret_cast<void **>(cpp),
                        _type, 0);
            }
            else
            {
                // Make a copy as it is a value type.
                void *copy = QMetaType::construct(_metatype, cpp);

                py = sipConvertFromNewType(copy, _type, 0);

                if (!py)
                    QMetaType::destroy(_metatype, copy);
            }
        }
    }

    if (!py)
        PyErr_Format(PyExc_TypeError,
                "unable to convert a C++ '%s' instance to a Python object",
                _name.constData());

    return py;
}