1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 // This file is part of GCC.
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
19 #include "rust-compile-context.h"
20 #include "rust-compile-type.h"
25 Context::Context (::Backend
*backend
)
26 : backend (backend
), resolver (Resolver::Resolver::get ()),
27 tyctx (Resolver::TypeCheckContext::get ()),
28 mappings (Analysis::Mappings::get ()), mangler (Mangler ())
34 Context::setup_builtins ()
36 auto builtins
= resolver
->get_builtin_types ();
37 for (auto it
= builtins
.begin (); it
!= builtins
.end (); it
++)
40 bool ok
= tyctx
->lookup_type_by_node_id ((*it
)->get_node_id (), &ref
);
43 TyTy::BaseType
*lookup
;
44 ok
= tyctx
->lookup_type (ref
, &lookup
);
47 TyTyResolveCompile::compile (this, lookup
);
52 Context::type_hasher (tree type
)
56 hstate
.add_int (TREE_CODE (type
));
60 hashval_t record_name_hash
61 = IDENTIFIER_HASH_VALUE (DECL_NAME (TYPE_NAME (type
)));
62 hstate
.add_object (record_name_hash
);
65 for (tree t
= TYPE_ATTRIBUTES (type
); t
; t
= TREE_CHAIN (t
))
66 /* Just the identifier is adequate to distinguish. */
67 hstate
.add_object (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (t
)));
69 switch (TREE_CODE (type
))
72 hstate
.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type
)));
75 for (tree t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
76 if (TREE_VALUE (t
) != error_mark_node
)
77 hstate
.add_object (TYPE_HASH (TREE_VALUE (t
)));
81 hstate
.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type
)));
85 if (TYPE_DOMAIN (type
))
86 hstate
.add_object (TYPE_HASH (TYPE_DOMAIN (type
)));
87 if (!AGGREGATE_TYPE_P (TREE_TYPE (type
)))
89 unsigned typeless
= TYPE_TYPELESS_STORAGE (type
);
90 hstate
.add_object (typeless
);
96 tree t
= TYPE_MAX_VALUE (type
);
98 t
= TYPE_MIN_VALUE (type
);
99 for (int i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
100 hstate
.add_object (TREE_INT_CST_ELT (t
, i
));
105 case FIXED_POINT_TYPE
: {
106 unsigned prec
= TYPE_PRECISION (type
);
107 hstate
.add_object (prec
);
112 hstate
.add_poly_int (TYPE_VECTOR_SUBPARTS (type
));
117 case QUAL_UNION_TYPE
: {
118 for (tree t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
120 hashval_t name_hash
= IDENTIFIER_HASH_VALUE (DECL_NAME (t
));
121 hashval_t type_hash
= type_hasher (TREE_TYPE (t
));
122 hstate
.add_object (name_hash
);
123 hstate
.add_object (type_hash
);
133 hashval_t type_hash
= type_hasher (TREE_TYPE (type
));
134 hstate
.add_object (type_hash
);
142 return hstate
.end ();
145 } // namespace Compile