public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Move cexpr_stree tree string build into utility function
@ 2024-06-12 14:02 Andi Kleen
  2024-06-12 14:25 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Andi Kleen @ 2024-06-12 14:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Andi Kleen

No semantics changes.

gcc/cp/ChangeLog:

	* cp-tree.h (extract): Add new overload to return tree.
	* parser.cc (cp_parser_asm_string_expression): Use tree extract.
	* semantics.cc (cexpr_str::extract): Add new overload to return
	  tree.
---
 gcc/cp/cp-tree.h    |  1 +
 gcc/cp/parser.cc    |  5 +----
 gcc/cp/semantics.cc | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 62718ff126a2..416c60b7311e 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -9026,6 +9026,7 @@ public:
 
   bool type_check (location_t location);
   bool extract (location_t location, const char * & msg, int &len);
+  bool extract (location_t location, tree &str);
   tree message;
 private:
   tree message_data = NULL_TREE;
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 6cd7274046da..de5f0483c120 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -22862,12 +22862,9 @@ cp_parser_asm_string_expression (cp_parser *parser)
       cexpr_str cstr (string);
       if (!cstr.type_check (tok->location))
 	return error_mark_node;
-      const char *msg;
-      int len;
-      if (!cstr.extract (tok->location, msg, len))
+      if (!cstr.extract (tok->location, string))
 	return error_mark_node;
       parens.require_close (parser);
-      string = build_string (len, msg);
       return string;
     }
   else if (!cp_parser_is_string_literal (tok))
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 20f4675833e2..08f5f245e7d1 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11728,6 +11728,20 @@ cexpr_str::type_check (location_t location)
   return true;
 }
 
+/* Extract constant string at LOCATON into output string STR.
+   Returns true if successful, otherwise false.  */
+
+bool
+cexpr_str::extract (location_t location, tree &str)
+{
+  const char *msg;
+  int len;
+  if (!extract (location, msg, len))
+    return false;
+  str = build_string (len, msg);
+  return true;
+}
+
 /* Extract constant string at LOCATION into output string MSG with LEN.
    Returns true if successful, otherwise false.  */
 
-- 
2.45.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Move cexpr_stree tree string build into utility function
  2024-06-12 14:02 [PATCH] Move cexpr_stree tree string build into utility function Andi Kleen
@ 2024-06-12 14:25 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-06-12 14:25 UTC (permalink / raw)
  To: Andi Kleen, gcc-patches

On 6/12/24 10:02, Andi Kleen wrote:
> No semantics changes.
> 
> gcc/cp/ChangeLog:
> 
> 	* cp-tree.h (extract): Add new overload to return tree.
> 	* parser.cc (cp_parser_asm_string_expression): Use tree extract.
> 	* semantics.cc (cexpr_str::extract): Add new overload to return
> 	  tree.

OK.

Jason

> ---
>   gcc/cp/cp-tree.h    |  1 +
>   gcc/cp/parser.cc    |  5 +----
>   gcc/cp/semantics.cc | 14 ++++++++++++++
>   3 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index 62718ff126a2..416c60b7311e 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -9026,6 +9026,7 @@ public:
>   
>     bool type_check (location_t location);
>     bool extract (location_t location, const char * & msg, int &len);
> +  bool extract (location_t location, tree &str);
>     tree message;
>   private:
>     tree message_data = NULL_TREE;
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 6cd7274046da..de5f0483c120 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -22862,12 +22862,9 @@ cp_parser_asm_string_expression (cp_parser *parser)
>         cexpr_str cstr (string);
>         if (!cstr.type_check (tok->location))
>   	return error_mark_node;
> -      const char *msg;
> -      int len;
> -      if (!cstr.extract (tok->location, msg, len))
> +      if (!cstr.extract (tok->location, string))
>   	return error_mark_node;
>         parens.require_close (parser);
> -      string = build_string (len, msg);
>         return string;
>       }
>     else if (!cp_parser_is_string_literal (tok))
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 20f4675833e2..08f5f245e7d1 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -11728,6 +11728,20 @@ cexpr_str::type_check (location_t location)
>     return true;
>   }
>   
> +/* Extract constant string at LOCATON into output string STR.
> +   Returns true if successful, otherwise false.  */
> +
> +bool
> +cexpr_str::extract (location_t location, tree &str)
> +{
> +  const char *msg;
> +  int len;
> +  if (!extract (location, msg, len))
> +    return false;
> +  str = build_string (len, msg);
> +  return true;
> +}
> +
>   /* Extract constant string at LOCATION into output string MSG with LEN.
>      Returns true if successful, otherwise false.  */
>   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-12 14:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-12 14:02 [PATCH] Move cexpr_stree tree string build into utility function Andi Kleen
2024-06-12 14:25 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).