aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-02-23 14:52:34 +0000
committerUbitUmarov2018-02-23 14:52:34 +0000
commit2129d941acbc5f83aca4dc4c30a62d3226888136 (patch)
treee12f2391978c923ef780f558ee5a32d857ee9124 /OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs
parentMerge branch 'master' into httptests (diff)
downloadopensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.zip
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.gz
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.bz2
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.xz
rename XMREngine as Yengine (still not all done), big mess source formating changes, move state files to proper folder, fix a source file locking on errors, more changes for cross platform including from Mike,... yes yes i know a messy commit
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs (renamed from OpenSim/Region/ScriptEngine/XMREngine/MMRScriptVarDict.cs)253
1 files changed, 158 insertions, 95 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/MMRScriptVarDict.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs
index 67e1c34..2561d02 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/MMRScriptVarDict.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs
@@ -33,63 +33,80 @@ using System.Collections.Generic;
33 * @brief Collection of variable/function/method definitions 33 * @brief Collection of variable/function/method definitions
34 */ 34 */
35 35
36namespace OpenSim.Region.ScriptEngine.XMREngine 36namespace OpenSim.Region.ScriptEngine.Yengine
37{ 37{
38 public class VarDict : IEnumerable { 38 public class VarDict: IEnumerable
39 {
39 public VarDict outerVarDict; // next outer VarDict to search 40 public VarDict outerVarDict; // next outer VarDict to search
40 public TokenDeclSDTypeClass thisClass; // this VarDict is for members of thisClass 41 public TokenDeclSDTypeClass thisClass; // this VarDict is for members of thisClass
41 42
42 private struct ArgTypes { 43 private struct ArgTypes
44 {
43 public TokenType[] argTypes; 45 public TokenType[] argTypes;
44 46
45 public bool CanBeCalledBy (TokenType[] calledBy) 47 public bool CanBeCalledBy(TokenType[] calledBy)
46 { 48 {
47 if ((argTypes == null) && (calledBy == null)) return true; 49 if((argTypes == null) && (calledBy == null))
48 if ((argTypes == null) || (calledBy == null)) return false; 50 return true;
49 if (argTypes.Length != calledBy.Length) return false; 51 if((argTypes == null) || (calledBy == null))
50 for (int i = argTypes.Length; -- i >= 0;) { 52 return false;
51 if (!TypeCast.IsAssignableFrom (argTypes[i], calledBy[i])) return false; 53 if(argTypes.Length != calledBy.Length)
54 return false;
55 for(int i = argTypes.Length; --i >= 0;)
56 {
57 if(!TypeCast.IsAssignableFrom(argTypes[i], calledBy[i]))
58 return false;
52 } 59 }
53 return true; 60 return true;
54 } 61 }
55 62
56 public override bool Equals (Object that) 63 public override bool Equals(Object that)
57 { 64 {
58 if (that == null) return false; 65 if(that == null)
59 if (that.GetType () != typeof (ArgTypes)) return false; 66 return false;
67 if(that.GetType() != typeof(ArgTypes))
68 return false;
60 TokenType[] at = this.argTypes; 69 TokenType[] at = this.argTypes;
61 TokenType[] bt = ((ArgTypes)that).argTypes; 70 TokenType[] bt = ((ArgTypes)that).argTypes;
62 if ((at == null) && (bt == null)) return true; 71 if((at == null) && (bt == null))
63 if ((at == null) || (bt == null)) return false; 72 return true;
64 if (at.Length != bt.Length) return false; 73 if((at == null) || (bt == null))
65 for (int i = at.Length; -- i >= 0;) { 74 return false;
66 if (at[i].ToString () != bt[i].ToString ()) return false; 75 if(at.Length != bt.Length)
76 return false;
77 for(int i = at.Length; --i >= 0;)
78 {
79 if(at[i].ToString() != bt[i].ToString())
80 return false;
67 } 81 }
68 return true; 82 return true;
69 } 83 }
70 84
71 public override int GetHashCode () 85 public override int GetHashCode()
72 { 86 {
73 TokenType[] at = this.argTypes; 87 TokenType[] at = this.argTypes;
74 if (at == null) return -1; 88 if(at == null)
89 return -1;
75 int hc = 0; 90 int hc = 0;
76 for (int i = at.Length; -- i >= 0;) { 91 for(int i = at.Length; --i >= 0;)
92 {
77 int c = (hc < 0) ? 1 : 0; 93 int c = (hc < 0) ? 1 : 0;
78 hc = hc * 2 + c; 94 hc = hc * 2 + c;
79 hc ^= at[i].ToString ().GetHashCode (); 95 hc ^= at[i].ToString().GetHashCode();
80 } 96 }
81 return hc; 97 return hc;
82 } 98 }
83 } 99 }
84 100
85 private struct TDVEntry { 101 private struct TDVEntry
102 {
86 public int count; 103 public int count;
87 public TokenDeclVar var; 104 public TokenDeclVar var;
88 } 105 }
89 106
90 private bool isFrozen = false; 107 private bool isFrozen = false;
91 private bool locals; 108 private bool locals;
92 private Dictionary<string, Dictionary<ArgTypes, TDVEntry>> master = new Dictionary<string, Dictionary<ArgTypes, TDVEntry>> (); 109 private Dictionary<string, Dictionary<ArgTypes, TDVEntry>> master = new Dictionary<string, Dictionary<ArgTypes, TDVEntry>>();
93 private int count = 0; 110 private int count = 0;
94 private VarDict frozenLocals = null; 111 private VarDict frozenLocals = null;
95 112
@@ -98,7 +115,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
98 * @param locals = false: cannot be frozen, allows forward references 115 * @param locals = false: cannot be frozen, allows forward references
99 * true: can be frozen, thus forbidding forward references 116 * true: can be frozen, thus forbidding forward references
100 */ 117 */
101 public VarDict (bool locals) 118 public VarDict(bool locals)
102 { 119 {
103 this.locals = locals; 120 this.locals = locals;
104 } 121 }
@@ -106,19 +123,21 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
106 /** 123 /**
107 * @brief Add new variable to the dictionary. 124 * @brief Add new variable to the dictionary.
108 */ 125 */
109 public bool AddEntry (TokenDeclVar var) 126 public bool AddEntry(TokenDeclVar var)
110 { 127 {
111 if (isFrozen) { 128 if(isFrozen)
112 throw new Exception ("var dict is frozen"); 129 {
130 throw new Exception("var dict is frozen");
113 } 131 }
114 132
115 /* 133 /*
116 * Make sure we have a sub-dictionary based on the bare name (ie, no signature) 134 * Make sure we have a sub-dictionary based on the bare name (ie, no signature)
117 */ 135 */
118 Dictionary<ArgTypes, TDVEntry> typedic; 136 Dictionary<ArgTypes, TDVEntry> typedic;
119 if (!master.TryGetValue (var.name.val, out typedic)) { 137 if(!master.TryGetValue(var.name.val, out typedic))
120 typedic = new Dictionary<ArgTypes, TDVEntry> (); 138 {
121 master.Add (var.name.val, typedic); 139 typedic = new Dictionary<ArgTypes, TDVEntry>();
140 master.Add(var.name.val, typedic);
122 } 141 }
123 142
124 /* 143 /*
@@ -127,41 +146,50 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
127 * Methods always have a non-null argument list, even if only 0 entries long. 146 * Methods always have a non-null argument list, even if only 0 entries long.
128 */ 147 */
129 ArgTypes types; 148 ArgTypes types;
130 types.argTypes = (var.argDecl == null) ? null : KeyTypesToStringTypes (var.argDecl.types); 149 types.argTypes = (var.argDecl == null) ? null : KeyTypesToStringTypes(var.argDecl.types);
131 if (typedic.ContainsKey (types)) return false; 150 if(typedic.ContainsKey(types))
151 return false;
132 152
133 /* 153 /*
134 * It is unique, add to its name-specific sub-dictionary. 154 * It is unique, add to its name-specific sub-dictionary.
135 */ 155 */
136 TDVEntry entry; 156 TDVEntry entry;
137 entry.count = ++ count; 157 entry.count = ++count;
138 entry.var = var; 158 entry.var = var;
139 typedic.Add (types, entry); 159 typedic.Add(types, entry);
140 return true; 160 return true;
141 } 161 }
142 162
143 public int Count { get { return count; } } 163 public int Count
164 {
165 get
166 {
167 return count;
168 }
169 }
144 170
145 /** 171 /**
146 * @brief If this is not a local variable frame, just return the frame as is. 172 * @brief If this is not a local variable frame, just return the frame as is.
147 * If this is a local variable frame, return a version that is frozen, 173 * If this is a local variable frame, return a version that is frozen,
148 * ie, one that does not contain any future additions. 174 * ie, one that does not contain any future additions.
149 */ 175 */
150 public VarDict FreezeLocals () 176 public VarDict FreezeLocals()
151 { 177 {
152 /* 178 /*
153 * If not local var frame, return original frame as is. 179 * If not local var frame, return original frame as is.
154 * This will allow forward references as the future additions 180 * This will allow forward references as the future additions
155 * will be seen by lookups done in this dictionary. 181 * will be seen by lookups done in this dictionary.
156 */ 182 */
157 if (!locals) return this; 183 if(!locals)
184 return this;
158 185
159 /* 186 /*
160 * If local var frame, return a copy frozen at this point. 187 * If local var frame, return a copy frozen at this point.
161 * This disallows forward referenes as those future additions 188 * This disallows forward referenes as those future additions
162 * will not be seen by lookups done in the frozen dictionary. 189 * will not be seen by lookups done in the frozen dictionary.
163 */ 190 */
164 if ((frozenLocals == null) || (frozenLocals.count != this.count)) { 191 if((frozenLocals == null) || (frozenLocals.count != this.count))
192 {
165 193
166 /* 194 /*
167 * Make a copy of the current var dictionary frame. 195 * Make a copy of the current var dictionary frame.
@@ -169,12 +197,12 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
169 * contain additions made after this point, those additions 197 * contain additions made after this point, those additions
170 * will have a count .gt. frozen count and will be ignored. 198 * will have a count .gt. frozen count and will be ignored.
171 */ 199 */
172 frozenLocals = new VarDict (true); 200 frozenLocals = new VarDict(true);
173 201
174 frozenLocals.outerVarDict = this.outerVarDict; 202 frozenLocals.outerVarDict = this.outerVarDict;
175 frozenLocals.thisClass = this.thisClass; 203 frozenLocals.thisClass = this.thisClass;
176 frozenLocals.master = this.master; 204 frozenLocals.master = this.master;
177 frozenLocals.count = this.count; 205 frozenLocals.count = this.count;
178 frozenLocals.frozenLocals = frozenLocals; 206 frozenLocals.frozenLocals = frozenLocals;
179 207
180 /* 208 /*
@@ -196,23 +224,27 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
196 * else: list of matching functions/variables 224 * else: list of matching functions/variables
197 * for variables, always of length 1 225 * for variables, always of length 1
198 */ 226 */
199 private List<TokenDeclVar> found = new List<TokenDeclVar> (); 227 private List<TokenDeclVar> found = new List<TokenDeclVar>();
200 public TokenDeclVar[] FindCallables (string name, TokenType[] argTypes) 228 public TokenDeclVar[] FindCallables(string name, TokenType[] argTypes)
201 { 229 {
202 argTypes = KeyTypesToStringTypes (argTypes); 230 argTypes = KeyTypesToStringTypes(argTypes);
203 TokenDeclVar var = FindExact (name, argTypes); 231 TokenDeclVar var = FindExact(name, argTypes);
204 if (var != null) return new TokenDeclVar[] { var }; 232 if(var != null)
233 return new TokenDeclVar[] { var };
205 234
206 Dictionary<ArgTypes, TDVEntry> typedic; 235 Dictionary<ArgTypes, TDVEntry> typedic;
207 if (!master.TryGetValue (name, out typedic)) return null; 236 if(!master.TryGetValue(name, out typedic))
237 return null;
208 238
209 found.Clear (); 239 found.Clear();
210 foreach (KeyValuePair<ArgTypes, TDVEntry> kvp in typedic) { 240 foreach(KeyValuePair<ArgTypes, TDVEntry> kvp in typedic)
211 if ((kvp.Value.count <= this.count) && kvp.Key.CanBeCalledBy (argTypes)) { 241 {
212 found.Add (kvp.Value.var); 242 if((kvp.Value.count <= this.count) && kvp.Key.CanBeCalledBy(argTypes))
243 {
244 found.Add(kvp.Value.var);
213 } 245 }
214 } 246 }
215 return (found.Count > 0) ? found.ToArray () : null; 247 return (found.Count > 0) ? found.ToArray() : null;
216 } 248 }
217 249
218 /** 250 /**
@@ -223,19 +255,22 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
223 * @returns null: no matching function/variable found 255 * @returns null: no matching function/variable found
224 * else: the matching function/variable 256 * else: the matching function/variable
225 */ 257 */
226 public TokenDeclVar FindExact (string name, TokenType[] argTypes) 258 public TokenDeclVar FindExact(string name, TokenType[] argTypes)
227 { 259 {
228 /* 260 /*
229 * Look for list of stuff that matches the given name. 261 * Look for list of stuff that matches the given name.
230 */ 262 */
231 Dictionary<ArgTypes, TDVEntry> typedic; 263 Dictionary<ArgTypes, TDVEntry> typedic;
232 if (!master.TryGetValue (name, out typedic)) return null; 264 if(!master.TryGetValue(name, out typedic))
265 return null;
233 266
234 /* 267 /*
235 * Loop through all fields/methods declared by that name, regardless of arg signature. 268 * Loop through all fields/methods declared by that name, regardless of arg signature.
236 */ 269 */
237 foreach (TDVEntry entry in typedic.Values) { 270 foreach(TDVEntry entry in typedic.Values)
238 if (entry.count > this.count) continue; 271 {
272 if(entry.count > this.count)
273 continue;
239 TokenDeclVar var = entry.var; 274 TokenDeclVar var = entry.var;
240 275
241 /* 276 /*
@@ -248,12 +283,13 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
248 /* 283 /*
249 * Convert any key args to string args. 284 * Convert any key args to string args.
250 */ 285 */
251 declArgs = KeyTypesToStringTypes (declArgs); 286 declArgs = KeyTypesToStringTypes(declArgs);
252 287
253 /* 288 /*
254 * If both are null, they are signature-less (ie, both are fields), and so match. 289 * If both are null, they are signature-less (ie, both are fields), and so match.
255 */ 290 */
256 if ((declArgs == null) && (argTypes == null)) return var; 291 if((declArgs == null) && (argTypes == null))
292 return var;
257 293
258 /* 294 /*
259 * If calling a delegate, it is a match, regardless of delegate arg types. 295 * If calling a delegate, it is a match, regardless of delegate arg types.
@@ -261,29 +297,38 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
261 * trying to cast the arguments to the delegate arg types. 297 * trying to cast the arguments to the delegate arg types.
262 * We don't allow overloading same field name with different delegate types. 298 * We don't allow overloading same field name with different delegate types.
263 */ 299 */
264 if ((declArgs == null) && (argTypes != null)) { 300 if((declArgs == null) && (argTypes != null))
301 {
265 TokenType fieldType = var.type; 302 TokenType fieldType = var.type;
266 if (fieldType is TokenTypeSDTypeDelegate) return var; 303 if(fieldType is TokenTypeSDTypeDelegate)
304 return var;
267 } 305 }
268 306
269 /* 307 /*
270 * If not both null, no match, keep looking. 308 * If not both null, no match, keep looking.
271 */ 309 */
272 if ((declArgs == null) || (argTypes == null)) continue; 310 if((declArgs == null) || (argTypes == null))
311 continue;
273 312
274 /* 313 /*
275 * Both not null, match argument types to make sure we have correct overload. 314 * Both not null, match argument types to make sure we have correct overload.
276 */ 315 */
277 int i = declArgs.Length; 316 int i = declArgs.Length;
278 if (i != argTypes.Length) continue; 317 if(i != argTypes.Length)
279 while (-- i >= 0) { 318 continue;
280 string da = declArgs[i].ToString (); 319 while(--i >= 0)
281 string ga = argTypes[i].ToString (); 320 {
282 if (da == "key") da = "string"; 321 string da = declArgs[i].ToString();
283 if (ga == "key") ga = "string"; 322 string ga = argTypes[i].ToString();
284 if (da != ga) break; 323 if(da == "key")
324 da = "string";
325 if(ga == "key")
326 ga = "string";
327 if(da != ga)
328 break;
285 } 329 }
286 if (i < 0) return var; 330 if(i < 0)
331 return var;
287 } 332 }
288 333
289 /* 334 /*
@@ -299,20 +344,26 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
299 * @param argTypes = argument types as declared in source code 344 * @param argTypes = argument types as declared in source code
300 * @returns argTypes with any key replaced by string 345 * @returns argTypes with any key replaced by string
301 */ 346 */
302 private static TokenType[] KeyTypesToStringTypes (TokenType[] argTypes) 347 private static TokenType[] KeyTypesToStringTypes(TokenType[] argTypes)
303 { 348 {
304 if (argTypes != null) { 349 if(argTypes != null)
350 {
305 int i; 351 int i;
306 int nats = argTypes.Length; 352 int nats = argTypes.Length;
307 for (i = nats; -- i >= 0;) { 353 for(i = nats; --i >= 0;)
308 if (argTypes[i] is TokenTypeKey) break; 354 {
355 if(argTypes[i] is TokenTypeKey)
356 break;
309 } 357 }
310 if (i >= 0) { 358 if(i >= 0)
359 {
311 TokenType[] at = new TokenType[nats]; 360 TokenType[] at = new TokenType[nats];
312 for (i = nats; -- i >= 0;) { 361 for(i = nats; --i >= 0;)
362 {
313 at[i] = argTypes[i]; 363 at[i] = argTypes[i];
314 if (argTypes[i] is TokenTypeKey) { 364 if(argTypes[i] is TokenTypeKey)
315 at[i] = new TokenTypeStr (argTypes[i]); 365 {
366 at[i] = new TokenTypeStr(argTypes[i]);
316 } 367 }
317 } 368 }
318 return at; 369 return at;
@@ -324,48 +375,60 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
324 // foreach goes through all the TokenDeclVars that were added 375 // foreach goes through all the TokenDeclVars that were added
325 376
326 // IEnumerable 377 // IEnumerable
327 public IEnumerator GetEnumerator () 378 public IEnumerator GetEnumerator()
328 { 379 {
329 return new VarDictEnumerator (this.master, this.count); 380 return new VarDictEnumerator(this.master, this.count);
330 } 381 }
331 382
332 private class VarDictEnumerator : IEnumerator { 383 private class VarDictEnumerator: IEnumerator
384 {
333 private IEnumerator masterEnum; 385 private IEnumerator masterEnum;
334 private IEnumerator typedicEnum; 386 private IEnumerator typedicEnum;
335 private int count; 387 private int count;
336 388
337 public VarDictEnumerator (Dictionary<string, Dictionary<ArgTypes, TDVEntry>> master, int count) 389 public VarDictEnumerator(Dictionary<string, Dictionary<ArgTypes, TDVEntry>> master, int count)
338 { 390 {
339 masterEnum = master.Values.GetEnumerator (); 391 masterEnum = master.Values.GetEnumerator();
340 this.count = count; 392 this.count = count;
341 } 393 }
342 394
343 // IEnumerator 395 // IEnumerator
344 public void Reset () 396 public void Reset()
345 { 397 {
346 masterEnum.Reset (); 398 masterEnum.Reset();
347 typedicEnum = null; 399 typedicEnum = null;
348 } 400 }
349 401
350 // IEnumerator 402 // IEnumerator
351 public bool MoveNext () 403 public bool MoveNext()
352 { 404 {
353 while (true) { 405 while(true)
354 if (typedicEnum != null) { 406 {
355 while (typedicEnum.MoveNext ()) { 407 if(typedicEnum != null)
356 if (((TDVEntry)typedicEnum.Current).count <= this.count) return true; 408 {
409 while(typedicEnum.MoveNext())
410 {
411 if(((TDVEntry)typedicEnum.Current).count <= this.count)
412 return true;
357 } 413 }
358 typedicEnum = null; 414 typedicEnum = null;
359 } 415 }
360 if (!masterEnum.MoveNext ()) return false; 416 if(!masterEnum.MoveNext())
417 return false;
361 Dictionary<ArgTypes, TDVEntry> ctd; 418 Dictionary<ArgTypes, TDVEntry> ctd;
362 ctd = (Dictionary<ArgTypes, TDVEntry>)masterEnum.Current; 419 ctd = (Dictionary<ArgTypes, TDVEntry>)masterEnum.Current;
363 typedicEnum = ctd.Values.GetEnumerator (); 420 typedicEnum = ctd.Values.GetEnumerator();
364 } 421 }
365 } 422 }
366 423
367 // IEnumerator 424 // IEnumerator
368 public object Current { get { return ((TDVEntry)typedicEnum.Current).var; } } 425 public object Current
426 {
427 get
428 {
429 return ((TDVEntry)typedicEnum.Current).var;
430 }
431 }
369 } 432 }
370 } 433 }
371} 434}