- Timestamp:
- May 8, 2012 12:02:13 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/VBoxCPP.cpp
r41195 r41202 75 75 { 76 76 kVBCppMode_Invalid = 0, 77 /* kVBCppMode_Full,*/ 77 kVBCppMode_Standard, 78 78 kVBCppMode_Selective, 79 79 kVBCppMode_SelectiveD, … … 210 210 211 211 /** 212 * The action to take with \#include. 213 */ 214 typedef enum VBCPPINCLUDEACTION 215 { 216 kVBCppIncludeAction_Invalid = 0, 217 kVBCppIncludeAction_Include, 218 kVBCppIncludeAction_PassThru, 219 kVBCppIncludeAction_Drop, 220 kVBCppIncludeAction_End 221 } VBCPPINCLUDEACTION; 222 223 224 /** 212 225 * C Preprocessor instance data. 213 226 */ … … 220 233 /** Whether to keep comments. */ 221 234 bool fKeepComments; 235 /** Whether to respect source defines. */ 236 bool fRespectSourceDefines; 237 /** Whether to let source defines overrides the ones on the command 238 * line. */ 239 bool fAllowRedefiningCmdLineDefines; 240 /** Whether to pass thru defines. */ 241 bool fPassThruDefines; 242 /** Whether to allow undecided conditionals. */ 243 bool fUndecidedConditionals; 244 /** Whether to preforme line splicing. 245 * @todo implement line splicing */ 246 bool fLineSplicing; 247 /** What to do about include files. */ 248 VBCPPINCLUDEACTION enmIncludeAction; 222 249 223 250 /** The number of include directories. */ … … 287 314 288 315 289 316 /** 317 * Changes the preprocessing mode. 318 * 319 * @param pThis The C preprocessor instance. 320 * @param enmMode The new mode. 321 */ 322 static void vbcppSetMode(PVBCPP pThis, VBCPPMODE enmMode) 323 { 324 switch (enmMode) 325 { 326 case kVBCppMode_Standard: 327 pThis->fKeepComments = false; 328 pThis->fRespectSourceDefines = true; 329 pThis->fAllowRedefiningCmdLineDefines = true; 330 pThis->fPassThruDefines = false; 331 pThis->fUndecidedConditionals = false; 332 pThis->fLineSplicing = true; 333 pThis->enmIncludeAction = kVBCppIncludeAction_Include; 334 break; 335 336 case kVBCppMode_Selective: 337 pThis->fKeepComments = true; 338 pThis->fRespectSourceDefines = false; 339 pThis->fAllowRedefiningCmdLineDefines = false; 340 pThis->fPassThruDefines = true; 341 pThis->fUndecidedConditionals = true; 342 pThis->fLineSplicing = false; 343 pThis->enmIncludeAction = kVBCppIncludeAction_PassThru; 344 break; 345 346 case kVBCppMode_SelectiveD: 347 pThis->fKeepComments = true; 348 pThis->fRespectSourceDefines = true; 349 pThis->fAllowRedefiningCmdLineDefines = false; 350 pThis->fPassThruDefines = false; 351 pThis->fUndecidedConditionals = false; 352 pThis->fLineSplicing = false; 353 pThis->enmIncludeAction = kVBCppIncludeAction_Drop; 354 break; 355 356 default: 357 AssertFailedReturnVoid(); 358 } 359 pThis->enmMode = enmMode; 360 } 361 362 363 /** 364 * Initializes the C preprocessor instance data. 365 * 366 * @param pThis The C preprocessor instance data. 367 */ 290 368 static void vbcppInit(PVBCPP pThis) 291 369 { 292 pThis->enmMode = kVBCppMode_Selective; 293 pThis->fKeepComments = true; 294 pThis->cIncludes = 0; 370 vbcppSetMode(pThis, kVBCppMode_Selective); 295 371 pThis->cIncludes = 0; 296 372 pThis->papszIncludes = NULL; … … 502 578 503 579 /** 504 * Inserts a define .580 * Inserts a define (rejecting and freeing it in some case). 505 581 * 506 582 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE + msg. … … 510 586 static RTEXITCODE vbcppDefineInsert(PVBCPP pThis, PVBCPPDEF pDef) 511 587 { 588 /* 589 * Ignore in source-file defines when doing selective preprocessing. 590 */ 591 if ( !pThis->fRespectSourceDefines 592 && !pDef->fCmdLine) 593 { 594 /* Ignore*/ 595 vbcppFreeDefine(&pDef->Core, NULL); 596 return RTEXITCODE_SUCCESS; 597 } 598 599 /* 600 * Insert it and update the lead character hint bitmap. 601 */ 512 602 if (RTStrSpaceInsert(&pThis->StrSpace, &pDef->Core)) 513 603 VBCPP_BITMAP_SET(pThis->bmDefined, *pDef->Core.pszString); 514 604 else 515 605 { 516 RTMsgWarning("Redefining '%s'\n", pDef->Core.pszString); 517 PVBCPPDEF pOld = (PVBCPPDEF)vbcppDefineUndef(pThis, pDef->Core.pszString, pDef->Core.cchString, false); 518 bool fRc = RTStrSpaceInsert(&pThis->StrSpace, &pDef->Core); 519 Assert(fRc); Assert(pOld); 520 vbcppFreeDefine(&pOld->Core, NULL); 606 /* 607 * Duplicate. When doing selective D preprocessing, let the command 608 * line take precendece. 609 */ 610 PVBCPPDEF pOld = (PVBCPPDEF)RTStrSpaceGet(&pThis->StrSpace, pDef->Core.pszString); Assert(pOld); 611 if ( pThis->fAllowRedefiningCmdLineDefines 612 || pDef->fCmdLine == pOld->fCmdLine) 613 { 614 if (pDef->fCmdLine) 615 RTMsgWarning("Redefining '%s'\n", pDef->Core.pszString); 616 617 RTStrSpaceRemove(&pThis->StrSpace, pOld->Core.pszString); 618 vbcppFreeDefine(&pOld->Core, NULL); 619 620 bool fRc = RTStrSpaceInsert(&pThis->StrSpace, &pDef->Core); 621 Assert(fRc); 622 } 623 else 624 { 625 RTMsgWarning("Ignoring redefinition of '%s'\n", pDef->Core.pszString); 626 vbcppFreeDefine(&pDef->Core, NULL); 627 } 521 628 } 522 629 … … 816 923 817 924 case 'd': 818 pThis->enmMode = kVBCppMode_SelectiveD; 819 pThis->fKeepComments = true; 925 vbcppSetMode(pThis, kVBCppMode_SelectiveD); 820 926 break; 821 927 … … 1358 1464 * Execute it. 1359 1465 */ 1360 if (pThis->enm Mode < kVBCppMode_Selective)1466 if (pThis->enmIncludeAction == kVBCppIncludeAction_Include) 1361 1467 { 1362 1468 /** @todo Search for the include file and push it onto the input stack. … … 1364 1470 rcExit = vbcppError(pThis, "Includes are fully implemented"); 1365 1471 } 1366 else if (pThis->enm Mode != kVBCppMode_SelectiveD)1472 else if (pThis->enmIncludeAction == kVBCppIncludeAction_PassThru) 1367 1473 { 1368 1474 /* Pretty print the passthru. */ … … 1384 1490 1385 1491 } 1386 /* else: drop it */ 1492 else 1493 Assert(pThis->enmIncludeAction == kVBCppIncludeAction_Drop); 1387 1494 } 1388 1495 } … … 1477 1584 * Pass thru? 1478 1585 */ 1479 if ( pThis->enmMode >= kVBCppMode_Selective 1480 && pThis->enmMode != kVBCppMode_SelectiveD 1481 && rcExit == RTEXITCODE_SUCCESS) 1586 if ( rcExit == RTEXITCODE_SUCCESS 1587 && pThis->fPassThruDefines) 1482 1588 { 1483 1589 unsigned cchIndent = pThis->pCondStack ? pThis->pCondStack->iKeepLevel : 0; … … 1517 1623 1518 1624 1519 static VBCPPEVAL vbcppCondCombine(VBCPPEVAL enmEvalPush, VBCPPEVAL enmEvalTop) 1520 { 1521 if (enmEvalTop == kVBCppEval_False) 1625 /** 1626 * Combines current stack result with the one being pushed. 1627 * 1628 * @returns Combined result. 1629 * @param enmEvalPush The result of the condition being pushed. 1630 * @param enmEvalStack The current stack result. 1631 */ 1632 static VBCPPEVAL vbcppCondCombine(VBCPPEVAL enmEvalPush, VBCPPEVAL enmEvalStack) 1633 { 1634 if (enmEvalStack == kVBCppEval_False) 1522 1635 return kVBCppEval_False; 1523 1636 return enmEvalPush; … … 1525 1638 1526 1639 1640 /** 1641 * Pushes an conditional onto the stack. 1642 * 1643 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg. 1644 * @param pThis The C preprocessor instance. 1645 * @param pStrmInput The current input stream. 1646 * @param offStart Not currently used, using @a pchCondition and 1647 * @a cchCondition instead. 1648 * @param enmKind The kind of conditional. 1649 * @param enmResult The result of the evaluation. 1650 * @param pchCondition The raw condition. 1651 * @param cchCondition The length of @a pchCondition. 1652 */ 1527 1653 static RTEXITCODE vbcppCondPush(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart, 1528 1654 VBCPPCONDKIND enmKind, VBCPPEVAL enmResult, … … 1624 1750 if (vbcppDefineExists(pThis, pchDefine, cchDefine)) 1625 1751 enmEval = kVBCppEval_True; 1626 else if ( pThis-> enmMode < kVBCppMode_Selective1752 else if ( pThis->fUndecidedConditionals 1627 1753 || RTStrSpaceGetN(&pThis->UndefStrSpace, pchDefine, cchDefine) != NULL) 1628 1754 enmEval = kVBCppEval_False; … … 1670 1796 if (vbcppDefineExists(pThis, pchDefine, cchDefine)) 1671 1797 enmEval = kVBCppEval_False; 1672 else if ( pThis-> enmMode < kVBCppMode_Selective1798 else if ( pThis->fUndecidedConditionals 1673 1799 || RTStrSpaceGetN(&pThis->UndefStrSpace, pchDefine, cchDefine) != NULL) 1674 1800 enmEval = kVBCppEval_True;
Note:
See TracChangeset
for help on using the changeset viewer.