1
2 #include "php_phalcon.h"
3 #include "phalcon.h"
4
5 #include <ext/standard/php_smart_str.h>
6 #include <main/spprintf.h>
7
8 #include "parser.php5.h"
9 #include "scanner.h"
10 #include "annot.h"
11
12 #include "kernel/main.h"
13 #include "kernel/exception.h"
14
phannot_alloc_zval()15 static inline zval *phannot_alloc_zval()
16 {
17 zval *ret;
18 MAKE_STD_ZVAL(ret);
19 return ret;
20 }
21
22 #define phannot_add_assoc_stringl(var, index, str, len) add_assoc_stringl(var, index, str, len, 0);
23 #define phannot_add_assoc_string_copy(var, index, str, copy) add_assoc_string(var, index, str, copy);
24 #define PHANNOT_IS_INTERNED(z) IS_INTERNED(z)
25
phannot_ret_literal_zval(int type,phannot_parser_token * T)26 static zval *phannot_ret_literal_zval(int type, phannot_parser_token *T)
27 {
28 zval *ret;
29
30 ret = phannot_alloc_zval();
31
32 array_init_size(ret, 2);
33 add_assoc_long(ret, "type", type);
34 if (T) {
35 phannot_add_assoc_stringl(ret, "value", T->token, T->token_len);
36 efree(T);
37 }
38
39 return ret;
40 }
41
phannot_ret_array(zval * items)42 static zval *phannot_ret_array(zval *items)
43 {
44 zval *ret;
45
46 ret = phannot_alloc_zval();
47 array_init_size(ret, 2);
48 add_assoc_long(ret, "type", PHANNOT_T_ARRAY);
49
50 if (items) {
51 add_assoc_zval(ret, "items", items);
52 }
53
54 return ret;
55 }
56
phannot_ret_zval_list(zval * list_left,zval * right_list)57 static zval *phannot_ret_zval_list(zval *list_left, zval *right_list)
58 {
59 zval *ret;
60 HashTable *list;
61
62 ret = phannot_alloc_zval();
63 array_init(ret);
64
65 if (list_left) {
66
67 list = Z_ARRVAL_P(list_left);
68 if (zend_hash_index_exists(list, 0)) {
69 {
70 HashPosition pos;
71 zend_hash_internal_pointer_reset_ex(list, &pos);
72 for (;; zend_hash_move_forward_ex(list, &pos)) {
73
74 zval ** item;
75
76 if (zend_hash_get_current_data_ex(list, (void**) &item, &pos) == FAILURE) {
77 break;
78 }
79
80 Z_ADDREF_PP(item);
81 add_next_index_zval(ret, *item);
82 }
83 zval_ptr_dtor(&list_left);
84 }
85 } else {
86 add_next_index_zval(ret, list_left);
87 }
88 }
89
90 add_next_index_zval(ret, right_list);
91
92 return ret;
93 }
94
phannot_ret_named_item(phannot_parser_token * name,zval * expr)95 static zval *phannot_ret_named_item(phannot_parser_token *name, zval *expr)
96 {
97 zval *ret;
98
99 ret = phannot_alloc_zval();
100 array_init_size(ret, 2);
101
102 add_assoc_zval(ret, "expr", expr);
103 if (name != NULL) {
104 phannot_add_assoc_stringl(ret, "name", name->token, name->token_len);
105 efree(name);
106 }
107
108 return ret;
109 }
110
phannot_ret_annotation(phannot_parser_token * name,zval * arguments,phannot_scanner_state * state)111 static zval *phannot_ret_annotation(phannot_parser_token *name, zval *arguments, phannot_scanner_state *state)
112 {
113 zval *ret;
114
115 ret = phannot_alloc_zval();
116 array_init_size(ret, 5);
117
118 add_assoc_long(ret, "type", PHANNOT_T_ANNOTATION);
119
120 if (name) {
121 phannot_add_assoc_stringl(ret, "name", name->token, name->token_len);
122 efree(name);
123 }
124
125 if (arguments) {
126 add_assoc_zval(ret, "arguments", arguments);
127 }
128
129 phannot_add_assoc_string_copy(ret, "file", (char*)state->active_file, !PHANNOT_IS_INTERNED(state->active_file));
130 add_assoc_long(ret, "line", state->active_line);
131
132 return ret;
133 }
134