diff mbox series

[3/4] typeof: extract examine_typeof() from examine_symbol_type()

Message ID 20191215110425.76533-4-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series tidy-up of typeof expansion | expand

Commit Message

Luc Van Oostenryck Dec. 15, 2019, 11:04 a.m. UTC
No functional changes here, just moving the code for the
conversion of SYM_TYPEOFs in its own function, in preparation
for some further changes.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 symbol.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

Comments

Ramsay Jones Dec. 15, 2019, 7:20 p.m. UTC | #1
On 15/12/2019 11:04, Luc Van Oostenryck wrote:
> No functional changes here, just moving the code for the
> conversion of SYM_TYPEOFs in its own function, in preparation
> for some further changes.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  symbol.c | 41 +++++++++++++++++++++--------------------
>  1 file changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/symbol.c b/symbol.c
> index 3655cbb78913..46fe740b4cc1 100644
> --- a/symbol.c
> +++ b/symbol.c
> @@ -453,6 +453,25 @@ static struct symbol *examine_pointer_type(struct symbol *sym)
>  	return sym;
>  }
>  
> +static struct symbol *examine_typeof(struct symbol *sym)
> +{
> +	struct symbol *base = evaluate_expression(sym->initializer);
> +	unsigned long mod = 0;
> +
> +	if (!base)
> +		base = &bad_ctype;
> +	if (is_bitfield_type(base))
> +		warning(base->pos, "typeof applied to bitfield type");
> +	if (base->type == SYM_NODE) {
> +		mod |= base->ctype.modifiers & MOD_TYPEOF;
> +		base = base->ctype.base_type;
> +	}
> +	sym->type = SYM_NODE;
> +	sym->ctype.modifiers = mod;
> +	sym->ctype.base_type = base;
> +	return examine_node_type(sym);
> +}
> +
>  /*
>   * Fill in type size and alignment information for
>   * regular SYM_TYPE things.
> @@ -486,26 +505,8 @@ struct symbol *examine_symbol_type(struct symbol * sym)
>  	case SYM_BASETYPE:
>  		/* Size and alignment had better already be set up */
>  		return sym;
> -	case SYM_TYPEOF: {
> -		struct symbol *base = evaluate_expression(sym->initializer);
> -		if (base) {
> -			unsigned long mod = 0;
> -
> -			if (is_bitfield_type(base))
> -				warning(base->pos, "typeof applied to bitfield type");
> -			if (base->type == SYM_NODE) {
> -				mod |= base->ctype.modifiers & MOD_TYPEOF;
> -				base = base->ctype.base_type;
> -			}
> -			sym->type = SYM_NODE;
> -			sym->ctype.modifiers = mod;
> -			sym->ctype.base_type = base;
> -			return examine_node_type(sym);
> -		}
> -		sym->type = SYM_NODE;
> -		sym->ctype.base_type = &bad_ctype;
> -		return sym;

Hmm, it was not immediately clear that the '!base' path did not
introduce an (effective) functional change. I suspect that it
does not, but I wasn't sure if examine_node_type(sym) for the
above 'bad_ctype' symbol would add alignment, bit_size or rank
to the symbol (and even if it did, would it matter?).

ATB,
Ramsay Jones

> -	}
> +	case SYM_TYPEOF:
> +		return examine_typeof(sym);
>  	case SYM_PREPROCESSOR:
>  		sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
>  		return NULL;
>
Luc Van Oostenryck Dec. 15, 2019, 7:26 p.m. UTC | #2
On Sun, Dec 15, 2019 at 07:20:34PM +0000, Ramsay Jones wrote:
> On 15/12/2019 11:04, Luc Van Oostenryck wrote:
> 
> Hmm, it was not immediately clear that the '!base' path did not
> introduce an (effective) functional change. I suspect that it
> does not, but I wasn't sure if examine_node_type(sym) for the
> above 'bad_ctype' symbol would add alignment, bit_size or rank
> to the symbol (and even if it did, would it matter?).

Mmmm, yes. It shouldn't matter but I prefer to avoid this.

Thanks for noticing.
-- Luc
Luc Van Oostenryck Dec. 15, 2019, 7:55 p.m. UTC | #3
On Sun, Dec 15, 2019 at 08:26:44PM +0100, Luc Van Oostenryck wrote:
> On Sun, Dec 15, 2019 at 07:20:34PM +0000, Ramsay Jones wrote:
> > On 15/12/2019 11:04, Luc Van Oostenryck wrote:
> > 
> > Hmm, it was not immediately clear that the '!base' path did not
> > introduce an (effective) functional change. I suspect that it
> > does not, but I wasn't sure if examine_node_type(sym) for the
> > above 'bad_ctype' symbol would add alignment, bit_size or rank
> > to the symbol (and even if it did, would it matter?).
> 
> Mmmm, yes. It shouldn't matter but I prefer to avoid this.

OTOH, examine_symbol_type() can anyway be called on it later.
So, I'll leave it so as I find it more readable.

-- Luc
diff mbox series

Patch

diff --git a/symbol.c b/symbol.c
index 3655cbb78913..46fe740b4cc1 100644
--- a/symbol.c
+++ b/symbol.c
@@ -453,6 +453,25 @@  static struct symbol *examine_pointer_type(struct symbol *sym)
 	return sym;
 }
 
+static struct symbol *examine_typeof(struct symbol *sym)
+{
+	struct symbol *base = evaluate_expression(sym->initializer);
+	unsigned long mod = 0;
+
+	if (!base)
+		base = &bad_ctype;
+	if (is_bitfield_type(base))
+		warning(base->pos, "typeof applied to bitfield type");
+	if (base->type == SYM_NODE) {
+		mod |= base->ctype.modifiers & MOD_TYPEOF;
+		base = base->ctype.base_type;
+	}
+	sym->type = SYM_NODE;
+	sym->ctype.modifiers = mod;
+	sym->ctype.base_type = base;
+	return examine_node_type(sym);
+}
+
 /*
  * Fill in type size and alignment information for
  * regular SYM_TYPE things.
@@ -486,26 +505,8 @@  struct symbol *examine_symbol_type(struct symbol * sym)
 	case SYM_BASETYPE:
 		/* Size and alignment had better already be set up */
 		return sym;
-	case SYM_TYPEOF: {
-		struct symbol *base = evaluate_expression(sym->initializer);
-		if (base) {
-			unsigned long mod = 0;
-
-			if (is_bitfield_type(base))
-				warning(base->pos, "typeof applied to bitfield type");
-			if (base->type == SYM_NODE) {
-				mod |= base->ctype.modifiers & MOD_TYPEOF;
-				base = base->ctype.base_type;
-			}
-			sym->type = SYM_NODE;
-			sym->ctype.modifiers = mod;
-			sym->ctype.base_type = base;
-			return examine_node_type(sym);
-		}
-		sym->type = SYM_NODE;
-		sym->ctype.base_type = &bad_ctype;
-		return sym;
-	}
+	case SYM_TYPEOF:
+		return examine_typeof(sym);
 	case SYM_PREPROCESSOR:
 		sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
 		return NULL;