Remove special cases for EXPR_ERROR and TYPE_ERROR from constant folding and type...
[cparser] / attribute.c
index 9dec22d..1ccdc5d 100644 (file)
@@ -20,6 +20,7 @@
 #include <config.h>
 
 #include <assert.h>
+#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;
@@ -215,7 +200,7 @@ static void handle_attribute_aligned(const attribute_t *attribute,
        }
 
        switch (entity->kind) {
-       DECLARATION_KIND_CASES
+       case DECLARATION_KIND_CASES:
                entity->declaration.alignment = alignment;
        case ENTITY_TYPEDEF:
                entity->typedefe.alignment = alignment;