void PointerType::isValid (NodeValidator* v) { Node::isValid(v); v->ensure(TypeNode() != NULL, "Ptr must have a type node"); }
TYPEPTR EnumDecl( int flags ) { TYPEPTR typ; TAGPTR tag; flags = flags; NextToken(); if( CurToken == T_ID ) { /* could be: (1) "enum" <id> ";" (2) "enum" <id> <variable_name> ";" (3) "enum" <id> "{" <enum_const_decl> ... "}" */ tag = TagLookup(); NextToken(); if( CurToken != T_LEFT_BRACE ) { typ = tag->sym_type; if( typ == NULL ) { CErr1( ERR_INCOMPLETE_ENUM_DECL ); typ = TypeDefault(); } else { if( typ->decl_type != TYPE_ENUM ) { /* 18-jan-89 */ CErr2p( ERR_DUPLICATE_TAG, tag->name ); } typ->u.tag = tag; } return( typ ); } tag = VfyNewTag( tag, TYPE_ENUM ); } else { tag = NullTag(); } typ = TypeNode( TYPE_ENUM, GetType( TYPE_INT ) ); typ->u.tag = tag; tag->sym_type = typ; tag->size = TARGET_INT; tag->u.enum_list = NULL; if( CurToken == T_LEFT_BRACE ) { const_val val; enum enum_rng index; enum enum_rng const_index; enum enum_rng start_index; enum enum_rng step; enum enum_rng error; uint64 n; uint64 Inc; bool minus; bool has_sign; ENUMPTR *prev_lnk; ENUMPTR esym; source_loc error_loc; char buff[50]; if( CompFlags.make_enums_an_int ) { start_index = ENUM_INT; } else { start_index = ENUM_S8; } const_index = ENUM_UNDEF; NextToken(); if( CurToken == T_RIGHT_BRACE ) { CErr1( ERR_EMPTY_ENUM_LIST ); } U32ToU64( 1, &Inc ); U64Clear( n ); minus = FALSE; has_sign = FALSE; step = 1; prev_lnk = &esym; esym = NULL; while( CurToken == T_ID ) { esym = EnumLkAdd( tag ); *prev_lnk = esym; prev_lnk = &esym->thread; error_loc = TokenLoc; NextToken(); if( CurToken == T_EQUAL ) { NextToken(); error_loc = TokenLoc; ConstExprAndType( &val ); switch( val.type ){ case TYPE_ULONG: case TYPE_UINT: case TYPE_ULONG64: minus = FALSE; break; default: if( val.value.u.sign.v ) { minus = TRUE; step = 2; } else { minus = FALSE; } break; } n = val.value; } else if( has_sign ) { if( n.u.sign.v ) { minus = TRUE; } else { minus = FALSE; } } for( index = start_index; index < ENUM_SIZE; index += step ) { if( minus ) { if( I64Cmp( &n, &( RangeTable[ index ][LOW] ) ) >= 0 ) break; } else { if( U64Cmp( &n, &( RangeTable[ index ][HIGH]) ) <= 0 ) break; } } error = ENUM_UNDEF; if( !CompFlags.extensions_enabled && ( index > ENUM_INT )) { error = ENUM_INT; } if( index >= ENUM_SIZE ) { // overflow signed maximum range if( error == ENUM_UNDEF ) { error = const_index; } } else if(( const_index == ENUM_SIZE - 1 ) && minus ) { // overflow unsigned maximum range by any negative signed value if( error == ENUM_UNDEF ) error = const_index; step = 1; } else { if( !has_sign && minus) { has_sign = TRUE; if( index < const_index ) { // round up to signed index = ( const_index + 1 ) & ~1; } } if( index > const_index ) { const_index = index; typ->object = GetType( ItypeTable[const_index].decl_type ); tag->size = ItypeTable[const_index].size; } } if( error != ENUM_UNDEF ) { SetErrLoc( &error_loc ); get_msg_range( buff, error ); CErr2p( ERR_ENUM_CONSTANT_OUT_OF_RANGE, buff ); InitErrLoc(); } esym->value = n; EnumTable[ esym->hash ] = esym; /* 08-nov-94 */ if( CurToken == T_RIGHT_BRACE ) break; U64Add( &n, &Inc, &n ); MustRecog( T_COMMA ); if( !CompFlags.extensions_enabled && !CompFlags.c99_extensions && ( CurToken == T_RIGHT_BRACE )) { ExpectIdentifier(); /* 13-may-91 */ } } MustRecog( T_RIGHT_BRACE ); } return( typ ); }
void StaticInit( SYMPTR sym, SYM_HANDLE sym_handle ) { TYPEPTR typ; TYPEPTR struct_typ; TYPEPTR last_array; GenStaticDataQuad( sym_handle ); CompFlags.non_zero_data = 0; struct_typ = NULL; last_array = NULL; typ = sym->sym_type; /* Follow chain of typedefs/structs/arrays */ for( ;; ) { SKIP_TYPEDEFS( typ ); if( typ->decl_type == TYPE_ARRAY ) { /* Remember innermost array type */ last_array = typ; typ = typ->object; } else if( typ->decl_type == TYPE_STRUCT ) { FIELDPTR field; /* Remember outermost structure type */ if( struct_typ == NULL ) { /* last_array cannot to be outside this struct! */ last_array = NULL; struct_typ = typ; } /* Determine the type of the last field in the struct */ field = typ->u.tag->u.field_list; if( field == NULL ) break; /* 10-sep-92 */ while( field->next_field != NULL ) field = field->next_field; typ = field->field_type; } else { break; } } typ = last_array; /* If innermost array had unspecified dimension, create new types whose * dimensions will be determined by number of initializers */ if( (typ != NULL) && typ->u.array->unspecified_dim ) { if( struct_typ == NULL ) { /* Array was not inside struct */ sym->sym_type = ArrayNode( typ->object ); /* 18-oct-88 */ sym->sym_type->u.array->unspecified_dim = TRUE; } else { typ = sym->sym_type; /* Create new structure type */ sym->sym_type = TypeNode( TYPE_STRUCT, ArrayNode( last_array->object ) ); sym->sym_type->u.tag = struct_typ->u.tag; struct_typ = sym->sym_type; /* Create new array types as necessary */ for( ;; ) { SKIP_TYPEDEFS( typ ); if( typ->decl_type != TYPE_ARRAY ) break; sym->sym_type = ArrayNode( sym->sym_type ); sym->sym_type->u.array->unspecified_dim = TRUE; typ = typ->object; } typ = last_array; } } else { struct_typ = NULL; } SymReplace( sym, sym_handle ); /* 31-aug-88 */ InitSymData( sym->sym_type, sym->sym_type, 0 ); SymGet( sym, sym_handle ); /* 31-aug-88 */ if( struct_typ != NULL ) { /* 17-mar-92 */ /* Structure contains an unspecified length array as last field */ struct_typ->object->u.array->dimension = typ->u.array->dimension; typ->u.array->unspecified_dim = TRUE; typ->u.array->dimension = 0; /* Reset back to 0 */ } if( sym->u.var.segment == 0 ) { /* 01-dec-91 */ SetFarHuge( sym, 0 ); SetSegment( sym ); SetSegAlign( sym ); /* 02-feb-92 */ } }