[gcc r10-9537] Objective-C : Implement SEL as a built-in typedef.

Iain D Sandoe iains@gcc.gnu.org
Wed Mar 24 22:07:38 GMT 2021


https://gcc.gnu.org/g:4b761ea8690cde76172409962b840b7c446e5065

commit r10-9537-g4b761ea8690cde76172409962b840b7c446e5065
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Sat Oct 24 09:48:44 2020 +0100

    Objective-C : Implement SEL as a built-in typedef.
    
    The reference implementation for Objective-C provides the SEL
    typedef (although it is also available from <objc/objc.h>).
    
    gcc/objc/ChangeLog:
    
            * objc-act.c (synth_module_prologue): Get the SEL identifier.
            * objc-act.h (enum objc_tree_index): Add OCTI_SEL_NAME.
            (objc_selector_name): New.
            (SEL_TYPEDEF_NAME): New.
            * objc-gnu-runtime-abi-01.c
            (gnu_runtime_01_initialize): Initialize SEL typedef.
            * objc-next-runtime-abi-01.c
            (next_runtime_01_initialize): Likewise.
            * objc-next-runtime-abi-02.c
    
    gcc/testsuite/ChangeLog:
    
            * obj-c++.dg/SEL-typedef.mm: New test.
            * objc.dg/SEL-typedef.m: New test.
    
    (cherry picked from commit bb93020ff852fb159bc329bbaea12a33a4ef6761)

Diff:
---
 gcc/objc/objc-act.c                     | 1 +
 gcc/objc/objc-act.h                     | 3 +++
 gcc/objc/objc-gnu-runtime-abi-01.c      | 7 +++++++
 gcc/objc/objc-next-runtime-abi-01.c     | 7 +++++++
 gcc/objc/objc-next-runtime-abi-02.c     | 7 +++++++
 gcc/testsuite/obj-c++.dg/SEL-typedef.mm | 7 +++++++
 gcc/testsuite/objc.dg/SEL-typedef.m     | 7 +++++++
 7 files changed, 39 insertions(+)

diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index efc63efda82..d2c39fb1702 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -3034,6 +3034,7 @@ synth_module_prologue (void)
   objc_object_name = get_identifier (OBJECT_TYPEDEF_NAME);
   objc_instancetype_name = get_identifier (INSTANCE_TYPEDEF_NAME);
   objc_class_name = get_identifier (CLASS_TYPEDEF_NAME);
+  objc_selector_name = get_identifier (SEL_TYPEDEF_NAME);
 
   /* Declare the 'id', 'instancetype' and 'Class' typedefs.  */
   type = lang_hooks.decls.pushdecl (build_decl (input_location,
diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h
index 913e152fdeb..db71b6a265e 100644
--- a/gcc/objc/objc-act.h
+++ b/gcc/objc/objc-act.h
@@ -371,6 +371,7 @@ enum objc_tree_index
     OCTI_ID_NAME,
     OCTI_INSTANCETYPE_NAME,
     OCTI_CLASS_NAME,
+    OCTI_SEL_NAME,
     OCTI_CNST_STR_ID,
     OCTI_CNST_STR_TYPE,
     OCTI_CNST_STR_GLOB_ID,
@@ -576,6 +577,7 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX];
 #define objc_object_name        objc_global_trees[OCTI_ID_NAME]
 #define objc_instancetype_name	objc_global_trees[OCTI_INSTANCETYPE_NAME]
 #define objc_class_name		objc_global_trees[OCTI_CLASS_NAME]
+#define objc_selector_name	objc_global_trees[OCTI_SEL_NAME]
 
 /* Constant string classes.  */
 #define constant_string_id	objc_global_trees[OCTI_CNST_STR_ID]
@@ -614,6 +616,7 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX];
 #define OBJECT_TYPEDEF_NAME		"id"
 #define INSTANCE_TYPEDEF_NAME		"instancetype"
 #define CLASS_TYPEDEF_NAME		"Class"
+#define SEL_TYPEDEF_NAME		"SEL"
 
 #define TAG_OBJECT			"objc_object"
 #define TAG_CLASS			"objc_class"
diff --git a/gcc/objc/objc-gnu-runtime-abi-01.c b/gcc/objc/objc-gnu-runtime-abi-01.c
index d5862435c29..3dd95219feb 100644
--- a/gcc/objc/objc-gnu-runtime-abi-01.c
+++ b/gcc/objc/objc-gnu-runtime-abi-01.c
@@ -208,6 +208,13 @@ static void gnu_runtime_01_initialize (void)
   type = build_qualified_type (type, TYPE_QUAL_CONST);
   objc_selector_type = build_pointer_type (type);
 
+  /* SEL typedef.  */
+  type = lang_hooks.decls.pushdecl (build_decl (input_location,
+						TYPE_DECL,
+						objc_selector_name,
+						objc_selector_type));
+  TREE_NO_WARNING (type) = 1;
+
   /* typedef id (*IMP)(id, SEL, ...); */
   ftype = build_varargs_function_type_list (objc_object_type,
 					    objc_object_type,
diff --git a/gcc/objc/objc-next-runtime-abi-01.c b/gcc/objc/objc-next-runtime-abi-01.c
index 5c34fcb05cb..be2e55e28b6 100644
--- a/gcc/objc/objc-next-runtime-abi-01.c
+++ b/gcc/objc/objc-next-runtime-abi-01.c
@@ -277,6 +277,13 @@ static void next_runtime_01_initialize (void)
   objc_selector_type = build_pointer_type (xref_tag (RECORD_TYPE,
 					   get_identifier (TAG_SELECTOR)));
 
+  /* SEL typedef.  */
+  type = lang_hooks.decls.pushdecl (build_decl (input_location,
+						TYPE_DECL,
+						objc_selector_name,
+						objc_selector_type));
+  TREE_NO_WARNING (type) = 1;
+
   build_v1_class_template ();
   build_super_template ();
   build_v1_protocol_template ();
diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index ceeca15f684..66c13ad0db2 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -374,6 +374,13 @@ static void next_runtime_02_initialize (void)
   objc_selector_type = build_pointer_type (xref_tag (RECORD_TYPE,
 					   get_identifier (TAG_SELECTOR)));
 
+  /* SEL typedef.  */
+  type = lang_hooks.decls.pushdecl (build_decl (input_location,
+						TYPE_DECL,
+						objc_selector_name,
+						objc_selector_type));
+  TREE_NO_WARNING (type) = 1;
+
   /* IMP : id (*) (id, _message_ref_t*, ...)
      SUPER_IMP : id (*) ( super_t*, _super_message_ref_t*, ...)
      objc_v2_selector_type.  */
diff --git a/gcc/testsuite/obj-c++.dg/SEL-typedef.mm b/gcc/testsuite/obj-c++.dg/SEL-typedef.mm
new file mode 100644
index 00000000000..2ece1fd46cd
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/SEL-typedef.mm
@@ -0,0 +1,7 @@
+/* Check that we accept the SEL typedef.  */
+/*  { dg-additional-options "-fsyntax-only " } */
+
+SEL aSelector;
+
+typedef SEL MySEL;
+
diff --git a/gcc/testsuite/objc.dg/SEL-typedef.m b/gcc/testsuite/objc.dg/SEL-typedef.m
new file mode 100644
index 00000000000..2ece1fd46cd
--- /dev/null
+++ b/gcc/testsuite/objc.dg/SEL-typedef.m
@@ -0,0 +1,7 @@
+/* Check that we accept the SEL typedef.  */
+/*  { dg-additional-options "-fsyntax-only " } */
+
+SEL aSelector;
+
+typedef SEL MySEL;
+


More information about the Gcc-cvs mailing list