Debian Codegraph @

net/sf/saxon/expr/parser/OptimizerOptions.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.parser;
9
10 /**
11 * Defines switches that can be used to control which optimizations take place.
12 * The object is immutable.
13 */
14 public class OptimizerOptions {
15
16 public static final int LOOP_LIFTING = 1;
17 public static final int EXTRACT_GLOBALS = 2;
18 public static final int INLINE_VARIABLES = 4;
19 public static final int INLINE_FUNCTIONS = 8;
20 public static final int INDEX_VARIABLES = 16;
21 public static final int CREATE_KEYS = 32;
22 public static final int BYTE_CODE = 64;
23 public static final int COMMON_SUBEXPRESSIONS = 128;
24 public static final int MISCELLANEOUS = 256;
25 public static final int SWITCH = 512;
26 public static final int JIT = 1024;
27 public static final int RULE_SET = 2048;
28 public static final int REGEX_CACHE = 4096;
29 public static final int VOID_EXPRESSIONS = 8192;
30 public static final int TAIL_CALLS = 16384;
31
32 private int options;
33
34 public final static OptimizerOptions FULL_HE_OPTIMIZATION = new OptimizerOptions("lvmt");
35 public final static OptimizerOptions FULL_EE_OPTIMIZATION = new OptimizerOptions(-1);
36
37 public OptimizerOptions(int options) {
38 this.options = options;
39 }
40
41 public OptimizerOptions(String flags) {
42 int opt = 0;
43 if (flags.startsWith("-")) {
44 opt = -1;
45 for (int i = 0; i < flags.length(); i++) {
46 char c = flags.charAt(i);
47 opt &= ~decodeFlag(c);
48 }
49 } else {
50 for (int i = 0; i < flags.length(); i++) {
51 char c = flags.charAt(i);
52 opt |= decodeFlag(c);
53 }
54 }
55 this.options = opt;
56 }
57
58 private int decodeFlag(char flag) {
59 switch (flag) {
60 case 'c':
61 return BYTE_CODE;
62 case 'd':
63 return VOID_EXPRESSIONS;
64 case 'e':
65 return REGEX_CACHE;
66 case 'f':
67 return INLINE_FUNCTIONS;
68 case 'g':
69 return EXTRACT_GLOBALS;
70 case 'j':
71 return JIT;
72 case 'k':
73 return CREATE_KEYS;
74 case 'l':
75 return LOOP_LIFTING;
76 case 'm':
77 return MISCELLANEOUS;
78 case 'r':
79 return RULE_SET;
80 case 's':
81 return COMMON_SUBEXPRESSIONS;
82 case 't':
83 return TAIL_CALLS;
84 case 'v':
85 return INLINE_VARIABLES;
86 case 'w':
87 return SWITCH;
88 case 'x':
89 return INDEX_VARIABLES;
90
91 default: return 0;
92 }
93 }
94
95 public OptimizerOptions intersect(OptimizerOptions other) {
96 return new OptimizerOptions(options & other.options);
97 }
98
99 public OptimizerOptions union(OptimizerOptions other) {
100 return new OptimizerOptions(options | other.options);
101 }
102
103 public OptimizerOptions except(OptimizerOptions other) {
104 return new OptimizerOptions(options & ~other.options);
105 }
106
107 public String toString() {
108 String result = "";
109 if (isSet(BYTE_CODE)) {
110 result += "c";
111 }
112 if (isSet(VOID_EXPRESSIONS)) {
113 result += "d";
114 }
115 if (isSet(REGEX_CACHE)) {
116 result += "e";
117 }
118 if (isSet(INLINE_FUNCTIONS)) {
119 result += "f";
120 }
121 if (isSet(EXTRACT_GLOBALS)) {
122 result += "g";
123 }
124 if (isSet(JIT)) {
125 result += "j";
126 }
127 if (isSet(CREATE_KEYS)) {
128 result += "k";
129 }
130 if (isSet(LOOP_LIFTING)) {
131 result += "l";
132 }
133 if (isSet(MISCELLANEOUS)) {
134 result += "m";
135 }
136 if (isSet(RULE_SET)) {
137 result += "r";
138 }
139 if (isSet(COMMON_SUBEXPRESSIONS)) {
140 result += "s";
141 }
142 if (isSet(TAIL_CALLS)) {
143 result += "t";
144 }
145 if (isSet(INLINE_VARIABLES)) {
146 result += "v";
147 }
148 if (isSet(SWITCH)) {
149 result += "w";
150 }
151 if (isSet(INDEX_VARIABLES)) {
152 result += "x";
153 }
154 return result;
155 }
156
157 public boolean isSet(int option) {
158 return (options & option) != 0;
159 }
160
161 public int getOptions() {
162 return options;
163 }
164 }
165