VirtualBox

Changeset 41217 in vbox for trunk/src


Ignore:
Timestamp:
May 8, 2012 8:18:36 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
77856
Message:

VBoxCPP: Groks cpumctx.h now.

Location:
trunk/src/bldprogs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/VBoxCPP.cpp

    r41209 r41217  
    244244    /** Whether to allow undecided conditionals. */
    245245    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;
    246254    /** Whether to preforme line splicing.
    247255     * @todo implement line splicing  */
     
    288296    /** The current condition evaluates to kVBCppEval_False, don't output. */
    289297    bool                fIf0Mode;
     298    /** Just dropped a line and should maybe drop the current line. */
     299    bool                fJustDroppedLine;
    290300
    291301    /** Whether the current line could be a preprocessor line.
     
    310320typedef VBCPP *PVBCPP;
    311321
     322
     323/*******************************************************************************
     324*   Internal Functions                                                         *
     325*******************************************************************************/
     326static PVBCPPDEF vbcppDefineLookup(PVBCPP pThis, const char *pszDefine, size_t cchDefine);
    312327
    313328
     
    715730
    716731/**
     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 */
     743static 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/**
    717794 * Processes a multi-line comment.
    718795 *
     
    752829        }
    753830
    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)
    759843            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;
    767847    }
    768848    return rcExit;
     
    782862static RTEXITCODE vbcppProcessOneLineComment(PVBCPP pThis, PSCMSTREAM pStrmInput)
    783863{
    784     RTEXITCODE  rcExit;
     864    RTEXITCODE  rcExit = RTEXITCODE_SUCCESS;
    785865    SCMEOL      enmEol;
    786866    size_t      cchLine;
     
    792872            && !pThis->fIf0Mode)
    793873            rcExit = vbcppOutputWrite(pThis, pszLine, cchLine + enmEol);
    794         else
     874        else if (   !pThis->fIf0Mode
     875                 || !pThis->fRemoveDroppedLines
     876                 || !ScmStreamIsAtStartOfLine(&pThis->StrmOutput) )
    795877            rcExit = vbcppOutputWrite(pThis, pszLine + cchLine, enmEol);
    796878        if (rcExit != RTEXITCODE_SUCCESS)
     
    804886            break;
    805887    }
     888    pThis->fJustDroppedLine       = false;
    806889    pThis->fMaybePreprocessorLine = true;
    807890    return rcExit;
     
    893976static RTEXITCODE vbcppProcessCWord(PVBCPP pThis, PSCMSTREAM pStrmInput, char ch)
    894977{
    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;
    8971013}
    8981014
     
    14891605            return vbcppError(pThis, "Output error %Rrc", (int)cch);
    14901606    }
     1607    else
     1608        pThis->fJustDroppedLine = true;
    14911609
    14921610    return RTEXITCODE_SUCCESS;
     
    17991917            *pcchExpr = cchExpr;
    18001918        if (poffComment)
    1801             *poffComment;
     1919            *poffComment = offComment;
    18021920    }
    18031921    else
     
    18952013                                rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch);
    18962014                        }
     2015                        else
     2016                            pThis->fJustDroppedLine = true;
    18972017                    }
    18982018                }
     
    20492169                        rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch);
    20502170                }
     2171                else
     2172                    pThis->fJustDroppedLine = true;
    20512173            }
    20522174            else
     
    20852207        {
    20862208            pThis->pCondStack = pCond->pUp;
    2087             pThis->fIf0Mode = pCond->pUp && pCond->pUp->enmStackResult == kVBCppEval_False;
     2209            pThis->fIf0Mode   = pCond->pUp && pCond->pUp->enmStackResult == kVBCppEval_False;
    20882210
    20892211            /*
     
    20992221                    rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch);
    21002222            }
     2223            else
     2224                pThis->fJustDroppedLine = true;
    21012225        }
    21022226        else
     
    22462370            }
    22472371            else
     2372            {
    22482373                Assert(pThis->enmIncludeAction == kVBCppIncludeAction_Drop);
     2374                pThis->fJustDroppedLine = true;
     2375            }
    22492376        }
    22502377    }
     
    22642391static RTEXITCODE vbcppProcessPragma(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)
    22652392{
    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;
    22672439}
    22682440
     
    24142586            else if (ch == '\r' || ch == '\n')
    24152587            {
     2588                if (   (   !pThis->fIf0Mode
     2589                        && !pThis->fJustDroppedLine)
     2590                    || !pThis->fRemoveDroppedLines
     2591                    || !ScmStreamIsAtStartOfLine(&pThis->StrmOutput))
     2592                    rcExit = vbcppOutputCh(pThis, ch);
     2593                pThis->fJustDroppedLine       = false;
    24162594                pThis->fMaybePreprocessorLine = true;
    2417                 rcExit = vbcppOutputCh(pThis, ch);
    24182595            }
    24192596            else if (RT_C_IS_SPACE(ch))
     
    25082685            pThis->fPassThruDefines                 = false;
    25092686            pThis->fUndecidedConditionals           = false;
     2687            pThis->fPassThruPragmaD                 = false;
     2688            pThis->fPassThruPragmaSTD               = true;
     2689            pThis->fPassThruPragmaOther             = true;
     2690            pThis->fRemoveDroppedLines              = false;
    25102691            pThis->fLineSplicing                    = true;
    25112692            pThis->enmIncludeAction                 = kVBCppIncludeAction_Include;
     
    25182699            pThis->fPassThruDefines                 = true;
    25192700            pThis->fUndecidedConditionals           = true;
     2701            pThis->fPassThruPragmaD                 = true;
     2702            pThis->fPassThruPragmaSTD               = true;
     2703            pThis->fPassThruPragmaOther             = true;
     2704            pThis->fRemoveDroppedLines              = true;
    25202705            pThis->fLineSplicing                    = false;
    25212706            pThis->enmIncludeAction                 = kVBCppIncludeAction_PassThru;
     
    25282713            pThis->fPassThruDefines                 = false;
    25292714            pThis->fUndecidedConditionals           = false;
     2715            pThis->fPassThruPragmaD                 = true;
     2716            pThis->fPassThruPragmaSTD               = false;
     2717            pThis->fPassThruPragmaOther             = false;
     2718            pThis->fRemoveDroppedLines              = true;
    25302719            pThis->fLineSplicing                    = false;
    25312720            pThis->enmIncludeAction                 = kVBCppIncludeAction_Drop;
     
    27242913    pThis->pCondStack       = NULL;
    27252914    pThis->fIf0Mode         = false;
     2915    pThis->fJustDroppedLine = false;
    27262916    pThis->fMaybePreprocessorLine = true;
    27272917    VBCPP_BITMAP_EMPTY(pThis->bmDefined);
  • trunk/src/bldprogs/scmstream.cpp

    r41195 r41217  
    640640    }
    641641    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 */
     650bool 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;
    642660}
    643661
  • trunk/src/bldprogs/scmstream.h

    r41194 r41217  
    108108int         ScmStreamSeekRelative(PSCMSTREAM pStream, ssize_t offRelative);
    109109int         ScmStreamSeekByLine(PSCMSTREAM pStream, size_t iLine);
     110bool        ScmStreamIsAtStartOfLine(PSCMSTREAM pStream);
    110111
    111112const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette