private XQueryFunction CompileFunction(FunctionDeclaration func) { if (func.External) { return(XQueryFunction.FromQName(func.Name)); } return(new XQueryUserFunction(func.Name, func.Parameters.ToArray(), func.FunctionBody.Expr, func.ReturnType)); }
// FIXME: consider those from imported modules public XQueryFunction ResolveFunction(XmlQualifiedName name) { XQueryFunction f = functions [name]; if (f != null) { return(f); } return(null); }
private void CompileProlog() { Prolog p = module.Prolog; // resolve external modules // FIXME: check if external queries are allowed by default. // FIXME: check recursion XmlUrlResolver res = new XmlUrlResolver(); foreach (ModuleImport modimp in p.ModuleImports) { foreach (string uri in modimp.Locations) { Stream s = res.GetEntity(res.ResolveUri(null, uri), null, typeof(Stream)) as Stream; XQueryLibraryModule ext = Mono.Xml.XQuery.Parser.Parser.Parse(new StreamReader(s)) as XQueryLibraryModule; if (ext == null) { throw new XmlQueryCompileException(String.Format("External module {0} is resolved as a main module, while it should be a library module.")); } XQueryStaticContext sctx = new XQueryASTCompiler(ext, options, compileContext, evidence, commandImpl).Compile(); libModuleContexts.Add(sctx); } } // resolve and compile in-scope schemas foreach (SchemaImport xsimp in p.SchemaImports) { foreach (string uri in xsimp.Locations) { XmlSchema schema = inScopeSchemas.Add(xsimp.Namespace, uri); compileContext.InEffectSchemas.Add(schema); } } inScopeSchemas.Compile(); CheckReferences(); ResolveVariableReferences(); // compile FunctionDeclaration into XQueryFunction foreach (FunctionDeclaration func in p.Functions.Values) { XQueryFunction cfunc = CompileFunction(func); localFunctions.Add(cfunc); } }
internal XQueryFunction ResolveFunction(XmlQualifiedName name) { XQueryFunction func = XQueryFunction.FindKnownFunction(name); if (func == null) { func = localFunctions [name]; } if (func != null) { return(func); } else { throw new XmlQueryCompileException("Could not find specified function."); } }
internal void CheckFunctionName(XmlQualifiedName name) { if (XQueryFunction.FindKnownFunction(name) != null) { return; } if (module.Prolog.Functions [name] != null) { return; } foreach (XQueryStaticContext ctx in libModuleContexts) { if (ctx.InScopeFunctions [name] != null) { return; } } throw new XmlQueryCompileException(String.Format("Unresolved function name: {0}", name)); }
internal void Add(XQueryFunction func) { Dictionary.Add(func.Name, func); }
internal void Add (XQueryFunction func) { Dictionary.Add (func.Name, func); }
internal override ExprSingle CompileCore (XQueryASTCompiler compiler) { // resolve function function = compiler.ResolveFunction (Name); CheckArguments (compiler); for (int i = 0; i < Args.Count; i++) Args [i] = Args [i].Compile (compiler); return this; }