- Timestamp:
- May 8, 2012 8:18:36 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 77856
- Location:
- trunk/src/bldprogs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/VBoxCPP.cpp
r41209 r41217 244 244 /** Whether to allow undecided conditionals. */ 245 245 bool fUndecidedConditionals; 246 /** Whether to pass thru D pragmas. */ 247 bool fPassThruPragmaD; 248 /** Whether to pass thru STD pragmas. */ 249 bool fPassThruPragmaSTD; 250 /** Whether to pass thru other pragmas. */ 251 bool fPassThruPragmaOther; 252 /** Whether to remove dropped lines from the output. */ 253 bool fRemoveDroppedLines; 246 254 /** Whether to preforme line splicing. 247 255 * @todo implement line splicing */ … … 288 296 /** The current condition evaluates to kVBCppEval_False, don't output. */ 289 297 bool fIf0Mode; 298 /** Just dropped a line and should maybe drop the current line. */ 299 bool fJustDroppedLine; 290 300 291 301 /** Whether the current line could be a preprocessor line. … … 310 320 typedef VBCPP *PVBCPP; 311 321 322 323 /******************************************************************************* 324 * Internal Functions * 325 *******************************************************************************/ 326 static PVBCPPDEF vbcppDefineLookup(PVBCPP pThis, const char *pszDefine, size_t cchDefine); 312 327 313 328 … … 715 730 716 731 /** 732 * Skips input until the real end of the current directive line has been 733 * reached. 734 * 735 * This includes multiline comments starting on the same line 736 * 737 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg. 738 * @param pThis The C preprocessor instance. 739 * @param pStrmInput The input stream. 740 * @param poffComment Where to note down the position of the final 741 * comment. Optional. 742 */ 743 static RTEXITCODE vbcppInputSkipToEndOfDirectiveLine(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t *poffComment) 744 { 745 if (poffComment) 746 *poffComment = ~(size_t)0; 747 748 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 749 bool fInComment = false; 750 unsigned chPrev = 0; 751 unsigned ch; 752 while ((ch = ScmStreamPeekCh(pStrmInput)) != ~(unsigned)0) 753 { 754 if (ch == '\r' || ch == '\n') 755 { 756 if (chPrev == '\\') 757 { 758 ScmStreamSeekByLine(pStrmInput, ScmStreamTellLine(pStrmInput) + 1); 759 continue; 760 } 761 if (!fInComment) 762 break; 763 /* The expression continues after multi-line comments. Cool. :-) */ 764 } 765 else if (!fInComment) 766 { 767 if (chPrev == '/' && ch == '*' ) 768 { 769 fInComment = true; 770 if (poffComment) 771 *poffComment = ScmStreamTell(pStrmInput) - 1; 772 } 773 else if (chPrev == '/' && ch == '/') 774 { 775 if (poffComment) 776 *poffComment = ScmStreamTell(pStrmInput) - 1; 777 rcExit = vbcppProcessSkipWhiteEscapedEolAndComments(pThis, pStrmInput); 778 break; /* done */ 779 } 780 } 781 else if (ch == '/' && chPrev == '*') 782 fInComment = false; 783 784 /* advance */ 785 chPrev = ch; 786 ch = ScmStreamGetCh(pStrmInput); Assert(ch == chPrev); 787 } 788 return rcExit; 789 } 790 791 792 793 /** 717 794 * Processes a multi-line comment. 718 795 * … … 752 829 } 753 830 754 if ( ( pThis->fKeepComments 755 && !pThis->fIf0Mode) 756 || ch == '\r' 757 || ch == '\n') 758 { 831 if (ch == '\r' || ch == '\n') 832 { 833 if ( ( pThis->fKeepComments 834 && !pThis->fIf0Mode) 835 || !pThis->fRemoveDroppedLines 836 || !ScmStreamIsAtStartOfLine(&pThis->StrmOutput)) 837 rcExit = vbcppOutputCh(pThis, ch); 838 pThis->fJustDroppedLine = false; 839 pThis->fMaybePreprocessorLine = true; 840 } 841 else if ( pThis->fKeepComments 842 && !pThis->fIf0Mode) 759 843 rcExit = vbcppOutputCh(pThis, ch); 760 if (rcExit != RTEXITCODE_SUCCESS) 761 break; 762 763 /* Reset the maybe-preprocessor-line indicator when necessary. */ 764 if (ch == '\r' || ch == '\n') 765 pThis->fMaybePreprocessorLine = true; 766 } 844 845 if (rcExit != RTEXITCODE_SUCCESS) 846 break; 767 847 } 768 848 return rcExit; … … 782 862 static RTEXITCODE vbcppProcessOneLineComment(PVBCPP pThis, PSCMSTREAM pStrmInput) 783 863 { 784 RTEXITCODE rcExit ;864 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 785 865 SCMEOL enmEol; 786 866 size_t cchLine; … … 792 872 && !pThis->fIf0Mode) 793 873 rcExit = vbcppOutputWrite(pThis, pszLine, cchLine + enmEol); 794 else 874 else if ( !pThis->fIf0Mode 875 || !pThis->fRemoveDroppedLines 876 || !ScmStreamIsAtStartOfLine(&pThis->StrmOutput) ) 795 877 rcExit = vbcppOutputWrite(pThis, pszLine + cchLine, enmEol); 796 878 if (rcExit != RTEXITCODE_SUCCESS) … … 804 886 break; 805 887 } 888 pThis->fJustDroppedLine = false; 806 889 pThis->fMaybePreprocessorLine = true; 807 890 return rcExit; … … 893 976 static RTEXITCODE vbcppProcessCWord(PVBCPP pThis, PSCMSTREAM pStrmInput, char ch) 894 977 { 895 /** @todo Implement this... */ 896 return vbcppOutputCh(pThis, ch); 978 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 979 size_t cchDefine; 980 const char *pchDefine = ScmStreamCGetWordM1(pStrmInput, &cchDefine); 981 AssertReturn(pchDefine, vbcppError(pThis, "Internal error in ScmStreamCGetWordM1")); 982 983 984 /* 985 * Does this look like a define we know? 986 */ 987 PVBCPPDEF pDef = vbcppDefineLookup(pThis, pchDefine, cchDefine); 988 if (pDef) 989 { 990 if (!pDef->fFunction) 991 { 992 #if 0 /** @todo proper expansion! */ 993 vbcppDefineExpandSimple(pThis, pDef, ) 994 #else 995 int rc = ScmStreamWrite(&pThis->StrmOutput, pDef->szValue, pDef->cchValue); 996 if (RT_FAILURE(rc)) 997 rcExit = vbcppError(pThis, "Output error: %Rrc", rc); 998 #endif 999 } 1000 else 1001 rcExit = vbcppError(pThis, "Expanding function macros is not implemented\n"); 1002 } 1003 else 1004 { 1005 /* 1006 * Not a define, just output the text unchanged. 1007 */ 1008 int rc = ScmStreamWrite(&pThis->StrmOutput, pchDefine, cchDefine); 1009 if (RT_FAILURE(rc)) 1010 rcExit = vbcppError(pThis, "Output error: %Rrc", rc); 1011 } 1012 return rcExit; 897 1013 } 898 1014 … … 1489 1605 return vbcppError(pThis, "Output error %Rrc", (int)cch); 1490 1606 } 1607 else 1608 pThis->fJustDroppedLine = true; 1491 1609 1492 1610 return RTEXITCODE_SUCCESS; … … 1799 1917 *pcchExpr = cchExpr; 1800 1918 if (poffComment) 1801 *poffComment ;1919 *poffComment = offComment; 1802 1920 } 1803 1921 else … … 1895 2013 rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch); 1896 2014 } 2015 else 2016 pThis->fJustDroppedLine = true; 1897 2017 } 1898 2018 } … … 2049 2169 rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch); 2050 2170 } 2171 else 2172 pThis->fJustDroppedLine = true; 2051 2173 } 2052 2174 else … … 2085 2207 { 2086 2208 pThis->pCondStack = pCond->pUp; 2087 pThis->fIf0Mode = pCond->pUp && pCond->pUp->enmStackResult == kVBCppEval_False;2209 pThis->fIf0Mode = pCond->pUp && pCond->pUp->enmStackResult == kVBCppEval_False; 2088 2210 2089 2211 /* … … 2099 2221 rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch); 2100 2222 } 2223 else 2224 pThis->fJustDroppedLine = true; 2101 2225 } 2102 2226 else … … 2246 2370 } 2247 2371 else 2372 { 2248 2373 Assert(pThis->enmIncludeAction == kVBCppIncludeAction_Drop); 2374 pThis->fJustDroppedLine = true; 2375 } 2249 2376 } 2250 2377 } … … 2264 2391 static RTEXITCODE vbcppProcessPragma(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2265 2392 { 2266 return vbcppError(pThis, "Not implemented: %s", __FUNCTION__); 2393 /* 2394 * Parse out the first word. 2395 */ 2396 RTEXITCODE rcExit = vbcppProcessSkipWhiteEscapedEolAndComments(pThis, pStrmInput); 2397 if (rcExit == RTEXITCODE_SUCCESS) 2398 { 2399 size_t cchPragma; 2400 const char *pchPragma = ScmStreamCGetWord(pStrmInput, &cchPragma); 2401 if (pchPragma) 2402 { 2403 size_t const off2nd = vbcppProcessSkipWhite(pStrmInput); 2404 size_t offComment; 2405 rcExit = vbcppInputSkipToEndOfDirectiveLine(pThis, pStrmInput, &offComment); 2406 if (rcExit == RTEXITCODE_SUCCESS) 2407 { 2408 /* 2409 * What to do about this 2410 */ 2411 bool fPassThru = false; 2412 if ( cchPragma == 1 2413 && *pchPragma == 'D') 2414 fPassThru = pThis->fPassThruPragmaD; 2415 else if ( cchPragma == 3 2416 && !strncmp(pchPragma, "STD", 3)) 2417 fPassThru = pThis->fPassThruPragmaSTD; 2418 else 2419 fPassThru = pThis->fPassThruPragmaOther; 2420 if (fPassThru) 2421 { 2422 unsigned cchIndent = pThis->pCondStack ? pThis->pCondStack->iKeepLevel : 0; 2423 size_t cch = ScmStreamPrintf(&pThis->StrmOutput, "#%*spragma %.*s", 2424 cchIndent, "", cchPragma, pchPragma); 2425 if (cch > 0) 2426 rcExit = vbcppOutputComment(pThis, pStrmInput, off2nd, cch, 1); 2427 else 2428 rcExit = vbcppError(pThis, "output error"); 2429 } 2430 else 2431 pThis->fJustDroppedLine = true; 2432 } 2433 } 2434 else 2435 rcExit = vbcppError(pThis, "Malformed #pragma"); 2436 } 2437 2438 return rcExit; 2267 2439 } 2268 2440 … … 2414 2586 else if (ch == '\r' || ch == '\n') 2415 2587 { 2588 if ( ( !pThis->fIf0Mode 2589 && !pThis->fJustDroppedLine) 2590 || !pThis->fRemoveDroppedLines 2591 || !ScmStreamIsAtStartOfLine(&pThis->StrmOutput)) 2592 rcExit = vbcppOutputCh(pThis, ch); 2593 pThis->fJustDroppedLine = false; 2416 2594 pThis->fMaybePreprocessorLine = true; 2417 rcExit = vbcppOutputCh(pThis, ch);2418 2595 } 2419 2596 else if (RT_C_IS_SPACE(ch)) … … 2508 2685 pThis->fPassThruDefines = false; 2509 2686 pThis->fUndecidedConditionals = false; 2687 pThis->fPassThruPragmaD = false; 2688 pThis->fPassThruPragmaSTD = true; 2689 pThis->fPassThruPragmaOther = true; 2690 pThis->fRemoveDroppedLines = false; 2510 2691 pThis->fLineSplicing = true; 2511 2692 pThis->enmIncludeAction = kVBCppIncludeAction_Include; … … 2518 2699 pThis->fPassThruDefines = true; 2519 2700 pThis->fUndecidedConditionals = true; 2701 pThis->fPassThruPragmaD = true; 2702 pThis->fPassThruPragmaSTD = true; 2703 pThis->fPassThruPragmaOther = true; 2704 pThis->fRemoveDroppedLines = true; 2520 2705 pThis->fLineSplicing = false; 2521 2706 pThis->enmIncludeAction = kVBCppIncludeAction_PassThru; … … 2528 2713 pThis->fPassThruDefines = false; 2529 2714 pThis->fUndecidedConditionals = false; 2715 pThis->fPassThruPragmaD = true; 2716 pThis->fPassThruPragmaSTD = false; 2717 pThis->fPassThruPragmaOther = false; 2718 pThis->fRemoveDroppedLines = true; 2530 2719 pThis->fLineSplicing = false; 2531 2720 pThis->enmIncludeAction = kVBCppIncludeAction_Drop; … … 2724 2913 pThis->pCondStack = NULL; 2725 2914 pThis->fIf0Mode = false; 2915 pThis->fJustDroppedLine = false; 2726 2916 pThis->fMaybePreprocessorLine = true; 2727 2917 VBCPP_BITMAP_EMPTY(pThis->bmDefined); -
trunk/src/bldprogs/scmstream.cpp
r41195 r41217 640 640 } 641 641 return VINF_SUCCESS; 642 } 643 644 /** 645 * Checks if the stream position is at the start of a line. 646 * 647 * @returns @c true if at the start, @c false if not. 648 * @param pStream The stream. 649 */ 650 bool ScmStreamIsAtStartOfLine(PSCMSTREAM pStream) 651 { 652 if ( !pStream->fFullyLineated 653 && !pStream->fWriteOrRead) 654 { 655 int rc = scmStreamLineate(pStream); 656 if (RT_FAILURE(rc)) 657 return false; 658 } 659 return pStream->off == pStream->paLines[pStream->iLine].off; 642 660 } 643 661 -
trunk/src/bldprogs/scmstream.h
r41194 r41217 108 108 int ScmStreamSeekRelative(PSCMSTREAM pStream, ssize_t offRelative); 109 109 int ScmStreamSeekByLine(PSCMSTREAM pStream, size_t iLine); 110 bool ScmStreamIsAtStartOfLine(PSCMSTREAM pStream); 110 111 111 112 const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol);
Note:
See TracChangeset
for help on using the changeset viewer.