input_location = saved_loc;
return enumtype;
}
+
+/* Implement LANG_HOOKS_SIMULATE_RECORD_DECL. */
+
+tree
+c_simulate_record_decl (location_t loc, const char *name,
+ array_slice<const tree> fields)
+{
+ location_t saved_loc = input_location;
+ input_location = loc;
+
+ class c_struct_parse_info *struct_info;
+ tree ident = get_identifier (name);
+ tree type = start_struct (loc, RECORD_TYPE, ident, &struct_info);
+
+ for (unsigned int i = 0; i < fields.size (); ++i)
+ {
+ DECL_FIELD_CONTEXT (fields[i]) = type;
+ if (i > 0)
+ DECL_CHAIN (fields[i - 1]) = fields[i];
+ }
+
+ finish_struct (loc, type, fields[0], NULL_TREE, struct_info);
+
+ tree decl = build_decl (loc, TYPE_DECL, ident, type);
+ set_underlying_type (decl);
+ lang_hooks.decls.pushdecl (decl);
+
+ input_location = saved_loc;
+ return type;
+}
\f
/* Create the FUNCTION_DECL for a function definition.
DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
#undef LANG_HOOKS_SIMULATE_ENUM_DECL
#define LANG_HOOKS_SIMULATE_ENUM_DECL c_simulate_enum_decl
+#undef LANG_HOOKS_SIMULATE_RECORD_DECL
+#define LANG_HOOKS_SIMULATE_RECORD_DECL c_simulate_record_decl
#undef LANG_HOOKS_TYPE_FOR_MODE
#define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
#undef LANG_HOOKS_TYPE_FOR_SIZE
class c_struct_parse_info *);
extern tree c_simulate_enum_decl (location_t, const char *,
vec<string_int_pair> *);
+extern tree c_simulate_record_decl (location_t, const char *,
+ array_slice<const tree>);
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 *,
extern tree cxx_make_type_hook (tree_code);
extern tree cxx_simulate_enum_decl (location_t, const char *,
vec<string_int_pair> *);
+extern tree cxx_simulate_record_decl (location_t, const char *,
+ array_slice<const tree>);
/* 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,
#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_SIMULATE_RECORD_DECL
+#define LANG_HOOKS_SIMULATE_RECORD_DECL cxx_simulate_record_decl
#undef LANG_HOOKS_TYPE_FOR_MODE
#define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
#undef LANG_HOOKS_TYPE_FOR_SIZE
#include "omp-general.h"
#include "omp-offload.h" /* For offload_vars. */
#include "opts.h"
+#include "langhooks-def.h" /* For lhd_simulate_record_decl */
/* Possible cases of bad specifiers type used by bad_specifiers. */
enum bad_spec_place {
input_location = saved_loc;
return enumtype;
}
+
+/* Implement LANG_HOOKS_SIMULATE_RECORD_DECL. */
+
+tree
+cxx_simulate_record_decl (location_t loc, const char *name,
+ array_slice<const tree> fields)
+{
+ iloc_sentinel ils (loc);
+
+ tree ident = get_identifier (name);
+ tree type = xref_tag (/*tag_code=*/record_type, ident);
+ if (type != error_mark_node
+ && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
+ {
+ error ("redefinition of %q#T", type);
+ type = error_mark_node;
+ }
+ if (type == error_mark_node)
+ return lhd_simulate_record_decl (loc, name, fields);
+
+ xref_basetypes (type, NULL_TREE);
+ type = begin_class_definition (type);
+ if (type == error_mark_node)
+ return lhd_simulate_record_decl (loc, name, fields);
+
+ for (tree field : fields)
+ finish_member_declaration (field);
+
+ type = finish_struct (type, NULL_TREE);
+
+ tree decl = build_decl (loc, TYPE_DECL, ident, type);
+ set_underlying_type (decl);
+ lang_hooks.decls.pushdecl (decl);
+
+ return type;
+}
\f
/* We're defining DECL. Make sure that its type is OK. */
extern bool lhd_warn_unused_global_decl (const_tree);
extern tree lhd_simulate_enum_decl (location_t, const char *,
vec<string_int_pair> *);
+extern tree lhd_simulate_record_decl (location_t, const char *,
+ array_slice<const tree>);
extern tree lhd_type_for_size (unsigned precision, int unsignedp);
extern void lhd_incomplete_type_error (location_t, const_tree, const_tree);
extern tree lhd_type_promotes_to (tree);
#define LANG_HOOKS_MAKE_TYPE lhd_make_node
#define LANG_HOOKS_SIMULATE_ENUM_DECL lhd_simulate_enum_decl
+#define LANG_HOOKS_SIMULATE_RECORD_DECL lhd_simulate_record_decl
#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
#define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
LANG_HOOKS_MAKE_TYPE, \
LANG_HOOKS_SIMULATE_ENUM_DECL, \
+ LANG_HOOKS_SIMULATE_RECORD_DECL, \
LANG_HOOKS_CLASSIFY_RECORD, \
LANG_HOOKS_TYPE_FOR_MODE, \
LANG_HOOKS_TYPE_FOR_SIZE, \
return enumtype;
}
+/* Default implementation of LANG_HOOKS_SIMULATE_RECORD_DECL.
+ Just create a normal RECORD_TYPE and a TYPE_DECL for it. */
+tree
+lhd_simulate_record_decl (location_t loc, const char *name,
+ array_slice<const tree> fields)
+{
+ for (unsigned int i = 1; i < fields.size (); ++i)
+ /* Reversed by finish_builtin_struct. */
+ DECL_CHAIN (fields[i]) = fields[i - 1];
+
+ tree type = lang_hooks.types.make_type (RECORD_TYPE);
+ finish_builtin_struct (type, name, fields.back (), NULL_TREE);
+
+ tree decl = build_decl (loc, TYPE_DECL, get_identifier (name), type);
+ lang_hooks.decls.pushdecl (decl);
+
+ return type;
+}
+
/* Default implementation of LANG_HOOKS_TYPE_FOR_SIZE.
Return an integer type with PRECISION bits of precision,
that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
them all with the given source location. */
tree (*simulate_enum_decl) (location_t, const char *, vec<string_int_pair> *);
+ /* Do the equivalent of:
+
+ typedef struct NAME { FIELDS; } NAME;
+
+ associating it with location LOC. Return the associated RECORD_TYPE.
+
+ FIELDS is a list of FIELD_DECLs, in layout order. */
+ tree (*simulate_record_decl) (location_t loc, const char *name,
+ array_slice<const tree> fields);
+
/* Return what kind of RECORD_TYPE this is, mainly for purposes of
debug information. If not defined, record types are assumed to
be structures. */