aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorFaisal Abbas <90.abbasfaisal@gmail.com>2022-07-10 12:38:12 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-08-25 12:40:24 +0100
commitb394fe4571f6c6207c1135da1297bf44f750bbf4 (patch)
tree2a89d61ab839546319f052fe9e37e73c9e9b267d /gcc/rust/backend
parentb9c08d705e6174bbbd0670b196d24e00b6f84d33 (diff)
downloadgcc-b394fe4571f6c6207c1135da1297bf44f750bbf4.zip
gcc-b394fe4571f6c6207c1135da1297bf44f750bbf4.tar.gz
gcc-b394fe4571f6c6207c1135da1297bf44f750bbf4.tar.bz2
gccrs const folding port: continue porting potential_constant_expression_1()
Following functions are ported in this changeset: - get_fileinfo - cxx_make_type - build_min_array_type - identifier_p Following structs are ported in this changeset: - c_fileinfo Signed-off-by: Faisal Abbas <90.abbasfaisal@gmail.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-tree.cc62
-rw-r--r--gcc/rust/backend/rust-tree.h89
2 files changed, 150 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc
index 4359c3d..73c50a4 100644
--- a/gcc/rust/backend/rust-tree.cc
+++ b/gcc/rust/backend/rust-tree.cc
@@ -21,6 +21,7 @@
#include "stringpool.h"
#include "attribs.h"
#include "escaped_string.h"
+#include "libiberty.h"
namespace Rust {
@@ -1463,4 +1464,65 @@ maybe_add_lang_type_raw (tree t)
return true;
}
+// forked from gcc/c-family/c-lex.cc get_fileinfo
+
+static splay_tree file_info_tree;
+
+struct c_fileinfo *
+get_fileinfo (const char *name)
+{
+ splay_tree_node n;
+ struct c_fileinfo *fi;
+
+ if (!file_info_tree)
+ file_info_tree = splay_tree_new (splay_tree_compare_strings, 0,
+ splay_tree_delete_pointers);
+
+ n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
+ if (n)
+ return (struct c_fileinfo *) n->value;
+
+ fi = XNEW (struct c_fileinfo);
+ fi->time = 0;
+ fi->interface_only = 0;
+ fi->interface_unknown = 1;
+ splay_tree_insert (file_info_tree, (splay_tree_key) name,
+ (splay_tree_value) fi);
+ return fi;
+}
+
+// forked from gcc/cp/lex.cc cxx_make_type
+
+tree
+cxx_make_type (enum tree_code code MEM_STAT_DECL)
+{
+ tree t = make_node (code PASS_MEM_STAT);
+
+ if (maybe_add_lang_type_raw (t))
+ {
+ /* Set up some flags that give proper default behavior. */
+ struct c_fileinfo *finfo = get_fileinfo (LOCATION_FILE (input_location));
+ SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
+ CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
+ }
+
+ if (code == RECORD_TYPE || code == UNION_TYPE)
+ TYPE_CXX_ODR_P (t) = 1;
+
+ return t;
+}
+
+// forked from gcc/cp/tree.cc build_min_array_type
+
+/* Build an ARRAY_TYPE without laying it out. */
+
+static tree
+build_min_array_type (tree elt_type, tree index_type)
+{
+ tree t = cxx_make_type (ARRAY_TYPE);
+ TREE_TYPE (t) = elt_type;
+ TYPE_DOMAIN (t) = index_type;
+ return t;
+}
+
} // namespace Rust
diff --git a/gcc/rust/backend/rust-tree.h b/gcc/rust/backend/rust-tree.h
index 99ec33c..e352268 100644
--- a/gcc/rust/backend/rust-tree.h
+++ b/gcc/rust/backend/rust-tree.h
@@ -23,6 +23,7 @@
#include "coretypes.h"
#include "tree.h"
#include "cpplib.h"
+#include "splay-tree.h"
/* Returns true if NODE is a pointer. */
#define TYPE_PTR_P(NODE) (TREE_CODE (NODE) == POINTER_TYPE)
@@ -677,7 +678,7 @@ extern GTY (()) tree cp_global_trees[CPTI_MAX];
pointer to member function. TYPE_PTRMEMFUNC_P _must_ be true,
before using this macro. */
#define TYPE_PTRMEMFUNC_FN_TYPE(NODE) \
- (cp_build_qualified_type (TREE_TYPE (TYPE_FIELDS (NODE)), \
+ (rs_build_qualified_type (TREE_TYPE (TYPE_FIELDS (NODE)), \
rs_type_quals (NODE)))
/* As above, but can be used in places that want an lvalue at the expense
@@ -733,6 +734,17 @@ extern GTY (()) tree cp_global_trees[CPTI_MAX];
/* The expression in question for a DECLTYPE_TYPE. */
#define DECLTYPE_TYPE_EXPR(NODE) (TYPE_VALUES_RAW (DECLTYPE_TYPE_CHECK (NODE)))
+#define SET_CLASSTYPE_INTERFACE_UNKNOWN_X(NODE, X) \
+ (LANG_TYPE_CLASS_CHECK (NODE)->interface_unknown = !!(X))
+
+/* Nonzero if this class is included from a header file which employs
+ `#pragma interface', and it is not included in its implementation file. */
+#define CLASSTYPE_INTERFACE_ONLY(NODE) \
+ (LANG_TYPE_CLASS_CHECK (NODE)->interface_only)
+
+#define TYPE_NAME_STRING(NODE) (IDENTIFIER_POINTER (TYPE_IDENTIFIER (NODE)))
+#define TYPE_NAME_LENGTH(NODE) (IDENTIFIER_LENGTH (TYPE_IDENTIFIER (NODE)))
+
// Below macros are copied from gcc/c-family/c-common.h
/* In a FIELD_DECL, nonzero if the decl was originally a bitfield. */
@@ -798,6 +810,24 @@ extern GTY (()) tree cp_global_trees[CPTI_MAX];
// Above macros are copied from gcc/cp/name-lookup.cc
+// forked from gcc/c-family/c-common.h c_fileinfo
+
+/* Information recorded about each file examined during compilation. */
+
+struct c_fileinfo
+{
+ int time; /* Time spent in the file. */
+
+ /* Flags used only by C++.
+ INTERFACE_ONLY nonzero means that we are in an "interface" section
+ of the compiler. INTERFACE_UNKNOWN nonzero means we cannot trust
+ the value of INTERFACE_ONLY. If INTERFACE_UNKNOWN is zero and
+ INTERFACE_ONLY is zero, it means that we are responsible for
+ exporting definitions that others might need. */
+ short interface_only;
+ short interface_unknown;
+};
+
// forked from gcc/cp/name-lookup.h
/* Datatype that represents binding established by a declaration between
@@ -1287,6 +1317,50 @@ inline tree ovl_first (tree) ATTRIBUTE_PURE;
inline bool type_unknown_p (const_tree);
extern tree
+lookup_add (tree fns, tree lookup);
+
+extern tree
+ovl_make (tree fn, tree next = NULL_TREE);
+
+extern int is_overloaded_fn (tree) ATTRIBUTE_PURE;
+
+extern bool maybe_add_lang_type_raw (tree);
+
+extern rs_ref_qualifier type_memfn_rqual (const_tree);
+
+extern bool builtin_pack_fn_p (tree);
+
+extern tree make_conv_op_name (tree);
+
+extern int type_memfn_quals (const_tree);
+
+struct c_fileinfo *
+get_fileinfo (const char *);
+
+extern tree
+cxx_make_type (enum tree_code CXX_MEM_STAT_INFO);
+
+extern tree
+build_cplus_array_type (tree, tree, int is_dep = -1);
+
+extern bool is_byte_access_type (tree);
+
+// forked from gcc/cp/cp-tree.h
+
+enum
+{
+ ce_derived,
+ ce_type,
+ ce_normal,
+ ce_exact
+};
+
+extern tree
+rs_build_qualified_type_real (tree, int, tsubst_flags_t);
+#define rs_build_qualified_type(TYPE, QUALS) \
+ rs_build_qualified_type_real ((TYPE), (QUALS), tf_warning_or_error)
+
+extern tree
rs_walk_subtrees (tree *, int *, walk_tree_fn, void *, hash_set<tree> *);
#define rs_walk_tree(tp, func, data, pset) \
walk_tree_1 (tp, func, data, pset, rs_walk_subtrees)
@@ -1354,6 +1428,19 @@ class_of_this_parm (const_tree fntype)
{
return TREE_TYPE (type_of_this_parm (fntype));
}
+
+// forked from gcc/cp/cp-tree.h identifier_p
+
+/* Return a typed pointer version of T if it designates a
+ C++ front-end identifier. */
+inline lang_identifier *
+identifier_p (tree t)
+{
+ if (TREE_CODE (t) == IDENTIFIER_NODE)
+ return (lang_identifier *) t;
+ return NULL;
+}
+
} // namespace Rust
#endif // RUST_TREE