Exemplo n.º 1
0
        public override CSPProcess Rename(Dictionary <string, Expression> constMapping, Dictionary <string, string> newDefNames, Dictionary <string, Definition> renamedProcesses)
        {
            Expression[] newArguments = new Expression[Args.Length];
            Array.Copy(Args, newArguments, Args.Length);
            for (int i = 0; i < Args.Length; i++)
            {
                newArguments[i] = constMapping.ContainsKey(Args[i].ToString()) ? constMapping[Args[i].ToString()] : Args[i];
            }

            if (!newDefNames.ContainsKey(Name))
            {
                newDefNames.Add(Name, Name + "-" + Common.Classes.Ultility.Ultility.PPStringList(newArguments) + "-");
            }
            string newName = newDefNames[Name];


            DefinitionRef newRef = new DefinitionRef(newName, new Expression[0]);

            newRef.IsBDDEncodableProp = IsBDDEncodableProp;

            if (renamedProcesses.ContainsKey(newName))
            {
                newRef.Def = renamedProcesses[newName];
            }
            else
            {
                Def.Name   = newName;
                newRef.Def = Def.Rename(constMapping, newDefNames, renamedProcesses, new List <Expression>(Args));

                //Remove this new name from the dictionary for a new DefRef
                newDefNames.Remove(Name);
            }

            return(newRef);
        }
Exemplo n.º 2
0
        public override Process ClearConstant(Dictionary <string, Expression> constMapping)
        {
            Expression[]  newArgs = new Expression[Args.Length];
            DefinitionRef newRef  = null;

            // Console.WriteLine("clearing constant for " + this.Name +" Def"+Def);
            try {
                for (int i = 0; i < Args.Length; i++)
                {
                    Expression arg = Args[i].ClearConstant(constMapping);

                    if (!arg.HasVar)
                    {
                        newArgs[i] = EvaluatorDenotational.Evaluate(arg, null);
                    }
                    else
                    {
                        newArgs[i] = arg;
                    }
                }

                newRef = new DefinitionRef(Name, newArgs);

                //this is a special cases happened in the middle of parsing, where the current Def is not initialized in the parser.
                //so need to put the newRef into the def list to initialize the Def once the parsing is done.
                if (Def == null)
                {
                    //    EGTreeWalker.dlist.Add(newRef);
                    //    EGTreeWalker.dtokens.Add(null);
                }
                else
                {
                    newRef.Def = Def;
                }
            } catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw e;
            }
            return(newRef);
        }
Exemplo n.º 3
0
        public List <DefinitionRef> GetIndexedDefRef(Dictionary <string, Expression> constMapping)
        {
            if (ContainedDefRefs == null)
            {
                return(null);
            }

            List <ParallelDefinition> newDefinitions = new List <ParallelDefinition>();

            foreach (ParallelDefinition definition in Definitions)
            {
                ParallelDefinition newPD = definition.ClearConstant(constMapping);
                newDefinitions.Add(newPD);
            }

            List <DefinitionRef> processes = new List <DefinitionRef>(16);

            foreach (ParallelDefinition pd in newDefinitions)
            {
                pd.DomainValues.Sort();
            }

            List <List <Expression> > list = new List <List <Expression> >();

            foreach (int v in newDefinitions[0].DomainValues)
            {
                List <Expression> l = new List <Expression>(newDefinitions.Count);
                l.Add(new IntConstant(v));
                list.Add(l);
            }

            for (int i = 1; i < newDefinitions.Count; i++)
            {
                List <List <Expression> > newList = new List <List <Expression> >();
                List <int> domain = newDefinitions[i].DomainValues;

                for (int j = 0; j < list.Count; j++)
                {
                    foreach (int i1 in domain)
                    {
                        List <Expression> cList = new List <Expression>(list[j]);
                        cList.Add(new IntConstant(i1));
                        newList.Add(cList);
                    }
                }
                list = newList;
            }

            foreach (List <Expression> constants in list)
            {
                //Dictionary<string, Expression> constMappingNew = new Dictionary<string, Expression>(constMapping);
                Dictionary <string, Expression> constMappingNew = new Dictionary <string, Expression>();
                for (int i = 0; i < constants.Count; i++)
                {
                    Expression constant = constants[i];
                    constMappingNew.Add(newDefinitions[i].Parameter, constant);
                }

                foreach (DefinitionRef containedDefRef in ContainedDefRefs)
                {
                    DefinitionRef newProcess = containedDefRef.ClearConstant(constMappingNew) as DefinitionRef;
                    processes.Add(newProcess);
                }
            }

            return(processes);
        }