zend_compile.h 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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: Andi Gutmans <andi@php.net> |
  16. | Zeev Suraski <zeev@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifndef ZEND_COMPILE_H
  20. #define ZEND_COMPILE_H
  21. #include "zend.h"
  22. #include "zend_ast.h"
  23. #include <stdarg.h>
  24. #include "zend_llist.h"
  25. #define SET_UNUSED(op) op ## _type = IS_UNUSED
  26. #define MAKE_NOP(opline) do { \
  27. (opline)->op1.num = 0; \
  28. (opline)->op2.num = 0; \
  29. (opline)->result.num = 0; \
  30. (opline)->opcode = ZEND_NOP; \
  31. (opline)->op1_type = IS_UNUSED; \
  32. (opline)->op2_type = IS_UNUSED; \
  33. (opline)->result_type = IS_UNUSED; \
  34. } while (0)
  35. #define RESET_DOC_COMMENT() do { \
  36. if (CG(doc_comment)) { \
  37. zend_string_release_ex(CG(doc_comment), 0); \
  38. CG(doc_comment) = NULL; \
  39. } \
  40. } while (0)
  41. typedef struct _zend_op_array zend_op_array;
  42. typedef struct _zend_op zend_op;
  43. /* On 64-bit systems less optimal, but more compact VM code leads to better
  44. * performance. So on 32-bit systems we use absolute addresses for jump
  45. * targets and constants, but on 64-bit systems relative 32-bit offsets */
  46. #if SIZEOF_SIZE_T == 4
  47. # define ZEND_USE_ABS_JMP_ADDR 1
  48. # define ZEND_USE_ABS_CONST_ADDR 1
  49. #else
  50. # define ZEND_USE_ABS_JMP_ADDR 0
  51. # define ZEND_USE_ABS_CONST_ADDR 0
  52. #endif
  53. typedef union _znode_op {
  54. uint32_t constant;
  55. uint32_t var;
  56. uint32_t num;
  57. uint32_t opline_num; /* Needs to be signed */
  58. #if ZEND_USE_ABS_JMP_ADDR
  59. zend_op *jmp_addr;
  60. #else
  61. uint32_t jmp_offset;
  62. #endif
  63. #if ZEND_USE_ABS_CONST_ADDR
  64. zval *zv;
  65. #endif
  66. } znode_op;
  67. typedef struct _znode { /* used only during compilation */
  68. zend_uchar op_type;
  69. zend_uchar flag;
  70. union {
  71. znode_op op;
  72. zval constant; /* replaced by literal/zv */
  73. } u;
  74. } znode;
  75. /* Temporarily defined here, to avoid header ordering issues */
  76. typedef struct _zend_ast_znode {
  77. zend_ast_kind kind;
  78. zend_ast_attr attr;
  79. uint32_t lineno;
  80. znode node;
  81. } zend_ast_znode;
  82. ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_znode(znode *node);
  83. static zend_always_inline znode *zend_ast_get_znode(zend_ast *ast) {
  84. return &((zend_ast_znode *) ast)->node;
  85. }
  86. typedef struct _zend_declarables {
  87. zend_long ticks;
  88. } zend_declarables;
  89. /* Compilation context that is different for each file, but shared between op arrays. */
  90. typedef struct _zend_file_context {
  91. zend_declarables declarables;
  92. zend_string *current_namespace;
  93. bool in_namespace;
  94. bool has_bracketed_namespaces;
  95. HashTable *imports;
  96. HashTable *imports_function;
  97. HashTable *imports_const;
  98. HashTable seen_symbols;
  99. } zend_file_context;
  100. typedef union _zend_parser_stack_elem {
  101. zend_ast *ast;
  102. zend_string *str;
  103. zend_ulong num;
  104. unsigned char *ptr;
  105. unsigned char *ident;
  106. } zend_parser_stack_elem;
  107. void zend_compile_top_stmt(zend_ast *ast);
  108. void zend_const_expr_to_zval(zval *result, zend_ast **ast_ptr, bool allow_dynamic);
  109. typedef int (*user_opcode_handler_t) (zend_execute_data *execute_data);
  110. struct _zend_op {
  111. const void *handler;
  112. znode_op op1;
  113. znode_op op2;
  114. znode_op result;
  115. uint32_t extended_value;
  116. uint32_t lineno;
  117. zend_uchar opcode;
  118. zend_uchar op1_type;
  119. zend_uchar op2_type;
  120. zend_uchar result_type;
  121. };
  122. typedef struct _zend_brk_cont_element {
  123. int start;
  124. int cont;
  125. int brk;
  126. int parent;
  127. bool is_switch;
  128. } zend_brk_cont_element;
  129. typedef struct _zend_label {
  130. int brk_cont;
  131. uint32_t opline_num;
  132. } zend_label;
  133. typedef struct _zend_try_catch_element {
  134. uint32_t try_op;
  135. uint32_t catch_op; /* ketchup! */
  136. uint32_t finally_op;
  137. uint32_t finally_end;
  138. } zend_try_catch_element;
  139. #define ZEND_LIVE_TMPVAR 0
  140. #define ZEND_LIVE_LOOP 1
  141. #define ZEND_LIVE_SILENCE 2
  142. #define ZEND_LIVE_ROPE 3
  143. #define ZEND_LIVE_NEW 4
  144. #define ZEND_LIVE_MASK 7
  145. typedef struct _zend_live_range {
  146. uint32_t var; /* low bits are used for variable type (ZEND_LIVE_* macros) */
  147. uint32_t start;
  148. uint32_t end;
  149. } zend_live_range;
  150. /* Compilation context that is different for each op array. */
  151. typedef struct _zend_oparray_context {
  152. uint32_t opcodes_size;
  153. int vars_size;
  154. int literals_size;
  155. uint32_t fast_call_var;
  156. uint32_t try_catch_offset;
  157. int current_brk_cont;
  158. int last_brk_cont;
  159. zend_brk_cont_element *brk_cont_array;
  160. HashTable *labels;
  161. } zend_oparray_context;
  162. /* Class, property and method flags class|meth.|prop.|const*/
  163. /* | | | */
  164. /* Common flags | | | */
  165. /* ============ | | | */
  166. /* | | | */
  167. /* Visibility flags (public < protected < private) | | | */
  168. #define ZEND_ACC_PUBLIC (1 << 0) /* | X | X | X */
  169. #define ZEND_ACC_PROTECTED (1 << 1) /* | X | X | X */
  170. #define ZEND_ACC_PRIVATE (1 << 2) /* | X | X | X */
  171. /* | | | */
  172. /* Property or method overrides private one | | | */
  173. #define ZEND_ACC_CHANGED (1 << 3) /* | X | X | */
  174. /* | | | */
  175. /* Static method or property | | | */
  176. #define ZEND_ACC_STATIC (1 << 4) /* | X | X | */
  177. /* | | | */
  178. /* Promoted property / parameter | | | */
  179. #define ZEND_ACC_PROMOTED (1 << 5) /* | | X | X */
  180. /* | | | */
  181. /* Final class or method | | | */
  182. #define ZEND_ACC_FINAL (1 << 5) /* X | X | | */
  183. /* | | | */
  184. /* Abstract method | | | */
  185. #define ZEND_ACC_ABSTRACT (1 << 6) /* X | X | | */
  186. #define ZEND_ACC_EXPLICIT_ABSTRACT_CLASS (1 << 6) /* X | | | */
  187. /* | | | */
  188. /* Readonly property | | | */
  189. #define ZEND_ACC_READONLY (1 << 7) /* | | X | */
  190. /* | | | */
  191. /* Immutable op_array and class_entries | | | */
  192. /* (implemented only for lazy loading of op_arrays) | | | */
  193. #define ZEND_ACC_IMMUTABLE (1 << 7) /* X | X | | */
  194. /* | | | */
  195. /* Function has typed arguments / class has typed props | | | */
  196. #define ZEND_ACC_HAS_TYPE_HINTS (1 << 8) /* X | X | | */
  197. /* | | | */
  198. /* Top-level class or function declaration | | | */
  199. #define ZEND_ACC_TOP_LEVEL (1 << 9) /* X | X | | */
  200. /* | | | */
  201. /* op_array or class is preloaded | | | */
  202. #define ZEND_ACC_PRELOADED (1 << 10) /* X | X | | */
  203. /* | | | */
  204. /* Flag to differentiate cases from constants. | | | */
  205. /* Must not conflict with ZEND_ACC_ visibility flags | | | */
  206. /* or IS_CONSTANT_VISITED_MARK | | | */
  207. #define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */
  208. /* | | | */
  209. /* Class Flags (unused: 15,21,30,31) | | | */
  210. /* =========== | | | */
  211. /* | | | */
  212. /* Special class types | | | */
  213. #define ZEND_ACC_INTERFACE (1 << 0) /* X | | | */
  214. #define ZEND_ACC_TRAIT (1 << 1) /* X | | | */
  215. #define ZEND_ACC_ANON_CLASS (1 << 2) /* X | | | */
  216. #define ZEND_ACC_ENUM (1 << 28) /* X | | | */
  217. /* | | | */
  218. /* Class linked with parent, interfaces and traits | | | */
  219. #define ZEND_ACC_LINKED (1 << 3) /* X | | | */
  220. /* | | | */
  221. /* Class is abstract, since it is set by any | | | */
  222. /* abstract method | | | */
  223. #define ZEND_ACC_IMPLICIT_ABSTRACT_CLASS (1 << 4) /* X | | | */
  224. /* | | | */
  225. /* Class has magic methods __get/__set/__unset/ | | | */
  226. /* __isset that use guards | | | */
  227. #define ZEND_ACC_USE_GUARDS (1 << 11) /* X | | | */
  228. /* | | | */
  229. /* Class constants updated | | | */
  230. #define ZEND_ACC_CONSTANTS_UPDATED (1 << 12) /* X | | | */
  231. /* | | | */
  232. /* Objects of this class may not have dynamic properties | | | */
  233. #define ZEND_ACC_NO_DYNAMIC_PROPERTIES (1 << 13) /* X | | | */
  234. /* | | | */
  235. /* User class has methods with static variables | | | */
  236. #define ZEND_HAS_STATIC_IN_METHODS (1 << 14) /* X | | | */
  237. /* | | | */
  238. /* Children must reuse parent get_iterator() | | | */
  239. #define ZEND_ACC_REUSE_GET_ITERATOR (1 << 16) /* X | | | */
  240. /* | | | */
  241. /* Parent class is resolved (CE). | | | */
  242. #define ZEND_ACC_RESOLVED_PARENT (1 << 17) /* X | | | */
  243. /* | | | */
  244. /* Interfaces are resolved (CEs). | | | */
  245. #define ZEND_ACC_RESOLVED_INTERFACES (1 << 18) /* X | | | */
  246. /* | | | */
  247. /* Class has unresolved variance obligations. | | | */
  248. #define ZEND_ACC_UNRESOLVED_VARIANCE (1 << 19) /* X | | | */
  249. /* | | | */
  250. /* Class is linked apart from variance obligations. | | | */
  251. #define ZEND_ACC_NEARLY_LINKED (1 << 20) /* X | | | */
  252. /* | | | */
  253. /* stored in opcache (may be partially) | | | */
  254. #define ZEND_ACC_CACHED (1 << 22) /* X | | | */
  255. /* | | | */
  256. /* temporary flag used during delayed variance checks | | | */
  257. #define ZEND_ACC_CACHEABLE (1 << 23) /* X | | | */
  258. /* | | | */
  259. #define ZEND_ACC_HAS_AST_CONSTANTS (1 << 24) /* X | | | */
  260. #define ZEND_ACC_HAS_AST_PROPERTIES (1 << 25) /* X | | | */
  261. #define ZEND_ACC_HAS_AST_STATICS (1 << 26) /* X | | | */
  262. /* | | | */
  263. /* loaded from file cache to process memory | | | */
  264. #define ZEND_ACC_FILE_CACHED (1 << 27) /* X | | | */
  265. /* | | | */
  266. /* Class cannot be serialized or unserialized | | | */
  267. #define ZEND_ACC_NOT_SERIALIZABLE (1 << 29) /* X | | | */
  268. /* | | | */
  269. /* Function Flags (unused: 27-30) | | | */
  270. /* ============== | | | */
  271. /* | | | */
  272. /* deprecation flag | | | */
  273. #define ZEND_ACC_DEPRECATED (1 << 11) /* | X | | */
  274. /* | | | */
  275. /* Function returning by reference | | | */
  276. #define ZEND_ACC_RETURN_REFERENCE (1 << 12) /* | X | | */
  277. /* | | | */
  278. /* Function has a return type | | | */
  279. #define ZEND_ACC_HAS_RETURN_TYPE (1 << 13) /* | X | | */
  280. /* | | | */
  281. /* Function with variable number of arguments | | | */
  282. #define ZEND_ACC_VARIADIC (1 << 14) /* | X | | */
  283. /* | | | */
  284. /* op_array has finally blocks (user only) | | | */
  285. #define ZEND_ACC_HAS_FINALLY_BLOCK (1 << 15) /* | X | | */
  286. /* | | | */
  287. /* "main" op_array with | | | */
  288. /* ZEND_DECLARE_CLASS_DELAYED opcodes | | | */
  289. #define ZEND_ACC_EARLY_BINDING (1 << 16) /* | X | | */
  290. /* | | | */
  291. /* closure uses $this | | | */
  292. #define ZEND_ACC_USES_THIS (1 << 17) /* | X | | */
  293. /* | | | */
  294. /* call through user function trampoline. e.g. | | | */
  295. /* __call, __callstatic | | | */
  296. #define ZEND_ACC_CALL_VIA_TRAMPOLINE (1 << 18) /* | X | | */
  297. /* | | | */
  298. /* disable inline caching | | | */
  299. #define ZEND_ACC_NEVER_CACHE (1 << 19) /* | X | | */
  300. /* | | | */
  301. /* op_array is a clone of trait method | | | */
  302. #define ZEND_ACC_TRAIT_CLONE (1 << 20) /* | X | | */
  303. /* | | | */
  304. /* functions is a constructor | | | */
  305. #define ZEND_ACC_CTOR (1 << 21) /* | X | | */
  306. /* | | | */
  307. /* Closure related | | | */
  308. #define ZEND_ACC_CLOSURE (1 << 22) /* | X | | */
  309. #define ZEND_ACC_FAKE_CLOSURE (1 << 23) /* | X | | */ /* Same as ZEND_CALL_FAKE_CLOSURE */
  310. /* | | | */
  311. #define ZEND_ACC_GENERATOR (1 << 24) /* | X | | */
  312. /* | | | */
  313. /* function was processed by pass two (user only) | | | */
  314. #define ZEND_ACC_DONE_PASS_TWO (1 << 25) /* | X | | */
  315. /* | | | */
  316. /* internal function is allocated at arena (int only) | | | */
  317. #define ZEND_ACC_ARENA_ALLOCATED (1 << 25) /* | X | | */
  318. /* | | | */
  319. /* run_time_cache allocated on heap (user only) | | | */
  320. #define ZEND_ACC_HEAP_RT_CACHE (1 << 26) /* | X | | */
  321. /* | | | */
  322. /* method flag used by Closure::__invoke() (int only) | | | */
  323. #define ZEND_ACC_USER_ARG_INFO (1 << 26) /* | X | | */
  324. /* | | | */
  325. /* op_array uses strict mode types | | | */
  326. #define ZEND_ACC_STRICT_TYPES (1U << 31) /* | X | | */
  327. #define ZEND_ACC_PPP_MASK (ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)
  328. /* call through internal function handler. e.g. Closure::invoke() */
  329. #define ZEND_ACC_CALL_VIA_HANDLER ZEND_ACC_CALL_VIA_TRAMPOLINE
  330. #define ZEND_SHORT_CIRCUITING_CHAIN_EXPR 0
  331. #define ZEND_SHORT_CIRCUITING_CHAIN_ISSET 1
  332. #define ZEND_SHORT_CIRCUITING_CHAIN_EMPTY 2
  333. char *zend_visibility_string(uint32_t fn_flags);
  334. typedef struct _zend_property_info {
  335. uint32_t offset; /* property offset for object properties or
  336. property index for static properties */
  337. uint32_t flags;
  338. zend_string *name;
  339. zend_string *doc_comment;
  340. HashTable *attributes;
  341. zend_class_entry *ce;
  342. zend_type type;
  343. } zend_property_info;
  344. #define OBJ_PROP(obj, offset) \
  345. ((zval*)((char*)(obj) + offset))
  346. #define OBJ_PROP_NUM(obj, num) \
  347. (&(obj)->properties_table[(num)])
  348. #define OBJ_PROP_TO_OFFSET(num) \
  349. ((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num)))
  350. #define OBJ_PROP_TO_NUM(offset) \
  351. ((offset - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
  352. typedef struct _zend_class_constant {
  353. zval value; /* flags are stored in u2 */
  354. zend_string *doc_comment;
  355. HashTable *attributes;
  356. zend_class_entry *ce;
  357. } zend_class_constant;
  358. #define ZEND_CLASS_CONST_FLAGS(c) Z_CONSTANT_FLAGS((c)->value)
  359. /* arg_info for internal functions */
  360. typedef struct _zend_internal_arg_info {
  361. const char *name;
  362. zend_type type;
  363. const char *default_value;
  364. } zend_internal_arg_info;
  365. /* arg_info for user functions */
  366. typedef struct _zend_arg_info {
  367. zend_string *name;
  368. zend_type type;
  369. zend_string *default_value;
  370. } zend_arg_info;
  371. /* the following structure repeats the layout of zend_internal_arg_info,
  372. * but its fields have different meaning. It's used as the first element of
  373. * arg_info array to define properties of internal functions.
  374. * It's also used for the return type.
  375. */
  376. typedef struct _zend_internal_function_info {
  377. zend_uintptr_t required_num_args;
  378. zend_type type;
  379. const char *default_value;
  380. } zend_internal_function_info;
  381. struct _zend_op_array {
  382. /* Common elements */
  383. zend_uchar type;
  384. zend_uchar arg_flags[3]; /* bitset of arg_info.pass_by_reference */
  385. uint32_t fn_flags;
  386. zend_string *function_name;
  387. zend_class_entry *scope;
  388. zend_function *prototype;
  389. uint32_t num_args;
  390. uint32_t required_num_args;
  391. zend_arg_info *arg_info;
  392. HashTable *attributes;
  393. /* END of common elements */
  394. int cache_size; /* number of run_time_cache_slots * sizeof(void*) */
  395. int last_var; /* number of CV variables */
  396. uint32_t T; /* number of temporary variables */
  397. uint32_t last; /* number of opcodes */
  398. zend_op *opcodes;
  399. ZEND_MAP_PTR_DEF(void **, run_time_cache);
  400. ZEND_MAP_PTR_DEF(HashTable *, static_variables_ptr);
  401. HashTable *static_variables;
  402. zend_string **vars; /* names of CV variables */
  403. uint32_t *refcount;
  404. int last_live_range;
  405. int last_try_catch;
  406. zend_live_range *live_range;
  407. zend_try_catch_element *try_catch_array;
  408. zend_string *filename;
  409. uint32_t line_start;
  410. uint32_t line_end;
  411. zend_string *doc_comment;
  412. int last_literal;
  413. uint32_t num_dynamic_func_defs;
  414. zval *literals;
  415. /* Functions that are declared dynamically are stored here and
  416. * referenced by index from opcodes. */
  417. zend_op_array **dynamic_func_defs;
  418. void *reserved[ZEND_MAX_RESERVED_RESOURCES];
  419. };
  420. #define ZEND_RETURN_VALUE 0
  421. #define ZEND_RETURN_REFERENCE 1
  422. /* zend_internal_function_handler */
  423. typedef void (ZEND_FASTCALL *zif_handler)(INTERNAL_FUNCTION_PARAMETERS);
  424. typedef struct _zend_internal_function {
  425. /* Common elements */
  426. zend_uchar type;
  427. zend_uchar arg_flags[3]; /* bitset of arg_info.pass_by_reference */
  428. uint32_t fn_flags;
  429. zend_string* function_name;
  430. zend_class_entry *scope;
  431. zend_function *prototype;
  432. uint32_t num_args;
  433. uint32_t required_num_args;
  434. zend_internal_arg_info *arg_info;
  435. HashTable *attributes;
  436. /* END of common elements */
  437. zif_handler handler;
  438. struct _zend_module_entry *module;
  439. void *reserved[ZEND_MAX_RESERVED_RESOURCES];
  440. } zend_internal_function;
  441. #define ZEND_FN_SCOPE_NAME(function) ((function) && (function)->common.scope ? ZSTR_VAL((function)->common.scope->name) : "")
  442. union _zend_function {
  443. zend_uchar type; /* MUST be the first element of this struct! */
  444. uint32_t quick_arg_flags;
  445. struct {
  446. zend_uchar type; /* never used */
  447. zend_uchar arg_flags[3]; /* bitset of arg_info.pass_by_reference */
  448. uint32_t fn_flags;
  449. zend_string *function_name;
  450. zend_class_entry *scope;
  451. zend_function *prototype;
  452. uint32_t num_args;
  453. uint32_t required_num_args;
  454. zend_arg_info *arg_info; /* index -1 represents the return value info, if any */
  455. HashTable *attributes;
  456. } common;
  457. zend_op_array op_array;
  458. zend_internal_function internal_function;
  459. };
  460. struct _zend_execute_data {
  461. const zend_op *opline; /* executed opline */
  462. zend_execute_data *call; /* current call */
  463. zval *return_value;
  464. zend_function *func; /* executed function */
  465. zval This; /* this + call_info + num_args */
  466. zend_execute_data *prev_execute_data;
  467. zend_array *symbol_table;
  468. void **run_time_cache; /* cache op_array->run_time_cache */
  469. zend_array *extra_named_params;
  470. };
  471. #define ZEND_CALL_HAS_THIS IS_OBJECT_EX
  472. /* Top 16 bits of Z_TYPE_INFO(EX(This)) are used as call_info flags */
  473. #define ZEND_CALL_FUNCTION (0 << 16)
  474. #define ZEND_CALL_CODE (1 << 16)
  475. #define ZEND_CALL_NESTED (0 << 17)
  476. #define ZEND_CALL_TOP (1 << 17)
  477. #define ZEND_CALL_ALLOCATED (1 << 18)
  478. #define ZEND_CALL_FREE_EXTRA_ARGS (1 << 19)
  479. #define ZEND_CALL_HAS_SYMBOL_TABLE (1 << 20)
  480. #define ZEND_CALL_RELEASE_THIS (1 << 21)
  481. #define ZEND_CALL_CLOSURE (1 << 22)
  482. #define ZEND_CALL_FAKE_CLOSURE (1 << 23) /* Same as ZEND_ACC_FAKE_CLOSURE */
  483. #define ZEND_CALL_GENERATOR (1 << 24)
  484. #define ZEND_CALL_DYNAMIC (1 << 25)
  485. #define ZEND_CALL_MAY_HAVE_UNDEF (1 << 26)
  486. #define ZEND_CALL_HAS_EXTRA_NAMED_PARAMS (1 << 27)
  487. #define ZEND_CALL_OBSERVED (1 << 28) /* "fcall_begin" observer handler may set this flag */
  488. /* to prevent optimization in RETURN handler and */
  489. /* keep all local variables for "fcall_end" handler */
  490. #define ZEND_CALL_JIT_RESERVED (1 << 29) /* reserved for tracing JIT */
  491. #define ZEND_CALL_SEND_ARG_BY_REF (1u << 31)
  492. #define ZEND_CALL_NESTED_FUNCTION (ZEND_CALL_FUNCTION | ZEND_CALL_NESTED)
  493. #define ZEND_CALL_NESTED_CODE (ZEND_CALL_CODE | ZEND_CALL_NESTED)
  494. #define ZEND_CALL_TOP_FUNCTION (ZEND_CALL_TOP | ZEND_CALL_FUNCTION)
  495. #define ZEND_CALL_TOP_CODE (ZEND_CALL_CODE | ZEND_CALL_TOP)
  496. #define ZEND_CALL_INFO(call) \
  497. Z_TYPE_INFO((call)->This)
  498. #define ZEND_CALL_KIND_EX(call_info) \
  499. (call_info & (ZEND_CALL_CODE | ZEND_CALL_TOP))
  500. #define ZEND_CALL_KIND(call) \
  501. ZEND_CALL_KIND_EX(ZEND_CALL_INFO(call))
  502. #define ZEND_ADD_CALL_FLAG_EX(call_info, flag) do { \
  503. call_info |= (flag); \
  504. } while (0)
  505. #define ZEND_DEL_CALL_FLAG_EX(call_info, flag) do { \
  506. call_info &= ~(flag); \
  507. } while (0)
  508. #define ZEND_ADD_CALL_FLAG(call, flag) do { \
  509. ZEND_ADD_CALL_FLAG_EX(Z_TYPE_INFO((call)->This), flag); \
  510. } while (0)
  511. #define ZEND_DEL_CALL_FLAG(call, flag) do { \
  512. ZEND_DEL_CALL_FLAG_EX(Z_TYPE_INFO((call)->This), flag); \
  513. } while (0)
  514. #define ZEND_CALL_NUM_ARGS(call) \
  515. (call)->This.u2.num_args
  516. #define ZEND_CALL_FRAME_SLOT \
  517. ((int)((ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval))))
  518. #define ZEND_CALL_VAR(call, n) \
  519. ((zval*)(((char*)(call)) + ((int)(n))))
  520. #define ZEND_CALL_VAR_NUM(call, n) \
  521. (((zval*)(call)) + (ZEND_CALL_FRAME_SLOT + ((int)(n))))
  522. #define ZEND_CALL_ARG(call, n) \
  523. ZEND_CALL_VAR_NUM(call, ((int)(n)) - 1)
  524. #define EX(element) ((execute_data)->element)
  525. #define EX_CALL_INFO() ZEND_CALL_INFO(execute_data)
  526. #define EX_CALL_KIND() ZEND_CALL_KIND(execute_data)
  527. #define EX_NUM_ARGS() ZEND_CALL_NUM_ARGS(execute_data)
  528. #define ZEND_CALL_USES_STRICT_TYPES(call) \
  529. (((call)->func->common.fn_flags & ZEND_ACC_STRICT_TYPES) != 0)
  530. #define EX_USES_STRICT_TYPES() \
  531. ZEND_CALL_USES_STRICT_TYPES(execute_data)
  532. #define ZEND_ARG_USES_STRICT_TYPES() \
  533. (EG(current_execute_data)->prev_execute_data && \
  534. EG(current_execute_data)->prev_execute_data->func && \
  535. ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)->prev_execute_data))
  536. #define ZEND_RET_USES_STRICT_TYPES() \
  537. ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))
  538. #define EX_VAR(n) ZEND_CALL_VAR(execute_data, n)
  539. #define EX_VAR_NUM(n) ZEND_CALL_VAR_NUM(execute_data, n)
  540. #define EX_VAR_TO_NUM(n) ((uint32_t)((n) / sizeof(zval) - ZEND_CALL_FRAME_SLOT))
  541. #define EX_NUM_TO_VAR(n) ((uint32_t)(((n) + ZEND_CALL_FRAME_SLOT) * sizeof(zval)))
  542. #define ZEND_OPLINE_TO_OFFSET(opline, target) \
  543. ((char*)(target) - (char*)(opline))
  544. #define ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline_num) \
  545. ((char*)&(op_array)->opcodes[opline_num] - (char*)(opline))
  546. #define ZEND_OFFSET_TO_OPLINE(base, offset) \
  547. ((zend_op*)(((char*)(base)) + (int)offset))
  548. #define ZEND_OFFSET_TO_OPLINE_NUM(op_array, base, offset) \
  549. (ZEND_OFFSET_TO_OPLINE(base, offset) - op_array->opcodes)
  550. #if ZEND_USE_ABS_JMP_ADDR
  551. /* run-time jump target */
  552. # define OP_JMP_ADDR(opline, node) \
  553. (node).jmp_addr
  554. # define ZEND_SET_OP_JMP_ADDR(opline, node, val) do { \
  555. (node).jmp_addr = (val); \
  556. } while (0)
  557. /* convert jump target from compile-time to run-time */
  558. # define ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, node) do { \
  559. (node).jmp_addr = (op_array)->opcodes + (node).opline_num; \
  560. } while (0)
  561. /* convert jump target back from run-time to compile-time */
  562. # define ZEND_PASS_TWO_UNDO_JMP_TARGET(op_array, opline, node) do { \
  563. (node).opline_num = (node).jmp_addr - (op_array)->opcodes; \
  564. } while (0)
  565. #else
  566. /* run-time jump target */
  567. # define OP_JMP_ADDR(opline, node) \
  568. ZEND_OFFSET_TO_OPLINE(opline, (node).jmp_offset)
  569. # define ZEND_SET_OP_JMP_ADDR(opline, node, val) do { \
  570. (node).jmp_offset = ZEND_OPLINE_TO_OFFSET(opline, val); \
  571. } while (0)
  572. /* convert jump target from compile-time to run-time */
  573. # define ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, node) do { \
  574. (node).jmp_offset = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, (node).opline_num); \
  575. } while (0)
  576. /* convert jump target back from run-time to compile-time */
  577. # define ZEND_PASS_TWO_UNDO_JMP_TARGET(op_array, opline, node) do { \
  578. (node).opline_num = ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, (node).jmp_offset); \
  579. } while (0)
  580. #endif
  581. /* constant-time constant */
  582. # define CT_CONSTANT_EX(op_array, num) \
  583. ((op_array)->literals + (num))
  584. # define CT_CONSTANT(node) \
  585. CT_CONSTANT_EX(CG(active_op_array), (node).constant)
  586. #if ZEND_USE_ABS_CONST_ADDR
  587. /* run-time constant */
  588. # define RT_CONSTANT(opline, node) \
  589. (node).zv
  590. /* convert constant from compile-time to run-time */
  591. # define ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline, node) do { \
  592. (node).zv = CT_CONSTANT_EX(op_array, (node).constant); \
  593. } while (0)
  594. #else
  595. /* At run-time, constants are allocated together with op_array->opcodes
  596. * and addressed relatively to current opline.
  597. */
  598. /* run-time constant */
  599. # define RT_CONSTANT(opline, node) \
  600. ((zval*)(((char*)(opline)) + (int32_t)(node).constant))
  601. /* convert constant from compile-time to run-time */
  602. # define ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline, node) do { \
  603. (node).constant = \
  604. (((char*)CT_CONSTANT_EX(op_array, (node).constant)) - \
  605. ((char*)opline)); \
  606. } while (0)
  607. #endif
  608. /* convert constant back from run-time to compile-time */
  609. #define ZEND_PASS_TWO_UNDO_CONSTANT(op_array, opline, node) do { \
  610. (node).constant = RT_CONSTANT(opline, node) - (op_array)->literals; \
  611. } while (0)
  612. #define RUN_TIME_CACHE(op_array) \
  613. ZEND_MAP_PTR_GET((op_array)->run_time_cache)
  614. #define ZEND_OP_ARRAY_EXTENSION(op_array, handle) \
  615. ((void**)RUN_TIME_CACHE(op_array))[handle]
  616. #define IS_UNUSED 0 /* Unused operand */
  617. #define IS_CONST (1<<0)
  618. #define IS_TMP_VAR (1<<1)
  619. #define IS_VAR (1<<2)
  620. #define IS_CV (1<<3) /* Compiled variable */
  621. /* Used for result.type of smart branch instructions */
  622. #define IS_SMART_BRANCH_JMPZ (1<<4)
  623. #define IS_SMART_BRANCH_JMPNZ (1<<5)
  624. #define ZEND_EXTRA_VALUE 1
  625. #include "zend_globals.h"
  626. BEGIN_EXTERN_C()
  627. void init_compiler(void);
  628. void shutdown_compiler(void);
  629. void zend_init_compiler_data_structures(void);
  630. void zend_oparray_context_begin(zend_oparray_context *prev_context);
  631. void zend_oparray_context_end(zend_oparray_context *prev_context);
  632. void zend_file_context_begin(zend_file_context *prev_context);
  633. void zend_file_context_end(zend_file_context *prev_context);
  634. extern ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type);
  635. extern ZEND_API zend_op_array *(*zend_compile_string)(zend_string *source_string, const char *filename);
  636. ZEND_API int ZEND_FASTCALL lex_scan(zval *zendlval, zend_parser_stack_elem *elem);
  637. void startup_scanner(void);
  638. void shutdown_scanner(void);
  639. ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename);
  640. ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename);
  641. ZEND_API zend_string *zend_get_compiled_filename(void);
  642. ZEND_API int zend_get_compiled_lineno(void);
  643. ZEND_API size_t zend_get_scanned_file_offset(void);
  644. ZEND_API zend_string *zend_get_compiled_variable_name(const zend_op_array *op_array, uint32_t var);
  645. #ifdef ZTS
  646. const char *zend_get_zendtext(void);
  647. int zend_get_zendleng(void);
  648. #endif
  649. typedef zend_result (ZEND_FASTCALL *unary_op_type)(zval *, zval *);
  650. typedef zend_result (ZEND_FASTCALL *binary_op_type)(zval *, zval *, zval *);
  651. ZEND_API unary_op_type get_unary_op(int opcode);
  652. ZEND_API binary_op_type get_binary_op(int opcode);
  653. void zend_stop_lexing(void);
  654. void zend_emit_final_return(bool return_one);
  655. /* Used during AST construction */
  656. zend_ast *zend_ast_append_str(zend_ast *left, zend_ast *right);
  657. zend_ast *zend_negate_num_string(zend_ast *ast);
  658. uint32_t zend_add_class_modifier(uint32_t flags, uint32_t new_flag);
  659. uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag);
  660. bool zend_handle_encoding_declaration(zend_ast *ast);
  661. ZEND_API zend_class_entry *zend_bind_class_in_slot(
  662. zval *class_table_slot, zval *lcname, zend_string *lc_parent_name);
  663. ZEND_API zend_result do_bind_function(zend_function *func, zval *lcname);
  664. ZEND_API zend_result do_bind_class(zval *lcname, zend_string *lc_parent_name);
  665. ZEND_API uint32_t zend_build_delayed_early_binding_list(const zend_op_array *op_array);
  666. ZEND_API void zend_do_delayed_early_binding(zend_op_array *op_array, uint32_t first_early_binding_opline);
  667. void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline);
  668. ZEND_API void function_add_ref(zend_function *function);
  669. void zend_init_static_variables_map_ptr(zend_op_array *op_array);
  670. zend_string *zval_make_interned_string(zval *zv);
  671. #define INITIAL_OP_ARRAY_SIZE 64
  672. /* helper functions in zend_language_scanner.l */
  673. struct _zend_arena;
  674. ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type);
  675. ZEND_API zend_op_array *compile_string(zend_string *source_string, const char *filename);
  676. ZEND_API zend_op_array *compile_filename(int type, zend_string *filename);
  677. ZEND_API zend_ast *zend_compile_string_to_ast(
  678. zend_string *code, struct _zend_arena **ast_arena, zend_string *filename);
  679. ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...);
  680. ZEND_API int open_file_for_scanning(zend_file_handle *file_handle);
  681. ZEND_API void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size);
  682. ZEND_API void destroy_op_array(zend_op_array *op_array);
  683. ZEND_API void zend_destroy_static_vars(zend_op_array *op_array);
  684. ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle);
  685. ZEND_API void zend_cleanup_mutable_class_data(zend_class_entry *ce);
  686. ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce);
  687. ZEND_API void zend_type_release(zend_type type, bool persistent);
  688. ZEND_API zend_string *zend_create_member_string(zend_string *class_name, zend_string *member_name);
  689. ZEND_API ZEND_COLD void zend_user_exception_handler(void);
  690. #define zend_try_exception_handler() do { \
  691. if (UNEXPECTED(EG(exception))) { \
  692. if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { \
  693. zend_user_exception_handler(); \
  694. } \
  695. } \
  696. } while (0)
  697. void zend_free_internal_arg_info(zend_internal_function *function);
  698. ZEND_API void destroy_zend_function(zend_function *function);
  699. ZEND_API void zend_function_dtor(zval *zv);
  700. ZEND_API void destroy_zend_class(zval *zv);
  701. void zend_class_add_ref(zval *zv);
  702. ZEND_API zend_string *zend_mangle_property_name(const char *src1, size_t src1_length, const char *src2, size_t src2_length, bool internal);
  703. #define zend_unmangle_property_name(mangled_property, class_name, prop_name) \
  704. zend_unmangle_property_name_ex(mangled_property, class_name, prop_name, NULL)
  705. ZEND_API zend_result zend_unmangle_property_name_ex(const zend_string *name, const char **class_name, const char **prop_name, size_t *prop_len);
  706. static zend_always_inline const char *zend_get_unmangled_property_name(const zend_string *mangled_prop) {
  707. const char *class_name, *prop_name;
  708. zend_unmangle_property_name(mangled_prop, &class_name, &prop_name);
  709. return prop_name;
  710. }
  711. #define ZEND_FUNCTION_DTOR zend_function_dtor
  712. #define ZEND_CLASS_DTOR destroy_zend_class
  713. typedef bool (*zend_needs_live_range_cb)(zend_op_array *op_array, zend_op *opline);
  714. ZEND_API void zend_recalc_live_ranges(
  715. zend_op_array *op_array, zend_needs_live_range_cb needs_live_range);
  716. ZEND_API void pass_two(zend_op_array *op_array);
  717. ZEND_API bool zend_is_compiling(void);
  718. ZEND_API char *zend_make_compiled_string_description(const char *name);
  719. ZEND_API void zend_initialize_class_data(zend_class_entry *ce, bool nullify_handlers);
  720. uint32_t zend_get_class_fetch_type(zend_string *name);
  721. ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc);
  722. ZEND_API bool zend_is_smart_branch(const zend_op *opline);
  723. typedef bool (*zend_auto_global_callback)(zend_string *name);
  724. typedef struct _zend_auto_global {
  725. zend_string *name;
  726. zend_auto_global_callback auto_global_callback;
  727. bool jit;
  728. bool armed;
  729. } zend_auto_global;
  730. ZEND_API zend_result zend_register_auto_global(zend_string *name, bool jit, zend_auto_global_callback auto_global_callback);
  731. ZEND_API void zend_activate_auto_globals(void);
  732. ZEND_API bool zend_is_auto_global(zend_string *name);
  733. ZEND_API bool zend_is_auto_global_str(const char *name, size_t len);
  734. ZEND_API size_t zend_dirname(char *path, size_t len);
  735. ZEND_API void zend_set_function_arg_flags(zend_function *func);
  736. int ZEND_FASTCALL zendlex(zend_parser_stack_elem *elem);
  737. void zend_assert_valid_class_name(const zend_string *const_name);
  738. zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scope);
  739. ZEND_API zend_string *zend_type_to_string(zend_type type);
  740. /* BEGIN: OPCODES */
  741. #include "zend_vm_opcodes.h"
  742. /* END: OPCODES */
  743. /* class fetches */
  744. #define ZEND_FETCH_CLASS_DEFAULT 0
  745. #define ZEND_FETCH_CLASS_SELF 1
  746. #define ZEND_FETCH_CLASS_PARENT 2
  747. #define ZEND_FETCH_CLASS_STATIC 3
  748. #define ZEND_FETCH_CLASS_AUTO 4
  749. #define ZEND_FETCH_CLASS_INTERFACE 5
  750. #define ZEND_FETCH_CLASS_TRAIT 6
  751. #define ZEND_FETCH_CLASS_MASK 0x0f
  752. #define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
  753. #define ZEND_FETCH_CLASS_SILENT 0x0100
  754. #define ZEND_FETCH_CLASS_EXCEPTION 0x0200
  755. #define ZEND_FETCH_CLASS_ALLOW_UNLINKED 0x0400
  756. #define ZEND_FETCH_CLASS_ALLOW_NEARLY_LINKED 0x0800
  757. /* These should not clash with ZEND_ACC_(PUBLIC|PROTECTED|PRIVATE) */
  758. #define ZEND_PARAM_REF (1<<3)
  759. #define ZEND_PARAM_VARIADIC (1<<4)
  760. #define ZEND_NAME_FQ 0
  761. #define ZEND_NAME_NOT_FQ 1
  762. #define ZEND_NAME_RELATIVE 2
  763. /* ZEND_FETCH_ flags in class name AST of new const expression must not clash with ZEND_NAME_ flags */
  764. #define ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT 2
  765. #define ZEND_TYPE_NULLABLE (1<<8)
  766. #define ZEND_ARRAY_SYNTAX_LIST 1 /* list() */
  767. #define ZEND_ARRAY_SYNTAX_LONG 2 /* array() */
  768. #define ZEND_ARRAY_SYNTAX_SHORT 3 /* [] */
  769. /* var status for backpatching */
  770. #define BP_VAR_R 0
  771. #define BP_VAR_W 1
  772. #define BP_VAR_RW 2
  773. #define BP_VAR_IS 3
  774. #define BP_VAR_FUNC_ARG 4
  775. #define BP_VAR_UNSET 5
  776. #define ZEND_INTERNAL_FUNCTION 1
  777. #define ZEND_USER_FUNCTION 2
  778. #define ZEND_EVAL_CODE 4
  779. #define ZEND_USER_CODE(type) ((type) != ZEND_INTERNAL_FUNCTION)
  780. #define ZEND_INTERNAL_CLASS 1
  781. #define ZEND_USER_CLASS 2
  782. #define ZEND_EVAL (1<<0)
  783. #define ZEND_INCLUDE (1<<1)
  784. #define ZEND_INCLUDE_ONCE (1<<2)
  785. #define ZEND_REQUIRE (1<<3)
  786. #define ZEND_REQUIRE_ONCE (1<<4)
  787. /* global/local fetches */
  788. #define ZEND_FETCH_GLOBAL (1<<1)
  789. #define ZEND_FETCH_LOCAL (1<<2)
  790. #define ZEND_FETCH_GLOBAL_LOCK (1<<3)
  791. #define ZEND_FETCH_TYPE_MASK 0xe
  792. /* Only one of these can ever be in use */
  793. #define ZEND_FETCH_REF 1
  794. #define ZEND_FETCH_DIM_WRITE 2
  795. #define ZEND_FETCH_OBJ_FLAGS 3
  796. #define ZEND_ISEMPTY (1<<0)
  797. #define ZEND_LAST_CATCH (1<<0)
  798. #define ZEND_FREE_ON_RETURN (1<<0)
  799. #define ZEND_FREE_SWITCH (1<<1)
  800. #define ZEND_SEND_BY_VAL 0u
  801. #define ZEND_SEND_BY_REF 1u
  802. #define ZEND_SEND_PREFER_REF 2u
  803. #define ZEND_THROW_IS_EXPR 1u
  804. #define ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS 1
  805. /* The send mode, the is_variadic, the is_promoted, and the is_tentative flags are stored as part of zend_type */
  806. #define _ZEND_SEND_MODE_SHIFT _ZEND_TYPE_EXTRA_FLAGS_SHIFT
  807. #define _ZEND_IS_VARIADIC_BIT (1 << (_ZEND_TYPE_EXTRA_FLAGS_SHIFT + 2))
  808. #define _ZEND_IS_PROMOTED_BIT (1 << (_ZEND_TYPE_EXTRA_FLAGS_SHIFT + 3))
  809. #define _ZEND_IS_TENTATIVE_BIT (1 << (_ZEND_TYPE_EXTRA_FLAGS_SHIFT + 4))
  810. #define ZEND_ARG_SEND_MODE(arg_info) \
  811. ((ZEND_TYPE_FULL_MASK((arg_info)->type) >> _ZEND_SEND_MODE_SHIFT) & 3)
  812. #define ZEND_ARG_IS_VARIADIC(arg_info) \
  813. ((ZEND_TYPE_FULL_MASK((arg_info)->type) & _ZEND_IS_VARIADIC_BIT) != 0)
  814. #define ZEND_ARG_IS_PROMOTED(arg_info) \
  815. ((ZEND_TYPE_FULL_MASK((arg_info)->type) & _ZEND_IS_PROMOTED_BIT) != 0)
  816. #define ZEND_ARG_TYPE_IS_TENTATIVE(arg_info) \
  817. ((ZEND_TYPE_FULL_MASK((arg_info)->type) & _ZEND_IS_TENTATIVE_BIT) != 0)
  818. #define ZEND_DIM_IS (1 << 0) /* isset fetch needed for null coalesce */
  819. #define ZEND_DIM_ALTERNATIVE_SYNTAX (1 << 1) /* deprecated curly brace usage */
  820. /* Make sure these don't clash with ZEND_FETCH_CLASS_* flags. */
  821. #define IS_CONSTANT_CLASS 0x400 /* __CLASS__ in trait */
  822. #define IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE 0x800
  823. static zend_always_inline bool zend_check_arg_send_type(const zend_function *zf, uint32_t arg_num, uint32_t mask)
  824. {
  825. arg_num--;
  826. if (UNEXPECTED(arg_num >= zf->common.num_args)) {
  827. if (EXPECTED((zf->common.fn_flags & ZEND_ACC_VARIADIC) == 0)) {
  828. return 0;
  829. }
  830. arg_num = zf->common.num_args;
  831. }
  832. return UNEXPECTED((ZEND_ARG_SEND_MODE(&zf->common.arg_info[arg_num]) & mask) != 0);
  833. }
  834. #define ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
  835. zend_check_arg_send_type(zf, arg_num, ZEND_SEND_BY_REF)
  836. #define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
  837. zend_check_arg_send_type(zf, arg_num, ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF)
  838. #define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
  839. zend_check_arg_send_type(zf, arg_num, ZEND_SEND_PREFER_REF)
  840. /* Quick API to check first 12 arguments */
  841. #define MAX_ARG_FLAG_NUM 12
  842. #ifdef WORDS_BIGENDIAN
  843. # define ZEND_SET_ARG_FLAG(zf, arg_num, mask) do { \
  844. (zf)->quick_arg_flags |= ((mask) << ((arg_num) - 1) * 2); \
  845. } while (0)
  846. # define ZEND_CHECK_ARG_FLAG(zf, arg_num, mask) \
  847. (((zf)->quick_arg_flags >> (((arg_num) - 1) * 2)) & (mask))
  848. #else
  849. # define ZEND_SET_ARG_FLAG(zf, arg_num, mask) do { \
  850. (zf)->quick_arg_flags |= (((mask) << 6) << (arg_num) * 2); \
  851. } while (0)
  852. # define ZEND_CHECK_ARG_FLAG(zf, arg_num, mask) \
  853. (((zf)->quick_arg_flags >> (((arg_num) + 3) * 2)) & (mask))
  854. #endif
  855. #define QUICK_ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
  856. ZEND_CHECK_ARG_FLAG(zf, arg_num, ZEND_SEND_BY_REF)
  857. #define QUICK_ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
  858. ZEND_CHECK_ARG_FLAG(zf, arg_num, ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF)
  859. #define QUICK_ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
  860. ZEND_CHECK_ARG_FLAG(zf, arg_num, ZEND_SEND_PREFER_REF)
  861. #define ZEND_RETURN_VAL 0
  862. #define ZEND_RETURN_REF 1
  863. #define ZEND_BIND_VAL 0
  864. #define ZEND_BIND_REF 1
  865. #define ZEND_BIND_IMPLICIT 2
  866. #define ZEND_BIND_EXPLICIT 4
  867. #define ZEND_RETURNS_FUNCTION (1<<0)
  868. #define ZEND_RETURNS_VALUE (1<<1)
  869. #define ZEND_ARRAY_ELEMENT_REF (1<<0)
  870. #define ZEND_ARRAY_NOT_PACKED (1<<1)
  871. #define ZEND_ARRAY_SIZE_SHIFT 2
  872. /* Attribute for ternary inside parentheses */
  873. #define ZEND_PARENTHESIZED_CONDITIONAL 1
  874. /* For "use" AST nodes and the seen symbol table */
  875. #define ZEND_SYMBOL_CLASS (1<<0)
  876. #define ZEND_SYMBOL_FUNCTION (1<<1)
  877. #define ZEND_SYMBOL_CONST (1<<2)
  878. /* All increment opcodes are even (decrement are odd) */
  879. #define ZEND_IS_INCREMENT(opcode) (((opcode) & 1) == 0)
  880. #define ZEND_IS_BINARY_ASSIGN_OP_OPCODE(opcode) \
  881. (((opcode) >= ZEND_ADD) && ((opcode) <= ZEND_POW))
  882. /* Pseudo-opcodes that are used only temporarily during compilation */
  883. #define ZEND_GOTO 253
  884. #define ZEND_BRK 254
  885. #define ZEND_CONT 255
  886. END_EXTERN_C()
  887. #define ZEND_CLONE_FUNC_NAME "__clone"
  888. #define ZEND_CONSTRUCTOR_FUNC_NAME "__construct"
  889. #define ZEND_DESTRUCTOR_FUNC_NAME "__destruct"
  890. #define ZEND_GET_FUNC_NAME "__get"
  891. #define ZEND_SET_FUNC_NAME "__set"
  892. #define ZEND_UNSET_FUNC_NAME "__unset"
  893. #define ZEND_ISSET_FUNC_NAME "__isset"
  894. #define ZEND_CALL_FUNC_NAME "__call"
  895. #define ZEND_CALLSTATIC_FUNC_NAME "__callstatic"
  896. #define ZEND_TOSTRING_FUNC_NAME "__tostring"
  897. #define ZEND_INVOKE_FUNC_NAME "__invoke"
  898. #define ZEND_DEBUGINFO_FUNC_NAME "__debuginfo"
  899. /* The following constants may be combined in CG(compiler_options)
  900. * to change the default compiler behavior */
  901. /* generate extended debug information */
  902. #define ZEND_COMPILE_EXTENDED_STMT (1<<0)
  903. #define ZEND_COMPILE_EXTENDED_FCALL (1<<1)
  904. #define ZEND_COMPILE_EXTENDED_INFO (ZEND_COMPILE_EXTENDED_STMT|ZEND_COMPILE_EXTENDED_FCALL)
  905. /* call op_array handler of extensions */
  906. #define ZEND_COMPILE_HANDLE_OP_ARRAY (1<<2)
  907. /* generate ZEND_INIT_FCALL_BY_NAME for internal functions instead of ZEND_INIT_FCALL */
  908. #define ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS (1<<3)
  909. /* don't perform early binding for classes inherited form internal ones;
  910. * in namespaces assume that internal class that doesn't exist at compile-time
  911. * may appear in run-time */
  912. #define ZEND_COMPILE_IGNORE_INTERNAL_CLASSES (1<<4)
  913. /* generate ZEND_DECLARE_CLASS_DELAYED opcode to delay early binding */
  914. #define ZEND_COMPILE_DELAYED_BINDING (1<<5)
  915. /* disable constant substitution at compile-time */
  916. #define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION (1<<6)
  917. /* disable substitution of persistent constants at compile-time */
  918. #define ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION (1<<8)
  919. /* generate ZEND_INIT_FCALL_BY_NAME for userland functions instead of ZEND_INIT_FCALL */
  920. #define ZEND_COMPILE_IGNORE_USER_FUNCTIONS (1<<9)
  921. /* force ZEND_ACC_USE_GUARDS for all classes */
  922. #define ZEND_COMPILE_GUARDS (1<<10)
  923. /* disable builtin special case function calls */
  924. #define ZEND_COMPILE_NO_BUILTINS (1<<11)
  925. /* result of compilation may be stored in file cache */
  926. #define ZEND_COMPILE_WITH_FILE_CACHE (1<<12)
  927. /* ignore functions and classes declared in other files */
  928. #define ZEND_COMPILE_IGNORE_OTHER_FILES (1<<13)
  929. /* this flag is set when compiler invoked by opcache_compile_file() */
  930. #define ZEND_COMPILE_WITHOUT_EXECUTION (1<<14)
  931. /* this flag is set when compiler invoked during preloading */
  932. #define ZEND_COMPILE_PRELOAD (1<<15)
  933. /* disable jumptable optimization for switch statements */
  934. #define ZEND_COMPILE_NO_JUMPTABLES (1<<16)
  935. /* this flag is set when compiler invoked during preloading in separate process */
  936. #define ZEND_COMPILE_PRELOAD_IN_CHILD (1<<17)
  937. /* The default value for CG(compiler_options) */
  938. #define ZEND_COMPILE_DEFAULT ZEND_COMPILE_HANDLE_OP_ARRAY
  939. /* The default value for CG(compiler_options) during eval() */
  940. #define ZEND_COMPILE_DEFAULT_FOR_EVAL 0
  941. ZEND_API bool zend_is_op_long_compatible(zval *op);
  942. ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op2);
  943. ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, zval *op);
  944. #endif /* ZEND_COMPILE_H */