Beispiel #1
0
        public SubtermMatcher Clone(TermIndex index)
        {
            var srcIndex = pattern[0].Owner;
            var clone    = new SubtermMatcher();

            clone.IsMatchOnlyNewKinds = IsMatchOnlyNewKinds;
            clone.Trigger             = Trigger == null ? null : index.MkClone(Trigger);
            clone.IsSatisfiable       = IsSatisfiable;
            clone.IsTriggerable       = IsTriggerable;

            Map <Term, Set <int> > levelMatches, clonedLevelMatches;

            clone.pattern        = new Term[pattern.Length];
            clone.matchingUnions = new AppFreeCanUnn[pattern.Length];
            for (int i = 0; i < pattern.Length; ++i)
            {
                clone.pattern[i] = index.MkClone(pattern[i]);
                if (matchingUnions[i] != null)
                {
                    clone.matchingUnions[i] = new AppFreeCanUnn(index.MkClone(matchingUnions[i].MkTypeTerm(srcIndex)));
                }

                if (matcher.TryFindValue(i, out levelMatches))
                {
                    clonedLevelMatches = new Map <Term, Set <int> >(Term.Compare);
                    foreach (var kv in levelMatches)
                    {
                        clonedLevelMatches.Add(index.MkClone(kv.Key), kv.Value);
                    }

                    clone.matcher.Add(i, clonedLevelMatches);
                }
            }

            return(clone);
        }
Beispiel #2
0
        internal void Start()
        {
            Contract.Assert(modelOutputs == null);
            modelOutputs = new Map <string, Set <Term> >(string.Compare);

            //// Then this is a copy operation.
            if (applyTarget.Reduced.Node.NodeKind == NodeKind.Model)
            {
                var copySet = modelInputs[string.Empty];
                var copy    = new Set <Term>(Term.Compare);
                foreach (var f in copySet.Facts)
                {
                    copy.Add(index.MkClone(f));
                }

                modelOutputs.Add(OutputNames.First <Id>().Name, copy);
            }
            else if (applyTarget.Reduced.Node.NodeKind == NodeKind.Transform)
            {
                var copyRules = ((RuleTable)applyTarget.FinalOutput).CloneTransformTable(index);
                var exe       = new Executer(copyRules, modelInputs, valueInputs, stats, KeepDerivations, cancel);
                exe.Execute();
                basicTransExe = exe;

                var transToUserMap = MkTransToUserMap();
                foreach (var kv in transToUserMap)
                {
                    modelOutputs.Add(kv.Value, new Set <Term>(Term.Compare));
                }

                Symbol     s;
                UserSymbol us;
                Namespace  ns;
                Set <Term> output;
                string     userName;
                foreach (var kv in exe.Fixpoint)
                {
                    s = kv.Key.Symbol;
                    if (!s.IsDataConstructor)
                    {
                        continue;
                    }

                    us = (UserSymbol)s;
                    if (us.Namespace.Parent == null || us.IsAutoGen || (s.Kind == SymbolKind.ConSymb && !((ConSymb)s).IsNew))
                    {
                        continue;
                    }

                    ns = us.Namespace;
                    while (ns.Parent.Parent != null)
                    {
                        ns = ns.Parent;
                    }

                    if (transToUserMap.TryFindValue(ns.Name, out userName) &&
                        modelOutputs.TryFindValue(userName, out output))
                    {
                        output.Add(kv.Key);
                    }
                }
            }
            else if (applyTarget.Reduced.Node.NodeKind == NodeKind.TSystem)
            {
                var task = ((Common.Composites.CoreTSystem)applyTarget.FinalOutput).Execute(modelInputs, valueInputs, cancel);
                task.Wait();
                var results = task.Result.Results;
                using (var userOutIt = OutputNames.GetEnumerator())
                {
                    using (var transOutIt = ((TSystem)applyTarget.Reduced.Node).Outputs.GetEnumerator())
                    {
                        while (userOutIt.MoveNext() && transOutIt.MoveNext())
                        {
                            modelOutputs.Add(userOutIt.Current.Name, results[((ModRef)transOutIt.Current.Type).Rename].Facts);
                        }
                    }
                }

                results.Dispose();
            }
            else
            {
                throw new NotImplementedException();
            }

            StopTime = DateTime.Now;
            if (cancel.IsCancellationRequested)
            {
                WasCancelled = true;
            }
        }
Beispiel #3
0
        public void Start()
        {
            var mod = (ModuleData)((Location)step.Rhs.Module.CompilerData).AST.Node.CompilerData;

            if (mod.Reduced.Node.NodeKind == NodeKind.Model)
            {
                var facts = ((FactSet)mod.FinalOutput).Facts;
                var copy  = new Set <Term>(Term.Compare);
                var index = new TermIndex(mod.SymbolTable);
                foreach (var f in facts)
                {
                    copy.Add(index.MkClone(f));
                }

                resultMap.SetResult(step.Lhs.First().Name, new FactSet(index, copy));
            }
            else if (mod.Reduced.Node.NodeKind == NodeKind.Transform)
            {
                var transform = (Transform)mod.Reduced.Node;
                var index     = new TermIndex(mod.SymbolTable);
                var copyRules = ((RuleTable)mod.FinalOutput).CloneTransformTable(index);

                var valParams = tsystem.InstantiateValueParams(step, index, valueParams);
                var modParams = tsystem.InstantiateModelParams(step, resultMap);

                var exe = new Executer(copyRules, modParams, valParams, null, false, cancel);
                exe.Execute();

                Namespace outNS;
                using (var lhsIt = step.Lhs.GetEnumerator())
                {
                    using (var outIt = transform.Outputs.GetEnumerator())
                    {
                        while (lhsIt.MoveNext() && outIt.MoveNext())
                        {
                            index.SymbolTable.Root.TryGetChild(((ModRef)outIt.Current.Type).Rename, out outNS);
                            resultMap.SetResult(lhsIt.Current.Name, outNS, exe.Fixpoint.Keys);
                        }
                    }
                }
            }
            else if (mod.Reduced.Node.NodeKind == NodeKind.TSystem)
            {
                var transform = (TSystem)mod.Reduced.Node;
                var index     = new TermIndex(mod.SymbolTable);
                var valParams = tsystem.InstantiateValueParams(step, index, valueParams);
                var modParams = tsystem.InstantiateModelParams(step, resultMap);

                var task = ((CoreTSystem)mod.FinalOutput).Execute(modParams, valParams, cancel);
                task.Wait();

                var subResults = task.Result.resultMap;
                using (var lhsIt = step.Lhs.GetEnumerator())
                {
                    using (var outIt = transform.Outputs.GetEnumerator())
                    {
                        while (lhsIt.MoveNext() && outIt.MoveNext())
                        {
                            resultMap.SetResult(lhsIt.Current.Name, subResults[((ModRef)outIt.Current.Type).Rename]);
                        }
                    }
                }

                subResults.Dispose();
            }
            else
            {
                throw new NotImplementedException();
            }
        }