⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xqresolvenames.java

📁 A framework written in Java for implementing high-level and dynamic languages, compiling them into J
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        if (decl != null)                          break;                      }                  }              }            if (decl == null)              {                sym = parser.namespaceResolve(name, function);                if (sym != null)                  {                    decl = lookup.lookup(sym, namespace);                    if (decl == null && function)                      {                        String uri = sym.getNamespaceURI();                        if (XQuery.SCHEMA_NAMESPACE.equals(uri))                          {                            Type type =                              XQuery.getStandardType(sym.getName());                            if (type != null)                              return QuoteExp.getInstance(type);                          }                        if (uri != null && uri.length() > 6 &&                            uri.startsWith("class:"))                          {                            ClassType ctype = ClassType.make(uri.substring(6));                            return GetNamedPart.makeExp(ctype, sym.getName());                          }                        decl = flookup(sym);                      }                  }              }          }        if (decl != null)          exp.setBinding(decl);        else if (function)          error('e', "unknown function "+symbol);        else          messages.error('e',"unknown variable $"+symbol, "XPST0008");      }    return exp;  }  protected Expression walkSetExp (SetExp exp)  {    Expression result = super.walkSetExp(exp);    Declaration decl = exp.getBinding();    Object name;    Expression new_value;    if (decl != null && ! getCompilation().immediate	&& (name = decl.getSymbol()) instanceof Symbol	&& XQuery.LOCAL_NAMESPACE.equals(((Symbol) name).getNamespaceURI())        && (! ((new_value = exp.getNewValue()) instanceof ApplyExp)            || ((ApplyExp) new_value).getFunction() != XQParser.getExternalFunction))      {	decl.setFlag(Declaration.PRIVATE_SPECIFIED);	decl.setPrivate(true);      }    return result;  }  private Declaration moduleDecl;  private Expression walkStatements (Expression exp)  {    // The tricky part here is interleaving declarations and statements    // so that a variable declaration is only visible *after* we have    // walked its initializing expression.    if (exp instanceof BeginExp)      {        BeginExp bbody = (BeginExp) exp;        Expression[] exps = bbody.getExpressions();        int nexps = bbody.getExpressionCount();        for (int i = 0;  i < nexps;  i++)          {            exps[i] = walkStatements(exps[i]);          }      }    else if (exp instanceof SetExp)      {        Declaration decl = moduleDecl;        SetExp sexp = (SetExp) exp;        exp = walkSetExp(sexp);        if (sexp.isDefining() && sexp.getBinding() == decl)          {            if (! decl.isProcedureDecl())              push(decl);            decl = decl.nextDecl();          }        moduleDecl = decl;      }    else      exp = walk(exp);    return exp;  }  public void resolveModule(ModuleExp exp)  {    currentLambda = exp;    for (Declaration decl = exp.firstDecl();         decl != null;  decl = decl.nextDecl())      {        if (decl.isProcedureDecl())	  push(decl);      }    moduleDecl = exp.firstDecl();    exp.body = walkStatements(exp.body);  }  /**   * Coerce argument to NamedCallator, or return default collator.   * @param args argument list   * @param argno index in args of collator argument   */  Expression getCollator (Expression[] args, int argno)  {    if (args != null && args.length > argno)      return new ApplyExp(ClassType.make("gnu.xquery.util.NamedCollator")                            .getDeclaredMethod("find", 1),                            new Expression[] { args[argno] });    NamedCollator coll = parser.defaultCollator;    return coll == null ? QuoteExp.nullExp : new QuoteExp(coll);  }  Expression withCollator (Method method, Expression[] args,                           String name, int minArgs)  {    return withCollator(new QuoteExp(new PrimProcedure(method)),                        args, name, minArgs);  }  /** Adjust call to add default collator if collator argument is missing. */  Expression withCollator (Expression function, Expression[] args,                           String name, int minArgs)  {    String err = WrongArguments.checkArgCount(name, minArgs, minArgs+1, args.length);    if (err != null)      return getCompilation().syntaxError(err);    Expression[] xargs = new Expression[minArgs+1];    System.arraycopy(args, 0, xargs, 0, minArgs);    xargs[minArgs] = getCollator(args, minArgs);    return new ApplyExp(function, xargs);  }  /** Adjust call to add default contex itemt if that argument is missing. */  Expression withContext (Method method, Expression[] args,                          String name, int minArgs)  {    String err = WrongArguments.checkArgCount(name, minArgs, minArgs+1,                                              args.length);    if (err != null)      return getCompilation().syntaxError(err);    if (args.length == minArgs)      {        Expression[] xargs = new Expression[minArgs+1];        System.arraycopy(args, 0, xargs, 0, minArgs);        Declaration dot = lookup.lookup(XQParser.DOT_VARNAME, false);        if (dot == null)          {            String message = "undefined context for " + name;            messages.error('e', message, "XPDY0002");            return new ErrorExp(message);          }        xargs[minArgs] = new ReferenceExp(dot);        args = xargs;      }    return new ApplyExp(method, args);  }  private Expression checkArgCount (Expression[] args, Declaration decl,                                    int min, int max)  {    String err = WrongArguments.checkArgCount("fn:"+decl.getName(),                                              min, max, args.length);    if (err == null)      return null;    else      return getCompilation().syntaxError(err);  }  protected Expression walkApplyExp (ApplyExp exp)  {    Expression func = exp.getFunction();    NamespaceBinding namespaceSave = parser.constructorNamespaces;    Object proc = exp.getFunctionValue();    if (proc instanceof MakeElement)      {        MakeElement mk = (MakeElement) proc;        NamespaceBinding nschain          = NamespaceBinding.nconc(mk.getNamespaceNodes(), namespaceSave);        mk.setNamespaceNodes(nschain);        parser.constructorNamespaces = nschain;      }    if (func instanceof ReferenceExp)      func = walkReferenceExp((ReferenceExp) func, exp);    else      func = walk(func);    exp.setFunction(func);    walkExps(exp.getArgs());    parser.constructorNamespaces = namespaceSave;    func = exp.getFunction();    if (func instanceof ReferenceExp)      {	Declaration decl = ((ReferenceExp) func).getBinding();	int code;        Expression err;        ModuleExp mexp;	if (decl != null && (code = decl.getCode()) < 0)	  {	    switch (code)	      {	      case POSITION_BUILTIN:	      case LAST_BUILTIN:		Symbol sym = code == LAST_BUILTIN ? XQParser.LAST_VARNAME		  : XQParser.POSITION_VARNAME;		decl = lookup.lookup(sym, false);		if (decl == null)		  error('e', "undefined context for " + sym.getName());                else                  // So ValuesFilter.inline can tell whether last() is used.                  decl.setCanRead(true);		return new ReferenceExp(sym, decl);              case CAST_AS_BUILTIN:                {		  Expression[] args = exp.getArgs();                  if (args[0].valueIfConstant() == Compilation.typeSymbol)                    return walkApplyExp(XQParser.castQName(args[1]));                  func                    = XQParser.makeFunctionExp("gnu.xquery.util.CastAs", "castAs");                  return new ApplyExp(func, args);                }              case CASTABLE_AS_BUILTIN:                {		  Expression[] args = exp.getArgs();                  if (args[1].valueIfConstant() == Compilation.typeSymbol                      && args[0] instanceof QuoteExp)                    {                      Object value = ((QuoteExp) args[0]).getValue();                        try                        {                          QNameUtils.resolveQName(value,                                                  parser.constructorNamespaces,                                                  parser.prologNamespaces);                          return XQuery.trueExp;                        }                      catch (RuntimeException ex)                        {	                          return XQuery.falseExp;                        }                    }                  func = XQParser.makeFunctionExp("gnu.xquery.lang.XQParser",                                       "castableAs");                  return new ApplyExp(func, args);                }	      case XS_QNAME_BUILTIN:		{		  Expression[] args = exp.getArgs();                  if ((err = checkArgCount(args, decl, 1, 1)) != null)                    return err;		  if (args[0] instanceof QuoteExp)		    {		      try			{			  Object val = ((QuoteExp) args[0]).getValue();			  val = QNameUtils.resolveQName(val,                                                        parser.constructorNamespaces,                                                        parser.prologNamespaces);			  return new QuoteExp(val);			}		      catch (RuntimeException ex)			{			  return getCompilation().syntaxError(ex.getMessage());			}		    }		  Expression[] xargs = {		    args[0],		    new QuoteExp(parser.constructorNamespaces),		    new QuoteExp(parser.prologNamespaces) };		  Method meth		    = (ClassType.make("gnu.xquery.util.QNameUtils")		       .getDeclaredMethod("resolveQName", 3));		  ApplyExp app = new ApplyExp(meth, xargs);		  app.setFlag(ApplyExp.INLINE_IF_CONSTANT);		  return app;		}	      case RESOLVE_PREFIX_BUILTIN:		{		  Expression[] args = exp.getArgs();                  if ((err = checkArgCount(args, decl, 1, 1)) != null)                    return err;		  if (args[0] instanceof QuoteExp)		    {                      Object val = ((QuoteExp) args[0]).getValue();                      String prefix = val == null ? null : val.toString();                      val = QNameUtils.lookupPrefix(prefix,                                                    parser.constructorNamespaces,                                                    parser.prologNamespaces);                      if (val == null)                        return getCompilation()                          .syntaxError("unknown namespace prefix '"                                       +prefix+"'");                      return new QuoteExp(val);		    }		  Expression[] xargs = {		    args[0],		    new QuoteExp(parser.constructorNamespaces),		    new QuoteExp(parser.prologNamespaces) };		  PrimProcedure pproc		    = new PrimProcedure(ClassType.make("gnu.xquery.util.QNameUtils")                                        .getDeclaredMethod("resolvePrefix", 3));		  ApplyExp app = new ApplyExp(pproc, xargs);		  app.setFlag(ApplyExp.INLINE_IF_CONSTANT);		  return app;		}              case LOCAL_NAME_BUILTIN:		{                  Method meth = ClassType.make("gnu.xquery.util.NodeUtils")                    .getDeclaredMethod("localName", 1);                  return withContext(meth, exp.getArgs(), "fn:local-name", 0);                }              case NAME_BUILTIN:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -