示例#1
0
        public override CoreRule Clone(int ruleId, Predicate <Symbol> isCompr, TermIndex index, Map <Term, Term> bindingReificationCache, Map <UserSymbol, UserSymbol> symbolTransfer, string renaming)
        {
            Contract.Assert(isCompr == null && index != null && bindingReificationCache == null && string.IsNullOrEmpty(renaming));

            bool wasAdded;
            var  newHeadArgs = new Term[Head.Symbol.Arity];
            var  newHeadCon  = symbolTransfer[(UserSymbol)Head.Symbol];

            for (int i = 0; i < newHeadArgs.Length; ++i)
            {
                newHeadArgs[i] = index.MkVar(((UserSymbol)Head.Args[i].Symbol).Name, true, out wasAdded);
            }

            var newHead = index.MkApply(newHeadCon, newHeadArgs, out wasAdded);

            return(new CoreSubRule(
                       ruleId,
                       newHead,
                       index.MkVar(((UserSymbol)Find1.Binding.Symbol).Name, true, out wasAdded),
                       Matcher.Clone(index)));
        }
示例#2
0
        private Term MkNormalizedVar(TermIndex index, int i)
        {
            bool wasAdded;

            return(index.MkVar("~pv~" + i.ToString(), true, out wasAdded));
        }
示例#3
0
        private IEnumerable <Node> Expand_Unfold(Node n,
                                                 Stack <Tuple <Namespace, Symbol> > symbStack,
                                                 MutableTuple <int> nextDcVarId,
                                                 SuccessToken success,
                                                 List <Flag> flags)
        {
            var space = symbStack.Peek().Item1;

            switch (n.NodeKind)
            {
            case NodeKind.Cnst:
            {
                bool         wasAdded;
                var          cnst = (Cnst)n;
                BaseCnstSymb symb;
                switch (cnst.CnstKind)
                {
                case CnstKind.Numeric:
                    symb = (BaseCnstSymb)index.MkCnst((Rational)cnst.Raw, out wasAdded).Symbol;
                    break;

                case CnstKind.String:
                    symb = (BaseCnstSymb)index.MkCnst((string)cnst.Raw, out wasAdded).Symbol;
                    break;

                default:
                    throw new NotImplementedException();
                }

                symbStack.Push(new Tuple <Namespace, Symbol>(space, symb));
                return(null);
            }

            case NodeKind.Id:
            {
                var        id = (Id)n;
                UserSymbol symb;
                if (index.SymbolTable.HasRenamingPrefix(id))
                {
                    if (!Resolve(id.Name, "constant", id, space, x => x.IsNonVarConstant, out symb, flags))
                    {
                        symbStack.Push(new Tuple <Namespace, Symbol>(null, null));
                        success.Failed();
                        return(null);
                    }
                }
                else if (id.Fragments.Length == 1 && id.Name == API.ASTQueries.ASTSchema.Instance.DontCareName)
                {
                    bool wasAdded;
                    var  fresh = index.MkVar(string.Format("{0}{1}{2}", SymbolTable.ManglePrefix, "dc", nextDcVarId.Item1), true, out wasAdded);
                    ++nextDcVarId.Item1;
                    symbStack.Push(new Tuple <Namespace, Symbol>(space, fresh.Symbol));
                    return(null);
                }
                else if (!Resolve(id.Fragments[0], "variable or constant", id, space, x => x.Kind == SymbolKind.UserCnstSymb, out symb, flags))
                {
                    symbStack.Push(new Tuple <Namespace, Symbol>(null, null));
                    success.Failed();
                    return(null);
                }
                else if (id.Fragments.Length > 1 && symb.IsNonVarConstant)
                {
                    var flag = new Flag(
                        SeverityKind.Error,
                        id,
                        Constants.BadSyntax.ToString("constants do not have fields"),
                        Constants.BadSyntax.Code);
                    flags.Add(flag);
                    symbStack.Push(new Tuple <Namespace, Symbol>(null, null));
                    success.Failed();
                    return(null);
                }
                else if (symb.IsVariable)
                {
                    var flag = new Flag(
                        SeverityKind.Error,
                        id,
                        Constants.BadSyntax.ToString("Variables cannot appear here."),
                        Constants.BadSyntax.Code);
                    flags.Add(flag);
                    symbStack.Push(new Tuple <Namespace, Symbol>(null, null));
                    success.Failed();
                    return(null);
                }

                symbStack.Push(new Tuple <Namespace, Symbol>(symb.Namespace, symb));
                return(null);
            }

            case NodeKind.FuncTerm:
            {
                var ft = (FuncTerm)n;
                if (ft.Function is Id)
                {
                    UserSymbol symb;
                    var        ftid = (Id)ft.Function;
                    if (ValidateUse_UserFunc(ft, space, out symb, flags, true))
                    {
                        symbStack.Push(new Tuple <Namespace, Symbol>(symb.Namespace, symb));
                    }
                    else
                    {
                        symbStack.Push(new Tuple <Namespace, Symbol>(null, null));
                        success.Failed();
                        return(null);
                    }

                    return(ft.Args);
                }
                else
                {
                    var flag = new Flag(
                        SeverityKind.Error,
                        ft,
                        Constants.BadSyntax.ToString("Only data constructors can appear here."),
                        Constants.BadSyntax.Code);
                    flags.Add(flag);
                    symbStack.Push(new Tuple <Namespace, Symbol>(null, null));
                    success.Failed();
                    return(null);
                }
            }

            default:
                throw new NotImplementedException();
            }
        }