Beispiel #1
0
Expression::Ptr ExpressionFactory::createExpression(const QString &expr,
                                                    const StaticContext::Ptr &context,
                                                    const QXmlQuery::QueryLanguage lang,
                                                    const SequenceType::Ptr &requiredType,
                                                    const QUrl &queryURI,
                                                    const QXmlName &initialTemplateName)
{
    if(lang == QXmlQuery::XSLT20)
    {
        QByteArray query(expr.toUtf8());
        QBuffer buffer(&query);
        buffer.open(QIODevice::ReadOnly);

        return createExpression(&buffer,
                                context,
                                lang,
                                requiredType,
                                queryURI,
                                initialTemplateName);
    }
    else
    {
        return createExpression(Tokenizer::Ptr(new XQueryTokenizer(expr, queryURI)),
                                context,
                                lang,
                                requiredType,
                                queryURI,
                                initialTemplateName);
    }
}
Beispiel #2
0
Expression::Ptr ExpressionFactory::createExpression(QIODevice *const device,
                                                    const StaticContext::Ptr &context,
                                                    const QXmlQuery::QueryLanguage lang,
                                                    const SequenceType::Ptr &requiredType,
                                                    const QUrl &queryURI,
                                                    const QXmlName &initialTemplateName)
{
    Q_ASSERT(device);
    Q_ASSERT(device->isReadable());

    Tokenizer::Ptr tokenizer;

    if(lang == QXmlQuery::XQuery10)
    {

        tokenizer = Tokenizer::Ptr(new XQueryTokenizer(QString::fromUtf8(device->readAll()), queryURI));
    }
    else
    {
        Q_ASSERT(lang == QXmlQuery::XSLT20);
        tokenizer = Tokenizer::Ptr(new XSLTTokenizer(device, queryURI, context, context->namePool()));
    }

    return createExpression(tokenizer, context, lang, requiredType, queryURI, initialTemplateName);
}
Beispiel #3
0
/*!
  \reimp
*/
void QThemeLevelItem::loadAttributes(QXmlStreamReader &reader)
{
    QThemeImageItem::loadAttributes(reader);
    if (!reader.attributes().value("count").isEmpty())
        d->count = reader.attributes().value("count").toString().toInt();
    if (!reader.attributes().value("min").isEmpty())
        d->min = reader.attributes().value("min").toString().toInt();
    if (!reader.attributes().value("max").isEmpty())
        d->max = reader.attributes().value("max").toString().toInt();
    if (!reader.attributes().value("loop").isEmpty())
        d->loop = reader.attributes().value("loop").toString().toInt();
    if (!reader.attributes().value("looprev").isEmpty())
        d->looprev = reader.attributes().value("looprev").toString().toInt();

    if (d->animInfo)
        delete d->animInfo;
    d->animInfo = new QThemeAnimationFrameInfo(this, reader.attributes().value("delay").toString().toInt());

    if (!reader.attributes().value("play").isEmpty()) {
        QString play = reader.attributes().value("play").toString();
        if (isExpression(play)) {
            d->playExpression = createExpression(strippedExpression(play));
            if (d->playExpression)
                expressionChanged(d->playExpression);
        } else if (play != "no") {
            /*            if (!attribute("playing"))*/
            start();
        }
    }
}
Beispiel #4
0
QgsScaleExpression::QgsScaleExpression( Type type, const QString& baseExpression, double minValue, double maxValue, double minSize, double maxSize, double nullSize, double exponent )
    : QgsExpression( createExpression( type, baseExpression, minValue, maxValue, minSize, maxSize, nullSize, exponent ) )
    , mExpression( baseExpression )
    , mType( type )
    , mMinSize( minSize )
    , mMaxSize( maxSize )
    , mMinValue( minValue )
    , mMaxValue( maxValue )
    , mNullSize( nullSize )
    , mExponent( 1 )
{
  switch ( type )
  {
    case Linear:
      mExponent = 1;
      break;
    case Area:
      mExponent = .5;
      break;
    case Flannery:
      mExponent = .57;
      break;
    case Exponential:
      mExponent = exponent;
      break;
    case Unknown:
      break;
  }
}
Beispiel #5
0
struct memorycontainer* appendLetWithOperatorStatement(char * identifier, struct memorycontainer* expressionContainer, unsigned char operator) {
	unsigned char token=0;
	if (operator == 0) {
		token=ADD_TOKEN;
	} else if (operator == 1) {
		token=SUB_TOKEN;
	} else if (operator == 2) {
		token=MUL_TOKEN;
	} else if (operator == 3 || operator == 6) {
		token=DIV_TOKEN;
	} else if (operator == 4) {
		token=MOD_TOKEN;
	} else if (operator == 5) {
		token=POW_TOKEN;
	} else {
		fprintf(stderr, "Can not find operator with id of %c\n", operator);
	}
	struct memorycontainer* rhs=createExpression(token, createIdentifierExpression(identifier), expressionContainer);
	if (operator == 6) {
		// Floor
		struct memorycontainer* mathCommand=createIntegerExpression(FLOOR_MATHS_OP);
		struct stack_t * argStack=getNewStack();
		pushExpression(argStack, mathCommand);
		pushExpression(argStack, rhs);
		rhs=appendNativeCallFunctionStatement(NATIVE_RTL_MATH_STR, argStack, NULL);
	}
	return appendLetStatement(identifier, rhs);
}
/*  getPhiFunction
 *
 *  This function will compare the liveness list from two parent 
 *  and create a phifunction in SSA form without the condition
 *
 *  @listA  a list of subscripts that was living at parent A
 *  @listB  a list of subscripts that was living at parent B
 *  @subs   The subscript that required a phiFunction
 *
 */
Expression* getPhiFunction(LinkedList* listA, LinkedList* listB, Subscript* subs){
  Subscript *subsA  = NULL;
  Subscript *subsB  = NULL;
  
  ListElement *ptrA, *ptrB;
  ptrA = listA->head;
  ptrB = listB->head;
  
  int subsName = subs->name;
  /*****************************************************************
   *  Find the latest index for operand A and operand B at this point
   *****************************************************************/
  while(ptrA != NULL && ((Subscript*)ptrA->node)->name != subsName)
    ptrA = ptrA->next;
  if(ptrA != NULL)
    subsA = ptrA->node;
  else
    ThrowError(ERR_UNDECLARE_VARIABLE, "Undefine reference to Subscript %c", subsName);
  
  while(ptrB != NULL && ((Subscript*)ptrB->node)->name != subsName)
    ptrB = ptrB->next;
  if(ptrB != NULL)
    subsB = ptrB->node;
  else
    ThrowError(ERR_UNDECLARE_VARIABLE, "Undefine reference to Subscript %c", subsName);
  
  //Create the phifunction without the condition yet
  Expression* phiFunction   = createExpression(subs->name, PHI_FUNC, subsA->name, subsB->name, 0);
  phiFunction->id.index     = subs->index + 1;
  phiFunction->oprdA.index  = subsA->index;
  phiFunction->oprdB.index  = subsB->index;
  
  return phiFunction;
}
Beispiel #7
0
struct memorycontainer* createFloorDivExpression(struct memorycontainer* expression1, struct memorycontainer* expression2) {
    struct memorycontainer* divExpr=createExpression(DIV_TOKEN, expression1, expression2);
    struct memorycontainer* mathCommand=createIntegerExpression(FLOOR_MATHS_OP);
    struct stack_t * argStack=getNewStack();
    pushExpression(argStack, mathCommand);
    pushExpression(argStack, divExpr);
    divExpr=appendNativeCallFunctionStatement(NATIVE_RTL_MATH_STR, argStack, NULL);
	return divExpr;
}
static void createRules( strus::PatternMatcherInstanceInterface* ptinst, const GlobalContext* ctx, const std::vector<TreeNode*> treear)
{
	std::vector<TreeNode*>::const_iterator ti = treear.begin(), te = treear.end();
	for (unsigned int tidx=0; ti != te; ++ti,++tidx)
	{
		createExpression( ptinst, ctx, *ti);
		ptinst->definePattern( (*ti)->name(), ""/*formatstring*/, true);
	}
}
QgsScaleExpression::QgsScaleExpression( Type type, const QString& baseExpression, double minValue, double maxValue, double minSize, double maxSize )
    : QgsExpression( createExpression( type, baseExpression, minValue, maxValue, minSize, maxSize ) )
    , mExpression( baseExpression )
    , mType( type )
    , mMinSize( minSize )
    , mMaxSize( maxSize )
    , mMinValue( minValue )
    , mMaxValue( maxValue )
{

}
Expression::Ptr ExpressionFactory::createExpression(QIODevice *const device,
                                                    const StaticContext::Ptr &context,
                                                    const LanguageAccent lang,
                                                    const SequenceType::Ptr &requiredType,
                                                    const QUrl &queryURI)
{
    Q_ASSERT(device);
    Q_ASSERT(device->isReadable());

    // TODO We need to do encoding detection.
    return createExpression(QString::fromUtf8(device->readAll()), context, lang, requiredType, queryURI);
}
Beispiel #11
0
/*!
  \reimp
*/
void QThemeLevelItem::constructionComplete()
{
    if (!d->text.isEmpty()) {
        if (isExpression(d->text)) {
            d->frameExpression = createExpression(strippedExpression(d->text));
            if (d->frameExpression != 0)
                expressionChanged(d->frameExpression);
        } else {
            setFrame(d->text.toInt());
        }
        d->text = QString();
    }
    QThemeImageItem::constructionComplete();
}
static void createExpression( strus::PatternMatcherInstanceInterface* ptinst, const GlobalContext* ctx, const TreeNode* tree)
{
	if (tree->term() && tree->args().empty())
	{
		ptinst->pushTerm( tree->term());
	}
	else
	{
		std::vector<TreeNode*>::const_iterator ti = tree->args().begin(), te = tree->args().end();
		for (; ti != te; ++ti)
		{
			createExpression( ptinst, ctx, *ti);
		}
		ptinst->pushExpression( tree->op(), tree->args().size(), tree->range(), tree->cardinality());
	}
	if (tree->variable())
	{
		ptinst->attachVariable( tree->variable());
	}
}
void QgsSizeScaleWidget::updatePreview()
{
  if ( !mSymbol || !mLayer )
    return;

  QScopedPointer<QgsScaleExpression> expr( createExpression() );
  QList<double> breaks = QgsSymbolLayerV2Utils::prettyBreaks( expr->minValue(), expr->maxValue(), 4 );

  treeView->setIconSize( QSize( 512, 512 ) );
  mPreviewList.clear();
  int widthMax = 0;
  for ( int i = 0; i < breaks.length(); i++ )
  {
    QScopedPointer< QgsMarkerSymbolV2 > symbol( dynamic_cast<QgsMarkerSymbolV2*>( mSymbol->clone() ) );
    symbol->setDataDefinedSize( QgsDataDefined() );
    symbol->setDataDefinedAngle( QgsDataDefined() ); // to avoid symbol not beeing drawn
    symbol->setSize( expr->size( breaks[i] ) );
    QgsSymbolV2LegendNode node( mLayerTreeLayer, QgsLegendSymbolItemV2( symbol.data(), QString::number( i ), 0 ) );
    const QSize sz( node.minimumIconSize() );
    node.setIconSize( sz );
    QScopedPointer< QStandardItem > item( new QStandardItem( node.data( Qt::DecorationRole ).value<QPixmap>(), QString::number( breaks[i] ) ) );
    widthMax = qMax( sz.width(), widthMax );
    mPreviewList.appendRow( item.take() );
  }

  // center icon and align text left by giving icons the same width
  // @todo maybe add some space so that icons don't touch
  for ( int i = 0; i < breaks.length(); i++ )
  {
    QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
    QPixmap enlarged( widthMax, img.height() );
    // fill transparent and add original image
    enlarged.fill( Qt::transparent );
    QPainter p( &enlarged );
    p.drawPixmap( QPoint(( widthMax - img.width() ) / 2, 0 ), img );
    p.end();
    mPreviewList.item( i )->setIcon( enlarged );
  }
}
Beispiel #14
0
struct memorycontainer* createLeqExpression(struct memorycontainer* expression1, struct memorycontainer* expression2) {
	return createExpression(LEQ_TOKEN, expression1, expression2);
}
Beispiel #15
0
static int compute_prob(void)
/* this is the function that implements the compute_prob predicate used in pp.pl
*/
{
    YAP_Term out,arg1,arg2,arg3,arg4;
    variables  vars;
    expr expression;
    DdNode * function;
    DdManager * mgr;
    int nBVar,i,intBits,create_dot;
    FILE * file;
    DdNode * array[1];
    double prob;
    char * onames[1];
    char inames[1000][20];
    char * names[1000];
    tablerow * nodes;

    arg1=YAP_ARG1;
    arg2=YAP_ARG2;
    arg3=YAP_ARG3;
    arg4=YAP_ARG4;

    mgr=Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0);
    create_dot=YAP_IntOfTerm(arg4);
    vars=createVars(arg1,mgr,create_dot,inames);

    //Cudd_PrintInfo(mgr,stderr);

    /* automatic variable reordering, default method CUDD_REORDER_SIFT used */
    //printf("status %d\n",Cudd_ReorderingStatus(mgr,&order));
    //printf("order %d\n",order);

    Cudd_AutodynEnable(mgr,CUDD_REORDER_SAME);
    /*   Cudd_AutodynEnable(mgr, CUDD_REORDER_RANDOM_PIVOT);
      printf("status %d\n",Cudd_ReorderingStatus(mgr,&order));
            printf("order %d\n",order);
      printf("%d",CUDD_REORDER_RANDOM_PIVOT);
    */


    expression=createExpression(arg2);

    function=retFunction(mgr,expression,vars);

    /* the BDD build by retFunction is converted to an ADD (algebraic decision diagram)
    because it is easier to interpret and to print */
    //add=Cudd_BddToAdd(mgr,function);
    //Cudd_PrintInfo(mgr,stderr);

    if (create_dot)
        /* if specified by the user, a dot file for the BDD is written to cpl.dot */
    {
        nBVar=vars.nBVar;
        for(i=0; i<nBVar; i++)
            names[i]=inames[i];
        array[0]=function;
        onames[0]="Out";
        file = open_file("cpl.dot", "w");
        Cudd_DumpDot(mgr,1,array,names,onames,file);
        fclose(file);
    }
    nodes=init_table(vars.nBVar);
    intBits=sizeof(unsigned int)*8;
    prob=Prob(function,vars,nodes);
    out=YAP_MkFloatTerm(prob);
    destroy_table(nodes,vars.nBVar);

    Cudd_Quit(mgr);
    for(i=0; i<vars.nVar; i++)
    {
        free(vars.varar[i].probabilities);
        free(vars.varar[i].booleanVars);
    }
    free(vars.varar);
    free(vars.bVar2mVar);
    for(i=0; i<expression.nTerms; i++)
    {
        free(expression.terms[i].factors);
    }
    free(expression.terms);
    return(YAP_Unify(out,arg3));
}
QgsDataDefined QgsSizeScaleWidget::dataDefined() const
{
  QScopedPointer<QgsScaleExpression> exp( createExpression() );
  return QgsDataDefined( exp.data() );
}
Beispiel #17
0
struct memorycontainer* createModExpression(struct memorycontainer* expression1, struct memorycontainer* expression2) {
	return createExpression(MOD_TOKEN, expression1, expression2);
}
Beispiel #18
0
struct memorycontainer* createDivExpression(struct memorycontainer* expression1, struct memorycontainer* expression2) {
	return createExpression(DIV_TOKEN, expression1, expression2);
}
Beispiel #19
0
struct memorycontainer* createSubExpression(struct memorycontainer* expression1, struct memorycontainer* expression2) {
	return createExpression(SUB_TOKEN, expression1, expression2);
}
Beispiel #20
0
struct memorycontainer* createGtExpression(struct memorycontainer* expression1, struct memorycontainer* expression2) {
	return createExpression(GT_TOKEN, expression1, expression2);
}
Beispiel #21
0
struct memorycontainer* createPowExpression(struct memorycontainer* expression1, struct memorycontainer* expression2) {
	return createExpression(POW_TOKEN, expression1, expression2);
}
Beispiel #22
0
static int compute_prob(void)
/* this is the function that implements the compute_prob predicate used in pp.pl
*/
{
	YAP_Term out,arg1,arg2,arg3,arg4;
	array_t * variables,* expression, * bVar2mVar;
	DdNode * function, * add;
	DdManager * mgr;
	int nBVar,i,j,intBits,create_dot;
        FILE * file;
        DdNode * array[1];
        char * onames[1];
        char inames[1000][20];
	char * names[1000];
	GHashTable  * nodes; /* hash table that associates nodes with their probability if already 
				computed, it is defined in glib */
	Cudd_ReorderingType order;
	arg1=YAP_ARG1;
	arg2=YAP_ARG2;
	arg3=YAP_ARG3;
	arg4=YAP_ARG4;

  	mgr=Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0);
	variables=array_alloc(variable,0);
	bVar2mVar=array_alloc(int,0);
	create_dot=YAP_IntOfTerm(arg4);
	createVars(variables,arg1,mgr,bVar2mVar,create_dot,inames);
        //Cudd_PrintInfo(mgr,stderr);

	/* automatic variable reordering, default method CUDD_REORDER_SIFT used */
	//printf("status %d\n",Cudd_ReorderingStatus(mgr,&order));
	//printf("order %d\n",order);

	Cudd_AutodynEnable(mgr,CUDD_REORDER_SAME); 
/*	 Cudd_AutodynEnable(mgr, CUDD_REORDER_RANDOM_PIVOT);
	printf("status %d\n",Cudd_ReorderingStatus(mgr,&order));
        printf("order %d\n",order);
	printf("%d",CUDD_REORDER_RANDOM_PIVOT);
*/


	expression=array_alloc(array_t *,0);
	createExpression(expression,arg2);	

	function=retFunction(mgr,expression,variables);
	/* the BDD build by retFunction is converted to an ADD (algebraic decision diagram)
	because it is easier to interpret and to print */
	add=Cudd_BddToAdd(mgr,function);
	//Cudd_PrintInfo(mgr,stderr);

	if (create_dot)
	/* if specified by the user, a dot file for the BDD is written to cpl.dot */
	{	
		nBVar=array_n(bVar2mVar);
		for(i=0;i<nBVar;i++)
		   names[i]=inames[i];
	  	array[0]=add;
		onames[0]="Out";
		file = open_file("cpl.dot", "w");
		Cudd_DumpDot(mgr,1,array,names,onames,file);
  		fclose(file);
	}
	
	nodes=g_hash_table_new(my_hash,my_equal);
	intBits=sizeof(unsigned int)*8;
	/* dividend is a global variable used by my_hash 
	   it is equal to an unsigned int with binary representation 11..1 */ 
	dividend=1;
	for(j=1;j<intBits;j++)
	{
		dividend=(dividend<<1)+1;
	}
	out=YAP_MkFloatTerm(Prob(add,variables,bVar2mVar,nodes));
	g_hash_table_foreach (nodes,dealloc,NULL);
	g_hash_table_destroy(nodes);
	Cudd_Quit(mgr);
	array_free(variables);
 	array_free(bVar2mVar);
	array_free(expression);
    	return(YAP_Unify(out,arg3));
}