Ticket #46260: _NscLib__NscParserRoutines.cpp.patch
File _NscLib__NscParserRoutines.cpp.patch, 14.6 KB (added by jmroot (Joshua Root), 10 years ago) |
---|
-
_NscLib/NscParserRoutines.cpp
old new bool NscBuildSyntaxError (int nToken, YY 396 396 397 397 switch (nToken) 398 398 { 399 case IDENTIFIER:399 case yy::parser::token::IDENTIFIER: 400 400 if (yylval) 401 401 pszToken = yylval ->GetIdentifier (); 402 402 else 403 403 pszToken = "identifier"; 404 404 break; 405 405 406 case INTEGER_CONST:406 case yy::parser::token::INTEGER_CONST: 407 407 pszToken = "integer constant"; 408 408 break; 409 409 410 case FLOAT_CONST:410 case yy::parser::token::FLOAT_CONST: 411 411 pszToken = "float constant"; 412 412 break; 413 413 414 case STRING_CONST:414 case yy::parser::token::STRING_CONST: 415 415 pszToken = "string constant"; 416 416 break; 417 417 418 case ADDEQ:418 case yy::parser::token::ADDEQ: 419 419 pszToken = "+="; 420 420 break; 421 421 422 case SUBEQ:422 case yy::parser::token::SUBEQ: 423 423 pszToken = "-="; 424 424 break; 425 425 426 case MULEQ:426 case yy::parser::token::MULEQ: 427 427 pszToken = "*="; 428 428 break; 429 429 430 case DIVEQ:430 case yy::parser::token::DIVEQ: 431 431 pszToken = "/="; 432 432 break; 433 433 434 case MODEQ:434 case yy::parser::token::MODEQ: 435 435 pszToken = "%="; 436 436 break; 437 437 438 case XOREQ:438 case yy::parser::token::XOREQ: 439 439 pszToken = "^="; 440 440 break; 441 441 442 case ANDEQ:442 case yy::parser::token::ANDEQ: 443 443 pszToken = "&="; 444 444 break; 445 445 446 case OREQ:446 case yy::parser::token::OREQ: 447 447 pszToken = "|="; 448 448 break; 449 449 450 case SL:450 case yy::parser::token::SL: 451 451 pszToken = "<<"; 452 452 break; 453 453 454 case SR:454 case yy::parser::token::SR: 455 455 pszToken = ">>"; 456 456 break; 457 457 458 case USR:458 case yy::parser::token::USR: 459 459 pszToken = ">>>"; 460 460 break; 461 461 462 case SLEQ:462 case yy::parser::token::SLEQ: 463 463 pszToken = "<<="; 464 464 break; 465 465 466 case SREQ:466 case yy::parser::token::SREQ: 467 467 pszToken = ">>="; 468 468 break; 469 469 470 case USREQ:470 case yy::parser::token::USREQ: 471 471 pszToken = ">>>="; 472 472 break; 473 473 474 case EQ:474 case yy::parser::token::EQ: 475 475 pszToken = "=="; 476 476 break; 477 477 478 case NOTEQ:478 case yy::parser::token::NOTEQ: 479 479 pszToken = "!="; 480 480 break; 481 481 482 case LTEQ:482 case yy::parser::token::LTEQ: 483 483 pszToken = "<="; 484 484 break; 485 485 486 case GTEQ:486 case yy::parser::token::GTEQ: 487 487 pszToken = ">="; 488 488 break; 489 489 490 case ANDAND:490 case yy::parser::token::ANDAND: 491 491 pszToken = "&&"; 492 492 break; 493 493 494 case OROR:494 case yy::parser::token::OROR: 495 495 pszToken = "||"; 496 496 break; 497 497 498 case PLUSPLUS:498 case yy::parser::token::PLUSPLUS: 499 499 pszToken = "++"; 500 500 break; 501 501 502 case MINUSMINUS:502 case yy::parser::token::MINUSMINUS: 503 503 pszToken = "--"; 504 504 break; 505 505 506 case FLOAT_TYPE:506 case yy::parser::token::FLOAT_TYPE: 507 507 pszToken = "float"; 508 508 break; 509 509 510 case INT_TYPE:510 case yy::parser::token::INT_TYPE: 511 511 pszToken = "int"; 512 512 break; 513 513 514 case OBJECT_TYPE:514 case yy::parser::token::OBJECT_TYPE: 515 515 pszToken = "object"; 516 516 break; 517 517 518 case STRING_TYPE:518 case yy::parser::token::STRING_TYPE: 519 519 pszToken = "string"; 520 520 break; 521 521 522 case VOID_TYPE:522 case yy::parser::token::VOID_TYPE: 523 523 pszToken = "void"; 524 524 break; 525 525 526 case STRUCT_TYPE:526 case yy::parser::token::STRUCT_TYPE: 527 527 pszToken = "struct"; 528 528 break; 529 529 530 case VECTOR_TYPE:530 case yy::parser::token::VECTOR_TYPE: 531 531 pszToken = "vector"; 532 532 break; 533 533 534 case ENGINE_TYPE:534 case yy::parser::token::ENGINE_TYPE: 535 535 if (yylval) 536 536 { 537 537 int nIndex = yylval ->GetType () - NscType_Engine_0; … … bool NscBuildSyntaxError (int nToken, YY 541 541 pszToken = "engine-type"; 542 542 break; 543 543 544 case ACTION_TYPE:544 case yy::parser::token::ACTION_TYPE: 545 545 pszToken = "action"; 546 546 break; 547 547 548 case OBJECT_SELF_CONST:548 case yy::parser::token::OBJECT_SELF_CONST: 549 549 pszToken = "OBJECT_SELF"; 550 550 break; 551 551 552 case OBJECT_INVALID_CONST:552 case yy::parser::token::OBJECT_INVALID_CONST: 553 553 pszToken = "OBJECT_INVALID"; 554 554 break; 555 555 556 case BREAK:556 case yy::parser::token::BREAK: 557 557 pszToken = "break"; 558 558 break; 559 559 560 case CASE:560 case yy::parser::token::CASE: 561 561 pszToken = "case"; 562 562 break; 563 563 564 case CONTINUE:564 case yy::parser::token::CONTINUE: 565 565 pszToken = "continue"; 566 566 break; 567 567 568 case DEFAULT:568 case yy::parser::token::DEFAULT: 569 569 pszToken = "default"; 570 570 break; 571 571 572 case DO:572 case yy::parser::token::DO: 573 573 pszToken = "do"; 574 574 break; 575 575 576 case ELSE:576 case yy::parser::token::ELSE: 577 577 pszToken = "else"; 578 578 break; 579 579 580 case FOR:580 case yy::parser::token::FOR: 581 581 pszToken = "for"; 582 582 break; 583 583 584 case IF:584 case yy::parser::token::IF: 585 585 pszToken = "if"; 586 586 break; 587 587 588 case RETURN:588 case yy::parser::token::RETURN: 589 589 pszToken = "return"; 590 590 break; 591 591 592 case SWITCH:592 case yy::parser::token::SWITCH: 593 593 pszToken = "switch"; 594 594 break; 595 595 596 case WHILE:596 case yy::parser::token::WHILE: 597 597 pszToken = "while"; 598 598 break; 599 599 600 case NWCONST:600 case yy::parser::token::NWCONST: 601 601 pszToken = "const"; 602 602 break; 603 603 … … YYSTYPE NscBuildType (int nType, YYSTYPE 657 657 658 658 switch (nType) 659 659 { 660 case VOID_TYPE:660 case yy::parser::token::VOID_TYPE: 661 661 pOut ->SetType (NscType_Void); 662 662 break; 663 663 664 case INT_TYPE:664 case yy::parser::token::INT_TYPE: 665 665 pOut ->SetType (NscType_Integer); 666 666 break; 667 667 668 case FLOAT_TYPE:668 case yy::parser::token::FLOAT_TYPE: 669 669 pOut ->SetType (NscType_Float); 670 670 break; 671 671 672 case OBJECT_TYPE:672 case yy::parser::token::OBJECT_TYPE: 673 673 pOut ->SetType (NscType_Object); 674 674 break; 675 675 676 case STRING_TYPE:676 case yy::parser::token::STRING_TYPE: 677 677 pOut ->SetType (NscType_String); 678 678 break; 679 679 680 case VECTOR_TYPE:680 case yy::parser::token::VECTOR_TYPE: 681 681 pOut ->SetType (NscType_Vector); 682 682 break; 683 683 684 case ACTION_TYPE:684 case yy::parser::token::ACTION_TYPE: 685 685 if (!g_pCtx ->IsNWScript ()) 686 686 { 687 687 g_pCtx ->GenerateError ("\"action\" identifier only " … … YYSTYPE NscBuildType (int nType, YYSTYPE 692 692 pOut ->SetType (NscType_Action); 693 693 break; 694 694 695 case STRUCT_TYPE:695 case yy::parser::token::STRUCT_TYPE: 696 696 assert (pId != NULL); 697 697 { 698 698 if (!g_pCtx ->IsPhase2 () && !g_pCtx ->IsNWScript ()) … … YYSTYPE NscBuildType (int nType, YYSTYPE 723 723 } 724 724 break; 725 725 726 case ENGINE_TYPE:726 case yy::parser::token::ENGINE_TYPE: 727 727 assert (pId != NULL); 728 728 { 729 729 pOut ->SetType (pId ->GetType ()); … … YYSTYPE NscBuildBinaryOp (int nToken, YY 2923 2923 } 2924 2924 break; 2925 2925 2926 case SL:2926 case yy::parser::token::SL: 2927 2927 if (nLhsType == NscType_Integer && nRhsType == NscType_Integer) 2928 2928 { 2929 2929 if (g_pCtx ->GetOptExpression () && … … YYSTYPE NscBuildBinaryOp (int nToken, YY 2948 2948 } 2949 2949 break; 2950 2950 2951 case SR:2951 case yy::parser::token::SR: 2952 2952 if (nLhsType == NscType_Integer && nRhsType == NscType_Integer) 2953 2953 { 2954 2954 #ifdef NOT_ENABLED_YET … … YYSTYPE NscBuildBinaryOp (int nToken, YY 2975 2975 } 2976 2976 break; 2977 2977 2978 case USR:2978 case yy::parser::token::USR: 2979 2979 if (nLhsType == NscType_Integer && nRhsType == NscType_Integer) 2980 2980 { 2981 2981 #ifdef NOT_ENABLED_YET … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3086 3086 } 3087 3087 break; 3088 3088 3089 case LTEQ:3089 case yy::parser::token::LTEQ: 3090 3090 if (nLhsType == NscType_Integer && nRhsType == NscType_Integer) 3091 3091 { 3092 3092 if (g_pCtx ->GetOptExpression () && … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3128 3128 } 3129 3129 break; 3130 3130 3131 case GTEQ:3131 case yy::parser::token::GTEQ: 3132 3132 if (nLhsType == NscType_Integer && nRhsType == NscType_Integer) 3133 3133 { 3134 3134 if (g_pCtx ->GetOptExpression () && … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3170 3170 } 3171 3171 break; 3172 3172 3173 case EQ:3173 case yy::parser::token::EQ: 3174 3174 if (nLhsType == NscType_Integer && nRhsType == NscType_Integer) 3175 3175 { 3176 3176 if (g_pCtx ->GetOptExpression () && … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3260 3260 } 3261 3261 break; 3262 3262 3263 case NOTEQ:3263 case yy::parser::token::NOTEQ: 3264 3264 if (nLhsType == NscType_Integer && nRhsType == NscType_Integer) 3265 3265 { 3266 3266 if (g_pCtx ->GetOptExpression () && … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3440 3440 } 3441 3441 break; 3442 3442 3443 case MULEQ:3443 case yy::parser::token::MULEQ: 3444 3444 if (nLhsType == NscType_Vector && nRhsType == NscType_Float) 3445 3445 { 3446 3446 NscPushAssignment (pOut, NscPCode_AsnMultiply, … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3468 3468 } 3469 3469 break; 3470 3470 3471 case DIVEQ:3471 case yy::parser::token::DIVEQ: 3472 3472 if (nLhsType == NscType_Vector && nRhsType == NscType_Float) 3473 3473 { 3474 3474 NscPushAssignment (pOut, NscPCode_AsnDivide, … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3496 3496 } 3497 3497 break; 3498 3498 3499 case MODEQ:3499 case yy::parser::token::MODEQ: 3500 3500 if (nLhsType == NscType_Integer && nRhsType == NscType_Integer) 3501 3501 { 3502 3502 NscPushAssignment (pOut, NscPCode_AsnModulus, … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3509 3509 } 3510 3510 break; 3511 3511 3512 case ADDEQ:3512 case yy::parser::token::ADDEQ: 3513 3513 if (nLhsType == NscType_Vector && nRhsType == NscType_Vector) 3514 3514 { 3515 3515 NscPushAssignment (pOut, NscPCode_AsnAdd, … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3542 3542 } 3543 3543 break; 3544 3544 3545 case SUBEQ:3545 case yy::parser::token::SUBEQ: 3546 3546 if (nLhsType == NscType_Vector && nRhsType == NscType_Vector) 3547 3547 { 3548 3548 NscPushAssignment (pOut, NscPCode_AsnSubtract, … … YYSTYPE NscBuildBinaryOp (int nToken, YY 3570 3570 } 3571 3571 break; 3572 3572 3573 case SLEQ:3573 case yy::parser::token::SLEQ: 3574 3574 pszOp = "<<="; 3575 3575 nOp = NscPCode_AsnShiftLeft; 3576 3576 asn_shift_operator:; … … asn_shift_operator:; 3586 3586 } 3587 3587 break; 3588 3588 3589 case SREQ:3589 case yy::parser::token::SREQ: 3590 3590 pszOp = ">>="; 3591 3591 nOp = NscPCode_AsnShiftRight; 3592 3592 goto asn_shift_operator; 3593 3593 3594 case USREQ:3594 case yy::parser::token::USREQ: 3595 3595 pszOp = ">>>="; 3596 3596 nOp = NscPCode_AsnUnsignedShiftRight; 3597 3597 goto asn_shift_operator; 3598 3598 3599 case ANDEQ:3599 case yy::parser::token::ANDEQ: 3600 3600 pszOp = "&="; 3601 3601 nOp = NscPCode_AsnBitwiseAND; 3602 3602 asn_bitwise_expression:; … … asn_bitwise_expression:; 3612 3612 } 3613 3613 break; 3614 3614 3615 case XOREQ:3615 case yy::parser::token::XOREQ: 3616 3616 pszOp = "^="; 3617 3617 nOp = NscPCode_AsnBitwiseXOR; 3618 3618 goto asn_bitwise_expression; 3619 3619 3620 case OREQ:3620 case yy::parser::token::OREQ: 3621 3621 pszOp = "|="; 3622 3622 nOp = NscPCode_AsnBitwiseOR; 3623 3623 goto asn_bitwise_expression; … … YYSTYPE NscBuildLogicalOp (int nToken, Y 3696 3696 3697 3697 const char *pszOp; 3698 3698 NscPCode nOp; 3699 if (nToken == ANDAND)3699 if (nToken == yy::parser::token::ANDAND) 3700 3700 { 3701 3701 pszOp = "&&"; 3702 3702 nOp = NscPCode_LogicalAND; 3703 3703 } 3704 else if (nToken == OROR)3704 else if (nToken == yy::parser::token::OROR) 3705 3705 { 3706 3706 pszOp = "||"; 3707 3707 nOp = NscPCode_LogicalOR; … … YYSTYPE NscBuildLogicalOp (int nToken, Y 3750 3750 // If the operation is known to be true or false by the lhs 3751 3751 // 3752 3752 3753 else if (nToken == ANDAND && nLhsConstant == 0)3753 else if (nToken == yy::parser::token::ANDAND && nLhsConstant == 0) 3754 3754 { 3755 3755 pOut ->PushConstantInteger (0); 3756 3756 pOut ->SetType (NscType_Integer); 3757 3757 } 3758 else if (nToken == OROR && nLhsConstant == 1)3758 else if (nToken == yy::parser::token::OROR && nLhsConstant == 1) 3759 3759 { 3760 3760 pOut ->PushConstantInteger (1); 3761 3761 pOut ->SetType (NscType_Integer); … … YYSTYPE NscBuild5Block (int nToken, YYST 4706 4706 bool fCheckCond; 4707 4707 switch (nToken) 4708 4708 { 4709 case IF:4709 case yy::parser::token::IF: 4710 4710 nPCode = NscPCode_If; 4711 4711 nFenceType = NscFenceType_If; 4712 4712 pszToken = "if"; … … YYSTYPE NscBuild5Block (int nToken, YYST 4714 4714 fCheckCond = pPrev == NULL; 4715 4715 break; 4716 4716 4717 case WHILE:4717 case yy::parser::token::WHILE: 4718 4718 nPCode = NscPCode_While; 4719 4719 nFenceType = NscFenceType_While; 4720 4720 pszToken = "while"; … … YYSTYPE NscBuild5Block (int nToken, YYST 4722 4722 fCheckCond = pPrev == NULL; 4723 4723 break; 4724 4724 4725 case DO:4725 case yy::parser::token::DO: 4726 4726 nPCode = NscPCode_Do; 4727 4727 nFenceType = NscFenceType_Do; 4728 4728 pszToken = "do"; … … YYSTYPE NscBuild5Block (int nToken, YYST 4730 4730 fCheckCond = pPrev != NULL; 4731 4731 break; 4732 4732 4733 case FOR:4733 case yy::parser::token::FOR: 4734 4734 nPCode = NscPCode_For; 4735 4735 nFenceType = NscFenceType_For; 4736 4736 pszToken = "for"; … … YYSTYPE NscBuild5Block (int nToken, YYST 4738 4738 fCheckCond = pPrev == NULL; 4739 4739 break; 4740 4740 4741 case SWITCH:4741 case yy::parser::token::SWITCH: 4742 4742 nPCode = NscPCode_Switch; 4743 4743 nFenceType = NscFenceType_Switch; 4744 4744 pszToken = "switch"; … … YYSTYPE NscBuild5Block (int nToken, YYST 4787 4787 // for this 4788 4788 // 4789 4789 4790 if (nToken == SWITCH)4790 if (nToken == yy::parser::token::SWITCH) 4791 4791 { 4792 4792 NscSymbolFence *pFence = g_pCtx ->GetCurrentFence (); 4793 4793 pFence ->nPrevLocals++; … … YYSTYPE NscBuild5Block (int nToken, YYST 4806 4806 // then set return 4807 4807 // 4808 4808 4809 if (nToken == IF && pFalse)4809 if (nToken == yy::parser::token::IF && pFalse) 4810 4810 { 4811 4811 if (fHadReturn) 4812 4812 NscSetFenceReturn (true); … … YYSTYPE NscBuildCase (int nToken, YYSTYP 4992 4992 // If this is a case 4993 4993 // 4994 4994 4995 if (nToken == CASE)4995 if (nToken == yy::parser::token::CASE) 4996 4996 { 4997 4997 4998 4998 // … … YYSTYPE NscBuildCase (int nToken, YYSTYP 5061 5061 // Test for only one default 5062 5062 // 5063 5063 5064 if (nToken == DEFAULT)5064 if (nToken == yy::parser::token::DEFAULT) 5065 5065 { 5066 5066 if (pFence ->fHasDefault) 5067 5067 { … … YYSTYPE NscBuildCase (int nToken, YYSTYP 5086 5086 // 5087 5087 5088 5088 NscPCode nPCode; 5089 if (nToken == CASE)5089 if (nToken == yy::parser::token::CASE) 5090 5090 nPCode = NscPCode_Case; 5091 else if (nToken == DEFAULT)5091 else if (nToken == yy::parser::token::DEFAULT) 5092 5092 nPCode = NscPCode_Default; 5093 5093 else 5094 5094 { … … YYSTYPE NscBuildBreakContinue (int nToke 5262 5262 // 5263 5263 5264 5264 NscPCode nPCode; 5265 if (nToken == BREAK)5265 if (nToken == yy::parser::token::BREAK) 5266 5266 nPCode = NscPCode_Break; 5267 else if (nToken == CONTINUE)5267 else if (nToken == yy::parser::token::CONTINUE) 5268 5268 nPCode = NscPCode_Continue; 5269 5269 else 5270 5270 { … … YYSTYPE NscBuildBreakContinue (int nToke 5279 5279 NscSymbolFence *pFence = g_pCtx ->GetCurrentFence (); 5280 5280 while (pFence) 5281 5281 { 5282 if ((pFence ->nFenceType == NscFenceType_Switch && nToken == BREAK) ||5282 if ((pFence ->nFenceType == NscFenceType_Switch && nToken == yy::parser::token::BREAK) || 5283 5283 pFence ->nFenceType == NscFenceType_Do || 5284 5284 pFence ->nFenceType == NscFenceType_While || 5285 5285 pFence ->nFenceType == NscFenceType_For) … … YYSTYPE NscBuildBreakContinue (int nToke 5288 5288 } 5289 5289 if (pFence == NULL) 5290 5290 { 5291 if (nToken == BREAK)5291 if (nToken == yy::parser::token::BREAK) 5292 5292 { 5293 5293 g_pCtx ->GenerateError ("\"break\" statement only allowed in " 5294 5294 "\"switch\", \"do\", \"while\", and \"for\" statements"); 5295 5295 } 5296 else if (nToken == CONTINUE)5296 else if (nToken == yy::parser::token::CONTINUE) 5297 5297 { 5298 5298 g_pCtx ->GenerateError ("\"continue\" statement only allowed in " 5299 5299 "\"do\", \"while\", and \"for\" statements");