儲存庫 kBuild 的更動 1724
- 時間撮記:
- 2008-9-5 上午12:34:53 (16 年 以前)
- 位置:
- trunk/src/kmk
- 檔案:
-
- 修改 4 筆資料
- 移動 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/kmk/Makefile.am
r1722 r1724 47 47 strcache.c variable.c version.c vpath.c hash.c \ 48 48 \ 49 expreval.c \ 49 50 kbuild.c \ 50 51 electric.c \ -
trunk/src/kmk/Makefile.kmk
r1722 r1724 178 178 main.c \ 179 179 read.c \ 180 ifcond.c \180 expreval.c \ 181 181 hash.c \ 182 182 strcache.c \ -
trunk/src/kmk/expreval.c
r1723 r1724 2 2 /* $Id$ */ 3 3 /** @file 4 * ifcond - C like if expressions.4 * expreval - Expressions evaluator, C / BSD make / nmake style. 5 5 */ 6 6 … … 53 53 *******************************************************************************/ 54 54 /** The max length of a string representation of a number. */ 55 #define IFCOND_NUM_LEN ((sizeof("-9223372036854775802") + 4) & ~3)55 #define EXPR_NUM_LEN ((sizeof("-9223372036854775802") + 4) & ~3) 56 56 57 57 /** The max operator stack depth. */ 58 #define IFCOND_MAX_OPERATORS 7258 #define EXPR_MAX_OPERATORS 72 59 59 /** The max operand depth. */ 60 #define IFCOND_MAX_OPERANDS 12860 #define EXPR_MAX_OPERANDS 128 61 61 62 62 … … 66 66 /** The 64-bit signed integer type we're using. */ 67 67 #ifdef _MSC_VER 68 typedef __int64 IFCONDINT64;68 typedef __int64 EXPRINT64; 69 69 #else 70 70 # include <stdint.h> 71 typedef int64_t IFCONDINT64;71 typedef int64_t EXPRINT64; 72 72 #endif 73 73 74 74 /** Pointer to a evaluator instance. */ 75 typedef struct IFCOND *PIFCOND;75 typedef struct EXPR *PEXPR; 76 76 77 77 … … 82 82 { 83 83 /** Invalid zero entry. */ 84 k IfCondVar_Invalid = 0,84 kExprVar_Invalid = 0, 85 85 /** A number. */ 86 k IfCondVar_Num,86 kExprVar_Num, 87 87 /** A string in need of expanding (perhaps). */ 88 k IfCondVar_String,88 kExprVar_String, 89 89 /** A simple string that doesn't need expanding. */ 90 k IfCondVar_SimpleString,90 kExprVar_SimpleString, 91 91 /** A quoted string in need of expanding (perhaps). */ 92 k IfCondVar_QuotedString,92 kExprVar_QuotedString, 93 93 /** A simple quoted string that doesn't need expanding. */ 94 k IfCondVar_QuotedSimpleString,94 kExprVar_QuotedSimpleString, 95 95 /** The end of the valid variable types. */ 96 k IfCondVar_End97 } IFCONDVARTYPE;96 kExprVar_End 97 } EXPRVARTYPE; 98 98 99 99 /** … … 103 103 { 104 104 /** The variable type. */ 105 IFCONDVARTYPE enmType;105 EXPRVARTYPE enmType; 106 106 /** The variable. */ 107 107 union … … 110 110 char *psz; 111 111 /** The variable. */ 112 IFCONDINT64 i;112 EXPRINT64 i; 113 113 } uVal; 114 } IFCONDVAR;114 } EXPRVAR; 115 115 /** Pointer to a operand variable. */ 116 typedef IFCONDVAR *PIFCONDVAR;116 typedef EXPRVAR *PEXPRVAR; 117 117 /** Pointer to a const operand variable. */ 118 typedef IFCONDVAR const *PCIFCONDVAR;118 typedef EXPRVAR const *PCEXPRVAR; 119 119 120 120 /** … … 123 123 typedef enum 124 124 { 125 k IfCondRet_Error = -1,126 k IfCondRet_Ok = 0,127 k IfCondRet_Operator,128 k IfCondRet_Operand,129 k IfCondRet_EndOfExpr,130 k IfCondRet_End131 } IFCONDRET;125 kExprRet_Error = -1, 126 kExprRet_Ok = 0, 127 kExprRet_Operator, 128 kExprRet_Operand, 129 kExprRet_EndOfExpr, 130 kExprRet_End 131 } EXPRRET; 132 132 133 133 /** … … 148 148 signed char cArgs; 149 149 /** Pointer to the method implementing the operator. */ 150 IFCONDRET (*pfn)(PIFCONDpThis);151 } IFCONDOP;150 EXPRRET (*pfn)(PEXPR pThis); 151 } EXPROP; 152 152 /** Pointer to a const operator. */ 153 typedef IFCONDOP const *PCIFCONDOP;153 typedef EXPROP const *PCEXPROP; 154 154 155 155 /** 156 156 * Expression evaluator instance. 157 157 */ 158 typedef struct IFCOND158 typedef struct EXPR 159 159 { 160 160 /** The full expression. */ … … 165 165 const struct floc *pFileLoc; 166 166 /** Pending binary operator. */ 167 PC IFCONDOP pPending;167 PCEXPROP pPending; 168 168 /** Top of the operator stack. */ 169 169 int iOp; … … 171 171 int iVar; 172 172 /** The operator stack. */ 173 PC IFCONDOP apOps[IFCOND_MAX_OPERATORS];173 PCEXPROP apOps[EXPR_MAX_OPERATORS]; 174 174 /** The operand stack. */ 175 IFCONDVAR aVars[IFCOND_MAX_OPERANDS];176 } IFCOND;175 EXPRVAR aVars[EXPR_MAX_OPERANDS]; 176 } EXPR; 177 177 178 178 … … 184 184 static char g_auchOpStartCharMap[256]; 185 185 /** Whether we've initialized the map. */ 186 static int g_f IfCondInitializedMap = 0;186 static int g_fExprInitializedMap = 0; 187 187 188 188 … … 190 190 * Internal Functions * 191 191 *******************************************************************************/ 192 static void ifcond_unget_op(PIFCONDpThis);193 static IFCONDRET ifcond_get_binary_or_eoe_or_rparen(PIFCONDpThis);192 static void expr_unget_op(PEXPR pThis); 193 static EXPRRET expr_get_binary_or_eoe_or_rparen(PEXPR pThis); 194 194 195 195 … … 205 205 * @param ... The message format args. 206 206 */ 207 static void ifcond_error(PIFCONDpThis, const char *pszError, ...)207 static void expr_error(PEXPR pThis, const char *pszError, ...) 208 208 { 209 209 char szTmp[256]; … … 222 222 * 223 223 * @returns pszDst. 224 * @param pszDst The string buffer to write into. Assumes length of IFCOND_NUM_LEN.224 * @param pszDst The string buffer to write into. Assumes length of EXPR_NUM_LEN. 225 225 * @param iSrc The number to convert. 226 226 */ 227 static char * ifcond_num_to_string(char *pszDst, IFCONDINT64 iSrc)227 static char *expr_num_to_string(char *pszDst, EXPRINT64 iSrc) 228 228 { 229 229 static const char s_szDigits[17] = "0123456789abcdef"; 230 char szTmp[ IFCOND_NUM_LEN];231 char *psz = &szTmp[ IFCOND_NUM_LEN - 1];230 char szTmp[EXPR_NUM_LEN]; 231 char *psz = &szTmp[EXPR_NUM_LEN - 1]; 232 232 int fNegative; 233 233 … … 261 261 /* copy it into the output buffer. */ 262 262 psz++; 263 return (char *)memcpy(pszDst, psz, &szTmp[ IFCOND_NUM_LEN] - psz);263 return (char *)memcpy(pszDst, psz, &szTmp[EXPR_NUM_LEN] - psz); 264 264 } 265 265 … … 274 274 * @param fQuiet Whether we should be quiet or grumpy on failure. 275 275 */ 276 static IFCONDRET ifcond_string_to_num(PIFCOND pThis, IFCONDINT64 *piDst, const char *pszSrc, int fQuiet)277 { 278 IFCONDRET rc = kIfCondRet_Ok;276 static EXPRRET expr_string_to_num(PEXPR pThis, EXPRINT64 *piDst, const char *pszSrc, int fQuiet) 277 { 278 EXPRRET rc = kExprRet_Ok; 279 279 char const *psz = pszSrc; 280 IFCONDINT64 i;280 EXPRINT64 i; 281 281 unsigned uBase; 282 282 int fNegative; … … 393 393 *piDst = i; 394 394 if (!fQuiet) 395 ifcond_error(pThis, "Invalid a number \"%.80s\"", pszSrc);396 return k IfCondRet_Error;395 expr_error(pThis, "Invalid a number \"%.80s\"", pszSrc); 396 return kExprRet_Error; 397 397 } 398 398 … … 412 412 * @param pVar The variable. 413 413 */ 414 static int ifcond_var_is_string(PCIFCONDVAR pVar)415 { 416 return pVar->enmType >= k IfCondVar_String;414 static int expr_var_is_string(PCEXPRVAR pVar) 415 { 416 return pVar->enmType >= kExprVar_String; 417 417 } 418 418 … … 425 425 * @param pVar The variable. 426 426 */ 427 static int ifcond_var_was_quoted(PCIFCONDVAR pVar)428 { 429 return pVar->enmType >= k IfCondVar_QuotedString;427 static int expr_var_was_quoted(PCEXPRVAR pVar) 428 { 429 return pVar->enmType >= kExprVar_QuotedString; 430 430 } 431 431 … … 436 436 * @param pVar The variable. 437 437 */ 438 static void ifcond_var_delete(PIFCONDVAR pVar)439 { 440 if ( ifcond_var_is_string(pVar))438 static void expr_var_delete(PEXPRVAR pVar) 439 { 440 if (expr_var_is_string(pVar)) 441 441 { 442 442 free(pVar->uVal.psz); 443 443 pVar->uVal.psz = NULL; 444 444 } 445 pVar->enmType = k IfCondVar_Invalid;445 pVar->enmType = kExprVar_Invalid; 446 446 } 447 447 … … 455 455 * @param enmType The string type. 456 456 */ 457 static void ifcond_var_init_substring(PIFCONDVAR pVar, const char *psz, size_t cch, IFCONDVARTYPE enmType)457 static void expr_var_init_substring(PEXPRVAR pVar, const char *psz, size_t cch, EXPRVARTYPE enmType) 458 458 { 459 459 /* convert string needing expanding into simple ones if possible. */ 460 if ( enmType == k IfCondVar_String460 if ( enmType == kExprVar_String 461 461 && !memchr(psz, '$', cch)) 462 enmType = k IfCondVar_SimpleString;463 else if ( enmType == k IfCondVar_QuotedString462 enmType = kExprVar_SimpleString; 463 else if ( enmType == kExprVar_QuotedString 464 464 && !memchr(psz, '$', cch)) 465 enmType = k IfCondVar_QuotedSimpleString;465 enmType = kExprVar_QuotedSimpleString; 466 466 467 467 pVar->enmType = enmType; … … 480 480 * @param enmType The string type. 481 481 */ 482 static void ifcond_var_init_string(PIFCONDVAR pVar, const char *psz, IFCONDVARTYPE enmType)483 { 484 ifcond_var_init_substring(pVar, psz, strlen(psz), enmType);482 static void expr_var_init_string(PEXPRVAR pVar, const char *psz, EXPRVARTYPE enmType) 483 { 484 expr_var_init_substring(pVar, psz, strlen(psz), enmType); 485 485 } 486 486 … … 494 494 * @param enmType The string type. 495 495 */ 496 static void ifcond_var_assign_substring(PIFCONDVAR pVar, const char *psz, size_t cch, IFCONDVARTYPE enmType)497 { 498 ifcond_var_delete(pVar);499 ifcond_var_init_substring(pVar, psz, cch, enmType);496 static void expr_var_assign_substring(PEXPRVAR pVar, const char *psz, size_t cch, EXPRVARTYPE enmType) 497 { 498 expr_var_delete(pVar); 499 expr_var_init_substring(pVar, psz, cch, enmType); 500 500 } 501 501 … … 508 508 * @param enmType The string type. 509 509 */ 510 static void ifcond_var_assign_string(PIFCONDVAR pVar, const char *psz, IFCONDVARTYPE enmType)511 { 512 ifcond_var_delete(pVar);513 ifcond_var_init_string(pVar, psz, enmType);510 static void expr_var_assign_string(PEXPRVAR pVar, const char *psz, EXPRVARTYPE enmType) 511 { 512 expr_var_delete(pVar); 513 expr_var_init_string(pVar, psz, enmType); 514 514 } 515 515 #endif /* unused */ … … 521 521 * @param pVar The variable. 522 522 */ 523 static void ifcond_var_make_simple_string(PIFCONDVAR pVar)523 static void expr_var_make_simple_string(PEXPRVAR pVar) 524 524 { 525 525 switch (pVar->enmType) 526 526 { 527 case k IfCondVar_Num:527 case kExprVar_Num: 528 528 { 529 char *psz = (char *)xmalloc( IFCOND_NUM_LEN);530 ifcond_num_to_string(psz, pVar->uVal.i);529 char *psz = (char *)xmalloc(EXPR_NUM_LEN); 530 expr_num_to_string(psz, pVar->uVal.i); 531 531 pVar->uVal.psz = psz; 532 pVar->enmType = k IfCondVar_SimpleString;532 pVar->enmType = kExprVar_SimpleString; 533 533 break; 534 534 } 535 535 536 case k IfCondVar_String:537 case k IfCondVar_QuotedString:536 case kExprVar_String: 537 case kExprVar_QuotedString: 538 538 { 539 539 char *psz; … … 544 544 pVar->uVal.psz = psz; 545 545 546 pVar->enmType = pVar->enmType == k IfCondVar_String547 ? k IfCondVar_SimpleString548 : k IfCondVar_QuotedSimpleString;546 pVar->enmType = pVar->enmType == kExprVar_String 547 ? kExprVar_SimpleString 548 : kExprVar_QuotedSimpleString; 549 549 break; 550 550 } 551 551 552 case k IfCondVar_SimpleString:553 case k IfCondVar_QuotedSimpleString:552 case kExprVar_SimpleString: 553 case kExprVar_QuotedSimpleString: 554 554 /* nothing to do. */ 555 555 break; … … 567 567 * @param pVar The variable. 568 568 */ 569 static void ifcond_var_make_string(PIFCONDVAR pVar)569 static void expr_var_make_string(PEXPRVAR pVar) 570 570 { 571 571 switch (pVar->enmType) 572 572 { 573 case k IfCondVar_Num:574 ifcond_var_make_simple_string(pVar);573 case kExprVar_Num: 574 expr_var_make_simple_string(pVar); 575 575 break; 576 576 577 case k IfCondVar_String:578 case k IfCondVar_SimpleString:579 case k IfCondVar_QuotedString:580 case k IfCondVar_QuotedSimpleString:577 case kExprVar_String: 578 case kExprVar_SimpleString: 579 case kExprVar_QuotedString: 580 case kExprVar_QuotedSimpleString: 581 581 /* nothing to do. */ 582 582 break; … … 595 595 * @param i The integer value. 596 596 */ 597 static void ifcond_var_init_num(PIFCONDVAR pVar, IFCONDINT64 i)598 { 599 pVar->enmType = k IfCondVar_Num;597 static void expr_var_init_num(PEXPRVAR pVar, EXPRINT64 i) 598 { 599 pVar->enmType = kExprVar_Num; 600 600 pVar->uVal.i = i; 601 601 } … … 608 608 * @param i The integer value. 609 609 */ 610 static void ifcond_var_assign_num(PIFCONDVAR pVar, IFCONDINT64 i)611 { 612 ifcond_var_delete(pVar);613 ifcond_var_init_num(pVar, i);610 static void expr_var_assign_num(PEXPRVAR pVar, EXPRINT64 i) 611 { 612 expr_var_delete(pVar); 613 expr_var_init_num(pVar, i); 614 614 } 615 615 … … 622 622 * @param pVar The variable. 623 623 */ 624 static IFCONDRET ifcond_var_make_num(PIFCOND pThis, PIFCONDVAR pVar)624 static EXPRRET expr_var_make_num(PEXPR pThis, PEXPRVAR pVar) 625 625 { 626 626 switch (pVar->enmType) 627 627 { 628 case k IfCondVar_Num:628 case kExprVar_Num: 629 629 /* nothing to do. */ 630 630 break; 631 631 632 case k IfCondVar_String:633 ifcond_var_make_simple_string(pVar);632 case kExprVar_String: 633 expr_var_make_simple_string(pVar); 634 634 /* fall thru */ 635 case k IfCondVar_SimpleString:635 case kExprVar_SimpleString: 636 636 { 637 IFCONDINT64 i;638 IFCONDRET rc = ifcond_string_to_num(pThis, &i, pVar->uVal.psz, 0 /* fQuiet */);639 if (rc < k IfCondRet_Ok)637 EXPRINT64 i; 638 EXPRRET rc = expr_string_to_num(pThis, &i, pVar->uVal.psz, 0 /* fQuiet */); 639 if (rc < kExprRet_Ok) 640 640 return rc; 641 ifcond_var_assign_num(pVar, i);641 expr_var_assign_num(pVar, i); 642 642 break; 643 643 } 644 644 645 case k IfCondVar_QuotedString:646 case k IfCondVar_QuotedSimpleString:647 ifcond_error(pThis, "Cannot convert a quoted string to a number");648 return k IfCondRet_Error;645 case kExprVar_QuotedString: 646 case kExprVar_QuotedSimpleString: 647 expr_error(pThis, "Cannot convert a quoted string to a number"); 648 return kExprRet_Error; 649 649 650 650 default: 651 651 assert(0); 652 return k IfCondRet_Error;653 } 654 655 return k IfCondRet_Ok;652 return kExprRet_Error; 653 } 654 655 return kExprRet_Ok; 656 656 } 657 657 … … 663 663 * @param pVar The variable. 664 664 */ 665 static IFCONDRET ifcond_var_try_make_num(PIFCONDVAR pVar)665 static EXPRRET expr_var_try_make_num(PEXPRVAR pVar) 666 666 { 667 667 switch (pVar->enmType) 668 668 { 669 case k IfCondVar_Num:669 case kExprVar_Num: 670 670 /* nothing to do. */ 671 671 break; 672 672 673 case k IfCondVar_String:674 ifcond_var_make_simple_string(pVar);673 case kExprVar_String: 674 expr_var_make_simple_string(pVar); 675 675 /* fall thru */ 676 case k IfCondVar_SimpleString:676 case kExprVar_SimpleString: 677 677 { 678 IFCONDINT64 i;679 IFCONDRET rc = ifcond_string_to_num(NULL, &i, pVar->uVal.psz, 1 /* fQuiet */);680 if (rc < k IfCondRet_Ok)678 EXPRINT64 i; 679 EXPRRET rc = expr_string_to_num(NULL, &i, pVar->uVal.psz, 1 /* fQuiet */); 680 if (rc < kExprRet_Ok) 681 681 return rc; 682 ifcond_var_assign_num(pVar, i);682 expr_var_assign_num(pVar, i); 683 683 break; 684 684 } … … 686 686 default: 687 687 assert(0); 688 case k IfCondVar_QuotedString:689 case k IfCondVar_QuotedSimpleString:688 case kExprVar_QuotedString: 689 case kExprVar_QuotedSimpleString: 690 690 /* can't do this */ 691 return k IfCondRet_Error;692 } 693 694 return k IfCondRet_Ok;691 return kExprRet_Error; 692 } 693 694 return kExprRet_Ok; 695 695 } 696 696 … … 702 702 * @param f The boolean value. 703 703 */ 704 static void ifcond_var_init_bool(PIFCONDVAR pVar, int f)705 { 706 pVar->enmType = k IfCondVar_Num;704 static void expr_var_init_bool(PEXPRVAR pVar, int f) 705 { 706 pVar->enmType = kExprVar_Num; 707 707 pVar->uVal.i = !!f; 708 708 } … … 715 715 * @param f The boolean value. 716 716 */ 717 static void ifcond_var_assign_bool(PIFCONDVAR pVar, int f)718 { 719 ifcond_var_delete(pVar);720 ifcond_var_init_bool(pVar, f);717 static void expr_var_assign_bool(PEXPRVAR pVar, int f) 718 { 719 expr_var_delete(pVar); 720 expr_var_init_bool(pVar, f); 721 721 } 722 722 … … 728 728 * @param pVar The variable. 729 729 */ 730 static int ifcond_var_make_bool(PIFCONDVAR pVar)730 static int expr_var_make_bool(PEXPRVAR pVar) 731 731 { 732 732 switch (pVar->enmType) 733 733 { 734 case k IfCondVar_Num:734 case kExprVar_Num: 735 735 pVar->uVal.i = !!pVar->uVal.i; 736 736 break; 737 737 738 case k IfCondVar_String:739 ifcond_var_make_simple_string(pVar);738 case kExprVar_String: 739 expr_var_make_simple_string(pVar); 740 740 /* fall thru */ 741 case k IfCondVar_SimpleString:741 case kExprVar_SimpleString: 742 742 { 743 743 /* … … 745 745 * GNU make boolean logic - not empty string means true. 746 746 */ 747 IFCONDINT64 iVal;747 EXPRINT64 iVal; 748 748 char const *psz = pVar->uVal.psz; 749 749 while (isblank((unsigned char)*psz)) 750 750 psz++; 751 751 if ( *psz 752 && ifcond_string_to_num(NULL, &iVal, psz, 1 /* fQuiet */) >= kIfCondRet_Ok)753 ifcond_var_assign_bool(pVar, iVal != 0);752 && expr_string_to_num(NULL, &iVal, psz, 1 /* fQuiet */) >= kExprRet_Ok) 753 expr_var_assign_bool(pVar, iVal != 0); 754 754 else 755 ifcond_var_assign_bool(pVar, *psz != '\0');755 expr_var_assign_bool(pVar, *psz != '\0'); 756 756 break; 757 757 } 758 758 759 case k IfCondVar_QuotedString:760 ifcond_var_make_simple_string(pVar);759 case kExprVar_QuotedString: 760 expr_var_make_simple_string(pVar); 761 761 /* fall thru */ 762 case k IfCondVar_QuotedSimpleString:762 case kExprVar_QuotedSimpleString: 763 763 /* 764 764 * Use GNU make boolean logic (not empty string means true). 765 765 * No stripping here, the string is quoted. 766 766 */ 767 ifcond_var_assign_bool(pVar, *pVar->uVal.psz != '\0');767 expr_var_assign_bool(pVar, *pVar->uVal.psz != '\0'); 768 768 break; 769 769 … … 781 781 * @param pThis The evaluator instance. 782 782 */ 783 static void ifcond_pop_and_delete_var(PIFCONDpThis)784 { 785 ifcond_var_delete(&pThis->aVars[pThis->iVar]);783 static void expr_pop_and_delete_var(PEXPR pThis) 784 { 785 expr_var_delete(&pThis->aVars[pThis->iVar]); 786 786 pThis->iVar--; 787 787 } … … 806 806 * @param pVar2 The second variable. 807 807 */ 808 static IFCONDRET ifcond_var_unify_types(PIFCOND pThis, PIFCONDVAR pVar1, PIFCONDVAR pVar2, const char *pszOp)808 static EXPRRET expr_var_unify_types(PEXPR pThis, PEXPRVAR pVar1, PEXPRVAR pVar2, const char *pszOp) 809 809 { 810 810 /* 811 811 * Try make the variables the same type before comparing. 812 812 */ 813 if ( ! ifcond_var_was_quoted(pVar1)814 && ! ifcond_var_was_quoted(pVar2))815 { 816 if ( ifcond_var_is_string(pVar1)817 || ifcond_var_is_string(pVar2))813 if ( !expr_var_was_quoted(pVar1) 814 && !expr_var_was_quoted(pVar2)) 815 { 816 if ( expr_var_is_string(pVar1) 817 || expr_var_is_string(pVar2)) 818 818 { 819 if (! ifcond_var_is_string(pVar1))820 ifcond_var_try_make_num(pVar2);821 else if (! ifcond_var_is_string(pVar2))822 ifcond_var_try_make_num(pVar1);819 if (!expr_var_is_string(pVar1)) 820 expr_var_try_make_num(pVar2); 821 else if (!expr_var_is_string(pVar2)) 822 expr_var_try_make_num(pVar1); 823 823 else 824 824 { … … 826 826 * Both are strings, simplify them then see if both can be made into numbers. 827 827 */ 828 IFCONDINT64 iVar1;829 IFCONDINT64 iVar2;830 831 ifcond_var_make_simple_string(pVar1);832 ifcond_var_make_simple_string(pVar2);833 834 if ( ifcond_string_to_num(NULL, &iVar1, pVar1->uVal.psz, 1 /* fQuiet */) >= kIfCondRet_Ok835 && ifcond_string_to_num(NULL, &iVar2, pVar2->uVal.psz, 1 /* fQuiet */) >= kIfCondRet_Ok)828 EXPRINT64 iVar1; 829 EXPRINT64 iVar2; 830 831 expr_var_make_simple_string(pVar1); 832 expr_var_make_simple_string(pVar2); 833 834 if ( expr_string_to_num(NULL, &iVar1, pVar1->uVal.psz, 1 /* fQuiet */) >= kExprRet_Ok 835 && expr_string_to_num(NULL, &iVar2, pVar2->uVal.psz, 1 /* fQuiet */) >= kExprRet_Ok) 836 836 { 837 ifcond_var_assign_num(pVar1, iVar1);838 ifcond_var_assign_num(pVar2, iVar2);837 expr_var_assign_num(pVar1, iVar1); 838 expr_var_assign_num(pVar2, iVar2); 839 839 } 840 840 } … … 843 843 else 844 844 { 845 ifcond_var_make_simple_string(pVar1);846 ifcond_var_make_simple_string(pVar2);845 expr_var_make_simple_string(pVar1); 846 expr_var_make_simple_string(pVar2); 847 847 } 848 848 … … 850 850 * Complain if they aren't the same type now. 851 851 */ 852 if ( ifcond_var_is_string(pVar1) != ifcond_var_is_string(pVar2))853 { 854 ifcond_error(pThis, "Unable to unify types for \"%s\"", pszOp);855 return k IfCondRet_Error;856 } 857 return k IfCondRet_Ok;852 if (expr_var_is_string(pVar1) != expr_var_is_string(pVar2)) 853 { 854 expr_error(pThis, "Unable to unify types for \"%s\"", pszOp); 855 return kExprRet_Error; 856 } 857 return kExprRet_Ok; 858 858 } 859 859 … … 865 865 * @param pThis The instance. 866 866 */ 867 static IFCONDRET ifcond_op_defined(PIFCONDpThis)868 { 869 P IFCONDVAR pVar = &pThis->aVars[pThis->iVar];867 static EXPRRET expr_op_defined(PEXPR pThis) 868 { 869 PEXPRVAR pVar = &pThis->aVars[pThis->iVar]; 870 870 struct variable *pMakeVar; 871 871 assert(pThis->iVar >= 0); 872 872 873 ifcond_var_make_simple_string(pVar);873 expr_var_make_simple_string(pVar); 874 874 pMakeVar = lookup_variable(pVar->uVal.psz, strlen(pVar->uVal.psz)); 875 ifcond_var_assign_bool(pVar, pMakeVar && *pMakeVar->value != '\0');876 877 return k IfCondRet_Ok;875 expr_var_assign_bool(pVar, pMakeVar && *pMakeVar->value != '\0'); 876 877 return kExprRet_Ok; 878 878 } 879 879 … … 885 885 * @param pThis The instance. 886 886 */ 887 static IFCONDRET ifcond_op_target(PIFCONDpThis)888 { 889 P IFCONDVAR pVar = &pThis->aVars[pThis->iVar];887 static EXPRRET expr_op_target(PEXPR pThis) 888 { 889 PEXPRVAR pVar = &pThis->aVars[pThis->iVar]; 890 890 struct file *pFile = NULL; 891 891 assert(pThis->iVar >= 0); … … 896 896 */ 897 897 #ifdef CONFIG_WITH_2ND_TARGET_EXPANSION 898 if ( pVar->enmType == k IfCondVar_String899 || pVar->enmType == k IfCondVar_QuotedString)898 if ( pVar->enmType == kExprVar_String 899 || pVar->enmType == kExprVar_QuotedString) 900 900 { 901 901 pFile = lookup_file(pVar->uVal.psz); … … 907 907 #endif 908 908 { 909 ifcond_var_make_simple_string(pVar);909 expr_var_make_simple_string(pVar); 910 910 pFile = lookup_file(pVar->uVal.psz); 911 911 } … … 923 923 pFile = pFile->prev; 924 924 925 ifcond_var_assign_bool(pVar, pFile != NULL && pFile->is_target);926 927 return k IfCondRet_Ok;925 expr_var_assign_bool(pVar, pFile != NULL && pFile->is_target); 926 927 return kExprRet_Ok; 928 928 } 929 929 … … 935 935 * @param pThis The instance. 936 936 */ 937 static IFCONDRET ifcond_op_pluss(PIFCONDpThis)938 { 939 P IFCONDVAR pVar = &pThis->aVars[pThis->iVar];937 static EXPRRET expr_op_pluss(PEXPR pThis) 938 { 939 PEXPRVAR pVar = &pThis->aVars[pThis->iVar]; 940 940 assert(pThis->iVar >= 0); 941 941 942 return ifcond_var_make_num(pThis, pVar);942 return expr_var_make_num(pThis, pVar); 943 943 } 944 944 … … 951 951 * @param pThis The instance. 952 952 */ 953 static IFCONDRET ifcond_op_minus(PIFCONDpThis)954 { 955 IFCONDRET rc;956 P IFCONDVAR pVar = &pThis->aVars[pThis->iVar];953 static EXPRRET expr_op_minus(PEXPR pThis) 954 { 955 EXPRRET rc; 956 PEXPRVAR pVar = &pThis->aVars[pThis->iVar]; 957 957 assert(pThis->iVar >= 0); 958 958 959 rc = ifcond_var_make_num(pThis, pVar);960 if (rc >= k IfCondRet_Ok)959 rc = expr_var_make_num(pThis, pVar); 960 if (rc >= kExprRet_Ok) 961 961 pVar->uVal.i = -pVar->uVal.i; 962 962 … … 972 972 * @param pThis The instance. 973 973 */ 974 static IFCONDRET ifcond_op_bitwise_not(PIFCONDpThis)975 { 976 IFCONDRET rc;977 P IFCONDVAR pVar = &pThis->aVars[pThis->iVar];974 static EXPRRET expr_op_bitwise_not(PEXPR pThis) 975 { 976 EXPRRET rc; 977 PEXPRVAR pVar = &pThis->aVars[pThis->iVar]; 978 978 assert(pThis->iVar >= 0); 979 979 980 rc = ifcond_var_make_num(pThis, pVar);981 if (rc >= k IfCondRet_Ok)980 rc = expr_var_make_num(pThis, pVar); 981 if (rc >= kExprRet_Ok) 982 982 pVar->uVal.i = ~pVar->uVal.i; 983 983 … … 992 992 * @param pThis The instance. 993 993 */ 994 static IFCONDRET ifcond_op_logical_not(PIFCONDpThis)995 { 996 P IFCONDVAR pVar = &pThis->aVars[pThis->iVar];994 static EXPRRET expr_op_logical_not(PEXPR pThis) 995 { 996 PEXPRVAR pVar = &pThis->aVars[pThis->iVar]; 997 997 assert(pThis->iVar >= 0); 998 998 999 ifcond_var_assign_bool(pVar, !ifcond_var_make_bool(pVar));1000 1001 return k IfCondRet_Ok;999 expr_var_assign_bool(pVar, !expr_var_make_bool(pVar)); 1000 1001 return kExprRet_Ok; 1002 1002 } 1003 1003 … … 1009 1009 * @param pThis The instance. 1010 1010 */ 1011 static IFCONDRET ifcond_op_multiply(PIFCONDpThis)1012 { 1013 IFCONDRET rc = kIfCondRet_Ok;1014 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1015 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1011 static EXPRRET expr_op_multiply(PEXPR pThis) 1012 { 1013 EXPRRET rc = kExprRet_Ok; 1014 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1015 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1016 1016 assert(pThis->iVar >= 1); 1017 1017 1018 rc = ifcond_var_make_num(pThis, pVar1);1019 if (rc >= k IfCondRet_Ok)1020 { 1021 rc = ifcond_var_make_num(pThis, pVar2);1022 if (rc >= k IfCondRet_Ok)1018 rc = expr_var_make_num(pThis, pVar1); 1019 if (rc >= kExprRet_Ok) 1020 { 1021 rc = expr_var_make_num(pThis, pVar2); 1022 if (rc >= kExprRet_Ok) 1023 1023 pVar1->uVal.i %= pVar2->uVal.i; 1024 1024 } 1025 1025 1026 ifcond_pop_and_delete_var(pThis);1026 expr_pop_and_delete_var(pThis); 1027 1027 return rc; 1028 1028 } … … 1036 1036 * @param pThis The instance. 1037 1037 */ 1038 static IFCONDRET ifcond_op_divide(PIFCONDpThis)1039 { 1040 IFCONDRET rc = kIfCondRet_Ok;1041 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1042 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1038 static EXPRRET expr_op_divide(PEXPR pThis) 1039 { 1040 EXPRRET rc = kExprRet_Ok; 1041 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1042 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1043 1043 assert(pThis->iVar >= 1); 1044 1044 1045 rc = ifcond_var_make_num(pThis, pVar1);1046 if (rc >= k IfCondRet_Ok)1047 { 1048 rc = ifcond_var_make_num(pThis, pVar2);1049 if (rc >= k IfCondRet_Ok)1045 rc = expr_var_make_num(pThis, pVar1); 1046 if (rc >= kExprRet_Ok) 1047 { 1048 rc = expr_var_make_num(pThis, pVar2); 1049 if (rc >= kExprRet_Ok) 1050 1050 pVar1->uVal.i /= pVar2->uVal.i; 1051 1051 } 1052 1052 1053 ifcond_pop_and_delete_var(pThis);1053 expr_pop_and_delete_var(pThis); 1054 1054 return rc; 1055 1055 } … … 1063 1063 * @param pThis The instance. 1064 1064 */ 1065 static IFCONDRET ifcond_op_modulus(PIFCONDpThis)1066 { 1067 IFCONDRET rc = kIfCondRet_Ok;1068 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1069 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1065 static EXPRRET expr_op_modulus(PEXPR pThis) 1066 { 1067 EXPRRET rc = kExprRet_Ok; 1068 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1069 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1070 1070 assert(pThis->iVar >= 1); 1071 1071 1072 rc = ifcond_var_make_num(pThis, pVar1);1073 if (rc >= k IfCondRet_Ok)1074 { 1075 rc = ifcond_var_make_num(pThis, pVar2);1076 if (rc >= k IfCondRet_Ok)1072 rc = expr_var_make_num(pThis, pVar1); 1073 if (rc >= kExprRet_Ok) 1074 { 1075 rc = expr_var_make_num(pThis, pVar2); 1076 if (rc >= kExprRet_Ok) 1077 1077 pVar1->uVal.i %= pVar2->uVal.i; 1078 1078 } 1079 1079 1080 ifcond_pop_and_delete_var(pThis);1080 expr_pop_and_delete_var(pThis); 1081 1081 return rc; 1082 1082 } … … 1090 1090 * @param pThis The instance. 1091 1091 */ 1092 static IFCONDRET ifcond_op_add(PIFCONDpThis)1093 { 1094 IFCONDRET rc = kIfCondRet_Ok;1095 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1096 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1092 static EXPRRET expr_op_add(PEXPR pThis) 1093 { 1094 EXPRRET rc = kExprRet_Ok; 1095 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1096 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1097 1097 assert(pThis->iVar >= 1); 1098 1098 1099 rc = ifcond_var_make_num(pThis, pVar1);1100 if (rc >= k IfCondRet_Ok)1101 { 1102 rc = ifcond_var_make_num(pThis, pVar2);1103 if (rc >= k IfCondRet_Ok)1099 rc = expr_var_make_num(pThis, pVar1); 1100 if (rc >= kExprRet_Ok) 1101 { 1102 rc = expr_var_make_num(pThis, pVar2); 1103 if (rc >= kExprRet_Ok) 1104 1104 pVar1->uVal.i += pVar2->uVal.i; 1105 1105 } 1106 1106 1107 ifcond_pop_and_delete_var(pThis);1107 expr_pop_and_delete_var(pThis); 1108 1108 return rc; 1109 1109 } … … 1116 1116 * @param pThis The instance. 1117 1117 */ 1118 static IFCONDRET ifcond_op_sub(PIFCONDpThis)1119 { 1120 IFCONDRET rc = kIfCondRet_Ok;1121 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1122 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1118 static EXPRRET expr_op_sub(PEXPR pThis) 1119 { 1120 EXPRRET rc = kExprRet_Ok; 1121 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1122 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1123 1123 assert(pThis->iVar >= 1); 1124 1124 1125 rc = ifcond_var_make_num(pThis, pVar1);1126 if (rc >= k IfCondRet_Ok)1127 { 1128 rc = ifcond_var_make_num(pThis, pVar2);1129 if (rc >= k IfCondRet_Ok)1125 rc = expr_var_make_num(pThis, pVar1); 1126 if (rc >= kExprRet_Ok) 1127 { 1128 rc = expr_var_make_num(pThis, pVar2); 1129 if (rc >= kExprRet_Ok) 1130 1130 pVar1->uVal.i -= pVar2->uVal.i; 1131 1131 } 1132 1132 1133 ifcond_pop_and_delete_var(pThis);1133 expr_pop_and_delete_var(pThis); 1134 1134 return rc; 1135 1135 } … … 1141 1141 * @param pThis The instance. 1142 1142 */ 1143 static IFCONDRET ifcond_op_shift_left(PIFCONDpThis)1144 { 1145 IFCONDRET rc = kIfCondRet_Ok;1146 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1147 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1143 static EXPRRET expr_op_shift_left(PEXPR pThis) 1144 { 1145 EXPRRET rc = kExprRet_Ok; 1146 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1147 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1148 1148 assert(pThis->iVar >= 1); 1149 1149 1150 rc = ifcond_var_make_num(pThis, pVar1);1151 if (rc >= k IfCondRet_Ok)1152 { 1153 rc = ifcond_var_make_num(pThis, pVar2);1154 if (rc >= k IfCondRet_Ok)1150 rc = expr_var_make_num(pThis, pVar1); 1151 if (rc >= kExprRet_Ok) 1152 { 1153 rc = expr_var_make_num(pThis, pVar2); 1154 if (rc >= kExprRet_Ok) 1155 1155 pVar1->uVal.i <<= pVar2->uVal.i; 1156 1156 } 1157 1157 1158 ifcond_pop_and_delete_var(pThis);1158 expr_pop_and_delete_var(pThis); 1159 1159 return rc; 1160 1160 } … … 1167 1167 * @param pThis The instance. 1168 1168 */ 1169 static IFCONDRET ifcond_op_shift_right(PIFCONDpThis)1170 { 1171 IFCONDRET rc = kIfCondRet_Ok;1172 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1173 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1169 static EXPRRET expr_op_shift_right(PEXPR pThis) 1170 { 1171 EXPRRET rc = kExprRet_Ok; 1172 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1173 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1174 1174 assert(pThis->iVar >= 1); 1175 1175 1176 rc = ifcond_var_make_num(pThis, pVar1);1177 if (rc >= k IfCondRet_Ok)1178 { 1179 rc = ifcond_var_make_num(pThis, pVar2);1180 if (rc >= k IfCondRet_Ok)1176 rc = expr_var_make_num(pThis, pVar1); 1177 if (rc >= kExprRet_Ok) 1178 { 1179 rc = expr_var_make_num(pThis, pVar2); 1180 if (rc >= kExprRet_Ok) 1181 1181 pVar1->uVal.i >>= pVar2->uVal.i; 1182 1182 } 1183 1183 1184 ifcond_pop_and_delete_var(pThis);1184 expr_pop_and_delete_var(pThis); 1185 1185 return rc; 1186 1186 } … … 1193 1193 * @param pThis The instance. 1194 1194 */ 1195 static IFCONDRET ifcond_op_less_or_equal_than(PIFCONDpThis)1196 { 1197 IFCONDRET rc = kIfCondRet_Ok;1198 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1199 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1195 static EXPRRET expr_op_less_or_equal_than(PEXPR pThis) 1196 { 1197 EXPRRET rc = kExprRet_Ok; 1198 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1199 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1200 1200 assert(pThis->iVar >= 1); 1201 1201 1202 rc = ifcond_var_unify_types(pThis, pVar1, pVar2, "<=");1203 if (rc >= k IfCondRet_Ok)1204 { 1205 if (! ifcond_var_is_string(pVar1))1206 ifcond_var_assign_bool(pVar1, pVar1->uVal.i <= pVar2->uVal.i);1202 rc = expr_var_unify_types(pThis, pVar1, pVar2, "<="); 1203 if (rc >= kExprRet_Ok) 1204 { 1205 if (!expr_var_is_string(pVar1)) 1206 expr_var_assign_bool(pVar1, pVar1->uVal.i <= pVar2->uVal.i); 1207 1207 else 1208 ifcond_var_assign_bool(pVar1, strcmp(pVar1->uVal.psz, pVar2->uVal.psz) <= 0);1209 } 1210 1211 ifcond_pop_and_delete_var(pThis);1208 expr_var_assign_bool(pVar1, strcmp(pVar1->uVal.psz, pVar2->uVal.psz) <= 0); 1209 } 1210 1211 expr_pop_and_delete_var(pThis); 1212 1212 return rc; 1213 1213 } … … 1220 1220 * @param pThis The instance. 1221 1221 */ 1222 static IFCONDRET ifcond_op_less_than(PIFCONDpThis)1223 { 1224 IFCONDRET rc = kIfCondRet_Ok;1225 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1226 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1222 static EXPRRET expr_op_less_than(PEXPR pThis) 1223 { 1224 EXPRRET rc = kExprRet_Ok; 1225 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1226 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1227 1227 assert(pThis->iVar >= 1); 1228 1228 1229 rc = ifcond_var_unify_types(pThis, pVar1, pVar2, "<");1230 if (rc >= k IfCondRet_Ok)1231 { 1232 if (! ifcond_var_is_string(pVar1))1233 ifcond_var_assign_bool(pVar1, pVar1->uVal.i < pVar2->uVal.i);1229 rc = expr_var_unify_types(pThis, pVar1, pVar2, "<"); 1230 if (rc >= kExprRet_Ok) 1231 { 1232 if (!expr_var_is_string(pVar1)) 1233 expr_var_assign_bool(pVar1, pVar1->uVal.i < pVar2->uVal.i); 1234 1234 else 1235 ifcond_var_assign_bool(pVar1, strcmp(pVar1->uVal.psz, pVar2->uVal.psz) < 0);1236 } 1237 1238 ifcond_pop_and_delete_var(pThis);1235 expr_var_assign_bool(pVar1, strcmp(pVar1->uVal.psz, pVar2->uVal.psz) < 0); 1236 } 1237 1238 expr_pop_and_delete_var(pThis); 1239 1239 return rc; 1240 1240 } … … 1247 1247 * @param pThis The instance. 1248 1248 */ 1249 static IFCONDRET ifcond_op_greater_or_equal_than(PIFCONDpThis)1250 { 1251 IFCONDRET rc = kIfCondRet_Ok;1252 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1253 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1249 static EXPRRET expr_op_greater_or_equal_than(PEXPR pThis) 1250 { 1251 EXPRRET rc = kExprRet_Ok; 1252 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1253 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1254 1254 assert(pThis->iVar >= 1); 1255 1255 1256 rc = ifcond_var_unify_types(pThis, pVar1, pVar2, ">=");1257 if (rc >= k IfCondRet_Ok)1258 { 1259 if (! ifcond_var_is_string(pVar1))1260 ifcond_var_assign_bool(pVar1, pVar1->uVal.i >= pVar2->uVal.i);1256 rc = expr_var_unify_types(pThis, pVar1, pVar2, ">="); 1257 if (rc >= kExprRet_Ok) 1258 { 1259 if (!expr_var_is_string(pVar1)) 1260 expr_var_assign_bool(pVar1, pVar1->uVal.i >= pVar2->uVal.i); 1261 1261 else 1262 ifcond_var_assign_bool(pVar1, strcmp(pVar1->uVal.psz, pVar2->uVal.psz) >= 0);1263 } 1264 1265 ifcond_pop_and_delete_var(pThis);1262 expr_var_assign_bool(pVar1, strcmp(pVar1->uVal.psz, pVar2->uVal.psz) >= 0); 1263 } 1264 1265 expr_pop_and_delete_var(pThis); 1266 1266 return rc; 1267 1267 } … … 1274 1274 * @param pThis The instance. 1275 1275 */ 1276 static IFCONDRET ifcond_op_greater_than(PIFCONDpThis)1277 { 1278 IFCONDRET rc = kIfCondRet_Ok;1279 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1280 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1276 static EXPRRET expr_op_greater_than(PEXPR pThis) 1277 { 1278 EXPRRET rc = kExprRet_Ok; 1279 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1280 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1281 1281 assert(pThis->iVar >= 1); 1282 1282 1283 rc = ifcond_var_unify_types(pThis, pVar1, pVar2, ">");1284 if (rc >= k IfCondRet_Ok)1285 { 1286 if (! ifcond_var_is_string(pVar1))1287 ifcond_var_assign_bool(pVar1, pVar1->uVal.i > pVar2->uVal.i);1283 rc = expr_var_unify_types(pThis, pVar1, pVar2, ">"); 1284 if (rc >= kExprRet_Ok) 1285 { 1286 if (!expr_var_is_string(pVar1)) 1287 expr_var_assign_bool(pVar1, pVar1->uVal.i > pVar2->uVal.i); 1288 1288 else 1289 ifcond_var_assign_bool(pVar1, strcmp(pVar1->uVal.psz, pVar2->uVal.psz) > 0);1290 } 1291 1292 ifcond_pop_and_delete_var(pThis);1289 expr_var_assign_bool(pVar1, strcmp(pVar1->uVal.psz, pVar2->uVal.psz) > 0); 1290 } 1291 1292 expr_pop_and_delete_var(pThis); 1293 1293 return rc; 1294 1294 } … … 1301 1301 * @param pThis The instance. 1302 1302 */ 1303 static IFCONDRET ifcond_op_equal(PIFCONDpThis)1304 { 1305 IFCONDRET rc = kIfCondRet_Ok;1306 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1307 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1303 static EXPRRET expr_op_equal(PEXPR pThis) 1304 { 1305 EXPRRET rc = kExprRet_Ok; 1306 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1307 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1308 1308 assert(pThis->iVar >= 1); 1309 1309 … … 1311 1311 * The same type? 1312 1312 */ 1313 if ( ifcond_var_is_string(pVar1) == ifcond_var_is_string(pVar2))1314 { 1315 if (! ifcond_var_is_string(pVar1))1313 if (expr_var_is_string(pVar1) == expr_var_is_string(pVar2)) 1314 { 1315 if (!expr_var_is_string(pVar1)) 1316 1316 /* numbers are simple */ 1317 ifcond_var_assign_bool(pVar1, pVar1->uVal.i == pVar2->uVal.i);1317 expr_var_assign_bool(pVar1, pVar1->uVal.i == pVar2->uVal.i); 1318 1318 else 1319 1319 { 1320 1320 /* try a normal string compare. */ 1321 ifcond_var_make_simple_string(pVar1);1322 ifcond_var_make_simple_string(pVar2);1321 expr_var_make_simple_string(pVar1); 1322 expr_var_make_simple_string(pVar2); 1323 1323 if (!strcmp(pVar1->uVal.psz, pVar2->uVal.psz)) 1324 ifcond_var_assign_bool(pVar1, 1);1324 expr_var_assign_bool(pVar1, 1); 1325 1325 /* try convert and compare as number instead. */ 1326 else if ( ifcond_var_try_make_num(pVar1) >= kIfCondRet_Ok1327 && ifcond_var_try_make_num(pVar2) >= kIfCondRet_Ok)1328 ifcond_var_assign_bool(pVar1, pVar1->uVal.i == pVar2->uVal.i);1326 else if ( expr_var_try_make_num(pVar1) >= kExprRet_Ok 1327 && expr_var_try_make_num(pVar2) >= kExprRet_Ok) 1328 expr_var_assign_bool(pVar1, pVar1->uVal.i == pVar2->uVal.i); 1329 1329 /* ok, they really aren't equal. */ 1330 1330 else 1331 ifcond_var_assign_bool(pVar1, 0);1331 expr_var_assign_bool(pVar1, 0); 1332 1332 } 1333 1333 } … … 1340 1340 * numerically. This one is a bit questionable, so we don't try this. 1341 1341 */ 1342 if ( ifcond_var_try_make_num(pVar1) >= kIfCondRet_Ok1343 && ifcond_var_try_make_num(pVar2) >= kIfCondRet_Ok)1344 ifcond_var_assign_bool(pVar1, pVar1->uVal.i == pVar2->uVal.i);1342 if ( expr_var_try_make_num(pVar1) >= kExprRet_Ok 1343 && expr_var_try_make_num(pVar2) >= kExprRet_Ok) 1344 expr_var_assign_bool(pVar1, pVar1->uVal.i == pVar2->uVal.i); 1345 1345 else 1346 1346 { 1347 ifcond_error(pThis, "Cannot compare strings and numbers");1348 rc = k IfCondRet_Error;1347 expr_error(pThis, "Cannot compare strings and numbers"); 1348 rc = kExprRet_Error; 1349 1349 } 1350 1350 } 1351 1351 1352 ifcond_pop_and_delete_var(pThis);1353 return k IfCondRet_Ok;1352 expr_pop_and_delete_var(pThis); 1353 return kExprRet_Ok; 1354 1354 } 1355 1355 … … 1361 1361 * @param pThis The instance. 1362 1362 */ 1363 static IFCONDRET ifcond_op_not_equal(PIFCONDpThis)1364 { 1365 IFCONDRET rc = ifcond_op_equal(pThis);1366 if (rc >= k IfCondRet_Ok)1367 rc = ifcond_op_logical_not(pThis);1363 static EXPRRET expr_op_not_equal(PEXPR pThis) 1364 { 1365 EXPRRET rc = expr_op_equal(pThis); 1366 if (rc >= kExprRet_Ok) 1367 rc = expr_op_logical_not(pThis); 1368 1368 return rc; 1369 1369 } … … 1376 1376 * @param pThis The instance. 1377 1377 */ 1378 static IFCONDRET ifcond_op_bitwise_and(PIFCONDpThis)1379 { 1380 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1381 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1382 IFCONDRET rc;1378 static EXPRRET expr_op_bitwise_and(PEXPR pThis) 1379 { 1380 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1381 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1382 EXPRRET rc; 1383 1383 assert(pThis->iVar >= 1); 1384 1384 1385 rc = ifcond_var_make_num(pThis, pVar1);1386 if (rc >= k IfCondRet_Ok)1387 { 1388 rc = ifcond_var_make_num(pThis, pVar2);1389 if (rc >= k IfCondRet_Ok)1385 rc = expr_var_make_num(pThis, pVar1); 1386 if (rc >= kExprRet_Ok) 1387 { 1388 rc = expr_var_make_num(pThis, pVar2); 1389 if (rc >= kExprRet_Ok) 1390 1390 pVar1->uVal.i &= pVar2->uVal.i; 1391 1391 } 1392 1392 1393 ifcond_pop_and_delete_var(pThis);1394 return k IfCondRet_Ok;1393 expr_pop_and_delete_var(pThis); 1394 return kExprRet_Ok; 1395 1395 } 1396 1396 … … 1402 1402 * @param pThis The instance. 1403 1403 */ 1404 static IFCONDRET ifcond_op_bitwise_xor(PIFCONDpThis)1405 { 1406 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1407 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1408 IFCONDRET rc;1404 static EXPRRET expr_op_bitwise_xor(PEXPR pThis) 1405 { 1406 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1407 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1408 EXPRRET rc; 1409 1409 assert(pThis->iVar >= 1); 1410 1410 1411 rc = ifcond_var_make_num(pThis, pVar1);1412 if (rc >= k IfCondRet_Ok)1413 { 1414 rc = ifcond_var_make_num(pThis, pVar2);1415 if (rc >= k IfCondRet_Ok)1411 rc = expr_var_make_num(pThis, pVar1); 1412 if (rc >= kExprRet_Ok) 1413 { 1414 rc = expr_var_make_num(pThis, pVar2); 1415 if (rc >= kExprRet_Ok) 1416 1416 pVar1->uVal.i ^= pVar2->uVal.i; 1417 1417 } 1418 1418 1419 ifcond_pop_and_delete_var(pThis);1420 return k IfCondRet_Ok;1419 expr_pop_and_delete_var(pThis); 1420 return kExprRet_Ok; 1421 1421 } 1422 1422 … … 1428 1428 * @param pThis The instance. 1429 1429 */ 1430 static IFCONDRET ifcond_op_bitwise_or(PIFCONDpThis)1431 { 1432 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1433 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1434 IFCONDRET rc;1430 static EXPRRET expr_op_bitwise_or(PEXPR pThis) 1431 { 1432 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1433 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1434 EXPRRET rc; 1435 1435 assert(pThis->iVar >= 1); 1436 1436 1437 rc = ifcond_var_make_num(pThis, pVar1);1438 if (rc >= k IfCondRet_Ok)1439 { 1440 rc = ifcond_var_make_num(pThis, pVar2);1441 if (rc >= k IfCondRet_Ok)1437 rc = expr_var_make_num(pThis, pVar1); 1438 if (rc >= kExprRet_Ok) 1439 { 1440 rc = expr_var_make_num(pThis, pVar2); 1441 if (rc >= kExprRet_Ok) 1442 1442 pVar1->uVal.i |= pVar2->uVal.i; 1443 1443 } 1444 1444 1445 ifcond_pop_and_delete_var(pThis);1446 return k IfCondRet_Ok;1445 expr_pop_and_delete_var(pThis); 1446 return kExprRet_Ok; 1447 1447 } 1448 1448 … … 1454 1454 * @param pThis The instance. 1455 1455 */ 1456 static IFCONDRET ifcond_op_logical_and(PIFCONDpThis)1457 { 1458 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1459 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1456 static EXPRRET expr_op_logical_and(PEXPR pThis) 1457 { 1458 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1459 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1460 1460 assert(pThis->iVar >= 1); 1461 1461 1462 if ( ifcond_var_make_bool(pVar1)1463 && ifcond_var_make_bool(pVar2))1464 ifcond_var_assign_bool(pVar1, 1);1462 if ( expr_var_make_bool(pVar1) 1463 && expr_var_make_bool(pVar2)) 1464 expr_var_assign_bool(pVar1, 1); 1465 1465 else 1466 ifcond_var_assign_bool(pVar1, 0);1467 1468 ifcond_pop_and_delete_var(pThis);1469 return k IfCondRet_Ok;1466 expr_var_assign_bool(pVar1, 0); 1467 1468 expr_pop_and_delete_var(pThis); 1469 return kExprRet_Ok; 1470 1470 } 1471 1471 … … 1477 1477 * @param pThis The instance. 1478 1478 */ 1479 static IFCONDRET ifcond_op_logical_or(PIFCONDpThis)1480 { 1481 P IFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1];1482 P IFCONDVAR pVar2 = &pThis->aVars[pThis->iVar];1479 static EXPRRET expr_op_logical_or(PEXPR pThis) 1480 { 1481 PEXPRVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 1482 PEXPRVAR pVar2 = &pThis->aVars[pThis->iVar]; 1483 1483 assert(pThis->iVar >= 1); 1484 1484 1485 if ( ifcond_var_make_bool(pVar1)1486 || ifcond_var_make_bool(pVar2))1487 ifcond_var_assign_bool(pVar1, 1);1485 if ( expr_var_make_bool(pVar1) 1486 || expr_var_make_bool(pVar2)) 1487 expr_var_assign_bool(pVar1, 1); 1488 1488 else 1489 ifcond_var_assign_bool(pVar1, 0);1490 1491 ifcond_pop_and_delete_var(pThis);1492 return k IfCondRet_Ok;1489 expr_var_assign_bool(pVar1, 0); 1490 1491 expr_pop_and_delete_var(pThis); 1492 return kExprRet_Ok; 1493 1493 } 1494 1494 … … 1500 1500 * @param pThis The instance. 1501 1501 */ 1502 static IFCONDRET ifcond_op_left_parenthesis(PIFCONDpThis)1502 static EXPRRET expr_op_left_parenthesis(PEXPR pThis) 1503 1503 { 1504 1504 /* … … 1506 1506 * eat it. If not found there is an inbalance. 1507 1507 */ 1508 IFCONDRET rc = ifcond_get_binary_or_eoe_or_rparen(pThis);1509 if ( rc == k IfCondRet_Operator1508 EXPRRET rc = expr_get_binary_or_eoe_or_rparen(pThis); 1509 if ( rc == kExprRet_Operator 1510 1510 && pThis->apOps[pThis->iOp]->szOp[0] == ')') 1511 1511 { 1512 1512 /* pop it and get another one which we can leave pending. */ 1513 1513 pThis->iOp--; 1514 rc = ifcond_get_binary_or_eoe_or_rparen(pThis);1515 if (rc >= k IfCondRet_Ok)1516 ifcond_unget_op(pThis);1514 rc = expr_get_binary_or_eoe_or_rparen(pThis); 1515 if (rc >= kExprRet_Ok) 1516 expr_unget_op(pThis); 1517 1517 } 1518 1518 else 1519 1519 { 1520 ifcond_error(pThis, "Missing ')'");1521 rc = k IfCondRet_Error;1520 expr_error(pThis, "Missing ')'"); 1521 rc = kExprRet_Error; 1522 1522 } 1523 1523 … … 1532 1532 * @param pThis The instance. 1533 1533 */ 1534 static IFCONDRET ifcond_op_right_parenthesis(PIFCONDpThis)1535 { 1536 return k IfCondRet_Ok;1534 static EXPRRET expr_op_right_parenthesis(PEXPR pThis) 1535 { 1536 return kExprRet_Ok; 1537 1537 } 1538 1538 … … 1548 1548 * means that || must come before |, or else | will match all. 1549 1549 */ 1550 static const IFCONDOP g_aIfCondOps[] =1551 { 1552 #define IFCOND_OP(szOp, iPrecedence, cArgs, pfn) { szOp, sizeof(szOp) - 1, '\0', iPrecedence, cArgs, pfn }1550 static const EXPROP g_aExprOps[] = 1551 { 1552 #define EXPR_OP(szOp, iPrecedence, cArgs, pfn) { szOp, sizeof(szOp) - 1, '\0', iPrecedence, cArgs, pfn } 1553 1553 /* Name, iPrecedence, cArgs, pfn */ 1554 IFCOND_OP("defined", 90, 1, ifcond_op_defined),1555 IFCOND_OP("target", 90, 1, ifcond_op_target),1556 IFCOND_OP("+", 80, 1, ifcond_op_pluss),1557 IFCOND_OP("-", 80, 1, ifcond_op_minus),1558 IFCOND_OP("~", 80, 1, ifcond_op_bitwise_not),1559 IFCOND_OP("*", 75, 2, ifcond_op_multiply),1560 IFCOND_OP("/", 75, 2, ifcond_op_divide),1561 IFCOND_OP("%", 75, 2, ifcond_op_modulus),1562 IFCOND_OP("+", 70, 2, ifcond_op_add),1563 IFCOND_OP("-", 70, 2, ifcond_op_sub),1564 IFCOND_OP("<<", 65, 2, ifcond_op_shift_left),1565 IFCOND_OP(">>", 65, 2, ifcond_op_shift_right),1566 IFCOND_OP("<=", 60, 2, ifcond_op_less_or_equal_than),1567 IFCOND_OP("<", 60, 2, ifcond_op_less_than),1568 IFCOND_OP(">=", 60, 2, ifcond_op_greater_or_equal_than),1569 IFCOND_OP(">", 60, 2, ifcond_op_greater_than),1570 IFCOND_OP("==", 55, 2, ifcond_op_equal),1571 IFCOND_OP("!=", 55, 2, ifcond_op_not_equal),1572 IFCOND_OP("!", 80, 1, ifcond_op_logical_not),1573 IFCOND_OP("^", 45, 2, ifcond_op_bitwise_xor),1574 IFCOND_OP("&&", 35, 2, ifcond_op_logical_and),1575 IFCOND_OP("&", 50, 2, ifcond_op_bitwise_and),1576 IFCOND_OP("||", 30, 2, ifcond_op_logical_or),1577 IFCOND_OP("|", 40, 2, ifcond_op_bitwise_or),1578 { "(", 1, ')', 10, 1, ifcond_op_left_parenthesis },1579 { ")", 1, '(', 10, 0, ifcond_op_right_parenthesis },1580 /* { "?", 1, ':', 5, 2, ifcond_op_question },1581 { ":", 1, '?', 5, 2, ifcond_op_colon }, -- too weird for now. */1582 #undef IFCOND_OP1554 EXPR_OP("defined", 90, 1, expr_op_defined), 1555 EXPR_OP("target", 90, 1, expr_op_target), 1556 EXPR_OP("+", 80, 1, expr_op_pluss), 1557 EXPR_OP("-", 80, 1, expr_op_minus), 1558 EXPR_OP("~", 80, 1, expr_op_bitwise_not), 1559 EXPR_OP("*", 75, 2, expr_op_multiply), 1560 EXPR_OP("/", 75, 2, expr_op_divide), 1561 EXPR_OP("%", 75, 2, expr_op_modulus), 1562 EXPR_OP("+", 70, 2, expr_op_add), 1563 EXPR_OP("-", 70, 2, expr_op_sub), 1564 EXPR_OP("<<", 65, 2, expr_op_shift_left), 1565 EXPR_OP(">>", 65, 2, expr_op_shift_right), 1566 EXPR_OP("<=", 60, 2, expr_op_less_or_equal_than), 1567 EXPR_OP("<", 60, 2, expr_op_less_than), 1568 EXPR_OP(">=", 60, 2, expr_op_greater_or_equal_than), 1569 EXPR_OP(">", 60, 2, expr_op_greater_than), 1570 EXPR_OP("==", 55, 2, expr_op_equal), 1571 EXPR_OP("!=", 55, 2, expr_op_not_equal), 1572 EXPR_OP("!", 80, 1, expr_op_logical_not), 1573 EXPR_OP("^", 45, 2, expr_op_bitwise_xor), 1574 EXPR_OP("&&", 35, 2, expr_op_logical_and), 1575 EXPR_OP("&", 50, 2, expr_op_bitwise_and), 1576 EXPR_OP("||", 30, 2, expr_op_logical_or), 1577 EXPR_OP("|", 40, 2, expr_op_bitwise_or), 1578 { "(", 1, ')', 10, 1, expr_op_left_parenthesis }, 1579 { ")", 1, '(', 10, 0, expr_op_right_parenthesis }, 1580 /* { "?", 1, ':', 5, 2, expr_op_question }, 1581 { ":", 1, '?', 5, 2, expr_op_colon }, -- too weird for now. */ 1582 #undef EXPR_OP 1583 1583 }; 1584 1584 1585 1585 /** Dummy end of expression fake. */ 1586 static const IFCONDOP g_IfCondEndOfExpOp =1586 static const EXPROP g_ExprEndOfExpOp = 1587 1587 { 1588 1588 "", 0, '\0', 0, 0, NULL … … 1593 1593 * Initializes the opcode character map if necessary. 1594 1594 */ 1595 static void ifcond_map_init(void)1595 static void expr_map_init(void) 1596 1596 { 1597 1597 int i; 1598 if (g_f IfCondInitializedMap)1598 if (g_fExprInitializedMap) 1599 1599 return; 1600 1600 … … 1603 1603 */ 1604 1604 memset(&g_auchOpStartCharMap, 0, sizeof(g_auchOpStartCharMap)); 1605 for (i = 0; i < sizeof(g_a IfCondOps) / sizeof(g_aIfCondOps[0]); i++)1606 { 1607 unsigned int ch = (unsigned int)g_a IfCondOps[i].szOp[0];1605 for (i = 0; i < sizeof(g_aExprOps) / sizeof(g_aExprOps[0]); i++) 1606 { 1607 unsigned int ch = (unsigned int)g_aExprOps[i].szOp[0]; 1608 1608 if (!g_auchOpStartCharMap[ch]) 1609 1609 g_auchOpStartCharMap[ch] = (i << 1) | 1; 1610 1610 } 1611 1611 1612 g_f IfCondInitializedMap = 1;1612 g_fExprInitializedMap = 1; 1613 1613 } 1614 1614 … … 1625 1625 * @param ch The character. 1626 1626 */ 1627 static unsigned char ifcond_map_get(char ch)1627 static unsigned char expr_map_get(char ch) 1628 1628 { 1629 1629 return g_auchOpStartCharMap[(unsigned int)ch]; … … 1636 1636 * @returns Pointer to the matching operator. NULL if not found. 1637 1637 * @param psz Pointer to what can be an operator. 1638 * @param uchVal The ifcond_map_get value.1638 * @param uchVal The expr_map_get value. 1639 1639 * @param fUnary Whether it must be an unary operator or not. 1640 1640 */ 1641 static PC IFCONDOP ifcond_lookup_op(char const *psz, unsigned char uchVal, int fUnary)1641 static PCEXPROP expr_lookup_op(char const *psz, unsigned char uchVal, int fUnary) 1642 1642 { 1643 1643 char ch = *psz; 1644 1644 int i; 1645 1645 1646 for (i = uchVal >> 1; i < sizeof(g_a IfCondOps) / sizeof(g_aIfCondOps[0]); i++)1646 for (i = uchVal >> 1; i < sizeof(g_aExprOps) / sizeof(g_aExprOps[0]); i++) 1647 1647 { 1648 1648 /* compare the string... */ 1649 switch (g_a IfCondOps[i].cchOp)1649 switch (g_aExprOps[i].cchOp) 1650 1650 { 1651 1651 case 1: 1652 if (g_a IfCondOps[i].szOp[0] != ch)1652 if (g_aExprOps[i].szOp[0] != ch) 1653 1653 continue; 1654 1654 break; 1655 1655 case 2: 1656 if ( g_a IfCondOps[i].szOp[0] != ch1657 || g_a IfCondOps[i].szOp[1] != psz[1])1656 if ( g_aExprOps[i].szOp[0] != ch 1657 || g_aExprOps[i].szOp[1] != psz[1]) 1658 1658 continue; 1659 1659 break; 1660 1660 default: 1661 if ( g_a IfCondOps[i].szOp[0] != ch1662 || strncmp(&g_a IfCondOps[i].szOp[1], psz + 1, g_aIfCondOps[i].cchOp - 1))1661 if ( g_aExprOps[i].szOp[0] != ch 1662 || strncmp(&g_aExprOps[i].szOp[1], psz + 1, g_aExprOps[i].cchOp - 1)) 1663 1663 continue; 1664 1664 break; … … 1666 1666 1667 1667 /* ... and the operator type. */ 1668 if (fUnary == (g_a IfCondOps[i].cArgs == 1))1668 if (fUnary == (g_aExprOps[i].cArgs == 1)) 1669 1669 { 1670 1670 /* got a match! */ 1671 return &g_a IfCondOps[i];1671 return &g_aExprOps[i]; 1672 1672 } 1673 1673 } … … 1684 1684 * @param pThis The evaluator instance. 1685 1685 */ 1686 static void ifcond_unget_op(PIFCONDpThis)1686 static void expr_unget_op(PEXPR pThis) 1687 1687 { 1688 1688 assert(pThis->pPending == NULL); … … 1704 1704 * 1705 1705 * @returns status code. Will grumble on failure. 1706 * @retval k IfCondRet_EndOfExpr if we encountered the end of the expression.1707 * @retval k IfCondRet_Operator if we encountered a binary operator or right1706 * @retval kExprRet_EndOfExpr if we encountered the end of the expression. 1707 * @retval kExprRet_Operator if we encountered a binary operator or right 1708 1708 * parenthesis. It's on the operator stack. 1709 1709 * 1710 1710 * @param pThis The evaluator instance. 1711 1711 */ 1712 static IFCONDRET ifcond_get_binary_or_eoe_or_rparen(PIFCONDpThis)1712 static EXPRRET expr_get_binary_or_eoe_or_rparen(PEXPR pThis) 1713 1713 { 1714 1714 /* 1715 1715 * See if there is anything pending first. 1716 1716 */ 1717 PC IFCONDOP pOp = pThis->pPending;1717 PCEXPROP pOp = pThis->pPending; 1718 1718 if (pOp) 1719 1719 pThis->pPending = NULL; … … 1731 1731 if (*psz) 1732 1732 { 1733 unsigned char uchVal = ifcond_map_get(*psz);1733 unsigned char uchVal = expr_map_get(*psz); 1734 1734 if (uchVal) 1735 pOp = ifcond_lookup_op(psz, uchVal, 0 /* fUnary */);1735 pOp = expr_lookup_op(psz, uchVal, 0 /* fUnary */); 1736 1736 if (!pOp) 1737 1737 { 1738 ifcond_error(pThis, "Expected binary operator, found \"%.42s\"...", psz);1739 return k IfCondRet_Error;1738 expr_error(pThis, "Expected binary operator, found \"%.42s\"...", psz); 1739 return kExprRet_Error; 1740 1740 } 1741 1741 psz += pOp->cchOp; 1742 1742 } 1743 1743 else 1744 pOp = &g_ IfCondEndOfExpOp;1744 pOp = &g_ExprEndOfExpOp; 1745 1745 pThis->psz = psz; 1746 1746 } … … 1749 1749 * Push it. 1750 1750 */ 1751 if (pThis->iOp >= IFCOND_MAX_OPERATORS - 1)1752 { 1753 ifcond_error(pThis, "Operator stack overflow");1754 return k IfCondRet_Error;1751 if (pThis->iOp >= EXPR_MAX_OPERATORS - 1) 1752 { 1753 expr_error(pThis, "Operator stack overflow"); 1754 return kExprRet_Error; 1755 1755 } 1756 1756 pThis->apOps[++pThis->iOp] = pOp; 1757 1757 1758 1758 return pOp->iPrecedence 1759 ? k IfCondRet_Operator1760 : k IfCondRet_EndOfExpr;1759 ? kExprRet_Operator 1760 : kExprRet_EndOfExpr; 1761 1761 } 1762 1762 … … 1773 1773 * 1774 1774 * @returns status code. On failure we'll be done bitching already. 1775 * @retval k IfCondRet_Operator if we encountered an unary operator.1775 * @retval kExprRet_Operator if we encountered an unary operator. 1776 1776 * It's on the operator stack. 1777 * @retval k IfCondRet_Operand if we encountered an operand operator.1777 * @retval kExprRet_Operand if we encountered an operand operator. 1778 1778 * It's on the operand stack. 1779 1779 * 1780 1780 * @param This The evaluator instance. 1781 1781 */ 1782 static IFCONDRET ifcond_get_unary_or_operand(PIFCONDpThis)1783 { 1784 IFCONDRET rc;1782 static EXPRRET expr_get_unary_or_operand(PEXPR pThis) 1783 { 1784 EXPRRET rc; 1785 1785 unsigned char uchVal; 1786 PC IFCONDOP pOp;1786 PCEXPROP pOp; 1787 1787 char const *psz = pThis->psz; 1788 1788 … … 1794 1794 if (!*psz) 1795 1795 { 1796 ifcond_error(pThis, "Unexpected end of expression");1797 return k IfCondRet_Error;1796 expr_error(pThis, "Unexpected end of expression"); 1797 return kExprRet_Error; 1798 1798 } 1799 1799 … … 1802 1802 */ 1803 1803 pOp = NULL; 1804 uchVal = ifcond_map_get(*psz);1804 uchVal = expr_map_get(*psz); 1805 1805 if (uchVal) 1806 pOp = ifcond_lookup_op(psz, uchVal, 1 /* fUnary */);1806 pOp = expr_lookup_op(psz, uchVal, 1 /* fUnary */); 1807 1807 if (pOp) 1808 1808 { … … 1810 1810 * Push the operator onto the stack. 1811 1811 */ 1812 if (pThis->iVar < IFCOND_MAX_OPERANDS - 1)1812 if (pThis->iVar < EXPR_MAX_OPERANDS - 1) 1813 1813 { 1814 1814 pThis->apOps[++pThis->iOp] = pOp; 1815 rc = k IfCondRet_Operator;1815 rc = kExprRet_Operator; 1816 1816 } 1817 1817 else 1818 1818 { 1819 ifcond_error(pThis, "Operator stack overflow");1820 rc = k IfCondRet_Error;1819 expr_error(pThis, "Operator stack overflow"); 1820 rc = kExprRet_Error; 1821 1821 } 1822 1822 psz += pOp->cchOp; 1823 1823 } 1824 else if (pThis->iVar < IFCOND_MAX_OPERANDS - 1)1824 else if (pThis->iVar < EXPR_MAX_OPERANDS - 1) 1825 1825 { 1826 1826 /* … … 1830 1830 const char *pszStart = psz; 1831 1831 1832 rc = k IfCondRet_Ok;1832 rc = kExprRet_Ok; 1833 1833 if (*psz == '"') 1834 1834 { … … 1836 1836 while (*psz && *psz != '"') 1837 1837 psz++; 1838 ifcond_var_init_substring(&pThis->aVars[++pThis->iVar], pszStart, psz - pszStart, kIfCondVar_QuotedString);1838 expr_var_init_substring(&pThis->aVars[++pThis->iVar], pszStart, psz - pszStart, kExprVar_QuotedString); 1839 1839 } 1840 1840 else if (*psz == '\'') … … 1843 1843 while (*psz && *psz != '\'') 1844 1844 psz++; 1845 ifcond_var_init_substring(&pThis->aVars[++pThis->iVar], pszStart, psz - pszStart, kIfCondVar_QuotedSimpleString);1845 expr_var_init_substring(&pThis->aVars[++pThis->iVar], pszStart, psz - pszStart, kExprVar_QuotedSimpleString); 1846 1846 } 1847 1847 else … … 1862 1862 if (iPar > sizeof(achPars) / sizeof(achPars[0])) 1863 1863 { 1864 ifcond_error(pThis, "Too deep nesting of variable expansions");1865 rc = k IfCondRet_Error;1864 expr_error(pThis, "Too deep nesting of variable expansions"); 1865 rc = kExprRet_Error; 1866 1866 break; 1867 1867 } … … 1875 1875 else if (!chEndPar) 1876 1876 { 1877 /** @todo combine isspace and ifcond_map_get! */1878 unsigned chVal = ifcond_map_get(ch);1877 /** @todo combine isspace and expr_map_get! */ 1878 unsigned chVal = expr_map_get(ch); 1879 1879 if (chVal) 1880 1880 { 1881 PC IFCONDOP pOp = ifcond_lookup_op(psz, uchVal, 0 /* fUnary */);1881 PCEXPROP pOp = expr_lookup_op(psz, uchVal, 0 /* fUnary */); 1882 1882 if (pOp) 1883 1883 break; … … 1891 1891 } 1892 1892 1893 if (rc == k IfCondRet_Ok)1894 ifcond_var_init_substring(&pThis->aVars[++pThis->iVar], pszStart, psz - pszStart, kIfCondVar_String);1893 if (rc == kExprRet_Ok) 1894 expr_var_init_substring(&pThis->aVars[++pThis->iVar], pszStart, psz - pszStart, kExprVar_String); 1895 1895 } 1896 1896 } 1897 1897 else 1898 1898 { 1899 ifcond_error(pThis, "Operand stack overflow");1900 rc = k IfCondRet_Error;1899 expr_error(pThis, "Operand stack overflow"); 1900 rc = kExprRet_Error; 1901 1901 } 1902 1902 pThis->psz = psz; … … 1913 1913 * @param pThis The instance. 1914 1914 */ 1915 static IFCONDRET ifcond_eval(PIFCONDpThis)1916 { 1917 IFCONDRET rc;1918 PC IFCONDOP pOp;1915 static EXPRRET expr_eval(PEXPR pThis) 1916 { 1917 EXPRRET rc; 1918 PCEXPROP pOp; 1919 1919 1920 1920 /* … … 1926 1926 * Eat unary operators until we hit an operand. 1927 1927 */ 1928 do rc = ifcond_get_unary_or_operand(pThis);1929 while (rc == k IfCondRet_Operator);1930 if (rc < k IfCondRet_Error)1928 do rc = expr_get_unary_or_operand(pThis); 1929 while (rc == kExprRet_Operator); 1930 if (rc < kExprRet_Error) 1931 1931 break; 1932 1932 … … 1934 1934 * Look for a binary operator, right parenthesis or end of expression. 1935 1935 */ 1936 rc = ifcond_get_binary_or_eoe_or_rparen(pThis);1937 if (rc < k IfCondRet_Error)1936 rc = expr_get_binary_or_eoe_or_rparen(pThis); 1937 if (rc < kExprRet_Error) 1938 1938 break; 1939 ifcond_unget_op(pThis);1939 expr_unget_op(pThis); 1940 1940 1941 1941 /* … … 1950 1950 pOp = pThis->apOps[pThis->iOp--]; 1951 1951 rc = pOp->pfn(pThis); 1952 if (rc < k IfCondRet_Error)1952 if (rc < kExprRet_Error) 1953 1953 break; 1954 1954 } 1955 if (rc < k IfCondRet_Error)1955 if (rc < kExprRet_Error) 1956 1956 break; 1957 1957 … … 1960 1960 * There should be no right parenthesis here. 1961 1961 */ 1962 rc = ifcond_get_binary_or_eoe_or_rparen(pThis);1963 if (rc < k IfCondRet_Error)1962 rc = expr_get_binary_or_eoe_or_rparen(pThis); 1963 if (rc < kExprRet_Error) 1964 1964 break; 1965 1965 pOp = pThis->apOps[pThis->iOp]; … … 1968 1968 if (!pOp->cArgs) 1969 1969 { 1970 ifcond_error(pThis, "Unexpected \"%s\"", pOp->szOp);1971 rc = k IfCondRet_Error;1970 expr_error(pThis, "Unexpected \"%s\"", pOp->szOp); 1971 rc = kExprRet_Error; 1972 1972 break; 1973 1973 } … … 1983 1983 * @param pThis The instance to destroy. 1984 1984 */ 1985 static void ifcond_destroy(PIFCONDpThis)1985 static void expr_destroy(PEXPR pThis) 1986 1986 { 1987 1987 while (pThis->iVar >= 0) 1988 1988 { 1989 ifcond_var_delete(pThis->aVars);1989 expr_var_delete(pThis->aVars); 1990 1990 pThis->iVar--; 1991 1991 } … … 2000 2000 * 2001 2001 * @param pszExpr What to parse. 2002 * This must stick around until ifcond_destroy.2003 */ 2004 static P IFCOND ifcond_create(char const *pszExpr)2005 { 2006 P IFCOND pThis = (PIFCOND)xmalloc(sizeof(*pThis));2002 * This must stick around until expr_destroy. 2003 */ 2004 static PEXPR expr_create(char const *pszExpr) 2005 { 2006 PEXPR pThis = (PEXPR)xmalloc(sizeof(*pThis)); 2007 2007 pThis->pszExpr = pszExpr; 2008 2008 pThis->psz = pszExpr; … … 2012 2012 pThis->iOp = -1; 2013 2013 2014 ifcond_map_init();2014 expr_map_init(); 2015 2015 return pThis; 2016 2016 } … … 2028 2028 * @param flocp The file location, used for errors. 2029 2029 */ 2030 int ifcond(char *line, const struct floc *flocp)2030 int expr_eval_if_conditionals(char *line, const struct floc *flocp) 2031 2031 { 2032 2032 /* … … 2035 2035 */ 2036 2036 int rc = -1; 2037 P IFCOND pIfCond = ifcond_create(line);2038 p IfCond->pFileLoc = flocp;2039 if ( ifcond_eval(pIfCond) >= kIfCondRet_Ok)2037 PEXPR pExpr = expr_create(line); 2038 pExpr->pFileLoc = flocp; 2039 if (expr_eval(pExpr) >= kExprRet_Ok) 2040 2040 { 2041 2041 /* … … 2043 2043 * set our return value accordingly. 2044 2044 */ 2045 if ( ifcond_var_make_bool(&pIfCond->aVars[0]))2045 if (expr_var_make_bool(&pExpr->aVars[0])) 2046 2046 rc = 0; 2047 2047 else 2048 2048 rc = 1; 2049 2049 } 2050 ifcond_destroy(pIfCond);2050 expr_destroy(pExpr); 2051 2051 2052 2052 return rc; … … 2054 2054 2055 2055 2056 /** 2057 * Evaluates the given expression and returns the result as a string. 2058 * 2059 * @returns variable buffer position. 2060 * 2061 * @param o The current variable buffer position. 2062 * @param expr The expression. 2063 */ 2064 char *expr_eval_to_string(char *o, char *expr) 2065 { 2066 /* 2067 * Instantiate the expression evaluator and let 2068 * it have a go at it. 2069 */ 2070 PEXPR pExpr = expr_create(expr); 2071 if (expr_eval(pExpr) >= kExprRet_Ok) 2072 { 2073 /* 2074 * Convert the result (on top of the stack) to a string 2075 * and copy it out the variable buffer. 2076 */ 2077 PEXPRVAR pVar = &pExpr->aVars[0]; 2078 expr_var_make_simple_string(pVar); 2079 o = variable_buffer_output(o, pVar->uVal.psz, strlen(pVar->uVal.psz)); 2080 } 2081 expr_destroy(pExpr); 2082 2083 return o; 2084 } 2085 2086 2056 2087 #endif /* CONFIG_WITH_IF_CONDITIONALS */ 2057 2088 -
trunk/src/kmk/make.h
r1719 r1724 729 729 730 730 #ifdef CONFIG_WITH_IF_CONDITIONALS 731 extern int ifcond(char *line, const struct floc *flocp); 732 #endif 733 731 extern int expr_eval_if_conditionals(char *line, const struct floc *flocp); 732 extern char *expr_eval_to_string(char *o, char *expr); 733 #endif 734 -
trunk/src/kmk/read.c
r1719 r1724 452 452 free (stream_buf); 453 453 } 454 #endif 454 #endif 455 455 free (ebuf.bufstart); 456 456 alloca (0); … … 2004 2004 { 2005 2005 char *cmdname; 2006 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, 2006 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, 2007 2007 #ifdef CONFIG_WITH_SET_CONDITIONALS 2008 c_if1of, c_ifn1of, 2008 c_if1of, c_ifn1of, 2009 2009 #endif 2010 2010 #ifdef CONFIG_WITH_IF_CONDITIONALS 2011 2011 c_ifcond, 2012 2012 #endif 2013 c_else, c_endif 2013 c_else, c_endif 2014 2014 } cmdtype; 2015 2015 unsigned int i; … … 2031 2031 #ifdef CONFIG_WITH_IF_CONDITIONALS 2032 2032 else chkword ("if", c_ifcond) 2033 #endif 2033 #endif 2034 2034 else chkword ("else", c_else) 2035 2035 else chkword ("endif", c_endif) … … 2173 2173 else if (cmdtype == c_ifcond) 2174 2174 { 2175 int rval = ifcond(line, flocp);2175 int rval = expr_eval_if_conditionals (line, flocp); 2176 2176 if (rval == -1) 2177 2177 return rval;
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器