X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=attribute.c;h=8f9b2e03711a3179580bdff79e16d934cb1b568f;hb=8e0cc9a1b4204fde79cca81b23fa8d932717de7f;hp=9dec22d551e72a7fa8be5e54f23a765ca4afcb9b;hpb=d712c64467db65ddfe4930735e3c464bab80d15c;p=cparser diff --git a/attribute.c b/attribute.c index 9dec22d..8f9b2e0 100644 --- a/attribute.c +++ b/attribute.c @@ -20,6 +20,7 @@ #include #include +#include "adt/strutil.h" #include "diagnostic.h" #include "warning.h" #include "attribute_t.h" @@ -119,22 +120,6 @@ const char *get_attribute_name(attribute_kind_t kind) return attribute_names[kind]; } -/** - * compare two string, ignoring double underscores on the second. - */ -static int strcmp_underscore(const char *s1, const char *s2) -{ - if (s2[0] == '_' && s2[1] == '_') { - size_t len2 = strlen(s2); - size_t len1 = strlen(s1); - if (len1 == len2-4 && s2[len2-2] == '_' && s2[len2-1] == '_') { - return strncmp(s1, s2+2, len2-4); - } - } - - return strcmp(s1, s2); -} - type_t *handle_attribute_mode(const attribute_t *attribute, type_t *orig_type) { type_t *type = skip_typeref(orig_type); @@ -154,16 +139,16 @@ type_t *handle_attribute_mode(const attribute_t *attribute, type_t *orig_type) const char *symbol_str = arg->v.symbol->string; bool sign = is_type_signed(type); atomic_type_kind_t akind; - if (strcmp_underscore("QI", symbol_str) == 0 || - strcmp_underscore("byte", symbol_str) == 0) { + if (streq_underscore("QI", symbol_str) || + streq_underscore("byte", symbol_str)) { akind = sign ? ATOMIC_TYPE_CHAR : ATOMIC_TYPE_UCHAR; - } else if (strcmp_underscore("HI", symbol_str) == 0) { + } else if (streq_underscore("HI", symbol_str)) { akind = sign ? ATOMIC_TYPE_SHORT : ATOMIC_TYPE_USHORT; - } else if (strcmp_underscore("SI", symbol_str) == 0 - || strcmp_underscore("word", symbol_str) == 0 - || strcmp_underscore("pointer", symbol_str) == 0) { + } else if (streq_underscore("SI", symbol_str) + || streq_underscore("word", symbol_str) + || streq_underscore("pointer", symbol_str)) { akind = sign ? ATOMIC_TYPE_INT : ATOMIC_TYPE_UINT; - } else if (strcmp_underscore("DI", symbol_str) == 0) { + } else if (streq_underscore("DI", symbol_str)) { akind = sign ? ATOMIC_TYPE_LONGLONG : ATOMIC_TYPE_ULONGLONG; } else { source_position_t const *const pos = &attribute->source_position;