Changeset 57498 in vbox for trunk/src/bldprogs/VBoxCompilerPlugInsCommon.cpp
- Timestamp:
- Aug 21, 2015 2:05:16 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/VBoxCompilerPlugInsCommon.cpp
r57002 r57498 31 31 #define MY_ISDIGIT(c) ((c) >= '0' && (c) <= '9') 32 32 33 /** @name RTSTR_Z_XXX - Size modifiers 34 * @{ */ 35 #define RTSTR_Z_DEFAULT UINT16_C(0x0001) 36 #define RTSTR_Z_LONG UINT16_C(0x0002) /**< l */ 37 #define RTSTR_Z_LONGLONG UINT16_C(0x0004) /**< ll, L, q. */ 38 #define RTSTR_Z_HALF UINT16_C(0x0008) /**< h */ 39 #define RTSTR_Z_HALFHALF UINT16_C(0x0010) /**< hh (internally H) */ 40 #define RTSTR_Z_SIZE UINT16_C(0x0020) /**< z */ 41 #define RTSTR_Z_PTRDIFF UINT16_C(0x0040) /**< t */ 42 #define RTSTR_Z_INTMAX UINT16_C(0x0080) /**< j */ 43 #define RTSTR_Z_MS_I32 UINT16_C(0x1000) /**< I32 */ 44 #define RTSTR_Z_MS_I64 UINT16_C(0x2000) /**< I64 */ 45 #define RTSTR_Z_ALL_INT UINT16_C(0x30fe) /**< short hand for integers. */ 46 /** @} */ 47 48 49 /** @name VFMTCHKTYPE_F_XXX - Type flags. 50 * @{ */ 51 /** Pointers type. */ 52 #define VFMTCHKTYPE_F_PTR UINT8_C(0x01) 53 /** Both const and non-const pointer types. */ 54 #define VFMTCHKTYPE_F_CPTR (UINT8_C(0x02) | VFMTCHKTYPE_F_PTR) 55 /** @} */ 56 57 /** @name VFMTCHKTYPE_Z_XXX - Special type sizes 58 * @{ */ 59 #define VFMTCHKTYPE_Z_CHAR UINT8_C(0xe0) 60 #define VFMTCHKTYPE_Z_SHORT UINT8_C(0xe1) 61 #define VFMTCHKTYPE_Z_INT UINT8_C(0xe2) 62 #define VFMTCHKTYPE_Z_LONG UINT8_C(0xe3) 63 #define VFMTCHKTYPE_Z_LONGLONG UINT8_C(0xe4) 64 #define VFMTCHKTYPE_Z_PTR UINT8_C(0xe5) /**< ASSUMED to be the same for 'void *', 'size_t' and 'ptrdiff_t'. */ 65 /** @} */ 66 67 /** @name VFMTCHKTYPE_NM_XXX - Standard C type names. 68 * @{ */ 69 #define VFMTCHKTYPE_NM_INT "int" 70 #define VFMTCHKTYPE_NM_UINT "unsigned int" 71 #define VFMTCHKTYPE_NM_LONG "long" 72 #define VFMTCHKTYPE_NM_ULONG "unsigned long" 73 #define VFMTCHKTYPE_NM_LONGLONG "long long" 74 #define VFMTCHKTYPE_NM_ULONGLONG "unsigned long long" 75 #define VFMTCHKTYPE_NM_SHORT "short" 76 #define VFMTCHKTYPE_NM_USHORT "unsigned short" 77 #define VFMTCHKTYPE_NM_CHAR "char" 78 #define VFMTCHKTYPE_NM_SCHAR "signed char" 79 #define VFMTCHKTYPE_NM_UCHAR "unsigned char" 80 /** @} */ 81 82 83 /** @name VFMTCHKDESC_F_XXX - Format descriptor flags. 84 * @{ */ 85 #define VFMTCHKDESC_F_NONE UINT32_C(0) 86 #define VFMTCHKDESC_F_SIGNED RT_BIT_32(0) 87 #define VFMTCHKDESC_F_UNSIGNED RT_BIT_32(1) 88 /** @} */ 89 90 91 /********************************************************************************************************************************* 92 * Structures and Typedefs * 93 *********************************************************************************************************************************/ 94 /** 95 * Format check type entry. 96 */ 97 typedef struct VFMTCHKTYPE 98 { 99 /** The format size flag(s). */ 100 uint16_t fSize; 101 /** The argument size. */ 102 uint8_t cbArg; 103 /** Argument flags (VFMTCHKTYPE_F_XXX). */ 104 uint8_t fFlags; 105 /** List of strings with acceptable types, if NULL only check the sizes. */ 106 const char *pszzTypeNames; 107 } VFMTCHKTYPE; 108 /** Pointer to a read only format check type entry. */ 109 typedef VFMTCHKTYPE const *PCVFMTCHKTYPE; 110 111 /** For use as an initializer in VFMTCHKDESK where it indicates that 112 * everything is covered by VFMTCHKDESC::paMoreTypes. Useful for repeating 113 * stuff. */ 114 #define VFMTCHKTYPE_USE_MORE_TYPES { 0, 0, 0, NULL } 115 116 /** 117 * Format type descriptor. 118 */ 119 typedef struct VFMTCHKDESC 120 { 121 /** The format type. */ 122 const char *pszType; 123 /** Recognized format flags (RTSTR_F_XXX). */ 124 uint16_t fFmtFlags; 125 /** Recognized format sizes (RTSTR_Z_XXX). */ 126 uint16_t fFmtSize; 127 /** Flags (VFMTCHKDESC_F_XXX). */ 128 uint32_t fFlags; 129 /** Primary type. */ 130 VFMTCHKTYPE Type; 131 /** More recognized types (optional). */ 132 PCVFMTCHKTYPE paMoreTypes; 133 } VFMTCHKDESC; 134 typedef VFMTCHKDESC const *PCVFMTCHKDESC; 135 136 137 /********************************************************************************************************************************* 138 * Global Variables * 139 *********************************************************************************************************************************/ 140 /** Integer type specs for 'x', 'd', 'u', 'i', ++ 141 * 142 * @todo RTUINT32U and friends... The whole type matching thing. 143 */ 144 static VFMTCHKTYPE const g_aIntTypes[] = 145 { 146 { RTSTR_Z_DEFAULT, VFMTCHKTYPE_Z_INT, 0, VFMTCHKTYPE_NM_INT "\0" VFMTCHKTYPE_NM_UINT "\0" }, 147 { RTSTR_Z_LONG, VFMTCHKTYPE_Z_LONG, 0, VFMTCHKTYPE_NM_LONG "\0" VFMTCHKTYPE_NM_ULONG "\0" }, 148 { RTSTR_Z_LONGLONG, VFMTCHKTYPE_Z_LONGLONG, 0, VFMTCHKTYPE_NM_LONGLONG "\0" VFMTCHKTYPE_NM_ULONGLONG "\0" }, 149 { RTSTR_Z_HALF, VFMTCHKTYPE_Z_SHORT, 0, VFMTCHKTYPE_NM_SHORT "\0" VFMTCHKTYPE_NM_USHORT "\0" }, 150 { RTSTR_Z_HALFHALF, VFMTCHKTYPE_Z_CHAR, 0, VFMTCHKTYPE_NM_SCHAR "\0" VFMTCHKTYPE_NM_UCHAR "\0" VFMTCHKTYPE_NM_CHAR "\0" }, 151 { RTSTR_Z_SIZE, VFMTCHKTYPE_Z_PTR, 0, "size_t\0" "RTUINTPTR\0" "RTINTPTR\0" }, 152 { RTSTR_Z_PTRDIFF, VFMTCHKTYPE_Z_PTR, 0, "ptrdiff_t\0" "RTUINTPTR\0" "RTINTPTR\0" }, 153 { RTSTR_Z_INTMAX, VFMTCHKTYPE_Z_PTR, 0, "uint64_t\0" "int64_t\0" "RTUINT64U\0" VFMTCHKTYPE_NM_LONGLONG "\0" VFMTCHKTYPE_NM_ULONGLONG "\0" }, 154 { RTSTR_Z_MS_I32, sizeof(uint32_t), 0, "uint32_t\0" "int32_t\0" "RTUINT32U\0" }, 155 { RTSTR_Z_MS_I64, sizeof(uint64_t), 0, "uint64_t\0" "int64_t\0" "RTUINT64U\0" }, 156 }; 157 158 /** String type specs for 's', 'ls' and 'Ls'. 159 */ 160 static VFMTCHKTYPE const g_aStringTypes[] = 161 { 162 { RTSTR_Z_DEFAULT, VFMTCHKTYPE_Z_PTR, VFMTCHKTYPE_F_CPTR, VFMTCHKTYPE_NM_CHAR "\0" }, 163 { RTSTR_Z_LONG, VFMTCHKTYPE_Z_PTR, VFMTCHKTYPE_F_CPTR, "RTUTF16\0" }, 164 { RTSTR_Z_LONGLONG, VFMTCHKTYPE_Z_PTR, VFMTCHKTYPE_F_CPTR, "RTUNICP\0" }, 165 }; 166 167 static VFMTCHKDESC const g_aFmtDescs[] = 168 { 169 { "s", 170 RTSTR_F_LEFT | RTSTR_F_WIDTH | RTSTR_F_PRECISION, 171 RTSTR_Z_DEFAULT | RTSTR_Z_LONG | RTSTR_Z_LONGLONG, 172 VFMTCHKDESC_F_UNSIGNED, 173 VFMTCHKTYPE_USE_MORE_TYPES, 174 g_aStringTypes 175 }, 176 { "x", 177 RTSTR_F_LEFT | RTSTR_F_ZEROPAD | RTSTR_F_SPECIAL | RTSTR_F_WIDTH | RTSTR_F_PRECISION, 178 RTSTR_Z_ALL_INT, 179 VFMTCHKDESC_F_UNSIGNED, 180 VFMTCHKTYPE_USE_MORE_TYPES, 181 g_aIntTypes 182 }, 183 { "RX32", 184 RTSTR_F_LEFT | RTSTR_F_ZEROPAD | RTSTR_F_SPECIAL | RTSTR_F_WIDTH | RTSTR_F_PRECISION, 185 RTSTR_Z_ALL_INT, 186 VFMTCHKDESC_F_UNSIGNED, 187 { RTSTR_Z_DEFAULT, sizeof(uint32_t), 0, "uint32_t\0" "int32_t\0" }, 188 NULL 189 }, 190 191 192 193 }; 33 194 34 195 … … 75 236 * Flags 76 237 */ 77 uint32_t fF lags = 0;238 uint32_t fFmtFlags = 0; 78 239 for (;;) 79 240 { … … 91 252 if (!fFlag) 92 253 break; 93 if (fF lags & fFlag)254 if (fFmtFlags & fFlag) 94 255 VFmtChkWarnFmt(pState, pszPct, "duplicate flag '%c'", ch); 95 fF lags |= fFlag;256 fFmtFlags |= fFlag; 96 257 ch = *pszFmt++; 97 258 } … … 110 271 cchWidth += ch - '0'; 111 272 } 112 fF lags |= RTSTR_F_WIDTH;273 fFmtFlags |= RTSTR_F_WIDTH; 113 274 } 114 275 else if (ch == '*') … … 117 278 iArg++; 118 279 cchWidth = 0; 119 fF lags |= RTSTR_F_WIDTH;280 fFmtFlags |= RTSTR_F_WIDTH; 120 281 ch = *pszFmt++; 121 282 } … … 152 313 cchPrecision = 0; 153 314 } 154 fF lags |= RTSTR_F_PRECISION;315 fFmtFlags |= RTSTR_F_PRECISION; 155 316 } 156 317 … … 158 319 * Argument size. 159 320 */ 160 char chSize = ch;321 uint16_t fFmtSize = RTSTR_Z_DEFAULT; 161 322 switch (ch) 162 323 { 163 324 default: 164 chSize = '\0';325 fFmtSize = RTSTR_Z_DEFAULT; 165 326 break; 166 327 167 328 case 'z': 329 fFmtSize = RTSTR_Z_SIZE; 330 ch = *pszFmt++; 331 break; 332 case 'j': 333 fFmtSize = RTSTR_Z_INTMAX; 334 ch = *pszFmt++; 335 case 't': 336 fFmtSize = RTSTR_Z_PTRDIFF; 337 ch = *pszFmt++; 338 break; 339 340 case 'l': 341 fFmtSize = RTSTR_Z_LONG; 342 ch = *pszFmt++; 343 if (ch == 'l') 344 { 345 fFmtSize = RTSTR_Z_LONGLONG; 346 ch = *pszFmt++; 347 } 348 break; 349 350 case 'q': /* Used on BSD platforms. */ 168 351 case 'L': 169 case 'j': 170 case 't': 171 ch = *pszFmt++; 172 break; 173 174 case 'l': 175 ch = *pszFmt++; 176 if (ch == 'l') 177 { 178 chSize = 'L'; 179 ch = *pszFmt++; 180 } 352 fFmtSize = RTSTR_Z_LONGLONG; 353 ch = *pszFmt++; 181 354 break; 182 355 183 356 case 'h': 357 fFmtSize = RTSTR_Z_HALF; 184 358 ch = *pszFmt++; 185 359 if (ch == 'h') 186 360 { 187 chSize = 'H';361 fFmtSize = RTSTR_Z_HALFHALF; 188 362 ch = *pszFmt++; 189 363 } … … 195 369 { 196 370 pszFmt += 2; 197 chSize = 'L';371 fFmtSize = RTSTR_Z_MS_I64; 198 372 } 199 373 else if ( pszFmt[0] == '3' … … 201 375 { 202 376 pszFmt += 2; 203 chSize = 0;377 fFmtSize = RTSTR_Z_MS_I32; 204 378 } 205 379 else 206 chSize = 'j'; 207 ch = *pszFmt++; 208 break; 209 210 case 'q': /* Used on BSD platforms. */ 211 chSize = 'L'; 380 { 381 VFmtChkErrFmt(pState, pszFmt, "Unknow format type/size/flag 'I%c'", pszFmt[0]); 382 fFmtSize = RTSTR_Z_INTMAX; 383 } 212 384 ch = *pszFmt++; 213 385 break; … … 226 398 if (*pszFmt) 227 399 VFmtChkErrFmt(pState, pszFmt, "Characters following '%%M' will be ignored"); 228 if ( chSize != '\0')229 VFmtChkWarnFmt(pState, pszFmt, "'%%M' does not support any size flags (% c)", chSize);230 if (fF lags != 0)231 VFmtChkWarnFmt(pState, pszFmt, "'%%M' does not support any format flags (%#x)", fF lags);400 if (fFmtSize != RTSTR_Z_DEFAULT) 401 VFmtChkWarnFmt(pState, pszFmt, "'%%M' does not support any size flags (%#x)", fFmtSize); 402 if (fFmtFlags != 0) 403 VFmtChkWarnFmt(pState, pszFmt, "'%%M' does not support any format flags (%#x)", fFmtFlags); 232 404 if (VFmtChkRequireStringArg(pState, pszPct, iArg, "'%M' expects a format string")) 233 405 VFmtChkHandleReplacementFormatString(pState, pszPct, iArg); … … 237 409 case 'N': /* real nesting. */ 238 410 { 239 if ( chSize != '\0')240 VFmtChkWarnFmt(pState, pszFmt, "'%%N' does not support any size flags (% c)", chSize);241 if (fF lags != 0)242 VFmtChkWarnFmt(pState, pszFmt, "'%%N' does not support any format flags (%#x)", fF lags);411 if (fFmtSize != RTSTR_Z_DEFAULT) 412 VFmtChkWarnFmt(pState, pszFmt, "'%%N' does not support any size flags (%#x)", fFmtSize); 413 if (fFmtFlags != 0) 414 VFmtChkWarnFmt(pState, pszFmt, "'%%N' does not support any format flags (%#x)", fFmtFlags); 243 415 VFmtChkRequireStringArg(pState, pszPct, iArg, "'%N' expects a string followed by a va_list pointer"); 244 416 VFmtChkRequireVaListPtrArg(pState, pszPct, iArg + 1, "'%N' expects a string followed by a va_list pointer");
Note:
See TracChangeset
for help on using the changeset viewer.