Exemple #1
0
        /// <summary>
        /// Tries to eliminate the quotations in a module using parser plugins.
        /// It succeeds, then the compiler data of module is set to the simplified
        /// module definition.
        /// </summary>
        private bool EliminateQuotations(bool isQueryContainer, AST <Node> module, List <Flag> flags)
        {
            var configStack = new Stack <Configuration>();
            var success     = new SuccessToken();
            var simplified  = module.Compute <Node>(
                (node) =>
            {
                return(ElimQuoteUnfold(node, configStack, success, flags, cancel));
            },
                (node, folds) =>
            {
                return(ElimQuoteFold(node, folds, configStack));
            },
                cancel);

            if (cancel.IsCancellationRequested)
            {
                return(false);
            }

            if (success.Result)
            {
                var modData = new ModuleData(Env, new Location(module), simplified, isQueryContainer);
                module.Node.CompilerData = modData;
                simplified.CompilerData  = modData;
            }

            return(success.Result);
        }
Exemple #2
0
        /// <summary>
        /// Converts a term AST to a term, and expands symbolic constants as much as possible.
        /// Returns null if there are errors.
        /// Should only be called after the set has been successfully compiled.
        /// </summary>
        private Term Expand(AST <Node> ast, List <Flag> flags)
        {
            bool gotLock = false;

            try
            {
                termIndexLock.Enter(ref gotLock);

                UserSymbol other;
                var        symTable        = index.SymbolTable;
                var        valParamToValue = new Map <UserCnstSymb, Term>(Symbol.Compare);
                foreach (var kv in valueInputs)
                {
                    valParamToValue.Add(
                        (UserCnstSymb)symTable.Resolve(string.Format("%{0}", kv.Key), out other, symTable.ModuleSpace),
                        kv.Value);
                }

                var nextDcVarId = new MutableTuple <int>(0);
                var success     = new SuccessToken();
                var symbStack   = new Stack <Tuple <Namespace, Symbol> >();
                symbStack.Push(new Tuple <Namespace, Symbol>(index.SymbolTable.Root, null));
                var result = ast.Compute <Tuple <Term, Term> >(
                    x => Expand_Unfold(x, symbStack, nextDcVarId, success, flags),
                    (x, y) => Expand_Fold(x, y, symbStack, valParamToValue, success, flags));
                return(result == null ? null : result.Item1);
            }
            finally
            {
                if (gotLock)
                {
                    termIndexLock.Exit();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Tries to eliminate the quotations from the AST using the provided configuration.
        /// </summary>
        internal static Node EliminateQuotations(Configuration config, AST <Node> ast, List <Flag> flags)
        {
            Contract.Requires(config != null && ast != null && flags != null);
            var configStack = new Stack <Configuration>();
            var success     = new SuccessToken();

            configStack.Push(config);
            var simplified = ast.Compute <Node>(
                (node) =>
            {
                return(ElimQuoteUnfold(node, configStack, success, flags, default(CancellationToken)));
            },
                (node, folds) =>
            {
                return(ElimQuoteFold(node, folds, configStack));
            });

            return(success.Result ? simplified : null);
        }