| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.instruct; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
import net.sf.saxon.Configuration; |
| 13 |
import net.sf.saxon.Controller; |
| 14 |
import net.sf.saxon.expr.*; |
| 15 |
import net.sf.saxon.expr.parser.*; |
| 16 |
import net.sf.saxon.expr.sort.AtomicComparer; |
| 17 |
import net.sf.saxon.om.*; |
| 18 |
import net.sf.saxon.pattern.NodeTest; |
| 19 |
import net.sf.saxon.query.AnnotationList; |
| 20 |
import net.sf.saxon.style.StylesheetPackage; |
| 21 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 22 |
import net.sf.saxon.trace.LocationKind; |
| 23 |
import net.sf.saxon.trans.FunctionStreamability; |
| 24 |
import net.sf.saxon.trans.SymbolicName; |
| 25 |
import net.sf.saxon.trans.Visibility; |
| 26 |
import net.sf.saxon.trans.XPathException; |
| 27 |
import net.sf.saxon.tree.iter.SingletonIterator; |
| 28 |
import net.sf.saxon.tree.iter.UnfailingIterator; |
| 29 |
import net.sf.saxon.type.*; |
| 30 |
import net.sf.saxon.value.EmptySequence; |
| 31 |
import net.sf.saxon.value.SequenceType; |
| 32 |
|
| 33 |
import java.util.Objects; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public class UserFunction extends Actor implements Function, ContextOriginator { |
| 46 |
|
| 47 |
public enum Determinism {DETERMINISTIC, PROACTIVE, ELIDABLE} |
| 48 |
private final static int MAX_INLININGS = 100; |
| 49 |
|
| 50 |
private StructuredQName functionName; |
| 51 |
private boolean tailCalls = false; |
| 52 |
|
| 53 |
private boolean tailRecursive = false; |
| 54 |
|
| 55 |
private UserFunctionParameter[] parameterDefinitions; |
| 56 |
private SequenceType resultType; |
| 57 |
private SequenceType declaredResultType; |
| 58 |
protected Evaluator evaluator = null; |
| 59 |
private boolean isUpdating = false; |
| 60 |
private int inlineable = -1; |
| 61 |
private int inliningCount = 0; |
| 62 |
private boolean overrideExtensionFunction = true; |
| 63 |
private AnnotationList annotations = AnnotationList.EMPTY; |
| 64 |
private FunctionStreamability declaredStreamability = FunctionStreamability.UNCLASSIFIED; |
| 65 |
private Determinism determinism = Determinism.PROACTIVE; |
| 66 |
private int refCount = 0; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public UserFunction() { |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
public int getComponentKind() { |
| 78 |
return StandardNames.XSL_FUNCTION; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public void setFunctionName(StructuredQName name) { |
| 88 |
functionName = name; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public StructuredQName getFunctionName() { |
| 98 |
return functionName; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public String getDescription() { |
| 109 |
return getFunctionName().getDisplayName(); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public StructuredQName getObjectName() { |
| 118 |
return functionName; |
| 119 |
} |
| 120 |
|
| 121 |
public SymbolicName.F getSymbolicName() { |
| 122 |
return new SymbolicName.F(functionName, getArity()); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public FunctionItemType getFunctionItemType() { |
| 133 |
SequenceType[] argTypes = new SequenceType[parameterDefinitions.length]; |
| 134 |
for (int i = 0; i < parameterDefinitions.length; i++) { |
| 135 |
UserFunctionParameter ufp = parameterDefinitions[i]; |
| 136 |
argTypes[i] = ufp.getRequiredType(); |
| 137 |
} |
| 138 |
return new SpecificFunctionType(argTypes, resultType, annotations); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public OperandRole[] getOperandRoles() { |
| 147 |
OperandRole[] roles = new OperandRole[getArity()]; |
| 148 |
OperandUsage first = null; |
| 149 |
switch (declaredStreamability) { |
| 150 |
case UNCLASSIFIED: |
| 151 |
SequenceType required = getArgumentType(0); |
| 152 |
first = OperandRole.getTypeDeterminedUsage(required.getPrimaryType()); |
| 153 |
break; |
| 154 |
case ABSORBING: |
| 155 |
first = OperandUsage.ABSORPTION; |
| 156 |
break; |
| 157 |
case INSPECTION: |
| 158 |
first = OperandUsage.INSPECTION; |
| 159 |
break; |
| 160 |
case FILTER: |
| 161 |
first = OperandUsage.TRANSMISSION; |
| 162 |
break; |
| 163 |
case SHALLOW_DESCENT: |
| 164 |
first = OperandUsage.TRANSMISSION; |
| 165 |
break; |
| 166 |
case DEEP_DESCENT: |
| 167 |
first = OperandUsage.TRANSMISSION; |
| 168 |
break; |
| 169 |
case ASCENT: |
| 170 |
first = OperandUsage.TRANSMISSION; |
| 171 |
break; |
| 172 |
} |
| 173 |
roles[0] = new OperandRole(0, first, getArgumentType(0)); |
| 174 |
for (int i = 1; i < roles.length; i++) { |
| 175 |
SequenceType required = getArgumentType(i); |
| 176 |
roles[i] = new OperandRole(0, OperandRole.getTypeDeterminedUsage(required.getPrimaryType()), required); |
| 177 |
} |
| 178 |
return roles; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
public boolean acceptsNodesWithoutAtomization() { |
| 188 |
for (int i = 0; i < getArity(); i++) { |
| 189 |
ItemType type = getArgumentType(i).getPrimaryType(); |
| 190 |
if (type instanceof NodeTest || type == AnyItemType.getInstance()) { |
| 191 |
return true; |
| 192 |
} |
| 193 |
} |
| 194 |
return false; |
| 195 |
} |
| 196 |
|
| 197 |
public boolean isOverrideExtensionFunction() { |
| 198 |
return overrideExtensionFunction; |
| 199 |
} |
| 200 |
|
| 201 |
public void setOverrideExtensionFunction(boolean overrideExtensionFunction) { |
| 202 |
this.overrideExtensionFunction = overrideExtensionFunction; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
public void setAnnotations(AnnotationList list) { |
| 212 |
this.annotations = Objects.requireNonNull(list); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public AnnotationList getAnnotations() { |
| 221 |
return annotations; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
public void setDeterminism(Determinism determinism) { |
| 231 |
this.determinism = determinism; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
public Determinism getDeterminism() { |
| 241 |
return determinism; |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public void computeEvaluationMode() { |
| 249 |
if (tailRecursive) { |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
evaluator = ExpressionTool.eagerEvaluator(getBody()); |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
} else { |
| 259 |
evaluator = ExpressionTool.lazyEvaluator(getBody(), true); |
| 260 |
|
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public Boolean isInlineable() { |
| 272 |
if (inlineable != -1) { |
| 273 |
return inlineable > 0 && inliningCount < MAX_INLININGS; |
| 274 |
} |
| 275 |
if (body == null) { |
| 276 |
|
| 277 |
return null; |
| 278 |
} |
| 279 |
if (body.hasSpecialProperty(StaticProperty.HAS_SIDE_EFFECTS) || tailCalls) { |
| 280 |
|
| 281 |
return false; |
| 282 |
} |
| 283 |
Component component = getDeclaringComponent(); |
| 284 |
if (component != null) { |
| 285 |
Visibility visibility = getDeclaringComponent().getVisibility(); |
| 286 |
if (visibility == Visibility.PRIVATE || visibility == Visibility.FINAL) { |
| 287 |
if (inlineable < 0) { |
| 288 |
return null; |
| 289 |
} else { |
| 290 |
return inlineable > 0; |
| 291 |
} |
| 292 |
} else { |
| 293 |
return false; |
| 294 |
} |
| 295 |
} else { |
| 296 |
return null; |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
public void setInlineable(boolean inlineable) { |
| 308 |
this.inlineable = inlineable ? 1 : 0; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
public void markAsInlined() { |
| 317 |
inliningCount++; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
public void setParameterDefinitions(UserFunctionParameter[] params) { |
| 327 |
parameterDefinitions = params; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
public UserFunctionParameter[] getParameterDefinitions() { |
| 337 |
return parameterDefinitions; |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
public void setResultType(SequenceType resultType) { |
| 347 |
this.declaredResultType = resultType; |
| 348 |
this.resultType = resultType; |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
public void setTailRecursive(boolean tailCalls, boolean recursiveTailCalls) { |
| 359 |
this.tailCalls = tailCalls; |
| 360 |
tailRecursive = recursiveTailCalls; |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
public boolean containsTailCalls() { |
| 370 |
return tailCalls; |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
public boolean isTailRecursive() { |
| 380 |
return tailRecursive; |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
public void setUpdating(boolean isUpdating) { |
| 390 |
this.isUpdating = isUpdating; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
public boolean isUpdating() { |
| 400 |
return isUpdating; |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
public void setDeclaredStreamability(FunctionStreamability streamability) { |
| 410 |
this.declaredStreamability = streamability == null ? FunctionStreamability.UNCLASSIFIED : streamability; |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
public FunctionStreamability getDeclaredStreamability() { |
| 420 |
return this.declaredStreamability; |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
public SequenceType getResultType() { |
| 431 |
if (resultType == SequenceType.ANY_SEQUENCE && getBody() != null) { |
| 432 |
|
| 433 |
|
| 434 |
if (!containsUserFunctionCalls(getBody())) { |
| 435 |
resultType = SequenceType.makeSequenceType( |
| 436 |
getBody().getItemType(), getBody().getCardinality()); |
| 437 |
} |
| 438 |
} |
| 439 |
return resultType; |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
public SequenceType getDeclaredResultType() { |
| 449 |
return declaredResultType; |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
private static boolean containsUserFunctionCalls(Expression exp) { |
| 460 |
if (exp instanceof UserFunctionCall) { |
| 461 |
return true; |
| 462 |
} |
| 463 |
for (Operand o : exp.operands()) { |
| 464 |
if (containsUserFunctionCalls(o.getChildExpression())) { |
| 465 |
return true; |
| 466 |
} |
| 467 |
} |
| 468 |
return false; |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
public SequenceType getArgumentType(int n) { |
| 479 |
return parameterDefinitions[n].getRequiredType(); |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
public Evaluator getEvaluator() { |
| 489 |
if (evaluator == null) { |
| 490 |
computeEvaluationMode(); |
| 491 |
} |
| 492 |
return evaluator; |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
public void setEvaluationMode(int mode) { |
| 502 |
evaluator = Evaluator.evaluatorForCode(mode); |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
public int getArity() { |
| 512 |
return parameterDefinitions.length; |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
public boolean isMemoFunction() { |
| 522 |
return false; |
| 523 |
} |
| 524 |
|
| 525 |
public void typeCheck(ExpressionVisitor visitor) throws XPathException { |
| 526 |
Expression exp = getBody(); |
| 527 |
if (exp instanceof ValueOf |
| 528 |
&& ((ValueOf)exp).getSelect().getItemType().isAtomicType() |
| 529 |
&& declaredResultType.getPrimaryType().isAtomicType() |
| 530 |
&& declaredResultType.getPrimaryType() != BuiltInAtomicType.STRING) { |
| 531 |
visitor.getStaticContext().issueWarning( |
| 532 |
"A function that computes atomic values should use xsl:sequence rather than xsl:value-of", |
| 533 |
getLocation()); |
| 534 |
} |
| 535 |
ExpressionTool.resetPropertiesWithinSubtree(exp); |
| 536 |
Expression exp2 = exp; |
| 537 |
try { |
| 538 |
|
| 539 |
|
| 540 |
ContextItemStaticInfo info = ContextItemStaticInfo.ABSENT; |
| 541 |
exp2 = exp.typeCheck(visitor, info); |
| 542 |
if (resultType != null) { |
| 543 |
RoleDiagnostic role = |
| 544 |
new RoleDiagnostic(RoleDiagnostic.FUNCTION_RESULT, |
| 545 |
functionName == null ? "" : functionName.getDisplayName() + "#" + getArity(), 0); |
| 546 |
role.setErrorCode(getPackageData().getHostLanguage() == Configuration.XSLT && getFunctionName() != null ? "XTTE0780" : "XPTY0004"); |
| 547 |
exp2 = visitor.getConfiguration().getTypeChecker(false).staticTypeCheck(exp2, resultType, role, visitor); |
| 548 |
} |
| 549 |
} catch (XPathException err) { |
| 550 |
err.maybeSetLocation(getLocation()); |
| 551 |
throw err; |
| 552 |
} |
| 553 |
if (exp2 != exp) { |
| 554 |
setBody(exp2); |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
public XPathContextMajor makeNewContext(XPathContext oldContext, ContextOriginator originator) { |
| 567 |
XPathContextMajor c2 = oldContext.newCleanContext(); |
| 568 |
c2.setReceiver(oldContext.getReceiver()); |
| 569 |
c2.setTemporaryOutputState(StandardNames.XSL_FUNCTION); |
| 570 |
c2.setCurrentOutputUri(null); |
| 571 |
c2.setCurrentComponent(getDeclaringComponent()); |
| 572 |
c2.setOrigin(originator); |
| 573 |
return c2; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
public Sequence<?> call(XPathContext context, Sequence[] actualArgs) |
| 592 |
throws XPathException { |
| 593 |
if (evaluator == null) { |
| 594 |
|
| 595 |
computeEvaluationMode(); |
| 596 |
} |
| 597 |
|
| 598 |
XPathContextMajor c2 = (XPathContextMajor) context; |
| 599 |
c2.setStackFrame(getStackFrameMap(), actualArgs); |
| 600 |
Sequence<?> result; |
| 601 |
try { |
| 602 |
result = evaluator.evaluate(getBody(), c2); |
| 603 |
} catch (XPathException err) { |
| 604 |
err.maybeSetLocation(getLocation()); |
| 605 |
err.maybeSetContext(c2); |
| 606 |
throw err; |
| 607 |
} catch (Exception err2) { |
| 608 |
String message = "Internal error evaluating function " |
| 609 |
+ (functionName == null ? "(unnamed)" : functionName.getDisplayName()) |
| 610 |
+ (getLineNumber() > 0 ? " at line " + getLineNumber() : "") |
| 611 |
+ (getSystemId() != null ? " in module " + getSystemId() : ""); |
| 612 |
throw new RuntimeException(message, err2); |
| 613 |
} |
| 614 |
return result; |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
public void process(Sequence[] actualArgs, XPathContextMajor context) |
| 632 |
throws XPathException { |
| 633 |
context.setStackFrame(getStackFrameMap(), actualArgs); |
| 634 |
getBody().process(context); |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
public Sequence<?> call(Sequence[] actualArgs, Controller controller) throws XPathException { |
| 654 |
return call(controller.newXPathContext(), actualArgs); |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
public void callUpdating(Sequence[] actualArgs, XPathContextMajor context, PendingUpdateList pul) |
| 671 |
throws XPathException { |
| 672 |
context.setStackFrame(getStackFrameMap(), actualArgs); |
| 673 |
try { |
| 674 |
getBody().evaluatePendingUpdates(context, pul); |
| 675 |
} catch (XPathException err) { |
| 676 |
err.maybeSetLocation(getLocation()); |
| 677 |
throw err; |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
@Override |
| 688 |
public void export(ExpressionPresenter presenter) throws XPathException { |
| 689 |
presenter.startElement("function"); |
| 690 |
if (getFunctionName() != null) { |
| 691 |
presenter.emitAttribute("name", getFunctionName()); |
| 692 |
presenter.emitAttribute("line", getLineNumber() + ""); |
| 693 |
presenter.emitAttribute("module", getSystemId()); |
| 694 |
presenter.emitAttribute("eval", getEvaluator().getCode() + ""); |
| 695 |
} |
| 696 |
String flags = ""; |
| 697 |
if (determinism == Determinism.PROACTIVE) { |
| 698 |
flags += "p"; |
| 699 |
} else if (determinism == Determinism.ELIDABLE) { |
| 700 |
flags += "e"; |
| 701 |
} else { |
| 702 |
flags += "d"; |
| 703 |
} |
| 704 |
if (isMemoFunction()) { |
| 705 |
flags += "m"; |
| 706 |
} |
| 707 |
switch (declaredStreamability) { |
| 708 |
case UNCLASSIFIED: |
| 709 |
flags += "U"; |
| 710 |
break; |
| 711 |
case ABSORBING: |
| 712 |
flags += "A"; |
| 713 |
break; |
| 714 |
case INSPECTION: |
| 715 |
flags += "I"; |
| 716 |
break; |
| 717 |
case FILTER: |
| 718 |
flags += "F"; |
| 719 |
break; |
| 720 |
case SHALLOW_DESCENT: |
| 721 |
flags += "S"; |
| 722 |
break; |
| 723 |
case DEEP_DESCENT: |
| 724 |
flags += "D"; |
| 725 |
break; |
| 726 |
case ASCENT: |
| 727 |
flags += "C"; |
| 728 |
break; |
| 729 |
} |
| 730 |
presenter.emitAttribute("flags", flags); |
| 731 |
presenter.emitAttribute("as", getDeclaredResultType().toExportString()); |
| 732 |
presenter.emitAttribute("slots", getStackFrameMap().getNumberOfVariables() + ""); |
| 733 |
for (UserFunctionParameter p : parameterDefinitions) { |
| 734 |
presenter.startElement("arg"); |
| 735 |
presenter.emitAttribute("name", p.getVariableQName()); |
| 736 |
presenter.emitAttribute("as", p.getRequiredType().toExportString()); |
| 737 |
presenter.endElement(); |
| 738 |
} |
| 739 |
presenter.setChildRole("body"); |
| 740 |
getBody().export(presenter); |
| 741 |
presenter.endElement(); |
| 742 |
} |
| 743 |
|
| 744 |
@Override |
| 745 |
public boolean isExportable() { |
| 746 |
return refCount > 0 || |
| 747 |
(getDeclaredVisibility() != null && getDeclaredVisibility() != Visibility.PRIVATE) || |
| 748 |
((StylesheetPackage) getPackageData()).isRetainUnusedFunctions(); |
| 749 |
} |
| 750 |
|
| 751 |
public boolean isTrustedResultType() { |
| 752 |
return false; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
public int getConstructType() { |
| 762 |
return LocationKind.FUNCTION; |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
public UnfailingIterator<Function> iterate() { |
| 772 |
return SingletonIterator.makeIterator(this); |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
public boolean isMap() { |
| 781 |
return false; |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
public boolean isArray() { |
| 790 |
return false; |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
public boolean deepEquals(Function other, XPathContext context, AtomicComparer comparer, int flags) throws XPathException { |
| 805 |
XPathException err = new XPathException("Cannot compare functions using deep-equal", "FOTY0015"); |
| 806 |
err.setIsTypeError(true); |
| 807 |
err.setXPathContext(context); |
| 808 |
throw err; |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
public Function itemAt(int n) { |
| 818 |
return n == 0 ? this : null; |
| 819 |
} |
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
public GroundedValue<Function> subsequence(int start, int length) { |
| 834 |
return start <= 0 && (start + length) > 0 ? this : EmptySequence.getInstance(); |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
public int getLength() { |
| 843 |
return 1; |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
public boolean effectiveBooleanValue() throws XPathException { |
| 853 |
return ExpressionTool.effectiveBooleanValue(this); |
| 854 |
} |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
public UserFunction reduce() { |
| 865 |
return this; |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
public UserFunction head() { |
| 876 |
return this; |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
public String getStringValue() { |
| 895 |
throw new UnsupportedOperationException("A function has no string value"); |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
public CharSequence getStringValueCS() { |
| 916 |
return getStringValue(); |
| 917 |
} |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
public AtomicSequence atomize() throws XPathException { |
| 927 |
throw new XPathException("Functions cannot be atomized", "FOTY0013"); |
| 928 |
} |
| 929 |
|
| 930 |
public void incrementReferenceCount() { |
| 931 |
refCount++; |
| 932 |
} |
| 933 |
|
| 934 |
public int getReferenceCount() { |
| 935 |
return refCount; |
| 936 |
} |
| 937 |
|
| 938 |
public void prepareForStreaming() throws XPathException { |
| 939 |
|
| 940 |
} |
| 941 |
|
| 942 |
} |
| 943 |
|
| 944 |
|