📄 ctype.c
字号:
decl_state state;
FIELDPTR field;
unsigned long struct_size;
unsigned long next_offset;
unsigned int worst_alignment;
decl_info info;
worst_alignment = 1;
struct_size = start;
next_offset = start;
GetComplexFieldTypeSpecifier( &info, TYPE_DOUBLE );
field = FieldCreate( "__ow_real" );
field->attrib = 0;
field->field_type = info.typ;
field = NewField( field, decl );
typ = info.typ;
state = DECL_STATE_NONE;
next_offset = FieldAlign( next_offset, field, &worst_alignment );
next_offset += SizeOfArg( field->field_type );
if( next_offset > struct_size ) struct_size = next_offset;
GetComplexFieldTypeSpecifier( &info, TYPE_DIMAGINARY );
field = FieldCreate( "__ow_imaginary" );
field->attrib = 0;
field->field_type = info.typ;
field = NewField( field, decl );
typ = info.typ;
state = DECL_STATE_NONE;
next_offset = FieldAlign( next_offset, field, &worst_alignment );
next_offset += SizeOfArg( field->field_type );
if( next_offset > struct_size ) struct_size = next_offset;
decl->u.tag->alignment = worst_alignment;
struct_size += worst_alignment - 1;
struct_size &= - (long)worst_alignment;
_CHECK_SIZE( struct_size );
return( struct_size );
}
local TYPEPTR ComplexDecl( int decl_typ, int packed )
{
TYPEPTR typ;
TAGPTR tag;
int saved_packamount;
TAGPTR TagLookup();
saved_packamount = PackAmount;
if( packed ) PackAmount = 1;
tag = NullTag();
typ = tag->sym_type;
if( typ == NULL ) {
typ = TypeNode( decl_typ, NULL );
tag->sym_type = typ;
}
typ->u.tag = tag;
tag->u.field_list = NULL;
tag->size = GetComplexFields( typ );
PackAmount = saved_packamount;
return( typ );
}
*/
local void CheckBitfieldType( TYPEPTR typ )
{
while( typ->decl_type == TYPE_TYPEDEF ) typ = typ->object;
if( CompFlags.extensions_enabled ) {
if( typ->decl_type == TYPE_ENUM ) {
typ = typ->object;
}
}
switch( typ->decl_type ) {
case TYPE_INT:
case TYPE_UINT:
/* ANSI C only allows int and unsigned [int] */
return;
case TYPE_CHAR:
case TYPE_UCHAR:
case TYPE_SHORT:
case TYPE_USHORT:
case TYPE_LONG: /* + AFS 05-mar-91 */
case TYPE_ULONG:
case TYPE_LONG64:
case TYPE_ULONG64:
if( CompFlags.extensions_enabled ) {
return;
}
break;
default:
break;
}
CErr1( ERR_INVALID_TYPE_FOR_FIELD );
}
void VfyNewSym( int hash_value, char *name )
{
int enum_var;
SYM_HANDLE sym_handle;
auto SYM_ENTRY sym;
auto struct enum_info ei;
enum_var = EnumLookup( hash_value, name, &ei );
if( enum_var ) {
if( ei.level != SymLevel ) enum_var = 0;
}
sym_handle = SymLook( hash_value, name );
if( sym_handle != 0 ) {
SymGet( &sym, sym_handle );
if( sym.level != SymLevel ) sym_handle = 0;
}
if( sym_handle != 0 || enum_var != 0 ) {
CErr2p( ERR_SYM_ALREADY_DEFINED, name );
}
}
TAGPTR TagLookup()
{
TAGPTR tag;
int hash;
hash = HashValue;
tag = TagHash[ hash ];;
while( tag != NULL ) {
if( strcmp( Buffer, tag->name ) == 0 ) return( tag );
tag = tag->next_tag;
}
return( NewTag( Buffer, hash ) );
}
void FreeTags()
{
TAGPTR tag;
int hash;
for( hash = 0; hash <= TAG_HASH_SIZE; ++hash ) {
for( ; (tag = TagHash[ hash ]); ) {
if( tag->level < SymLevel ) break;
TagHash[ hash ] = tag->next_tag;
tag->next_tag = DeadTags;
DeadTags = tag;
}
}
}
void WalkTagList( void (*func)(TAGPTR) )
{
TAGPTR tag;
int index;
for( index = 0; index <= TAG_HASH_SIZE; ++index ) {
for( tag = TagHash[index]; tag; tag = tag->next_tag ) {
func( tag );
}
}
}
void AddTypeHash( TYPEPTR typ )
{
if( typ->decl_type == TYPE_POINTER ) {
if( typ->object != NULL ) {
typ->next_type = PtrTypeHash[ typ->object->decl_type ];
PtrTypeHash[ typ->object->decl_type ] = typ;
}
} else if( typ->decl_type == TYPE_FUNCTION ) {
typ->next_type = NULL;
} else {
typ->next_type = CTypeHash[ typ->decl_type ];
CTypeHash[ typ->decl_type ] = typ;
}
}
void AddPtrTypeHash( TYPEPTR typ )
{
typ->next_type = PtrTypeHash[ typ->object->decl_type ];
PtrTypeHash[ typ->object->decl_type ] = typ;
}
TYPEPTR TypeNode( DATA_TYPE type_spec, TYPEPTR the_object )
{
TYPEPTR typ;
typ = (TYPEPTR) CPermAlloc( sizeof(TYPEDEFN) );
typ->decl_type = type_spec;
typ->object = the_object;
typ->u.tag = NULL;
AddTypeHash( typ );
++TypeCount;
++CTypeCounts[type_spec];
return( typ );
}
TYPEPTR ArrayNode( TYPEPTR the_object )
{
TYPEPTR typ;
typ = TypeNode( TYPE_ARRAY, the_object );
typ->u.array = CPermAlloc( sizeof( struct array_info ) );
return( typ );
}
local TYPEPTR MkPtrNode( TYPEPTR typ, type_modifiers flags,
int segid, SYM_HANDLE base, BASED_KIND based_kind )
{
TYPEPTR ptrtyp;
if( typ != NULL ) {
ptrtyp = PtrTypeHash[ typ->decl_type ];
for( ; ptrtyp; ptrtyp = ptrtyp->next_type ) {
if( ptrtyp->decl_type == TYPE_POINTER &&
ptrtyp->object == typ &&
ptrtyp->u.p.segment == segid &&
ptrtyp->u.p.based_sym == base &&
ptrtyp->u.p.based_kind == based_kind &&
ptrtyp->u.p.decl_flags == flags ) {
return( ptrtyp );
}
}
}
ptrtyp = TypeNode( TYPE_POINTER, typ );
ptrtyp->u.p.decl_flags = flags;
ptrtyp->u.p.segment = segid;
ptrtyp->u.p.based_sym = base;
ptrtyp->u.p.based_kind = based_kind;
return( ptrtyp );
}
TYPEPTR PtrNode( TYPEPTR typ, int flags, int segid )
{
return( MkPtrNode( typ, flags, segid, 0, BASED_NONE ) );
}
TYPEPTR BPtrNode( TYPEPTR typ, int flags, int segid,
SYM_HANDLE base, BASED_KIND kind )
{
return( MkPtrNode( typ, flags, segid, base, kind ) );
}
int FuncHeadIndex( TYPEPTR *parm_types )
{
int index;
index = 0;
if( parm_types != NULL ) {
while( *parm_types != NULL ) {
++parm_types;
++index;
if( index == MAX_PARM_LIST_HASH_SIZE ) break;
}
}
return( index );
}
TYPEPTR FuncNode( TYPEPTR return_typ, int flag, TYPEPTR *parm_types )
{
TYPEPTR typ;
int index;
index = FuncHeadIndex( parm_types );
if( return_typ != NULL ){
for( typ = FuncTypeHead[ index ]; typ; typ = typ->next_type ) {
if( typ->object == return_typ &&
typ->type_flags == flag &&
typ->u.parms == parm_types ) {
return( typ );
}
}
}
typ = TypeNode( TYPE_FUNCTION, return_typ );
typ->type_flags = flag;
typ->u.parms = parm_types;
typ->next_type = FuncTypeHead[ index ];
FuncTypeHead[ index ] = typ;
return( typ );
}
/* CarlYoung 31-Oct-03 */
unsigned long TypeSize( TYPEPTR typ )
{
return(TypeSizeEx(typ, NULL));
}
/* CarlYoung 31-Oct-03 */
unsigned long TypeSizeEx( TYPEPTR typ , unsigned long * pFieldWidth)
{
unsigned long size;
if( typ == NULL ) return( 0 ); /* 22-feb-90 */
while( typ->decl_type == TYPE_TYPEDEF ) typ = typ->object;
switch( typ->decl_type ) {
case TYPE_CHAR:
case TYPE_UCHAR:
case TYPE_SHORT:
case TYPE_USHORT:
case TYPE_INT:
case TYPE_UINT:
case TYPE_LONG:
case TYPE_ULONG:
case TYPE_LONG64:
case TYPE_ULONG64:
case TYPE_FLOAT:
case TYPE_DOUBLE:
case TYPE_FUNCTION:
case TYPE_DOT_DOT_DOT:
case TYPE_PLAIN_CHAR:
case TYPE_LONG_DOUBLE:
case TYPE_FCOMPLEX:
case TYPE_DCOMPLEX:
case TYPE_LDCOMPLEX:
case TYPE_FIMAGINARY:
case TYPE_DIMAGINARY:
case TYPE_LDIMAGINARY:
case TYPE_BOOL:
size = CTypeSizes[ typ->decl_type ];
break;
case TYPE_VOID:
if( CompFlags.unix_ext ){
size = 1;
}else{
size = 0;
}
break;
case TYPE_POINTER:
if( typ->u.p.decl_flags & ( FLAG_FAR | FLAG_HUGE ) ) {
size = TARGET_FAR_POINTER; /* 20-feb-89 */
} else if( typ->u.p.decl_flags & FLAG_NEAR ) {
size = TARGET_POINTER;
} else {
do {
typ = typ->object;
} while( typ->decl_type == TYPE_TYPEDEF );
if( typ->decl_type == TYPE_FUNCTION ) {
size = CodePtrSize;
} else {
size = DataPtrSize;
}
}
break;
case TYPE_ARRAY:
size = typ->u.array->dimension;
break;
case TYPE_STRUCT:
size = typ->u.tag->size;
if( typ->object != NULL ) { /* 17-mar-92 */
/* structure has a zero length array as last field */
typ = typ->object; /* point to TYPE_ARRAY entry */
size += SizeOfArg( typ ); /* 13-jun-94 */
}
break;
case TYPE_UNION:
case TYPE_ENUM:
size = typ->u.tag->size;
break;
case TYPE_FIELD:
case TYPE_UFIELD:
size = CTypeSizes[ typ->u.f.field_type ];
/* CarlYoung 31-Oct-03 */
if(pFieldWidth){
*pFieldWidth = typ->u.f.field_width;
}
break;
default:
size = 0;
}
return( size );
}
void TypesPurge()
{
#if 0
/* The type entries are in permanent memory, so they can't be freed */
TYPEPTR temp;
while( TypeHead != NULL ) {
temp = TypeHead->next_type;
CMemFree( TypeHead );
TypeHead = temp;
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -