Changeset 94905 in vbox for trunk/src/bldprogs/scmrw.cpp
- Timestamp:
- May 7, 2022 4:10:49 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scmrw.cpp
r93945 r94905 3334 3334 3335 3335 /** 3336 * Checks for usage of rc in code instead of vrc for IPRT status codes (int) and hrc for COM 3337 * status codes (HRESULT). 3338 * 3339 * @returns true if modifications were made, false if not. 3340 * @param pIn The input stream. 3341 * @param pOut The output stream. 3342 * @param pSettings The settings. 3343 * 3344 * @note Used in Main to avoid ambiguity when just using rc. 3345 */ 3346 bool rewrite_ForceHrcVrcInsteadOfRc(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings) 3347 { 3348 RT_NOREF(pOut); 3349 if (!pSettings->fOnlyHrcVrcInsteadOfRc) 3350 return false; 3351 3352 static const SCMMATCHWORD s_aHresultVrc[] = 3353 { 3354 { RT_STR_TUPLE("HRESULT"), 0, true, false }, 3355 { RT_STR_TUPLE("vrc"), 1, true, false } 3356 }; 3357 3358 static const SCMMATCHWORD s_aIntHrc[] = 3359 { 3360 { RT_STR_TUPLE("int"), 0, true, false }, 3361 { RT_STR_TUPLE("hrc"), 1, true, false } 3362 }; 3363 3364 uint32_t iLine = 0; 3365 SCMEOL enmEol; 3366 size_t cchLine; 3367 const char *pchLine; 3368 RTERRINFOSTATIC ErrInfo; 3369 while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL) 3370 { 3371 iLine++; 3372 3373 /* Look for forbidden declarations first. */ 3374 size_t offNext = 0; 3375 int rc = ScmMatchWords(pchLine, cchLine, s_aHresultVrc, RT_ELEMENTS(s_aHresultVrc), 3376 &offNext, NULL /*paIdentifiers*/, RTErrInfoInitStatic(&ErrInfo)); 3377 if (RT_SUCCESS(rc)) 3378 { 3379 ScmFixManually(pState, "%u:%zu: 'HRESULT vrc' is not allowed! Use 'HRESULT hrc' instead.\n", 3380 iLine, offNext); 3381 continue; 3382 } 3383 3384 rc = ScmMatchWords(pchLine, cchLine, s_aIntHrc, RT_ELEMENTS(s_aIntHrc), 3385 &offNext, NULL /*paIdentifiers*/, RTErrInfoInitStatic(&ErrInfo)); 3386 if (RT_SUCCESS(rc)) 3387 { 3388 ScmFixManually(pState, "%u:%zu: 'int hrc' is not allowed! Use 'int vrc' instead.\n", 3389 iLine, offNext); 3390 continue; 3391 } 3392 3393 const RTSTRTUPLE RcTuple = { RT_STR_TUPLE("rc") }; 3394 size_t const cchWord = RcTuple.cch; 3395 if (cchLine >= cchWord) 3396 { 3397 const char *pchHit = (const char *)memchr(pchLine, *RcTuple.psz, cchLine); 3398 while (pchHit) 3399 { 3400 size_t cchLeft = (uintptr_t)&pchLine[cchLine] - (uintptr_t)pchHit; 3401 if ( cchLeft >= cchWord 3402 && memcmp(pchHit, RcTuple.psz, cchWord) == 0 3403 && ( pchHit == pchLine 3404 || !ScmIsCIdentifierChar(pchHit[-1])) 3405 && ( cchLeft == cchWord 3406 || !ScmIsCIdentifierChar(pchHit[cchWord])) ) 3407 ScmFixManually(pState, "%u:%zu: %s is not allowed! Use hrc or vrc instead.\n", 3408 iLine, pchHit - pchLine + 1, RcTuple.psz); 3409 3410 /* next */ 3411 cchLeft -= 1; 3412 if (cchLeft < cchWord) 3413 break; 3414 pchHit = (const char *)memchr(pchHit + 1, *RcTuple.psz, cchLeft); 3415 } 3416 } 3417 } 3418 3419 return false; 3420 } 3421 3422 3423 /** 3336 3424 * Rewrite a C/C++ source or header file. 3337 3425 *
Note:
See TracChangeset
for help on using the changeset viewer.