diff mbox series

[1/4] as-name: add and use show_as()

Message ID 20181208220401.10409-2-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series display address spaces by name | expand

Commit Message

Luc Van Oostenryck Dec. 8, 2018, 10:03 p.m. UTC
Use a function to display the address spaces.
This will allow to display a real name instead of '<asn:1>'.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c   |  6 +++---
 show-parse.c | 13 ++++++++++++-
 symbol.h     |  1 +
 3 files changed, 16 insertions(+), 4 deletions(-)

Comments

Ramsay Jones Dec. 9, 2018, 2:48 a.m. UTC | #1
On 08/12/2018 22:03, Luc Van Oostenryck wrote:
> Use a function to display the address spaces.
> This will allow to display a real name instead of '<asn:1>'.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  evaluate.c   |  6 +++---
>  show-parse.c | 13 ++++++++++++-
>  symbol.h     |  1 +
>  3 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/evaluate.c b/evaluate.c
> index 9c2304a7e..f4d49a678 100644
> --- a/evaluate.c
> +++ b/evaluate.c
> @@ -3018,13 +3018,13 @@ static struct symbol *evaluate_cast(struct expression *expr)
>  	}
>  
>  	if (!tas && sas > 0)
> -		warning(expr->pos, "cast removes address space of expression (<asn:%d>)", sas);
> +		warning(expr->pos, "cast removes address space '%s' from expression", show_as(sas));
>  	if (tas > 0 && sas > 0 && tas != sas)
> -		warning(expr->pos, "cast between address spaces (<asn:%d>-><asn:%d>)", sas, tas);
> +		warning(expr->pos, "cast between address spaces (%s - %s)", show_as(sas), show_as(tas));

s/-/->/ ?

ATB,
Ramsay Jones

>  	if (tas > 0 && !sas &&
>  	    !is_null_pointer_constant(source) && Wcast_to_as)
>  		warning(expr->pos,
> -			"cast adds address space to expression (<asn:%d>)", tas);
> +			"cast adds address space '%s' to expression", show_as(tas));
>  
>  	if (!(ttype->ctype.modifiers & MOD_PTRINHERIT) && tclass == TYPE_PTR &&
>  	    !tas && (source->flags & CEF_ICE)) {
> diff --git a/show-parse.c b/show-parse.c
> index 6328439c9..89afdb5f4 100644
> --- a/show-parse.c
> +++ b/show-parse.c
> @@ -182,6 +182,17 @@ void show_symbol_list(struct symbol_list *list, const char *sep)
>  	} END_FOR_EACH_PTR(sym);
>  }
>  
> +const char *show_as(unsigned int as)
> +{
> +	static char buffer[2][32];
> +	static int n;
> +	char *buff;
> +
> +	buff = buffer[2 & ++n];
> +	sprintf(buff, "<asn:%u>", as);
> +	return buff;
> +}
> +
>  struct type_name {
>  	char *start;
>  	char *end;
> @@ -288,7 +299,7 @@ deeper:
>  		size_t len;
>  
>  		if (as)
> -			prepend(name, "<asn:%d>", as);
> +			prepend(name, "%s ", show_as(as));
>  
>  		s = modifier_string(mod);
>  		len = strlen(s);
> diff --git a/symbol.h b/symbol.h
> index 5a3d7cef5..b8e0cac82 100644
> --- a/symbol.h
> +++ b/symbol.h
> @@ -315,6 +315,7 @@ extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
>  
>  extern struct symbol *examine_symbol_type(struct symbol *);
>  extern struct symbol *examine_pointer_target(struct symbol *);
> +extern const char *show_as(unsigned int as);
>  extern const char *show_typename(struct symbol *sym);
>  extern const char *builtin_typename(struct symbol *sym);
>  extern const char *builtin_ctypename(struct ctype *ctype);
>
Luc Van Oostenryck Dec. 9, 2018, 1:19 p.m. UTC | #2
On Sun, Dec 09, 2018 at 02:48:15AM +0000, Ramsay Jones wrote:
> On 08/12/2018 22:03, Luc Van Oostenryck wrote:
> > @@ -3018,13 +3018,13 @@ static struct symbol *evaluate_cast(struct expression *expr)
> >  	}
> >  
> >  	if (!tas && sas > 0)
> > -		warning(expr->pos, "cast removes address space of expression (<asn:%d>)", sas);
> > +		warning(expr->pos, "cast removes address space '%s' from expression", show_as(sas));
> >  	if (tas > 0 && sas > 0 && tas != sas)
> > -		warning(expr->pos, "cast between address spaces (<asn:%d>-><asn:%d>)", sas, tas);
> > +		warning(expr->pos, "cast between address spaces (%s - %s)", show_as(sas), show_as(tas));
> 
> s/-/->/ ?

Yes, it's slightly more clear.

Thanks,
-- Luc
diff mbox series

Patch

diff --git a/evaluate.c b/evaluate.c
index 9c2304a7e..f4d49a678 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3018,13 +3018,13 @@  static struct symbol *evaluate_cast(struct expression *expr)
 	}
 
 	if (!tas && sas > 0)
-		warning(expr->pos, "cast removes address space of expression (<asn:%d>)", sas);
+		warning(expr->pos, "cast removes address space '%s' from expression", show_as(sas));
 	if (tas > 0 && sas > 0 && tas != sas)
-		warning(expr->pos, "cast between address spaces (<asn:%d>-><asn:%d>)", sas, tas);
+		warning(expr->pos, "cast between address spaces (%s - %s)", show_as(sas), show_as(tas));
 	if (tas > 0 && !sas &&
 	    !is_null_pointer_constant(source) && Wcast_to_as)
 		warning(expr->pos,
-			"cast adds address space to expression (<asn:%d>)", tas);
+			"cast adds address space '%s' to expression", show_as(tas));
 
 	if (!(ttype->ctype.modifiers & MOD_PTRINHERIT) && tclass == TYPE_PTR &&
 	    !tas && (source->flags & CEF_ICE)) {
diff --git a/show-parse.c b/show-parse.c
index 6328439c9..89afdb5f4 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -182,6 +182,17 @@  void show_symbol_list(struct symbol_list *list, const char *sep)
 	} END_FOR_EACH_PTR(sym);
 }
 
+const char *show_as(unsigned int as)
+{
+	static char buffer[2][32];
+	static int n;
+	char *buff;
+
+	buff = buffer[2 & ++n];
+	sprintf(buff, "<asn:%u>", as);
+	return buff;
+}
+
 struct type_name {
 	char *start;
 	char *end;
@@ -288,7 +299,7 @@  deeper:
 		size_t len;
 
 		if (as)
-			prepend(name, "<asn:%d>", as);
+			prepend(name, "%s ", show_as(as));
 
 		s = modifier_string(mod);
 		len = strlen(s);
diff --git a/symbol.h b/symbol.h
index 5a3d7cef5..b8e0cac82 100644
--- a/symbol.h
+++ b/symbol.h
@@ -315,6 +315,7 @@  extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
 
 extern struct symbol *examine_symbol_type(struct symbol *);
 extern struct symbol *examine_pointer_target(struct symbol *);
+extern const char *show_as(unsigned int as);
 extern const char *show_typename(struct symbol *sym);
 extern const char *builtin_typename(struct symbol *sym);
 extern const char *builtin_ctypename(struct ctype *ctype);