diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs | 97 |
1 files changed, 32 insertions, 65 deletions
diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs index 2561d02..a0bc7ba 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptVarDict.cs | |||
@@ -130,9 +130,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
130 | throw new Exception("var dict is frozen"); | 130 | throw new Exception("var dict is frozen"); |
131 | } | 131 | } |
132 | 132 | ||
133 | /* | 133 | // 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) | ||
135 | */ | ||
136 | Dictionary<ArgTypes, TDVEntry> typedic; | 134 | Dictionary<ArgTypes, TDVEntry> typedic; |
137 | if(!master.TryGetValue(var.name.val, out typedic)) | 135 | if(!master.TryGetValue(var.name.val, out typedic)) |
138 | { | 136 | { |
@@ -140,19 +138,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
140 | master.Add(var.name.val, typedic); | 138 | master.Add(var.name.val, typedic); |
141 | } | 139 | } |
142 | 140 | ||
143 | /* | 141 | // See if there is an entry in the sub-dictionary that matches the argument signature. |
144 | * See if there is an entry in the sub-dictionary that matches the argument signature. | 142 | // Note that fields have null argument lists. |
145 | * Note that fields have null argument lists. | 143 | // 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. | ||
147 | */ | ||
148 | ArgTypes types; | 144 | ArgTypes types; |
149 | types.argTypes = (var.argDecl == null) ? null : KeyTypesToStringTypes(var.argDecl.types); | 145 | types.argTypes = (var.argDecl == null) ? null : KeyTypesToStringTypes(var.argDecl.types); |
150 | if(typedic.ContainsKey(types)) | 146 | if(typedic.ContainsKey(types)) |
151 | return false; | 147 | return false; |
152 | 148 | ||
153 | /* | 149 | // It is unique, add to its name-specific sub-dictionary. |
154 | * It is unique, add to its name-specific sub-dictionary. | ||
155 | */ | ||
156 | TDVEntry entry; | 150 | TDVEntry entry; |
157 | entry.count = ++count; | 151 | entry.count = ++count; |
158 | entry.var = var; | 152 | entry.var = var; |
@@ -175,28 +169,21 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
175 | */ | 169 | */ |
176 | public VarDict FreezeLocals() | 170 | public VarDict FreezeLocals() |
177 | { | 171 | { |
178 | /* | 172 | // If not local var frame, return original frame as is. |
179 | * If not local var frame, return original frame as is. | 173 | // This will allow forward references as the future additions |
180 | * This will allow forward references as the future additions | 174 | // will be seen by lookups done in this dictionary. |
181 | * will be seen by lookups done in this dictionary. | ||
182 | */ | ||
183 | if(!locals) | 175 | if(!locals) |
184 | return this; | 176 | return this; |
185 | 177 | ||
186 | /* | 178 | // If local var frame, return a copy frozen at this point. |
187 | * If local var frame, return a copy frozen at this point. | 179 | // This disallows forward referenes as those future additions |
188 | * This disallows forward referenes as those future additions | 180 | // will not be seen by lookups done in the frozen dictionary. |
189 | * will not be seen by lookups done in the frozen dictionary. | ||
190 | */ | ||
191 | if((frozenLocals == null) || (frozenLocals.count != this.count)) | 181 | if((frozenLocals == null) || (frozenLocals.count != this.count)) |
192 | { | 182 | { |
193 | 183 | // Make a copy of the current var dictionary frame. | |
194 | /* | 184 | // We copy a reference to the dictionary, and though it may |
195 | * Make a copy of the current var dictionary frame. | 185 | // contain additions made after this point, those additions |
196 | * We copy a reference to the dictionary, and though it may | 186 | // will have a count .gt. frozen count and will be ignored. |
197 | * contain additions made after this point, those additions | ||
198 | * will have a count .gt. frozen count and will be ignored. | ||
199 | */ | ||
200 | frozenLocals = new VarDict(true); | 187 | frozenLocals = new VarDict(true); |
201 | 188 | ||
202 | frozenLocals.outerVarDict = this.outerVarDict; | 189 | frozenLocals.outerVarDict = this.outerVarDict; |
@@ -205,11 +192,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
205 | frozenLocals.count = this.count; | 192 | frozenLocals.count = this.count; |
206 | frozenLocals.frozenLocals = frozenLocals; | 193 | frozenLocals.frozenLocals = frozenLocals; |
207 | 194 | ||
208 | /* | 195 | // Mark it as being frozen. |
209 | * Mark it as being frozen. | 196 | // - assert fail if any attempt is made to add to it |
210 | * - assert fail if any attempt is made to add to it | 197 | // - ignore any additions to the dictionary with greater count |
211 | * - ignore any additions to the dictionary with greater count | ||
212 | */ | ||
213 | frozenLocals.isFrozen = true; | 198 | frozenLocals.isFrozen = true; |
214 | } | 199 | } |
215 | return frozenLocals; | 200 | return frozenLocals; |
@@ -257,46 +242,34 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
257 | */ | 242 | */ |
258 | public TokenDeclVar FindExact(string name, TokenType[] argTypes) | 243 | public TokenDeclVar FindExact(string name, TokenType[] argTypes) |
259 | { | 244 | { |
260 | /* | 245 | // Look for list of stuff that matches the given name. |
261 | * Look for list of stuff that matches the given name. | ||
262 | */ | ||
263 | Dictionary<ArgTypes, TDVEntry> typedic; | 246 | Dictionary<ArgTypes, TDVEntry> typedic; |
264 | if(!master.TryGetValue(name, out typedic)) | 247 | if(!master.TryGetValue(name, out typedic)) |
265 | return null; | 248 | return null; |
266 | 249 | ||
267 | /* | 250 | // 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. | ||
269 | */ | ||
270 | foreach(TDVEntry entry in typedic.Values) | 251 | foreach(TDVEntry entry in typedic.Values) |
271 | { | 252 | { |
272 | if(entry.count > this.count) | 253 | if(entry.count > this.count) |
273 | continue; | 254 | continue; |
274 | TokenDeclVar var = entry.var; | 255 | TokenDeclVar var = entry.var; |
275 | 256 | ||
276 | /* | 257 | // Get argument types of declaration. |
277 | * Get argument types of declaration. | 258 | // fields are always null |
278 | * fields are always null | 259 | // methods are always non-null, though may be zero-length |
279 | * methods are always non-null, though may be zero-length | ||
280 | */ | ||
281 | TokenType[] declArgs = (var.argDecl == null) ? null : var.argDecl.types; | 260 | TokenType[] declArgs = (var.argDecl == null) ? null : var.argDecl.types; |
282 | 261 | ||
283 | /* | 262 | // Convert any key args to string args. |
284 | * Convert any key args to string args. | ||
285 | */ | ||
286 | declArgs = KeyTypesToStringTypes(declArgs); | 263 | declArgs = KeyTypesToStringTypes(declArgs); |
287 | 264 | ||
288 | /* | 265 | // 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. | ||
290 | */ | ||
291 | if((declArgs == null) && (argTypes == null)) | 266 | if((declArgs == null) && (argTypes == null)) |
292 | return var; | 267 | return var; |
293 | 268 | ||
294 | /* | 269 | // 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. | 270 | // If it turns out the arg types do not match, the compiler will give an error |
296 | * If it turns out the arg types do not match, the compiler will give an error | 271 | // trying to cast the arguments to the delegate arg types. |
297 | * trying to cast the arguments to the delegate arg types. | 272 | // 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. | ||
299 | */ | ||
300 | if((declArgs == null) && (argTypes != null)) | 273 | if((declArgs == null) && (argTypes != null)) |
301 | { | 274 | { |
302 | TokenType fieldType = var.type; | 275 | TokenType fieldType = var.type; |
@@ -304,15 +277,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
304 | return var; | 277 | return var; |
305 | } | 278 | } |
306 | 279 | ||
307 | /* | 280 | // If not both null, no match, keep looking. |
308 | * If not both null, no match, keep looking. | ||
309 | */ | ||
310 | if((declArgs == null) || (argTypes == null)) | 281 | if((declArgs == null) || (argTypes == null)) |
311 | continue; | 282 | continue; |
312 | 283 | ||
313 | /* | 284 | // 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. | ||
315 | */ | ||
316 | int i = declArgs.Length; | 285 | int i = declArgs.Length; |
317 | if(i != argTypes.Length) | 286 | if(i != argTypes.Length) |
318 | continue; | 287 | continue; |
@@ -331,9 +300,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
331 | return var; | 300 | return var; |
332 | } | 301 | } |
333 | 302 | ||
334 | /* | 303 | // No match. |
335 | * No match. | ||
336 | */ | ||
337 | return null; | 304 | return null; |
338 | } | 305 | } |
339 | 306 | ||