Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CompilerScopeManager.cs
Go to the documentation of this file.
4
5namespace System.Xml.Xsl.Xslt;
6
7internal sealed class CompilerScopeManager<V>
8{
9 public enum ScopeFlags
10 {
14 NsDecl = 16,
15 NsExcl = 32,
16 Variable = 64,
19 ExclusiveFlags = 112
20 }
21
22 public struct ScopeRecord
23 {
24 public int scopeCount;
25
27
28 public string ncName;
29
30 public string nsUri;
31
32 [AllowNull]
33 public V value;
34
35 public bool IsVariable => (flags & ScopeFlags.Variable) != 0;
36
37 public bool IsNamespace => (flags & ScopeFlags.NsDecl) != 0;
38 }
39
40 internal struct NamespaceEnumerator
41 {
43
44 private readonly int _lastRecord;
45
46 private int _currentRecord;
47
49
51 {
52 _scope = scope;
53 _lastRecord = scope._lastRecord;
55 }
56
57 public bool MoveNext()
58 {
59 while (0 < --_currentRecord)
60 {
61 if (_scope._records[_currentRecord].IsNamespace && _scope.LookupNamespace(_scope._records[_currentRecord].ncName, _lastRecord, _currentRecord + 1) == null)
62 {
63 return true;
64 }
65 }
66 return false;
67 }
68 }
69
70 private ScopeRecord[] _records = new ScopeRecord[32];
71
72 private int _lastRecord;
73
74 private int _lastScopes;
75
77 {
78 get
79 {
80 return (_records[_lastRecord].flags & ScopeFlags.ForwardCompatibility) != 0;
81 }
82 set
83 {
84 SetFlag(ScopeFlags.ForwardCompatibility, value);
85 }
86 }
87
89 {
90 get
91 {
92 return (_records[_lastRecord].flags & ScopeFlags.BackwardCompatibility) != 0;
93 }
94 set
95 {
96 SetFlag(ScopeFlags.BackwardCompatibility, value);
97 }
98 }
99
101 {
102 get
103 {
104 return (_records[_lastRecord].flags & ScopeFlags.CanHaveApplyImports) != 0;
105 }
106 set
107 {
108 SetFlag(ScopeFlags.CanHaveApplyImports, value);
109 }
110 }
111
113 {
114 _records[0].flags = ScopeFlags.NsDecl;
115 _records[0].ncName = "xml";
116 _records[0].nsUri = "http://www.w3.org/XML/1998/namespace";
117 }
118
120 {
121 _records[0].flags = ScopeFlags.NsDecl;
122 _records[0].ncName = atoms.Xml;
123 _records[0].nsUri = atoms.UriXml;
124 }
125
126 public void EnterScope()
127 {
128 _lastScopes++;
129 }
130
131 public void ExitScope()
132 {
133 if (0 < _lastScopes)
134 {
135 _lastScopes--;
136 return;
137 }
138 while (_records[--_lastRecord].scopeCount == 0)
139 {
140 }
142 _lastScopes--;
143 }
144
145 public bool EnterScope([NotNullWhen(true)] NsDecl nsDecl)
146 {
147 _lastScopes++;
148 bool result = false;
149 bool flag = false;
150 while (nsDecl != null)
151 {
152 if (nsDecl.NsUri == null)
153 {
154 flag = true;
155 }
156 else if (nsDecl.Prefix == null)
157 {
158 AddExNamespace(nsDecl.NsUri);
159 }
160 else
161 {
162 result = true;
163 AddNsDeclaration(nsDecl.Prefix, nsDecl.NsUri);
164 }
165 nsDecl = nsDecl.Prev;
166 }
167 if (flag)
168 {
169 AddExNamespace(null);
170 }
171 return result;
172 }
173
174 private void AddRecord()
175 {
177 if (++_lastRecord == _records.Length)
178 {
181 _records = array;
182 }
183 _lastScopes = 0;
184 }
185
186 private void AddRecord(ScopeFlags flag, string ncName, string uri, [AllowNull] V value)
187 {
189 if (_lastScopes != 0 || (scopeFlags & ScopeFlags.ExclusiveFlags) != 0)
190 {
191 AddRecord();
192 scopeFlags &= ScopeFlags.InheritedFlags;
193 }
195 _records[_lastRecord].ncName = ncName;
198 }
199
200 private void SetFlag(ScopeFlags flag, bool value)
201 {
203 if ((scopeFlags & flag) != 0 == value)
204 {
205 return;
206 }
207 if (_lastScopes != 0)
208 {
209 AddRecord();
210 scopeFlags &= ScopeFlags.InheritedFlags;
211 }
212 if (flag == ScopeFlags.CanHaveApplyImports)
213 {
214 scopeFlags ^= flag;
215 }
216 else
217 {
218 scopeFlags &= (ScopeFlags)(-4);
219 if (value)
220 {
221 scopeFlags |= flag;
222 }
223 }
225 }
226
228 {
229 AddRecord(ScopeFlags.Variable, varName.LocalName, varName.NamespaceUri, value);
230 }
231
232 private string LookupNamespace(string prefix, int from, int to)
233 {
234 int num = from;
235 while (to <= num)
236 {
237 string prefix2;
238 string nsUri;
239 ScopeFlags name = GetName(ref _records[num], out prefix2, out nsUri);
240 if ((name & ScopeFlags.NsDecl) != 0 && prefix2 == prefix)
241 {
242 return nsUri;
243 }
244 num--;
245 }
246 return null;
247 }
248
249 public string LookupNamespace(string prefix)
250 {
252 }
253
254 private static ScopeFlags GetName(ref ScopeRecord re, out string prefix, out string nsUri)
255 {
256 prefix = re.ncName;
257 nsUri = re.nsUri;
258 return re.flags;
259 }
260
261 public void AddNsDeclaration(string prefix, string nsUri)
262 {
263 AddRecord(ScopeFlags.NsDecl, prefix, nsUri, default(V));
264 }
265
266 public void AddExNamespace(string nsUri)
267 {
268 AddRecord(ScopeFlags.NsExcl, null, nsUri, default(V));
269 }
270
271 public bool IsExNamespace(string nsUri)
272 {
273 int num = 0;
274 int num2 = _lastRecord;
275 while (0 <= num2)
276 {
277 string prefix;
278 string nsUri2;
280 if ((name & ScopeFlags.NsExcl) != 0)
281 {
282 if (nsUri2 == nsUri)
283 {
284 return true;
285 }
286 if (nsUri2 == null)
287 {
288 num = num2;
289 }
290 }
291 else if (num != 0 && (name & ScopeFlags.NsDecl) != 0 && nsUri2 == nsUri)
292 {
293 bool flag = false;
294 for (int i = num2 + 1; i < num; i++)
295 {
297 if ((name & ScopeFlags.NsDecl) != 0 && prefix2 == prefix)
298 {
299 flag = true;
300 break;
301 }
302 }
303 if (!flag)
304 {
305 return true;
306 }
307 }
308 num2--;
309 }
310 return false;
311 }
312
313 private int SearchVariable(string localName, string uri)
314 {
315 int num = _lastRecord;
316 while (0 <= num)
317 {
318 string prefix;
319 string nsUri;
320 ScopeFlags name = GetName(ref _records[num], out prefix, out nsUri);
321 if ((name & ScopeFlags.Variable) != 0 && prefix == localName && nsUri == uri)
322 {
323 return num;
324 }
325 num--;
326 }
327 return -1;
328 }
329
330 [return: MaybeNull]
331 public V LookupVariable(string localName, string uri)
332 {
333 int num = SearchVariable(localName, uri);
334 if (num >= 0)
335 {
336 return _records[num].value;
337 }
338 return default(V);
339 }
340
341 public bool IsLocalVariable(string localName, string uri)
342 {
343 int num = SearchVariable(localName, uri);
344 while (0 <= --num)
345 {
346 if (_records[num].scopeCount != 0)
347 {
348 return true;
349 }
350 }
351 return false;
352 }
353
355 {
356 int currentRecord = _lastRecord + 1;
357 while (true)
358 {
359 int num = currentRecord - 1;
360 currentRecord = num;
361 if (0 < num)
362 {
363 if (!_records[currentRecord].IsNamespace || LookupNamespace(_records[currentRecord].ncName, _lastRecord, currentRecord + 1) == null)
364 {
366 }
367 continue;
368 }
369 break;
370 }
371 }
372
374 {
375 return new NamespaceEnumerator(this);
376 }
377}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
void AddRecord(ScopeFlags flag, string ncName, string uri, [AllowNull] V value)
static ScopeFlags GetName(ref ScopeRecord re, out string prefix, out string nsUri)
int SearchVariable(string localName, string uri)
void AddNsDeclaration(string prefix, string nsUri)
IEnumerable< ScopeRecord > GetActiveRecords()
void AddVariable(QilName varName, V value)
bool IsLocalVariable(string localName, string uri)
V LookupVariable(string localName, string uri)
void SetFlag(ScopeFlags flag, bool value)
string LookupNamespace(string prefix, int from, int to)
bool EnterScope([NotNullWhen(true)] NsDecl nsDecl)