cleanup: Add and use macro MAX().
authorChristoph Mallon <christoph.mallon@gmx.de>
Tue, 25 Dec 2012 19:13:14 +0000 (20:13 +0100)
committerChristoph Mallon <christoph.mallon@gmx.de>
Thu, 27 Dec 2012 14:54:10 +0000 (15:54 +0100)
adt/hashset.c.inl
adt/util.h
ast.c
ast2firm.c
attribute.c
format_check.c
main.c
parser.c
type.c

index 06f4312..2782200 100644 (file)
@@ -384,9 +384,7 @@ static inline void maybe_shrink(HashSet *self)
                return;
 
        resize_to = ceil_po2(size);
                return;
 
        resize_to = ceil_po2(size);
-
-       if (resize_to < 4)
-               resize_to = 4;
+       resize_to = MAX(resize_to, 4);
 
        resize(self, resize_to);
 }
 
        resize(self, resize_to);
 }
@@ -502,8 +500,7 @@ void hashset_remove(HashSet *self, ConstKeyType key)
  */
 static inline void init_size(HashSet *self, size_t initial_size)
 {
  */
 static inline void init_size(HashSet *self, size_t initial_size)
 {
-       if (initial_size < 4)
-               initial_size = 4;
+       initial_size = MAX(initial_size, 4);
 
        self->entries         = Alloc(initial_size);
        SetRangeEmpty(self->entries, initial_size);
 
        self->entries         = Alloc(initial_size);
        SetRangeEmpty(self->entries, initial_size);
index 851855b..403a14f 100644 (file)
@@ -38,4 +38,7 @@
 
 #define endof(x) ((x) + lengthof(x))
 
 
 #define endof(x) ((x) + lengthof(x))
 
+#undef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
 #endif
 #endif
diff --git a/ast.c b/ast.c
index e3ce659..ebcb03c 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1712,7 +1712,7 @@ static expression_classification_t is_object_with_constant_address(const express
                        return idx_class;
                expression_classification_t const ref_addr = is_object_with_constant_address(array_access->array_ref);
                expression_classification_t const ref_ptr  = is_constant_pointer(array_access->array_ref);
                        return idx_class;
                expression_classification_t const ref_addr = is_object_with_constant_address(array_access->array_ref);
                expression_classification_t const ref_ptr  = is_constant_pointer(array_access->array_ref);
-               return ref_addr > ref_ptr ? ref_addr : ref_ptr;
+               return MAX(ref_addr, ref_ptr);
        }
 
        case EXPR_UNARY_DEREFERENCE:
        }
 
        case EXPR_UNARY_DEREFERENCE:
index fb4e53b..c93c67c 100644 (file)
@@ -193,9 +193,7 @@ static unsigned decide_modulo_shift(unsigned type_size)
 {
        if (architecture_modulo_shift == 0)
                return 0;
 {
        if (architecture_modulo_shift == 0)
                return 0;
-       if (type_size < architecture_modulo_shift)
-               return architecture_modulo_shift;
-       return type_size;
+       return MAX(type_size, architecture_modulo_shift);
 }
 
 static ir_mode *init_atomic_ir_mode(atomic_type_kind_t kind)
 }
 
 static ir_mode *init_atomic_ir_mode(atomic_type_kind_t kind)
index 40c9009..a29299a 100644 (file)
@@ -187,9 +187,7 @@ static void handle_attribute_aligned(const attribute_t *attribute,
                break;
        case ENTITY_STRUCT:
        case ENTITY_UNION:
                break;
        case ENTITY_STRUCT:
        case ENTITY_UNION:
-               if (alignment > (int)entity->compound.alignment) {
-                       entity->compound.alignment = alignment;
-               }
+               entity->compound.alignment = MAX(entity->compound.alignment, (il_alignment_t)alignment);
                break;
 
        default:
                break;
 
        default:
index d4beefa..41eecca 100644 (file)
@@ -109,7 +109,7 @@ static int internal_check_printf_format(const expression_t *fmt_expr,
                        t = c->condition;
                int const nt = internal_check_printf_format(t,                   arg, spec);
                int const nf = internal_check_printf_format(c->false_expression, arg, spec);
                        t = c->condition;
                int const nt = internal_check_printf_format(t,                   arg, spec);
                int const nf = internal_check_printf_format(c->false_expression, arg, spec);
-               return nt > nf ? nt : nf;
+               return MAX(nt, nf);
        }
 
        if (fmt_expr->kind != EXPR_STRING_LITERAL)
        }
 
        if (fmt_expr->kind != EXPR_STRING_LITERAL)
diff --git a/main.c b/main.c
index 21d82e9..876416a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -46,6 +46,7 @@
 #include <libfirm/be.h>
 #include <libfirm/statev.h>
 
 #include <libfirm/be.h>
 #include <libfirm/statev.h>
 
+#include "adt/util.h"
 #include "ast_t.h"
 #include "preprocessor.h"
 #include "token_t.h"
 #include "ast_t.h"
 #include "preprocessor.h"
 #include "token_t.h"
@@ -900,9 +901,7 @@ static unsigned decide_modulo_shift(unsigned type_size)
 {
        if (architecture_modulo_shift == 0)
                return 0;
 {
        if (architecture_modulo_shift == 0)
                return 0;
-       if (type_size < architecture_modulo_shift)
-               return architecture_modulo_shift;
-       return type_size;
+       return MAX(type_size, architecture_modulo_shift);
 }
 
 static bool is_ia32_cpu(const char *architecture)
 }
 
 static bool is_ia32_cpu(const char *architecture)
index b95b756..b637dd2 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2106,9 +2106,7 @@ finish_designator:
                type_t                  *first_type = first->type;
                first_type                          = skip_typeref(first_type);
                if (is_type_array(first_type)) {
                type_t                  *first_type = first->type;
                first_type                          = skip_typeref(first_type);
                if (is_type_array(first_type)) {
-                       size_t index = first->v.index;
-                       if (index > path->max_index)
-                               path->max_index = index;
+                       path->max_index = MAX(path->max_index, first->v.index);
                }
 
                /* append to initializers list */
                }
 
                /* append to initializers list */
diff --git a/type.c b/type.c
index 319a9fe..7b938a9 100644 (file)
--- a/type.c
+++ b/type.c
@@ -1084,12 +1084,8 @@ unsigned get_type_alignment(type_t *type)
        case TYPE_ARRAY:
                return get_type_alignment(type->array.element_type);
        case TYPE_TYPEDEF: {
        case TYPE_ARRAY:
                return get_type_alignment(type->array.element_type);
        case TYPE_TYPEDEF: {
-               il_alignment_t alignment
-                       = get_type_alignment(type->typedeft.typedefe->type);
-               if (type->typedeft.typedefe->alignment > alignment)
-                       alignment = type->typedeft.typedefe->alignment;
-
-               return alignment;
+               il_alignment_t const alignment = get_type_alignment(type->typedeft.typedefe->type);
+               return MAX(alignment, type->typedeft.typedefe->alignment);
        }
        case TYPE_TYPEOF:
                return get_type_alignment(type->typeoft.typeof_type);
        }
        case TYPE_TYPEOF:
                return get_type_alignment(type->typeoft.typeof_type);
@@ -1385,8 +1381,7 @@ static entity_t *pack_bitfield_members(il_size_t *struct_offset,
                type_t *const base_type = skip_typeref(member->declaration.type);
                il_alignment_t base_alignment = get_type_alignment_compound(base_type);
                il_alignment_t alignment_mask = base_alignment-1;
                type_t *const base_type = skip_typeref(member->declaration.type);
                il_alignment_t base_alignment = get_type_alignment_compound(base_type);
                il_alignment_t alignment_mask = base_alignment-1;
-               if (base_alignment > alignment)
-                       alignment = base_alignment;
+               alignment = MAX(alignment, base_alignment);
 
                size_t bit_size = member->compound_member.bit_size;
                if (!packed) {
 
                size_t bit_size = member->compound_member.bit_size;
                if (!packed) {
@@ -1454,8 +1449,7 @@ void layout_struct_type(compound_type_t *type)
                }
 
                il_alignment_t m_alignment = get_type_alignment_compound(m_type);
                }
 
                il_alignment_t m_alignment = get_type_alignment_compound(m_type);
-               if (m_alignment > alignment)
-                       alignment = m_alignment;
+               alignment = MAX(alignment, m_alignment);
 
                if (!compound->packed) {
                        il_size_t const new_offset = round_up2(offset, m_alignment);
 
                if (!compound->packed) {
                        il_size_t const new_offset = round_up2(offset, m_alignment);
@@ -1516,11 +1510,9 @@ void layout_union_type(compound_type_t *type)
 
                entry->compound_member.offset = 0;
                il_size_t m_size = get_type_size(m_type);
 
                entry->compound_member.offset = 0;
                il_size_t m_size = get_type_size(m_type);
-               if (m_size > size)
-                       size = m_size;
+               size = MAX(size, m_size);
                il_alignment_t m_alignment = get_type_alignment_compound(m_type);
                il_alignment_t m_alignment = get_type_alignment_compound(m_type);
-               if (m_alignment > alignment)
-                       alignment = m_alignment;
+               alignment = MAX(alignment, m_alignment);
        }
        size = round_up2(size, alignment);
 
        }
        size = round_up2(size, alignment);