aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Stallman <rms@gnu.org>1993-03-04 19:41:50 +0000
committerRichard Stallman <rms@gnu.org>1993-03-04 19:41:50 +0000
commit0b1278213bf3d8fbc14be61416a2467755d77ed2 (patch)
tree1396953bff690257dd47bbfaee1b0d5513f7a778 /gcc
parent766f6c304d4173d2b279d29dd096e8aec4fbacc8 (diff)
downloadgcc-0b1278213bf3d8fbc14be61416a2467755d77ed2.zip
gcc-0b1278213bf3d8fbc14be61416a2467755d77ed2.tar.gz
gcc-0b1278213bf3d8fbc14be61416a2467755d77ed2.tar.bz2
(convert_to_real): Convert complex to real.
(convert_to_integer): Likewise. (convert_to_complex): New function. From-SVN: r3639
Diffstat (limited to 'gcc')
-rw-r--r--gcc/convert.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/gcc/convert.c b/gcc/convert.c
index c67f510..f4e6efa 100644
--- a/gcc/convert.c
+++ b/gcc/convert.c
@@ -86,6 +86,10 @@ convert_to_real (type, expr)
if (form == INTEGER_TYPE || form == ENUMERAL_TYPE)
return build1 (FLOAT_EXPR, type, expr);
+ if (form == COMPLEX_TYPE)
+ return convert (type, fold (build1 (REALPART_EXPR,
+ TREE_TYPE (TREE_TYPE (expr)), expr)));
+
if (form == POINTER_TYPE)
error ("pointer value used where a floating point value was expected");
else
@@ -360,6 +364,10 @@ convert_to_integer (type, expr)
if (form == REAL_TYPE)
return build1 (FIX_TRUNC_EXPR, type, expr);
+ if (form == COMPLEX_TYPE)
+ return convert (type, fold (build1 (REALPART_EXPR,
+ TREE_TYPE (TREE_TYPE (expr)), expr)));
+
error ("aggregate value used where an integer was expected");
{
@@ -368,3 +376,50 @@ convert_to_integer (type, expr)
return tem;
}
}
+
+/* Convert EXPR to the complex type TYPE in the usual ways. */
+
+tree
+convert_to_complex (type, expr)
+ tree type, expr;
+{
+ register enum tree_code form = TREE_CODE (TREE_TYPE (expr));
+ tree subtype = TREE_TYPE (type);
+
+ if (form == REAL_TYPE || form == INTEGER_TYPE || form == ENUMERAL_TYPE)
+ {
+ expr = convert (subtype, expr);
+ return build (COMPLEX_EXPR, type, expr,
+ convert (subtype, integer_zero_node));
+ }
+
+ if (form == COMPLEX_TYPE)
+ {
+ if (comptypes (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (expr))))
+ return expr;
+ else if (TREE_CODE (expr) == COMPLEX_EXPR)
+ return fold (build (COMPLEX_EXPR,
+ type,
+ convert (subtype, TREE_OPERAND (expr, 0)),
+ convert (subtype, TREE_OPERAND (expr, 1))));
+ else
+ {
+ expr = save_expr (expr);
+ return fold (build (COMPLEX_EXPR,
+ type,
+ convert (subtype,
+ build_unary_op (REALPART_EXPR, expr, 1)),
+ convert (subtype,
+ build_unary_op (IMAGPART_EXPR, expr, 1))));
+ }
+ }
+
+ if (form == POINTER_TYPE)
+ error ("pointer value used where a complex was expected");
+ else
+ error ("aggregate value used where a complex was expected");
+
+ return build (COMPLEX_EXPR, type,
+ convert (subtype, integer_zero_node),
+ convert (subtype, integer_zero_node));
+}