VirtualBox

Changeset 41194 in vbox for trunk/src


Ignore:
Timestamp:
May 7, 2012 8:23:52 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
77822
Message:

VBoxCPP: Half functional.

Location:
trunk/src/bldprogs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/Makefile.kmk

    r41186 r41194  
    5050        scmstream.cpp
    5151
    52  #BLDPROGS += VBoxCPP
     52 BLDPROGS += VBoxCPP
    5353 VBoxCPP_TEMPLATE = VBoxAdvBldProg
    5454 VBoxCPP_SOURCES = \
  • trunk/src/bldprogs/VBoxCPP.cpp

    r41186 r41194  
    33 * VBox Build Tool - A mini C Preprocessor.
    44 *
    5  * Purpuses to which this preprocessor will be put:
     5 * Purposes to which this preprocessor will be put:
    66 *      - Preprocessig vm.h into dtrace/lib/vm.d so we can access the VM
    77 *        structure (as well as substructures) from DTrace without having
     
    694694     * Simple define, no arguments.
    695695     */
    696     if (vbcppValidateCIdentifier(pThis, pszDefine, cchDefine))
     696    if (!vbcppValidateCIdentifier(pThis, pszDefine, cchDefine))
    697697        return RTEXITCODE_FAILURE;
    698698
     
    917917    if (RT_SUCCESS(rc))
    918918        return RTEXITCODE_SUCCESS;
    919     return vbcppError(pThis, "Output error %Rrc");
     919    return vbcppError(pThis, "Output error: %Rrc", rc);
    920920}
    921921
     
    934934    if (RT_SUCCESS(rc))
    935935        return RTEXITCODE_SUCCESS;
    936     return vbcppError(pThis, "Output error %Rrc");
     936    return vbcppError(pThis, "Output error: %Rrc", rc);
     937}
     938
     939
     940static RTEXITCODE vbcppOutputComment(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart, size_t cchOutputted)
     941{
     942    size_t offCur = ScmStreamTell(pStrmInput);
     943    if (offStart < offCur)
     944    {
     945        int rc = ScmStreamSeekAbsolute(pStrmInput, offStart);
     946        AssertRCReturn(rc, vbcppError(pThis, "Input seek error: %Rrc", rc));
     947
     948        /*
     949         * Use the same indent, if possible.
     950         */
     951        size_t cchIndent = offStart - ScmStreamTellOffsetOfLine(pStrmInput, ScmStreamTellLine(pStrmInput));
     952        if (cchOutputted < cchIndent)
     953            rc = ScmStreamPrintf(&pThis->StrmOutput, "%*s", cchIndent - cchOutputted, "");
     954        else
     955            rc = ScmStreamPutCh(&pThis->StrmOutput, ' ');
     956        if (RT_FAILURE(rc))
     957            return vbcppError(pThis, "Output error: %Rrc", rc);
     958
     959        /*
     960         * Copy the bytes.
     961         */
     962        while (ScmStreamTell(pStrmInput) < offCur)
     963        {
     964            unsigned ch = ScmStreamGetCh(pStrmInput);
     965            if (ch == ~(unsigned)0)
     966                return vbcppError(pThis, "Input error: %Rrc", rc);
     967            rc = ScmStreamPutCh(&pThis->StrmOutput, ch);
     968            if (RT_FAILURE(rc))
     969                return vbcppError(pThis, "Output error: %Rrc", rc);
     970        }
     971    }
     972
     973    return RTEXITCODE_SUCCESS;
    937974}
    938975
     
    953990    ScmStreamGetCh(pStrmInput);         /* '*' */
    954991    RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
    955     if (pThis->fKeepComments)
     992    if (   pThis->fKeepComments
     993        && !pThis->fIf0Mode)
    956994        rcExit = vbcppOutputWrite(pThis, "/*", 2);
    957995
     
    9681006            {
    9691007                ScmStreamGetCh(pStrmInput);
    970                 if (pThis->fKeepComments)
     1008                if (   pThis->fKeepComments
     1009                    && !pThis->fIf0Mode)
    9711010                    rcExit = vbcppOutputWrite(pThis, "*/", 2);
    9721011                break;
     
    9741013        }
    9751014
    976         if (pThis->fKeepComments || ch == '\r' || ch == '\n')
     1015        if (   (   pThis->fKeepComments
     1016                && !pThis->fIf0Mode)
     1017            || ch == '\r'
     1018            || ch == '\n')
    9771019        {
    9781020            rcExit = vbcppOutputCh(pThis, ch);
     
    10081050    for (;;)
    10091051    {
    1010         if (pThis->fKeepComments)
     1052        if (   pThis->fKeepComments
     1053            && !pThis->fIf0Mode)
    10111054            rcExit = vbcppOutputWrite(pThis, pszLine, cchLine + enmEol);
    10121055        else
     
    12191262 * Skips white spaces.
    12201263 *
    1221  * @param   pStrmInput          The input stream.
    1222  */
    1223 static void vbcppProcessSkipWhite(PSCMSTREAM pStrmInput)
     1264 * @returns The current location upon return..
     1265 * @param   pStrmInput          The input stream.
     1266 */
     1267static size_t vbcppProcessSkipWhite(PSCMSTREAM pStrmInput)
    12241268{
    12251269    unsigned ch;
     
    12311275        AssertBreak(chCheck == ch);
    12321276    }
     1277    return ScmStreamTell(pStrmInput);
    12331278}
    12341279
     
    12521297    if (rcExit == RTEXITCODE_SUCCESS)
    12531298    {
    1254         size_t      cchFilename;
    1255         const char *pchFilename;
     1299        size_t      cchFileSpec = 0;
     1300        const char *pchFileSpec = NULL;
     1301        size_t      cchFilename = 0;
     1302        const char *pchFilename = NULL;
    12561303
    12571304        unsigned ch = ScmStreamPeekCh(pStrmInput);
     
    12601307        {
    12611308            ScmStreamGetCh(pStrmInput);
    1262             pchFilename = ScmStreamGetCur(pStrmInput);
     1309            pchFileSpec = pchFilename = ScmStreamGetCur(pStrmInput);
     1310            unsigned chEnd  = chType == '<' ? '>' : '"';
    12631311            unsigned chPrev = ch;
    12641312            while (   (ch = ScmStreamGetCh(pStrmInput)) != ~(unsigned)0
    1265                    &&  ch != chType)
     1313                   &&  ch != chEnd)
    12661314            {
    12671315                if (ch == '\r' || ch == '\n')
     
    12721320            }
    12731321
    1274             if (rcExit != RTEXITCODE_SUCCESS)
     1322            if (rcExit == RTEXITCODE_SUCCESS)
    12751323            {
    12761324                if (ch != ~(unsigned)0)
    1277                     cchFilename = ScmStreamGetCur(pStrmInput) - pchFilename;
     1325                    cchFileSpec = cchFilename = ScmStreamGetCur(pStrmInput) - pchFilename - 1;
    12781326                else
    12791327                    rcExit = vbcppError(pThis, "Expected '%c'", chType);
     
    12821330        else if (vbcppIsCIdentifierLeadChar(ch))
    12831331        {
    1284             //size_t      cchDefine;
    1285             //const char *pchDefine = ScmStreamCGetWord(pStrmInput, &cchDefine);
    1286             rcExit = vbcppError(pThis, "Including via a define is not implemented yet")
     1332            //pchFileSpec = ScmStreamCGetWord(pStrmInput, &cchFileSpec);
     1333            rcExit = vbcppError(pThis, "Including via a define is not implemented yet");
    12871334        }
    12881335        else
    1289             rcExit = vbcppError(pThis, "Malformed include directive")
     1336            rcExit = vbcppError(pThis, "Malformed include directive");
    12901337
    12911338        /*
    1292          * Take down the location of the next non-white space, if we need to
    1293          * pass thru the directive further down. Then skip to the end of the
     1339         * Take down the location of the next non-white space, in case we need
     1340         * to pass thru the directive further down. Then skip to the end of the
    12941341         * line.
    12951342         */
    1296         if (rcExit != RTEXITCODE_SUCCESS)
    1297             vbcppProcessSkipWhite(pStrmInput);
    1298         size_t const offIncEnd = ScmStreamTell(pStrmInput);
    1299         if (rcExit != RTEXITCODE_SUCCESS)
     1343        size_t const offIncEnd = vbcppProcessSkipWhite(pStrmInput);
     1344        if (rcExit == RTEXITCODE_SUCCESS)
    13001345            rcExit = vbcppProcessSkipWhiteEscapedEolAndCommentsCheckEol(pThis, pStrmInput);
    13011346
    1302         if (rcExit != RTEXITCODE_SUCCESS)
     1347        if (rcExit == RTEXITCODE_SUCCESS)
    13031348        {
    13041349            /*
     
    13131358            else if (pThis->enmMode != kVBCppMode_SelectiveD)
    13141359            {
    1315 /** @todo put this in a function or smth. */
    1316                 ssize_t cch = ScmStreamPrintf(&pThis->StrmOutput, "#%*sinclude %.*s",
    1317                                               pCond->iKeepLevel - 1, "", pchCondition);
    1318                 if (cch < 0)
    1319                     return vbcppError(pThis, "Output error %Rrc", (int)cch);
    1320                 if (offIncEnd < ScmStreamTell(pStrmInput))
    1321                 {
    1322                     /** @todo  */
    1323                     ScmStreamPrintf(&pThis->StrmOutput, "/* missing comment - fixme */");
    1324                 }
    1325 
    1326             }
    1327             /* else: strip it */
     1360                /* Pretty print the passthru. */
     1361                unsigned cchIndent = pThis->pCondStack ? pThis->pCondStack->iKeepLevel : 0;
     1362                size_t cch;
     1363                if (chType == '<')
     1364                    cch = ScmStreamPrintf(&pThis->StrmOutput, "#%*sinclude <%.*s>",
     1365                                          cchIndent, "", cchFileSpec, pchFileSpec);
     1366                else if (chType == '"')
     1367                    cch = ScmStreamPrintf(&pThis->StrmOutput, "#%*sinclude \"%.*s\"",
     1368                                          cchIndent, "", cchFileSpec, pchFileSpec);
     1369                else
     1370                    cch = ScmStreamPrintf(&pThis->StrmOutput, "#%*sinclude %.*s",
     1371                                          cchIndent, "", cchFileSpec, pchFileSpec);
     1372                if (cch > 0)
     1373                    rcExit = vbcppOutputComment(pThis, pStrmInput, offIncEnd, cch);
     1374                else
     1375                    rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch);
     1376
     1377            }
     1378            /* else: drop it */
    13281379        }
    13291380    }
     
    15421593static RTEXITCODE vbcppProcessElse(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)
    15431594{
    1544     return vbcppError(pThis, "Not implemented %s", __FUNCTION__);
     1595    /*
     1596     * Nothing to parse, just comment positions to find and note down.
     1597     */
     1598    offStart = vbcppProcessSkipWhite(pStrmInput);
     1599    RTEXITCODE rcExit = vbcppProcessSkipWhiteEscapedEolAndCommentsCheckEol(pThis, pStrmInput);
     1600    if (rcExit == RTEXITCODE_SUCCESS)
     1601    {
     1602        /*
     1603         * Execute.
     1604         */
     1605        PVBCPPCOND pCond = pThis->pCondStack;
     1606        if (pCond)
     1607        {
     1608            if (!pCond->fSeenElse)
     1609            {
     1610                pCond->fSeenElse = true;
     1611                if (   pCond->enmResult != kVBCppEval_Undecided
     1612                    && (   !pCond->pUp
     1613                        || pCond->pUp->enmStackResult == kVBCppEval_True))
     1614                {
     1615                    if (pCond->enmResult == kVBCppEval_True)
     1616                        pCond->enmStackResult = kVBCppEval_False;
     1617                    else
     1618                        pCond->enmStackResult = kVBCppEval_True;
     1619                    pThis->fIf0Mode = pCond->enmStackResult == kVBCppEval_False;
     1620                }
     1621
     1622                /*
     1623                 * Do pass thru.
     1624                 */
     1625                if (   !pThis->fIf0Mode
     1626                    && pCond->enmResult == kVBCppEval_Undecided)
     1627                {
     1628                    ssize_t cch = ScmStreamPrintf(&pThis->StrmOutput, "#%*selse", pCond->iKeepLevel - 1, "");
     1629                    if (cch > 0)
     1630                        rcExit = vbcppOutputComment(pThis, pStrmInput, offStart, cch);
     1631                    else
     1632                        rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch);
     1633                }
     1634            }
     1635            else
     1636                rcExit = vbcppError(pThis, "Double #else or/and missing #endif");
     1637        }
     1638        else
     1639            rcExit = vbcppError(pThis, "#else without #if");
     1640    }
     1641    return rcExit;
    15451642}
    15461643
     
    15571654static RTEXITCODE vbcppProcessEndif(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)
    15581655{
    1559     return vbcppError(pThis, "Not implemented %s", __FUNCTION__);
     1656    /*
     1657     * Nothing to parse, just comment positions to find and note down.
     1658     */
     1659    offStart = vbcppProcessSkipWhite(pStrmInput);
     1660    RTEXITCODE rcExit = vbcppProcessSkipWhiteEscapedEolAndCommentsCheckEol(pThis, pStrmInput);
     1661    if (rcExit == RTEXITCODE_SUCCESS)
     1662    {
     1663        /*
     1664         * Execute.
     1665         */
     1666        PVBCPPCOND pCond = pThis->pCondStack;
     1667        if (pCond)
     1668        {
     1669            pThis->pCondStack = pCond->pUp;
     1670            pThis->fIf0Mode = pCond->pUp && pCond->pUp->enmStackResult == kVBCppEval_False;
     1671
     1672            /*
     1673             * Do pass thru.
     1674             */
     1675            if (   !pThis->fIf0Mode
     1676                && pCond->enmResult == kVBCppEval_Undecided)
     1677            {
     1678                ssize_t cch = ScmStreamPrintf(&pThis->StrmOutput, "#%*sendif", pCond->iKeepLevel - 1, "");
     1679                if (cch > 0)
     1680                    rcExit = vbcppOutputComment(pThis, pStrmInput, offStart, cch);
     1681                else
     1682                    rcExit = vbcppError(pThis, "Output error %Rrc", (int)cch);
     1683            }
     1684        }
     1685        else
     1686            rcExit = vbcppError(pThis, "#endif without #if");
     1687    }
     1688    return rcExit;
    15601689}
    15611690
     
    15721701static RTEXITCODE vbcppProcessPragma(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)
    15731702{
    1574     return vbcppError(pThis, "Not implemented %s", __FUNCTION__);
     1703    return vbcppError(pThis, "Not implemented: %s", __FUNCTION__);
    15751704}
    15761705
     
    15871716static RTEXITCODE vbcppProcessLineNo(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)
    15881717{
    1589     return vbcppError(pThis, "Not implemented %s", __FUNCTION__);
     1718    return vbcppError(pThis, "Not implemented: %s", __FUNCTION__);
    15901719}
    15911720
     
    15971726 * @param   pThis               The C preprocessor instance.
    15981727 * @param   pStrmInput          The input stream.
    1599  * @param   offStart            The stream position where the directive
    1600  *                              started (for pass thru).
    1601  */
    1602 static RTEXITCODE vbcppProcessLineNoShort(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)
    1603 {
    1604     return vbcppError(pThis, "Not implemented %s", __FUNCTION__);
     1728 */
     1729static RTEXITCODE vbcppProcessLineNoShort(PVBCPP pThis, PSCMSTREAM pStrmInput)
     1730{
     1731    return vbcppError(pThis, "Not implemented: %s", __FUNCTION__);
    16051732}
    16061733
     
    18521979}
    18531980
    1854 
  • trunk/src/bldprogs/scmstream.cpp

    r41186 r41194  
    480480}
    481481
     482
     483/**
     484 * Gets the stream offset of a given line.
     485 *
     486 * @returns The offset of the line, or the stream size if the line number is too
     487 *          high.
     488 * @param   pStream             The stream. Must be in read mode.
     489 * @param   iLine               The line we're asking about.
     490 */
     491size_t ScmStreamTellOffsetOfLine(PSCMSTREAM pStream, size_t iLine)
     492{
     493    AssertReturn(!pStream->fWriteOrRead, pStream->cb);
     494    if (!pStream->fFullyLineated)
     495    {
     496        int rc = scmStreamLineate(pStream);
     497        AssertRCReturn(rc, pStream->cb);
     498    }
     499    if (iLine >= pStream->cLines)
     500        return pStream->cb;
     501    return pStream->paLines[iLine].off;
     502}
     503
     504
    482505/**
    483506 * Get the current stream size in bytes.
     
    692715    size_t      iCurLine = pStream->iLine;
    693716    const char *pszLine  = ScmStreamGetLineByNo(pStream, iCurLine, pcchLine, penmEol);
    694     if (   pszLine 
     717    if (   pszLine
    695718        && offCur > pStream->paLines[iCurLine].off)
    696719    {
     
    708731/**
    709732 * Get the current buffer pointer.
    710  * 
     733 *
    711734 * @returns Buffer pointer on success, NULL on failure (asserted).
    712735 * @param   pStream             The stream.  Must be in read mode.
  • trunk/src/bldprogs/scmstream.h

    r41186 r41194  
    102102size_t      ScmStreamTell(PSCMSTREAM pStream);
    103103size_t      ScmStreamTellLine(PSCMSTREAM pStream);
     104size_t      ScmStreamTellOffsetOfLine(PSCMSTREAM pStream, size_t iLine);
    104105size_t      ScmStreamSize(PSCMSTREAM pStream);
    105106size_t      ScmStreamCountLines(PSCMSTREAM pStream);
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