diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs | 1518 |
1 files changed, 509 insertions, 1009 deletions
diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs index b0653f7..85bc9aa 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs | |||
@@ -58,7 +58,6 @@ using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | |||
58 | 58 | ||
59 | namespace OpenSim.Region.ScriptEngine.Yengine | 59 | namespace OpenSim.Region.ScriptEngine.Yengine |
60 | { | 60 | { |
61 | |||
62 | public class ScriptReduce | 61 | public class ScriptReduce |
63 | { | 62 | { |
64 | public const uint SDT_PRIVATE = 1; | 63 | public const uint SDT_PRIVATE = 1; |
@@ -177,25 +176,21 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
177 | */ | 176 | */ |
178 | private ScriptReduce(TokenBegin tokenBegin) | 177 | private ScriptReduce(TokenBegin tokenBegin) |
179 | { | 178 | { |
180 | /* | 179 | // Create a place to put the top-level script components, |
181 | * Create a place to put the top-level script components, | 180 | // eg, state bodies, functions, global variables. |
182 | * eg, state bodies, functions, global variables. | ||
183 | */ | ||
184 | tokenScript = new TokenScript(tokenBegin.nextToken); | 181 | tokenScript = new TokenScript(tokenBegin.nextToken); |
185 | 182 | ||
186 | /* | 183 | // 'class', 'delegate', 'instance' all define types. |
187 | * 'class', 'delegate', 'instance' all define types. | 184 | // So we pre-scan the source tokens for those keywords |
188 | * So we pre-scan the source tokens for those keywords | 185 | // to build a script-defined type table and substitute |
189 | * to build a script-defined type table and substitute | 186 | // type tokens for those names in the source. This is |
190 | * type tokens for those names in the source. This is | 187 | // done as a separate scan so they can cross-reference |
191 | * done as a separate scan so they can cross-reference | 188 | // each other. Also does likewise for fixed array types. |
192 | * each other. Also does likewise for fixed array types. | 189 | // |
193 | * | 190 | // Also, all 'typedef's are processed here. Their definitions |
194 | * Also, all 'typedef's are processed here. Their definitions | 191 | // remain in the source token stream after this, but they can |
195 | * remain in the source token stream after this, but they can | 192 | // be skipped over, because their bodies have been substituted |
196 | * be skipped over, because their bodies have been substituted | 193 | // in the source for any references. |
197 | * in the source for any references. | ||
198 | */ | ||
199 | ParseSDTypePreScanPassOne(tokenBegin); // catalog definitions | 194 | ParseSDTypePreScanPassOne(tokenBegin); // catalog definitions |
200 | ParseSDTypePreScanPassTwo(tokenBegin); // substitute references | 195 | ParseSDTypePreScanPassTwo(tokenBegin); // substitute references |
201 | 196 | ||
@@ -226,10 +221,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
226 | } | 221 | } |
227 | */ | 222 | */ |
228 | 223 | ||
229 | /* | 224 | // Create a function $globalvarinit to hold all explicit |
230 | * Create a function $globalvarinit to hold all explicit | 225 | // global variable initializations. |
231 | * global variable initializations. | ||
232 | */ | ||
233 | TokenDeclVar gviFunc = new TokenDeclVar(tokenBegin, null, tokenScript); | 226 | TokenDeclVar gviFunc = new TokenDeclVar(tokenBegin, null, tokenScript); |
234 | gviFunc.name = new TokenName(gviFunc, "$globalvarinit"); | 227 | gviFunc.name = new TokenName(gviFunc, "$globalvarinit"); |
235 | gviFunc.retType = new TokenTypeVoid(gviFunc); | 228 | gviFunc.retType = new TokenTypeVoid(gviFunc); |
@@ -240,9 +233,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
240 | tokenScript.globalVarInit = gviFunc; | 233 | tokenScript.globalVarInit = gviFunc; |
241 | tokenScript.AddVarEntry(gviFunc); | 234 | tokenScript.AddVarEntry(gviFunc); |
242 | 235 | ||
243 | /* | 236 | // Scan through the tokens until we reach the end. |
244 | * Scan through the tokens until we reach the end. | ||
245 | */ | ||
246 | for(Token token = tokenBegin.nextToken; !(token is TokenEnd);) | 237 | for(Token token = tokenBegin.nextToken; !(token is TokenEnd);) |
247 | { | 238 | { |
248 | if(token is TokenKwSemi) | 239 | if(token is TokenKwSemi) |
@@ -251,25 +242,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
251 | continue; | 242 | continue; |
252 | } | 243 | } |
253 | 244 | ||
254 | /* | 245 | // Script-defined type declarations. |
255 | * Script-defined type declarations. | ||
256 | */ | ||
257 | if(ParseDeclSDTypes(ref token, null, SDT_PUBLIC)) | 246 | if(ParseDeclSDTypes(ref token, null, SDT_PUBLIC)) |
258 | continue; | 247 | continue; |
259 | 248 | ||
260 | /* | 249 | // constant <name> = <rval> ; |
261 | * constant <name> = <rval> ; | ||
262 | */ | ||
263 | if(token is TokenKwConst) | 250 | if(token is TokenKwConst) |
264 | { | 251 | { |
265 | ParseDeclVar(ref token, null); | 252 | ParseDeclVar(ref token, null); |
266 | continue; | 253 | continue; |
267 | } | 254 | } |
268 | 255 | ||
269 | /* | 256 | // <type> <name> ; |
270 | * <type> <name> ; | 257 | // <type> <name> = <rval> ; |
271 | * <type> <name> = <rval> ; | ||
272 | */ | ||
273 | if((token is TokenType) && | 258 | if((token is TokenType) && |
274 | (token.nextToken is TokenName) && | 259 | (token.nextToken is TokenName) && |
275 | ((token.nextToken.nextToken is TokenKwSemi) || | 260 | ((token.nextToken.nextToken is TokenKwSemi) || |
@@ -285,9 +270,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
285 | continue; | 270 | continue; |
286 | } | 271 | } |
287 | 272 | ||
288 | /* | 273 | // <type> <name> { [ get { <body> } ] [ set { <body> } ] } |
289 | * <type> <name> { [ get { <body> } ] [ set { <body> } ] } | ||
290 | */ | ||
291 | if((token is TokenType) && | 274 | if((token is TokenType) && |
292 | (token.nextToken is TokenName) && | 275 | (token.nextToken is TokenName) && |
293 | (token.nextToken.nextToken is TokenKwBrcOpen)) | 276 | (token.nextToken.nextToken is TokenKwBrcOpen)) |
@@ -296,10 +279,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
296 | continue; | 279 | continue; |
297 | } | 280 | } |
298 | 281 | ||
299 | /* | 282 | // <type> <name> <funcargs> <funcbody> |
300 | * <type> <name> <funcargs> <funcbody> | 283 | // global function returning specified type |
301 | * global function returning specified type | ||
302 | */ | ||
303 | if(token is TokenType) | 284 | if(token is TokenType) |
304 | { | 285 | { |
305 | TokenType tokenType = (TokenType)token; | 286 | TokenType tokenType = (TokenType)token; |
@@ -330,10 +311,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
330 | continue; | 311 | continue; |
331 | } | 312 | } |
332 | 313 | ||
333 | /* | 314 | // <name> <funcargs> <funcbody> |
334 | * <name> <funcargs> <funcbody> | 315 | // global function returning void |
335 | * global function returning void | ||
336 | */ | ||
337 | if(token is TokenName) | 316 | if(token is TokenName) |
338 | { | 317 | { |
339 | TokenName tokenName = (TokenName)token; | 318 | TokenName tokenName = (TokenName)token; |
@@ -355,9 +334,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
355 | continue; | 334 | continue; |
356 | } | 335 | } |
357 | 336 | ||
358 | /* | 337 | // default <statebody> |
359 | * default <statebody> | ||
360 | */ | ||
361 | if(token is TokenKwDefault) | 338 | if(token is TokenKwDefault) |
362 | { | 339 | { |
363 | TokenDeclState tokenDeclState = new TokenDeclState(token); | 340 | TokenDeclState tokenDeclState = new TokenDeclState(token); |
@@ -374,9 +351,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
374 | continue; | 351 | continue; |
375 | } | 352 | } |
376 | 353 | ||
377 | /* | 354 | // state <name> <statebody> |
378 | * state <name> <statebody> | ||
379 | */ | ||
380 | if(token is TokenKwState) | 355 | if(token is TokenKwState) |
381 | { | 356 | { |
382 | TokenDeclState tokenDeclState = new TokenDeclState(token); | 357 | TokenDeclState tokenDeclState = new TokenDeclState(token); |
@@ -401,25 +376,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
401 | continue; | 376 | continue; |
402 | } | 377 | } |
403 | 378 | ||
404 | /* | 379 | // Doesn't fit any of those forms, output message and skip to next statement. |
405 | * Doesn't fit any of those forms, output message and skip to next statement. | ||
406 | */ | ||
407 | ErrorMsg(token, "looking for var name, type, state or default, script-defined type declaration"); | 380 | ErrorMsg(token, "looking for var name, type, state or default, script-defined type declaration"); |
408 | token = SkipPastSemi(token); | 381 | token = SkipPastSemi(token); |
409 | continue; | 382 | continue; |
410 | } | 383 | } |
411 | 384 | ||
412 | /* | 385 | // Must have a default state to start in. |
413 | * Must have a default state to start in. | ||
414 | */ | ||
415 | if(!errors && (tokenScript.defaultState == null)) | 386 | if(!errors && (tokenScript.defaultState == null)) |
416 | { | 387 | { |
417 | ErrorMsg(tokenScript, "no default state defined"); | 388 | ErrorMsg(tokenScript, "no default state defined"); |
418 | } | 389 | } |
419 | 390 | ||
420 | /* | 391 | // If any error messages were written out, set return value to null. |
421 | * If any error messages were written out, set return value to null. | ||
422 | */ | ||
423 | if(errors) | 392 | if(errors) |
424 | tokenScript = null; | 393 | tokenScript = null; |
425 | } | 394 | } |
@@ -444,10 +413,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
444 | 413 | ||
445 | for(Token t = tokenBegin; !((t = t.nextToken) is TokenEnd);) | 414 | for(Token t = tokenBegin; !((t = t.nextToken) is TokenEnd);) |
446 | { | 415 | { |
447 | /* | 416 | // Keep track of nested definitions so we can link them up. |
448 | * Keep track of nested definitions so we can link them up. | 417 | // We also need to detect the end of class and interface definitions. |
449 | * We also need to detect the end of class and interface definitions. | ||
450 | */ | ||
451 | if(t is TokenKwBrcOpen) | 418 | if(t is TokenKwBrcOpen) |
452 | { | 419 | { |
453 | openBraceLevel++; | 420 | openBraceLevel++; |
@@ -468,11 +435,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
468 | continue; | 435 | continue; |
469 | } | 436 | } |
470 | 437 | ||
471 | /* | 438 | // Check for 'class' or 'interface'. |
472 | * Check for 'class' or 'interface'. | 439 | // They always define a new class or interface. |
473 | * They always define a new class or interface. | 440 | // They can contain nested script-defined type definitions. |
474 | * They can contain nested script-defined type definitions. | ||
475 | */ | ||
476 | if((t is TokenKwClass) || (t is TokenKwInterface)) | 441 | if((t is TokenKwClass) || (t is TokenKwInterface)) |
477 | { | 442 | { |
478 | Token kw = t; | 443 | Token kw = t; |
@@ -486,9 +451,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
486 | TokenName name = (TokenName)t; | 451 | TokenName name = (TokenName)t; |
487 | t = t.nextToken; | 452 | t = t.nextToken; |
488 | 453 | ||
489 | /* | 454 | // Malloc the script-defined type object. |
490 | * Malloc the script-defined type object. | ||
491 | */ | ||
492 | TokenDeclSDType decl; | 455 | TokenDeclSDType decl; |
493 | if(kw is TokenKwClass) | 456 | if(kw is TokenKwClass) |
494 | decl = new TokenDeclSDTypeClass(name, kw.prevToken is TokenKwPartial); | 457 | decl = new TokenDeclSDTypeClass(name, kw.prevToken is TokenKwPartial); |
@@ -496,56 +459,43 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
496 | decl = new TokenDeclSDTypeInterface(name); | 459 | decl = new TokenDeclSDTypeInterface(name); |
497 | decl.outerSDType = outerLevels.Peek(); | 460 | decl.outerSDType = outerLevels.Peek(); |
498 | 461 | ||
499 | /* | 462 | // Check for generic parameter list. |
500 | * Check for generic parameter list. | ||
501 | */ | ||
502 | if(!ParseGenProtoParamList(ref t, decl)) | 463 | if(!ParseGenProtoParamList(ref t, decl)) |
503 | continue; | 464 | continue; |
504 | 465 | ||
505 | /* | 466 | // Splice in a TokenDeclSDType token that replaces the keyword and the name tokens |
506 | * Splice in a TokenDeclSDType token that replaces the keyword and the name tokens | 467 | // and any generic parameters including the '<', ','s and '>'. |
507 | * and any generic parameters including the '<', ','s and '>'. | 468 | // kw = points to 'class' or 'interface' keyword. |
508 | * kw = points to 'class' or 'interface' keyword. | 469 | // t = points to just past last part of class name parsed, hopefully a ':' or '{'. |
509 | * t = points to just past last part of class name parsed, hopefully a ':' or '{'. | ||
510 | */ | ||
511 | decl.prevToken = decl.isPartial ? kw.prevToken.prevToken : kw.prevToken; | 470 | decl.prevToken = decl.isPartial ? kw.prevToken.prevToken : kw.prevToken; |
512 | decl.nextToken = t; | 471 | decl.nextToken = t; |
513 | decl.prevToken.nextToken = decl; | 472 | decl.prevToken.nextToken = decl; |
514 | decl.nextToken.prevToken = decl; | 473 | decl.nextToken.prevToken = decl; |
515 | 474 | ||
516 | /* | 475 | // Enter it in name lists so it can be seen by others. |
517 | * Enter it in name lists so it can be seen by others. | ||
518 | */ | ||
519 | Token partialNewBody = CatalogSDTypeDecl(decl); | 476 | Token partialNewBody = CatalogSDTypeDecl(decl); |
520 | 477 | ||
521 | /* | 478 | // Start inner type definitions. |
522 | * Start inner type definitions. | ||
523 | */ | ||
524 | braceLevels.Push(openBraceLevel); | 479 | braceLevels.Push(openBraceLevel); |
525 | outerLevels.Push(decl); | 480 | outerLevels.Push(decl); |
526 | 481 | ||
527 | /* | 482 | // Scan the body starting on for before the '{'. |
528 | * Scan the body starting on for before the '{'. | 483 | // |
529 | * | 484 | // If this body had an old partial merged into it, |
530 | * If this body had an old partial merged into it, | 485 | // resume scanning at the beginning of the new body, |
531 | * resume scanning at the beginning of the new body, | 486 | // ie, what used to be the first token after the '{' |
532 | * ie, what used to be the first token after the '{' | 487 | // before the old body was spliced in. |
533 | * before the old body was spliced in. | ||
534 | */ | ||
535 | if(partialNewBody != null) | 488 | if(partialNewBody != null) |
536 | { | 489 | { |
537 | 490 | // We have a partial that has had old partial body merged | |
538 | /* | 491 | // into new partial body. So resume scanning at the beginning |
539 | * We have a partial that has had old partial body merged | 492 | // of the new partial body so we don't get any duplicate scanning |
540 | * into new partial body. So resume scanning at the beginning | 493 | // of the old partial body. |
541 | * of the new partial body so we don't get any duplicate scanning | 494 | // |
542 | * of the old partial body. | 495 | // <decl> ... { <oldbody> <newbody> } |
543 | * | 496 | // ^- resume scanning here |
544 | * <decl> ... { <oldbody> <newbody> } | 497 | // but inc openBraceLevel because |
545 | * ^- resume scanning here | 498 | // we skipped scanning the '{' |
546 | * but inc openBraceLevel because | ||
547 | * we skipped scanning the '{' | ||
548 | */ | ||
549 | openBraceLevel++; | 499 | openBraceLevel++; |
550 | t = partialNewBody; | 500 | t = partialNewBody; |
551 | } | 501 | } |
@@ -553,23 +503,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
553 | continue; | 503 | continue; |
554 | } | 504 | } |
555 | 505 | ||
556 | /* | 506 | // Check for 'delegate'. |
557 | * Check for 'delegate'. | 507 | // It always defines a new delegate. |
558 | * It always defines a new delegate. | 508 | // Delegates never define nested types. |
559 | * Delegates never define nested types. | ||
560 | */ | ||
561 | if(t is TokenKwDelegate) | 509 | if(t is TokenKwDelegate) |
562 | { | 510 | { |
563 | Token kw = t; | 511 | Token kw = t; |
564 | t = t.nextToken; | 512 | t = t.nextToken; |
565 | 513 | ||
566 | /* | 514 | // Next thing might be an explicit return type or the delegate's name. |
567 | * Next thing might be an explicit return type or the delegate's name. | 515 | // If it's a type token, then it's the return type, simple enough. |
568 | * If it's a type token, then it's the return type, simple enough. | 516 | // But if it's a name token, it might be the name of some other script-defined type. |
569 | * But if it's a name token, it might be the name of some other script-defined type. | 517 | // The way to tell is that the delegate name is followed by a '(', whereas an |
570 | * The way to tell is that the delegate name is followed by a '(', whereas an | 518 | // explicit return type is followed by the delegate name. |
571 | * explicit return type is followed by the delegate name. | ||
572 | */ | ||
573 | Token retType = t; | 519 | Token retType = t; |
574 | TokenName delName = null; | 520 | TokenName delName = null; |
575 | Token u; | 521 | Token u; |
@@ -602,29 +548,21 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
602 | if(retType == delName) | 548 | if(retType == delName) |
603 | retType = null; | 549 | retType = null; |
604 | 550 | ||
605 | /* | 551 | // Malloc the script-defined type object. |
606 | * Malloc the script-defined type object. | ||
607 | */ | ||
608 | TokenDeclSDTypeDelegate decl = new TokenDeclSDTypeDelegate(delName); | 552 | TokenDeclSDTypeDelegate decl = new TokenDeclSDTypeDelegate(delName); |
609 | decl.outerSDType = outerLevels.Peek(); | 553 | decl.outerSDType = outerLevels.Peek(); |
610 | 554 | ||
611 | /* | 555 | // Check for generic parameter list. |
612 | * Check for generic parameter list. | ||
613 | */ | ||
614 | t = delName.nextToken; | 556 | t = delName.nextToken; |
615 | if(!ParseGenProtoParamList(ref t, decl)) | 557 | if(!ParseGenProtoParamList(ref t, decl)) |
616 | continue; | 558 | continue; |
617 | 559 | ||
618 | /* | 560 | // Enter it in name lists so it can be seen by others. |
619 | * Enter it in name lists so it can be seen by others. | ||
620 | */ | ||
621 | CatalogSDTypeDecl(decl); | 561 | CatalogSDTypeDecl(decl); |
622 | 562 | ||
623 | /* | 563 | // Splice in the token that replaces the 'delegate' keyword and the whole name |
624 | * Splice in the token that replaces the 'delegate' keyword and the whole name | 564 | // (including the '<' name ... '>' parts). The return type token(s), if any, |
625 | * (including the '<' name ... '>' parts). The return type token(s), if any, | 565 | // follow the splice token and come before the '('. |
626 | * follow the splice token and come before the '('. | ||
627 | */ | ||
628 | decl.prevToken = kw.prevToken; | 566 | decl.prevToken = kw.prevToken; |
629 | kw.prevToken.nextToken = decl; | 567 | kw.prevToken.nextToken = decl; |
630 | 568 | ||
@@ -641,10 +579,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
641 | t.prevToken = retType; | 579 | t.prevToken = retType; |
642 | } | 580 | } |
643 | 581 | ||
644 | /* | 582 | // Scan for terminating ';'. |
645 | * Scan for terminating ';'. | 583 | // There cannot be an intervening class, delegate, interfate, typedef, { or }. |
646 | * There cannot be an intervening class, delegate, interfate, typedef, { or }. | ||
647 | */ | ||
648 | for(t = decl; !(t is TokenKwSemi); t = u) | 584 | for(t = decl; !(t is TokenKwSemi); t = u) |
649 | { | 585 | { |
650 | u = t.nextToken; | 586 | u = t.nextToken; |
@@ -664,11 +600,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
664 | continue; | 600 | continue; |
665 | } | 601 | } |
666 | 602 | ||
667 | /* | 603 | // Check for 'typedef'. |
668 | * Check for 'typedef'. | 604 | // It always defines a new macro. |
669 | * It always defines a new macro. | 605 | // Typedefs never define nested types. |
670 | * Typedefs never define nested types. | ||
671 | */ | ||
672 | if(t is TokenKwTypedef) | 606 | if(t is TokenKwTypedef) |
673 | { | 607 | { |
674 | Token kw = t; | 608 | Token kw = t; |
@@ -683,37 +617,27 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
683 | TokenName tdName = (TokenName)t; | 617 | TokenName tdName = (TokenName)t; |
684 | t = t.nextToken; | 618 | t = t.nextToken; |
685 | 619 | ||
686 | /* | 620 | // Malloc the script-defined type object. |
687 | * Malloc the script-defined type object. | ||
688 | */ | ||
689 | TokenDeclSDTypeTypedef decl = new TokenDeclSDTypeTypedef(tdName); | 621 | TokenDeclSDTypeTypedef decl = new TokenDeclSDTypeTypedef(tdName); |
690 | decl.outerSDType = outerLevels.Peek(); | 622 | decl.outerSDType = outerLevels.Peek(); |
691 | 623 | ||
692 | /* | 624 | // Check for generic parameter list. |
693 | * Check for generic parameter list. | ||
694 | */ | ||
695 | if(!ParseGenProtoParamList(ref t, decl)) | 625 | if(!ParseGenProtoParamList(ref t, decl)) |
696 | continue; | 626 | continue; |
697 | 627 | ||
698 | /* | 628 | // Enter it in name lists so it can be seen by others. |
699 | * Enter it in name lists so it can be seen by others. | ||
700 | */ | ||
701 | CatalogSDTypeDecl(decl); | 629 | CatalogSDTypeDecl(decl); |
702 | numTypedefs++; | 630 | numTypedefs++; |
703 | 631 | ||
704 | /* | 632 | // Splice in the token that replaces the 'typedef' keyword and the whole name |
705 | * Splice in the token that replaces the 'typedef' keyword and the whole name | 633 | // (including the '<' name ... '>' parts). |
706 | * (including the '<' name ... '>' parts). | ||
707 | */ | ||
708 | decl.prevToken = kw.prevToken; | 634 | decl.prevToken = kw.prevToken; |
709 | kw.prevToken.nextToken = decl; | 635 | kw.prevToken.nextToken = decl; |
710 | decl.nextToken = t; | 636 | decl.nextToken = t; |
711 | t.prevToken = decl; | 637 | t.prevToken = decl; |
712 | 638 | ||
713 | /* | 639 | // Scan for terminating ';'. |
714 | * Scan for terminating ';'. | 640 | // There cannot be an intervening class, delegate, interfate, typedef, { or }. |
715 | * There cannot be an intervening class, delegate, interfate, typedef, { or }. | ||
716 | */ | ||
717 | Token u; | 641 | Token u; |
718 | for(t = decl; !(t is TokenKwSemi); t = u) | 642 | for(t = decl; !(t is TokenKwSemi); t = u) |
719 | { | 643 | { |
@@ -747,16 +671,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
747 | */ | 671 | */ |
748 | private bool ParseGenProtoParamList(ref Token t, TokenDeclSDType decl) | 672 | private bool ParseGenProtoParamList(ref Token t, TokenDeclSDType decl) |
749 | { | 673 | { |
750 | /* | 674 | // Maybe there aren't any generic parameters. |
751 | * Maybe there aren't any generic parameters. | 675 | // If so, leave decl.genParams = null. |
752 | * If so, leave decl.genParams = null. | ||
753 | */ | ||
754 | if(!(t is TokenKwCmpLT)) | 676 | if(!(t is TokenKwCmpLT)) |
755 | return true; | 677 | return true; |
756 | 678 | ||
757 | /* | 679 | // Build list of generic parameter names. |
758 | * Build list of generic parameter names. | ||
759 | */ | ||
760 | Dictionary<string, int> parms = new Dictionary<string, int>(); | 680 | Dictionary<string, int> parms = new Dictionary<string, int>(); |
761 | do | 681 | do |
762 | { | 682 | { |
@@ -813,17 +733,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
813 | if(!GenericParametersMatch(decl, dupDecl)) | 733 | if(!GenericParametersMatch(decl, dupDecl)) |
814 | ErrorMsg(decl, "all partial class generic parameters must match"); | 734 | ErrorMsg(decl, "all partial class generic parameters must match"); |
815 | 735 | ||
816 | /* | 736 | // Have new declaration be the cataloged one because body is going to get |
817 | * Have new declaration be the cataloged one because body is going to get | 737 | // snipped out of old declaration and pasted into new declaration. |
818 | * snipped out of old declaration and pasted into new declaration. | ||
819 | */ | ||
820 | tokenScript.sdSrcTypesRep(longName, decl); | 738 | tokenScript.sdSrcTypesRep(longName, decl); |
821 | if(decl.outerSDType != null) | 739 | if(decl.outerSDType != null) |
822 | decl.outerSDType.innerSDTypes[decl.shortName.val] = decl; | 740 | decl.outerSDType.innerSDTypes[decl.shortName.val] = decl; |
823 | 741 | ||
824 | /* | 742 | // Find old partial definition's opening brace. |
825 | * Find old partial definition's opening brace. | ||
826 | */ | ||
827 | Token dupBrcOpen; | 743 | Token dupBrcOpen; |
828 | for(dupBrcOpen = dupDecl; !(dupBrcOpen is TokenKwBrcOpen); dupBrcOpen = dupBrcOpen.nextToken) | 744 | for(dupBrcOpen = dupDecl; !(dupBrcOpen is TokenKwBrcOpen); dupBrcOpen = dupBrcOpen.nextToken) |
829 | { | 745 | { |
@@ -834,9 +750,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
834 | } | 750 | } |
835 | } | 751 | } |
836 | 752 | ||
837 | /* | 753 | // Find new partial definition's opening brace. |
838 | * Find new partial definition's opening brace. | ||
839 | */ | ||
840 | Token brcOpen; | 754 | Token brcOpen; |
841 | for(brcOpen = decl; !(brcOpen is TokenKwBrcOpen); brcOpen = brcOpen.nextToken) | 755 | for(brcOpen = decl; !(brcOpen is TokenKwBrcOpen); brcOpen = brcOpen.nextToken) |
842 | { | 756 | { |
@@ -848,25 +762,23 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
848 | } | 762 | } |
849 | Token body = brcOpen.nextToken; | 763 | Token body = brcOpen.nextToken; |
850 | 764 | ||
851 | /* | 765 | // Stick old partial definition's extends/implementeds list just |
852 | * Stick old partial definition's extends/implementeds list just | 766 | // in front of new partial definition's extends/implementeds list. |
853 | * in front of new partial definition's extends/implementeds list. | 767 | // |
854 | * | 768 | // class oldextimp { oldbody } ... |
855 | * class oldextimp { oldbody } ... | 769 | // dupDecl dupBrcOpen dupDecl.endToken |
856 | * dupDecl dupBrcOpen dupDecl.endToken | 770 | // |
857 | * | 771 | // class newextimp { newbody } ... |
858 | * class newextimp { newbody } ... | 772 | // decl brcOpen body decl.endToken |
859 | * decl brcOpen body decl.endToken | 773 | // |
860 | * | 774 | // becomes |
861 | * becomes | 775 | // |
862 | * | 776 | // class ... |
863 | * class ... | 777 | // dupDecl |
864 | * dupDecl | 778 | // dupDecl.endToken |
865 | * dupDecl.endToken | 779 | // |
866 | * | 780 | // class oldextimp newextimp { oldbody newbody } ... |
867 | * class oldextimp newextimp { oldbody newbody } ... | 781 | // decl brcOpen body decl.endToken |
868 | * decl brcOpen body decl.endToken | ||
869 | */ | ||
870 | if(dupBrcOpen != dupDecl.nextToken) | 782 | if(dupBrcOpen != dupDecl.nextToken) |
871 | { | 783 | { |
872 | dupBrcOpen.prevToken.nextToken = decl.nextToken; | 784 | dupBrcOpen.prevToken.nextToken = decl.nextToken; |
@@ -875,10 +787,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
875 | decl.nextToken = dupDecl.nextToken; | 787 | decl.nextToken = dupDecl.nextToken; |
876 | } | 788 | } |
877 | 789 | ||
878 | /* | 790 | // Stick old partial definition's body just |
879 | * Stick old partial definition's body just | 791 | // in front of new partial definition's body. |
880 | * in front of new partial definition's body. | ||
881 | */ | ||
882 | if(dupBrcOpen.nextToken != dupDecl.endToken) | 792 | if(dupBrcOpen.nextToken != dupDecl.endToken) |
883 | { | 793 | { |
884 | dupBrcOpen.nextToken.prevToken = brcOpen; | 794 | dupBrcOpen.nextToken.prevToken = brcOpen; |
@@ -887,10 +797,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
887 | brcOpen.nextToken = dupBrcOpen.nextToken; | 797 | brcOpen.nextToken = dupBrcOpen.nextToken; |
888 | } | 798 | } |
889 | 799 | ||
890 | /* | 800 | // Null out old definition's extends/implementeds list and body |
891 | * Null out old definition's extends/implementeds list and body | 801 | // by having the declaration token be the only thing left. |
892 | * by having the declaration token be the only thing left. | ||
893 | */ | ||
894 | dupDecl.nextToken = dupDecl.endToken.nextToken; | 802 | dupDecl.nextToken = dupDecl.endToken.nextToken; |
895 | dupDecl.nextToken.prevToken = dupDecl; | 803 | dupDecl.nextToken.prevToken = dupDecl; |
896 | dupDecl.endToken = dupDecl; | 804 | dupDecl.endToken = dupDecl; |
@@ -946,41 +854,34 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
946 | 854 | ||
947 | for(Token t = tokenBegin; !((t = t.nextToken) is TokenEnd);) | 855 | for(Token t = tokenBegin; !((t = t.nextToken) is TokenEnd);) |
948 | { | 856 | { |
949 | 857 | // Maybe it's time to pop out of an outer class definition. | |
950 | /* | ||
951 | * Maybe it's time to pop out of an outer class definition. | ||
952 | */ | ||
953 | if((outerSDType != null) && (outerSDType.endToken == t)) | 858 | if((outerSDType != null) && (outerSDType.endToken == t)) |
954 | { | 859 | { |
955 | outerSDType = outerSDType.outerSDType; | 860 | outerSDType = outerSDType.outerSDType; |
956 | continue; | 861 | continue; |
957 | } | 862 | } |
958 | 863 | ||
959 | /* | 864 | // Skip completely over any script-defined generic prototypes. |
960 | * Skip completely over any script-defined generic prototypes. | 865 | // We only need to process their instantiations which are non- |
961 | * We only need to process their instantiations which are non- | 866 | // generic versions of the generics. |
962 | * generic versions of the generics. | ||
963 | */ | ||
964 | if((t is TokenDeclSDType) && (((TokenDeclSDType)t).genParams != null)) | 867 | if((t is TokenDeclSDType) && (((TokenDeclSDType)t).genParams != null)) |
965 | { | 868 | { |
966 | t = ((TokenDeclSDType)t).endToken; | 869 | t = ((TokenDeclSDType)t).endToken; |
967 | continue; | 870 | continue; |
968 | } | 871 | } |
969 | 872 | ||
970 | /* | 873 | // Check for beginning of non-generic script-defined type definitions. |
971 | * Check for beginning of non-generic script-defined type definitions. | 874 | // They can have nested definitions in their innerSDTypes[] that match |
972 | * They can have nested definitions in their innerSDTypes[] that match | 875 | // name tokens, so add them to the stack. |
973 | * name tokens, so add them to the stack. | 876 | // |
974 | * | 877 | // But just ignore any preliminary partial definitions as they have had |
975 | * But just ignore any preliminary partial definitions as they have had | 878 | // their entire contents spliced out and spliced into a subsequent partial |
976 | * their entire contents spliced out and spliced into a subsequent partial | 879 | // definition. So if we originally had: |
977 | * definition. So if we originally had: | 880 | // partial class Abc { public intenger one; } |
978 | * partial class Abc { public intenger one; } | 881 | // partial class Abc { public intenger two; } |
979 | * partial class Abc { public intenger two; } | 882 | // We now have: |
980 | * We now have: | 883 | // partial_class_Abc <== if we are here, just ignore the partial_class_Abc token |
981 | * partial_class_Abc <== if we are here, just ignore the partial_class_Abc token | 884 | // partial_class_Abc { public intenger one; public intenger two; } |
982 | * partial_class_Abc { public intenger one; public intenger two; } | ||
983 | */ | ||
984 | if(t is TokenDeclSDType) | 885 | if(t is TokenDeclSDType) |
985 | { | 886 | { |
986 | if(((TokenDeclSDType)t).endToken != t) | 887 | if(((TokenDeclSDType)t).endToken != t) |
@@ -989,22 +890,18 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
989 | continue; | 890 | continue; |
990 | } | 891 | } |
991 | 892 | ||
992 | /* | 893 | // For names not preceded by a '.', scan the script-defined type definition |
993 | * For names not preceded by a '.', scan the script-defined type definition | 894 | // stack for that name. Splice the name out and replace with equivalent token. |
994 | * stack for that name. Splice the name out and replace with equivalent token. | ||
995 | */ | ||
996 | if((t is TokenName) && !(t.prevToken is TokenKwDot)) | 895 | if((t is TokenName) && !(t.prevToken is TokenKwDot)) |
997 | t = TrySpliceTypeRef(t, outerSDType, ref repeat, noTypes); | 896 | t = TrySpliceTypeRef(t, outerSDType, ref repeat, noTypes); |
998 | 897 | ||
999 | /* | 898 | // This handles types such as integer[,][], List<string>[], etc. |
1000 | * This handles types such as integer[,][], List<string>[], etc. | 899 | // They are an instantiation of an internally generated type of the same name, brackets and all. |
1001 | * They are an instantiation of an internally generated type of the same name, brackets and all. | 900 | // Note that to malloc an array, use something like 'new float[,][](3,5)', not 'new float[3,5][]'. |
1002 | * Note that to malloc an array, use something like 'new float[,][](3,5)', not 'new float[3,5][]'. | 901 | // |
1003 | * | 902 | // Note that we must not get confused by $idxprop property declarations such as: |
1004 | * Note that we must not get confused by $idxprop property declarations such as: | 903 | // float [string kee] { get { ... } } |
1005 | * float [string kee] { get { ... } } | 904 | // ... and try to convert 'float' '[' to an array type. |
1006 | * ... and try to convert 'float' '[' to an array type. | ||
1007 | */ | ||
1008 | if((t is TokenType) && (t.nextToken is TokenKwBrkOpen)) | 905 | if((t is TokenType) && (t.nextToken is TokenKwBrkOpen)) |
1009 | { | 906 | { |
1010 | if((t.nextToken.nextToken is TokenKwBrkClose) || | 907 | if((t.nextToken.nextToken is TokenKwBrkClose) || |
@@ -1015,19 +912,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1015 | } | 912 | } |
1016 | } | 913 | } |
1017 | 914 | ||
1018 | /* | 915 | // If we instantiated a generic, loop back to process its contents |
1019 | * If we instantiated a generic, loop back to process its contents | 916 | // just as if the source code had the instantiated code to begin with. |
1020 | * just as if the source code had the instantiated code to begin with. | 917 | // Also repeat if we found a non-type inside the <> of a generic reference |
1021 | * Also repeat if we found a non-type inside the <> of a generic reference | 918 | // provided we have made at least one name->type substitution. |
1022 | * provided we have made at least one name->type substitution. | ||
1023 | */ | ||
1024 | } while(((repeat & REPEAT_INSTGEN) != 0) || | 919 | } while(((repeat & REPEAT_INSTGEN) != 0) || |
1025 | ((repeat & (REPEAT_NOTYPE | REPEAT_SUBST)) == (REPEAT_NOTYPE | REPEAT_SUBST))); | 920 | ((repeat & (REPEAT_NOTYPE | REPEAT_SUBST)) == (REPEAT_NOTYPE | REPEAT_SUBST))); |
1026 | 921 | ||
1027 | /* | 922 | // These are places where we required a type be present, |
1028 | * These are places where we required a type be present, | 923 | // eg, a generic type argument or the body of a typedef. |
1029 | * eg, a generic type argument or the body of a typedef. | ||
1030 | */ | ||
1031 | foreach(Token t in noTypes) | 924 | foreach(Token t in noTypes) |
1032 | ErrorMsg(t, "looking for type"); | 925 | ErrorMsg(t, "looking for type"); |
1033 | } | 926 | } |
@@ -1048,11 +941,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1048 | Token start = t; | 941 | Token start = t; |
1049 | string tnamestr = ((TokenName)t).val; | 942 | string tnamestr = ((TokenName)t).val; |
1050 | 943 | ||
1051 | /* | 944 | // Look for the name as a type declared by outerSDType or anything |
1052 | * Look for the name as a type declared by outerSDType or anything | 945 | // even farther out than that. If not found, simply return |
1053 | * even farther out than that. If not found, simply return | 946 | // without updating t, meaning that t isn't the name of a type. |
1054 | * without updating t, meaning that t isn't the name of a type. | ||
1055 | */ | ||
1056 | TokenDeclSDType decl = null; | 947 | TokenDeclSDType decl = null; |
1057 | while(outerSDType != null) | 948 | while(outerSDType != null) |
1058 | { | 949 | { |
@@ -1066,10 +957,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1066 | TokenDeclSDType instdecl; | 957 | TokenDeclSDType instdecl; |
1067 | while(true) | 958 | while(true) |
1068 | { | 959 | { |
1069 | 960 | // If it is a generic type, it must be followed by instantiation arguments. | |
1070 | /* | ||
1071 | * If it is a generic type, it must be followed by instantiation arguments. | ||
1072 | */ | ||
1073 | instdecl = decl; | 961 | instdecl = decl; |
1074 | if(decl.genParams != null) | 962 | if(decl.genParams != null) |
1075 | { | 963 | { |
@@ -1134,12 +1022,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1134 | tokenScript.sdSrcTypesTryGetValue(tnamestr, out instdecl); | 1022 | tokenScript.sdSrcTypesTryGetValue(tnamestr, out instdecl); |
1135 | } | 1023 | } |
1136 | 1024 | ||
1137 | /* | 1025 | // Couldn't find 'List<string>' but found 'List' and we have genArgs = 'string'. |
1138 | * Couldn't find 'List<string>' but found 'List' and we have genArgs = 'string'. | 1026 | // Instantiate the generic to create 'List<string>'. This splices the definition |
1139 | * Instantiate the generic to create 'List<string>'. This splices the definition | 1027 | // of 'List<string>' into the source token stream just as if it had been there all |
1140 | * of 'List<string>' into the source token stream just as if it had been there all | 1028 | // along. We have to then repeat the scan to process the instance's contents. |
1141 | * along. We have to then repeat the scan to process the instance's contents. | ||
1142 | */ | ||
1143 | if(instdecl == null) | 1029 | if(instdecl == null) |
1144 | { | 1030 | { |
1145 | instdecl = decl.InstantiateGeneric(tnamestr, genArgs, this); | 1031 | instdecl = decl.InstantiateGeneric(tnamestr, genArgs, this); |
@@ -1148,9 +1034,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1148 | } | 1034 | } |
1149 | } | 1035 | } |
1150 | 1036 | ||
1151 | /* | 1037 | // Maybe caller wants a subtype by putting a '.' following all that. |
1152 | * Maybe caller wants a subtype by putting a '.' following all that. | ||
1153 | */ | ||
1154 | if(!(t.nextToken is TokenKwDot)) | 1038 | if(!(t.nextToken is TokenKwDot)) |
1155 | break; | 1039 | break; |
1156 | if(!(t.nextToken.nextToken is TokenName)) | 1040 | if(!(t.nextToken.nextToken is TokenName)) |
@@ -1162,14 +1046,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1162 | outerSDType = instdecl; | 1046 | outerSDType = instdecl; |
1163 | } | 1047 | } |
1164 | 1048 | ||
1165 | /* | 1049 | // Create a reference in the source to the definition |
1166 | * Create a reference in the source to the definition | 1050 | // that encapsulates the long dotted type name given in |
1167 | * that encapsulates the long dotted type name given in | 1051 | // the source, and replace the long dotted type name in |
1168 | * the source, and replace the long dotted type name in | 1052 | // the source with the reference token, eg, replace |
1169 | * the source with the reference token, eg, replace | 1053 | // 'Dictionary' '<' 'string' ',' 'integer' '>' '.' 'ValueList' |
1170 | * 'Dictionary' '<' 'string' ',' 'integer' '>' '.' 'ValueList' | 1054 | // with 'Dictionary<string,integer>.ValueList'. |
1171 | * with 'Dictionary<string,integer>.ValueList'. | ||
1172 | */ | ||
1173 | TokenType refer = instdecl.MakeRefToken(start); | 1055 | TokenType refer = instdecl.MakeRefToken(start); |
1174 | if(refer == null) | 1056 | if(refer == null) |
1175 | { | 1057 | { |
@@ -1203,11 +1085,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1203 | 1085 | ||
1204 | Stack<int> ranks = new Stack<int>(); | 1086 | Stack<int> ranks = new Stack<int>(); |
1205 | 1087 | ||
1206 | /* | 1088 | // When script specifies 'float[,][]' it means a two-dimensional matrix |
1207 | * When script specifies 'float[,][]' it means a two-dimensional matrix | 1089 | // that points to one-dimensional vectors of floats. So we would push |
1208 | * that points to one-dimensional vectors of floats. So we would push | 1090 | // a 2 then a 1 in this parsing code... |
1209 | * a 2 then a 1 in this parsing code... | ||
1210 | */ | ||
1211 | do | 1091 | do |
1212 | { | 1092 | { |
1213 | t = t.nextToken; // point at '[' | 1093 | t = t.nextToken; // point at '[' |
@@ -1225,14 +1105,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1225 | ranks.Push(rank); | 1105 | ranks.Push(rank); |
1226 | } while(t.nextToken is TokenKwBrkOpen); | 1106 | } while(t.nextToken is TokenKwBrkOpen); |
1227 | 1107 | ||
1228 | /* | 1108 | // Now we build the types in reverse order. For the example above we will: |
1229 | * Now we build the types in reverse order. For the example above we will: | 1109 | // first, create a type that is a one-dimensional vector of floats, float[] |
1230 | * first, create a type that is a one-dimensional vector of floats, float[] | 1110 | // second, create a type that is a two-dimensional matrix of that. |
1231 | * second, create a type that is a two-dimensional matrix of that. | 1111 | // This keeps declaration and referencing similar, eg, |
1232 | * This keeps declaration and referencing similar, eg, | 1112 | // float[,][] jag = new float[,][] (3,4); |
1233 | * float[,][] jag = new float[,][] (3,4); | 1113 | // jag[i,j][k] ... is used to access the elements |
1234 | * jag[i,j][k] ... is used to access the elements | ||
1235 | */ | ||
1236 | do | 1114 | do |
1237 | { | 1115 | { |
1238 | int rank = ranks.Pop(); | 1116 | int rank = ranks.Pop(); |
@@ -1240,17 +1118,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1240 | ofType = decl.MakeRefToken(ofType); | 1118 | ofType = decl.MakeRefToken(ofType); |
1241 | } while(ranks.Count > 0); | 1119 | } while(ranks.Count > 0); |
1242 | 1120 | ||
1243 | /* | 1121 | // Finally splice in the resultant array type to replace the original tokens. |
1244 | * Finally splice in the resultant array type to replace the original tokens. | ||
1245 | */ | ||
1246 | ofType.prevToken = start.prevToken; | 1122 | ofType.prevToken = start.prevToken; |
1247 | ofType.nextToken = t.nextToken; | 1123 | ofType.nextToken = t.nextToken; |
1248 | ofType.prevToken.nextToken = ofType; | 1124 | ofType.prevToken.nextToken = ofType; |
1249 | ofType.nextToken.prevToken = ofType; | 1125 | ofType.nextToken.prevToken = ofType; |
1250 | 1126 | ||
1251 | /* | 1127 | // Resume parsing just after the spliced-in array type token. |
1252 | * Resume parsing just after the spliced-in array type token. | ||
1253 | */ | ||
1254 | return ofType; | 1128 | return ofType; |
1255 | } | 1129 | } |
1256 | 1130 | ||
@@ -1262,13 +1136,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1262 | */ | 1136 | */ |
1263 | private TokenDeclSDType InstantiateFixedArray(int rank, TokenType ofType, Token tokenBegin, ref uint repeat) | 1137 | private TokenDeclSDType InstantiateFixedArray(int rank, TokenType ofType, Token tokenBegin, ref uint repeat) |
1264 | { | 1138 | { |
1265 | /* | 1139 | // Create the array type's name. |
1266 | * Create the array type's name. | 1140 | // If starting with a non-array type, just append the rank to it, eg, float + rank=1 -> float[] |
1267 | * If starting with a non-array type, just append the rank to it, eg, float + rank=1 -> float[] | 1141 | // If starting with an array type, slip this rank in front of existing array, eg, float[] + rank=2 -> float[,][]. |
1268 | * If starting with an array type, slip this rank in front of existing array, eg, float[] + rank=2 -> float[,][]. | 1142 | // This makes it consistent with what the script-writer sees for both a type specification and when |
1269 | * This makes it consistent with what the script-writer sees for both a type specification and when | 1143 | // referencing elements in a jagged array. |
1270 | * referencing elements in a jagged array. | ||
1271 | */ | ||
1272 | string name = ofType.ToString(); | 1144 | string name = ofType.ToString(); |
1273 | StringBuilder sb = new StringBuilder(name); | 1145 | StringBuilder sb = new StringBuilder(name); |
1274 | int ix = name.IndexOf('['); | 1146 | int ix = name.IndexOf('['); |
@@ -1293,12 +1165,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1293 | if(ofType is TokenTypeInt) | 1165 | if(ofType is TokenTypeInt) |
1294 | suffix = 'I'; | 1166 | suffix = 'I'; |
1295 | 1167 | ||
1296 | /* | 1168 | // Don't already have one, create a new skeleton struct. |
1297 | * Don't already have one, create a new skeleton struct. | 1169 | // Splice in a definition for the class at beginning of source file. |
1298 | * Splice in a definition for the class at beginning of source file. | 1170 | // |
1299 | * | 1171 | // class <arraytypename> { |
1300 | * class <arraytypename> { | ||
1301 | */ | ||
1302 | fa = new TokenDeclSDTypeClass(new TokenName(tokenScript, name), false); | 1172 | fa = new TokenDeclSDTypeClass(new TokenName(tokenScript, name), false); |
1303 | CatalogSDTypeDecl(fa); | 1173 | CatalogSDTypeDecl(fa); |
1304 | repeat |= REPEAT_INSTGEN; | 1174 | repeat |= REPEAT_INSTGEN; |
@@ -1308,12 +1178,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1308 | Token t = SpliceAfter(tokenBegin, fa); | 1178 | Token t = SpliceAfter(tokenBegin, fa); |
1309 | t = SpliceAfter(t, new TokenKwBrcOpen(t)); | 1179 | t = SpliceAfter(t, new TokenKwBrcOpen(t)); |
1310 | 1180 | ||
1311 | /* | 1181 | // public integer len0; |
1312 | * public integer len0; | 1182 | // public integer len1; |
1313 | * public integer len1; | 1183 | // ... |
1314 | * ... | 1184 | // public object obj; |
1315 | * public object obj; | ||
1316 | */ | ||
1317 | for(int i = 0; i < rank; i++) | 1185 | for(int i = 0; i < rank; i++) |
1318 | { | 1186 | { |
1319 | t = SpliceAfter(t, new TokenKwPublic(t)); | 1187 | t = SpliceAfter(t, new TokenKwPublic(t)); |
@@ -1327,14 +1195,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1327 | t = SpliceAfter(t, new TokenName(t, "obj")); | 1195 | t = SpliceAfter(t, new TokenName(t, "obj")); |
1328 | t = SpliceAfter(t, new TokenKwSemi(t)); | 1196 | t = SpliceAfter(t, new TokenKwSemi(t)); |
1329 | 1197 | ||
1330 | /* | 1198 | // public constructor (integer len0, integer len1, ...) { |
1331 | * public constructor (integer len0, integer len1, ...) { | 1199 | // this.len0 = len0; |
1332 | * this.len0 = len0; | 1200 | // this.len1 = len1; |
1333 | * this.len1 = len1; | 1201 | // ... |
1334 | * ... | 1202 | // this.obj = xmrFixedArrayAlloc<suffix> (len0 * len1 * ...); |
1335 | * this.obj = xmrFixedArrayAlloc<suffix> (len0 * len1 * ...); | 1203 | // } |
1336 | * } | ||
1337 | */ | ||
1338 | t = SpliceAfter(t, new TokenKwPublic(t)); | 1204 | t = SpliceAfter(t, new TokenKwPublic(t)); |
1339 | t = SpliceAfter(t, new TokenKwConstructor(t)); | 1205 | t = SpliceAfter(t, new TokenKwConstructor(t)); |
1340 | t = SpliceAfter(t, new TokenKwParOpen(t)); | 1206 | t = SpliceAfter(t, new TokenKwParOpen(t)); |
@@ -1374,11 +1240,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1374 | t = SpliceAfter(t, new TokenKwSemi(t)); | 1240 | t = SpliceAfter(t, new TokenKwSemi(t)); |
1375 | t = SpliceAfter(t, new TokenKwBrcClose(t)); | 1241 | t = SpliceAfter(t, new TokenKwBrcClose(t)); |
1376 | 1242 | ||
1377 | /* | 1243 | // public integer Length { get { |
1378 | * public integer Length { get { | 1244 | // return this.len0 * this.len1 * ... ; |
1379 | * return this.len0 * this.len1 * ... ; | 1245 | // } } |
1380 | * } } | ||
1381 | */ | ||
1382 | t = SpliceAfter(t, new TokenKwPublic(t)); | 1246 | t = SpliceAfter(t, new TokenKwPublic(t)); |
1383 | t = SpliceAfter(t, new TokenTypeInt(t)); | 1247 | t = SpliceAfter(t, new TokenTypeInt(t)); |
1384 | t = SpliceAfter(t, new TokenName(t, "Length")); | 1248 | t = SpliceAfter(t, new TokenName(t, "Length")); |
@@ -1400,16 +1264,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1400 | t = SpliceAfter(t, new TokenKwBrcClose(t)); | 1264 | t = SpliceAfter(t, new TokenKwBrcClose(t)); |
1401 | t = SpliceAfter(t, new TokenKwBrcClose(t)); | 1265 | t = SpliceAfter(t, new TokenKwBrcClose(t)); |
1402 | 1266 | ||
1403 | /* | 1267 | // public integer Length (integer dim) { |
1404 | * public integer Length (integer dim) { | 1268 | // switch (dim) { |
1405 | * switch (dim) { | 1269 | // case 0: return this.len0; |
1406 | * case 0: return this.len0; | 1270 | // case 1: return this.len1; |
1407 | * case 1: return this.len1; | 1271 | // ... |
1408 | * ... | 1272 | // } |
1409 | * } | 1273 | // return 0; |
1410 | * return 0; | 1274 | // } |
1411 | * } | ||
1412 | */ | ||
1413 | t = SpliceAfter(t, new TokenKwPublic(t)); | 1275 | t = SpliceAfter(t, new TokenKwPublic(t)); |
1414 | t = SpliceAfter(t, new TokenTypeInt(t)); | 1276 | t = SpliceAfter(t, new TokenTypeInt(t)); |
1415 | t = SpliceAfter(t, new TokenName(t, "Length")); | 1277 | t = SpliceAfter(t, new TokenName(t, "Length")); |
@@ -1443,15 +1305,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1443 | t = SpliceAfter(t, new TokenKwSemi(t)); | 1305 | t = SpliceAfter(t, new TokenKwSemi(t)); |
1444 | t = SpliceAfter(t, new TokenKwBrcClose(t)); | 1306 | t = SpliceAfter(t, new TokenKwBrcClose(t)); |
1445 | 1307 | ||
1446 | /* | 1308 | // public integer Index (integer idx0, integet idx1, ...) { |
1447 | * public integer Index (integer idx0, integet idx1, ...) { | 1309 | // integer idx = idx0; |
1448 | * integer idx = idx0; | 1310 | // idx *= this.len1; idx += idx1; |
1449 | * idx *= this.len1; idx += idx1; | 1311 | // idx *= this.len2; idx += idx2; |
1450 | * idx *= this.len2; idx += idx2; | 1312 | // ... |
1451 | * ... | 1313 | // return idx; |
1452 | * return idx; | 1314 | // } |
1453 | * } | ||
1454 | */ | ||
1455 | t = SpliceAfter(t, new TokenKwPublic(t)); | 1315 | t = SpliceAfter(t, new TokenKwPublic(t)); |
1456 | t = SpliceAfter(t, new TokenTypeInt(t)); | 1316 | t = SpliceAfter(t, new TokenTypeInt(t)); |
1457 | t = SpliceAfter(t, new TokenName(t, "Index")); | 1317 | t = SpliceAfter(t, new TokenName(t, "Index")); |
@@ -1491,15 +1351,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1491 | t = SpliceAfter(t, new TokenKwSemi(t)); | 1351 | t = SpliceAfter(t, new TokenKwSemi(t)); |
1492 | t = SpliceAfter(t, new TokenKwBrcClose(t)); | 1352 | t = SpliceAfter(t, new TokenKwBrcClose(t)); |
1493 | 1353 | ||
1494 | /* | 1354 | // public <oftype> Get (integer idx0, integet idx1, ...) { |
1495 | * public <oftype> Get (integer idx0, integet idx1, ...) { | 1355 | // integer idx = idx0; |
1496 | * integer idx = idx0; | 1356 | // idx *= this.len1; idx += idx1; |
1497 | * idx *= this.len1; idx += idx1; | 1357 | // idx *= this.len2; idx += idx2; |
1498 | * idx *= this.len2; idx += idx2; | 1358 | // ... |
1499 | * ... | 1359 | // return (<oftype>) xmrFixedArrayGet<suffix> (this.obj, idx); |
1500 | * return (<oftype>) xmrFixedArrayGet<suffix> (this.obj, idx); | 1360 | // } |
1501 | * } | ||
1502 | */ | ||
1503 | t = SpliceAfter(t, new TokenKwPublic(t)); | 1361 | t = SpliceAfter(t, new TokenKwPublic(t)); |
1504 | t = SpliceAfter(t, ofType.CopyToken(t)); | 1362 | t = SpliceAfter(t, ofType.CopyToken(t)); |
1505 | t = SpliceAfter(t, new TokenName(t, "Get")); | 1363 | t = SpliceAfter(t, new TokenName(t, "Get")); |
@@ -1552,15 +1410,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1552 | t = SpliceAfter(t, new TokenKwSemi(t)); | 1410 | t = SpliceAfter(t, new TokenKwSemi(t)); |
1553 | t = SpliceAfter(t, new TokenKwBrcClose(t)); | 1411 | t = SpliceAfter(t, new TokenKwBrcClose(t)); |
1554 | 1412 | ||
1555 | /* | 1413 | // public void Set (integer idx0, integer idx1, ..., <oftype> val) { |
1556 | * public void Set (integer idx0, integer idx1, ..., <oftype> val) { | 1414 | // integer idx = idx0; |
1557 | * integer idx = idx0; | 1415 | // idx *= this.len1; idx += idx1; |
1558 | * idx *= this.len1; idx += idx1; | 1416 | // idx *= this.len2; idx += idx2; |
1559 | * idx *= this.len2; idx += idx2; | 1417 | // ... |
1560 | * ... | 1418 | // xmrFixedArraySet<suffix> (this.obj, idx, val); |
1561 | * xmrFixedArraySet<suffix> (this.obj, idx, val); | 1419 | // } |
1562 | * } | ||
1563 | */ | ||
1564 | t = SpliceAfter(t, new TokenKwPublic(t)); | 1420 | t = SpliceAfter(t, new TokenKwPublic(t)); |
1565 | t = SpliceAfter(t, new TokenTypeVoid(t)); | 1421 | t = SpliceAfter(t, new TokenTypeVoid(t)); |
1566 | t = SpliceAfter(t, new TokenName(t, "Set")); | 1422 | t = SpliceAfter(t, new TokenName(t, "Set")); |
@@ -1764,10 +1620,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1764 | tokdeclcl.members.thisClass = tokdeclcl; | 1620 | tokdeclcl.members.thisClass = tokdeclcl; |
1765 | tokenScript.PushVarFrame(tokdeclcl.members); | 1621 | tokenScript.PushVarFrame(tokdeclcl.members); |
1766 | 1622 | ||
1767 | /* | 1623 | // Create a function $instfieldnit to hold all explicit |
1768 | * Create a function $instfieldnit to hold all explicit | 1624 | // instance field initializations. |
1769 | * instance field initializations. | ||
1770 | */ | ||
1771 | TokenDeclVar ifiFunc = new TokenDeclVar(tokdeclcl, null, tokenScript); | 1625 | TokenDeclVar ifiFunc = new TokenDeclVar(tokdeclcl, null, tokenScript); |
1772 | ifiFunc.name = new TokenName(ifiFunc, "$instfieldinit"); | 1626 | ifiFunc.name = new TokenName(ifiFunc, "$instfieldinit"); |
1773 | ifiFunc.retType = new TokenTypeVoid(ifiFunc); | 1627 | ifiFunc.retType = new TokenTypeVoid(ifiFunc); |
@@ -1780,10 +1634,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1780 | tokdeclcl.instFieldInit = ifiFunc; | 1634 | tokdeclcl.instFieldInit = ifiFunc; |
1781 | tokenScript.AddVarEntry(ifiFunc); | 1635 | tokenScript.AddVarEntry(ifiFunc); |
1782 | 1636 | ||
1783 | /* | 1637 | // Create a function $staticfieldnit to hold all explicit |
1784 | * Create a function $staticfieldnit to hold all explicit | 1638 | // static field initializations. |
1785 | * static field initializations. | ||
1786 | */ | ||
1787 | TokenDeclVar sfiFunc = new TokenDeclVar(tokdeclcl, null, tokenScript); | 1639 | TokenDeclVar sfiFunc = new TokenDeclVar(tokdeclcl, null, tokenScript); |
1788 | sfiFunc.name = new TokenName(sfiFunc, "$staticfieldinit"); | 1640 | sfiFunc.name = new TokenName(sfiFunc, "$staticfieldinit"); |
1789 | sfiFunc.retType = new TokenTypeVoid(sfiFunc); | 1641 | sfiFunc.retType = new TokenTypeVoid(sfiFunc); |
@@ -1805,25 +1657,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1805 | continue; | 1657 | continue; |
1806 | } | 1658 | } |
1807 | 1659 | ||
1808 | /* | 1660 | // Check for all qualifiers. |
1809 | * Check for all qualifiers. | 1661 | // typedef has an implied 'public' qualifier. |
1810 | * typedef has an implied 'public' qualifier. | ||
1811 | */ | ||
1812 | flags = SDT_PUBLIC; | 1662 | flags = SDT_PUBLIC; |
1813 | if(!(token is TokenDeclSDTypeTypedef)) | 1663 | if(!(token is TokenDeclSDTypeTypedef)) |
1814 | { | 1664 | { |
1815 | flags = ParseQualifierFlags(ref token); | 1665 | flags = ParseQualifierFlags(ref token); |
1816 | } | 1666 | } |
1817 | 1667 | ||
1818 | /* | 1668 | // Parse nested script-defined type definitions. |
1819 | * Parse nested script-defined type definitions. | ||
1820 | */ | ||
1821 | if(ParseDeclSDTypes(ref token, tokdeclcl, flags)) | 1669 | if(ParseDeclSDTypes(ref token, tokdeclcl, flags)) |
1822 | continue; | 1670 | continue; |
1823 | 1671 | ||
1824 | /* | 1672 | // constant <name> = <rval> ; |
1825 | * constant <name> = <rval> ; | ||
1826 | */ | ||
1827 | if(token is TokenKwConst) | 1673 | if(token is TokenKwConst) |
1828 | { | 1674 | { |
1829 | if((flags & (SDT_ABSTRACT | SDT_NEW | SDT_OVERRIDE | SDT_VIRTUAL)) != 0) | 1675 | if((flags & (SDT_ABSTRACT | SDT_NEW | SDT_OVERRIDE | SDT_VIRTUAL)) != 0) |
@@ -1839,10 +1685,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1839 | continue; | 1685 | continue; |
1840 | } | 1686 | } |
1841 | 1687 | ||
1842 | /* | 1688 | // <type> <name> ; |
1843 | * <type> <name> ; | 1689 | // <type> <name> = <rval> ; |
1844 | * <type> <name> = <rval> ; | ||
1845 | */ | ||
1846 | if((token is TokenType) && | 1690 | if((token is TokenType) && |
1847 | (token.nextToken is TokenName) && | 1691 | (token.nextToken is TokenName) && |
1848 | ((token.nextToken.nextToken is TokenKwSemi) || | 1692 | ((token.nextToken.nextToken is TokenKwSemi) || |
@@ -1877,10 +1721,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1877 | continue; | 1721 | continue; |
1878 | } | 1722 | } |
1879 | 1723 | ||
1880 | /* | 1724 | // <type> <name> [ : <implintfs> ] { [ get { <body> } ] [ set { <body> } ] } |
1881 | * <type> <name> [ : <implintfs> ] { [ get { <body> } ] [ set { <body> } ] } | 1725 | // <type> '[' ... ']' [ : <implintfs> ] { [ get { <body> } ] [ set { <body> } ] } |
1882 | * <type> '[' ... ']' [ : <implintfs> ] { [ get { <body> } ] [ set { <body> } ] } | ||
1883 | */ | ||
1884 | bool prop = (token is TokenType) && | 1726 | bool prop = (token is TokenType) && |
1885 | (token.nextToken is TokenName) && | 1727 | (token.nextToken is TokenName) && |
1886 | (token.nextToken.nextToken is TokenKwBrcOpen || | 1728 | (token.nextToken.nextToken is TokenKwBrcOpen || |
@@ -1907,9 +1749,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1907 | continue; | 1749 | continue; |
1908 | } | 1750 | } |
1909 | 1751 | ||
1910 | /* | 1752 | // 'constructor' '(' arglist ')' [ ':' [ 'base' ] '(' baseconstructorcall ')' ] '{' body '}' |
1911 | * 'constructor' '(' arglist ')' [ ':' [ 'base' ] '(' baseconstructorcall ')' ] '{' body '}' | ||
1912 | */ | ||
1913 | if(token is TokenKwConstructor) | 1753 | if(token is TokenKwConstructor) |
1914 | { | 1754 | { |
1915 | ParseSDTClassCtorDecl(ref token, flags, tokdeclcl); | 1755 | ParseSDTClassCtorDecl(ref token, flags, tokdeclcl); |
@@ -1917,36 +1757,28 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1917 | continue; | 1757 | continue; |
1918 | } | 1758 | } |
1919 | 1759 | ||
1920 | /* | 1760 | // <type> <name> <funcargs> <funcbody> |
1921 | * <type> <name> <funcargs> <funcbody> | 1761 | // method with explicit return type |
1922 | * method with explicit return type | ||
1923 | */ | ||
1924 | if(token is TokenType) | 1762 | if(token is TokenType) |
1925 | { | 1763 | { |
1926 | ParseSDTClassMethodDecl(ref token, flags, tokdeclcl); | 1764 | ParseSDTClassMethodDecl(ref token, flags, tokdeclcl); |
1927 | continue; | 1765 | continue; |
1928 | } | 1766 | } |
1929 | 1767 | ||
1930 | /* | 1768 | // <name> <funcargs> <funcbody> |
1931 | * <name> <funcargs> <funcbody> | 1769 | // method returning void |
1932 | * method returning void | ||
1933 | */ | ||
1934 | if((token is TokenName) || ((token is TokenKw) && ((TokenKw)token).sdtClassOp)) | 1770 | if((token is TokenName) || ((token is TokenKw) && ((TokenKw)token).sdtClassOp)) |
1935 | { | 1771 | { |
1936 | ParseSDTClassMethodDecl(ref token, flags, tokdeclcl); | 1772 | ParseSDTClassMethodDecl(ref token, flags, tokdeclcl); |
1937 | continue; | 1773 | continue; |
1938 | } | 1774 | } |
1939 | 1775 | ||
1940 | /* | 1776 | // That's all we support in a class declaration. |
1941 | * That's all we support in a class declaration. | ||
1942 | */ | ||
1943 | ErrorMsg(token, "expecting field or method declaration"); | 1777 | ErrorMsg(token, "expecting field or method declaration"); |
1944 | token = SkipPastSemi(token); | 1778 | token = SkipPastSemi(token); |
1945 | } | 1779 | } |
1946 | 1780 | ||
1947 | /* | 1781 | // If script didn't specify any constructor, create a default no-argument one. |
1948 | * If script didn't specify any constructor, create a default no-argument one. | ||
1949 | */ | ||
1950 | if(!haveExplicitConstructor) | 1782 | if(!haveExplicitConstructor) |
1951 | { | 1783 | { |
1952 | TokenDeclVar tokenDeclFunc = new TokenDeclVar(token, null, tokenScript); | 1784 | TokenDeclVar tokenDeclFunc = new TokenDeclVar(token, null, tokenScript); |
@@ -1971,9 +1803,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
1971 | tokenScript.AddVarEntry(tokenDeclFunc); | 1803 | tokenScript.AddVarEntry(tokenDeclFunc); |
1972 | } | 1804 | } |
1973 | 1805 | ||
1974 | /* | 1806 | // Skip over the closing brace and pop corresponding var frame. |
1975 | * Skip over the closing brace and pop corresponding var frame. | ||
1976 | */ | ||
1977 | token = token.nextToken; | 1807 | token = token.nextToken; |
1978 | tokenScript.PopVarFrame(); | 1808 | tokenScript.PopVarFrame(); |
1979 | ret: | 1809 | ret: |
@@ -2079,10 +1909,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2079 | */ | 1909 | */ |
2080 | private TokenDeclVar ParseProperty(ref Token token, bool abs, bool imp) | 1910 | private TokenDeclVar ParseProperty(ref Token token, bool abs, bool imp) |
2081 | { | 1911 | { |
2082 | /* | 1912 | // Parse out the property's type and name. |
2083 | * Parse out the property's type and name. | 1913 | // <type> <name> |
2084 | * <type> <name> | ||
2085 | */ | ||
2086 | TokenType type = (TokenType)token; | 1914 | TokenType type = (TokenType)token; |
2087 | TokenName name; | 1915 | TokenName name; |
2088 | TokenArgDecl args; | 1916 | TokenArgDecl args; |
@@ -2101,10 +1929,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2101 | args = new TokenArgDecl(token); | 1929 | args = new TokenArgDecl(token); |
2102 | } | 1930 | } |
2103 | 1931 | ||
2104 | /* | 1932 | // Maybe it claims to implement some interface properties. |
2105 | * Maybe it claims to implement some interface properties. | 1933 | // [ ':' <ifacetype>[.<propname>] ',' ... ] |
2106 | * [ ':' <ifacetype>[.<propname>] ',' ... ] | ||
2107 | */ | ||
2108 | TokenIntfImpl implements = null; | 1934 | TokenIntfImpl implements = null; |
2109 | if(token is TokenKwColon) | 1935 | if(token is TokenKwColon) |
2110 | { | 1936 | { |
@@ -2117,9 +1943,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2117 | } | 1943 | } |
2118 | } | 1944 | } |
2119 | 1945 | ||
2120 | /* | 1946 | // Should have an opening brace. |
2121 | * Should have an opening brace. | ||
2122 | */ | ||
2123 | if(!(token is TokenKwBrcOpen)) | 1947 | if(!(token is TokenKwBrcOpen)) |
2124 | { | 1948 | { |
2125 | ErrorMsg(token, "expect { to open property definition"); | 1949 | ErrorMsg(token, "expect { to open property definition"); |
@@ -2128,19 +1952,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2128 | } | 1952 | } |
2129 | token = token.nextToken; | 1953 | token = token.nextToken; |
2130 | 1954 | ||
2131 | /* | 1955 | // Parse out the getter and/or setter. |
2132 | * Parse out the getter and/or setter. | 1956 | // 'get' { <body> | ';' } |
2133 | * 'get' { <body> | ';' } | 1957 | // 'set' { <body> | ';' } |
2134 | * 'set' { <body> | ';' } | ||
2135 | */ | ||
2136 | TokenDeclVar getFunc = null; | 1958 | TokenDeclVar getFunc = null; |
2137 | TokenDeclVar setFunc = null; | 1959 | TokenDeclVar setFunc = null; |
2138 | while(!(token is TokenKwBrcClose)) | 1960 | while(!(token is TokenKwBrcClose)) |
2139 | { | 1961 | { |
2140 | 1962 | // Maybe create a getter function. | |
2141 | /* | ||
2142 | * Maybe create a getter function. | ||
2143 | */ | ||
2144 | if(token is TokenKwGet) | 1963 | if(token is TokenKwGet) |
2145 | { | 1964 | { |
2146 | getFunc = new TokenDeclVar(token, null, tokenScript); | 1965 | getFunc = new TokenDeclVar(token, null, tokenScript); |
@@ -2161,9 +1980,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2161 | continue; | 1980 | continue; |
2162 | } | 1981 | } |
2163 | 1982 | ||
2164 | /* | 1983 | // Maybe create a setter function. |
2165 | * Maybe create a setter function. | ||
2166 | */ | ||
2167 | if(token is TokenKwSet) | 1984 | if(token is TokenKwSet) |
2168 | { | 1985 | { |
2169 | TokenArgDecl argDecl = args; | 1986 | TokenArgDecl argDecl = args; |
@@ -2204,18 +2021,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2204 | return null; | 2021 | return null; |
2205 | } | 2022 | } |
2206 | 2023 | ||
2207 | /* | 2024 | // Set up a variable for the property. |
2208 | * Set up a variable for the property. | ||
2209 | */ | ||
2210 | TokenDeclVar tokenDeclVar = new TokenDeclVar(name, null, tokenScript); | 2025 | TokenDeclVar tokenDeclVar = new TokenDeclVar(name, null, tokenScript); |
2211 | tokenDeclVar.type = type; | 2026 | tokenDeclVar.type = type; |
2212 | tokenDeclVar.name = name; | 2027 | tokenDeclVar.name = name; |
2213 | tokenDeclVar.getProp = getFunc; | 2028 | tokenDeclVar.getProp = getFunc; |
2214 | tokenDeclVar.setProp = setFunc; | 2029 | tokenDeclVar.setProp = setFunc; |
2215 | 2030 | ||
2216 | /* | 2031 | // Can't be same name already in block. |
2217 | * Can't be same name already in block. | ||
2218 | */ | ||
2219 | if(!tokenScript.AddVarEntry(tokenDeclVar)) | 2032 | if(!tokenScript.AddVarEntry(tokenDeclVar)) |
2220 | { | 2033 | { |
2221 | ErrorMsg(tokenDeclVar, "duplicate member " + name.val); | 2034 | ErrorMsg(tokenDeclVar, "duplicate member " + name.val); |
@@ -2279,17 +2092,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2279 | tokenScript.PushVarFrame(tokenDeclFunc.argDecl.varDict); | 2092 | tokenScript.PushVarFrame(tokenDeclFunc.argDecl.varDict); |
2280 | try | 2093 | try |
2281 | { | 2094 | { |
2282 | /* | 2095 | // Set up reference to base constructor. |
2283 | * Set up reference to base constructor. | ||
2284 | */ | ||
2285 | TokenLValBaseField baseCtor = new TokenLValBaseField(token, | 2096 | TokenLValBaseField baseCtor = new TokenLValBaseField(token, |
2286 | new TokenName(token, "$ctor"), | 2097 | new TokenName(token, "$ctor"), |
2287 | tokdeclcl); | 2098 | tokdeclcl); |
2288 | 2099 | ||
2289 | /* | 2100 | // Parse any base constructor call as if it were the first statement of the |
2290 | * Parse any base constructor call as if it were the first statement of the | 2101 | // constructor itself. |
2291 | * constructor itself. | ||
2292 | */ | ||
2293 | if(token is TokenKwColon) | 2102 | if(token is TokenKwColon) |
2294 | { | 2103 | { |
2295 | token = token.nextToken; | 2104 | token = token.nextToken; |
@@ -2318,17 +2127,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2318 | } | 2127 | } |
2319 | else if(tokdeclcl.extends != null) | 2128 | else if(tokdeclcl.extends != null) |
2320 | { | 2129 | { |
2321 | 2130 | // Caller didn't specify a constructor but we are extending, so we will | |
2322 | /* | 2131 | // call the extended class's default constructor. |
2323 | * Caller didn't specify a constructor but we are extending, so we will | ||
2324 | * call the extended class's default constructor. | ||
2325 | */ | ||
2326 | SetUpDefaultBaseCtorCall(tokenDeclFunc); | 2132 | SetUpDefaultBaseCtorCall(tokenDeclFunc); |
2327 | } | 2133 | } |
2328 | 2134 | ||
2329 | /* | 2135 | // Parse the constructor body. |
2330 | * Parse the constructor body. | ||
2331 | */ | ||
2332 | tokenDeclFunc.body = ParseStmtBlock(ref token); | 2136 | tokenDeclFunc.body = ParseStmtBlock(ref token); |
2333 | if(tokenDeclFunc.body == null) | 2137 | if(tokenDeclFunc.body == null) |
2334 | return; | 2138 | return; |
@@ -2341,10 +2145,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2341 | currentDeclFunc = saveDeclFunc; | 2145 | currentDeclFunc = saveDeclFunc; |
2342 | } | 2146 | } |
2343 | 2147 | ||
2344 | /* | 2148 | // Add to list of methods defined by this class. |
2345 | * Add to list of methods defined by this class. | 2149 | // It has the name "$ctor(argsig)". |
2346 | * It has the name "$ctor(argsig)". | ||
2347 | */ | ||
2348 | if(!tokenScript.AddVarEntry(tokenDeclFunc)) | 2150 | if(!tokenScript.AddVarEntry(tokenDeclFunc)) |
2349 | { | 2151 | { |
2350 | ErrorMsg(tokenDeclFunc, "duplicate constructor definition"); | 2152 | ErrorMsg(tokenDeclFunc, "duplicate constructor definition"); |
@@ -2443,7 +2245,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2443 | } | 2245 | } |
2444 | else | 2246 | else |
2445 | { | 2247 | { |
2446 | |||
2447 | // other times should have ',' <type> | 2248 | // other times should have ',' <type> |
2448 | if(!(u is TokenKwComma)) | 2249 | if(!(u is TokenKwComma)) |
2449 | { | 2250 | { |
@@ -2550,16 +2351,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2550 | continue; | 2351 | continue; |
2551 | } | 2352 | } |
2552 | 2353 | ||
2553 | /* | 2354 | // Parse nested script-defined type definitions. |
2554 | * Parse nested script-defined type definitions. | ||
2555 | */ | ||
2556 | if(ParseDeclSDTypes(ref token, tokdeclin, SDT_PUBLIC)) | 2355 | if(ParseDeclSDTypes(ref token, tokdeclin, SDT_PUBLIC)) |
2557 | continue; | 2356 | continue; |
2558 | 2357 | ||
2559 | /* | 2358 | // <type> <name> <funcargs> ; |
2560 | * <type> <name> <funcargs> ; | 2359 | // abstract method with explicit return type |
2561 | * abstract method with explicit return type | ||
2562 | */ | ||
2563 | if((token is TokenType) && | 2360 | if((token is TokenType) && |
2564 | (token.nextToken is TokenName) && | 2361 | (token.nextToken is TokenName) && |
2565 | (token.nextToken.nextToken is TokenKwParOpen)) | 2362 | (token.nextToken.nextToken is TokenKwParOpen)) |
@@ -2576,10 +2373,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2576 | continue; | 2373 | continue; |
2577 | } | 2374 | } |
2578 | 2375 | ||
2579 | /* | 2376 | // <name> <funcargs> ; |
2580 | * <name> <funcargs> ; | 2377 | // abstract method returning void |
2581 | * abstract method returning void | ||
2582 | */ | ||
2583 | if((token is TokenName) && | 2378 | if((token is TokenName) && |
2584 | (token.nextToken is TokenKwParOpen)) | 2379 | (token.nextToken is TokenKwParOpen)) |
2585 | { | 2380 | { |
@@ -2594,11 +2389,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2594 | continue; | 2389 | continue; |
2595 | } | 2390 | } |
2596 | 2391 | ||
2597 | /* | 2392 | // <type> <name> { [ get ; ] [ set ; ] } |
2598 | * <type> <name> { [ get ; ] [ set ; ] } | 2393 | // <type> '[' ... ']' { [ get ; ] [ set ; ] } |
2599 | * <type> '[' ... ']' { [ get ; ] [ set ; ] } | 2394 | // abstract property |
2600 | * abstract property | ||
2601 | */ | ||
2602 | bool prop = (token is TokenType) && | 2395 | bool prop = (token is TokenType) && |
2603 | (token.nextToken is TokenName) && | 2396 | (token.nextToken is TokenName) && |
2604 | (token.nextToken.nextToken is TokenKwBrcOpen || | 2397 | (token.nextToken.nextToken is TokenKwBrcOpen || |
@@ -2610,16 +2403,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2610 | continue; | 2403 | continue; |
2611 | } | 2404 | } |
2612 | 2405 | ||
2613 | /* | 2406 | // That's all we support in an interface declaration. |
2614 | * That's all we support in an interface declaration. | ||
2615 | */ | ||
2616 | ErrorMsg(token, "expecting method or property prototype"); | 2407 | ErrorMsg(token, "expecting method or property prototype"); |
2617 | token = SkipPastSemi(token); | 2408 | token = SkipPastSemi(token); |
2618 | } | 2409 | } |
2619 | 2410 | ||
2620 | /* | 2411 | // Skip over the closing brace and pop the corresponding var frame. |
2621 | * Skip over the closing brace and pop the corresponding var frame. | ||
2622 | */ | ||
2623 | token = token.nextToken; | 2412 | token = token.nextToken; |
2624 | tokenScript.PopVarFrame(); | 2413 | tokenScript.PopVarFrame(); |
2625 | } | 2414 | } |
@@ -2807,29 +2596,21 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2807 | return true; | 2596 | return true; |
2808 | } | 2597 | } |
2809 | 2598 | ||
2810 | /* | 2599 | // Declare this function as being the one currently being processed |
2811 | * Declare this function as being the one currently being processed | 2600 | // for anything that cares. We also start a variable frame that |
2812 | * for anything that cares. We also start a variable frame that | 2601 | // includes all the declared parameters. |
2813 | * includes all the declared parameters. | ||
2814 | */ | ||
2815 | TokenDeclVar saveDeclFunc = currentDeclFunc; | 2602 | TokenDeclVar saveDeclFunc = currentDeclFunc; |
2816 | currentDeclFunc = tokenDeclFunc; | 2603 | currentDeclFunc = tokenDeclFunc; |
2817 | tokenScript.PushVarFrame(tokenDeclFunc.argDecl.varDict); | 2604 | tokenScript.PushVarFrame(tokenDeclFunc.argDecl.varDict); |
2818 | 2605 | ||
2819 | /* | 2606 | // Now parse the function statement block. |
2820 | * Now parse the function statement block. | ||
2821 | */ | ||
2822 | tokenDeclFunc.body = ParseStmtBlock(ref token); | 2607 | tokenDeclFunc.body = ParseStmtBlock(ref token); |
2823 | 2608 | ||
2824 | /* | 2609 | // Pop the var frame that contains the arguments. |
2825 | * Pop the var frame that contains the arguments. | ||
2826 | */ | ||
2827 | tokenScript.PopVarFrame(); | 2610 | tokenScript.PopVarFrame(); |
2828 | currentDeclFunc = saveDeclFunc; | 2611 | currentDeclFunc = saveDeclFunc; |
2829 | 2612 | ||
2830 | /* | 2613 | // Check final errors. |
2831 | * Check final errors. | ||
2832 | */ | ||
2833 | if(tokenDeclFunc.body == null) | 2614 | if(tokenDeclFunc.body == null) |
2834 | return false; | 2615 | return false; |
2835 | if(abs) | 2616 | if(abs) |
@@ -2851,9 +2632,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2851 | */ | 2632 | */ |
2852 | private TokenStmt ParseStmt(ref Token token) | 2633 | private TokenStmt ParseStmt(ref Token token) |
2853 | { | 2634 | { |
2854 | /* | 2635 | // Statements that begin with a specific keyword. |
2855 | * Statements that begin with a specific keyword. | ||
2856 | */ | ||
2857 | if(token is TokenKwAt) | 2636 | if(token is TokenKwAt) |
2858 | return ParseStmtLabel(ref token); | 2637 | return ParseStmtLabel(ref token); |
2859 | if(token is TokenKwBrcOpen) | 2638 | if(token is TokenKwBrcOpen) |
@@ -2887,10 +2666,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2887 | if(token is TokenKwWhile) | 2666 | if(token is TokenKwWhile) |
2888 | return ParseStmtWhile(ref token); | 2667 | return ParseStmtWhile(ref token); |
2889 | 2668 | ||
2890 | /* | 2669 | // Try to parse anything else as an expression, possibly calling |
2891 | * Try to parse anything else as an expression, possibly calling | 2670 | // something and/or writing to a variable. |
2892 | * something and/or writing to a variable. | ||
2893 | */ | ||
2894 | TokenRVal tokenRVal = ParseRVal(ref token, semiOnly); | 2671 | TokenRVal tokenRVal = ParseRVal(ref token, semiOnly); |
2895 | if(tokenRVal != null) | 2672 | if(tokenRVal != null) |
2896 | { | 2673 | { |
@@ -2899,9 +2676,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
2899 | return tokenStmtRVal; | 2676 | return tokenStmtRVal; |
2900 | } | 2677 | } |
2901 | 2678 | ||
2902 | /* | 2679 | // Who knows what it is... |
2903 | * Who knows what it is... | ||
2904 | */ | ||
2905 | ErrorMsg(token, "unknown statement"); | 2680 | ErrorMsg(token, "unknown statement"); |
2906 | token = SkipPastSemi(token); | 2681 | token = SkipPastSemi(token); |
2907 | return null; | 2682 | return null; |
@@ -3053,9 +2828,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3053 | { | 2828 | { |
3054 | currentDeclFunc.triviality = Triviality.complex; | 2829 | currentDeclFunc.triviality = Triviality.complex; |
3055 | 2830 | ||
3056 | /* | 2831 | // Create encapsulating token and skip past 'for (' |
3057 | * Create encapsulating token and skip past 'for (' | ||
3058 | */ | ||
3059 | TokenStmtFor tokenStmtFor = new TokenStmtFor(token); | 2832 | TokenStmtFor tokenStmtFor = new TokenStmtFor(token); |
3060 | token = token.nextToken; | 2833 | token = token.nextToken; |
3061 | if(!(token is TokenKwParOpen)) | 2834 | if(!(token is TokenKwParOpen)) |
@@ -3065,9 +2838,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3065 | } | 2838 | } |
3066 | token = token.nextToken; | 2839 | token = token.nextToken; |
3067 | 2840 | ||
3068 | /* | 2841 | // If a plain for, ie, not declaring a variable, it's straightforward. |
3069 | * If a plain for, ie, not declaring a variable, it's straightforward. | ||
3070 | */ | ||
3071 | if(!(token is TokenType)) | 2842 | if(!(token is TokenType)) |
3072 | { | 2843 | { |
3073 | tokenStmtFor.initStmt = ParseStmt(ref token); | 2844 | tokenStmtFor.initStmt = ParseStmt(ref token); |
@@ -3076,10 +2847,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3076 | return ParseStmtFor2(tokenStmtFor, ref token) ? tokenStmtFor : null; | 2847 | return ParseStmtFor2(tokenStmtFor, ref token) ? tokenStmtFor : null; |
3077 | } | 2848 | } |
3078 | 2849 | ||
3079 | /* | 2850 | // Initialization declares a variable, so encapsulate it in a block so |
3080 | * Initialization declares a variable, so encapsulate it in a block so | 2851 | // variable has scope only in the for statement, including its body. |
3081 | * variable has scope only in the for statement, including its body. | ||
3082 | */ | ||
3083 | TokenStmtBlock forStmtBlock = new TokenStmtBlock(tokenStmtFor); | 2852 | TokenStmtBlock forStmtBlock = new TokenStmtBlock(tokenStmtFor); |
3084 | forStmtBlock.outerStmtBlock = currentStmtBlock; | 2853 | forStmtBlock.outerStmtBlock = currentStmtBlock; |
3085 | forStmtBlock.function = currentDeclFunc; | 2854 | forStmtBlock.function = currentDeclFunc; |
@@ -3148,9 +2917,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3148 | { | 2917 | { |
3149 | currentDeclFunc.triviality = Triviality.complex; | 2918 | currentDeclFunc.triviality = Triviality.complex; |
3150 | 2919 | ||
3151 | /* | 2920 | // Create encapsulating token and skip past 'foreach (' |
3152 | * Create encapsulating token and skip past 'foreach (' | ||
3153 | */ | ||
3154 | TokenStmtForEach tokenStmtForEach = new TokenStmtForEach(token); | 2921 | TokenStmtForEach tokenStmtForEach = new TokenStmtForEach(token); |
3155 | token = token.nextToken; | 2922 | token = token.nextToken; |
3156 | if(!(token is TokenKwParOpen)) | 2923 | if(!(token is TokenKwParOpen)) |
@@ -3222,9 +2989,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3222 | 2989 | ||
3223 | private TokenStmtJump ParseStmtJump(ref Token token) | 2990 | private TokenStmtJump ParseStmtJump(ref Token token) |
3224 | { | 2991 | { |
3225 | /* | 2992 | // Create jump statement token to encapsulate the whole statement. |
3226 | * Create jump statement token to encapsulate the whole statement. | ||
3227 | */ | ||
3228 | TokenStmtJump tokenStmtJump = new TokenStmtJump(token); | 2993 | TokenStmtJump tokenStmtJump = new TokenStmtJump(token); |
3229 | token = token.nextToken; | 2994 | token = token.nextToken; |
3230 | if(!(token is TokenName) || !(token.nextToken is TokenKwSemi)) | 2995 | if(!(token is TokenName) || !(token.nextToken is TokenKwSemi)) |
@@ -3236,11 +3001,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3236 | tokenStmtJump.label = (TokenName)token; | 3001 | tokenStmtJump.label = (TokenName)token; |
3237 | token = token.nextToken.nextToken; | 3002 | token = token.nextToken.nextToken; |
3238 | 3003 | ||
3239 | /* | 3004 | // If label is already defined, it means this is a backward (looping) |
3240 | * If label is already defined, it means this is a backward (looping) | 3005 | // jump, so remember the label has backward jump references. |
3241 | * jump, so remember the label has backward jump references. | 3006 | // We also then assume the function is complex, ie, it has a loop. |
3242 | * We also then assume the function is complex, ie, it has a loop. | ||
3243 | */ | ||
3244 | if(currentDeclFunc.labels.ContainsKey(tokenStmtJump.label.val)) | 3007 | if(currentDeclFunc.labels.ContainsKey(tokenStmtJump.label.val)) |
3245 | { | 3008 | { |
3246 | currentDeclFunc.labels[tokenStmtJump.label.val].hasBkwdRefs = true; | 3009 | currentDeclFunc.labels[tokenStmtJump.label.val].hasBkwdRefs = true; |
@@ -3450,9 +3213,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3450 | */ | 3213 | */ |
3451 | private TokenStmtTry ParseStmtTry(ref Token token) | 3214 | private TokenStmtTry ParseStmtTry(ref Token token) |
3452 | { | 3215 | { |
3453 | /* | 3216 | // Parse out the 'try { ... }' part |
3454 | * Parse out the 'try { ... }' part | ||
3455 | */ | ||
3456 | Token tryKw = token; | 3217 | Token tryKw = token; |
3457 | token = token.nextToken; | 3218 | token = token.nextToken; |
3458 | TokenStmt body = ParseStmtBlock(ref token); | 3219 | TokenStmt body = ParseStmtBlock(ref token); |
@@ -3585,14 +3346,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3585 | { | 3346 | { |
3586 | TokenDeclVar tokenDeclVar = new TokenDeclVar(token.nextToken, currentDeclFunc, tokenScript); | 3347 | TokenDeclVar tokenDeclVar = new TokenDeclVar(token.nextToken, currentDeclFunc, tokenScript); |
3587 | 3348 | ||
3588 | /* | 3349 | // Handle constant declaration. |
3589 | * Handle constant declaration. | 3350 | // It ends up in the declared variables list for the statement block just like |
3590 | * It ends up in the declared variables list for the statement block just like | 3351 | // any other variable, except it has .constant = true. |
3591 | * any other variable, except it has .constant = true. | 3352 | // The code generator will test that the initialization expression is constant. |
3592 | * The code generator will test that the initialization expression is constant. | 3353 | // |
3593 | * | 3354 | // constant <name> = <value> ; |
3594 | * constant <name> = <value> ; | ||
3595 | */ | ||
3596 | if(token is TokenKwConst) | 3355 | if(token is TokenKwConst) |
3597 | { | 3356 | { |
3598 | token = token.nextToken; | 3357 | token = token.nextToken; |
@@ -3618,14 +3377,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3618 | tokenDeclVar.constant = true; | 3377 | tokenDeclVar.constant = true; |
3619 | } | 3378 | } |
3620 | 3379 | ||
3621 | /* | 3380 | // Otherwise, normal variable declaration with optional initialization value. |
3622 | * Otherwise, normal variable declaration with optional initialization value. | ||
3623 | */ | ||
3624 | else | 3381 | else |
3625 | { | 3382 | { |
3626 | /* | 3383 | // Build basic encapsulating token with type and name. |
3627 | * Build basic encapsulating token with type and name. | ||
3628 | */ | ||
3629 | tokenDeclVar.type = (TokenType)token; | 3384 | tokenDeclVar.type = (TokenType)token; |
3630 | token = token.nextToken; | 3385 | token = token.nextToken; |
3631 | if(!(token is TokenName)) | 3386 | if(!(token is TokenName)) |
@@ -3637,10 +3392,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3637 | tokenDeclVar.name = (TokenName)token; | 3392 | tokenDeclVar.name = (TokenName)token; |
3638 | token = token.nextToken; | 3393 | token = token.nextToken; |
3639 | 3394 | ||
3640 | /* | 3395 | // If just a ;, there is no explicit initialization value. |
3641 | * If just a ;, there is no explicit initialization value. | 3396 | // Otherwise, look for an =RVal; expression that has init value. |
3642 | * Otherwise, look for an =RVal; expression that has init value. | ||
3643 | */ | ||
3644 | if(token is TokenKwSemi) | 3397 | if(token is TokenKwSemi) |
3645 | { | 3398 | { |
3646 | token = token.nextToken; | 3399 | token = token.nextToken; |
@@ -3673,18 +3426,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3673 | } | 3426 | } |
3674 | } | 3427 | } |
3675 | 3428 | ||
3676 | /* | 3429 | // If doing local vars, each var goes in its own var frame, |
3677 | * If doing local vars, each var goes in its own var frame, | 3430 | // to make sure no code before this point can reference it. |
3678 | * to make sure no code before this point can reference it. | ||
3679 | */ | ||
3680 | if(currentStmtBlock != null) | 3431 | if(currentStmtBlock != null) |
3681 | { | 3432 | { |
3682 | tokenScript.PushVarFrame(true); | 3433 | tokenScript.PushVarFrame(true); |
3683 | } | 3434 | } |
3684 | 3435 | ||
3685 | /* | 3436 | // Can't be same name already in block. |
3686 | * Can't be same name already in block. | ||
3687 | */ | ||
3688 | if(!tokenScript.AddVarEntry(tokenDeclVar)) | 3437 | if(!tokenScript.AddVarEntry(tokenDeclVar)) |
3689 | { | 3438 | { |
3690 | ErrorMsg(tokenDeclVar, "duplicate variable " + tokenDeclVar.name.val); | 3439 | ErrorMsg(tokenDeclVar, "duplicate variable " + tokenDeclVar.name.val); |
@@ -3702,9 +3451,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3702 | */ | 3451 | */ |
3703 | private void DoVarInit(TokenDeclVar initFunc, TokenLVal left, TokenRVal init) | 3452 | private void DoVarInit(TokenDeclVar initFunc, TokenLVal left, TokenRVal init) |
3704 | { | 3453 | { |
3705 | /* | 3454 | // Make a statement that assigns the initialization value to the variable. |
3706 | * Make a statement that assigns the initialization value to the variable. | ||
3707 | */ | ||
3708 | TokenStmt stmt; | 3455 | TokenStmt stmt; |
3709 | if(init == null) | 3456 | if(init == null) |
3710 | { | 3457 | { |
@@ -3720,11 +3467,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3720 | stmt = tsrv; | 3467 | stmt = tsrv; |
3721 | } | 3468 | } |
3722 | 3469 | ||
3723 | /* | 3470 | // Add statement to end of initialization function. |
3724 | * Add statement to end of initialization function. | 3471 | // Be sure to execute them in same order as in source |
3725 | * Be sure to execute them in same order as in source | 3472 | // as some doofus scripts depend on it. |
3726 | * as some doofus scripts depend on it. | ||
3727 | */ | ||
3728 | Token lastStmt = initFunc.body.statements; | 3473 | Token lastStmt = initFunc.body.statements; |
3729 | if(lastStmt == null) | 3474 | if(lastStmt == null) |
3730 | { | 3475 | { |
@@ -3805,17 +3550,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3805 | */ | 3550 | */ |
3806 | public TokenRVal ParseRVal(ref Token token, Type[] termTokenTypes) | 3551 | public TokenRVal ParseRVal(ref Token token, Type[] termTokenTypes) |
3807 | { | 3552 | { |
3808 | /* | 3553 | // Start with pushing the first operand on operand stack. |
3809 | * Start with pushing the first operand on operand stack. | ||
3810 | */ | ||
3811 | BinOp binOps = null; | 3554 | BinOp binOps = null; |
3812 | TokenRVal operands = GetOperand(ref token); | 3555 | TokenRVal operands = GetOperand(ref token); |
3813 | if(operands == null) | 3556 | if(operands == null) |
3814 | return null; | 3557 | return null; |
3815 | 3558 | ||
3816 | /* | 3559 | // Keep scanning until we hit the termination token. |
3817 | * Keep scanning until we hit the termination token. | ||
3818 | */ | ||
3819 | while(true) | 3560 | while(true) |
3820 | { | 3561 | { |
3821 | Type tokType = token.GetType(); | 3562 | Type tokType = token.GetType(); |
@@ -3825,59 +3566,47 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3825 | goto done; | 3566 | goto done; |
3826 | } | 3567 | } |
3827 | 3568 | ||
3828 | /* | 3569 | // Special form: |
3829 | * Special form: | 3570 | // <operand> is <typeexp> |
3830 | * <operand> is <typeexp> | ||
3831 | */ | ||
3832 | if(token is TokenKwIs) | 3571 | if(token is TokenKwIs) |
3833 | { | 3572 | { |
3834 | TokenRValIsType tokenRValIsType = new TokenRValIsType(token); | 3573 | TokenRValIsType tokenRValIsType = new TokenRValIsType(token); |
3835 | token = token.nextToken; | 3574 | token = token.nextToken; |
3836 | 3575 | ||
3837 | /* | 3576 | // Parse the <typeexp>. |
3838 | * Parse the <typeexp>. | ||
3839 | */ | ||
3840 | tokenRValIsType.typeExp = ParseTypeExp(ref token); | 3577 | tokenRValIsType.typeExp = ParseTypeExp(ref token); |
3841 | if(tokenRValIsType.typeExp == null) | 3578 | if(tokenRValIsType.typeExp == null) |
3842 | return null; | 3579 | return null; |
3843 | 3580 | ||
3844 | /* | 3581 | // Replace top operand with result of <operand> is <typeexp> |
3845 | * Replace top operand with result of <operand> is <typeexp> | ||
3846 | */ | ||
3847 | tokenRValIsType.rValExp = operands; | 3582 | tokenRValIsType.rValExp = operands; |
3848 | tokenRValIsType.nextToken = operands.nextToken; | 3583 | tokenRValIsType.nextToken = operands.nextToken; |
3849 | operands = tokenRValIsType; | 3584 | operands = tokenRValIsType; |
3850 | 3585 | ||
3851 | /* | 3586 | // token points just past <typeexp> so see if it is another operator. |
3852 | * token points just past <typeexp> so see if it is another operator. | ||
3853 | */ | ||
3854 | continue; | 3587 | continue; |
3855 | } | 3588 | } |
3856 | 3589 | ||
3857 | /* | 3590 | // Peek at next operator. |
3858 | * Peek at next operator. | ||
3859 | */ | ||
3860 | BinOp binOp = GetOperator(ref token); | 3591 | BinOp binOp = GetOperator(ref token); |
3861 | if(binOp == null) | 3592 | if(binOp == null) |
3862 | return null; | 3593 | return null; |
3863 | 3594 | ||
3864 | /* | 3595 | // If there are stacked operators of higher or same precedence than new one, |
3865 | * If there are stacked operators of higher or same precedence than new one, | 3596 | // perform their computation then push result back on operand stack. |
3866 | * perform their computation then push result back on operand stack. | 3597 | // |
3867 | * | 3598 | // higher or same = left-to-right application of operators |
3868 | * higher or same = left-to-right application of operators | 3599 | // eg, a - b - c becomes (a - b) - c |
3869 | * eg, a - b - c becomes (a - b) - c | 3600 | // |
3870 | * | 3601 | // higher precedence = right-to-left application of operators |
3871 | * higher precedence = right-to-left application of operators | 3602 | // eg, a - b - c becomes a - (b - c) |
3872 | * eg, a - b - c becomes a - (b - c) | 3603 | // |
3873 | * | 3604 | // Now of course, there is some ugliness necessary: |
3874 | * Now of course, there is some ugliness necessary: | 3605 | // we want: a - b - c => (a - b) - c so we do 'higher or same' |
3875 | * we want: a - b - c => (a - b) - c so we do 'higher or same' | 3606 | // but we want: a += b = c => a += (b = c) so we do 'higher only' |
3876 | * but we want: a += b = c => a += (b = c) so we do 'higher only' | 3607 | // |
3877 | * | 3608 | // binOps is the first operator (or null if only one) |
3878 | * binOps is the first operator (or null if only one) | 3609 | // binOp is the second operator (or first if only one) |
3879 | * binOp is the second operator (or first if only one) | ||
3880 | */ | ||
3881 | while(binOps != null) | 3610 | while(binOps != null) |
3882 | { | 3611 | { |
3883 | if(binOps.preced < binOp.preced) | 3612 | if(binOps.preced < binOp.preced) |
@@ -3894,10 +3623,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3894 | binOps = binOps.pop; | 3623 | binOps = binOps.pop; |
3895 | } | 3624 | } |
3896 | 3625 | ||
3897 | /* | 3626 | // Handle conditional expression as a special form: |
3898 | * Handle conditional expression as a special form: | 3627 | // <condexp> ? <trueexp> : <falseexp> |
3899 | * <condexp> ? <trueexp> : <falseexp> | ||
3900 | */ | ||
3901 | if(binOp.token is TokenKwQMark) | 3628 | if(binOp.token is TokenKwQMark) |
3902 | { | 3629 | { |
3903 | TokenRValCondExpr condExpr = new TokenRValCondExpr(binOp.token); | 3630 | TokenRValCondExpr condExpr = new TokenRValCondExpr(binOp.token); |
@@ -3910,15 +3637,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3910 | goto done; | 3637 | goto done; |
3911 | } | 3638 | } |
3912 | 3639 | ||
3913 | /* | 3640 | // Push new operator on its stack. |
3914 | * Push new operator on its stack. | ||
3915 | */ | ||
3916 | binOp.pop = binOps; | 3641 | binOp.pop = binOps; |
3917 | binOps = binOp; | 3642 | binOps = binOp; |
3918 | 3643 | ||
3919 | /* | 3644 | // Push next operand on its stack. |
3920 | * Push next operand on its stack. | ||
3921 | */ | ||
3922 | TokenRVal operand = GetOperand(ref token); | 3645 | TokenRVal operand = GetOperand(ref token); |
3923 | if(operand == null) | 3646 | if(operand == null) |
3924 | return null; | 3647 | return null; |
@@ -3927,9 +3650,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3927 | } | 3650 | } |
3928 | done: | 3651 | done: |
3929 | 3652 | ||
3930 | /* | 3653 | // At end of expression, perform any stacked computations. |
3931 | * At end of expression, perform any stacked computations. | ||
3932 | */ | ||
3933 | while(binOps != null) | 3654 | while(binOps != null) |
3934 | { | 3655 | { |
3935 | TokenRVal result = PerformBinOp((TokenRVal)operands.prevToken, binOps, (TokenRVal)operands); | 3656 | TokenRVal result = PerformBinOp((TokenRVal)operands.prevToken, binOps, (TokenRVal)operands); |
@@ -3938,15 +3659,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
3938 | binOps = binOps.pop; | 3659 | binOps = binOps.pop; |
3939 | } | 3660 | } |
3940 | 3661 | ||
3941 | /* | 3662 | // There should be exactly one remaining operand on the stack which is our final result. |
3942 | * There should be exactly one remaining operand on the stack which is our final result. | ||
3943 | */ | ||
3944 | if(operands.prevToken != null) | 3663 | if(operands.prevToken != null) |
3945 | throw new Exception("too many operands"); | 3664 | throw new Exception("too many operands"); |
3946 | 3665 | ||
3947 | /* | 3666 | // If only one terminator type possible, advance past the terminator. |
3948 | * If only one terminator type possible, advance past the terminator. | ||
3949 | */ | ||
3950 | if(termTokenTypes.Length == 1) | 3667 | if(termTokenTypes.Length == 1) |
3951 | token = token.nextToken; | 3668 | token = token.nextToken; |
3952 | 3669 | ||
@@ -4028,9 +3745,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4028 | */ | 3745 | */ |
4029 | private TokenRVal GetOperand(ref Token token) | 3746 | private TokenRVal GetOperand(ref Token token) |
4030 | { | 3747 | { |
4031 | /* | 3748 | // Prefix unary operators (eg ++, --) requiring an L-value. |
4032 | * Prefix unary operators (eg ++, --) requiring an L-value. | ||
4033 | */ | ||
4034 | if((token is TokenKwIncr) || (token is TokenKwDecr)) | 3749 | if((token is TokenKwIncr) || (token is TokenKwDecr)) |
4035 | { | 3750 | { |
4036 | TokenRValAsnPre asnPre = new TokenRValAsnPre(token); | 3751 | TokenRValAsnPre asnPre = new TokenRValAsnPre(token); |
@@ -4048,17 +3763,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4048 | return asnPre; | 3763 | return asnPre; |
4049 | } | 3764 | } |
4050 | 3765 | ||
4051 | /* | 3766 | // Get the bulk of the operand, ie, without any of the below suffixes. |
4052 | * Get the bulk of the operand, ie, without any of the below suffixes. | ||
4053 | */ | ||
4054 | TokenRVal operand = GetOperandNoMods(ref token); | 3767 | TokenRVal operand = GetOperandNoMods(ref token); |
4055 | if(operand == null) | 3768 | if(operand == null) |
4056 | return null; | 3769 | return null; |
4057 | modifiers: | 3770 | modifiers: |
4058 | 3771 | ||
4059 | /* | 3772 | // If followed by '++' or '--', it is post-{in,de}cremented. |
4060 | * If followed by '++' or '--', it is post-{in,de}cremented. | ||
4061 | */ | ||
4062 | if((token is TokenKwIncr) || (token is TokenKwDecr)) | 3773 | if((token is TokenKwIncr) || (token is TokenKwDecr)) |
4063 | { | 3774 | { |
4064 | TokenRValAsnPost asnPost = new TokenRValAsnPost(token); | 3775 | TokenRValAsnPost asnPost = new TokenRValAsnPost(token); |
@@ -4073,9 +3784,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4073 | return asnPost; | 3784 | return asnPost; |
4074 | } | 3785 | } |
4075 | 3786 | ||
4076 | /* | 3787 | // If followed by a '.', it is an instance field or instance method reference. |
4077 | * If followed by a '.', it is an instance field or instance method reference. | ||
4078 | */ | ||
4079 | if(token is TokenKwDot) | 3788 | if(token is TokenKwDot) |
4080 | { | 3789 | { |
4081 | token = token.nextToken; | 3790 | token = token.nextToken; |
@@ -4092,17 +3801,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4092 | goto modifiers; | 3801 | goto modifiers; |
4093 | } | 3802 | } |
4094 | 3803 | ||
4095 | /* | 3804 | // If followed by a '[', it is an array subscript. |
4096 | * If followed by a '[', it is an array subscript. | ||
4097 | */ | ||
4098 | if(token is TokenKwBrkOpen) | 3805 | if(token is TokenKwBrkOpen) |
4099 | { | 3806 | { |
4100 | TokenLValArEle tokenLValArEle = new TokenLValArEle(token); | 3807 | TokenLValArEle tokenLValArEle = new TokenLValArEle(token); |
4101 | token = token.nextToken; | 3808 | token = token.nextToken; |
4102 | 3809 | ||
4103 | /* | 3810 | // Parse subscript(s) expression. |
4104 | * Parse subscript(s) expression. | ||
4105 | */ | ||
4106 | tokenLValArEle.subRVal = ParseRVal(ref token, brkCloseOnly); | 3811 | tokenLValArEle.subRVal = ParseRVal(ref token, brkCloseOnly); |
4107 | if(tokenLValArEle.subRVal == null) | 3812 | if(tokenLValArEle.subRVal == null) |
4108 | { | 3813 | { |
@@ -4110,44 +3815,33 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4110 | return null; | 3815 | return null; |
4111 | } | 3816 | } |
4112 | 3817 | ||
4113 | /* | 3818 | // See if comma-separated list of values. |
4114 | * See if comma-separated list of values. | ||
4115 | */ | ||
4116 | TokenRVal subscriptRVals; | 3819 | TokenRVal subscriptRVals; |
4117 | int numSubscripts = SplitCommaRVals(tokenLValArEle.subRVal, out subscriptRVals); | 3820 | int numSubscripts = SplitCommaRVals(tokenLValArEle.subRVal, out subscriptRVals); |
4118 | if(numSubscripts > 1) | 3821 | if(numSubscripts > 1) |
4119 | { | 3822 | { |
4120 | 3823 | // If so, put the values in an LSL_List object. | |
4121 | /* | ||
4122 | * If so, put the values in an LSL_List object. | ||
4123 | */ | ||
4124 | TokenRValList rValList = new TokenRValList(tokenLValArEle); | 3824 | TokenRValList rValList = new TokenRValList(tokenLValArEle); |
4125 | rValList.rVal = subscriptRVals; | 3825 | rValList.rVal = subscriptRVals; |
4126 | rValList.nItems = numSubscripts; | 3826 | rValList.nItems = numSubscripts; |
4127 | tokenLValArEle.subRVal = rValList; | 3827 | tokenLValArEle.subRVal = rValList; |
4128 | } | 3828 | } |
4129 | 3829 | ||
4130 | /* | 3830 | // Either way, save array variable name |
4131 | * Either way, save array variable name | 3831 | // and substitute whole reference for L-value |
4132 | * and substitute whole reference for L-value | ||
4133 | */ | ||
4134 | tokenLValArEle.baseRVal = operand; | 3832 | tokenLValArEle.baseRVal = operand; |
4135 | operand = tokenLValArEle; | 3833 | operand = tokenLValArEle; |
4136 | goto modifiers; | 3834 | goto modifiers; |
4137 | } | 3835 | } |
4138 | 3836 | ||
4139 | /* | 3837 | // If followed by a '(', it is a function/method call. |
4140 | * If followed by a '(', it is a function/method call. | ||
4141 | */ | ||
4142 | if(token is TokenKwParOpen) | 3838 | if(token is TokenKwParOpen) |
4143 | { | 3839 | { |
4144 | operand = ParseRValCall(ref token, operand); | 3840 | operand = ParseRValCall(ref token, operand); |
4145 | goto modifiers; | 3841 | goto modifiers; |
4146 | } | 3842 | } |
4147 | 3843 | ||
4148 | /* | 3844 | // If 'new' arraytipe '{', it is an array initializer. |
4149 | * If 'new' arraytipe '{', it is an array initializer. | ||
4150 | */ | ||
4151 | if((token is TokenKwBrcOpen) && (operand is TokenLValSField) && | 3845 | if((token is TokenKwBrcOpen) && (operand is TokenLValSField) && |
4152 | (((TokenLValSField)operand).fieldName.val == "$new") && | 3846 | (((TokenLValSField)operand).fieldName.val == "$new") && |
4153 | ((TokenLValSField)operand).baseType.ToString().EndsWith("]")) | 3847 | ((TokenLValSField)operand).baseType.ToString().EndsWith("]")) |
@@ -4165,9 +3859,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4165 | */ | 3859 | */ |
4166 | private TokenRVal GetOperandNoMods(ref Token token) | 3860 | private TokenRVal GetOperandNoMods(ref Token token) |
4167 | { | 3861 | { |
4168 | /* | 3862 | // Simple unary operators. |
4169 | * Simple unary operators. | ||
4170 | */ | ||
4171 | if((token is TokenKwSub) || | 3863 | if((token is TokenKwSub) || |
4172 | (token is TokenKwTilde) || | 3864 | (token is TokenKwTilde) || |
4173 | (token is TokenKwExclam)) | 3865 | (token is TokenKwExclam)) |
@@ -4180,9 +3872,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4180 | return PerformUnOp(uop, rVal); | 3872 | return PerformUnOp(uop, rVal); |
4181 | } | 3873 | } |
4182 | 3874 | ||
4183 | /* | 3875 | // Type casting. |
4184 | * Type casting. | ||
4185 | */ | ||
4186 | if((token is TokenKwParOpen) && | 3876 | if((token is TokenKwParOpen) && |
4187 | (token.nextToken is TokenType) && | 3877 | (token.nextToken is TokenType) && |
4188 | (token.nextToken.nextToken is TokenKwParClose)) | 3878 | (token.nextToken.nextToken is TokenKwParClose)) |
@@ -4195,17 +3885,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4195 | return new TokenRValCast(type, rVal); | 3885 | return new TokenRValCast(type, rVal); |
4196 | } | 3886 | } |
4197 | 3887 | ||
4198 | /* | 3888 | // Parenthesized expression. |
4199 | * Parenthesized expression. | ||
4200 | */ | ||
4201 | if(token is TokenKwParOpen) | 3889 | if(token is TokenKwParOpen) |
4202 | { | 3890 | { |
4203 | return ParseRValParen(ref token); | 3891 | return ParseRValParen(ref token); |
4204 | } | 3892 | } |
4205 | 3893 | ||
4206 | /* | 3894 | // Constants. |
4207 | * Constants. | ||
4208 | */ | ||
4209 | if(token is TokenChar) | 3895 | if(token is TokenChar) |
4210 | { | 3896 | { |
4211 | TokenRValConst rValConst = new TokenRValConst(token, ((TokenChar)token).val); | 3897 | TokenRValConst rValConst = new TokenRValConst(token, ((TokenChar)token).val); |
@@ -4237,9 +3923,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4237 | return rValUndef; | 3923 | return rValUndef; |
4238 | } | 3924 | } |
4239 | 3925 | ||
4240 | /* | 3926 | // '<'value,...'>', ie, rotation or vector |
4241 | * '<'value,...'>', ie, rotation or vector | ||
4242 | */ | ||
4243 | if(token is TokenKwCmpLT) | 3927 | if(token is TokenKwCmpLT) |
4244 | { | 3928 | { |
4245 | Token openBkt = token; | 3929 | Token openBkt = token; |
@@ -4277,9 +3961,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4277 | } | 3961 | } |
4278 | } | 3962 | } |
4279 | 3963 | ||
4280 | /* | 3964 | // '['value,...']', ie, list |
4281 | * '['value,...']', ie, list | ||
4282 | */ | ||
4283 | if(token is TokenKwBrkOpen) | 3965 | if(token is TokenKwBrkOpen) |
4284 | { | 3966 | { |
4285 | TokenRValList rValList = new TokenRValList(token); | 3967 | TokenRValList rValList = new TokenRValList(token); |
@@ -4298,9 +3980,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4298 | return rValList; | 3980 | return rValList; |
4299 | } | 3981 | } |
4300 | 3982 | ||
4301 | /* | 3983 | // Maybe we have <type>.<name> referencing a static field or method of some type. |
4302 | * Maybe we have <type>.<name> referencing a static field or method of some type. | ||
4303 | */ | ||
4304 | if((token is TokenType) && (token.nextToken is TokenKwDot) && (token.nextToken.nextToken is TokenName)) | 3984 | if((token is TokenType) && (token.nextToken is TokenKwDot) && (token.nextToken.nextToken is TokenName)) |
4305 | { | 3985 | { |
4306 | TokenLValSField field = new TokenLValSField(token.nextToken.nextToken); | 3986 | TokenLValSField field = new TokenLValSField(token.nextToken.nextToken); |
@@ -4310,9 +3990,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4310 | return field; | 3990 | return field; |
4311 | } | 3991 | } |
4312 | 3992 | ||
4313 | /* | 3993 | // Maybe we have 'this' referring to the object of the instance method. |
4314 | * Maybe we have 'this' referring to the object of the instance method. | ||
4315 | */ | ||
4316 | if(token is TokenKwThis) | 3994 | if(token is TokenKwThis) |
4317 | { | 3995 | { |
4318 | if((currentDeclSDType == null) || !(currentDeclSDType is TokenDeclSDTypeClass)) | 3996 | if((currentDeclSDType == null) || !(currentDeclSDType is TokenDeclSDTypeClass)) |
@@ -4326,9 +4004,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4326 | return zhis; | 4004 | return zhis; |
4327 | } | 4005 | } |
4328 | 4006 | ||
4329 | /* | 4007 | // Maybe we have 'base' referring to a field/method of the extended class. |
4330 | * Maybe we have 'base' referring to a field/method of the extended class. | ||
4331 | */ | ||
4332 | if(token is TokenKwBase) | 4008 | if(token is TokenKwBase) |
4333 | { | 4009 | { |
4334 | if((currentDeclFunc == null) || (currentDeclFunc.sdtClass == null) || !(currentDeclFunc.sdtClass is TokenDeclSDTypeClass)) | 4010 | if((currentDeclFunc == null) || (currentDeclFunc.sdtClass == null) || !(currentDeclFunc.sdtClass is TokenDeclSDTypeClass)) |
@@ -4351,11 +4027,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4351 | return baseField; | 4027 | return baseField; |
4352 | } | 4028 | } |
4353 | 4029 | ||
4354 | /* | 4030 | // Maybe we have 'new <script-defined-type>' saying to create an object instance. |
4355 | * Maybe we have 'new <script-defined-type>' saying to create an object instance. | 4031 | // This ends up generating a call to static function <script-defined-type>.$new(...) |
4356 | * This ends up generating a call to static function <script-defined-type>.$new(...) | 4032 | // whose CIL code is generated by GenerateNewobjBody(). |
4357 | * whose CIL code is generated by GenerateNewobjBody(). | ||
4358 | */ | ||
4359 | if(token is TokenKwNew) | 4033 | if(token is TokenKwNew) |
4360 | { | 4034 | { |
4361 | if(!(token.nextToken is TokenType)) | 4035 | if(!(token.nextToken is TokenType)) |
@@ -4371,9 +4045,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4371 | return field; | 4045 | return field; |
4372 | } | 4046 | } |
4373 | 4047 | ||
4374 | /* | 4048 | // All we got left is <name>, eg, arg, function, global or local variable reference |
4375 | * All we got left is <name>, eg, arg, function, global or local variable reference | ||
4376 | */ | ||
4377 | if(token is TokenName) | 4049 | if(token is TokenName) |
4378 | { | 4050 | { |
4379 | TokenLValName name = new TokenLValName((TokenName)token, tokenScript.variablesStack); | 4051 | TokenLValName name = new TokenLValName((TokenName)token, tokenScript.variablesStack); |
@@ -4381,9 +4053,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4381 | return name; | 4053 | return name; |
4382 | } | 4054 | } |
4383 | 4055 | ||
4384 | /* | 4056 | // Who knows what it is supposed to be? |
4385 | * Who knows what it is supposed to be? | ||
4386 | */ | ||
4387 | ErrorMsg(token, "invalid operand token"); | 4057 | ErrorMsg(token, "invalid operand token"); |
4388 | token = SkipPastSemi(token); | 4058 | token = SkipPastSemi(token); |
4389 | return null; | 4059 | return null; |
@@ -4398,15 +4068,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4398 | */ | 4068 | */ |
4399 | private TokenRValCall ParseRValCall(ref Token token, TokenRVal meth) | 4069 | private TokenRValCall ParseRValCall(ref Token token, TokenRVal meth) |
4400 | { | 4070 | { |
4401 | /* | 4071 | // Set up basic function call struct with function name. |
4402 | * Set up basic function call struct with function name. | ||
4403 | */ | ||
4404 | TokenRValCall rValCall = new TokenRValCall(token); | 4072 | TokenRValCall rValCall = new TokenRValCall(token); |
4405 | rValCall.meth = meth; | 4073 | rValCall.meth = meth; |
4406 | 4074 | ||
4407 | /* | 4075 | // Parse the call parameters, if any. |
4408 | * Parse the call parameters, if any. | ||
4409 | */ | ||
4410 | token = token.nextToken; | 4076 | token = token.nextToken; |
4411 | if(token is TokenKwParClose) | 4077 | if(token is TokenKwParClose) |
4412 | { | 4078 | { |
@@ -4747,24 +4413,18 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4747 | */ | 4413 | */ |
4748 | public TokenDeclSDType InstantiateGeneric(string name, TokenType[] genArgs, ScriptReduce reduce) | 4414 | public TokenDeclSDType InstantiateGeneric(string name, TokenType[] genArgs, ScriptReduce reduce) |
4749 | { | 4415 | { |
4750 | /* | 4416 | // Malloc the struct and give it a name. |
4751 | * Malloc the struct and give it a name. | ||
4752 | */ | ||
4753 | TokenDeclSDType instdecl = this.MakeBlank(new TokenName(this, name)); | 4417 | TokenDeclSDType instdecl = this.MakeBlank(new TokenName(this, name)); |
4754 | 4418 | ||
4755 | /* | 4419 | // If the original had an outer type, then so does the new one. |
4756 | * If the original had an outer type, then so does the new one. | 4420 | // The outer type will never be a generic prototype, eg, if this |
4757 | * The outer type will never be a generic prototype, eg, if this | 4421 | // is 'ValueList' it will always be inside 'Dictionary<string,integer>' |
4758 | * is 'ValueList' it will always be inside 'Dictionary<string,integer>' | 4422 | // not 'Dictionary' at this point. |
4759 | * not 'Dictionary' at this point. | ||
4760 | */ | ||
4761 | if((this.outerSDType != null) && (this.outerSDType.genParams != null)) | 4423 | if((this.outerSDType != null) && (this.outerSDType.genParams != null)) |
4762 | throw new Exception(); | 4424 | throw new Exception(); |
4763 | instdecl.outerSDType = this.outerSDType; | 4425 | instdecl.outerSDType = this.outerSDType; |
4764 | 4426 | ||
4765 | /* | 4427 | // The generic prototype may have stuff like 'public' just before it and we need to copy that too. |
4766 | * The generic prototype may have stuff like 'public' just before it and we need to copy that too. | ||
4767 | */ | ||
4768 | Token prefix; | 4428 | Token prefix; |
4769 | for(prefix = this; (prefix = prefix.prevToken) != null;) | 4429 | for(prefix = this; (prefix = prefix.prevToken) != null;) |
4770 | { | 4430 | { |
@@ -4773,108 +4433,78 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4773 | } | 4433 | } |
4774 | this.begToken = prefix.nextToken; | 4434 | this.begToken = prefix.nextToken; |
4775 | 4435 | ||
4776 | /* | 4436 | // Splice in a copy of the prefix tokens, just before the beginning token of prototype (this.begToken). |
4777 | * Splice in a copy of the prefix tokens, just before the beginning token of prototype (this.begToken). | ||
4778 | */ | ||
4779 | while((prefix = prefix.nextToken) != this) | 4437 | while((prefix = prefix.nextToken) != this) |
4780 | { | 4438 | { |
4781 | SpliceSourceToken(prefix.CopyToken(prefix)); | 4439 | SpliceSourceToken(prefix.CopyToken(prefix)); |
4782 | } | 4440 | } |
4783 | 4441 | ||
4784 | /* | 4442 | // Splice instantiation (instdecl) in just before the beginning token of prototype (this.begToken). |
4785 | * Splice instantiation (instdecl) in just before the beginning token of prototype (this.begToken). | ||
4786 | */ | ||
4787 | SpliceSourceToken(instdecl); | 4443 | SpliceSourceToken(instdecl); |
4788 | 4444 | ||
4789 | /* | 4445 | // Now for the fun part... Copy the rest of the prototype body to the |
4790 | * Now for the fun part... Copy the rest of the prototype body to the | 4446 | // instantiated body, replacing all generic parameter type tokens with |
4791 | * instantiated body, replacing all generic parameter type tokens with | 4447 | // the corresponding generic argument types. Note that the parameters |
4792 | * the corresponding generic argument types. Note that the parameters | 4448 | // are numbered starting with the outermost so we need the full genArgs |
4793 | * are numbered starting with the outermost so we need the full genArgs | 4449 | // array. Eg if we are doing 'Converter<V=float>' from |
4794 | * array. Eg if we are doing 'Converter<V=float>' from | 4450 | // 'Dictionary<T=string,U=integer>.Converter<V=float>', any V's are |
4795 | * 'Dictionary<T=string,U=integer>.Converter<V=float>', any V's are | 4451 | // numbered [2]. Any [0]s or [1]s should be gone by now but it doesn't |
4796 | * numbered [2]. Any [0]s or [1]s should be gone by now but it doesn't | 4452 | // matter. |
4797 | * matter. | ||
4798 | */ | ||
4799 | int index; | 4453 | int index; |
4800 | Token it, pt; | 4454 | Token it, pt; |
4801 | TokenDeclSDType innerProto = this; | 4455 | TokenDeclSDType innerProto = this; |
4802 | TokenDeclSDType innerInst = instdecl; | 4456 | TokenDeclSDType innerInst = instdecl; |
4803 | for(pt = this; (pt = pt.nextToken) != this.endToken;) | 4457 | for(pt = this; (pt = pt.nextToken) != this.endToken;) |
4804 | { | 4458 | { |
4805 | 4459 | // Coming across a sub-type's declaration involves a deep copy of the | |
4806 | /* | 4460 | // declaration token. Fortunately we are early on in parsing, so there |
4807 | * Coming across a sub-type's declaration involves a deep copy of the | 4461 | // really isn't much to copy: |
4808 | * declaration token. Fortunately we are early on in parsing, so there | 4462 | // 1) short name is the same, eg, doing List of Dictionary<string,integer>.List is same short name as Dictionary<T,U>.List |
4809 | * really isn't much to copy: | 4463 | // if generic, eg doing Converter<W> of Dictionary<T,U>.Converter<W>, we have to manually copy the W as well. |
4810 | * 1) short name is the same, eg, doing List of Dictionary<string,integer>.List is same short name as Dictionary<T,U>.List | 4464 | // 2) outerSDType is transformed from Dictionary<T,U> to Dictionary<string,integer>. |
4811 | * if generic, eg doing Converter<W> of Dictionary<T,U>.Converter<W>, we have to manually copy the W as well. | 4465 | // 3) innerSDTypes is rebuilt when/if we find classes that are inner to this one. |
4812 | * 2) outerSDType is transformed from Dictionary<T,U> to Dictionary<string,integer>. | ||
4813 | * 3) innerSDTypes is rebuilt when/if we find classes that are inner to this one. | ||
4814 | */ | ||
4815 | if(pt is TokenDeclSDType) | 4466 | if(pt is TokenDeclSDType) |
4816 | { | 4467 | { |
4817 | 4468 | // Make a new TokenDeclSDType{Class,Delegate,Interface}. | |
4818 | /* | ||
4819 | * Make a new TokenDeclSDType{Class,Delegate,Interface}. | ||
4820 | */ | ||
4821 | TokenDeclSDType ptSDType = (TokenDeclSDType)pt; | 4469 | TokenDeclSDType ptSDType = (TokenDeclSDType)pt; |
4822 | TokenDeclSDType itSDType = ptSDType.MakeBlank(new TokenName(ptSDType.shortName, ptSDType.shortName.val)); | 4470 | TokenDeclSDType itSDType = ptSDType.MakeBlank(new TokenName(ptSDType.shortName, ptSDType.shortName.val)); |
4823 | 4471 | ||
4824 | /* | 4472 | // Set up the transformed outerSDType. |
4825 | * Set up the transformed outerSDType. | 4473 | // Eg, if we are creating Enumerator of Dictionary<string,integer>.Enumerator, |
4826 | * Eg, if we are creating Enumerator of Dictionary<string,integer>.Enumerator, | 4474 | // innerProto = Dictionary<T,U> and innerInst = Dictionary<string,integer>. |
4827 | * innerProto = Dictionary<T,U> and innerInst = Dictionary<string,integer>. | ||
4828 | */ | ||
4829 | itSDType.outerSDType = innerInst; | 4475 | itSDType.outerSDType = innerInst; |
4830 | 4476 | ||
4831 | /* | 4477 | // This clone is an inner type of its next outer level. |
4832 | * This clone is an inner type of its next outer level. | ||
4833 | */ | ||
4834 | reduce.CatalogSDTypeDecl(itSDType); | 4478 | reduce.CatalogSDTypeDecl(itSDType); |
4835 | 4479 | ||
4836 | /* | 4480 | // We need to manually copy any generic parameters of the class declaration being cloned. |
4837 | * We need to manually copy any generic parameters of the class declaration being cloned. | 4481 | // eg, if we are cloning Converter<W>, this is where the W gets copied. |
4838 | * eg, if we are cloning Converter<W>, this is where the W gets copied. | 4482 | // Since it is an immutable array of strings, just copy the array pointer, if any. |
4839 | * Since it is an immutable array of strings, just copy the array pointer, if any. | ||
4840 | */ | ||
4841 | itSDType.genParams = ptSDType.genParams; | 4483 | itSDType.genParams = ptSDType.genParams; |
4842 | 4484 | ||
4843 | /* | 4485 | // We are now processing tokens for this cloned type declaration. |
4844 | * We are now processing tokens for this cloned type declaration. | ||
4845 | */ | ||
4846 | innerProto = ptSDType; | 4486 | innerProto = ptSDType; |
4847 | innerInst = itSDType; | 4487 | innerInst = itSDType; |
4848 | 4488 | ||
4849 | /* | 4489 | // Splice this clone token in. |
4850 | * Splice this clone token in. | ||
4851 | */ | ||
4852 | it = itSDType; | 4490 | it = itSDType; |
4853 | } | 4491 | } |
4854 | 4492 | ||
4855 | /* | 4493 | // Check for an generic parameter to substitute out. |
4856 | * Check for an generic parameter to substitute out. | ||
4857 | */ | ||
4858 | else if((pt is TokenName) && this.genParams.TryGetValue(((TokenName)pt).val, out index)) | 4494 | else if((pt is TokenName) && this.genParams.TryGetValue(((TokenName)pt).val, out index)) |
4859 | { | 4495 | { |
4860 | it = genArgs[index].CopyToken(pt); | 4496 | it = genArgs[index].CopyToken(pt); |
4861 | } | 4497 | } |
4862 | 4498 | ||
4863 | /* | 4499 | // Everything else is a simple copy. |
4864 | * Everything else is a simple copy. | ||
4865 | */ | ||
4866 | else | 4500 | else |
4867 | it = pt.CopyToken(pt); | 4501 | it = pt.CopyToken(pt); |
4868 | 4502 | ||
4869 | /* | 4503 | // Whatever we came up with, splice it into the source token stream. |
4870 | * Whatever we came up with, splice it into the source token stream. | ||
4871 | */ | ||
4872 | SpliceSourceToken(it); | 4504 | SpliceSourceToken(it); |
4873 | 4505 | ||
4874 | /* | 4506 | // Maybe we just finished copying an inner type definition. |
4875 | * Maybe we just finished copying an inner type definition. | 4507 | // If so, remember where it ends and pop it from the stack. |
4876 | * If so, remember where it ends and pop it from the stack. | ||
4877 | */ | ||
4878 | if(innerProto.endToken == pt) | 4508 | if(innerProto.endToken == pt) |
4879 | { | 4509 | { |
4880 | innerInst.endToken = it; | 4510 | innerInst.endToken = it; |
@@ -4883,9 +4513,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
4883 | } | 4513 | } |
4884 | } | 4514 | } |
4885 | 4515 | ||
4886 | /* | 4516 | // Clone and insert the terminator, either '}' or ';' |
4887 | * Clone and insert the terminator, either '}' or ';' | ||
4888 | */ | ||
4889 | it = pt.CopyToken(pt); | 4517 | it = pt.CopyToken(pt); |
4890 | SpliceSourceToken(it); | 4518 | SpliceSourceToken(it); |
4891 | instdecl.endToken = it; | 4519 | instdecl.endToken = it; |
@@ -5225,16 +4853,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5225 | 4853 | ||
5226 | if((numVirtFuncs > 0) && (stackedMethods != null)) | 4854 | if((numVirtFuncs > 0) && (stackedMethods != null)) |
5227 | { | 4855 | { |
5228 | 4856 | // Allocate arrays big enough for mine plus type we are extending. | |
5229 | /* | ||
5230 | * Allocate arrays big enough for mine plus type we are extending. | ||
5231 | */ | ||
5232 | vDynMeths = new DynamicMethod[numVirtFuncs]; | 4857 | vDynMeths = new DynamicMethod[numVirtFuncs]; |
5233 | vMethTypes = new Type[numVirtFuncs]; | 4858 | vMethTypes = new Type[numVirtFuncs]; |
5234 | 4859 | ||
5235 | /* | 4860 | // Fill in low parts from type we are extending. |
5236 | * Fill in low parts from type we are extending. | ||
5237 | */ | ||
5238 | if(extends != null) | 4861 | if(extends != null) |
5239 | { | 4862 | { |
5240 | int n = extends.numVirtFuncs; | 4863 | int n = extends.numVirtFuncs; |
@@ -5245,10 +4868,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5245 | } | 4868 | } |
5246 | } | 4869 | } |
5247 | 4870 | ||
5248 | /* | 4871 | // Fill in high parts with my own methods. |
5249 | * Fill in high parts with my own methods. | 4872 | // Might also overwrite lower ones with 'override' methods. |
5250 | * Might also overwrite lower ones with 'override' methods. | ||
5251 | */ | ||
5252 | foreach(StackedMethod sm in stackedMethods) | 4873 | foreach(StackedMethod sm in stackedMethods) |
5253 | { | 4874 | { |
5254 | int i = sm.methVTI; | 4875 | int i = sm.methVTI; |
@@ -5294,16 +4915,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5294 | 4915 | ||
5295 | public override void DebString(StringBuilder sb) | 4916 | public override void DebString(StringBuilder sb) |
5296 | { | 4917 | { |
5297 | /* | 4918 | // Don't output if array of some type. |
5298 | * Don't output if array of some type. | 4919 | // They will be re-instantiated as referenced by rest of script. |
5299 | * They will be re-instantiated as referenced by rest of script. | ||
5300 | */ | ||
5301 | if(arrayOfType != null) | 4920 | if(arrayOfType != null) |
5302 | return; | 4921 | return; |
5303 | 4922 | ||
5304 | /* | 4923 | // This class name and extended/implemented type declaration. |
5305 | * This class name and extended/implemented type declaration. | ||
5306 | */ | ||
5307 | sb.Append("class "); | 4924 | sb.Append("class "); |
5308 | sb.Append(shortName.val); | 4925 | sb.Append(shortName.val); |
5309 | bool first = true; | 4926 | bool first = true; |
@@ -5321,17 +4938,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5321 | } | 4938 | } |
5322 | sb.Append(" {"); | 4939 | sb.Append(" {"); |
5323 | 4940 | ||
5324 | /* | 4941 | // Inner type definitions. |
5325 | * Inner type definitions. | ||
5326 | */ | ||
5327 | foreach(TokenDeclSDType subs in innerSDTypes.Values) | 4942 | foreach(TokenDeclSDType subs in innerSDTypes.Values) |
5328 | { | 4943 | { |
5329 | subs.DebString(sb); | 4944 | subs.DebString(sb); |
5330 | } | 4945 | } |
5331 | 4946 | ||
5332 | /* | 4947 | // Members (fields, methods, properties). |
5333 | * Members (fields, methods, properties). | ||
5334 | */ | ||
5335 | foreach(TokenDeclVar memb in members) | 4948 | foreach(TokenDeclVar memb in members) |
5336 | { | 4949 | { |
5337 | if((memb == instFieldInit) || (memb == staticFieldInit)) | 4950 | if((memb == instFieldInit) || (memb == staticFieldInit)) |
@@ -5511,12 +5124,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5511 | { | 5124 | { |
5512 | int nArgs; | 5125 | int nArgs; |
5513 | 5126 | ||
5514 | /* | 5127 | // This happens when the node was restored via ReadFromFile(). |
5515 | * This happens when the node was restored via ReadFromFile(). | 5128 | // It leaves the types in retStr/argStrs for resolution after |
5516 | * It leaves the types in retStr/argStrs for resolution after | 5129 | // all definitions have been read from the object file in case |
5517 | * all definitions have been read from the object file in case | 5130 | // there are forward references. |
5518 | * there are forward references. | ||
5519 | */ | ||
5520 | if(retType == null) | 5131 | if(retType == null) |
5521 | { | 5132 | { |
5522 | retType = MakeTypeToken(retStr); | 5133 | retType = MakeTypeToken(retStr); |
@@ -5531,10 +5142,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5531 | } | 5142 | } |
5532 | } | 5143 | } |
5533 | 5144 | ||
5534 | /* | 5145 | // Fill in system types from token types. |
5535 | * Fill in system types from token types. | 5146 | // Might as well build the signature strings too from token types. |
5536 | * Might as well build the signature strings too from token types. | ||
5537 | */ | ||
5538 | retSysType = retType.ToSysType(); | 5147 | retSysType = retType.ToSysType(); |
5539 | 5148 | ||
5540 | nArgs = argTypes.Length; | 5149 | nArgs = argTypes.Length; |
@@ -5552,11 +5161,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5552 | argSig = sb.ToString(); | 5161 | argSig = sb.ToString(); |
5553 | wholeSig = retType.ToString() + argSig; | 5162 | wholeSig = retType.ToString() + argSig; |
5554 | 5163 | ||
5555 | /* | 5164 | // Now we can create a system delegate type from the given |
5556 | * Now we can create a system delegate type from the given | 5165 | // return and argument types. Give it an unique name using |
5557 | * return and argument types. Give it an unique name using | 5166 | // the whole signature string. |
5558 | * the whole signature string. | ||
5559 | */ | ||
5560 | sysType = DelegateCommon.GetType(retSysType, argSysTypes, wholeSig); | 5167 | sysType = DelegateCommon.GetType(retSysType, argSysTypes, wholeSig); |
5561 | } | 5168 | } |
5562 | 5169 | ||
@@ -5570,9 +5177,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5570 | { | 5177 | { |
5571 | TokenDeclSDTypeDelegate decldel; | 5178 | TokenDeclSDTypeDelegate decldel; |
5572 | 5179 | ||
5573 | /* | 5180 | // Name it after the whole signature string. |
5574 | * Name it after the whole signature string. | ||
5575 | */ | ||
5576 | StringBuilder sb = new StringBuilder("$inline"); | 5181 | StringBuilder sb = new StringBuilder("$inline"); |
5577 | sb.Append(retType.ToString()); | 5182 | sb.Append(retType.ToString()); |
5578 | sb.Append("("); | 5183 | sb.Append("("); |
@@ -5588,10 +5193,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5588 | string inlname = sb.ToString(); | 5193 | string inlname = sb.ToString(); |
5589 | if(!inlines.TryGetValue(inlname, out decldel)) | 5194 | if(!inlines.TryGetValue(inlname, out decldel)) |
5590 | { | 5195 | { |
5591 | 5196 | // Create the corresponding declaration and link to it | |
5592 | /* | ||
5593 | * Create the corresponding declaration and link to it | ||
5594 | */ | ||
5595 | TokenName name = new TokenName(null, inlname); | 5197 | TokenName name = new TokenName(null, inlname); |
5596 | decldel = new TokenDeclSDTypeDelegate(name); | 5198 | decldel = new TokenDeclSDTypeDelegate(name); |
5597 | decldel.retType = retType; | 5199 | decldel.retType = retType; |
@@ -5860,9 +5462,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5860 | { | 5462 | { |
5861 | TokenDeclSDTypeDelegate decldel; | 5463 | TokenDeclSDTypeDelegate decldel; |
5862 | 5464 | ||
5863 | /* | 5465 | // See if we already have a matching declared one cataloged. |
5864 | * See if we already have a matching declared one cataloged. | ||
5865 | */ | ||
5866 | int nArgs = argTypes.Length; | 5466 | int nArgs = argTypes.Length; |
5867 | foreach(TokenDeclSDType decl in tokenScript.sdSrcTypesValues) | 5467 | foreach(TokenDeclSDType decl in tokenScript.sdSrcTypesValues) |
5868 | { | 5468 | { |
@@ -5886,9 +5486,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
5886 | ; | 5486 | ; |
5887 | } | 5487 | } |
5888 | 5488 | ||
5889 | /* | 5489 | // No such luck, create a new anonymous declaration. |
5890 | * No such luck, create a new anonymous declaration. | ||
5891 | */ | ||
5892 | StringBuilder sb = new StringBuilder("$anondel$"); | 5490 | StringBuilder sb = new StringBuilder("$anondel$"); |
5893 | sb.Append(retType.ToString()); | 5491 | sb.Append(retType.ToString()); |
5894 | sb.Append("("); | 5492 | sb.Append("("); |
@@ -6309,50 +5907,36 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6309 | */ | 5907 | */ |
6310 | public bool IsFuncTrivial(ScriptCodeGen scg) | 5908 | public bool IsFuncTrivial(ScriptCodeGen scg) |
6311 | { | 5909 | { |
6312 | /* | 5910 | // If not really a function, assume it's a delegate. |
6313 | * If not really a function, assume it's a delegate. | 5911 | // And since we don't really know what functions it can point to, |
6314 | * And since we don't really know what functions it can point to, | 5912 | // assume it can point to a non-trivial one. |
6315 | * assume it can point to a non-trivial one. | ||
6316 | */ | ||
6317 | if(retType == null) | 5913 | if(retType == null) |
6318 | return false; | 5914 | return false; |
6319 | 5915 | ||
6320 | /* | 5916 | // All virtual functions are non-trivial because although a particular |
6321 | * All virtual functions are non-trivial because although a particular | 5917 | // one might be trivial, it might be overidden with a non-trivial one. |
6322 | * one might be trivial, it might be overidden with a non-trivial one. | ||
6323 | */ | ||
6324 | if((sdtFlags & (ScriptReduce.SDT_ABSTRACT | ScriptReduce.SDT_OVERRIDE | | 5918 | if((sdtFlags & (ScriptReduce.SDT_ABSTRACT | ScriptReduce.SDT_OVERRIDE | |
6325 | ScriptReduce.SDT_VIRTUAL)) != 0) | 5919 | ScriptReduce.SDT_VIRTUAL)) != 0) |
6326 | { | 5920 | { |
6327 | return false; | 5921 | return false; |
6328 | } | 5922 | } |
6329 | 5923 | ||
6330 | /* | 5924 | // Check the triviality status of the function. |
6331 | * Check the triviality status of the function. | ||
6332 | */ | ||
6333 | switch(triviality) | 5925 | switch(triviality) |
6334 | { | 5926 | { |
6335 | 5927 | // Don't yet know if it is trivial. | |
6336 | /* | 5928 | // We know at this point it doesn't have any direct looping. |
6337 | * Don't yet know if it is trivial. | 5929 | // But if it calls something that has loops, it isn't trivial. |
6338 | * We know at this point it doesn't have any direct looping. | 5930 | // Otherwise it is trivial. |
6339 | * But if it calls something that has loops, it isn't trivial. | ||
6340 | * Otherwise it is trivial. | ||
6341 | */ | ||
6342 | case Triviality.unknown: | 5931 | case Triviality.unknown: |
6343 | { | 5932 | { |
6344 | 5933 | // Mark that we are analyzing this function now. So if there are | |
6345 | /* | 5934 | // any recursive call loops, that will show that the function is |
6346 | * Mark that we are analyzing this function now. So if there are | 5935 | // non-trivial and the analysis will terminate at that point. |
6347 | * any recursive call loops, that will show that the function is | ||
6348 | * non-trivial and the analysis will terminate at that point. | ||
6349 | */ | ||
6350 | triviality = Triviality.analyzing; | 5936 | triviality = Triviality.analyzing; |
6351 | 5937 | ||
6352 | /* | 5938 | // Check out everything else this function calls. If any say they |
6353 | * Check out everything else this function calls. If any say they | 5939 | // aren't trivial, then we say this function isn't trivial. |
6354 | * aren't trivial, then we say this function isn't trivial. | ||
6355 | */ | ||
6356 | foreach(TokenRValCall call in unknownTrivialityCalls) | 5940 | foreach(TokenRValCall call in unknownTrivialityCalls) |
6357 | { | 5941 | { |
6358 | if(!call.IsRValTrivial(scg, null)) | 5942 | if(!call.IsRValTrivial(scg, null)) |
@@ -6362,28 +5946,22 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6362 | } | 5946 | } |
6363 | } | 5947 | } |
6364 | 5948 | ||
6365 | /* | 5949 | // All functions called by this function are trivial, and this |
6366 | * All functions called by this function are trivial, and this | 5950 | // function's code doesn't have any loops, so we can mark this |
6367 | * function's code doesn't have any loops, so we can mark this | 5951 | // function as being trivial. |
6368 | * function as being trivial. | ||
6369 | */ | ||
6370 | triviality = Triviality.trivial; | 5952 | triviality = Triviality.trivial; |
6371 | return true; | 5953 | return true; |
6372 | } | 5954 | } |
6373 | 5955 | ||
6374 | /* | 5956 | // We already know that it is trivial. |
6375 | * We already know that it is trivial. | ||
6376 | */ | ||
6377 | case Triviality.trivial: | 5957 | case Triviality.trivial: |
6378 | { | 5958 | { |
6379 | return true; | 5959 | return true; |
6380 | } | 5960 | } |
6381 | 5961 | ||
6382 | /* | 5962 | // We either know it is complex or are trying to analyze it already. |
6383 | * We either know it is complex or are trying to analyze it already. | 5963 | // If we are already analyzing it, it means it has a recursive loop |
6384 | * If we are already analyzing it, it means it has a recursive loop | 5964 | // and we assume those are non-trivial. |
6385 | * and we assume those are non-trivial. | ||
6386 | */ | ||
6387 | default: | 5965 | default: |
6388 | return false; | 5966 | return false; |
6389 | } | 5967 | } |
@@ -6450,22 +6028,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6450 | 6028 | ||
6451 | for(Token stmt = body.statements; stmt != null; stmt = stmt.nextToken) | 6029 | for(Token stmt = body.statements; stmt != null; stmt = stmt.nextToken) |
6452 | { | 6030 | { |
6453 | 6031 | // Body of the function should all be arithmetic statements (not eg for loops, if statements etc). | |
6454 | /* | ||
6455 | * Body of the function should all be arithmetic statements (not eg for loops, if statements etc). | ||
6456 | */ | ||
6457 | TokenRVal rval = ((TokenStmtRVal)stmt).rVal; | 6032 | TokenRVal rval = ((TokenStmtRVal)stmt).rVal; |
6458 | 6033 | ||
6459 | /* | 6034 | // And the opcode should be a simple assignment operator. |
6460 | * And the opcode should be a simple assignment operator. | ||
6461 | */ | ||
6462 | TokenRValOpBin rvob = (TokenRValOpBin)rval; | 6035 | TokenRValOpBin rvob = (TokenRValOpBin)rval; |
6463 | if(!(rvob.opcode is TokenKwAssign)) | 6036 | if(!(rvob.opcode is TokenKwAssign)) |
6464 | throw new Exception("bad op type " + rvob.opcode.GetType().Name); | 6037 | throw new Exception("bad op type " + rvob.opcode.GetType().Name); |
6465 | 6038 | ||
6466 | /* | 6039 | // Get field or variable being assigned to. |
6467 | * Get field or variable being assigned to. | ||
6468 | */ | ||
6469 | TokenDeclVar var = null; | 6040 | TokenDeclVar var = null; |
6470 | TokenRVal left = rvob.rValLeft; | 6041 | TokenRVal left = rvob.rValLeft; |
6471 | if(left is TokenLValIField) | 6042 | if(left is TokenLValIField) |
@@ -6490,28 +6061,22 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6490 | if(var == null) | 6061 | if(var == null) |
6491 | throw new Exception("unknown var type " + left.GetType().Name); | 6062 | throw new Exception("unknown var type " + left.GetType().Name); |
6492 | 6063 | ||
6493 | /* | 6064 | // Output flags, type name and bare variable name. |
6494 | * Output flags, type name and bare variable name. | 6065 | // This should look like a declaration in the 'sb' |
6495 | * This should look like a declaration in the 'sb' | 6066 | // as it is not enclosed in a function. |
6496 | * as it is not enclosed in a function. | ||
6497 | */ | ||
6498 | var.DebStringSDTFlags(sb); | 6067 | var.DebStringSDTFlags(sb); |
6499 | var.type.DebString(sb); | 6068 | var.type.DebString(sb); |
6500 | sb.Append(' '); | 6069 | sb.Append(' '); |
6501 | sb.Append(var.name.val); | 6070 | sb.Append(var.name.val); |
6502 | 6071 | ||
6503 | /* | 6072 | // Maybe it has a non-default initialization value. |
6504 | * Maybe it has a non-default initialization value. | ||
6505 | */ | ||
6506 | if((var.init != null) && !(var.init is TokenRValInitDef)) | 6073 | if((var.init != null) && !(var.init is TokenRValInitDef)) |
6507 | { | 6074 | { |
6508 | sb.Append(" = "); | 6075 | sb.Append(" = "); |
6509 | var.init.DebString(sb); | 6076 | var.init.DebString(sb); |
6510 | } | 6077 | } |
6511 | 6078 | ||
6512 | /* | 6079 | // End of declaration statement. |
6513 | * End of declaration statement. | ||
6514 | */ | ||
6515 | sb.Append(';'); | 6080 | sb.Append(';'); |
6516 | } | 6081 | } |
6517 | } | 6082 | } |
@@ -6578,17 +6143,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6578 | { | 6143 | { |
6579 | TokenType baseType = baseRVal.GetRValType(scg, null); | 6144 | TokenType baseType = baseRVal.GetRValType(scg, null); |
6580 | 6145 | ||
6581 | /* | 6146 | // Maybe referencing element of a fixed-dimension array. |
6582 | * Maybe referencing element of a fixed-dimension array. | ||
6583 | */ | ||
6584 | if((baseType is TokenTypeSDTypeClass) && (((TokenTypeSDTypeClass)baseType).decl.arrayOfType != null)) | 6147 | if((baseType is TokenTypeSDTypeClass) && (((TokenTypeSDTypeClass)baseType).decl.arrayOfType != null)) |
6585 | { | 6148 | { |
6586 | return ((TokenTypeSDTypeClass)baseType).decl.arrayOfType; | 6149 | return ((TokenTypeSDTypeClass)baseType).decl.arrayOfType; |
6587 | } | 6150 | } |
6588 | 6151 | ||
6589 | /* | 6152 | // Maybe referencing $idxprop property of script-defined class or interface. |
6590 | * Maybe referencing $idxprop property of script-defined class or interface. | ||
6591 | */ | ||
6592 | if(baseType is TokenTypeSDTypeClass) | 6153 | if(baseType is TokenTypeSDTypeClass) |
6593 | { | 6154 | { |
6594 | TokenDeclSDTypeClass sdtDecl = ((TokenTypeSDTypeClass)baseType).decl; | 6155 | TokenDeclSDTypeClass sdtDecl = ((TokenTypeSDTypeClass)baseType).decl; |
@@ -6604,17 +6165,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6604 | return idxProp.type; | 6165 | return idxProp.type; |
6605 | } | 6166 | } |
6606 | 6167 | ||
6607 | /* | 6168 | // Maybe referencing single character of a string. |
6608 | * Maybe referencing single character of a string. | ||
6609 | */ | ||
6610 | if((baseType is TokenTypeKey) || (baseType is TokenTypeStr)) | 6169 | if((baseType is TokenTypeKey) || (baseType is TokenTypeStr)) |
6611 | { | 6170 | { |
6612 | return new TokenTypeChar(this); | 6171 | return new TokenTypeChar(this); |
6613 | } | 6172 | } |
6614 | 6173 | ||
6615 | /* | 6174 | // Assume XMR_Array element or extracting element from list. |
6616 | * Assume XMR_Array element or extracting element from list. | ||
6617 | */ | ||
6618 | if((baseType is TokenTypeArray) || (baseType is TokenTypeList)) | 6175 | if((baseType is TokenTypeArray) || (baseType is TokenTypeList)) |
6619 | { | 6176 | { |
6620 | return new TokenTypeObject(this); | 6177 | return new TokenTypeObject(this); |
@@ -6714,19 +6271,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6714 | 6271 | ||
6715 | public override bool IsRValTrivial(ScriptCodeGen scg, TokenType[] argsig) | 6272 | public override bool IsRValTrivial(ScriptCodeGen scg, TokenType[] argsig) |
6716 | { | 6273 | { |
6717 | /* | 6274 | // If getting pointer to instance isn't trivial, then accessing the member isn't trivial either. |
6718 | * If getting pointer to instance isn't trivial, then accessing the member isn't trivial either. | ||
6719 | */ | ||
6720 | if(!baseRVal.IsRValTrivial(scg, null)) | 6275 | if(!baseRVal.IsRValTrivial(scg, null)) |
6721 | return false; | 6276 | return false; |
6722 | 6277 | ||
6723 | /* | 6278 | // Accessing a member of a class depends on the member. |
6724 | * Accessing a member of a class depends on the member. | 6279 | // In the case of a method, this is accessing it as a delegate, not calling it, and |
6725 | * In the case of a method, this is accessing it as a delegate, not calling it, and | 6280 | // argsig simply serves as selecting which of possibly overloaded methods to select. |
6726 | * argsig simply serves as selecting which of possibly overloaded methods to select. | 6281 | // The case of accessing a property, however, depends on the property implementation, |
6727 | * The case of accessing a property, however, depends on the property implementation, | 6282 | // as there could be looping inside the property code. |
6728 | * as there could be looping inside the property code. | ||
6729 | */ | ||
6730 | TokenType baseType = baseRVal.GetRValType(scg, null); | 6283 | TokenType baseType = baseRVal.GetRValType(scg, null); |
6731 | if(baseType is TokenTypeSDTypeClass) | 6284 | if(baseType is TokenTypeSDTypeClass) |
6732 | { | 6285 | { |
@@ -6734,9 +6287,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6734 | return (var != null) && var.IsVarTrivial(scg); | 6287 | return (var != null) && var.IsVarTrivial(scg); |
6735 | } | 6288 | } |
6736 | 6289 | ||
6737 | /* | 6290 | // Accessing the members of anything else (arrays, rotations, vectors) is always trivial. |
6738 | * Accessing the members of anything else (arrays, rotations, vectors) is always trivial. | ||
6739 | */ | ||
6740 | return true; | 6291 | return true; |
6741 | } | 6292 | } |
6742 | 6293 | ||
@@ -6748,15 +6299,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6748 | */ | 6299 | */ |
6749 | public override bool IsCallTrivial(ScriptCodeGen scg, TokenType[] argsig) | 6300 | public override bool IsCallTrivial(ScriptCodeGen scg, TokenType[] argsig) |
6750 | { | 6301 | { |
6751 | /* | 6302 | // If getting pointer to instance isn't trivial, then calling the method isn't trivial either. |
6752 | * If getting pointer to instance isn't trivial, then calling the method isn't trivial either. | ||
6753 | */ | ||
6754 | if(!baseRVal.IsRValTrivial(scg, null)) | 6303 | if(!baseRVal.IsRValTrivial(scg, null)) |
6755 | return false; | 6304 | return false; |
6756 | 6305 | ||
6757 | /* | 6306 | // Calling a method of a class depends on the method. |
6758 | * Calling a method of a class depends on the method. | ||
6759 | */ | ||
6760 | TokenType baseType = baseRVal.GetRValType(scg, null); | 6307 | TokenType baseType = baseRVal.GetRValType(scg, null); |
6761 | if(baseType is TokenTypeSDTypeClass) | 6308 | if(baseType is TokenTypeSDTypeClass) |
6762 | { | 6309 | { |
@@ -6764,21 +6311,17 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6764 | return (var != null) && var.IsFuncTrivial(scg); | 6311 | return (var != null) && var.IsFuncTrivial(scg); |
6765 | } | 6312 | } |
6766 | 6313 | ||
6767 | /* | 6314 | // Calling via a pointer to an interface instance is never trivial. |
6768 | * Calling via a pointer to an interface instance is never trivial. | 6315 | // (It is really a pointer to an array of delegates). |
6769 | * (It is really a pointer to an array of delegates). | 6316 | // We can't tell for this call site whether the actual method being called is trivial or not, |
6770 | * We can't tell for this call site whether the actual method being called is trivial or not, | 6317 | // so we have to assume it isn't. |
6771 | * so we have to assume it isn't. | 6318 | // ??? We could theoretically check to see if *all* implementations of this method of |
6772 | * ??? We could theoretically check to see if *all* implementations of this method of | 6319 | // this interface are trivial, then we could conclude that this call is trivial. |
6773 | * this interface are trivial, then we could conclude that this call is trivial. | ||
6774 | */ | ||
6775 | if(baseType is TokenTypeSDTypeInterface) | 6320 | if(baseType is TokenTypeSDTypeInterface) |
6776 | return false; | 6321 | return false; |
6777 | 6322 | ||
6778 | /* | 6323 | // Calling a method of anything else (arrays, rotations, vectors) is always trivial. |
6779 | * Calling a method of anything else (arrays, rotations, vectors) is always trivial. | 6324 | // Even methods of delegates, such as ".GetArgTypes()" that we may someday do is trivial. |
6780 | * Even methods of delegates, such as ".GetArgTypes()" that we may someday do is trivial. | ||
6781 | */ | ||
6782 | return true; | 6325 | return true; |
6783 | } | 6326 | } |
6784 | 6327 | ||
@@ -6801,23 +6344,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6801 | 6344 | ||
6802 | public TokenLValName(TokenName name, VarDict stack) : base(name) | 6345 | public TokenLValName(TokenName name, VarDict stack) : base(name) |
6803 | { | 6346 | { |
6804 | /* | 6347 | // Save name of variable/method/function/field. |
6805 | * Save name of variable/method/function/field. | ||
6806 | */ | ||
6807 | this.name = name; | 6348 | this.name = name; |
6808 | 6349 | ||
6809 | /* | 6350 | // Save where in the stack it can be looked up. |
6810 | * Save where in the stack it can be looked up. | 6351 | // If the current stack is for locals, do not allow forward references. |
6811 | * If the current stack is for locals, do not allow forward references. | 6352 | // this allows idiocy like: |
6812 | * this allows idiocy like: | 6353 | // list buttons = [ 1, 2, 3 ]; |
6813 | * list buttons = [ 1, 2, 3 ]; | 6354 | // x () { |
6814 | * x () { | 6355 | // list buttons = llList2List (buttons, 0, 1); |
6815 | * list buttons = llList2List (buttons, 0, 1); | 6356 | // llOwnerSay (llList2CSV (buttons)); |
6816 | * llOwnerSay (llList2CSV (buttons)); | 6357 | // } |
6817 | * } | 6358 | // If it is not locals, allow forward references. |
6818 | * If it is not locals, allow forward references. | 6359 | // this allows function X() to call Y() and Y() to call X(). |
6819 | * this allows function X() to call Y() and Y() to call X(). | ||
6820 | */ | ||
6821 | this.stack = stack.FreezeLocals(); | 6360 | this.stack = stack.FreezeLocals(); |
6822 | } | 6361 | } |
6823 | 6362 | ||
@@ -6879,22 +6418,18 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6879 | 6418 | ||
6880 | public override bool IsRValTrivial(ScriptCodeGen scg, TokenType[] argsig) | 6419 | public override bool IsRValTrivial(ScriptCodeGen scg, TokenType[] argsig) |
6881 | { | 6420 | { |
6882 | /* | 6421 | // Accessing a member of a class depends on the member. |
6883 | * Accessing a member of a class depends on the member. | 6422 | // In the case of a method, this is accessing it as a delegate, not calling it, and |
6884 | * In the case of a method, this is accessing it as a delegate, not calling it, and | 6423 | // argsig simply serves as selecting which of possibly overloaded methods to select. |
6885 | * argsig simply serves as selecting which of possibly overloaded methods to select. | 6424 | // The case of accessing a property, however, depends on the property implementation, |
6886 | * The case of accessing a property, however, depends on the property implementation, | 6425 | // as there could be looping inside the property code. |
6887 | * as there could be looping inside the property code. | ||
6888 | */ | ||
6889 | if(baseType is TokenTypeSDTypeClass) | 6426 | if(baseType is TokenTypeSDTypeClass) |
6890 | { | 6427 | { |
6891 | TokenDeclVar var = scg.FindThisMember((TokenTypeSDTypeClass)baseType, fieldName, argsig); | 6428 | TokenDeclVar var = scg.FindThisMember((TokenTypeSDTypeClass)baseType, fieldName, argsig); |
6892 | return (var != null) && var.IsVarTrivial(scg); | 6429 | return (var != null) && var.IsVarTrivial(scg); |
6893 | } | 6430 | } |
6894 | 6431 | ||
6895 | /* | 6432 | // Accessing the fields/methods/properties of anything else (arrays, rotations, vectors) is always trivial. |
6896 | * Accessing the fields/methods/properties of anything else (arrays, rotations, vectors) is always trivial. | ||
6897 | */ | ||
6898 | return true; | 6433 | return true; |
6899 | } | 6434 | } |
6900 | 6435 | ||
@@ -6906,18 +6441,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
6906 | */ | 6441 | */ |
6907 | public override bool IsCallTrivial(ScriptCodeGen scg, TokenType[] argsig) | 6442 | public override bool IsCallTrivial(ScriptCodeGen scg, TokenType[] argsig) |
6908 | { | 6443 | { |
6909 | /* | 6444 | // Calling a static method of a class depends on the method. |
6910 | * Calling a static method of a class depends on the method. | ||
6911 | */ | ||
6912 | if(baseType is TokenTypeSDTypeClass) | 6445 | if(baseType is TokenTypeSDTypeClass) |
6913 | { | 6446 | { |
6914 | TokenDeclVar var = scg.FindThisMember((TokenTypeSDTypeClass)baseType, fieldName, argsig); | 6447 | TokenDeclVar var = scg.FindThisMember((TokenTypeSDTypeClass)baseType, fieldName, argsig); |
6915 | return (var != null) && var.IsFuncTrivial(scg); | 6448 | return (var != null) && var.IsFuncTrivial(scg); |
6916 | } | 6449 | } |
6917 | 6450 | ||
6918 | /* | 6451 | // Calling a static method of anything else (arrays, rotations, vectors) is always trivial. |
6919 | * Calling a static method of anything else (arrays, rotations, vectors) is always trivial. | ||
6920 | */ | ||
6921 | return true; | 6452 | return true; |
6922 | } | 6453 | } |
6923 | 6454 | ||
@@ -7075,9 +6606,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
7075 | */ | 6606 | */ |
7076 | public override TokenType GetRValType(ScriptCodeGen scg, TokenType[] argsig) | 6607 | public override TokenType GetRValType(ScriptCodeGen scg, TokenType[] argsig) |
7077 | { | 6608 | { |
7078 | /* | 6609 | // Build type signature so we select correct overloaded function. |
7079 | * Build type signature so we select correct overloaded function. | ||
7080 | */ | ||
7081 | if(myArgSig == null) | 6610 | if(myArgSig == null) |
7082 | { | 6611 | { |
7083 | myArgSig = new TokenType[nArgs]; | 6612 | myArgSig = new TokenType[nArgs]; |
@@ -7088,9 +6617,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
7088 | } | 6617 | } |
7089 | } | 6618 | } |
7090 | 6619 | ||
7091 | /* | 6620 | // Get the type of the method itself. This should get us a delegate type. |
7092 | * Get the type of the method itself. This should get us a delegate type. | ||
7093 | */ | ||
7094 | TokenType delType = meth.GetRValType(scg, myArgSig); | 6621 | TokenType delType = meth.GetRValType(scg, myArgSig); |
7095 | if(!(delType is TokenTypeSDTypeDelegate)) | 6622 | if(!(delType is TokenTypeSDTypeDelegate)) |
7096 | { | 6623 | { |
@@ -7098,9 +6625,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
7098 | return new TokenTypeVoid(meth); | 6625 | return new TokenTypeVoid(meth); |
7099 | } | 6626 | } |
7100 | 6627 | ||
7101 | /* | 6628 | // Get the return type from the delegate type. |
7102 | * Get the return type from the delegate type. | ||
7103 | */ | ||
7104 | return ((TokenTypeSDTypeDelegate)delType).decl.GetRetType(); | 6629 | return ((TokenTypeSDTypeDelegate)delType).decl.GetRetType(); |
7105 | } | 6630 | } |
7106 | 6631 | ||
@@ -7112,9 +6637,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
7112 | */ | 6637 | */ |
7113 | public override bool IsRValTrivial(ScriptCodeGen scg, TokenType[] argsig) | 6638 | public override bool IsRValTrivial(ScriptCodeGen scg, TokenType[] argsig) |
7114 | { | 6639 | { |
7115 | /* | 6640 | // Build type signature so we select correct overloaded function. |
7116 | * Build type signature so we select correct overloaded function. | ||
7117 | */ | ||
7118 | if(myArgSig == null) | 6641 | if(myArgSig == null) |
7119 | { | 6642 | { |
7120 | myArgSig = new TokenType[nArgs]; | 6643 | myArgSig = new TokenType[nArgs]; |
@@ -7125,18 +6648,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
7125 | } | 6648 | } |
7126 | } | 6649 | } |
7127 | 6650 | ||
7128 | /* | 6651 | // Make sure all arguments can be computed trivially. |
7129 | * Make sure all arguments can be computed trivially. | ||
7130 | */ | ||
7131 | for(Token t = args; t != null; t = t.nextToken) | 6652 | for(Token t = args; t != null; t = t.nextToken) |
7132 | { | 6653 | { |
7133 | if(!((TokenRVal)t).IsRValTrivial(scg, null)) | 6654 | if(!((TokenRVal)t).IsRValTrivial(scg, null)) |
7134 | return false; | 6655 | return false; |
7135 | } | 6656 | } |
7136 | 6657 | ||
7137 | /* | 6658 | // See if the function call itself and the function body are trivial. |
7138 | * See if the function call itself and the function body are trivial. | ||
7139 | */ | ||
7140 | return meth.IsCallTrivial(scg, myArgSig); | 6659 | return meth.IsCallTrivial(scg, myArgSig); |
7141 | } | 6660 | } |
7142 | 6661 | ||
@@ -7717,9 +7236,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
7717 | 7236 | ||
7718 | public override TokenType GetRValType(ScriptCodeGen scg, TokenType[] argsig) | 7237 | public override TokenType GetRValType(ScriptCodeGen scg, TokenType[] argsig) |
7719 | { | 7238 | { |
7720 | /* | 7239 | // Comparisons and the like always return bool. |
7721 | * Comparisons and the like always return bool. | ||
7722 | */ | ||
7723 | string opstr = opcode.ToString(); | 7240 | string opstr = opcode.ToString(); |
7724 | if((opstr == "==") || (opstr == "!=") || (opstr == ">=") || (opstr == ">") || | 7241 | if((opstr == "==") || (opstr == "!=") || (opstr == ">=") || (opstr == ">") || |
7725 | (opstr == "&&") || (opstr == "||") || (opstr == "<=") || (opstr == "<") || | 7242 | (opstr == "&&") || (opstr == "||") || (opstr == "<=") || (opstr == "<") || |
@@ -7728,25 +7245,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
7728 | return new TokenTypeBool(opcode); | 7245 | return new TokenTypeBool(opcode); |
7729 | } | 7246 | } |
7730 | 7247 | ||
7731 | /* | 7248 | // Comma is always type of right-hand operand. |
7732 | * Comma is always type of right-hand operand. | ||
7733 | */ | ||
7734 | if(opstr == ",") | 7249 | if(opstr == ",") |
7735 | return rValRight.GetRValType(scg, argsig); | 7250 | return rValRight.GetRValType(scg, argsig); |
7736 | 7251 | ||
7737 | /* | 7252 | // Assignments are always the type of the left-hand operand, |
7738 | * Assignments are always the type of the left-hand operand, | 7253 | // including stuff like "+=". |
7739 | * including stuff like "+=". | ||
7740 | */ | ||
7741 | if(opstr.EndsWith("=")) | 7254 | if(opstr.EndsWith("=")) |
7742 | { | 7255 | { |
7743 | return rValLeft.GetRValType(scg, argsig); | 7256 | return rValLeft.GetRValType(scg, argsig); |
7744 | } | 7257 | } |
7745 | 7258 | ||
7746 | /* | 7259 | // string+something or something+string is always string. |
7747 | * string+something or something+string is always string. | 7260 | // except list+something or something+list is always a list. |
7748 | * except list+something or something+list is always a list. | ||
7749 | */ | ||
7750 | string lType = rValLeft.GetRValType(scg, argsig).ToString(); | 7261 | string lType = rValLeft.GetRValType(scg, argsig).ToString(); |
7751 | string rType = rValRight.GetRValType(scg, argsig).ToString(); | 7262 | string rType = rValRight.GetRValType(scg, argsig).ToString(); |
7752 | if((opstr == "+") && ((lType == "list") || (rType == "list"))) | 7263 | if((opstr == "+") && ((lType == "list") || (rType == "list"))) |
@@ -7759,9 +7270,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
7759 | return new TokenTypeStr(opcode); | 7270 | return new TokenTypeStr(opcode); |
7760 | } | 7271 | } |
7761 | 7272 | ||
7762 | /* | 7273 | // Everything else depends on both operands. |
7763 | * Everything else depends on both operands. | ||
7764 | */ | ||
7765 | string key = lType + opstr + rType; | 7274 | string key = lType + opstr + rType; |
7766 | BinOpStr binOpStr; | 7275 | BinOpStr binOpStr; |
7767 | if(BinOpStr.defined.TryGetValue(key, out binOpStr)) | 7276 | if(BinOpStr.defined.TryGetValue(key, out binOpStr)) |
@@ -8234,7 +7743,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8234 | */ | 7743 | */ |
8235 | public class TokenStmtBlock: TokenStmt | 7744 | public class TokenStmtBlock: TokenStmt |
8236 | { | 7745 | { |
8237 | |||
8238 | public Token statements; // null-terminated list of statements, can also have TokenDeclVar's in here | 7746 | public Token statements; // null-terminated list of statements, can also have TokenDeclVar's in here |
8239 | public TokenStmtBlock outerStmtBlock; // next outer stmtBlock or null if top-level, ie, function definition | 7747 | public TokenStmtBlock outerStmtBlock; // next outer stmtBlock or null if top-level, ie, function definition |
8240 | public TokenDeclVar function; // function it is part of | 7748 | public TokenDeclVar function; // function it is part of |
@@ -8262,7 +7770,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8262 | */ | 7770 | */ |
8263 | public class TokenStmtLabel: TokenStmt | 7771 | public class TokenStmtLabel: TokenStmt |
8264 | { | 7772 | { |
8265 | |||
8266 | public TokenName name; // the label's name | 7773 | public TokenName name; // the label's name |
8267 | public TokenStmtBlock block; // which block it is defined in | 7774 | public TokenStmtBlock block; // which block it is defined in |
8268 | public bool hasBkwdRefs = false; | 7775 | public bool hasBkwdRefs = false; |
@@ -8437,7 +7944,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8437 | 7944 | ||
8438 | public class TokenStmtNull: TokenStmt | 7945 | public class TokenStmtNull: TokenStmt |
8439 | { | 7946 | { |
8440 | |||
8441 | public TokenStmtNull(Token original) : base(original) { } | 7947 | public TokenStmtNull(Token original) : base(original) { } |
8442 | 7948 | ||
8443 | public override void DebString(StringBuilder sb) | 7949 | public override void DebString(StringBuilder sb) |
@@ -8448,7 +7954,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8448 | 7954 | ||
8449 | public class TokenStmtRet: TokenStmt | 7955 | public class TokenStmtRet: TokenStmt |
8450 | { | 7956 | { |
8451 | |||
8452 | public TokenRVal rVal; // null if void | 7957 | public TokenRVal rVal; // null if void |
8453 | 7958 | ||
8454 | public TokenStmtRet(Token original) : base(original) { } | 7959 | public TokenStmtRet(Token original) : base(original) { } |
@@ -8470,7 +7975,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8470 | */ | 7975 | */ |
8471 | public class TokenStmtState: TokenStmt | 7976 | public class TokenStmtState: TokenStmt |
8472 | { | 7977 | { |
8473 | |||
8474 | public TokenName state; // null for default | 7978 | public TokenName state; // null for default |
8475 | 7979 | ||
8476 | public TokenStmtState(Token original) : base(original) { } | 7980 | public TokenStmtState(Token original) : base(original) { } |
@@ -8488,7 +7992,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8488 | */ | 7992 | */ |
8489 | public class TokenStmtSwitch: TokenStmt | 7993 | public class TokenStmtSwitch: TokenStmt |
8490 | { | 7994 | { |
8491 | |||
8492 | public TokenRValParen testRVal; // the integer index expression | 7995 | public TokenRValParen testRVal; // the integer index expression |
8493 | public TokenSwitchCase cases = null; // list of all cases, linked by .nextCase | 7996 | public TokenSwitchCase cases = null; // list of all cases, linked by .nextCase |
8494 | public TokenSwitchCase lastCase = null; // used during reduce to point to last in 'cases' list | 7997 | public TokenSwitchCase lastCase = null; // used during reduce to point to last in 'cases' list |
@@ -8558,7 +8061,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8558 | 8061 | ||
8559 | public class TokenStmtThrow: TokenStmt | 8062 | public class TokenStmtThrow: TokenStmt |
8560 | { | 8063 | { |
8561 | |||
8562 | public TokenRVal rVal; // null if rethrow style | 8064 | public TokenRVal rVal; // null if rethrow style |
8563 | 8065 | ||
8564 | public TokenStmtThrow(Token original) : base(original) { } | 8066 | public TokenStmtThrow(Token original) : base(original) { } |
@@ -8576,7 +8078,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8576 | */ | 8078 | */ |
8577 | public class TokenStmtTry: TokenStmt | 8079 | public class TokenStmtTry: TokenStmt |
8578 | { | 8080 | { |
8579 | |||
8580 | public TokenStmtBlock tryStmt; | 8081 | public TokenStmtBlock tryStmt; |
8581 | public TokenDeclVar catchVar; // null iff catchStmt is null | 8082 | public TokenDeclVar catchVar; // null iff catchStmt is null |
8582 | public TokenStmtBlock catchStmt; // can be null | 8083 | public TokenStmtBlock catchStmt; // can be null |
@@ -8620,7 +8121,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine | |||
8620 | 8121 | ||
8621 | public class TokenStmtWhile: TokenStmt | 8122 | public class TokenStmtWhile: TokenStmt |
8622 | { | 8123 | { |
8623 | |||
8624 | public TokenRValParen testRVal; | 8124 | public TokenRValParen testRVal; |
8625 | public TokenStmt bodyStmt; | 8125 | public TokenStmt bodyStmt; |
8626 | 8126 | ||