| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.instruct.Block; |
| 11 |
import net.sf.saxon.expr.instruct.UserFunction; |
| 12 |
import net.sf.saxon.expr.parser.*; |
| 13 |
import net.sf.saxon.om.*; |
| 14 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 15 |
import net.sf.saxon.trace.LocationKind; |
| 16 |
import net.sf.saxon.trans.*; |
| 17 |
import net.sf.saxon.tree.util.FastStringBuffer; |
| 18 |
import net.sf.saxon.type.AnyItemType; |
| 19 |
import net.sf.saxon.type.ItemType; |
| 20 |
import net.sf.saxon.type.UType; |
| 21 |
import net.sf.saxon.value.Cardinality; |
| 22 |
import net.sf.saxon.value.EmptySequence; |
| 23 |
import net.sf.saxon.value.SequenceType; |
| 24 |
import net.sf.saxon.value.Whitespace; |
| 25 |
|
| 26 |
import java.util.ArrayList; |
| 27 |
import java.util.List; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class UserFunctionCall extends FunctionCall implements UserFunctionResolvable, ComponentInvocation, ContextOriginator { |
| 35 |
|
| 36 |
private SequenceType staticType; |
| 37 |
private UserFunction function; |
| 38 |
private int bindingSlot = -1; |
| 39 |
private int tailCall = NOT_TAIL_CALL; |
| 40 |
private StructuredQName name; |
| 41 |
|
| 42 |
public boolean isBeingInlined() { |
| 43 |
return beingInlined; |
| 44 |
} |
| 45 |
|
| 46 |
public void setBeingInlined(boolean beingInlined) { |
| 47 |
this.beingInlined = beingInlined; |
| 48 |
} |
| 49 |
|
| 50 |
private boolean beingInlined = false; |
| 51 |
|
| 52 |
|
| 53 |
private Evaluator[] argumentEvaluators = null; |
| 54 |
|
| 55 |
public static final int NOT_TAIL_CALL = 0; |
| 56 |
public static final int FOREIGN_TAIL_CALL = 1; |
| 57 |
public static final int SELF_TAIL_CALL = 2; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public UserFunctionCall() { |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public final void setFunctionName(StructuredQName name) { |
| 74 |
this.name = name; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public void setStaticType(SequenceType type) { |
| 85 |
staticType = type; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public void setFunction(UserFunction compiledFunction) { |
| 95 |
function = compiledFunction; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public void setBindingSlot(int slot) { |
| 109 |
this.bindingSlot = slot; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public int getBindingSlot() { |
| 121 |
return bindingSlot; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public UserFunction getFunction() { |
| 133 |
return function; |
| 134 |
} |
| 135 |
|
| 136 |
public Component getFixedTarget() { |
| 137 |
Visibility v = function.getDeclaringComponent().getVisibility(); |
| 138 |
if (v == Visibility.PRIVATE || v == Visibility.FINAL) { |
| 139 |
return function.getDeclaringComponent(); |
| 140 |
} else { |
| 141 |
return null; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public boolean isTailCall() { |
| 152 |
return tailCall != NOT_TAIL_CALL; |
| 153 |
} |
| 154 |
|
| 155 |
public boolean isRecursiveTailCall() { |
| 156 |
return tailCall == SELF_TAIL_CALL; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public final StructuredQName getFunctionName() { |
| 166 |
if (name == null) { |
| 167 |
return function.getFunctionName(); |
| 168 |
} else { |
| 169 |
return name; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
public SymbolicName getSymbolicName() { |
| 174 |
return new SymbolicName.F(getFunctionName(), getArity()); |
| 175 |
} |
| 176 |
|
| 177 |
public Component getTarget() { |
| 178 |
return function.getDeclaringComponent(); |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
public void setArgumentEvaluationModes(int[] evalModes) { |
| 188 |
argumentEvaluators = new Evaluator[evalModes.length]; |
| 189 |
for (int i=0; i<evalModes.length; i++) { |
| 190 |
argumentEvaluators[i] = Evaluator.evaluatorForCode(evalModes[i]); |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
private static final int UNHANDLED_DEPENDENCIES = |
| 196 |
StaticProperty.DEPENDS_ON_POSITION | StaticProperty.DEPENDS_ON_LAST | |
| 197 |
StaticProperty.DEPENDS_ON_XSLT_CONTEXT | StaticProperty.DEPENDS_ON_USER_FUNCTIONS; |
| 198 |
|
| 199 |
public void allocateArgumentEvaluators() { |
| 200 |
argumentEvaluators = new Evaluator[getArity()]; |
| 201 |
int i=0; |
| 202 |
for (Operand o : operands()) { |
| 203 |
Expression arg = o.getChildExpression(); |
| 204 |
SequenceType required = function.getArgumentType(i); |
| 205 |
int cardinality = required.getCardinality(); |
| 206 |
|
| 207 |
if (i == 0 && function.getDeclaredStreamability().isConsuming()) { |
| 208 |
argumentEvaluators[i] = Evaluator.STREAMING_ARGUMENT; |
| 209 |
} else if (function.getParameterDefinitions()[i].isIndexedVariable()) { |
| 210 |
argumentEvaluators[i] = Evaluator.MAKE_INDEXED_VARIABLE; |
| 211 |
} else { |
| 212 |
if (arg instanceof Literal) { |
| 213 |
argumentEvaluators[i] = Evaluator.LITERAL; |
| 214 |
} else if (arg instanceof VariableReference) { |
| 215 |
argumentEvaluators[i] = Evaluator.VARIABLE; |
| 216 |
} else if (cardinality == StaticProperty.EXACTLY_ONE) { |
| 217 |
argumentEvaluators[i] = Evaluator.SINGLE_ITEM; |
| 218 |
} else if ((arg.getDependencies() & UNHANDLED_DEPENDENCIES) != 0) { |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
argumentEvaluators[i] = Evaluator.EAGER_SEQUENCE; |
| 226 |
} else if (!Cardinality.allowsMany(arg.getCardinality()) && arg.getCost() < 20) { |
| 227 |
|
| 228 |
argumentEvaluators[i] = Evaluator.EAGER_SEQUENCE; |
| 229 |
} else if (cardinality == StaticProperty.ALLOWS_ZERO_OR_ONE) { |
| 230 |
argumentEvaluators[i] = Evaluator.OPTIONAL_ITEM; |
| 231 |
} else if (arg instanceof Block && ((Block) arg).isCandidateForSharedAppend()) { |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
argumentEvaluators[i] = Evaluator.SHARED_APPEND; |
| 240 |
} else { |
| 241 |
argumentEvaluators[i] = Evaluator.MEMO_CLOSURE; |
| 242 |
} |
| 243 |
} |
| 244 |
i++; |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
public Evaluator[] getArgumentEvaluators() { |
| 249 |
return argumentEvaluators; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
public Expression preEvaluate(ExpressionVisitor visitor) { |
| 261 |
return this; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public ItemType getItemType() { |
| 272 |
if (staticType == null) { |
| 273 |
|
| 274 |
return AnyItemType.getInstance(); |
| 275 |
} else { |
| 276 |
return staticType.getPrimaryType(); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
@Override |
| 288 |
public UType getStaticUType(UType contextItemType) { |
| 289 |
UserFunction f = getFunction(); |
| 290 |
if (f == null) { |
| 291 |
|
| 292 |
return UType.ANY; |
| 293 |
} |
| 294 |
return f.getResultType().getPrimaryType().getUType(); |
| 295 |
} |
| 296 |
|
| 297 |
public int getIntrinsicDependencies() { |
| 298 |
return StaticProperty.DEPENDS_ON_USER_FUNCTIONS; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
public boolean isUpdatingExpression() { |
| 308 |
return function.isUpdating(); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
protected int computeSpecialProperties() { |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
if (function == null) { |
| 326 |
return super.computeSpecialProperties(); |
| 327 |
} else if (function.getBody() != null && |
| 328 |
(function.getDeclaredVisibility() == Visibility.PRIVATE || function.getDeclaredVisibility() == Visibility.FINAL)) { |
| 329 |
int props; |
| 330 |
List<UserFunction> calledFunctions = new ArrayList<>(); |
| 331 |
ExpressionTool.gatherCalledFunctions(function.getBody(), calledFunctions); |
| 332 |
if (calledFunctions.isEmpty()) { |
| 333 |
props = function.getBody().getSpecialProperties(); |
| 334 |
} else { |
| 335 |
props = super.computeSpecialProperties(); |
| 336 |
} |
| 337 |
if (function.getDeterminism() != UserFunction.Determinism.PROACTIVE) { |
| 338 |
props |= StaticProperty.NO_NODES_NEWLY_CREATED; |
| 339 |
} |
| 340 |
return props; |
| 341 |
} else { |
| 342 |
return super.computeSpecialProperties(); |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
public Expression copy(RebindingMap rebindings) { |
| 355 |
if (function == null) { |
| 356 |
|
| 357 |
throw new UnsupportedOperationException("UserFunctionCall.copy()"); |
| 358 |
} |
| 359 |
UserFunctionCall ufc = new UserFunctionCall(); |
| 360 |
ufc.setFunction(function); |
| 361 |
ufc.setStaticType(staticType); |
| 362 |
int numArgs = getArity(); |
| 363 |
Expression[] a2 = new Expression[numArgs]; |
| 364 |
for (int i = 0; i < numArgs; i++) { |
| 365 |
a2[i] = getArg(i).copy(rebindings); |
| 366 |
} |
| 367 |
ufc.setArguments(a2); |
| 368 |
ExpressionTool.copyLocationInfo(this, ufc); |
| 369 |
return ufc; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
public int computeCardinality() { |
| 377 |
if (staticType == null) { |
| 378 |
|
| 379 |
return StaticProperty.ALLOWS_ZERO_OR_MORE; |
| 380 |
} else { |
| 381 |
return staticType.getCardinality(); |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { |
| 387 |
Expression e = super.typeCheck(visitor, contextInfo); |
| 388 |
if (e != this) { |
| 389 |
return e; |
| 390 |
} |
| 391 |
if (function != null) { |
| 392 |
checkFunctionCall(function, visitor); |
| 393 |
if (staticType == null || staticType == SequenceType.ANY_SEQUENCE) { |
| 394 |
|
| 395 |
staticType = function.getResultType(); |
| 396 |
} |
| 397 |
} |
| 398 |
return this; |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { |
| 403 |
|
| 404 |
Expression e = super.optimize(visitor, contextItemType); |
| 405 |
if (e == this && function != null) { |
| 406 |
Expression e2 = visitor.obtainOptimizer().tryInlineFunctionCall( |
| 407 |
this, visitor, contextItemType); |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
return e2; |
| 412 |
} |
| 413 |
return e; |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
@Override |
| 421 |
public void resetLocalStaticProperties() { |
| 422 |
super.resetLocalStaticProperties(); |
| 423 |
argumentEvaluators = null; |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) { |
| 447 |
return addExternalFunctionCallToPathMap(pathMap, pathMapNodeSet); |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
public int markTailFunctionCalls(StructuredQName qName, int arity) { |
| 457 |
tailCall = getFunctionName().equals(qName) && |
| 458 |
arity == getArity() ? SELF_TAIL_CALL : FOREIGN_TAIL_CALL; |
| 459 |
return tailCall; |
| 460 |
} |
| 461 |
|
| 462 |
public int getImplementationMethod() { |
| 463 |
if (Cardinality.allowsMany(getCardinality())) { |
| 464 |
return ITERATE_METHOD | PROCESS_METHOD; |
| 465 |
} else { |
| 466 |
return EVALUATE_METHOD; |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
public Item evaluateItem(XPathContext c) throws XPathException { |
| 477 |
return callFunction(c).head(); |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
public SequenceIterator<?> iterate(XPathContext c) throws XPathException { |
| 487 |
return callFunction(c).iterate(); |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException { |
| 501 |
Sequence[] actualArgs = evaluateArguments(context); |
| 502 |
XPathContextMajor c2 = context.newCleanContext(); |
| 503 |
c2.setOrigin(this); |
| 504 |
function.callUpdating(actualArgs, c2, pul); |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
private Sequence<?> callFunction(XPathContext context) throws XPathException { |
| 515 |
UserFunction targetFunction; |
| 516 |
Sequence<?>[] actualArgs = evaluateArguments(context); |
| 517 |
XPathContextMajor c2; |
| 518 |
if (isTailCall()) { |
| 519 |
requestTailCall(context, actualArgs); |
| 520 |
return EmptySequence.getInstance(); |
| 521 |
} |
| 522 |
|
| 523 |
if (bindingSlot >= 0) { |
| 524 |
Component target = getTargetComponent(context); |
| 525 |
if (target.isHiddenAbstractComponent()) { |
| 526 |
throw new XPathException("Cannot call an abstract function (" + |
| 527 |
name.getDisplayName() + |
| 528 |
") with no implementation", "XTDE3052"); |
| 529 |
} |
| 530 |
targetFunction = (UserFunction) target.getActor(); |
| 531 |
c2 = targetFunction.makeNewContext(context, this); |
| 532 |
c2.setCurrentComponent(target); |
| 533 |
c2.setOrigin(this); |
| 534 |
} else { |
| 535 |
targetFunction = function; |
| 536 |
c2 = targetFunction.makeNewContext(context, this); |
| 537 |
c2.setOrigin(this); |
| 538 |
} |
| 539 |
|
| 540 |
try { |
| 541 |
return targetFunction.call(c2, actualArgs); |
| 542 |
} catch (UncheckedXPathException e) { |
| 543 |
XPathException xe = e.getXPathException(); |
| 544 |
xe.maybeSetLocation(getLocation()); |
| 545 |
throw xe; |
| 546 |
} catch (StackOverflowError err) { |
| 547 |
err.printStackTrace(); |
| 548 |
throw new XPathException("Too many nested function calls. May be due to infinite recursion", |
| 549 |
SaxonErrorCode.SXLM0001, getLocation()); |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
private void requestTailCall(XPathContext context, Sequence<?>[] actualArgs) throws XPathException { |
| 554 |
if (bindingSlot >= 0) { |
| 555 |
TailCallLoop.TailCallComponent info = new TailCallLoop.TailCallComponent(); |
| 556 |
Component target = getTargetComponent(context); |
| 557 |
info.component = target; |
| 558 |
info.function = (UserFunction) target.getActor(); |
| 559 |
if (target.isHiddenAbstractComponent()) { |
| 560 |
throw new XPathException("Cannot call an abstract function (" + |
| 561 |
name.getDisplayName() + |
| 562 |
") with no implementation", "XTDE3052"); |
| 563 |
} |
| 564 |
((XPathContextMajor) context).requestTailCall(info, actualArgs); |
| 565 |
|
| 566 |
} else { |
| 567 |
TailCallLoop.TailCallFunction info = new TailCallLoop.TailCallFunction(); |
| 568 |
info.function = function; |
| 569 |
((XPathContextMajor) context).requestTailCall(info, actualArgs); |
| 570 |
} |
| 571 |
|
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
public void process(XPathContext context) throws XPathException { |
| 582 |
|
| 583 |
Sequence<?>[] actualArgs = evaluateArguments(context); |
| 584 |
|
| 585 |
if (isTailCall()) { |
| 586 |
requestTailCall(context, actualArgs); |
| 587 |
return; |
| 588 |
} |
| 589 |
|
| 590 |
if (bindingSlot >= 0) { |
| 591 |
Component target = getTargetComponent(context); |
| 592 |
UserFunction targetFunction = (UserFunction) target.getActor(); |
| 593 |
if (target.getVisibility() == Visibility.ABSTRACT) { |
| 594 |
throw new XPathException("Cannot call a function defined with visibility=abstract", "XTDE3052"); |
| 595 |
} |
| 596 |
XPathContextMajor c2 = targetFunction.makeNewContext(context, this); |
| 597 |
c2.setCurrentComponent(target); |
| 598 |
c2.setOrigin(this); |
| 599 |
targetFunction.process(actualArgs, c2); |
| 600 |
} else { |
| 601 |
XPathContextMajor c2 = function.makeNewContext(context, this); |
| 602 |
c2.setOrigin(this); |
| 603 |
function.process(actualArgs, c2); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
public Component getTargetComponent(XPathContext context) { |
| 608 |
if (bindingSlot == -1) { |
| 609 |
|
| 610 |
return function.getDeclaringComponent(); |
| 611 |
} else { |
| 612 |
return context.getTargetComponent(bindingSlot); |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
public UserFunction getTargetFunction(XPathContext context) { |
| 617 |
return (UserFunction) getTargetComponent(context).getActor(); |
| 618 |
} |
| 619 |
|
| 620 |
public Sequence<?>[] evaluateArguments(XPathContext c) throws XPathException { |
| 621 |
return evaluateArguments(c, false); |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
public Sequence<?>[] evaluateArguments(XPathContext c, boolean streamed) throws XPathException { |
| 626 |
int numArgs = getArity(); |
| 627 |
Sequence<?>[] actualArgs = SequenceTool.makeSequenceArray(numArgs); |
| 628 |
synchronized(this) { |
| 629 |
if (argumentEvaluators == null) { |
| 630 |
|
| 631 |
allocateArgumentEvaluators(); |
| 632 |
} |
| 633 |
} |
| 634 |
for (int i = 0; i < numArgs; i++) { |
| 635 |
Evaluator eval = argumentEvaluators[i]; |
| 636 |
if (eval == Evaluator.STREAMING_ARGUMENT && !streamed) { |
| 637 |
eval = Evaluator.EAGER_SEQUENCE; |
| 638 |
} |
| 639 |
actualArgs[i] = eval.evaluate(getArg(i), c); |
| 640 |
|
| 641 |
if (actualArgs[i] == null) { |
| 642 |
actualArgs[i] = EmptySequence.getInstance(); |
| 643 |
} |
| 644 |
} |
| 645 |
return actualArgs; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
public void export(ExpressionPresenter out) throws XPathException { |
| 654 |
out.startElement("ufCall", this); |
| 655 |
if (getFunctionName() != null) { |
| 656 |
out.emitAttribute("name", getFunctionName()); |
| 657 |
out.emitAttribute("tailCall", |
| 658 |
tailCall == NOT_TAIL_CALL ? "false" : tailCall == SELF_TAIL_CALL ? "self" : "foreign"); |
| 659 |
} |
| 660 |
out.emitAttribute("bSlot", "" + getBindingSlot()); |
| 661 |
if (argumentEvaluators != null && getArity() > 0) { |
| 662 |
FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.C64); |
| 663 |
for (Evaluator e : argumentEvaluators) { |
| 664 |
fsb.append(e.getCode() + " "); |
| 665 |
} |
| 666 |
out.emitAttribute("eval", Whitespace.trim(fsb)); |
| 667 |
} |
| 668 |
for (Operand o : operands()) { |
| 669 |
o.getChildExpression().export(out); |
| 670 |
} |
| 671 |
if (getFunctionName() == null) { |
| 672 |
out.setChildRole("inline"); |
| 673 |
function.getBody().export(out); |
| 674 |
out.endElement(); |
| 675 |
} |
| 676 |
out.endElement(); |
| 677 |
} |
| 678 |
|
| 679 |
public int getConstructType() { |
| 680 |
return LocationKind.FUNCTION_CALL; |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
@Override |
| 691 |
public String getExpressionName() { |
| 692 |
return "userFunctionCall"; |
| 693 |
} |
| 694 |
|
| 695 |
public Object getProperty(String name) { |
| 696 |
if (name.equals("target")) { |
| 697 |
return function; |
| 698 |
} |
| 699 |
return super.getProperty(name); |
| 700 |
} |
| 701 |
|
| 702 |
public StructuredQName getObjectName() { |
| 703 |
return getFunctionName(); |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
} |