* @param config the Saxon configuration
     * @return the compiled XQuery expression
     */

    public XQueryExpression makeXQueryExpression(String query,
                                                 QueryModule staticContext,
                                                 Configuration config) throws XPathException {
        try {
            if (config.getXMLVersion() == Configuration.XML10) {
                query = normalizeLineEndings10(query);
            } else {
                query = normalizeLineEndings11(query);
            }
            Executable exec = staticContext.getExecutable();
            if (exec == null) {
                exec = new Executable(config);
                exec.setHostLanguage(Configuration.XQUERY);
                staticContext.setExecutable(exec);
            }

            Properties outputProps = new Properties(config.getDefaultSerializationProperties());
            if (outputProps.getProperty(OutputKeys.METHOD) == null) {
                outputProps.setProperty(OutputKeys.METHOD, "xml");
            }
            exec.setDefaultOutputProperties(outputProps);

            //exec.setLocationMap(new LocationMap());
            exec.setFunctionLibrary(new ExecutableFunctionLibrary(config));
            // this will be changed later
            setExecutable(exec);

            Expression exp = parseQuery(query, 0, Token.EOF, staticContext);
            int loc = env.getLocationMap().allocateLocationId(env.getSystemId(), 1);
            exp.setContainer(new TemporaryContainer(staticContext.getLocationMap(), loc));
            exec.fixupQueryModules(staticContext);

            // Check for cyclic dependencies among the modules

            if (!disableCycleChecks) {
                Iterator miter = exec.getQueryLibraryModules();
                while (miter.hasNext()) {
                    QueryModule module = (QueryModule)miter.next();
                    module.lookForModuleCycles(new Stack(), 1);
                }
            }

            // Make the XQueryexpression object

            XQueryExpression queryExp = new XQueryExpression(exp, exec, staticContext, config);

            // Make the function library that's available at run-time (e.g. for saxon:evaluate()). This includes
            // all user-defined functions regardless of which module they are in

            FunctionLibrary userlib = exec.getFunctionLibrary();
            FunctionLibraryList lib = new FunctionLibraryList();
            lib.addFunctionLibrary(
                    SystemFunctionLibrary.getSystemFunctionLibrary(getPermittedFunctions()));
            lib.addFunctionLibrary(config.getVendorFunctionLibrary());
            lib.addFunctionLibrary(new ConstructorFunctionLibrary(config));
            lib.addFunctionLibrary(config.getIntegratedFunctionLibrary());
            config.addExtensionBinders(lib);
            lib.addFunctionLibrary(userlib);
            exec.setFunctionLibrary(lib);

            return queryExp;
        } catch (XPathException e) {
            if (!e.hasBeenReported()) {
                reportError(e);
            }
            throw e;
        }
    }