aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
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/c
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/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-decl.c30
-rw-r--r--gcc/c/c-objc-common.h2
-rw-r--r--gcc/c/c-tree.h2
4 files changed, 40 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 3b0e3ba..b76dfc2 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,5 +1,11 @@
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.
* c-decl.c (c_simulate_builtin_function_decl): New function.
* c-objc-common.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 1013996..ae0ee3a 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -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;
+}
/* Create the FUNCTION_DECL for a function definition.
DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 8d3bcc2..c8739e0 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -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
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index d01d422..71cd77d 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -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 *,