summaryrefslogtreecommitdiff
path: root/src/sp_var_value.c
diff options
context:
space:
mode:
authorThibault "bui" Koechlin2017-12-28 17:04:06 +0100
committerjvoisin2017-12-28 17:04:06 +0100
commit9f5e8d12f05fb24c915a5266a1e908a75c8aed08 (patch)
tree9160075ea943c7fd29a3923f844a0ac0d6b8b457 /src/sp_var_value.c
parent62c48bf9a85e0294b7b32cea438e904e1cd50669 (diff)
Clang-format pass
- `clang-format --style="{BasedOnStyle: google, SortIncludes: false}" -i snuffleu*.c sp_*.c sp_*.h` - Update the documentation accordingly
Diffstat (limited to 'src/sp_var_value.c')
-rw-r--r--src/sp_var_value.c102
1 files changed, 51 insertions, 51 deletions
diff --git a/src/sp_var_value.c b/src/sp_var_value.c
index 7f74afa..9a23ad9 100644
--- a/src/sp_var_value.c
+++ b/src/sp_var_value.c
@@ -23,16 +23,16 @@ static zval *get_local_var(zend_execute_data *ed, const char *var_name) {
23 zval *value = NULL; 23 zval *value = NULL;
24 24
25 while (current) { 25 while (current) {
26 zend_string* key = NULL; 26 zend_string *key = NULL;
27 EG(current_execute_data) = current; 27 EG(current_execute_data) = current;
28 zend_array* symtable = zend_rebuild_symbol_table(); 28 zend_array *symtable = zend_rebuild_symbol_table();
29 ZEND_HASH_FOREACH_STR_KEY_VAL(symtable, key, value) { 29 ZEND_HASH_FOREACH_STR_KEY_VAL(symtable, key, value) {
30 if (0 == strcmp(var_name, key->val)) { 30 if (0 == strcmp(var_name, key->val)) {
31 if (Z_TYPE_P(value) == IS_INDIRECT) { 31 if (Z_TYPE_P(value) == IS_INDIRECT) {
32 value = Z_INDIRECT_P(value); 32 value = Z_INDIRECT_P(value);
33 } 33 }
34 EG(current_execute_data) = orig_execute_data; 34 EG(current_execute_data) = orig_execute_data;
35 return value; 35 return value;
36 } 36 }
37 } 37 }
38 ZEND_HASH_FOREACH_END(); 38 ZEND_HASH_FOREACH_END();
@@ -51,7 +51,7 @@ static zval *get_constant(const char *value) {
51} 51}
52 52
53static zval *get_var_value(zend_execute_data *ed, const char *var_name, 53static zval *get_var_value(zend_execute_data *ed, const char *var_name,
54 bool is_param) { 54 bool is_param) {
55 zval *zvalue = NULL; 55 zval *zvalue = NULL;
56 56
57 if (!var_name) { 57 if (!var_name) {
@@ -73,14 +73,14 @@ static zval *get_var_value(zend_execute_data *ed, const char *var_name,
73} 73}
74 74
75static void *get_entry_hashtable(const HashTable *ht, const char *entry, 75static void *get_entry_hashtable(const HashTable *ht, const char *entry,
76 size_t entry_len) { 76 size_t entry_len) {
77 zval *zvalue = zend_hash_str_find(ht, entry, entry_len); 77 zval *zvalue = zend_hash_str_find(ht, entry, entry_len);
78 78
79 if (!zvalue) { 79 if (!zvalue) {
80 zvalue = zend_hash_index_find(ht, atol(entry)); 80 zvalue = zend_hash_index_find(ht, atol(entry));
81 } 81 }
82 while (zvalue && (Z_TYPE_P(zvalue) == IS_INDIRECT 82 while (zvalue &&
83 || Z_TYPE_P(zvalue) == IS_PTR)) { 83 (Z_TYPE_P(zvalue) == IS_INDIRECT || Z_TYPE_P(zvalue) == IS_PTR)) {
84 if (Z_TYPE_P(zvalue) == IS_INDIRECT) { 84 if (Z_TYPE_P(zvalue) == IS_INDIRECT) {
85 zvalue = Z_INDIRECT_P(zvalue); 85 zvalue = Z_INDIRECT_P(zvalue);
86 } else { 86 } else {
@@ -91,7 +91,7 @@ static void *get_entry_hashtable(const HashTable *ht, const char *entry,
91} 91}
92 92
93static zval *get_array_value(zend_execute_data *ed, zval *zvalue, 93static zval *get_array_value(zend_execute_data *ed, zval *zvalue,
94 const sp_tree *tree) { 94 const sp_tree *tree) {
95 zval *idx_value, *ret = NULL; 95 zval *idx_value, *ret = NULL;
96 char *idx = NULL; 96 char *idx = NULL;
97 97
@@ -108,7 +108,7 @@ static zval *get_array_value(zend_execute_data *ed, zval *zvalue,
108} 108}
109 109
110static zval *get_object_property(zend_execute_data *ed, zval *object, 110static zval *get_object_property(zend_execute_data *ed, zval *object,
111 const char *property, bool is_param) { 111 const char *property, bool is_param) {
112 char *class_name = object->value.obj->ce->name->val; 112 char *class_name = object->value.obj->ce->name->val;
113 HashTable *array = Z_OBJPROP_P(object); 113 HashTable *array = Z_OBJPROP_P(object);
114 zval *zvalue = NULL; 114 zval *zvalue = NULL;
@@ -131,7 +131,8 @@ static zval *get_object_property(zend_execute_data *ed, zval *object,
131 } 131 }
132 if (!zvalue) { 132 if (!zvalue) {
133 char *private_property = emalloc(strlen(class_name) + 3 + strlen(property)); 133 char *private_property = emalloc(strlen(class_name) + 3 + strlen(property));
134 len = sprintf(private_property, PRIVATE_PROP_FMT, 0, class_name, 0, property); 134 len =
135 sprintf(private_property, PRIVATE_PROP_FMT, 0, class_name, 0, property);
135 zvalue = get_entry_hashtable(array, private_property, len); 136 zvalue = get_entry_hashtable(array, private_property, len);
136 efree(private_property); 137 efree(private_property);
137 } 138 }
@@ -149,8 +150,8 @@ static zend_class_entry *get_class(const char *value) {
149} 150}
150 151
151static zval *get_unknown_type(const char *restrict value, zval *zvalue, 152static zval *get_unknown_type(const char *restrict value, zval *zvalue,
152 zend_class_entry *ce, zend_execute_data *ed, 153 zend_class_entry *ce, zend_execute_data *ed,
153 const sp_tree *tree, bool is_param) { 154 const sp_tree *tree, bool is_param) {
154 if (ce) { 155 if (ce) {
155 zvalue = get_entry_hashtable(&ce->constants_table, value, strlen(value)); 156 zvalue = get_entry_hashtable(&ce->constants_table, value, strlen(value));
156 ce = NULL; 157 ce = NULL;
@@ -171,51 +172,50 @@ static zval *get_unknown_type(const char *restrict value, zval *zvalue,
171 return zvalue; 172 return zvalue;
172} 173}
173 174
174zval *get_value(zend_execute_data *ed, const sp_tree *tree, 175zval *get_value(zend_execute_data *ed, const sp_tree *tree, bool is_param) {
175 bool is_param) {
176 zval *zvalue = NULL; 176 zval *zvalue = NULL;
177 zend_class_entry *ce = NULL; 177 zend_class_entry *ce = NULL;
178 178
179 while (tree) { 179 while (tree) {
180 switch (tree->type) { 180 switch (tree->type) {
181 case ARRAY: 181 case ARRAY:
182 if (ce) { 182 if (ce) {
183 zvalue = get_entry_hashtable(&ce->constants_table, tree->value, 183 zvalue = get_entry_hashtable(&ce->constants_table, tree->value,
184 strlen(tree->value)); 184 strlen(tree->value));
185 ce = NULL; 185 ce = NULL;
186 } else if (!zvalue) { 186 } else if (!zvalue) {
187 zvalue = get_var_value(ed, tree->value, is_param); 187 zvalue = get_var_value(ed, tree->value, is_param);
188 } else if (Z_TYPE_P(zvalue) == IS_OBJECT) { 188 } else if (Z_TYPE_P(zvalue) == IS_OBJECT) {
189 zvalue = get_object_property(ed, zvalue, tree->value, is_param); 189 zvalue = get_object_property(ed, zvalue, tree->value, is_param);
190 } 190 }
191 zvalue = get_array_value(ed, zvalue, tree); 191 zvalue = get_array_value(ed, zvalue, tree);
192 break; 192 break;
193 case VAR: 193 case VAR:
194 if (zvalue && Z_TYPE_P(zvalue) == IS_OBJECT) { 194 if (zvalue && Z_TYPE_P(zvalue) == IS_OBJECT) {
195 zvalue = get_object_property(ed, zvalue, tree->value, is_param); 195 zvalue = get_object_property(ed, zvalue, tree->value, is_param);
196 } else { 196 } else {
197 zvalue = get_var_value(ed, tree->value, is_param); 197 zvalue = get_var_value(ed, tree->value, is_param);
198 } 198 }
199 break; 199 break;
200 case OBJECT: 200 case OBJECT:
201 if (!zvalue) { 201 if (!zvalue) {
202 zvalue = get_var_value(ed, tree->value, is_param); 202 zvalue = get_var_value(ed, tree->value, is_param);
203 } else if (Z_TYPE_P(zvalue) == IS_OBJECT) { 203 } else if (Z_TYPE_P(zvalue) == IS_OBJECT) {
204 if (0 != strlen(tree->value)) { 204 if (0 != strlen(tree->value)) {
205 zvalue = get_object_property(ed, zvalue, tree->value, is_param); 205 zvalue = get_object_property(ed, zvalue, tree->value, is_param);
206 } 206 }
207 } else { 207 } else {
208 return NULL; 208 return NULL;
209 } 209 }
210 break; 210 break;
211 case CLASS: 211 case CLASS:
212 ce = get_class(tree->value); 212 ce = get_class(tree->value);
213 zvalue = NULL; 213 zvalue = NULL;
214 break; 214 break;
215 default: 215 default:
216 zvalue = get_unknown_type(tree->value, zvalue, ce, ed, tree, is_param); 216 zvalue = get_unknown_type(tree->value, zvalue, ce, ed, tree, is_param);
217 ce = NULL; 217 ce = NULL;
218 break; 218 break;
219 } 219 }
220 if (!zvalue && !ce) { 220 if (!zvalue && !ce) {
221 return NULL; 221 return NULL;