Ejemplo n.º 1
0
        /// <returns>a dictionary indicating for each node whether a winning strategy exists for even</returns>
        public Dictionary<Vertex, bool> Solve(LiftingStrategy liftStrat)
        {
            liftStrat.Initialize(this.pg);
            var rho = new StrategySet();
            foreach (var v in pg.V)
                rho[v] = new DTuple(d);

            // calculate fixpoint
            var workBatch = liftStrat.GetBatch();
            while (workBatch != null && workBatch.Count() > 0) {
                // lifting strategy determines which order in which to lift vertices
                foreach (var v in workBatch) {
                    // repeatedly lift vertex v
                    DTuple old;
                    int numIteration = 0;
                    do {
                        if (numIteration++ > 0)
                            liftStrat.Progress(); // tell strategy we made progress
                        old = rho[v];
                        Lift(v, rho);
                    } while (rho[v] > old);
                }
                // continue with next batch
                workBatch = liftStrat.GetBatch();
            }

            var ret = new Dictionary<Vertex, bool>();
            foreach (var entry in rho) ret[entry.Key] = entry.Value != MTop;
            return ret;
        }
Ejemplo n.º 2
0
 public DTuple Prog(StrategySet rho, Vertex v, Vertex w)
 {
     var rho_w = rho[w];
     var ret = new DTuple(rho_w.Count);
     if (v.PriorityEven) {
         // return the least m >= (up to p(v)) rho
         // easily constructed by copying values up to p(v) and padding with 0
         if (rho_w.IsTop) ret = MTop;
         else for (int i = 0; i < v.Priority; i++)
                 ret[i] = rho_w[i];
     }
     else {
         // return the least m > (up to p(v)) rho[w]
         // constructed by taking the first elem before p(v) that can be incremented, MTop otherwise
         for (int i = v.Priority; i >= 0; i--) {
             if (rho_w[i] < MMaxEven[i]) {
                 ret[i] = rho_w[i] + 1;
                 // leave stuff in front same as rho_w
                 for (int j = 0; j < i; j++)
                     ret[j] = rho_w[j];
                 // and set remainder to 0
                 for (int j = i + 1; j < d; j++)
                     ret[j] = 0;
                 break;
             }
             else if (i == 0) // nothing could be incremented
                 ret = MTop;
             else // copy this val, try to incr. next
                 ret[i] = rho_w[i];
         }
     }
     return ret;
 }
Ejemplo n.º 3
0
 public Jurdzinsky(ParityGame pg)
 {
     this.pg = pg;
     // determine maximum values for dtuple
     d = pg.V.Max(m => m.Priority) + 1; // d = max{ p(v) | v in V} + 1.
     MMaxEven = new DTuple(d);
     for (int i = 1; i < d; i += 2)
         MMaxEven[i] = pg.V.Count(v => v.Priority == i);
     //MMaxOdd = new DTuple(d);
     //for (int i = 0; i < d; i += 2)
     //	MMaxOdd[i] = pg.V.Count(v => v.Priority == i);
     MTop = new DTuple(d);
     for (int i = 0; i < d; i++)
         MTop[i] = int.MaxValue;
 }
        internal static bool TryHandleMethodArgumentTuple(ResolutionContext ctxt, ref bool add,
                                                          List <ISemantic> callArguments,
                                                          DMethod dm,
                                                          DeducedTypeDictionary deducedTypeDict, int currentParameter, ref int currentArg)
        {
            // .. so only check if it's an identifer & if the id represents a tuple parameter
            var id                 = dm.Parameters[currentParameter].Type as IdentifierDeclaration;
            var curNode            = dm as DNode;
            TemplateParameter tpar = null;

            while (curNode != null && !curNode.TryGetTemplateParameter(id.IdHash, out tpar))
            {
                curNode = curNode.Parent as DNode;
            }

            if (!(tpar is TemplateTupleParameter))
            {
                return(false);
            }

            int lastArgumentToTake = -1;

            /*
             * Note: an expression tuple parameter can occur also somewhere in between the parameter list!
             * void write(A...)(bool b, A a, double d) {}
             *
             * can be matched by
             * write(true, 1.2) as well as
             * write(true, "asdf", 1.2) as well as
             * write(true, 123, true, 'c', [3,4,5], 3.4) !
             */

            TemplateParameterSymbol tps;
            DTuple tuple = null;

            if (deducedTypeDict.TryGetValue(tpar, out tps) && tps != null)
            {
                if (tps.Base is DTuple)
                {
                    tuple = tps.Base as DTuple;
                    lastArgumentToTake = currentParameter + (tuple.Items == null ? 0 : (tuple.Items.Length - 1));
                }
                else
                {
                    // Error: Type param must be tuple!
                }
            }
            // - Get the (amount of) arguments that shall be put into the tuple
            else if (currentParameter == dm.Parameters.Count - 1)
            {
                // The usual case: A tuple of a variable length is put at the end of a parameter list..
                // take all arguments from i until the end of the argument list..
                // ; Also accept empty tuples
                lastArgumentToTake = callArguments.Count - 1;
            }
            else
            {
                // Get the type of the next expected parameter
                var nextExpectedParameter = DResolver.StripMemberSymbols(TypeDeclarationResolver.ResolveSingle(dm.Parameters[currentParameter + 1].Type, ctxt));

                // Look for the first argument whose type is equal to the next parameter's type..
                for (int k = currentArg; k < callArguments.Count; k++)
                {
                    if (ResultComparer.IsEqual(AbstractType.Get(callArguments[k]), nextExpectedParameter))
                    {
                        // .. and assume the tuple to go from i to the previous argument..
                        lastArgumentToTake = k - 1;
                        break;
                    }
                }
            }

            int argCountToHandle = lastArgumentToTake - currentArg + 1;

            if (tuple != null)
            {
                // - If there's been set an explicit type tuple, compare all arguments' types with those in the tuple
                if (tuple.Items != null)
                {
                    foreach (ISemantic item in tuple.Items)
                    {
                        if (currentArg >= callArguments.Count || !ResultComparer.IsImplicitlyConvertible(callArguments[currentArg++], AbstractType.Get(item), ctxt))
                        {
                            add = false;
                            return(true);
                        }
                    }
                }
            }
            else
            {
                // - If there was no explicit initialization, put all arguments' types into a type tuple
                var argsToTake = new ISemantic[argCountToHandle];
                callArguments.CopyTo(currentArg, argsToTake, 0, argsToTake.Length);
                currentArg += argsToTake.Length;
                var tt = new DTuple(null, argsToTake);
                tps = new TemplateParameterSymbol(tpar, tt);

                //   and set the actual template tuple parameter deduction
                deducedTypeDict[tpar] = tps;
            }
            add = true;
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Item1 - True, if isExpression returns true
        /// Item2 - If Item1 is true, it contains the type of the alias that is defined in the isExpression 
        /// </summary>
        private Tuple<bool, AbstractType> evalIsExpression_EvalSpecToken(IsExpression isExpression, AbstractType typeToCheck, bool DoAliasHandling = false)
        {
            bool r = false;
            AbstractType res = null;

            switch (isExpression.TypeSpecializationToken)
            {
                /*
                 * To handle semantic tokens like "return" or "super" it's just needed to
                 * look into the current resolver context -
                 * then, we'll be able to gather either the parent method or the currently scoped class definition.
                 */
                case DTokens.Struct:
                case DTokens.Union:
                case DTokens.Class:
                case DTokens.Interface:
                    if (r = typeToCheck is UserDefinedType &&
                        ((TemplateIntermediateType)typeToCheck).Definition.ClassType == isExpression.TypeSpecializationToken)
                        res = typeToCheck;
                    break;

                case DTokens.Enum:
                    if (!(typeToCheck is EnumType))
                        break;
                    {
                        var tr = (UserDefinedType)typeToCheck;
                        r = true;
                        res = tr.Base;
                    }
                    break;

                case DTokens.Function:
                case DTokens.Delegate:
                    if (typeToCheck is DelegateType)
                    {
                        var isFun = false;
                        var dgr = (DelegateType)typeToCheck;
                        if (!dgr.IsFunctionLiteral)
                            r = isExpression.TypeSpecializationToken == (
                                (isFun = ((DelegateDeclaration)dgr.DeclarationOrExpressionBase).IsFunction) ? DTokens.Function : DTokens.Delegate);
                        // Must be a delegate otherwise
                        else
                            isFun = !(r = isExpression.TypeSpecializationToken == DTokens.Delegate);

                        if (r)
                        {
                            //TODO
                            if (isFun)
                            {
                                // TypeTuple of the function parameter types. For C- and D-style variadic functions, only the non-variadic parameters are included.
                                // For typesafe variadic functions, the ... is ignored.
                            }
                            else
                            {
                                // the function type of the delegate
                            }
                        }
                    }
                    else // Normal functions are also accepted as delegates
                    {
                        r = isExpression.TypeSpecializationToken == DTokens.Delegate &&
                            typeToCheck is MemberSymbol &&
                            ((DSymbol)typeToCheck).Definition is DMethod;

                        //TODO: Alias handling, same as couple of lines above
                    }
                    break;

                case DTokens.Super: //TODO: Test this
                    var dc = DResolver.SearchClassLikeAt(ctxt.ScopedBlock, isExpression.Location) as DClassLike;

                    if (dc != null)
                    {
                        var udt = DResolver.ResolveBaseClasses(new ClassType(dc, dc, null), ctxt, true) as ClassType;

                        if (r = udt.Base != null && ResultComparer.IsEqual(typeToCheck, udt.Base))
                        {
                            var l = new List<AbstractType>();
                            if (udt.Base != null)
                                l.Add(udt.Base);
                            if (udt.BaseInterfaces != null && udt.BaseInterfaces.Length != 0)
                                l.AddRange(udt.BaseInterfaces);

                            res = new DTuple(isExpression, l);
                        }
                    }
                    break;

                case DTokens.Const:
                case DTokens.Immutable:
                case DTokens.InOut: // TODO?
                case DTokens.Shared:
                    if (r = typeToCheck.Modifier == isExpression.TypeSpecializationToken)
                        res = typeToCheck;
                    break;

                case DTokens.Return: // TODO: Test
                    IStatement _u = null;
                    var dm = DResolver.SearchBlockAt(ctxt.ScopedBlock, isExpression.Location, out _u) as DMethod;

                    if (dm != null)
                    {
                        var retType_ = TypeDeclarationResolver.GetMethodReturnType(dm, ctxt);

                        if (r = retType_ != null && ResultComparer.IsEqual(typeToCheck, retType_))
                            res = retType_;
                    }
                    break;
            }

            return new Tuple<bool, AbstractType>(r, res);
        }
        private bool TryHandleMethodArgumentTuple(ref bool add,
			List<ISemantic> callArguments, 
			DMethod dm, 
			DeducedTypeDictionary deducedTypeDict, int currentParameter,ref int currentArg)
        {
            // .. so only check if it's an identifer & if the id represents a tuple parameter
            var id = dm.Parameters[currentParameter].Type as IdentifierDeclaration;
            var curNode = dm as DNode;
            TemplateParameter tpar = null;
            while (curNode != null && !curNode.TryGetTemplateParameter(id.IdHash, out tpar))
                curNode = curNode.Parent as DNode;

            if (!(tpar is TemplateTupleParameter))
                return false;

            int lastArgumentToTake = -1;
            /*
             * Note: an expression tuple parameter can occur also somewhere in between the parameter list!
             * void write(A...)(bool b, A a, double d) {}
             *
             * can be matched by
             * write(true, 1.2) as well as
             * write(true, "asdf", 1.2) as well as
             * write(true, 123, true, 'c', [3,4,5], 3.4) !
             */

            TemplateParameterSymbol tps;
            DTuple tuple = null;
            if (deducedTypeDict.TryGetValue(tpar, out tps) && tps != null)
            {
                if (tps.Base is DTuple)
                {
                    tuple = tps.Base as DTuple;
                    lastArgumentToTake = currentParameter + (tuple.Items == null ? 0 : (tuple.Items.Length-1));
                }
                else
                {
                    // Error: Type param must be tuple!
                }
            }
            // - Get the (amount of) arguments that shall be put into the tuple
            else if (currentParameter == dm.Parameters.Count - 1)
            {
                // The usual case: A tuple of a variable length is put at the end of a parameter list..
                // take all arguments from i until the end of the argument list..
                lastArgumentToTake = callArguments.Count - 1;

                // Also accept empty tuples..
                if (callArguments.Count == 0)
                    lastArgumentToTake = 0;
            }
            else
            {
                // Get the type of the next expected parameter
                var nextExpectedParameter = DResolver.StripMemberSymbols(TypeDeclarationResolver.ResolveSingle(dm.Parameters[currentParameter + 1].Type, ctxt));

                // Look for the first argument whose type is equal to the next parameter's type..
                for (int k = currentArg; k < callArguments.Count; k++)
                {
                    if (ResultComparer.IsEqual(AbstractType.Get(callArguments[k]), nextExpectedParameter))
                    {
                        // .. and assume the tuple to go from i to the previous argument..
                        lastArgumentToTake = k - 1;
                        break;
                    }
                }
            }

            if (lastArgumentToTake < 0)
            {
                // An error occurred somewhere..
                add = false;
                return true;
            }

            int argCountToHandle = lastArgumentToTake - currentArg;
            if (argCountToHandle > 0)
                argCountToHandle++;

            if (tuple != null)
            {
                // - If there's been set an explicit type tuple, compare all arguments' types with those in the tuple
                if(tuple.Items != null)
                    foreach (ISemantic item in tuple.Items)
                    {
                        if (currentArg >= callArguments.Count || !ResultComparer.IsImplicitlyConvertible(callArguments[currentArg++], AbstractType.Get(item), ctxt))
                        {
                            add = false;
                            return true;
                        }
                    }
            }
            else
            {
                // - If there was no explicit initialization, put all arguments' types into a type tuple
                var argsToTake = new ISemantic[argCountToHandle];
                callArguments.CopyTo(currentArg, argsToTake, 0, argsToTake.Length);
                currentArg += argsToTake.Length;
                var tt = new DTuple(null, argsToTake);
                tps = new TemplateParameterSymbol(tpar, tt);

                //   and set the actual template tuple parameter deduction
                deducedTypeDict[tpar] = tps;
            }
            add = true;
            return true;
        }
Ejemplo n.º 7
0
 public void VisitDTuple(DTuple tps)
 {
     GenUfcsAndStaticProperties(tps);
 }
Ejemplo n.º 8
0
 public ulong VisitDTuple(DTuple t)
 {
     return(1001981);
 }
Ejemplo n.º 9
0
 public ISymbolValue VisitDTuple(DTuple t)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Item1 - True, if isExpression returns true
        /// Item2 - If Item1 is true, it contains the type of the alias that is defined in the isExpression
        /// </summary>
        private Tuple <bool, AbstractType> evalIsExpression_EvalSpecToken(IsExpression isExpression, AbstractType typeToCheck, bool DoAliasHandling = false)
        {
            bool         r   = false;
            AbstractType res = null;

            switch (isExpression.TypeSpecializationToken)
            {
            /*
             * To handle semantic tokens like "return" or "super" it's just needed to
             * look into the current resolver context -
             * then, we'll be able to gather either the parent method or the currently scoped class definition.
             */
            case DTokens.Struct:
            case DTokens.Union:
            case DTokens.Class:
            case DTokens.Interface:
                if (r = typeToCheck is UserDefinedType &&
                        ((TemplateIntermediateType)typeToCheck).Definition.ClassType == isExpression.TypeSpecializationToken)
                {
                    res = typeToCheck;
                }
                break;

            case DTokens.Enum:
                if (!(typeToCheck is EnumType))
                {
                    break;
                }
                {
                    var tr = (UserDefinedType)typeToCheck;
                    r   = true;
                    res = tr.Base;
                }
                break;

            case DTokens.Function:
            case DTokens.Delegate:
                if (typeToCheck is DelegateType)
                {
                    var isFun = false;
                    var dgr   = (DelegateType)typeToCheck;
                    if (!dgr.IsFunctionLiteral)
                    {
                        r = isExpression.TypeSpecializationToken == (
                            (isFun = ((DelegateDeclaration)dgr.DeclarationOrExpressionBase).IsFunction) ? DTokens.Function : DTokens.Delegate);
                    }
                    // Must be a delegate otherwise
                    else
                    {
                        isFun = !(r = isExpression.TypeSpecializationToken == DTokens.Delegate);
                    }

                    if (r)
                    {
                        //TODO
                        if (isFun)
                        {
                            // TypeTuple of the function parameter types. For C- and D-style variadic functions, only the non-variadic parameters are included.
                            // For typesafe variadic functions, the ... is ignored.
                        }
                        else
                        {
                            // the function type of the delegate
                        }
                    }
                }
                else                         // Normal functions are also accepted as delegates
                {
                    r = isExpression.TypeSpecializationToken == DTokens.Delegate &&
                        typeToCheck is MemberSymbol &&
                        ((DSymbol)typeToCheck).Definition is DMethod;

                    //TODO: Alias handling, same as couple of lines above
                }
                break;

            case DTokens.Super:                     //TODO: Test this
                var dc = DResolver.SearchClassLikeAt(ctxt.ScopedBlock, isExpression.Location) as DClassLike;

                if (dc != null)
                {
                    var udt = DResolver.ResolveBaseClasses(new ClassType(dc, dc, null), ctxt, true) as ClassType;

                    if (r = udt.Base != null && ResultComparer.IsEqual(typeToCheck, udt.Base))
                    {
                        var l = new List <AbstractType>();
                        if (udt.Base != null)
                        {
                            l.Add(udt.Base);
                        }
                        if (udt.BaseInterfaces != null && udt.BaseInterfaces.Length != 0)
                        {
                            l.AddRange(udt.BaseInterfaces);
                        }

                        res = new DTuple(isExpression, l);
                    }
                }
                break;

            case DTokens.Const:
            case DTokens.Immutable:
            case DTokens.InOut:                     // TODO?
            case DTokens.Shared:
                if (r = typeToCheck.Modifier == isExpression.TypeSpecializationToken)
                {
                    res = typeToCheck;
                }
                break;

            case DTokens.Return:                     // TODO: Test
                IStatement _u = null;
                var        dm = DResolver.SearchBlockAt(ctxt.ScopedBlock, isExpression.Location, out _u) as DMethod;

                if (dm != null)
                {
                    var retType_ = TypeDeclarationResolver.GetMethodReturnType(dm, ctxt);

                    if (r = retType_ != null && ResultComparer.IsEqual(typeToCheck, retType_))
                    {
                        res = retType_;
                    }
                }
                break;
            }

            return(new Tuple <bool, AbstractType>(r, res));
        }
Ejemplo n.º 11
0
 public ISymbolValue VisitDTuple(DTuple t)
 {
     return(new TypeValue(t));
 }