summaryrefslogtreecommitdiff
path: root/Zend/zend_ast.h
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2014-07-27 22:26:06 +0200
committerNikita Popov <nikic@php.net>2014-07-28 12:06:57 +0200
commitd3cb2393052d435abdad7dcdeaa726c949a37668 (patch)
tree77df7abb1a091b03fccbfe58009c913a8ab10451 /Zend/zend_ast.h
parent21eb6807c98756708c49cb5d571de030e41af218 (diff)
downloadphp-git-d3cb2393052d435abdad7dcdeaa726c949a37668.tar.gz
Use separate node type for lists
This saves storing the children count for normal ast nodes.
Diffstat (limited to 'Zend/zend_ast.h')
-rw-r--r--Zend/zend_ast.h173
1 files changed, 106 insertions, 67 deletions
diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h
index 5288ad8023..87b26405a6 100644
--- a/Zend/zend_ast.h
+++ b/Zend/zend_ast.h
@@ -25,31 +25,49 @@
#include "zend.h"
+
+#define ZEND_AST_IS_LIST_SHIFT 11
+#define ZEND_AST_NUM_CHILDREN_SHIFT 12
+
enum _zend_ast_kind {
/* first 256 kinds are reserved for opcodes */
ZEND_AST_ZVAL = 256,
ZEND_AST_ZNODE,
- ZEND_AST_VAR,
- ZEND_AST_DIM,
- ZEND_AST_PROP,
- ZEND_AST_STATIC_PROP,
+ /* declaration nodes */
+ ZEND_AST_FUNC_DECL,
+ ZEND_AST_CLOSURE,
+ ZEND_AST_METHOD,
+ ZEND_AST_CLASS,
- ZEND_AST_CALL,
- ZEND_AST_METHOD_CALL,
- ZEND_AST_STATIC_CALL,
- ZEND_AST_ARG_LIST,
- ZEND_AST_UNPACK,
+ /* list nodes */
+ ZEND_AST_ARG_LIST = 1 << ZEND_AST_IS_LIST_SHIFT,
+ ZEND_AST_LIST,
+ ZEND_AST_ARRAY,
+ ZEND_AST_ENCAPS_LIST,
+ ZEND_AST_EXPR_LIST,
+ ZEND_AST_STMT_LIST,
+ ZEND_AST_IF,
+ ZEND_AST_SWITCH_LIST,
+ ZEND_AST_CATCH_LIST,
+ ZEND_AST_PARAM_LIST,
+ ZEND_AST_CLOSURE_USES,
+ ZEND_AST_PROP_DECL,
+ ZEND_AST_CONST_DECL,
+ ZEND_AST_CLASS_CONST_DECL,
+ ZEND_AST_NAME_LIST,
+ ZEND_AST_TRAIT_ADAPTATIONS,
+ ZEND_AST_USE,
+
+ /* 0 child nodes */
+ ZEND_AST_MAGIC_CONST = 0 << ZEND_AST_NUM_CHILDREN_SHIFT,
+ ZEND_AST_TYPE,
+ /* 1 child node */
+ ZEND_AST_VAR = 1 << ZEND_AST_NUM_CHILDREN_SHIFT,
ZEND_AST_CONST,
- ZEND_AST_CLASS_CONST,
ZEND_AST_RESOLVE_CLASS_NAME,
-
- ZEND_AST_ASSIGN,
- ZEND_AST_ASSIGN_REF,
- ZEND_AST_ASSIGN_OP,
- ZEND_AST_LIST,
-
+ ZEND_AST_UNPACK,
ZEND_AST_UNARY_PLUS,
ZEND_AST_UNARY_MINUS,
ZEND_AST_CAST,
@@ -57,75 +75,75 @@ enum _zend_ast_kind {
ZEND_AST_ISSET,
ZEND_AST_SILENCE,
ZEND_AST_SHELL_EXEC,
+ ZEND_AST_CLONE,
+ ZEND_AST_EXIT,
+ ZEND_AST_PRINT,
+ ZEND_AST_INCLUDE_OR_EVAL,
+ ZEND_AST_UNARY_OP,
+ ZEND_AST_PRE_INC,
+ ZEND_AST_PRE_DEC,
+ ZEND_AST_POST_INC,
+ ZEND_AST_POST_DEC,
+ ZEND_AST_GLOBAL,
+ ZEND_AST_UNSET,
+ ZEND_AST_RETURN,
+ ZEND_AST_LABEL,
+ ZEND_AST_REF,
+ ZEND_AST_HALT_COMPILER,
+ ZEND_AST_ECHO,
+ ZEND_AST_THROW,
+ ZEND_AST_GOTO,
+ ZEND_AST_BREAK,
+ ZEND_AST_CONTINUE,
+
+ /* 2 child nodes */
+ ZEND_AST_DIM = 2 << ZEND_AST_NUM_CHILDREN_SHIFT,
+ ZEND_AST_PROP,
+ ZEND_AST_STATIC_PROP,
+ ZEND_AST_CALL,
+ ZEND_AST_CLASS_CONST,
+ ZEND_AST_ASSIGN,
+ ZEND_AST_ASSIGN_REF,
+ ZEND_AST_ASSIGN_OP,
ZEND_AST_BINARY_OP,
ZEND_AST_GREATER,
ZEND_AST_GREATER_EQUAL,
ZEND_AST_AND,
ZEND_AST_OR,
-
- ZEND_AST_CONDITIONAL,
-
- ZEND_AST_ARRAY,
ZEND_AST_ARRAY_ELEM,
- ZEND_AST_ENCAPS_LIST,
- ZEND_AST_MAGIC_CONST,
-
- ZEND_AST_EXPR_LIST,
- ZEND_AST_STMT_LIST,
+ ZEND_AST_NEW,
+ ZEND_AST_INSTANCEOF,
+ ZEND_AST_YIELD,
- ZEND_AST_GLOBAL,
ZEND_AST_STATIC,
- ZEND_AST_UNSET,
- ZEND_AST_RETURN,
- ZEND_AST_LABEL,
-
ZEND_AST_WHILE,
ZEND_AST_DO_WHILE,
- ZEND_AST_FOR,
- ZEND_AST_FOREACH,
- ZEND_AST_REF,
- ZEND_AST_IF,
ZEND_AST_IF_ELEM,
-
ZEND_AST_SWITCH,
- ZEND_AST_SWITCH_LIST,
ZEND_AST_SWITCH_CASE,
-
- ZEND_AST_TRY,
- ZEND_AST_CATCH_LIST,
- ZEND_AST_CATCH,
ZEND_AST_DECLARE,
-
- ZEND_AST_PARAM_LIST,
- ZEND_AST_PARAM,
- ZEND_AST_TYPE,
-
- ZEND_AST_FUNC_DECL,
- ZEND_AST_CLOSURE,
- ZEND_AST_CLOSURE_USES,
- ZEND_AST_METHOD,
-
- ZEND_AST_PROP_DECL,
ZEND_AST_PROP_ELEM,
-
- ZEND_AST_CONST_DECL,
- ZEND_AST_CLASS_CONST_DECL,
ZEND_AST_CONST_ELEM,
-
ZEND_AST_USE_TRAIT,
- ZEND_AST_NAME_LIST,
- ZEND_AST_TRAIT_ADAPTATIONS,
ZEND_AST_TRAIT_PRECEDENCE,
- ZEND_AST_TRAIT_ALIAS,
ZEND_AST_METHOD_REFERENCE,
+ ZEND_AST_NAMESPACE,
+ ZEND_AST_USE_ELEM,
+ ZEND_AST_TRAIT_ALIAS,
- ZEND_AST_CLASS,
+ /* 3 child nodes */
+ ZEND_AST_METHOD_CALL = 3 << ZEND_AST_NUM_CHILDREN_SHIFT,
+ ZEND_AST_STATIC_CALL,
+ ZEND_AST_CONDITIONAL,
- ZEND_AST_USE,
- ZEND_AST_USE_ELEM,
- ZEND_AST_NAMESPACE,
- ZEND_AST_HALT_COMPILER,
+ ZEND_AST_TRY,
+ ZEND_AST_CATCH,
+ ZEND_AST_PARAM,
+
+ /* 4 child nodes */
+ ZEND_AST_FOR = 4 << ZEND_AST_NUM_CHILDREN_SHIFT,
+ ZEND_AST_FOREACH,
};
typedef unsigned short zend_ast_kind;
@@ -135,10 +153,18 @@ struct _zend_ast {
zend_ast_kind kind; /* Type of the node (either opcode or ZEND_AST_* constant) */
zend_ast_attr attr; /* Additional attribute, use depending on node type */
zend_uint lineno; /* Line number */
- zend_uint children; /* Number of children */
zend_ast *child[1]; /* Array of children (using struct hack) */
};
+/* Same as zend_ast, but with children count, which is updated dynamically */
+typedef struct _zend_ast_list {
+ zend_ast_kind kind;
+ zend_ast_attr attr;
+ zend_uint lineno;
+ zend_uint children;
+ zend_ast *child[1];
+} zend_ast_list;
+
typedef struct _zend_ast_zval {
zend_ast_kind kind;
zend_ast_attr attr;
@@ -173,9 +199,6 @@ ZEND_API zend_ast *zend_ast_create_decl(
ZEND_API zend_ast *zend_ast_create_dynamic(zend_ast_kind kind);
ZEND_API zend_ast *zend_ast_dynamic_add(zend_ast *ast, zend_ast *op);
-ZEND_API void zend_ast_dynamic_shrink(zend_ast **ast);
-
-ZEND_API int zend_ast_is_ct_constant(zend_ast *ast);
ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *scope TSRMLS_DC);
@@ -183,6 +206,22 @@ ZEND_API zend_ast *zend_ast_copy(zend_ast *ast);
ZEND_API void zend_ast_destroy(zend_ast *ast);
ZEND_API void zend_ast_destroy_and_free(zend_ast *ast);
+typedef void (*zend_ast_apply_func)(zend_ast **ast_ptr TSRMLS_DC);
+ZEND_API void zend_ast_apply(zend_ast *ast, zend_ast_apply_func fn TSRMLS_DC);
+
+static inline zend_bool zend_ast_is_list(zend_ast *ast) {
+ return (ast->kind >> ZEND_AST_IS_LIST_SHIFT) & 1;
+}
+static inline zend_ast_list *zend_ast_get_list(zend_ast *ast) {
+ ZEND_ASSERT(zend_ast_is_list(ast));
+ return (zend_ast_list *) ast;
+}
+
+/* Only for non-lists! */
+static inline zend_uint zend_ast_get_num_children(zend_ast *ast) {
+ return ast->kind >> ZEND_AST_NUM_CHILDREN_SHIFT;
+}
+
static inline zval *zend_ast_get_zval(zend_ast *ast) {
return &((zend_ast_zval *) ast)->val;
}