Example #1
0
        // does a for and a quantified expression
        // takes the iterator for var expr paris
        private void doForExpr(IEnumerator iter, Expr expr)
        {
            int scopes = 0;

            // add variables to scope and check the binding sequence
            while (iter.MoveNext())
            {
                VarExprPair pair = (VarExprPair)iter.Current;

                QName @var = pair.varname();
                if (!expandVarQName(@var))
                {
                    reportBadPrefix(@var.prefix());
                }

                Expr e = pair.expr();

                e.accept(this);

                pushScope(@var, BuiltinTypeLibrary.XS_ANYTYPE);
                scopes++;
            }

            expr.accept(this);

            // kill the scopes
            for (int i = 0; i < scopes; i++)
            {
                popScope();
            }
        }
Example #2
0
        private void printVarExprPairs(IEnumerator i)
        {
            while (i.MoveNext())
            {
                VarExprPair pair = (VarExprPair)i.Current;

                QName @var = pair.varname();
                Expr  e    = pair.expr();

                e.accept(this);
            }
        }
Example #3
0
        // does a for and a quantified expression
        // takes the iterator for var expr paris
        private void doForExpr(IEnumerator iter, Expr expr)
        {
            var vars = new ArrayList();

            // go through expression and cache variables
            while (iter.MoveNext())
            {
                VarExprPair pair = (VarExprPair)iter.Current;

                QName @var = pair.varname();
                Expr  e    = pair.expr();

                // XXX this is wrong!
                // need to define new scope, and reference "inner scope"
                // [shadow outer vars]

                /*
                 * if(_sc.variable_exists(var)) report_error(new
                 * StaticNameError("Variable " + var.string() +
                 * " already defined"));
                 */
                // ok we can cheat here cuz we only care about variable
                // "presence" not its specific instance / value so we
                // can fakely shadow without creating explicit scopes
                // if variable already exists.... then leave it there...
                // [we do not need to create a new instance and delete
                // it at the end]
                // we only need to if variable does not exist
                // XXX: i fink this is all wrong
                vars.Add(@var);

                e.accept(this);
            }

            // add variables to scope
            for (IEnumerator i = vars.GetEnumerator(); i.MoveNext();)
            {
                QName @var = (QName)i.Current;
            }

            // do the bounded expression
            expr.accept(this);

            // remove variables
        }
Example #4
0
        ///
        /// <param name="qex">
        ///            is the Quantified expression. </param>
        /// <returns> qex expression. </returns>
        // XXX: code duplication
        public virtual object visit(QuantifiedExpr qex)
        {
            QuantifiedExpr last  = qex;
            Expr           ret   = qex.expr();
            int            depth = 0;

            for (IEnumerator i = qex.iterator(); i.MoveNext();)
            {
                VarExprPair ve = (VarExprPair)i.Current;

                // ok we got nested fors...
                if (depth > 0)
                {
                    var pairs = new List <VarExprPair>();
                    pairs.Add(ve);

                    QuantifiedExpr qe = new QuantifiedExpr(qex.type(), pairs, ret);
                    last.set_expr(qe);

                    last = qe;
                }

                depth++;
            }

            // normalize return value, and set it to the last for expr
            ret.accept(this);

            // get rid of the pairs in the parent (original) for
            if (depth > 1)
            {
                qex.truncate_pairs();
            }

            return(qex);
        }