[gcc(refs/users/mikael/heads/refactor_descriptor_v291.01)] Extraction gfc_set_descriptor_from_scalar

Mikael Morin via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:93ac80b16a25affd8ab1a7f0d1ef9d25005838ef

commit 93ac80b16a25affd8ab1a7f0d1ef9d25005838ef
Author: Mikael Morin <[email protected]>
Date:   Thu Aug 7 14:11:43 2025 +0200

    Extraction gfc_set_descriptor_from_scalar
    
    Correction gfc_get_scalar_to_descriptor_type
    
    Renommage set_descriptor_from_scalar{,_class}

Diff:
---
 gcc/fortran/trans-descriptor.cc | 17 +++++++++++++++++
 gcc/fortran/trans-descriptor.h  |  2 ++
 gcc/fortran/trans-expr.cc       | 13 +------------
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 8c44c68836c8..f227e998e6ec 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -993,3 +993,20 @@ gfc_create_null_actual_descriptor (stmtblock_t *block, gfc_typespec *ts,
 
   return desc;
 }
+
+
+void
+gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
+				      tree scalar, gfc_expr *scalar_expr)
+{
+  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
+						 gfc_expr_attr (scalar_expr));
+  gfc_conv_descriptor_dtype_set (block, descr,
+				 gfc_get_dtype (type));
+
+  tree tmp = gfc_class_data_get (scalar);
+  if (!POINTER_TYPE_P (TREE_TYPE (tmp)))
+    tmp = gfc_build_addr_expr (NULL_TREE, tmp);
+
+  gfc_conv_descriptor_data_set (block, descr, tmp);
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 1e419bb7d964..3eb120e52f78 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -83,4 +83,6 @@ tree gfc_create_null_actual_descriptor (stmtblock_t *, gfc_typespec *,
 
 void gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, tree descr);
 
+void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr *);
+
 #endif /* GFC_TRANS_DESCRIPTOR_H */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index a36734564b7f..13e3dab729b6 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1378,18 +1378,7 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, gfc_typespec class_ts,
       && e->rank != class_ts.u.derived->components->as->rank)
     {
       if (e->rank == 0)
-	{
-	  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (parmse->expr),
-							 gfc_expr_attr (e));
-	  gfc_conv_descriptor_dtype_set (&block, ctree,
-					 gfc_get_dtype (type));
-
-	  tmp = gfc_class_data_get (parmse->expr);
-	  if (!POINTER_TYPE_P (TREE_TYPE (tmp)))
-	    tmp = gfc_build_addr_expr (NULL_TREE, tmp);
-
-	  gfc_conv_descriptor_data_set (&block, ctree, tmp);
-	}
+	gfc_set_descriptor_from_scalar_class (&block, ctree, parmse->expr, e);
       else
 	gfc_class_array_data_assign (&block, ctree, parmse->expr, false);
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.