Changeset 41226 in vbox
- Timestamp:
- May 9, 2012 8:32:08 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/VBoxCPP.cpp
r41217 r41226 109 109 typedef VBCPPDEF *PVBCPPDEF; 110 110 111 112 /**113 * Expansion context.114 */115 typedef struct VBCPPCTX116 {117 /** The next context on the stack. */118 struct VBCPPCTX *pUp;119 /** The define being expanded. */120 PVBCPPDEF pDef;121 /** Arguments. */122 struct VBCPPCTXARG123 {124 /** The value. */125 const char *pchValue;126 /** The value length. */127 const char *cchValue;128 } aArgs[1];129 } VBCPPCTX;130 /** Pointer to an define expansion context. */131 typedef VBCPPCTX *PVBCPPCTX;132 111 133 112 /** … … 279 258 * should expand. */ 280 259 VBCPP_BITMAP_TYPE bmDefined[VBCPP_BITMAP_SIZE]; 281 /** Indicates whether a C-word might need argument expansion.282 * The bitmap is indexed by C-word lead character. Bits that are set283 * indicates that the lead character is used in an argument of an currently284 * expanding \#define. */285 VBCPP_BITMAP_TYPE bmArgs[VBCPP_BITMAP_SIZE];286 287 /** Expansion context stack. */288 PVBCPPCTX pExpStack;289 /** The current expansion stack depth. */290 uint32_t cExpStackDepth;291 260 292 261 /** The current depth of the conditional stack. */ … … 324 293 * Internal Functions * 325 294 *******************************************************************************/ 326 static PVBCPPDEF vbcppDefineLookup(PVBCPP pThis, const char *pszDefine, size_t cchDefine); 327 295 static PVBCPPDEF vbcppMacroLookup(PVBCPP pThis, const char *pszDefine, size_t cchDefine); 296 static RTEXITCODE vbcppMacroExpandFunctionLike(PVBCPP pThis, PVBCPPDEF pMacro, PSCMSTREAM pStrmInput, char **ppszExpansion); 297 static RTEXITCODE vbcppMacroExpandObjectLike(PVBCPP pThis, PVBCPPDEF pMacro, PSCMSTREAM pStrmInput, char **ppszExpansion); 328 298 329 299 … … 726 696 } 727 697 return ScmStreamTell(pStrmInput); 698 } 699 700 701 /** 702 * Looks for a left parenthesis in the input stream. 703 * 704 * Used during macro expansion. Will ignore comments, newlines and other 705 * whitespace. 706 * 707 * @retval true if found. The stream position at opening parenthesis. 708 * @retval false if not found. The stream position is unchanged. 709 * 710 * @param pThis The C preprocessor instance. 711 * @param pStrmInput The input stream. 712 */ 713 static bool vbcppInputLookForLeftParenthesis(PVBCPP pThis, PSCMSTREAM pStrmInput) 714 { 715 size_t offSaved = ScmStreamTell(pStrmInput); 716 RTEXITCODE rcExit = vbcppProcessSkipWhiteEscapedEolAndComments(pThis, pStrmInput); 717 unsigned ch = ScmStreamPeekCh(pStrmInput); 718 if (ch == '(') 719 return true; 720 721 int rc = ScmStreamSeekAbsolute(pStrmInput, offSaved); 722 AssertFatalRC(rc); 723 return false; 728 724 } 729 725 … … 901 897 * @param pStrmInput The input stream. 902 898 */ 903 static RTEXITCODE vbcppProcess DoubleQuotedString(PVBCPP pThis, PSCMSTREAM pStrmInput)899 static RTEXITCODE vbcppProcessStringLitteral(PVBCPP pThis, PSCMSTREAM pStrmInput) 904 900 { 905 901 RTEXITCODE rcExit = vbcppOutputCh(pThis, '"'); … … 938 934 * @param pStrmInput The input stream. 939 935 */ 940 static RTEXITCODE vbcppProcess SingledQuotedString(PVBCPP pThis, PSCMSTREAM pStrmInput)936 static RTEXITCODE vbcppProcessCharacterConstant(PVBCPP pThis, PSCMSTREAM pStrmInput) 941 937 { 942 938 RTEXITCODE rcExit = vbcppOutputCh(pThis, '\''); … … 967 963 968 964 /** 969 * Processes a C word, possibly replacing it with a definition. 965 * Processes a integer or floating point number constant. 966 * 967 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg. 968 * @param pThis The C preprocessor instance. 969 * @param pStrmInput The input stream. 970 * @param chFirst The first character. 971 */ 972 static RTEXITCODE vbcppProcessNumber(PVBCPP pThis, PSCMSTREAM pStrmInput, char chFirst) 973 { 974 RTEXITCODE rcExit = vbcppOutputCh(pThis, chFirst); 975 976 unsigned ch; 977 while ( rcExit == RTEXITCODE_SUCCESS 978 && (ch = ScmStreamPeekCh(pStrmInput)) != ~(unsigned)0) 979 { 980 if ( !vbcppIsCIdentifierChar(ch) 981 && ch != '.') 982 break; 983 984 unsigned ch2 = ScmStreamGetCh(pStrmInput); 985 AssertBreakStmt(ch2 == ch, rcExit = vbcppError(pThis, "internal error")); 986 rcExit = vbcppOutputCh(pThis, ch); 987 } 988 989 return rcExit; 990 } 991 992 993 /** 994 * Processes a identifier, possibly replacing it with a definition. 970 995 * 971 996 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg. … … 974 999 * @param ch The first character. 975 1000 */ 976 static RTEXITCODE vbcppProcessCWord(PVBCPP pThis, PSCMSTREAM pStrmInput, char ch) 977 { 1001 static RTEXITCODE vbcppProcessIdentifier(PVBCPP pThis, PSCMSTREAM pStrmInput, char ch) 1002 { 1003 int rc = VINF_SUCCESS; 978 1004 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 979 1005 size_t cchDefine; … … 981 1007 AssertReturn(pchDefine, vbcppError(pThis, "Internal error in ScmStreamCGetWordM1")); 982 1008 983 984 1009 /* 985 1010 * Does this look like a define we know? 986 1011 */ 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); 1012 PVBCPPDEF pMacro = vbcppMacroLookup(pThis, pchDefine, cchDefine); 1013 if ( pMacro 1014 && ( !pMacro->fFunction 1015 || vbcppInputLookForLeftParenthesis(pThis, pStrmInput)) ) 1016 { 1017 char *pszExpansion = NULL; 1018 if (!pMacro->fFunction) 1019 rcExit = vbcppMacroExpandObjectLike(pThis, pMacro, pStrmInput, &pszExpansion); 1020 else 1021 rcExit = vbcppMacroExpandFunctionLike(pThis, pMacro, pStrmInput, &pszExpansion); 1022 if (rcExit == RTEXITCODE_SUCCESS) 1023 { 1024 rc = ScmStreamWrite(&pThis->StrmOutput, pszExpansion, strlen(pszExpansion)); 996 1025 if (RT_FAILURE(rc)) 997 1026 rcExit = vbcppError(pThis, "Output error: %Rrc", rc); 998 #endif 999 } 1000 else 1001 rcExit = vbcppError(pThis, "Expanding function macros is not implemented\n"); 1027 RTMemFree(pszExpansion); 1028 } 1002 1029 } 1003 1030 else 1004 1031 { 1005 1032 /* 1006 * Not a define, just output the text unchanged. 1033 * Not a macro or a function-macro name match but no invocation, just 1034 * output the text unchanged. 1007 1035 */ 1008 intrc = ScmStreamWrite(&pThis->StrmOutput, pchDefine, cchDefine);1036 rc = ScmStreamWrite(&pThis->StrmOutput, pchDefine, cchDefine); 1009 1037 if (RT_FAILURE(rc)) 1010 1038 rcExit = vbcppError(pThis, "Output error: %Rrc", rc); … … 1022 1050 * 1023 1051 * 1024 * D E F I N E S 1025 * D E F I N E S 1026 * D E F I N E S 1027 * D E F I N E S 1028 * D E F I N E S 1052 * D E F I N E S / M A C R O S 1053 * D E F I N E S / M A C R O S 1054 * D E F I N E S / M A C R O S 1055 * D E F I N E S / M A C R O S 1056 * D E F I N E S / M A C R O S 1029 1057 * 1030 1058 * … … 1041 1069 * @param cchDefine The length of the name. RTSTR_MAX is ok. 1042 1070 */ 1043 static bool vbcpp DefineExists(PVBCPP pThis, const char *pszDefine, size_t cchDefine)1071 static bool vbcppMacroExists(PVBCPP pThis, const char *pszDefine, size_t cchDefine) 1044 1072 { 1045 1073 return cchDefine > 0 … … 1058 1086 * @param cchDefine The length of the name. RTSTR_MAX is ok. 1059 1087 */ 1060 static PVBCPPDEF vbcpp DefineLookup(PVBCPP pThis, const char *pszDefine, size_t cchDefine)1088 static PVBCPPDEF vbcppMacroLookup(PVBCPP pThis, const char *pszDefine, size_t cchDefine) 1061 1089 { 1062 1090 if (!cchDefine) … … 1068 1096 1069 1097 1098 1099 static RTEXITCODE vbcppMacroExpandObjectLike(PVBCPP pThis, PVBCPPDEF pMacro, PSCMSTREAM pStrmInput, char **ppszExpansion) 1100 { 1101 *ppszExpansion = RTStrDup(pMacro->szValue); 1102 if (!*ppszExpansion) 1103 return vbcppError(pThis, "out of memory"); 1104 return RTEXITCODE_SUCCESS; 1105 } 1106 1107 1108 static RTEXITCODE vbcppMacroExpandFunctionLike(PVBCPP pThis, PVBCPPDEF pMacro, PSCMSTREAM pStrmInput, char **ppszExpansion) 1109 { 1110 *ppszExpansion = NULL; 1111 return vbcppError(pThis, "Expansion of function like macros is not yet supported"); 1112 } 1113 1114 1115 1070 1116 /** 1071 1117 * Frees a define. … … 1075 1121 * @param pvUser Unused. 1076 1122 */ 1077 static DECLCALLBACK(int) vbcpp FreeDefine(PRTSTRSPACECORE pStr, void *pvUser)1123 static DECLCALLBACK(int) vbcppMacroFree(PRTSTRSPACECORE pStr, void *pvUser) 1078 1124 { 1079 1125 RTMemFree(pStr); … … 1093 1139 * preprocessing run it will evaluate to undefined. 1094 1140 */ 1095 static RTEXITCODE vbcpp DefineUndef(PVBCPP pThis, const char *pszDefine, size_t cchDefine, bool fExplicitUndef)1141 static RTEXITCODE vbcppMacroUndef(PVBCPP pThis, const char *pszDefine, size_t cchDefine, bool fExplicitUndef) 1096 1142 { 1097 1143 PRTSTRSPACECORE pHit = RTStrSpaceGetN(&pThis->StrSpace, pszDefine, cchDefine); … … 1099 1145 { 1100 1146 RTStrSpaceRemove(&pThis->StrSpace, pHit->pszString); 1101 vbcpp FreeDefine(pHit, NULL);1147 vbcppMacroFree(pHit, NULL); 1102 1148 } 1103 1149 … … 1127 1173 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE + msg. 1128 1174 * @param pThis The C preprocessor instance. 1129 * @param p DefThe define to insert.1130 */ 1131 static RTEXITCODE vbcpp DefineInsert(PVBCPP pThis, PVBCPPDEF pDef)1175 * @param pMacro The define to insert. 1176 */ 1177 static RTEXITCODE vbcppMacroInsert(PVBCPP pThis, PVBCPPDEF pMacro) 1132 1178 { 1133 1179 /* 1134 1180 * Reject illegal macro names. 1135 1181 */ 1136 if (!strcmp(p Def->Core.pszString, "defined"))1137 { 1138 RTEXITCODE rcExit = vbcppError(pThis, "Cannot use '%s' as a macro name", p Def->Core.pszString);1139 vbcpp FreeDefine(&pDef->Core, NULL);1182 if (!strcmp(pMacro->Core.pszString, "defined")) 1183 { 1184 RTEXITCODE rcExit = vbcppError(pThis, "Cannot use '%s' as a macro name", pMacro->Core.pszString); 1185 vbcppMacroFree(&pMacro->Core, NULL); 1140 1186 return rcExit; 1141 1187 } … … 1145 1191 */ 1146 1192 if ( !pThis->fRespectSourceDefines 1147 && !p Def->fCmdLine)1193 && !pMacro->fCmdLine) 1148 1194 { 1149 1195 /* Ignore*/ 1150 vbcpp FreeDefine(&pDef->Core, NULL);1196 vbcppMacroFree(&pMacro->Core, NULL); 1151 1197 return RTEXITCODE_SUCCESS; 1152 1198 } … … 1155 1201 * Insert it and update the lead character hint bitmap. 1156 1202 */ 1157 if (RTStrSpaceInsert(&pThis->StrSpace, &p Def->Core))1158 VBCPP_BITMAP_SET(pThis->bmDefined, *p Def->Core.pszString);1203 if (RTStrSpaceInsert(&pThis->StrSpace, &pMacro->Core)) 1204 VBCPP_BITMAP_SET(pThis->bmDefined, *pMacro->Core.pszString); 1159 1205 else 1160 1206 { … … 1163 1209 * line take precendece. 1164 1210 */ 1165 PVBCPPDEF pOld = (PVBCPPDEF)RTStrSpaceGet(&pThis->StrSpace, p Def->Core.pszString); Assert(pOld);1211 PVBCPPDEF pOld = (PVBCPPDEF)RTStrSpaceGet(&pThis->StrSpace, pMacro->Core.pszString); Assert(pOld); 1166 1212 if ( pThis->fAllowRedefiningCmdLineDefines 1167 || p Def->fCmdLine == pOld->fCmdLine)1168 { 1169 if (p Def->fCmdLine)1170 RTMsgWarning("Redefining '%s' \n", pDef->Core.pszString);1213 || pMacro->fCmdLine == pOld->fCmdLine) 1214 { 1215 if (pMacro->fCmdLine) 1216 RTMsgWarning("Redefining '%s'", pMacro->Core.pszString); 1171 1217 1172 1218 RTStrSpaceRemove(&pThis->StrSpace, pOld->Core.pszString); 1173 vbcpp FreeDefine(&pOld->Core, NULL);1174 1175 bool fRc = RTStrSpaceInsert(&pThis->StrSpace, &p Def->Core);1219 vbcppMacroFree(&pOld->Core, NULL); 1220 1221 bool fRc = RTStrSpaceInsert(&pThis->StrSpace, &pMacro->Core); 1176 1222 Assert(fRc); 1177 1223 } 1178 1224 else 1179 1225 { 1180 RTMsgWarning("Ignoring redefinition of '%s' \n", pDef->Core.pszString);1181 vbcpp FreeDefine(&pDef->Core, NULL);1226 RTMsgWarning("Ignoring redefinition of '%s'", pMacro->Core.pszString); 1227 vbcppMacroFree(&pMacro->Core, NULL); 1182 1228 } 1183 1229 } … … 1200 1246 * @param fCmdLine Set if originating on the command line. 1201 1247 */ 1202 static RTEXITCODE vbcpp DefineAddFn(PVBCPP pThis, const char *pszDefine, size_t cchDefine,1203 1204 1205 1248 static RTEXITCODE vbcppMacroAddFn(PVBCPP pThis, const char *pszDefine, size_t cchDefine, 1249 const char *pszParams, size_t cchParams, 1250 const char *pszValue, size_t cchValue, 1251 bool fCmdLine) 1206 1252 1207 1253 { … … 1253 1299 + sizeof(const char *) * cArgs; 1254 1300 cbDef = RT_ALIGN_Z(cbDef, sizeof(const char *)); 1255 PVBCPPDEF p Def= (PVBCPPDEF)RTMemAlloc(cbDef);1256 if (!p Def)1301 PVBCPPDEF pMacro = (PVBCPPDEF)RTMemAlloc(cbDef); 1302 if (!pMacro) 1257 1303 return RTMsgErrorExit(RTEXITCODE_FAILURE, "out of memory"); 1258 1304 1259 char *pszDst = &p Def->szValue[cchValue + 1];1260 p Def->Core.pszString = pszDst;1305 char *pszDst = &pMacro->szValue[cchValue + 1]; 1306 pMacro->Core.pszString = pszDst; 1261 1307 memcpy(pszDst, pszDefine, cchDefine); 1262 1308 pszDst += cchDefine; 1263 1309 *pszDst++ = '\0'; 1264 p Def->fFunction = true;1265 p Def->fVarArg = false;1266 p Def->fCmdLine = fCmdLine;1267 p Def->cArgs = cArgs;1268 p Def->papszArgs = (const char **)((uintptr_t)pDef+ cbDef - sizeof(const char *) * cArgs);1269 VBCPP_BITMAP_EMPTY(p Def->bmArgs);1270 p Def->cchValue = cchValue;1271 memcpy(p Def->szValue, pszValue, cchValue);1272 p Def->szValue[cchValue] = '\0';1310 pMacro->fFunction = true; 1311 pMacro->fVarArg = false; 1312 pMacro->fCmdLine = fCmdLine; 1313 pMacro->cArgs = cArgs; 1314 pMacro->papszArgs = (const char **)((uintptr_t)pMacro + cbDef - sizeof(const char *) * cArgs); 1315 VBCPP_BITMAP_EMPTY(pMacro->bmArgs); 1316 pMacro->cchValue = cchValue; 1317 memcpy(pMacro->szValue, pszValue, cchValue); 1318 pMacro->szValue[cchValue] = '\0'; 1273 1319 1274 1320 /* … … 1294 1340 1295 1341 /* Found and argument. First character is already validated. */ 1296 p Def->papszArgs[iArg] = pszDst;1342 pMacro->papszArgs[iArg] = pszDst; 1297 1343 do 1298 1344 { … … 1303 1349 iArg++; 1304 1350 } 1305 Assert((uintptr_t)pszDst <= (uintptr_t)p Def->papszArgs);1306 1307 return vbcpp DefineInsert(pThis, pDef);1351 Assert((uintptr_t)pszDst <= (uintptr_t)pMacro->papszArgs); 1352 1353 return vbcppMacroInsert(pThis, pMacro); 1308 1354 } 1309 1355 … … 1321 1367 * @param fCmdLine Set if originating on the command line. 1322 1368 */ 1323 static RTEXITCODE vbcpp DefineAdd(PVBCPP pThis, const char *pszDefine, size_t cchDefine,1324 1369 static RTEXITCODE vbcppMacroAdd(PVBCPP pThis, const char *pszDefine, size_t cchDefine, 1370 const char *pszValue, size_t cchValue, bool fCmdLine) 1325 1371 { 1326 1372 /* … … 1357 1403 pszParams++; 1358 1404 cchParams -= 2; 1359 return vbcpp DefineAddFn(pThis, pszDefine, cchDefine, pszParams, cchParams, pszValue, cchValue, fCmdLine);1405 return vbcppMacroAddFn(pThis, pszDefine, cchDefine, pszParams, cchParams, pszValue, cchValue, fCmdLine); 1360 1406 } 1361 1407 … … 1366 1412 return RTEXITCODE_FAILURE; 1367 1413 1368 PVBCPPDEF p Def= (PVBCPPDEF)RTMemAlloc(RT_OFFSETOF(VBCPPDEF, szValue[cchValue + 1 + cchDefine + 1]));1369 if (!p Def)1414 PVBCPPDEF pMacro = (PVBCPPDEF)RTMemAlloc(RT_OFFSETOF(VBCPPDEF, szValue[cchValue + 1 + cchDefine + 1])); 1415 if (!pMacro) 1370 1416 return RTMsgErrorExit(RTEXITCODE_FAILURE, "out of memory"); 1371 1417 1372 p Def->Core.pszString = &pDef->szValue[cchValue + 1];1373 memcpy((char *)p Def->Core.pszString, pszDefine, cchDefine);1374 ((char *)p Def->Core.pszString)[cchDefine] = '\0';1375 p Def->fFunction = false;1376 p Def->fVarArg = false;1377 p Def->fCmdLine = fCmdLine;1378 p Def->cArgs = 0;1379 p Def->papszArgs = NULL;1380 VBCPP_BITMAP_EMPTY(p Def->bmArgs);1381 p Def->cchValue = cchValue;1382 memcpy(p Def->szValue, pszValue, cchValue);1383 p Def->szValue[cchValue] = '\0';1384 1385 return vbcpp DefineInsert(pThis, pDef);1418 pMacro->Core.pszString = &pMacro->szValue[cchValue + 1]; 1419 memcpy((char *)pMacro->Core.pszString, pszDefine, cchDefine); 1420 ((char *)pMacro->Core.pszString)[cchDefine] = '\0'; 1421 pMacro->fFunction = false; 1422 pMacro->fVarArg = false; 1423 pMacro->fCmdLine = fCmdLine; 1424 pMacro->cArgs = 0; 1425 pMacro->papszArgs = NULL; 1426 VBCPP_BITMAP_EMPTY(pMacro->bmArgs); 1427 pMacro->cchValue = cchValue; 1428 memcpy(pMacro->szValue, pszValue, cchValue); 1429 pMacro->szValue[cchValue] = '\0'; 1430 1431 return vbcppMacroInsert(pThis, pMacro); 1386 1432 } 1387 1433 … … 1396 1442 * started (for pass thru). 1397 1443 */ 1398 static RTEXITCODE vbcpp ProcessDefine(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)1444 static RTEXITCODE vbcppDirectiveDefine(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 1399 1445 { 1400 1446 /* … … 1466 1512 */ 1467 1513 if (pchParams) 1468 rcExit = vbcpp DefineAddFn(pThis, pchDefine, cchDefine, pchParams, cchParams, pchValue, cchValue, false);1514 rcExit = vbcppMacroAddFn(pThis, pchDefine, cchDefine, pchParams, cchParams, pchValue, cchValue, false); 1469 1515 else 1470 rcExit = vbcpp DefineAdd(pThis, pchDefine, cchDefine, pchValue, cchValue, false);1516 rcExit = vbcppMacroAdd(pThis, pchDefine, cchDefine, pchValue, cchValue, false); 1471 1517 1472 1518 /* … … 1506 1552 * started (for pass thru). 1507 1553 */ 1508 static RTEXITCODE vbcpp ProcessUndef(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)1554 static RTEXITCODE vbcppDirectiveUndef(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 1509 1555 { 1510 1556 return vbcppError(pThis, "Not implemented %s", __FUNCTION__); … … 1770 1816 1771 1817 /* Does it exist? Will save a whole lot of trouble if it doesn't. */ 1772 PVBCPPDEF p Def = vbcppDefineLookup(pThis, &pszExpr[offIdentifier], cchIdentifier);1773 if (p Def)1818 PVBCPPDEF pMacro = vbcppMacroLookup(pThis, &pszExpr[offIdentifier], cchIdentifier); 1819 if (pMacro) 1774 1820 { 1775 1821 /* Skip white space and check for parenthesis. */ … … 1787 1833 { 1788 1834 /* Expand simple define if found. */ 1789 if (p Def->cchValue + 2 < cchIdentifier)1835 if (pMacro->cchValue + 2 < cchIdentifier) 1790 1836 { 1791 size_t offDelta = cchIdentifier - p Def->cchValue - 2;1837 size_t offDelta = cchIdentifier - pMacro->cchValue - 2; 1792 1838 memmove(&pszExpr[offIdentifier], &pszExpr[offIdentifier + offDelta], 1793 1839 cchExpr - offIdentifier - offDelta + 1); /* Lazy bird is moving too much! */ 1794 1840 cchExpr -= offDelta; 1795 1841 } 1796 else if (p Def->cchValue + 2 > cchIdentifier)1842 else if (pMacro->cchValue + 2 > cchIdentifier) 1797 1843 { 1798 size_t offDelta = p Def->cchValue + 2 - cchIdentifier;1844 size_t offDelta = pMacro->cchValue + 2 - cchIdentifier; 1799 1845 if (cchExpr + offDelta + 1 > cbExprAlloc) 1800 1846 { … … 1819 1865 standard compliant this is... */ 1820 1866 pszExpr[offIdentifier] = ' '; 1821 memcpy(&pszExpr[offIdentifier + 1], p Def->szValue, pDef->cchValue);1822 pszExpr[offIdentifier + 1 + p Def->cchValue] = ' ';1867 memcpy(&pszExpr[offIdentifier + 1], pMacro->szValue, pMacro->cchValue); 1868 pszExpr[offIdentifier + 1 + pMacro->cchValue] = ' '; 1823 1869 1824 1870 /* Restart parsing at the inserted macro. */ … … 1935 1981 * @param enmKind The kind of directive we're processing. 1936 1982 */ 1937 static RTEXITCODE vbcpp ProcessIfOrElif(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart,1983 static RTEXITCODE vbcppDirectiveIfOrElif(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart, 1938 1984 VBCPPCONDKIND enmKind) 1939 1985 { … … 2036 2082 * started (for pass thru). 2037 2083 */ 2038 static RTEXITCODE vbcpp ProcessIfDef(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)2084 static RTEXITCODE vbcppDirectiveIfDef(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2039 2085 { 2040 2086 /* … … 2055 2101 */ 2056 2102 VBCPPEVAL enmEval; 2057 if (vbcpp DefineExists(pThis, pchDefine, cchDefine))2103 if (vbcppMacroExists(pThis, pchDefine, cchDefine)) 2058 2104 enmEval = kVBCppEval_True; 2059 2105 else if ( !pThis->fUndecidedConditionals … … 2082 2128 * started (for pass thru). 2083 2129 */ 2084 static RTEXITCODE vbcpp ProcessIfNDef(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)2130 static RTEXITCODE vbcppDirectiveIfNDef(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2085 2131 { 2086 2132 /* … … 2101 2147 */ 2102 2148 VBCPPEVAL enmEval; 2103 if (vbcpp DefineExists(pThis, pchDefine, cchDefine))2149 if (vbcppMacroExists(pThis, pchDefine, cchDefine)) 2104 2150 enmEval = kVBCppEval_False; 2105 2151 else if ( !pThis->fUndecidedConditionals … … 2128 2174 * started (for pass thru). 2129 2175 */ 2130 static RTEXITCODE vbcpp ProcessElse(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)2176 static RTEXITCODE vbcppDirectiveElse(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2131 2177 { 2132 2178 /* … … 2191 2237 * started (for pass thru). 2192 2238 */ 2193 static RTEXITCODE vbcpp ProcessEndif(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)2239 static RTEXITCODE vbcppDirectiveEndif(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2194 2240 { 2195 2241 /* … … 2282 2328 * started (for pass thru). 2283 2329 */ 2284 static RTEXITCODE vbcpp ProcessInclude(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)2330 static RTEXITCODE vbcppDirectiveInclude(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2285 2331 { 2286 2332 /* … … 2389 2435 * started (for pass thru). 2390 2436 */ 2391 static RTEXITCODE vbcpp ProcessPragma(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart)2437 static RTEXITCODE vbcppDirectivePragma(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2392 2438 { 2393 2439 /* … … 2441 2487 2442 2488 /** 2443 * Processes a abbreviated line number directive.2489 * Processes an error directive. 2444 2490 * 2445 2491 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg. … … 2449 2495 * started (for pass thru). 2450 2496 */ 2451 static RTEXITCODE vbcppProcessLineNo(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2497 static RTEXITCODE vbcppDirectiveError(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2498 { 2499 return vbcppError(pThis, "Hit an #error"); 2500 } 2501 2502 2503 /** 2504 * Processes a abbreviated line number directive. 2505 * 2506 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg. 2507 * @param pThis The C preprocessor instance. 2508 * @param pStrmInput The input stream. 2509 * @param offStart The stream position where the directive 2510 * started (for pass thru). 2511 */ 2512 static RTEXITCODE vbcppDirectiveLineNo(PVBCPP pThis, PSCMSTREAM pStrmInput, size_t offStart) 2452 2513 { 2453 2514 return vbcppError(pThis, "Not implemented: %s", __FUNCTION__); … … 2462 2523 * @param pStrmInput The input stream. 2463 2524 */ 2464 static RTEXITCODE vbcpp ProcessLineNoShort(PVBCPP pThis, PSCMSTREAM pStrmInput)2525 static RTEXITCODE vbcppDirectiveLineNoShort(PVBCPP pThis, PSCMSTREAM pStrmInput) 2465 2526 { 2466 2527 return vbcppError(pThis, "Not implemented: %s", __FUNCTION__); … … 2490 2551 #define IS_DIRECTIVE(a_sz) ( sizeof(a_sz) - 1 == cchDirective && strncmp(pchDirective, a_sz, sizeof(a_sz) - 1) == 0) 2491 2552 if (IS_DIRECTIVE("if")) 2492 rcExit = vbcpp ProcessIfOrElif(pThis, pStrmInput, offStart, kVBCppCondKind_If);2553 rcExit = vbcppDirectiveIfOrElif(pThis, pStrmInput, offStart, kVBCppCondKind_If); 2493 2554 else if (IS_DIRECTIVE("elif")) 2494 rcExit = vbcpp ProcessIfOrElif(pThis, pStrmInput, offStart, kVBCppCondKind_ElIf);2555 rcExit = vbcppDirectiveIfOrElif(pThis, pStrmInput, offStart, kVBCppCondKind_ElIf); 2495 2556 else if (IS_DIRECTIVE("ifdef")) 2496 rcExit = vbcpp ProcessIfDef(pThis, pStrmInput, offStart);2557 rcExit = vbcppDirectiveIfDef(pThis, pStrmInput, offStart); 2497 2558 else if (IS_DIRECTIVE("ifndef")) 2498 rcExit = vbcpp ProcessIfNDef(pThis, pStrmInput, offStart);2559 rcExit = vbcppDirectiveIfNDef(pThis, pStrmInput, offStart); 2499 2560 else if (IS_DIRECTIVE("else")) 2500 rcExit = vbcpp ProcessElse(pThis, pStrmInput, offStart);2561 rcExit = vbcppDirectiveElse(pThis, pStrmInput, offStart); 2501 2562 else if (IS_DIRECTIVE("endif")) 2502 rcExit = vbcpp ProcessEndif(pThis, pStrmInput, offStart);2563 rcExit = vbcppDirectiveEndif(pThis, pStrmInput, offStart); 2503 2564 else if (!pThis->fIf0Mode) 2504 2565 { 2505 2566 if (IS_DIRECTIVE("include")) 2506 rcExit = vbcpp ProcessInclude(pThis, pStrmInput, offStart);2567 rcExit = vbcppDirectiveInclude(pThis, pStrmInput, offStart); 2507 2568 else if (IS_DIRECTIVE("define")) 2508 rcExit = vbcpp ProcessDefine(pThis, pStrmInput, offStart);2569 rcExit = vbcppDirectiveDefine(pThis, pStrmInput, offStart); 2509 2570 else if (IS_DIRECTIVE("undef")) 2510 rcExit = vbcpp ProcessUndef(pThis, pStrmInput, offStart);2571 rcExit = vbcppDirectiveUndef(pThis, pStrmInput, offStart); 2511 2572 else if (IS_DIRECTIVE("pragma")) 2512 rcExit = vbcppProcessPragma(pThis, pStrmInput, offStart); 2573 rcExit = vbcppDirectivePragma(pThis, pStrmInput, offStart); 2574 else if (IS_DIRECTIVE("error")) 2575 rcExit = vbcppDirectiveError(pThis, pStrmInput, offStart); 2513 2576 else if (IS_DIRECTIVE("line")) 2514 rcExit = vbcpp ProcessLineNo(pThis, pStrmInput, offStart);2577 rcExit = vbcppDirectiveLineNo(pThis, pStrmInput, offStart); 2515 2578 else 2516 2579 rcExit = vbcppError(pThis, "Unknown preprocessor directive '#%.*s'", cchDirective, pchDirective); … … 2523 2586 unsigned ch = ScmStreamPeekCh(pStrmInput); 2524 2587 if (RT_C_IS_DIGIT(ch)) 2525 rcExit = vbcpp ProcessLineNoShort(pThis, pStrmInput);2588 rcExit = vbcppDirectiveLineNoShort(pThis, pStrmInput); 2526 2589 else 2527 2590 rcExit = vbcppError(pThis, "Malformed preprocessor directive"); … … 2605 2668 { 2606 2669 if (ch == '"') 2607 rcExit = vbcppProcess DoubleQuotedString(pThis, pStrmInput);2670 rcExit = vbcppProcessStringLitteral(pThis, pStrmInput); 2608 2671 else if (ch == '\'') 2609 rcExit = vbcppProcess SingledQuotedString(pThis, pStrmInput);2672 rcExit = vbcppProcessCharacterConstant(pThis, pStrmInput); 2610 2673 else if (vbcppIsCIdentifierLeadChar(ch)) 2611 rcExit = vbcppProcessCWord(pThis, pStrmInput, ch); 2674 rcExit = vbcppProcessIdentifier(pThis, pStrmInput, ch); 2675 else if (RT_C_IS_DIGIT(ch)) 2676 rcExit = vbcppProcessNumber(pThis, pStrmInput, ch); 2612 2677 else 2613 2678 rcExit = vbcppOutputCh(pThis, ch); … … 2784 2849 const char *pszEqual = strchr(ValueUnion.psz, '='); 2785 2850 if (pszEqual) 2786 rcExit = vbcpp DefineAdd(pThis, ValueUnion.psz, pszEqual - ValueUnion.psz, pszEqual + 1, RTSTR_MAX, true);2851 rcExit = vbcppMacroAdd(pThis, ValueUnion.psz, pszEqual - ValueUnion.psz, pszEqual + 1, RTSTR_MAX, true); 2787 2852 else 2788 rcExit = vbcpp DefineAdd(pThis, ValueUnion.psz, RTSTR_MAX, "1", 1, true);2853 rcExit = vbcppMacroAdd(pThis, ValueUnion.psz, RTSTR_MAX, "1", 1, true); 2789 2854 if (rcExit != RTEXITCODE_SUCCESS) 2790 2855 return rcExit; … … 2799 2864 2800 2865 case 'U': 2801 rcExit = vbcpp DefineUndef(pThis, ValueUnion.psz, RTSTR_MAX, true);2866 rcExit = vbcppMacroUndef(pThis, ValueUnion.psz, RTSTR_MAX, true); 2802 2867 break; 2803 2868 … … 2881 2946 ScmStreamDelete(&pThis->StrmOutput); 2882 2947 2883 RTStrSpaceDestroy(&pThis->StrSpace, vbcpp FreeDefine, NULL);2948 RTStrSpaceDestroy(&pThis->StrSpace, vbcppMacroFree, NULL); 2884 2949 pThis->StrSpace = NULL; 2885 2950 … … 2908 2973 pThis->StrSpace = NULL; 2909 2974 pThis->UndefStrSpace = NULL; 2910 pThis->pExpStack = NULL;2911 pThis->cExpStackDepth = 0;2912 2975 pThis->cCondStackDepth = 0; 2913 2976 pThis->pCondStack = NULL; … … 2916 2979 pThis->fMaybePreprocessorLine = true; 2917 2980 VBCPP_BITMAP_EMPTY(pThis->bmDefined); 2918 VBCPP_BITMAP_EMPTY(pThis->bmArgs);2919 2981 pThis->cCondStackDepth = 0; 2920 2982 pThis->pInputStack = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.