objc.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* Basic data types for Objective C.
  2. Copyright (C) 1993-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #ifndef __objc_INCLUDE_GNU
  20. #define __objc_INCLUDE_GNU
  21. /* This file contains the definition of the basic types used by the
  22. Objective-C language. It needs to be included to do almost
  23. anything with Objective-C. */
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stddef.h>
  28. /* The current version of the GNU Objective-C Runtime library in
  29. compressed ISO date format. This should be updated any time a new
  30. version is released with changes to the public API (there is no
  31. need to update it if there were no API changes since the previous
  32. release). This macro is only defined starting with the GNU
  33. Objective-C Runtime shipped with GCC 4.6.0. If it is not defined,
  34. it is either an older version of the runtime, or another runtime. */
  35. #define __GNU_LIBOBJC__ 20110608
  36. /* Definition of the boolean type.
  37. Compatibility note: the Apple/NeXT runtime defines a BOOL as a
  38. 'signed char'. The GNU runtime uses an 'unsigned char'.
  39. Important: this could change and we could switch to 'typedef bool
  40. BOOL' in the future. Do not depend on the type of BOOL. */
  41. #undef BOOL
  42. typedef unsigned char BOOL;
  43. #define YES (BOOL)1
  44. #define NO (BOOL)0
  45. /* The basic Objective-C types (SEL, Class, id) are defined as pointer
  46. to opaque structures. The details of the structures are private to
  47. the runtime and may potentially change from one version to the
  48. other. */
  49. /* A SEL (selector) represents an abstract method (in the
  50. object-oriented sense) and includes all the details of how to
  51. invoke the method (which means its name, arguments and return
  52. types) but provides no implementation of its own. You can check
  53. whether a class implements a selector or not, and if you have a
  54. selector and know that the class implements it, you can use it to
  55. call the method for an object in the class. */
  56. typedef const struct objc_selector *SEL;
  57. /* A Class is a class (in the object-oriented sense). In Objective-C
  58. there is the complication that each Class is an object itself, and
  59. so belongs to a class too. This class that a class belongs to is
  60. called its 'meta class'. */
  61. typedef struct objc_class *Class;
  62. /* An 'id' is an object of an unknown class. The way the object data
  63. is stored inside the object is private and what you see here is
  64. only the beginning of the actual struct. The first field is always
  65. a pointer to the Class that the object belongs to. */
  66. typedef struct objc_object
  67. {
  68. /* 'class_pointer' is the Class that the object belongs to. In case
  69. of a Class object, this pointer points to the meta class.
  70. Compatibility Note: The Apple/NeXT runtime calls this field
  71. 'isa'. To access this field, use object_getClass() from
  72. runtime.h, which is an inline function so does not add any
  73. overhead and is also portable to other runtimes. */
  74. Class class_pointer;
  75. } *id;
  76. /* 'IMP' is a C function that implements a method. When retrieving
  77. the implementation of a method from the runtime, this is the type
  78. of the pointer returned. The idea of the definition of IMP is to
  79. represent a 'pointer to a general function taking an id, a SEL,
  80. followed by other unspecified arguments'. You must always cast an
  81. IMP to a pointer to a function taking the appropriate, specific
  82. types for that function, before calling it - to make sure the
  83. appropriate arguments are passed to it. The code generated by the
  84. compiler to perform method calls automatically does this cast
  85. inside method calls. */
  86. typedef id (*IMP)(id, SEL, ...);
  87. /* 'nil' is the null object. Messages to nil do nothing and always
  88. return 0. */
  89. #define nil (id)0
  90. /* 'Nil' is the null class. Since classes are objects too, this is
  91. actually the same object as 'nil' (and behaves in the same way),
  92. but it has a type of Class, so it is good to use it instead of
  93. 'nil' if you are comparing a Class object to nil as it enables the
  94. compiler to do some type-checking. */
  95. #define Nil (Class)0
  96. /* TODO: Move the 'Protocol' declaration into objc/runtime.h. A
  97. Protocol is simply an object, not a basic Objective-C type. The
  98. Apple runtime defines Protocol in objc/runtime.h too, so it's good
  99. to move it there for API compatibility. */
  100. /* A 'Protocol' is a formally defined list of selectors (normally
  101. created using the @protocol Objective-C syntax). It is mostly used
  102. at compile-time to check that classes implement all the methods
  103. that they are supposed to. Protocols are also available in the
  104. runtime system as Protocol objects. */
  105. #ifndef __OBJC__
  106. /* Once we stop including the deprecated struct_objc_protocol.h
  107. there is no reason to even define a 'struct objc_protocol'. As
  108. all the structure details will be hidden, a Protocol basically is
  109. simply an object (as it should be). */
  110. typedef struct objc_object Protocol;
  111. #else /* __OBJC__ */
  112. @class Protocol;
  113. #endif
  114. /* Compatibility note: the Apple/NeXT runtime defines sel_getName(),
  115. sel_registerName(), object_getClassName(), object_getIndexedIvars()
  116. in this file while the GNU runtime defines them in runtime.h.
  117. The reason the GNU runtime does not define them here is that they
  118. are not basic Objective-C types (defined in this file), but are
  119. part of the runtime API (defined in runtime.h). */
  120. #ifdef __cplusplus
  121. }
  122. #endif
  123. #endif /* not __objc_INCLUDE_GNU */