- Timestamp:
- May 7, 2012 8:23:52 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 77822
- Location:
- trunk/src/bldprogs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/Makefile.kmk
r41186 r41194 50 50 scmstream.cpp 51 51 52 #BLDPROGS += VBoxCPP52 BLDPROGS += VBoxCPP 53 53 VBoxCPP_TEMPLATE = VBoxAdvBldProg 54 54 VBoxCPP_SOURCES = \ -
trunk/src/bldprogs/VBoxCPP.cpp
r41186 r41194 3 3 * VBox Build Tool - A mini C Preprocessor. 4 4 * 5 * Purp uses to which this preprocessor will be put:5 * Purposes to which this preprocessor will be put: 6 6 * - Preprocessig vm.h into dtrace/lib/vm.d so we can access the VM 7 7 * structure (as well as substructures) from DTrace without having … … 694 694 * Simple define, no arguments. 695 695 */ 696 if ( vbcppValidateCIdentifier(pThis, pszDefine, cchDefine))696 if (!vbcppValidateCIdentifier(pThis, pszDefine, cchDefine)) 697 697 return RTEXITCODE_FAILURE; 698 698 … … 917 917 if (RT_SUCCESS(rc)) 918 918 return RTEXITCODE_SUCCESS; 919 return vbcppError(pThis, "Output error %Rrc");919 return vbcppError(pThis, "Output error: %Rrc", rc); 920 920 } 921 921 … … 934 934 if (RT_SUCCESS(rc)) 935 935 return RTEXITCODE_SUCCESS; 936 return vbcppError(pThis, "Output error %Rrc"); 936 return vbcppError(pThis, "Output error: %Rrc", rc); 937 } 938 939 940 static 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; 937 974 } 938 975 … … 953 990 ScmStreamGetCh(pStrmInput); /* '*' */ 954 991 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 955 if (pThis->fKeepComments) 992 if ( pThis->fKeepComments 993 && !pThis->fIf0Mode) 956 994 rcExit = vbcppOutputWrite(pThis, "/*", 2); 957 995 … … 968 1006 { 969 1007 ScmStreamGetCh(pStrmInput); 970 if (pThis->fKeepComments) 1008 if ( pThis->fKeepComments 1009 && !pThis->fIf0Mode) 971 1010 rcExit = vbcppOutputWrite(pThis, "*/", 2); 972 1011 break; … … 974 1013 } 975 1014 976 if (pThis->fKeepComments || ch == '\r' || ch == '\n') 1015 if ( ( pThis->fKeepComments 1016 && !pThis->fIf0Mode) 1017 || ch == '\r' 1018 || ch == '\n') 977 1019 { 978 1020 rcExit = vbcppOutputCh(pThis, ch); … … 1008 1050 for (;;) 1009 1051 { 1010 if (pThis->fKeepComments) 1052 if ( pThis->fKeepComments 1053 && !pThis->fIf0Mode) 1011 1054 rcExit = vbcppOutputWrite(pThis, pszLine, cchLine + enmEol); 1012 1055 else … … 1219 1262 * Skips white spaces. 1220 1263 * 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 */ 1267 static size_t vbcppProcessSkipWhite(PSCMSTREAM pStrmInput) 1224 1268 { 1225 1269 unsigned ch; … … 1231 1275 AssertBreak(chCheck == ch); 1232 1276 } 1277 return ScmStreamTell(pStrmInput); 1233 1278 } 1234 1279 … … 1252 1297 if (rcExit == RTEXITCODE_SUCCESS) 1253 1298 { 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; 1256 1303 1257 1304 unsigned ch = ScmStreamPeekCh(pStrmInput); … … 1260 1307 { 1261 1308 ScmStreamGetCh(pStrmInput); 1262 pchFilename = ScmStreamGetCur(pStrmInput); 1309 pchFileSpec = pchFilename = ScmStreamGetCur(pStrmInput); 1310 unsigned chEnd = chType == '<' ? '>' : '"'; 1263 1311 unsigned chPrev = ch; 1264 1312 while ( (ch = ScmStreamGetCh(pStrmInput)) != ~(unsigned)0 1265 && ch != ch Type)1313 && ch != chEnd) 1266 1314 { 1267 1315 if (ch == '\r' || ch == '\n') … … 1272 1320 } 1273 1321 1274 if (rcExit != RTEXITCODE_SUCCESS)1322 if (rcExit == RTEXITCODE_SUCCESS) 1275 1323 { 1276 1324 if (ch != ~(unsigned)0) 1277 cchFile name = ScmStreamGetCur(pStrmInput) - pchFilename;1325 cchFileSpec = cchFilename = ScmStreamGetCur(pStrmInput) - pchFilename - 1; 1278 1326 else 1279 1327 rcExit = vbcppError(pThis, "Expected '%c'", chType); … … 1282 1330 else if (vbcppIsCIdentifierLeadChar(ch)) 1283 1331 { 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"); 1287 1334 } 1288 1335 else 1289 rcExit = vbcppError(pThis, "Malformed include directive") 1336 rcExit = vbcppError(pThis, "Malformed include directive"); 1290 1337 1291 1338 /* 1292 * Take down the location of the next non-white space, i f we need to1293 * pass thru the directive further down. Then skip to the end of the1339 * 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 1294 1341 * line. 1295 1342 */ 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) 1300 1345 rcExit = vbcppProcessSkipWhiteEscapedEolAndCommentsCheckEol(pThis, pStrmInput); 1301 1346 1302 if (rcExit != RTEXITCODE_SUCCESS)1347 if (rcExit == RTEXITCODE_SUCCESS) 1303 1348 { 1304 1349 /* … … 1313 1358 else if (pThis->enmMode != kVBCppMode_SelectiveD) 1314 1359 { 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 */ 1328 1379 } 1329 1380 } … … 1542 1593 static RTEXITCODE vbcppProcessElse(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 1543 1594 { 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; 1545 1642 } 1546 1643 … … 1557 1654 static RTEXITCODE vbcppProcessEndif(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 1558 1655 { 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; 1560 1689 } 1561 1690 … … 1572 1701 static RTEXITCODE vbcppProcessPragma(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 1573 1702 { 1574 return vbcppError(pThis, "Not implemented %s", __FUNCTION__);1703 return vbcppError(pThis, "Not implemented: %s", __FUNCTION__); 1575 1704 } 1576 1705 … … 1587 1716 static RTEXITCODE vbcppProcessLineNo(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 1588 1717 { 1589 return vbcppError(pThis, "Not implemented %s", __FUNCTION__);1718 return vbcppError(pThis, "Not implemented: %s", __FUNCTION__); 1590 1719 } 1591 1720 … … 1597 1726 * @param pThis The C preprocessor instance. 1598 1727 * @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 */ 1729 static RTEXITCODE vbcppProcessLineNoShort(PVBCPP pThis, PSCMSTREAM pStrmInput) 1730 { 1731 return vbcppError(pThis, "Not implemented: %s", __FUNCTION__); 1605 1732 } 1606 1733 … … 1852 1979 } 1853 1980 1854 -
trunk/src/bldprogs/scmstream.cpp
r41186 r41194 480 480 } 481 481 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 */ 491 size_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 482 505 /** 483 506 * Get the current stream size in bytes. … … 692 715 size_t iCurLine = pStream->iLine; 693 716 const char *pszLine = ScmStreamGetLineByNo(pStream, iCurLine, pcchLine, penmEol); 694 if ( pszLine 717 if ( pszLine 695 718 && offCur > pStream->paLines[iCurLine].off) 696 719 { … … 708 731 /** 709 732 * Get the current buffer pointer. 710 * 733 * 711 734 * @returns Buffer pointer on success, NULL on failure (asserted). 712 735 * @param pStream The stream. Must be in read mode. -
trunk/src/bldprogs/scmstream.h
r41186 r41194 102 102 size_t ScmStreamTell(PSCMSTREAM pStream); 103 103 size_t ScmStreamTellLine(PSCMSTREAM pStream); 104 size_t ScmStreamTellOffsetOfLine(PSCMSTREAM pStream, size_t iLine); 104 105 size_t ScmStreamSize(PSCMSTREAM pStream); 105 106 size_t ScmStreamCountLines(PSCMSTREAM pStream);
Note:
See TracChangeset
for help on using the changeset viewer.