X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=type_hash.c;h=3f84c5d4620227a4bb302a013bee24920fbfe76c;hb=e66a2691d3291916ed2ec07ed1cdead2a95e1a9a;hp=b3ae80199ee445480f61ee1d08f91564667cddc1;hpb=daab1c4b9ec9146053f6d4f16ca2b92222104ddc;p=cparser diff --git a/type_hash.c b/type_hash.c index b3ae801..3f84c5d 100644 --- a/type_hash.c +++ b/type_hash.c @@ -18,7 +18,7 @@ static unsigned hash_ptr(const void *ptr) { - unsigned ptr_int = (ptr - NULL); + unsigned ptr_int = ((char*) ptr - (char*) NULL); return ptr_int >> 3; } @@ -52,12 +52,11 @@ unsigned hash_method_type(const method_type_t *type) { unsigned result = hash_ptr(type->result_type); - method_parameter_type_t *parameter = type->parameter_types; + declaration_t *parameter = type->parameters; while(parameter != NULL) { - result ^= hash_ptr(parameter->type); + result ^= hash_ptr(parameter); parameter = parameter->next; } - result ^= hash_ptr(type->abi_style); return result; } @@ -97,6 +96,9 @@ unsigned hash_type(const type_t *type) case TYPE_POINTER: hash = hash_pointer_type((const pointer_type_t*) type); break; + case TYPE_BUILTIN: + hash = hash_ptr(((const builtin_type_t*) type)->symbol); + break; } unsigned some_prime = 99991; @@ -115,22 +117,24 @@ static int compound_types_equal(const compound_type_t *type1, const compound_type_t *type2) { + if(type1->type.type != type2->type.type) + return 0; if(type1->symbol != type2->symbol) return 0; -#if 0 - struct_entry_t *entry1 = type1->entries; - struct_entry_t *entry2 = type2->entries; + declaration_t *entry1 = type1->context.declarations; + declaration_t *entry2 = type2->context.declarations; while(entry1 != NULL && entry2 != NULL) { if(entry1->type != entry2->type) return 0; + if(entry1->symbol != entry2->symbol) + return 0; entry1 = entry1->next; entry2 = entry2->next; } if(entry1 != NULL || entry2 != NULL) return 0; -#endif return 1; } @@ -141,11 +145,8 @@ int method_types_equal(const method_type_t *type1, const method_type_t *type2) if(type1->result_type != type2->result_type) return 0; - if(type1->abi_style != type2->abi_style) - return 0; - - method_parameter_type_t *param1 = type1->parameter_types; - method_parameter_type_t *param2 = type2->parameter_types; + declaration_t *param1 = type1->parameters; + declaration_t *param2 = type2->parameters; while(param1 != NULL && param2 != NULL) { if(param1->type != param2->type) return 0; @@ -168,7 +169,28 @@ int pointer_types_equal(const pointer_type_t *type1, static int enum_types_equal(const enum_type_t *type1, const enum_type_t *type2) { - /* TODO */ + if(type1->symbol != NULL && type1->symbol == type2->symbol) + return 1; + + enum_entry_t *entry1 = type1->entries; + enum_entry_t *entry2 = type2->entries; + while(entry1 != NULL && entry2 != NULL) { + if(entry1->symbol != entry2->symbol) + return 0; + /* TODO: compare expressions */ + entry1 = entry1->next; + entry2 = entry2->next; + } + if(entry1 != NULL || entry2 != NULL) + return 0; + + return 1; +} + +static +int builtin_types_equal(const builtin_type_t *type1, + const builtin_type_t *type2) +{ return type1->symbol == type2->symbol; } @@ -201,6 +223,9 @@ int types_equal(const type_t *type1, const type_t *type2) case TYPE_POINTER: return pointer_types_equal((const pointer_type_t*) type1, (const pointer_type_t*) type2); + case TYPE_BUILTIN: + return builtin_types_equal((const builtin_type_t*) type1, + (const builtin_type_t*) type2); } abort();