aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-tree.cc
diff options
context:
space:
mode:
authorFaisal Abbas <90.abbasfaisal@gmail.com>2022-08-16 12:40:33 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-08-25 12:40:28 +0100
commit4ca228d2f32e5eb6e9516f487be85383225d5a00 (patch)
treee2e870e7baea1e918a9757db8ad6c1e456077ebc /gcc/rust/backend/rust-tree.cc
parentdebe4aedc76a1f52c3072254b6be4da4f4c4696c (diff)
downloadgcc-4ca228d2f32e5eb6e9516f487be85383225d5a00.zip
gcc-4ca228d2f32e5eb6e9516f487be85383225d5a00.tar.gz
gcc-4ca228d2f32e5eb6e9516f487be85383225d5a00.tar.bz2
rust-constexpr.cc: port over cxx_eval_array_reference and
cxx_eval_component_reference. Some important parts are commented out and marked such. These will need revisiting.
Diffstat (limited to 'gcc/rust/backend/rust-tree.cc')
-rw-r--r--gcc/rust/backend/rust-tree.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc
index fc32c7c..ce820f0 100644
--- a/gcc/rust/backend/rust-tree.cc
+++ b/gcc/rust/backend/rust-tree.cc
@@ -6146,4 +6146,63 @@ explain_non_literal_class (tree t)
}
}
+// forked from gcc/cp/call.cc reference_related_p
+
+/* Returns nonzero if T1 is reference-related to T2. */
+
+bool
+reference_related_p (tree t1, tree t2)
+{
+ if (t1 == error_mark_node || t2 == error_mark_node)
+ return false;
+
+ t1 = TYPE_MAIN_VARIANT (t1);
+ t2 = TYPE_MAIN_VARIANT (t2);
+
+ /* [dcl.init.ref]
+
+ Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
+ to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2. */
+ return (similar_type_p (t1, t2)
+ /*|| (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
+ && DERIVED_FROM_P (t1, t2))*/);
+}
+
+// forked from gcc/cp/typeck2.cc ordinary_char_type_p
+
+/* True iff TYPE is a C++20 "ordinary" character type. */
+
+bool
+ordinary_char_type_p (tree type)
+{
+ type = TYPE_MAIN_VARIANT (type);
+ return (type == char_type_node || type == signed_char_type_node
+ || type == unsigned_char_type_node);
+}
+
+// forked from gcc/cp/typeck2.cc array_string_literal_compatible_p
+
+/* True iff the string literal INIT has a type suitable for initializing array
+ TYPE. */
+
+bool
+array_string_literal_compatible_p (tree type, tree init)
+{
+ tree to_char_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
+ tree from_char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
+
+ if (to_char_type == from_char_type)
+ return true;
+ /* The array element type does not match the initializing string
+ literal element type; this is only allowed when both types are
+ ordinary character type. There are no string literals of
+ signed or unsigned char type in the language, but we can get
+ them internally from converting braced-init-lists to
+ STRING_CST. */
+ if (ordinary_char_type_p (to_char_type)
+ && ordinary_char_type_p (from_char_type))
+ return true;
+ return false;
+}
+
} // namespace Rust