VirtualBox

Changeset 94905 in vbox


Ignore:
Timestamp:
May 7, 2022 4:10:49 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
151312
Message:

scm: Introduce a check to force the use of either hrc for COM status codes or vrc for IPRT ones instead of using rc for both causing confusion when to use which, bugref:10223

Location:
trunk/src/bldprogs
Files:
3 edited

Legend:

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

    r94038 r94905  
    9393    SCMOPT_UNRESTRICTED_ASM_MEM_PAGE_USE,
    9494    SCMOPT_NO_PAGE_RESTRICTIONS,
     95    SCMOPT_NO_RC_USE,
     96    SCMOPT_UNRESTRICTED_RC_USE,
    9597    SCMOPT_UPDATE_COPYRIGHT_YEAR,
    9698    SCMOPT_NO_UPDATE_COPYRIGHT_YEAR,
     
    202204    /* .fOnlyGuestHostPage = */                     false,
    203205    /* .fNoASMMemPageUse = */                       false,
     206    /* .fOnlyHrcVrcInsteadOfRc */                   false,
    204207    /* .fUpdateCopyrightYear = */                   false,
    205208    /* .fExternalCopyright = */                     false,
     
    259262    { "--no-ASMMemPage-use",                SCMOPT_NO_ASM_MEM_PAGE_USE,             RTGETOPT_REQ_NOTHING },
    260263    { "--unrestricted-ASMMemPage-use",      SCMOPT_UNRESTRICTED_ASM_MEM_PAGE_USE,   RTGETOPT_REQ_NOTHING },
     264    { "--no-rc-use",                        SCMOPT_NO_RC_USE,                       RTGETOPT_REQ_NOTHING },
     265    { "--unrestricted-rc-use",              SCMOPT_UNRESTRICTED_RC_USE,             RTGETOPT_REQ_NOTHING },
    261266    { "--update-copyright-year",            SCMOPT_UPDATE_COPYRIGHT_YEAR,           RTGETOPT_REQ_NOTHING },
    262267    { "--no-update-copyright-year",         SCMOPT_NO_UPDATE_COPYRIGHT_YEAR,        RTGETOPT_REQ_NOTHING },
     
    323328SCM_REWRITER_CFG(g_UnicodeChecks,                   "unicode-checks",               rewrite_UnicodeChecks);
    324329SCM_REWRITER_CFG(g_PageChecks,                      "page-checks",                  rewrite_PageChecks);
     330SCM_REWRITER_CFG(g_ForceHrcVrcInsteadOfRc,          "force-hrc-vrc-no-rc",          rewrite_ForceHrcVrcInsteadOfRc);
    325331SCM_REWRITER_CFG(g_Copyright_CstyleComment,         "copyright-c-style",            rewrite_Copyright_CstyleComment);
    326332SCM_REWRITER_CFG(g_Copyright_HashComment,           "copyright-hash-style",         rewrite_Copyright_HashComment);
     
    368374    &g_UnicodeChecks,
    369375    &g_PageChecks,
     376    &g_ForceHrcVrcInsteadOfRc,
    370377    &g_C_and_CPP,
    371378};
     
    416423    &g_UnicodeChecks,
    417424    &g_PageChecks,
     425    &g_ForceHrcVrcInsteadOfRc,
    418426    &g_Copyright_CstyleComment,
    419427    &g_FixFlowerBoxMarkers,
     
    434442    &g_UnicodeChecks,
    435443    &g_PageChecks,
     444    &g_ForceHrcVrcInsteadOfRc,
    436445    &g_Copyright_CstyleComment,
    437446    /// @todo &g_FixFlowerBoxMarkers,
     
    11961205        case SCMOPT_UNRESTRICTED_ASM_MEM_PAGE_USE:
    11971206            pSettings->fNoASMMemPageUse = false;
     1207            return VINF_SUCCESS;
     1208
     1209        case SCMOPT_NO_RC_USE:
     1210            pSettings->fOnlyHrcVrcInsteadOfRc = true;
     1211            return VINF_SUCCESS;
     1212        case SCMOPT_UNRESTRICTED_RC_USE:
     1213            pSettings->fOnlyHrcVrcInsteadOfRc = false;
    11981214            return VINF_SUCCESS;
    11991215
     
    29282944                         g_Defaults.fNoASMMemPageUse);
    29292945                break;
     2946            case SCMOPT_NO_RC_USE:
     2947                RTPrintf("      No rc declaration allowed, must instead use\n"
     2948                         "      vrc for IPRT status codes and hrc for COM status codes.  Default: %RTbool\n",
     2949                         g_Defaults.fOnlyHrcVrcInsteadOfRc);
     2950                break;
    29302951            case SCMOPT_UPDATE_COPYRIGHT_YEAR:
    29312952                RTPrintf("      Update the copyright year.  Default: %RTbool\n", g_Defaults.fUpdateCopyrightYear);
  • trunk/src/bldprogs/scm.h

    r93556 r94905  
    254254FNSCMREWRITER rewrite_UnicodeChecks;
    255255FNSCMREWRITER rewrite_PageChecks;
     256FNSCMREWRITER rewrite_ForceHrcVrcInsteadOfRc;
    256257FNSCMREWRITER rewrite_Copyright_CstyleComment;
    257258FNSCMREWRITER rewrite_Copyright_HashComment;
     
    361362    /** No ASMMemIsZeroPage or ASMMemZeroPage calls allowed (C/C++). */
    362363    bool            fNoASMMemPageUse;
     364    /** No rc declarations allowed, only hrc or vrc depending on the result type. */
     365    bool            fOnlyHrcVrcInsteadOfRc;
    363366
    364367    /** Update the copyright year. */
  • trunk/src/bldprogs/scmrw.cpp

    r93945 r94905  
    33343334
    33353335/**
     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 */
     3346bool 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/**
    33363424 * Rewrite a C/C++ source or header file.
    33373425 *
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