?? ccheck.c
字號:
if( opnd2->op.ulong_value > high ) {
if( (opnd2->op.ulong_value | (high >> 1)) != ~0UL ) {
CWarn1( WARN_CONSTANT_TOO_BIG, ERR_CONSTANT_TOO_BIG );
}
}
break;
case TYPE_CHAR:
if( opnd2->op.long_value > 127 ||
opnd2->op.long_value < -128 ) {
CWarn1( WARN_CONSTANT_TOO_BIG, ERR_CONSTANT_TOO_BIG );
}
break;
case TYPE_UCHAR:
if( opnd2->op.ulong_value > 0xff) {
if( (opnd2->op.ulong_value | (0xff >> 1)) != ~0UL ) {
CWarn1( WARN_CONSTANT_TOO_BIG, ERR_CONSTANT_TOO_BIG );
}
}
break;
case TYPE_UINT:
if( sizeof( target_uint ) > 2 ) break;
case TYPE_USHORT:
if( opnd2->op.ulong_value > 0xffff ) {
if( (opnd2->op.ulong_value | (0xffff >> 1)) != ~0UL ) {
CWarn1( WARN_CONSTANT_TOO_BIG, ERR_CONSTANT_TOO_BIG );
}
}
break;
case TYPE_INT:
if( sizeof( target_uint ) > 2 ) break;
case TYPE_SHORT:
if( opnd2->op.long_value > 32767 ||
opnd2->op.long_value < -32768L ) {
CWarn1( WARN_CONSTANT_TOO_BIG, ERR_CONSTANT_TOO_BIG );
}
break;
default:
break;
}
} else if( opnd2->op.opr == OPR_PUSHFLOAT ) {
if( typ1->decl_type == TYPE_FLOAT ) {
if( atof( opnd2->op.float_value->string ) > TARGET_FLT_MAX ) {
CWarn1( WARN_CONSTANT_TOO_BIG, ERR_CONSTANT_TOO_BIG );
}
}
}
}
static bool IsPtrtoFunc( TYPEPTR typ )
{
int ret;
ret = FALSE;
while( typ->decl_type == TYPE_TYPEDEF ) typ = typ->object;
if( typ->decl_type == TYPE_POINTER ) {
typ = typ->object;
while( typ->decl_type == TYPE_TYPEDEF ) typ = typ->object;
if( typ->decl_type == TYPE_FUNCTION ) {
ret = TRUE;
}
}
return( ret );
}
void ParmAsgnCheck( TYPEPTR typ1, TREEPTR opnd2, int parm_num )
{
//TODO merge up with ChkCalls
TYPEPTR typ2;
if( opnd2->op.opr == OPR_ERROR ) return;
typ2 = opnd2->expr_type;
SetDiagType2( typ2, typ1 );
switch( CompatibleType( typ1, typ2, 1 ) ) {
case NO:
if ( parm_num == 0 ) {
CErr1( ERR_TYPE_MISMATCH );
} else {
CErr2( ERR_PARM_TYPE_MISMATCH, parm_num );
}
break;
case PT: /* 31-aug-89 */
CWarn1( WARN_POINTER_TRUNCATION, ERR_POINTER_TRUNCATION );
break;
case PX:
if( IsPtrtoFunc( typ1 ) ) {
CWarn1( WARN_POINTER_TYPE_MISMATCH,ERR_POINTER_TYPE_MISMATCH );
}
break;
case PQ:
if( !CompFlags.no_check_qualifiers ) { // else fuck em
if ( parm_num == 0 ) {
CWarn1( WARN_QUALIFIER_MISMATCH, ERR_QUALIFIER_MISMATCH );
} else {
CWarn2( WARN_QUALIFIER_MISMATCH,
ERR_PARM_QUALIFIER_MISMATCH, parm_num );
}
}
break;
case PM: /* 16-may-91 */
if ( parm_num == 0 ) {
CWarn1( WARN_POINTER_TYPE_MISMATCH, ERR_POINTER_TYPE_MISMATCH );
} else {
CWarn2( WARN_POINTER_TYPE_MISMATCH,
ERR_PARM_POINTER_TYPE_MISMATCH, parm_num );
}
break;
case PS: /* 16-may-91 */
if ( parm_num == 0 ) {
CWarn1( WARN_SIGN_MISMATCH, ERR_SIGN_MISMATCH );
} else {
CWarn2( WARN_SIGN_MISMATCH,
ERR_PARM_SIGN_MISMATCH, parm_num );
}
break;
case PW:
if ( parm_num == 0 ) {
CWarn1( WARN_INCONSISTENT_INDIRECTION_LEVEL,
ERR_INCONSISTENT_INDIRECTION_LEVEL );
} else {
CWarn2( WARN_PARM_INCONSISTENT_INDIRECTION_LEVEL,
ERR_PARM_INCONSISTENT_INDIRECTION_LEVEL, parm_num );
}
break;
case PC:
if( opnd2->op.opr == OPR_PUSHINT ) {
if( opnd2->op.long_value != 0 ) {
CWarn1( WARN_NONPORTABLE_PTR_CONV,
ERR_NONPORTABLE_PTR_CONV );
}
} else {
CWarn1( WARN_PCTYPE_MISMATCH, ERR_PCTYPE_MISMATCH );
}
break;
case AC:
/* CarlYoung 31-Oct-03 */
{
unsigned long fsize_1 = 0, fsize_2 = 0;
if( TypeSizeEx( typ2, &fsize_2 ) > TypeSizeEx( typ1, &fsize_1 ) ) {
CWarn1( WARN_LOSE_PRECISION, ERR_LOSE_PRECISION );
}
if( fsize_2 > fsize_1 ) {
CWarn1( WARN_LOSE_PRECISION, ERR_LOSE_PRECISION );
}
}
case OK:
AssRangeChk( typ1, opnd2 );
break;
}
SetDiagPop();
}
void TernChk( TYPEPTR typ1, TYPEPTR typ2 )
{
cmp_type cmp;
cmp = CompatibleType( typ1, typ2, 0 );
switch( cmp ) {
case NO:
CErr1( ERR_TYPE_MISMATCH );
break;
case PT: /* 31-aug-89 */
case PX:
CWarn1( WARN_POINTER_TRUNCATION, ERR_POINTER_TRUNCATION );
break;
case PQ:
if( !CompFlags.no_check_qualifiers ) { // else fuck em
CWarn1( WARN_QUALIFIER_MISMATCH,ERR_QUALIFIER_MISMATCH );
}
break;
case PM: /* 16-may-91 */
CWarn1( WARN_POINTER_TYPE_MISMATCH, ERR_POINTER_TYPE_MISMATCH );
break;
case PS: /* 16-may-91 */
CWarn1( WARN_SIGN_MISMATCH, ERR_SIGN_MISMATCH );
break;
case PW:
CWarn1( WARN_INCONSISTENT_INDIRECTION_LEVEL,
ERR_INCONSISTENT_INDIRECTION_LEVEL );
break;
case PC:
CWarn1( WARN_PCTYPE_MISMATCH, ERR_PCTYPE_MISMATCH );
break;
case OK:
case AC:
break;
}
}
void ChkRetType( TREEPTR tree )
{
TYPEPTR ret_type;
TYPEPTR func_type;
if( tree->op.opr == OPR_ERROR ) return;
ret_type = TypeOf( tree );
func_type = CurFunc->sym_type->object;
if( func_type->decl_type == TYPE_VOID ) {
CErr2p( ERR_NOT_EXPECTING_RETURN_VALUE, CurFunc->name );
} else if( ret_type->decl_type == TYPE_POINTER ) {
if( ret_type->u.p.segment == SEG_STACK ) {
CWarn1( WARN_RET_ADDR_OF_AUTO, ERR_RET_ADDR_OF_AUTO );
}
}
/* check that the types are compatible */
ParmAsgnCheck( func_type, tree, 0 );
}
int IdenticalType( TYPEPTR typ1, TYPEPTR typ2 )
{
int rc;
rc = TypeCheck( typ1, typ2 );
return( rc == TC_OK || rc == TC_TYPE2_HAS_MORE_INFO );
}
int VerifyType( TYPEPTR new, TYPEPTR old, SYMPTR sym )
{
int rc;
rc = TypeCheck( new, old );
switch( rc ) {
case TC_OK: /* OK */
break;
case TC_TYPE_MISMATCH: /* types didn't match */
while( new->decl_type == TYPE_TYPEDEF ) new = new->object;
while( old->decl_type == TYPE_TYPEDEF ) old = old->object;
/*
types won't match for:
extern char a[]; char a[200];
char a[200]; extern char a[];
*/
if(( new->decl_type == TYPE_ARRAY ) &&
( old->decl_type == TYPE_ARRAY ) &&
( IdenticalType( new->object, old->object ) ) ) {
if( TypeSize(new) != 0 ) {
if( TypeSize(old) == 0 ) {
/* let it go but indicate that the new type holds */
}
} else {
if( TypeSize(old) != 0 ) {
/* let it go */
return( 1 );
break;
}
}
}
CErr2p( ERR_TYPE_DOES_NOT_AGREE, sym->name );
break;
case TC_PARM_COUNT_MISMATCH: /* parm count mismatch */
CErr1( ERR_PARM_COUNT_MISMATCH );
break;
case TC_TYPE2_HAS_MORE_INFO: /* OK, new= void *, old= something *;*/
return( 1 ); /* indicate want old definition */
break;
default: /* parm type mismatch */
CErr2( ERR_PARM_TYPE_MISMATCH, rc - TC_PARM_TYPE_MISMATCH );
break;
}
return( 0 );
}
local int TypeCheck( TYPEPTR typ1, TYPEPTR typ2 )
{
int pointer_type;
type_modifiers mask;
int retcode;
pointer_type = 0;
/* "char *s" and "char s[]" differs only by FLAG_WAS_ARRAY, ignore it too */
if( TargetSwitches & BIG_DATA )
mask = ~(FLAG_FAR | FLAG_WAS_ARRAY);
else
mask = ~(FLAG_NEAR | FLAG_WAS_ARRAY);
for( ;; ) {
typ1 = SkipTypeFluff( typ1 );
typ2 = SkipTypeFluff( typ2 );
/* this compare was moved here 20-sep-88 */
/* ptr to typedef struct failed when this was before typedef skips */
if( typ1 == typ2 ) return( TC_OK );
if( typ1->decl_type != typ2->decl_type ) {
if( pointer_type ) {
/* by popular demand, I disabled the questionable feature to accept
void *foo(void);
int *foo(void) {return NULL};
- Bart Oldeman, 2002/10/24 */
if( typ1->decl_type == TYPE_ARRAY ) {
return( TypeCheck( typ1->object, typ2 ) );
}
if( typ2->decl_type == TYPE_ARRAY ) {
return( TypeCheck( typ1, typ2->object ) );
}
}
return( TC_TYPE_MISMATCH );
}
if( typ1->decl_type == TYPE_POINTER ) {
pointer_type = 1;
if( (typ1->u.p.decl_flags & mask) != (typ2->u.p.decl_flags & mask) ) {
return( TC_TYPE_MISMATCH );
}
}
if( TypeSize(typ1) != TypeSize(typ2) ) {
if( typ1->decl_type == TYPE_ARRAY ) { /* 09-mar-94 */
if( TypeSize(typ1) == 0 ) {
return( TC_TYPE2_HAS_MORE_INFO );
}
if( TypeSize(typ2) == 0 ) {
return( TC_OK );
}
}
return( TC_TYPE_MISMATCH );
}
/* CarlYoung 31-Oct-03 */
if( (TYPE_FIELD == typ1->decl_type) || (TYPE_UFIELD == typ1->decl_type) ) {
if( typ1->u.f.field_width != typ2->u.f.field_width ) {
return( TC_TYPE_MISMATCH );
}
}
if( typ1->decl_type == TYPE_STRUCT ||
typ1->decl_type == TYPE_UNION ) {
/* must be the same tag to be identical, if they are the
same tag, then typ1 == typ2 which is checked above */
return( TC_TYPE_MISMATCH );
}
if( typ1->decl_type == TYPE_FUNCTION ) {
retcode = ChkCompatibleFunction( typ1, typ2, 0 );
if( retcode != TC_OK ) return( retcode );
if( typ1->object == NULL || typ2->object == NULL ) {
return( TC_OK );
}
}
typ1 = typ1->object;
typ2 = typ2->object;
if( typ1 == NULL ) break;
if( typ2 == NULL ) break;
}
if( typ1 != typ2 ) return( TC_TYPE_MISMATCH );
return( TC_OK ); /* indicate types are identical */
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -