Ejemplo n.º 1
0
bool CEvaluationNode::operator<(const CEvaluationNode& right) const
{
  if (mainType() != right.mainType())
    {
      return mainType() < right.mainType();
    }

  if (subType() != right.subType())
    {
      return subType() < right.subType();
    }

  switch (mainType())
    {
      case T_CONSTANT:
      case T_NUMBER:
      case T_OBJECT:
      case T_CALL:
      case T_STRUCTURE:
      case T_VARIABLE:
      case T_WHITESPACE:
        return getData() < right.getData();
        break;

      case T_OPERATOR:
      case T_FUNCTION:
      case T_CHOICE:
      case T_LOGICAL:
      case T_MV_FUNCTION:
      case T_VECTOR:
      case T_DELAY:
      case T_INVALID:
        break;
    }

  const CEvaluationNode* pChild1 = dynamic_cast<const CEvaluationNode*>(this->getChild());
  const CEvaluationNode* pChild2 = dynamic_cast<const CEvaluationNode*>(right.getChild());

  while (true)
    {
      if (pChild1 == NULL || pChild2 == NULL)
        {
          return pChild1 < pChild2;
        }

      if (*pChild1 < *pChild2) return true;

      pChild1 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling());
      pChild2 = dynamic_cast<const CEvaluationNode*>(pChild2->getSibling());
    }

  return false;
}
Ejemplo n.º 2
0
// TODO Replace the recursive call (not critical since only used for debug)
void CEvaluationNode::printRecursively(std::ostream & os, int indent) const
{
  int i;

  os << std::endl;

  for (i = 0; i < indent; ++i) os << " ";

  os << "mData: " << mData << std::endl;

  for (i = 0; i < indent; ++i) os << " ";

  os << "mType: " << type(mType) << "  subType: " << subType(mType) << std::endl;

  for (i = 0; i < indent; ++i) os << " ";

  os << "mValue: " << mValue << std::endl;

  CEvaluationNode* tmp;

  tmp = (CEvaluationNode*)getChild();

  while (tmp)
    {
      tmp -> printRecursively(os, indent + 2);
      tmp = (CEvaluationNode*)tmp->getSibling();
    }
}
Ejemplo n.º 3
0
void Application::queryMarketDataRequest()
{

  FIX::MDReqID genMDReqID;
  genMDReqID = m_generator.genOrderID();
  FIX::MDReqID mdReqID( genMDReqID );
  FIX::SubscriptionRequestType subType( '1' );
  FIX::MarketDepth marketDepth( 2 );
  FIX::MDUpdateType mDUpdateType(1);
  FIX::AggregatedBook aggregatedBook(true);

  FIX42::MarketDataRequest::NoMDEntryTypes marketDataEntryGroup;
  FIX::MDEntryType mdEntryType1( FIX::MDEntryType_BID );
  FIX::MDEntryType mdEntryType2( FIX::MDEntryType_OFFER);
  marketDataEntryGroup.set( mdEntryType1 );
  marketDataEntryGroup.set( mdEntryType2 );

  FIX42::MarketDataRequest::NoRelatedSym symbolGroup;

  FIX::Symbol symbol( "IBM" );
  symbolGroup.set( symbol );

  FIX42::MarketDataRequest message( mdReqID, subType, marketDepth );
  message.addGroup( marketDataEntryGroup );
  message.addGroup( symbolGroup );

  message.set(mDUpdateType);
  message.set(aggregatedBook);

  setHeader( message.getHeader() );
  FIX::Session::sendToTarget( message );
}
Ejemplo n.º 4
0
void QMessage::setBody(const QString &body, const QByteArray &mimeType)
{
    QByteArray mainType("text");
    QByteArray subType("plain");
    QByteArray charset;

    QString mime = QString(mimeType);

    int index = mimeType.indexOf("/");
    if (index != -1) {
        mainType = mimeType.left(index).trimmed();

        subType = mimeType.mid(index + 1).trimmed();
        index = subType.indexOf(";");
        if (index != -1) {
            QString remainder = subType.mid(index + 1);
            subType = subType.left(index).trimmed();

            QRegExp charsetPattern("charset=(\\S+)");
            index = charsetPattern.indexIn(remainder);
            if (index != -1) {
                charset = charsetPattern.cap(1).toLatin1();
            }
        }
    }

    if (charset.isEmpty()) {
        charset = QMessage::preferredCharsetFor(body);
        if (charset.isEmpty()) {
            charset = "UTF-8";
        }
    }

    QMessageContentContainerPrivate *container(((QMessageContentContainer *)(this))->d_ptr);

    QMessageContentContainerId existingBodyId(bodyId());
    if (existingBodyId.isValid()) {
        if (existingBodyId == QMessageContentContainerPrivate::bodyContentId()) {
            // The body content is in the message itself
            container->setContent(body, mainType, subType, charset);
        } else {
            // The body content is in the first attachment
            QMessageContentContainerPrivate *attachmentContainer(container->attachment(existingBodyId)->d_ptr);
            attachmentContainer->setContent(body, mainType, subType, charset);
        }
    } else {
        if (container->_attachments.isEmpty()) {
            // Put the content directly into the message
            container->setContent(body, mainType, subType, charset);
            d_ptr->_bodyId = QMessageContentContainerPrivate::bodyContentId();
        } else {
            // Add the body as the first attachment
            QMessageContentContainer newBody;
            newBody.d_ptr->setContent(body, mainType, subType, charset);
            d_ptr->_bodyId = container->prependContent(newBody);
        }
    }

    d_ptr->_modified = true;
}
Ejemplo n.º 5
0
bool SMESH_MesherHelper::IsQuadraticSubMesh(const TopoDS_Shape& aSh)
{
  SMESHDS_Mesh* meshDS = GetMeshDS();
  // we can create quadratic elements only if all elements
  // created on subshapes of given shape are quadratic
  // also we have to fill myNLinkNodeMap
  myCreateQuadratic = true;
  mySeamShapeIds.clear();
  myDegenShapeIds.clear();
  TopAbs_ShapeEnum subType( aSh.ShapeType()==TopAbs_FACE ? TopAbs_EDGE : TopAbs_FACE );
  SMDSAbs_ElementType elemType( subType==TopAbs_FACE ? SMDSAbs_Face : SMDSAbs_Edge );

  int nbOldLinks = myNLinkNodeMap.size();

  TopExp_Explorer exp( aSh, subType );
  for (; exp.More() && myCreateQuadratic; exp.Next()) {
    if ( SMESHDS_SubMesh * subMesh = meshDS->MeshElements( exp.Current() )) {
      if ( SMDS_ElemIteratorPtr it = subMesh->GetElements() ) {
        while(it->more()) {
          const SMDS_MeshElement* e = it->next();
          if ( e->GetType() != elemType || !e->IsQuadratic() ) {
            myCreateQuadratic = false;
            break;
          }
          else {
            // fill NLinkNodeMap
            switch ( e->NbNodes() ) {
            case 3:
              AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(2)); break;
            case 6:
              AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(3));
              AddNLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(4));
              AddNLinkNode(e->GetNode(2),e->GetNode(0),e->GetNode(5)); break;
            case 8:
              AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(4));
              AddNLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(5));
              AddNLinkNode(e->GetNode(2),e->GetNode(3),e->GetNode(6));
              AddNLinkNode(e->GetNode(3),e->GetNode(0),e->GetNode(7));
              break;
            default:
              myCreateQuadratic = false;
              break;
            }
          }
        }
      }
    }
  }

  if ( nbOldLinks == myNLinkNodeMap.size() )
    myCreateQuadratic = false;

  if(!myCreateQuadratic) {
    myNLinkNodeMap.clear();
  }
  SetSubShape( aSh );

  return myCreateQuadratic;
}
Ejemplo n.º 6
0
bool CEvaluationNodeObject::setData(const Data & data)
{
  mData = data;

  if ((int) subType(mType) == (int) CN)
    mRegisteredObjectCN = data.substr(1, data.length() - 2);

  return true;
}
Ejemplo n.º 7
0
bool TypeChecker::typecheckFuncTerm(const func_term * ft)
{
	if(!isTyped) return true;
	func_decl_list::const_iterator fd = 
		std::find_if(thea->the_domain->functions->begin(),thea->the_domain->functions->end(),
				matchFunc(ft->getFunction()));
	if(fd==thea->the_domain->functions->end())
		return false;
	var_symbol_list::const_iterator arg = (*fd)->getArgs()->begin();
	const var_symbol_list::const_iterator argEnd = (*fd)->getArgs()->end();
	parameter_symbol_list::const_iterator i = ft->getArgs()->begin();
	const parameter_symbol_list::const_iterator e = ft->getArgs()->end();
	int idx = 1;
	for(; i != e && arg != argEnd;++i,++arg,++idx)
	{
		if(!subType(*i,*arg)) 
		{
			if(Verbose) {
				*report << "Type problem with function term (";
				*report << ft->getFunction()->getName();
				parameter_symbol_list::const_iterator it = ft->getArgs()->begin();
				parameter_symbol_list::const_iterator et = ft->getArgs()->end();
				for(;it != et;++it) {
					*report << " " << (*it)->getName();
				}
				*report << ") - parameter " << idx << " is incorrectly typed\n";
			}
			return false;
		};
	};
	if (arg != argEnd) {
		if(Verbose) {
			*report << "Problem with function term (";
			*report << ft->getFunction()->getName();
			parameter_symbol_list::const_iterator it = ft->getArgs()->begin();
			parameter_symbol_list::const_iterator et = ft->getArgs()->end();
			for(;it != et;++it) {
				*report << " " << (*it)->getName();
			}
			*report << ") - too few parameters\n";
		}
	}
	if (i != e) {
		if(Verbose) {
			*report << "Problem with function term (";
			*report << ft->getFunction()->getName();
			parameter_symbol_list::const_iterator it = ft->getArgs()->begin();
			parameter_symbol_list::const_iterator et = ft->getArgs()->end();
			for(;it != et;++it) {
				*report << " " << (*it)->getName();
			}
			*report << ") - too many parameters\n";
		}
	}

	return true;
};
Ejemplo n.º 8
0
vector<const_symbol *> TypeChecker::range(const parameter_symbol * v) 
{
	vector<const_symbol *> l;
	for(const_symbol_table::const_iterator i = thea->const_tab.begin();
			i != thea->const_tab.end();++i)
	{
		if(subType(i->second,v)) l.push_back(i->second);
	};
	
	return l;
};
Ejemplo n.º 9
0
void QMessage::setBody(const QString &bodyText, const QByteArray &mimeType)
{
    QByteArray mainType("text");
    QByteArray subType("plain");
    QByteArray charset;

    int index = mimeType.indexOf("/");
    if (index != -1) {
        mainType = mimeType.left(index).trimmed();

        subType = mimeType.mid(index + 1).trimmed();
        index = subType.indexOf(";");
        if (index != -1) {
            QString remainder = subType.mid(index + 1);
            subType = subType.left(index).trimmed();

            QRegExp charsetPattern("charset=(\\S+)");
            index = charsetPattern.indexIn(remainder);
            if (index != -1) {
                charset = charsetPattern.cap(1).toLatin1();
            }
        }
    }

    if (charset.isEmpty()) {
        charset = charsetFor(bodyText);
    }

    QMailMessageContentType ct;
    ct.setType(mainType);
    ct.setSubType(subType);
    ct.setCharset(charset);

    QMailMessageBody textBody(QMailMessageBody::fromData(bodyText, ct, QMailMessageBody::Base64));

    if (d_ptr->_message.multipartType() == QMailMessage::MultipartNone) {
        // Replace the body with this data
        d_ptr->_message.setBody(textBody);
    } else {
        // Replace any existing text with this part
        TextPartLocator locator;
        d_ptr->_message.foreachPart<TextPartLocator&>(locator);
        if (locator._location.isValid()) {
            // Update the existing body text part to contain the new text
            QMailMessagePart &bodyPart = d_ptr->_message.partAt(locator._location);
            bodyPart.setBody(textBody);
        } else {
            // Insert the text as the new first part
            QMailMessageContentDisposition cd(QMailMessageContentDisposition::Inline);
            QMailMessagePart part(QMailMessagePart::fromData(bodyText, ct, cd, QMailMessageBody::Base64));
            d_ptr->_message.prependPart(part);
        }
    }
}
Ejemplo n.º 10
0
bool CEvaluationNodeObject::compile(const CEvaluationTree * pTree)
{
  mpObject = NULL;

  switch ((int) subType(mType))
    {
      case CN:
      {
        const CExpression * pExpression = dynamic_cast< const CExpression * >(pTree);

        if (!pExpression) return false;

        mpObject =
          pExpression->getNodeObject(mRegisteredObjectCN);

        if (mpObject)
          mpValue = (C_FLOAT64 *) mpObject->getValuePointer();
        else
          mpValue = NULL;

        if (mpValue == NULL)
          {
            mValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();
            mpValue = &mValue;
            return false;
          }

        if (!mpObject->isValueDbl()) return false;

        mData = "<" + mRegisteredObjectCN + ">";
      }
      break;

      case POINTER:
        // We need to convert the data into a pointer
      {
        std::istringstream Pointer;
        void * pPointer;
        Pointer.str(mData.substr(2));
        Pointer.flags(std::ios::right | std::ios::hex | std::ios::showbase);
        Pointer >> pPointer;
        mpValue = (const C_FLOAT64 *) pPointer;
      }
      break;

      case INVALID:
        break;
    }

  return (getChild() == NULL); // We must not have any children.
}
Ejemplo n.º 11
0
void FixProviderImpl::unsubscribe(std::vector<std::string> symbols) {
    std::string uuid = FreeQuant::toGuidString();
    FIX::MDReqID mdReqId(uuid);
    FIX::SubscriptionRequestType subType(FIX::SubscriptionRequestType_DISABLE_PREVIOUS_SNAPSHOT_PLUS_UPDATE_REQUEST);
    FIX::MarketDepth marketDepth(1);

    FIX44::MarketDataRequest message(mdReqId, subType, marketDepth);

    message.set(FIX::MDUpdateType(FIX::MDUpdateType_INCREMENTAL_REFRESH));
    message.set(FIX::AggregatedBook(true));
    std::string s;
    s.append(1, FIX::Scope_LOCAL);

    FIX::Scope scope(s);
    message.set(scope);

    message.set(FIX::MDImplicitDelete(false));

    FIX44::MarketDataRequest::NoMDEntryTypes typeGroup;
    typeGroup.set(FIX::MDEntryType(FIX::MDEntryType_OPENING_PRICE));
    message.addGroup(typeGroup);
    typeGroup.set(FIX::MDEntryType(FIX::MDEntryType_CLOSING_PRICE));
    message.addGroup(typeGroup);
    typeGroup.set(FIX::MDEntryType(FIX::MDEntryType_TRADING_SESSION_HIGH_PRICE));
    message.addGroup(typeGroup);
    typeGroup.set(FIX::MDEntryType(FIX::MDEntryType_TRADING_SESSION_LOW_PRICE));
    message.addGroup(typeGroup);
    typeGroup.set(FIX::MDEntryType(FIX::MDEntryType_BID));
    message.addGroup(typeGroup);
    typeGroup.set(FIX::MDEntryType(FIX::MDEntryType_OFFER));
    message.addGroup(typeGroup);
    typeGroup.set(FIX::MDEntryType(FIX::MDEntryType_TRADE_VOLUME));
    message.addGroup(typeGroup);
    typeGroup.set(FIX::MDEntryType(FIX::MDEntryType_OPEN_INTEREST));
    message.addGroup(typeGroup);

    FIX44::MarketDataRequest::NoRelatedSym symGroup;
    symGroup.set(FIX::Symbol("GOOG"));
    message.addGroup(symGroup);
    symGroup.set(FIX::Symbol("IF1210"));
    message.addGroup(symGroup);


    FIX::SessionID sessionID;
    sessionID.fromString(_sessionString);
    try {
        FIX::Session::sendToTarget(message, sessionID);
    } catch (FIX::SessionNotFound&) {}
}
Ejemplo n.º 12
0
std::string CEvaluationNodeObject::getInfix() const
{
  switch ((int) subType(mType))
    {
      case CN:
        return "<" + mRegisteredObjectCN + ">";
        break;

      case POINTER:
        return mData;
        break;
    }

  return mData;
}
Ejemplo n.º 13
0
const CEvaluationNode::Data & CEvaluationNodeObject::getData() const
{
  static std::string data;

  switch ((int) subType(mType))
    {
      case CN:
        return data = "<" + mRegisteredObjectCN + ">";
        break;

      case POINTER:
        return mData;
        break;
    }

  return mData;
}
Ejemplo n.º 14
0
/*!
  Find the node in this node's children that has the
  given \a name. If this node is a QML class node, be
  sure to also look in the children of its property
  group nodes. Return the matching node or 0.
 */
Node *InnerNode::findNode(const QString& name)
{
    Node *node = childMap.value(name);
    if (node)
        return node;
    if ((type() == Fake) && (subType() == QmlClass)) {
        for (int i=0; i<children.size(); ++i) {
            Node* n = children.at(i);
            if (n->subType() == QmlPropertyGroup) {
                node = static_cast<InnerNode*>(n)->findNode(name);
                if (node)
                    return node;
            }
        }
    }
    return primaryFunctionMap.value(name);
}
Ejemplo n.º 15
0
bool TypeChecker::typecheckActionInstance(const plan_step * p)
{
	if(!isTyped) return true;
	operator_list::const_iterator op = 
		std::find_if(thea->the_domain->ops->begin(),thea->the_domain->ops->end(),
				matchOp(p->op_sym));
	if(op==thea->the_domain->ops->end())
		return false;
	var_symbol_list::const_iterator arg = (*op)->parameters->begin();
	const_symbol_list::const_iterator e = p->params->end();
	for(const_symbol_list::const_iterator i = p->params->begin();
			i != e;++i,++arg)
	{
		if(!subType(*i,*arg))
		{
			if(Verbose) *report << "Type problem in action " << *p << "\n";
			return false;
		};
	};
	return true;
};
Ejemplo n.º 16
0
QPainterPath DiagonalWipeStrategy::clipPath( int step, const QRect &area )
{
    qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount);

    QPoint vecx( static_cast<int>(2.0 * area.width() * percent), 0 ) ;
    QPoint vecy( 0, static_cast<int>( 2.0 * area.height() * percent ) );

    QPainterPath path;

    switch( subType() )
    {
        case DiagonalWipeEffectFactory::FromTopLeft:
            path.moveTo( area.topLeft() );
            path.lineTo( area.topLeft() + vecx );
            path.lineTo( area.topLeft() + vecy );
            break;
        case DiagonalWipeEffectFactory::FromTopRight:
            path.moveTo( area.topRight() );
            path.lineTo( area.topRight() - vecx );
            path.lineTo( area.topRight() + vecy );
            break;
        case DiagonalWipeEffectFactory::FromBottomLeft:
            path.moveTo( area.bottomLeft() );
            path.lineTo( area.bottomLeft() + vecx );
            path.lineTo( area.bottomLeft() - vecy );
            break;
        case DiagonalWipeEffectFactory::FromBottomRight:
            path.moveTo( area.bottomRight() );
            path.lineTo( area.bottomRight() - vecx );
            path.lineTo( area.bottomRight() - vecy );
            break;
        default:
            return QPainterPath();
    }

    path.closeSubpath();

    return path;
}
Ejemplo n.º 17
0
bool TypeChecker::subType(const pddl_typed_symbol * tp1,const pddl_typed_symbol * tp2)
{
	if(!isTyped) return true;
	if(tp1->type)
	{
		if(tp2->type)
		{
			return th.reachable(PTypeRef(tp1->type),PTypeRef(tp2->type));
		}
		else
		{
			if(tp2->either_types)
			{
				return th.reachable(PTypeRef(tp1->type),UTypeRef(tp2->either_types));
			};
			if(Verbose) *report << tp2->getName() << " has bad type definition\n";
			TypeException te;
			throw(te);
		};		
	}
	else
	{
		if(!tp1->either_types) 
		{
			if(Verbose) *report << "Object with unknown type: " << tp1->getName() << "\n";
			TypeException te;
			throw(te);
		};

		// The situation is now complicated by the fact that variables and constants
		// must be treated differently. Constants have either types representing 
		// conjunctions of types, while variables use them for disjunctions. 

		if(!tp1->either_types)
		{
			if(Verbose) *report << tp1->getName() << " badly typed!\n";
			TypeException te;
			throw(te);
		};
		
		if(dynamic_cast<const const_symbol*>(tp1))
		{
			// The following confirms that a constant is a subtype of a given type by
			// checking that one of its types is appropriate. 

			
			for(pddl_type_list::const_iterator i = tp1->either_types->begin();
						i != tp1->either_types->end();++i)
			{
				if(subType(*i,tp2)) return true;
			};
			return false;
		}
		else
		{
		
			for(pddl_type_list::const_iterator i = tp1->either_types->begin();
						i != tp1->either_types->end();++i)
			{
				if(!subType(*i,tp2)) return false;
			};
			return true;
		};
	};
};
QString IqPostmanVideoContentType::imageFormat() const
{
    return m_subTypeNames[subType()];
}
Ejemplo n.º 19
0
QCString partNode::subTypeString() const {
  DwString s;
  DwSubtypeEnumToStr( subType(), s );
  return s.c_str();
}
Ejemplo n.º 20
0
QPainterPath BarnDoorWipeStrategy::clipPath(int step, const QRect &area)
{
    qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount);
    if(reverse())
        percent = static_cast<qreal>(StepCount-step) / static_cast<qreal>(StepCount);

    int stepx = static_cast<int>(area.width() * percent);
    int stepy = static_cast<int>(area.height() * percent);

    int width_2 = area.width() >> 1;
    int height_2 = area.height() >> 1;

    QPainterPath path;

    switch(subType())
    {
        case BarnDoorWipeEffectFactory::Vertical:
        case BarnDoorWipeEffectFactory::VerticalReverse:
        {
            stepx = static_cast<int>(width_2 * percent);
            QPoint top(width_2, 0);
            QPoint bottom(width_2, area.height());
            path.moveTo(top - QPoint(stepx, 0));
            path.lineTo(top + QPoint(stepx, 0));
            path.lineTo(bottom + QPoint(stepx, 0));
            path.lineTo(bottom - QPoint(stepx, 0));
            break;
        }
        case BarnDoorWipeEffectFactory::Horizontal:
        case BarnDoorWipeEffectFactory::HorizontalReverse:
        {
            stepy = static_cast<int>(height_2 * percent);
            QPoint left(0, height_2);
            QPoint right(area.width(), height_2);
            path.moveTo(left + QPoint(0, stepy));
            path.lineTo(left - QPoint(0, stepy));
            path.lineTo(right - QPoint(0, stepy));
            path.lineTo(right + QPoint(0, stepy));
            break;
        }
        case BarnDoorWipeEffectFactory::DiagonalBottomLeft:
        case BarnDoorWipeEffectFactory::DiagonalBottomLeftReverse:
        {
            path.moveTo(area.bottomLeft() + QPoint(stepx, 0));
            path.lineTo(area.bottomLeft());
            path.lineTo(area.bottomLeft() - QPoint(0, stepy));
            path.lineTo(area.topRight() - QPoint(stepx, 0));
            path.lineTo(area.topRight());
            path.lineTo(area.topRight() + QPoint(0, stepy));
            break;
        }
        case BarnDoorWipeEffectFactory::DiagonalTopLeft:
        case BarnDoorWipeEffectFactory::DiagonalTopLeftReverse:
        {
            path.moveTo(area.topLeft() + QPoint(0, stepy));
            path.lineTo(area.topLeft());
            path.lineTo(area.topLeft() + QPoint(stepx, 0));
            path.lineTo(area.bottomRight() - QPoint(0, stepy));
            path.lineTo(area.bottomRight());
            path.lineTo(area.bottomRight() - QPoint(stepx, 0));
            break;
        }
        default:
            return QPainterPath();
    }

    path.closeSubpath();

    if(reverse())
    {
        QPainterPath areaPath;
        areaPath.addRect(area);
        path = areaPath.subtracted(path);
    }

    return path;
}
Ejemplo n.º 21
0
types::Function::ReturnValue sci_fieldnames(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), "fieldnames", 1);
        return types::Function::Error;
    }


    // FIXME : iso-functionnal to Scilab < 6
    // Works on other types except userType, {m,t}list and struct
    if (in[0]->isStruct() == false && in[0]->isMList() == false && in[0]->isTList() == false && in[0]->isUserType() == false)
    {
        out.push_back(types::Double::Empty());
        return types::Function::OK;
    }

    // STRUCT
    if (in[0]->isStruct() == true)
    {
        types::String* pFields = in[0]->getAs<types::Struct>()->getFieldNames();
        if (pFields)
        {
            out.push_back(pFields);
            //delete pFields;
        }
        else
        {
            out.push_back(types::Double::Empty());
        }
        return types::Function::OK;
    }

    types::InternalType* pIT;

    // TLIST or MLIST
    if (in[0]->isList() == true)
    {
        // We only need list capabilities to retrieve first argument as List.
        types::List *pInList = in[0]->getAs<types::List>();
        pIT = pInList->get(0);

        if (pIT == nullptr || pIT->isString() == false)
        {
            // FIXME : iso-functionnal to Scilab < 6
            // Works on other types except userType, {m,t}list and struct
            out.push_back(types::Double::Empty());
            return types::Function::OK;
        }
    }

    // USER-TYPE (typically an Xcos object)
    if (in[0]->isUserType() == true)
    {
        // We only need userType capabilities to retrieve first argument as UserType.
        types::UserType *pInUser = in[0]->getAs<types::UserType>();

        // Extract the sub-type
        std::wstring subType (pInUser->getShortTypeStr());

        // Extract the properties
        types::typed_list one(1, new types::Double(1));
        types::InternalType* pProperties = pInUser->extract(&one);
        if (pProperties == nullptr || pProperties->isString() == false)
        {
            // FIXME : iso-functionnal to Scilab < 6
            // Works on other types except userType, {m,t}list and struct
            out.push_back(types::Double::Empty());
            return types::Function::OK;
        }
        int nProp = ((types::String*) pProperties)->getSize();

        pIT = new types::String(nProp + 1, 1);
        ((types::String*) pIT)->set(0, subType.data());
        for (int i = 0; i < nProp; ++i)
        {
            ((types::String*) pIT)->set(i + 1, ((types::String*)pProperties)->get(i));
        }
    }

    types::String *pAllFields;
    if (pIT)
    {
        pAllFields = pIT->getAs<types::String>();
    }
    else
    {
        Scierror(999, _("Could not retrieve sub-type.\n"));
        return types::Function::Error;
    }
    wchar_t **pwcsAllStrings =  pAllFields->get();
    // shift to forget first value corresponding to type.
    //    ++pwcsAllStrings;


    types::String *pNewString = new types::String(pAllFields->getSize() - 1, 1, pwcsAllStrings + 1);

    out.push_back(pNewString);

    return types::Function::OK;
}
Ejemplo n.º 22
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;
}
Ejemplo n.º 23
0
CEvaluationNode * CEvaluationNode::create(const Type & type,
    const std::string & contents)
{
  CEvaluationNode * pNode = NULL;

  switch (CEvaluationNode::type(type))
    {
      case CEvaluationNode::CALL:
        pNode = new CEvaluationNodeCall((CEvaluationNodeCall::SubType) subType(type),
                                        contents);
        break;

      case CEvaluationNode::CHOICE:
        pNode = new CEvaluationNodeChoice((CEvaluationNodeChoice::SubType) subType(type),
                                          contents);
        break;

      case CEvaluationNode::CONSTANT:
        pNode = new CEvaluationNodeConstant((CEvaluationNodeConstant::SubType) subType(type),
                                            contents);
        break;

      case CEvaluationNode::DELAY:
        pNode = new CEvaluationNodeDelay((CEvaluationNodeDelay::SubType) subType(type),
                                         contents);
        break;

      case CEvaluationNode::FUNCTION:
        pNode = new CEvaluationNodeFunction((CEvaluationNodeFunction::SubType) subType(type),
                                            contents);
        break;

      case CEvaluationNode::LOGICAL:
        pNode = new CEvaluationNodeLogical((CEvaluationNodeLogical::SubType) subType(type),
                                           contents);
        break;

      case CEvaluationNode::NUMBER:
        pNode = new CEvaluationNodeNumber((CEvaluationNodeNumber::SubType) subType(type),
                                          contents);
        break;

      case CEvaluationNode::OBJECT:
        pNode = new CEvaluationNodeObject((CEvaluationNodeObject::SubType) subType(type),
                                          contents);
        break;

      case CEvaluationNode::OPERATOR:
        pNode = new CEvaluationNodeOperator((CEvaluationNodeOperator::SubType) subType(type),
                                            contents);
        break;

      case CEvaluationNode::STRUCTURE:
        pNode = new CEvaluationNodeStructure((CEvaluationNodeStructure::SubType) subType(type),
                                             contents);
        break;

      case CEvaluationNode::VARIABLE:
        pNode = new CEvaluationNodeVariable((CEvaluationNodeVariable::SubType) subType(type),
                                            contents);
        break;

      case CEvaluationNode::VECTOR:
        pNode = new CEvaluationNodeVector((CEvaluationNodeVector::SubType) subType(type),
                                          contents);
        break;

      case CEvaluationNode::WHITESPACE:
        pNode = new CEvaluationNodeWhiteSpace((CEvaluationNodeWhiteSpace::SubType) subType(type),
                                              contents);
        break;

      case CEvaluationNode::INVALID:
        pNode = new CEvaluationNode();
        break;

      case CEvaluationNode::MV_FUNCTION:
        break;
    }

  return pNode;
}
Ejemplo n.º 24
0
bool TypeChecker::typecheckProposition(const proposition * p)
{
	if(!isTyped || !thea->the_domain->predicates) return true;
	pred_decl_list::const_iterator prd = 
		std::find_if(thea->the_domain->predicates->begin(),thea->the_domain->predicates->end(),
				matchPred(p->head));
	if(prd==thea->the_domain->predicates->end())
	{
		if(p->head->getName()=="=") return true;
		if(Verbose) *report << "Predicate " << p->head->getName() << " not found\n";
		return false;
	};
	int idx = 1;

	var_symbol_list::const_iterator arg = (*prd)->getArgs()->begin();
	const var_symbol_list::const_iterator argEnd = (*prd)->getArgs()->end();
	
	parameter_symbol_list::const_iterator i = p->args->begin();
	const parameter_symbol_list::const_iterator e = p->args->end();

	for(;i != e && arg != argEnd;++i,++arg,++idx)
	{
		if(!subType(*i,*arg)) 
		{
			if(Verbose) {
				*report << "Type problem with proposition (";
				*report << p->head->getName();
				parameter_symbol_list::const_iterator it = p->args->begin();
				parameter_symbol_list::const_iterator et = p->args->end();
				for(;it != et;++it) {
					*report << " " << (*it)->getName();
				}
				*report << ") - parameter " << idx << " is incorrectly typed\n";			
			}
			return false;
		};
	};
	if (i != e) {
		if(Verbose) {
			*report << "Problem with proposition (";
			*report << p->head->getName();
			parameter_symbol_list::const_iterator it = p->args->begin();
			parameter_symbol_list::const_iterator et = p->args->end();
			for(;it != et;++it) {
				*report << " " << (*it)->getName();
			}
			*report << ") - too many parameters\n";
		}
		return false;
	}

	if (arg != argEnd) {
		if(Verbose) {
			*report << "Problem with proposition (";
			*report << p->head->getName();
			parameter_symbol_list::const_iterator it = p->args->begin();
			parameter_symbol_list::const_iterator et = p->args->end();
			for(;it != et;++it) {
				*report << " " << (*it)->getName();
			}
			*report << ") - too few parameters\n";
		}
		return false;
	}

	return true;
};
Ejemplo n.º 25
0
QPainterPath ZigZagWipeStrategy::clipPath(int step, const QRect &area)
{
    const int zigZagCount = 10;
    const qreal zigZagHeight = area.height() / static_cast<qreal>(zigZagCount);
    const qreal zigZagWidth = area.width() / static_cast<qreal>(zigZagCount);

    qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount);
    if(reverse())
        percent = static_cast<qreal>(StepCount-step) / static_cast<qreal>(StepCount);

    int stepx = static_cast<int>((area.width() + 2*zigZagWidth) * percent);
    int stepy = static_cast<int>((area.height() + 2*zigZagHeight) * percent);

    qreal zigZagHeight_2 = 0.5 * zigZagHeight;
    qreal zigZagWidth_2 = 0.5 * zigZagWidth;

    QPainterPath path;
    switch(subType())
    {
    case ZigZagWipeEffectFactory::FromTop:
    case ZigZagWipeEffectFactory::FromBottom:
    {
        qreal zigZagBase = stepy - zigZagHeight;
        qreal zigZagTip = stepy;
        path.moveTo(area.topLeft() - QPointF(0, zigZagHeight));
        path.lineTo(QPointF(area.left(), zigZagBase));
        for(int i = 0; i < zigZagCount; ++i)
        {
            path.lineTo(area.topLeft() + QPointF((2*i+1) * zigZagWidth_2, zigZagTip));
            path.lineTo(area.topLeft() + QPointF((i+1) * zigZagWidth, zigZagBase));
        }
        path.lineTo(area.topRight() - QPointF(0, zigZagHeight));
        break;
    }
    case ZigZagWipeEffectFactory::FromLeft:
    case ZigZagWipeEffectFactory::FromRight:
    {
        qreal zigZagBase = stepx - zigZagWidth;
        qreal zigZagTip = stepx;
        path.moveTo(area.topLeft() - QPointF(zigZagWidth, 0));
        path.lineTo(QPointF(zigZagBase, area.top()));
        for(int i = 0; i < zigZagCount; ++i)
        {
            path.lineTo(area.topLeft() + QPointF(zigZagTip, (2*i+1) * zigZagHeight_2));
            path.lineTo(area.topLeft() + QPointF(zigZagBase, (i+1) * zigZagHeight));
        }
        path.lineTo(area.bottomLeft() - QPointF(zigZagWidth, 0));
        break;
    }
    default:
        return QPainterPath();
    }

    path.closeSubpath();

    if(reverse())
    {
        QPainterPath areaPath;
        areaPath.addRect(area);
        path = areaPath.subtracted(path);
    }

    return path;
}
Ejemplo n.º 26
0
QPainterPath VeeWipeStrategy::clipPath(int step, const QRect &area)
{
    qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount);
    if(reverse())
        percent = static_cast<qreal>(StepCount-step) / static_cast<qreal>(StepCount);

    int stepx = static_cast<int>(2 * area.width() * percent);
    int stepy = static_cast<int>(2 * area.height() * percent);

    int width_2 = area.width() >> 1;
    int height_2 = area.height() >> 1;

    QPainterPath path;
    switch(subType())
    {
        case VeeWipeEffectFactory::FromTop:
        {
            QPoint move(0, stepy - 2 * area.height());
            path.moveTo(move + area.topLeft());
            path.lineTo(move + area.bottomLeft());
            path.lineTo(move + QPoint(width_2, 2 * area.height()));
            path.lineTo(move + area.bottomRight());
            path.lineTo(move + area.topRight());
            break;
        }
        case VeeWipeEffectFactory::FromRight:
        {
            QPoint move(2 * area.width()-stepx, 0);
            path.moveTo(move + area.topRight());
            path.lineTo(move + area.topLeft());
            path.lineTo(move + QPoint(-area.width(), height_2));
            path.lineTo(move + area.bottomLeft());
            path.lineTo(move + area.bottomRight());
            break;
        }
        case VeeWipeEffectFactory::FromBottom:
        {
            QPoint move(0, 2 * area.height() - stepy);
            path.moveTo(move + area.bottomLeft());
            path.lineTo(move + area.topLeft());
            path.lineTo(move + QPoint(width_2, -area.height()));
            path.lineTo(move + area.topRight());
            path.lineTo(move + area.bottomRight());
            break;
        }
        case VeeWipeEffectFactory::FromLeft:
        {
            QPoint move(stepx - 2 * area.width(), 0);
            path.moveTo(move + area.topLeft());
            path.lineTo(move + area.topRight());
            path.lineTo(move + QPoint(2 * area.width(), height_2));
            path.lineTo(move + area.bottomRight());
            path.lineTo(move + area.bottomLeft());
            break;
        }
        default:
            return QPainterPath();
    }

    path.closeSubpath();

    if(reverse())
    {
        QPainterPath areaPath;
        areaPath.addRect(area);
        path = areaPath.subtracted(path);
    }

    return path;
}