Debian Codegraph @

net/sf/saxon/expr/instruct/BreakInstr.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.expr.instruct;
9
10 import net.sf.saxon.expr.*;
11 import net.sf.saxon.expr.parser.ExpressionTool;
12 import net.sf.saxon.expr.parser.RebindingMap;
13 import net.sf.saxon.om.StandardNames;
14 import net.sf.saxon.trace.ExpressionPresenter;
15 import net.sf.saxon.trans.XPathException;
16
17 import java.util.Collections;
18
19 /**
20 * A compiled xsl:break instruction. The effect of executing this instruction is to register with the
21 * dynamic context that a tail call on a pseudo-function break() has been made; the enclosing xsl:iterate
22 * loop detects this tail call request and uses it as a signal to terminate execution of the loop.
23 */
24 public class BreakInstr extends Instruction implements TailCallLoop.TailCallInfo {
25
26 /**
27 * Create the instruction
28 */
29 public BreakInstr() {
30 }
31
32 @Override
33 public Iterable<Operand> operands() {
34 return Collections.emptyList();
35 }
36
37 /*@NotNull*/
38 public Expression copy(RebindingMap rebindings) {
39 BreakInstr b2 = new BreakInstr();
40 ExpressionTool.copyLocationInfo(this, b2);
41 return b2;
42 }
43
44
45 public boolean mayCreateNewNodes() {
46 // this is a fiction, but it prevents the instruction being moved to a global variable,
47 // which would be pointless and possibly harmful
48 return true;
49 }
50
51 /**
52 * Ask whether the expression can be lifted out of a loop, assuming it has no dependencies
53 * on the controlling variable/focus of the loop
54 * @param forStreaming
55 */
56
57 public boolean isLiftable(boolean forStreaming) {
58 return false;
59 }
60
61 /**
62 * Get the namecode of the instruction for use in diagnostics
63 *
64 * @return a code identifying the instruction: typically but not always
65 * the fingerprint of a name in the XSLT namespace
66 */
67 @Override
68 public int getInstructionNameCode() {
69 return StandardNames.XSL_BREAK;
70 }
71
72 /*@Nullable*/
73 public TailCall processLeavingTail(XPathContext context) throws XPathException {
74 markContext(context);
75 return null;
76 }
77
78 public void markContext(XPathContext context) {
79 XPathContext c = context;
80 while (!(c instanceof XPathContextMajor)) {
81 c = c.getCaller();
82 }
83 ((XPathContextMajor) c).requestTailCall(this, null);
84 }
85
86 @Override
87 public String getExpressionName() {
88 return "xsl:break";
89 }
90
91 public void export(ExpressionPresenter out) throws XPathException {
92 out.startElement("break", this);
93 out.endElement();
94 }
95 }
96