Download CodeCheck Technical Notes - Summer 2003
Transcript
CodeCheck Technical Notes http://www.abraxas-software.com Printed 02/26/06 Creating new intrinsic type specifiers with new_type Some compilers have nonstandard intrinsic types that are not defined in any header file. The function new_type() informs CodeCheck of the existence of such a built-in nonstandard type. The first argument for new_type() should be the new keyword itself, in quotes. The second argument should be any of the possible values of dcl_base except DEFINED_TYPE. (These values are defined as constants in the standard CodeCheck header check.cch). If the value is one of these: EXTRA_INT_TYPE EXTRA_UINT_TYPE EXTRA_FLOAT_TYPE EXTRA_PTR_TYPE then CodeCheck will treat the new keyword as a new base type that is not equivalent to any of the standard types. If it is any other value then the keyword will be considered a synonym for the specified type. Here is the complete list of 25 base types as defined in check.cch: #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define VOID_TYPE BOOL_TYPE CHAR_TYPE SHORT_TYPE WCHAR_TYPE INT_TYPE LONG_TYPE LONG_LONG_TYPE EXTRA_INT_TYPE UCHAR_TYPE USHORT_TYPE UINT_TYPE ULONG_TYPE EXTRA_UINT_TYPE FLOAT_TYPE SHORT_DOUBLE_TYPE DOUBLE_TYPE LONG_DOUBLE_TYPE INT8_TYPE INT16_TYPE INT32_TYPE INT64_TYPE EXTRA_FLOAT_TYPE ENUM_TYPE UNION_TYPE STRUCT_TYPE CLASS_TYPE DEFINED_TYPE EXTRA_PTR_TYPE CONSTRUCTOR_TYPE DESTRUCTOR_TYPE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 // mainframe long long type // nonstandard integer // unsigned char // unsigned short // unsigned int // unsigned long // nonstandard unsigned integer // Symantec and others // __int8, __int16, __int32, and __int64 // are types of Microsoft C++, Borland C++ // and IBM VisualAge C++. // non-standard float // // // // // C++ only any typedef name nonstandard pointer C++ only C++ only Up to 64 new intrinsic types can be defined with calls to new_type(). Please note: use this mechanism only for type keywords that are built into your compiler, never for types that are defined in header files. An Example of the use of new_type() Let us suppose that your compiler has a nonstandard type specifier int64, which stands for a 64-bit integer type that is not defined in any header. This rule could be inserted into every CodeCheck rule file to handle this new keyword: if ( prj_begin ) new_type( "int64", EXTRA_INT_TYPE ); This rule introduces int64 as a new integer type, not equivalent to any other integer type. Whenever CodeCheck finds a declaration with base type int64, it will set the variable dcl_base to EXTRA_INT_TYPE. CodeCheck Technotes © 1988-2006 by Abraxas Software, Inc. Page 21