zend_attributes.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Benjamin Eberlei <kontakt@beberlei.de> |
  16. | Martin Schröder <m.schroeder2007@gmail.com> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifndef ZEND_ATTRIBUTES_H
  20. #define ZEND_ATTRIBUTES_H
  21. #define ZEND_ATTRIBUTE_TARGET_CLASS (1<<0)
  22. #define ZEND_ATTRIBUTE_TARGET_FUNCTION (1<<1)
  23. #define ZEND_ATTRIBUTE_TARGET_METHOD (1<<2)
  24. #define ZEND_ATTRIBUTE_TARGET_PROPERTY (1<<3)
  25. #define ZEND_ATTRIBUTE_TARGET_CLASS_CONST (1<<4)
  26. #define ZEND_ATTRIBUTE_TARGET_PARAMETER (1<<5)
  27. #define ZEND_ATTRIBUTE_TARGET_ALL ((1<<6) - 1)
  28. #define ZEND_ATTRIBUTE_IS_REPEATABLE (1<<6)
  29. #define ZEND_ATTRIBUTE_FLAGS ((1<<7) - 1)
  30. /* Flags for zend_attribute.flags */
  31. #define ZEND_ATTRIBUTE_PERSISTENT (1<<0)
  32. #define ZEND_ATTRIBUTE_STRICT_TYPES (1<<1)
  33. #define ZEND_ATTRIBUTE_SIZE(argc) \
  34. (sizeof(zend_attribute) + sizeof(zend_attribute_arg) * (argc) - sizeof(zend_attribute_arg))
  35. BEGIN_EXTERN_C()
  36. extern ZEND_API zend_class_entry *zend_ce_attribute;
  37. typedef struct {
  38. zend_string *name;
  39. zval value;
  40. } zend_attribute_arg;
  41. typedef struct _zend_attribute {
  42. zend_string *name;
  43. zend_string *lcname;
  44. uint32_t flags;
  45. uint32_t lineno;
  46. /* Parameter offsets start at 1, everything else uses 0. */
  47. uint32_t offset;
  48. uint32_t argc;
  49. zend_attribute_arg args[1];
  50. } zend_attribute;
  51. typedef struct _zend_internal_attribute {
  52. zend_class_entry *ce;
  53. uint32_t flags;
  54. void (*validator)(zend_attribute *attr, uint32_t target, zend_class_entry *scope);
  55. } zend_internal_attribute;
  56. ZEND_API zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *lcname);
  57. ZEND_API zend_attribute *zend_get_attribute_str(HashTable *attributes, const char *str, size_t len);
  58. ZEND_API zend_attribute *zend_get_parameter_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset);
  59. ZEND_API zend_attribute *zend_get_parameter_attribute_str(HashTable *attributes, const char *str, size_t len, uint32_t offset);
  60. ZEND_API zend_result zend_get_attribute_value(zval *ret, zend_attribute *attr, uint32_t i, zend_class_entry *scope);
  61. ZEND_API zend_string *zend_get_attribute_target_names(uint32_t targets);
  62. ZEND_API bool zend_is_attribute_repeated(HashTable *attributes, zend_attribute *attr);
  63. ZEND_API zend_internal_attribute *zend_internal_attribute_register(zend_class_entry *ce, uint32_t flags);
  64. ZEND_API zend_internal_attribute *zend_internal_attribute_get(zend_string *lcname);
  65. ZEND_API zend_attribute *zend_add_attribute(
  66. HashTable **attributes, zend_string *name, uint32_t argc,
  67. uint32_t flags, uint32_t offset, uint32_t lineno);
  68. END_EXTERN_C()
  69. static zend_always_inline zend_attribute *zend_add_class_attribute(zend_class_entry *ce, zend_string *name, uint32_t argc)
  70. {
  71. uint32_t flags = ce->type != ZEND_USER_CLASS ? ZEND_ATTRIBUTE_PERSISTENT : 0;
  72. return zend_add_attribute(&ce->attributes, name, argc, flags, 0, 0);
  73. }
  74. static zend_always_inline zend_attribute *zend_add_function_attribute(zend_function *func, zend_string *name, uint32_t argc)
  75. {
  76. uint32_t flags = func->common.type != ZEND_USER_FUNCTION ? ZEND_ATTRIBUTE_PERSISTENT : 0;
  77. return zend_add_attribute(&func->common.attributes, name, argc, flags, 0, 0);
  78. }
  79. static zend_always_inline zend_attribute *zend_add_parameter_attribute(zend_function *func, uint32_t offset, zend_string *name, uint32_t argc)
  80. {
  81. uint32_t flags = func->common.type != ZEND_USER_FUNCTION ? ZEND_ATTRIBUTE_PERSISTENT : 0;
  82. return zend_add_attribute(&func->common.attributes, name, argc, flags, offset + 1, 0);
  83. }
  84. static zend_always_inline zend_attribute *zend_add_property_attribute(zend_class_entry *ce, zend_property_info *info, zend_string *name, uint32_t argc)
  85. {
  86. uint32_t flags = ce->type != ZEND_USER_CLASS ? ZEND_ATTRIBUTE_PERSISTENT : 0;
  87. return zend_add_attribute(&info->attributes, name, argc, flags, 0, 0);
  88. }
  89. static zend_always_inline zend_attribute *zend_add_class_constant_attribute(zend_class_entry *ce, zend_class_constant *c, zend_string *name, uint32_t argc)
  90. {
  91. uint32_t flags = ce->type != ZEND_USER_CLASS ? ZEND_ATTRIBUTE_PERSISTENT : 0;
  92. return zend_add_attribute(&c->attributes, name, argc, flags, 0, 0);
  93. }
  94. void zend_register_attribute_ce(void);
  95. void zend_attributes_shutdown(void);
  96. #endif