From 779610287a11b207e958e31a29f0dd9ea5459e39 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Tue, 25 Dec 2012 20:13:14 +0100 Subject: [PATCH] cleanup: Add and use macro MAX(). --- adt/hashset.c.inl | 7 ++----- adt/util.h | 3 +++ ast.c | 2 +- ast2firm.c | 4 +--- attribute.c | 4 +--- format_check.c | 2 +- main.c | 5 ++--- parser.c | 4 +--- type.c | 20 ++++++-------------- 9 files changed, 18 insertions(+), 33 deletions(-) diff --git a/adt/hashset.c.inl b/adt/hashset.c.inl index 06f4312..2782200 100644 --- a/adt/hashset.c.inl +++ b/adt/hashset.c.inl @@ -384,9 +384,7 @@ static inline void maybe_shrink(HashSet *self) return; resize_to = ceil_po2(size); - - if (resize_to < 4) - resize_to = 4; + resize_to = MAX(resize_to, 4); 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) { - if (initial_size < 4) - initial_size = 4; + initial_size = MAX(initial_size, 4); self->entries = Alloc(initial_size); SetRangeEmpty(self->entries, initial_size); diff --git a/adt/util.h b/adt/util.h index 851855b..403a14f 100644 --- a/adt/util.h +++ b/adt/util.h @@ -38,4 +38,7 @@ #define endof(x) ((x) + lengthof(x)) +#undef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + #endif diff --git a/ast.c b/ast.c index e3ce659..ebcb03c 100644 --- 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 ref_addr > ref_ptr ? ref_addr : ref_ptr; + return MAX(ref_addr, ref_ptr); } case EXPR_UNARY_DEREFERENCE: diff --git a/ast2firm.c b/ast2firm.c index fb4e53b..c93c67c 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -193,9 +193,7 @@ static unsigned decide_modulo_shift(unsigned type_size) { 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) diff --git a/attribute.c b/attribute.c index 40c9009..a29299a 100644 --- a/attribute.c +++ b/attribute.c @@ -187,9 +187,7 @@ static void handle_attribute_aligned(const attribute_t *attribute, 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: diff --git a/format_check.c b/format_check.c index d4beefa..41eecca 100644 --- a/format_check.c +++ b/format_check.c @@ -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); - return nt > nf ? nt : nf; + return MAX(nt, nf); } if (fmt_expr->kind != EXPR_STRING_LITERAL) diff --git a/main.c b/main.c index 21d82e9..876416a 100644 --- a/main.c +++ b/main.c @@ -46,6 +46,7 @@ #include #include +#include "adt/util.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 (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) diff --git a/parser.c b/parser.c index b95b756..b637dd2 100644 --- 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)) { - 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 */ diff --git a/type.c b/type.c index 319a9fe..7b938a9 100644 --- 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: { - 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); @@ -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; - if (base_alignment > alignment) - alignment = base_alignment; + alignment = MAX(alignment, base_alignment); 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); - 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); @@ -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); - if (m_size > size) - size = m_size; + size = MAX(size, m_size); 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); -- 2.20.1