aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2019-10-29 08:39:45 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2019-10-29 08:39:45 +0000
commitac2cfa6cc35175311f92c25acbdd244f0f3bbb87 (patch)
treec61b52f882b58f537f31ac567c953b78eeef6644 /gcc/cp
parent740785381ec9944c861dcc29b420c96aa933f040 (diff)
downloadgcc-ac2cfa6cc35175311f92c25acbdd244f0f3bbb87.zip
gcc-ac2cfa6cc35175311f92c25acbdd244f0f3bbb87.tar.gz
gcc-ac2cfa6cc35175311f92c25acbdd244f0f3bbb87.tar.bz2
Add a simulate_enum_decl langhook
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
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/cp-objcp-common.h4
-rw-r--r--gcc/cp/decl.c34
3 files changed, 44 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 02cb6f3..c244438 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
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.
* decl.c (cxx_simulate_builtin_function_decl): New function.
* cp-objcp-common.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define
diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h
index 1827e53..e5d34f1 100644
--- a/gcc/cp/cp-objcp-common.h
+++ b/gcc/cp/cp-objcp-common.h
@@ -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
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index dccde80..95c8415 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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;
+}
/* We're defining DECL. Make sure that its type is OK. */