]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add a simulate_enum_decl langhook
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 29 Oct 2019 08:39:45 +0000 (08:39 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Tue, 29 Oct 2019 08:39:45 +0000 (08:39 +0000)
Similarly to the simulate_builtin_function_decl patch, this one
adds a hook for simulating an enum declaration in the source
language.  Again, the main SVE ACLE patch has tests for various
error conditions.

2019-10-29  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* coretypes.h (string_int_pair): New typedef.
* langhooks-def.h (LANG_HOOKS_SIMULATE_ENUM_DECL): Define.
(LANG_HOOKS_FOR_TYPES_INITIALIZER): Include it.
* langhooks.h (lang_hooks_for_types::simulate_enum_decl): New hook.

gcc/c/
* c-tree.h (c_simulate_enum_decl): Declare.
* c-decl.c (c_simulate_enum_decl): New function.
* c-objc-common.h (LANG_HOOKS_SIMULATE_ENUM_DECL): Define to the above.

gcc/cp/
* cp-objcp-common.h (cxx_simulate_enum_decl): Declare.
(LANG_HOOKS_SIMULATE_ENUM_DECL): Define to the above.
* decl.c (cxx_simulate_enum_decl): New function.

From-SVN: r277555

gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/c/c-objc-common.h
gcc/c/c-tree.h
gcc/coretypes.h
gcc/cp/ChangeLog
gcc/cp/cp-objcp-common.h
gcc/cp/decl.c
gcc/langhooks-def.h
gcc/langhooks.h

index e7d69ac896f1f061e1cfefe2c736dbb7142bb964..4bb1f91cb9aff5bb320d651b5bf569671c750f37 100644 (file)
@@ -1,3 +1,10 @@
+2019-10-29  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * coretypes.h (string_int_pair): New typedef.
+       * langhooks-def.h (LANG_HOOKS_SIMULATE_ENUM_DECL): Define.
+       (LANG_HOOKS_FOR_TYPES_INITIALIZER): Include it.
+       * langhooks.h (lang_hooks_for_types::simulate_enum_decl): New hook.
+
 2019-10-29  Richard Sandiford  <richard.sandiford@arm.com>
 
        * langhooks.h (lang_hooks::simulate_builtin_function_decl): New hook.
index 3b0e3baf58aeb0a0a7212566598761fd8226d0e6..b76dfc27164a16ec5ad4147dee4d7761be43fc55 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-29  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * c-tree.h (c_simulate_enum_decl): Declare.
+       * c-decl.c (c_simulate_enum_decl): New function.
+       * c-objc-common.h (LANG_HOOKS_SIMULATE_ENUM_DECL): Define to the above.
+
 2019-10-29  Richard Sandiford  <richard.sandiford@arm.com>
 
        * c-tree.h (c_simulate_builtin_function_decl): Declare.
index 1013996194c6ac191b07cae8987e7c8256d25b7e..ae0ee3a9c9606a8009c2b60767c5227cd6671043 100644 (file)
@@ -8907,6 +8907,36 @@ build_enumerator (location_t decl_loc, location_t loc,
   return tree_cons (decl, value, NULL_TREE);
 }
 
+/* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
+
+tree
+c_simulate_enum_decl (location_t loc, const char *name,
+                     vec<string_int_pair> values)
+{
+  location_t saved_loc = input_location;
+  input_location = loc;
+
+  struct c_enum_contents the_enum;
+  tree enumtype = start_enum (loc, &the_enum, get_identifier (name));
+
+  tree value_chain = NULL_TREE;
+  string_int_pair *value;
+  unsigned int i;
+  FOR_EACH_VEC_ELT (values, i, value)
+    {
+      tree decl = build_enumerator (loc, loc, &the_enum,
+                                   get_identifier (value->first),
+                                   build_int_cst (integer_type_node,
+                                                  value->second));
+      TREE_CHAIN (decl) = value_chain;
+      value_chain = decl;
+    }
+
+  finish_enum (enumtype, nreverse (value_chain), NULL_TREE);
+
+  input_location = saved_loc;
+  return enumtype;
+}
 \f
 /* Create the FUNCTION_DECL for a function definition.
    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
index 8d3bcc2fdf127d88a3994bb2f29bbc1fb6c21a32..c8739e0b8355551a4fbc7a50f5d809c050cb37fc 100644 (file)
@@ -75,6 +75,8 @@ along with GCC; see the file COPYING3.  If not see
 #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
 #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN c_dump_tree
 
+#undef LANG_HOOKS_SIMULATE_ENUM_DECL
+#define LANG_HOOKS_SIMULATE_ENUM_DECL c_simulate_enum_decl
 #undef LANG_HOOKS_TYPE_FOR_MODE
 #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
 #undef LANG_HOOKS_TYPE_FOR_SIZE
index d01d4224fdde791089f46ac1840849562e0d1bff..71cd77d49b1002876c3b954c28a1e570eaca84c0 100644 (file)
@@ -563,6 +563,8 @@ extern tree finish_enum (tree, tree, tree);
 extern void finish_function (void);
 extern tree finish_struct (location_t, tree, tree, tree,
                           class c_struct_parse_info *);
+extern tree c_simulate_enum_decl (location_t, const char *,
+                                 vec<string_int_pair>);
 extern struct c_arg_info *build_arg_info (void);
 extern struct c_arg_info *get_parm_info (bool, tree);
 extern tree grokfield (location_t, struct c_declarator *,
index b683f1298803e8e4c93a73da506e3db947caad77..a18aaa2963a1023a625b408933cd8fb9d094e218 100644 (file)
@@ -341,6 +341,7 @@ namespace gcc {
 }
 
 typedef std::pair <tree, tree> tree_pair;
+typedef std::pair <const char *, int> string_int_pair;
 
 /* Define a name->value mapping.  */
 template <typename ValueType>
index 02cb6f3bf5b873bd03d5d4dad69b77eca3f1c21e..c244438bca14493d9dc96a788cc56643790d48b8 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-29  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * cp-objcp-common.h (cxx_simulate_enum_decl): Declare.
+       (LANG_HOOKS_SIMULATE_ENUM_DECL): Define to the above.
+       * decl.c (cxx_simulate_enum_decl): New function.
+
 2019-10-29  Richard Sandiford  <richard.sandiford@arm.com>
 
        * cp-tree.h (cxx_simulate_builtin_function_decl): Declare.
index 1827e53e73ade399390666bb65f829b6d322e985..e5d34f18028c2bfba45dcb991c2b062360b69711 100644 (file)
@@ -35,6 +35,8 @@ extern tree cp_get_global_decls ();
 extern tree cp_pushdecl (tree);
 extern void cp_register_dumps (gcc::dump_manager *);
 extern tree cxx_make_type_hook                 (tree_code);
+extern tree cxx_simulate_enum_decl (location_t, const char *,
+                                   vec<string_int_pair>);
 
 /* Lang hooks that are shared between C++ and ObjC++ are defined here.  Hooks
    specific to C++ or ObjC++ go in cp/cp-lang.c and objcp/objcp-lang.c,
@@ -131,6 +133,8 @@ extern tree cxx_make_type_hook                      (tree_code);
 
 #undef LANG_HOOKS_MAKE_TYPE
 #define LANG_HOOKS_MAKE_TYPE cxx_make_type_hook
+#undef LANG_HOOKS_SIMULATE_ENUM_DECL
+#define LANG_HOOKS_SIMULATE_ENUM_DECL cxx_simulate_enum_decl
 #undef LANG_HOOKS_TYPE_FOR_MODE
 #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
 #undef LANG_HOOKS_TYPE_FOR_SIZE
index dccde80b1a78502142a0895b381d22073b85046c..95c84159d7aa1eedf8379d4431005e2243079e18 100644 (file)
@@ -15433,6 +15433,40 @@ lookup_enumerator (tree enumtype, tree name)
   return e? TREE_VALUE (e) : NULL_TREE;
 }
 
+/* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
+
+tree
+cxx_simulate_enum_decl (location_t loc, const char *name,
+                       vec<string_int_pair> values)
+{
+  location_t saved_loc = input_location;
+  input_location = loc;
+
+  tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
+                             NULL_TREE, false, NULL);
+  if (!OPAQUE_ENUM_P (enumtype))
+    {
+      error_at (loc, "multiple definition of %q#T", enumtype);
+      inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
+             "previous definition here");
+      return enumtype;
+    }
+  SET_OPAQUE_ENUM_P (enumtype, false);
+  DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
+
+  string_int_pair *value;
+  unsigned int i;
+  FOR_EACH_VEC_ELT (values, i, value)
+    build_enumerator (get_identifier (value->first),
+                     build_int_cst (integer_type_node, value->second),
+                     enumtype, NULL_TREE, loc);
+
+  finish_enum_value_list (enumtype);
+  finish_enum (enumtype);
+
+  input_location = saved_loc;
+  return enumtype;
+}
 \f
 /* We're defining DECL.  Make sure that its type is OK.  */
 
index af0c1b359c75eef6381274c1d6bff8a4760d6485..54f80e51f8cc7bee61174a7c6d28623dfcfcd111 100644 (file)
@@ -171,6 +171,7 @@ extern tree lhd_make_node (enum tree_code);
 extern tree lhd_unit_size_without_reusable_padding (tree);
 
 #define LANG_HOOKS_MAKE_TYPE lhd_make_node
+#define LANG_HOOKS_SIMULATE_ENUM_DECL  NULL
 #define LANG_HOOKS_CLASSIFY_RECORD     NULL
 #define LANG_HOOKS_TYPE_FOR_SIZE       lhd_type_for_size
 #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR lhd_incomplete_type_error
@@ -204,6 +205,7 @@ extern tree lhd_unit_size_without_reusable_padding (tree);
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
+  LANG_HOOKS_SIMULATE_ENUM_DECL, \
   LANG_HOOKS_CLASSIFY_RECORD, \
   LANG_HOOKS_TYPE_FOR_MODE, \
   LANG_HOOKS_TYPE_FOR_SIZE, \
index 76f530eaeaf2acfe5db4d8384d5cef129c141da3..e50162f9482fafd5f6da27c43fd238197fa67759 100644 (file)
@@ -64,6 +64,10 @@ struct lang_hooks_for_types
      language-specific processing is required.  */
   tree (*make_type) (enum tree_code);
 
+  /* Make an enum type with the given name and values, associating
+     them all with the given source location.  */
+  tree (*simulate_enum_decl) (location_t, const char *, vec<string_int_pair>);
+
   /* Return what kind of RECORD_TYPE this is, mainly for purposes of
      debug information.  If not defined, record types are assumed to
      be structures.  */