Debian Codegraph @

net/sf/saxon/expr/StackFrame.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;
9
10 import net.sf.saxon.expr.instruct.SlotManager;
11 import net.sf.saxon.om.Item;
12 import net.sf.saxon.om.Sequence;
13
14 import java.util.Arrays;
15 import java.util.Stack;
16
17 /**
18 * This class represents a stack frame holding details of the variables used in a function or in
19 * an XSLT template.
20 */
21
22 public class StackFrame {
23 protected SlotManager map;
24 protected Sequence<?>[] slots;
25 protected Stack<Sequence<?>> dynamicStack;
26
27 public static final StackFrame EMPTY = new StackFrame(SlotManager.EMPTY, new Sequence[0]);
28
29 public StackFrame(SlotManager map, Sequence[] slots) {
30 this.map = map;
31 this.slots = (Sequence<?>[])slots;
32 }
33
34 public SlotManager getStackFrameMap() {
35 return map;
36 }
37
38 public Sequence<?>[] getStackFrameValues() {
39 return slots;
40 }
41
42 public void setStackFrameValues(Sequence[] values) {
43 slots = (Sequence<?>[])values;
44 }
45
46 public StackFrame copy() {
47 Sequence[] v2 = Arrays.copyOf(slots, slots.length);
48 StackFrame s = new StackFrame(map, v2);
49 if (dynamicStack != null) {
50 s.dynamicStack = new Stack<>();
51 s.dynamicStack.addAll(dynamicStack);
52 }
53 return s;
54 }
55
56 public void pushDynamicValue(Sequence<?> value) {
57 if (this == StackFrame.EMPTY) {
58 throw new IllegalStateException("Immutable stack frame");
59 }
60 if (dynamicStack == null) {
61 dynamicStack = new Stack<>();
62 }
63 dynamicStack.push(value);
64 }
65
66 public Sequence<?> popDynamicValue() {
67 return dynamicStack.pop();
68 }
69
70 public boolean holdsDynamicValue() {
71 return dynamicStack != null && !dynamicStack.empty();
72 }
73
74
75 }
76