diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/php_snuffleupagus.h | 1 | ||||
| -rw-r--r-- | src/sp_tree.c | 2 | ||||
| -rw-r--r-- | src/sp_tree.h | 27 | ||||
| -rw-r--r-- | src/sp_var_parser.c | 4 | ||||
| -rw-r--r-- | src/sp_var_parser.h | 48 |
5 files changed, 44 insertions, 38 deletions
diff --git a/src/php_snuffleupagus.h b/src/php_snuffleupagus.h index bccf998..cf50a10 100644 --- a/src/php_snuffleupagus.h +++ b/src/php_snuffleupagus.h | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include "zend_extensions.h" | 26 | #include "zend_extensions.h" |
| 27 | 27 | ||
| 28 | #include "sp_list.h" | 28 | #include "sp_list.h" |
| 29 | #include "sp_tree.h" | ||
| 29 | #include "sp_var_parser.h" | 30 | #include "sp_var_parser.h" |
| 30 | #include "sp_config.h" | 31 | #include "sp_config.h" |
| 31 | #include "sp_config_utils.h" | 32 | #include "sp_config_utils.h" |
diff --git a/src/sp_tree.c b/src/sp_tree.c index 328a919..55b6ff4 100644 --- a/src/sp_tree.c +++ b/src/sp_tree.c | |||
| @@ -15,6 +15,6 @@ sp_tree *sp_tree_new() { | |||
| 15 | sp_tree *new = pecalloc(sizeof(sp_tree), 1, 1); | 15 | sp_tree *new = pecalloc(sizeof(sp_tree), 1, 1); |
| 16 | new->next = new->idx = NULL; | 16 | new->next = new->idx = NULL; |
| 17 | new->value = NULL; | 17 | new->value = NULL; |
| 18 | new->type = 0; | 18 | new->type = UNDEFINED; |
| 19 | return new; | 19 | return new; |
| 20 | } | 20 | } |
diff --git a/src/sp_tree.h b/src/sp_tree.h new file mode 100644 index 0000000..c831736 --- /dev/null +++ b/src/sp_tree.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #ifndef SP_TREE_H | ||
| 2 | #define SP_TREE_H | ||
| 3 | #include "php_snuffleupagus.h" | ||
| 4 | |||
| 5 | typedef enum { | ||
| 6 | UNDEFINED = 0, | ||
| 7 | OBJECT, | ||
| 8 | ARRAY, | ||
| 9 | ARRAY_END, | ||
| 10 | STRING_DELIMITER, | ||
| 11 | CLASS, | ||
| 12 | VAR, | ||
| 13 | ESC_STRING_DELIMITER, | ||
| 14 | CONSTANT | ||
| 15 | } elem_type; | ||
| 16 | |||
| 17 | typedef struct parser_s { | ||
| 18 | elem_type type; | ||
| 19 | char *value; | ||
| 20 | struct parser_s *idx; | ||
| 21 | struct parser_s *next; | ||
| 22 | } sp_tree; | ||
| 23 | |||
| 24 | sp_tree *sp_tree_new(); | ||
| 25 | void sp_tree_free(sp_tree *); | ||
| 26 | |||
| 27 | #endif | ||
diff --git a/src/sp_var_parser.c b/src/sp_var_parser.c index bc0a80e..6d80b39 100644 --- a/src/sp_var_parser.c +++ b/src/sp_var_parser.c | |||
| @@ -52,7 +52,7 @@ static int create_var(sp_tree *tree, const char *restrict value, | |||
| 52 | if (!tree) { | 52 | if (!tree) { |
| 53 | return -1; | 53 | return -1; |
| 54 | } | 54 | } |
| 55 | if (tree->next == NULL && tree->type == 0) { | 55 | if (tree->next == NULL && tree->type == UNDEFINED) { |
| 56 | var_node = tree; | 56 | var_node = tree; |
| 57 | } else { | 57 | } else { |
| 58 | var_node = pecalloc(sizeof(sp_tree), 1, 1); | 58 | var_node = pecalloc(sizeof(sp_tree), 1, 1); |
| @@ -239,7 +239,7 @@ sp_tree *parse_var(const char *line) { | |||
| 239 | tree = parse_tokens(line, tokens_list); | 239 | tree = parse_tokens(line, tokens_list); |
| 240 | sp_list_free(tokens_list); | 240 | sp_list_free(tokens_list); |
| 241 | // Check if tree is empty. | 241 | // Check if tree is empty. |
| 242 | if (tree && tree->next == NULL && tree->type == 0) { | 242 | if (tree && tree->next == NULL && tree->type == UNDEFINED) { |
| 243 | tree->type = CONSTANT; | 243 | tree->type = CONSTANT; |
| 244 | tree->value = pestrdup("", 1); | 244 | tree->value = pestrdup("", 1); |
| 245 | } | 245 | } |
diff --git a/src/sp_var_parser.h b/src/sp_var_parser.h index eec1d06..eec77c9 100644 --- a/src/sp_var_parser.h +++ b/src/sp_var_parser.h | |||
| @@ -1,18 +1,6 @@ | |||
| 1 | #ifndef SP_VAR_PARSER_H | 1 | #ifndef SP_VAR_PARSER_H |
| 2 | # define SP_VAR_PARSER_H | 2 | #define SP_VAR_PARSER_H |
| 3 | # include "php_snuffleupagus.h" | 3 | #include "php_snuffleupagus.h" |
| 4 | # include "sp_list.h" | ||
| 5 | |||
| 6 | typedef enum { | ||
| 7 | OBJECT = 1, | ||
| 8 | ARRAY, | ||
| 9 | ARRAY_END, | ||
| 10 | STRING_DELIMITER, | ||
| 11 | CLASS, | ||
| 12 | VAR, | ||
| 13 | ESC_STRING_DELIMITER, | ||
| 14 | CONSTANT | ||
| 15 | } elem_type; | ||
| 16 | 4 | ||
| 17 | typedef struct sp_token_s { | 5 | typedef struct sp_token_s { |
| 18 | elem_type type; | 6 | elem_type type; |
| @@ -20,32 +8,22 @@ typedef struct sp_token_s { | |||
| 20 | unsigned int pos; | 8 | unsigned int pos; |
| 21 | } sp_token_t; | 9 | } sp_token_t; |
| 22 | 10 | ||
| 23 | typedef struct parser_s { | ||
| 24 | elem_type type; | ||
| 25 | char *value; | ||
| 26 | struct parser_s *idx; | ||
| 27 | struct parser_s *next; | ||
| 28 | } sp_tree; | ||
| 29 | |||
| 30 | zval *get_value(zend_execute_data *, const sp_tree *, bool); | 11 | zval *get_value(zend_execute_data *, const sp_tree *, bool); |
| 31 | sp_tree *sp_tree_new(); | ||
| 32 | sp_tree *parse_var(const char *); | 12 | sp_tree *parse_var(const char *); |
| 33 | void print_type_list(const char *, sp_tree*, int); | ||
| 34 | void sp_tree_free(sp_tree *); | ||
| 35 | 13 | ||
| 36 | # define OBJECT_TOKEN "->" | 14 | #define OBJECT_TOKEN "->" |
| 37 | # define ARRAY_TOKEN "[" | 15 | #define ARRAY_TOKEN "[" |
| 38 | # define ARRAY_END_TOKEN "]" | 16 | #define ARRAY_END_TOKEN "]" |
| 39 | # define STRING_TOKEN "\"" | 17 | #define STRING_TOKEN "\"" |
| 40 | # define ESC_STRING_TOKEN "\'" | 18 | #define ESC_STRING_TOKEN "\'" |
| 41 | # define CLASS_TOKEN "::" | 19 | #define CLASS_TOKEN "::" |
| 42 | 20 | ||
| 43 | # define VARIABLE_TOKEN '$' | 21 | #define VARIABLE_TOKEN '$' |
| 44 | 22 | ||
| 45 | # define PRIVATE_PROP_FMT "%c%s%c%s" | 23 | #define PRIVATE_PROP_FMT "%c%s%c%s" |
| 46 | # define PROTECTED_PROP_FMT "%c*%c%s" | 24 | #define PROTECTED_PROP_FMT "%c*%c%s" |
| 47 | 25 | ||
| 48 | # define REGEXP_VAR "^\\$[a-z_][a-z0-9_]*$" | 26 | #define REGEXP_VAR "^\\$[a-z_][a-z0-9_]*$" |
| 49 | # define REGEXP_CONST "^[a-z_0-9\\\\]*$" | 27 | #define REGEXP_CONST "^[a-z_0-9\\\\]*$" |
| 50 | 28 | ||
| 51 | #endif | 29 | #endif |
