LCOV - code coverage report
Current view: top level - ext - lsp_abstraction.c (source / functions) Coverage Total Hit
Test: Extension code coverage Lines: 9.8 % 132 13
Test Date: 2026-07-13 00:58:38 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :   +----------------------------------------------------------------------+
       3              :   | LSParrot PHP LSP Extension                                           |
       4              :   +----------------------------------------------------------------------+
       5              :   | Copyright (c) LSParrot GitHub Organization                           |
       6              :   +----------------------------------------------------------------------+
       7              :   | This source file is subject to the 0BSD license that is              |
       8              :   | bundled with this package in the file LICENSE.                       |
       9              :   +----------------------------------------------------------------------+
      10              :   | Author: Go Kudo <zeriyoshi@gmail.com>                                |
      11              :   +----------------------------------------------------------------------+
      12              : */
      13              : 
      14              : #ifdef HAVE_CONFIG_H
      15              : # include <config.h>
      16              : #endif
      17              : 
      18              : #include <php.h>
      19              : 
      20              : #include "lsp_internal.h"
      21              : 
      22              : #if PHP_VERSION_ID >= 80500
      23           44 : static inline const char *lsp_latest_ast_kind_name(zend_ast_kind kind)
      24              : {
      25           44 :         switch (kind) {
      26            8 :                 case ZEND_AST_ZVAL: return "ZVAL";
      27            0 :                 case ZEND_AST_CONSTANT: return "CONSTANT";
      28            0 :                 case ZEND_AST_OP_ARRAY: return "OP_ARRAY";
      29            0 :                 case ZEND_AST_ZNODE: return "ZNODE";
      30            8 :                 case ZEND_AST_FUNC_DECL: return "FUNC_DECL";
      31            0 :                 case ZEND_AST_CLOSURE: return "CLOSURE";
      32            0 :                 case ZEND_AST_METHOD: return "METHOD";
      33            0 :                 case ZEND_AST_CLASS: return "CLASS";
      34            0 :                 case ZEND_AST_ARROW_FUNC: return "ARROW_FUNC";
      35            0 :                 case ZEND_AST_PROPERTY_HOOK: return "PROPERTY_HOOK";
      36            0 :                 case ZEND_AST_ARG_LIST: return "ARG_LIST";
      37            0 :                 case ZEND_AST_ARRAY: return "ARRAY";
      38            0 :                 case ZEND_AST_ENCAPS_LIST: return "ENCAPS_LIST";
      39            0 :                 case ZEND_AST_EXPR_LIST: return "EXPR_LIST";
      40           16 :                 case ZEND_AST_STMT_LIST: return "STMT_LIST";
      41            0 :                 case ZEND_AST_IF: return "IF";
      42            0 :                 case ZEND_AST_SWITCH_LIST: return "SWITCH_LIST";
      43            0 :                 case ZEND_AST_CATCH_LIST: return "CATCH_LIST";
      44            8 :                 case ZEND_AST_PARAM_LIST: return "PARAM_LIST";
      45            0 :                 case ZEND_AST_CLOSURE_USES: return "CLOSURE_USES";
      46            0 :                 case ZEND_AST_PROP_DECL: return "PROP_DECL";
      47            0 :                 case ZEND_AST_CONST_DECL: return "CONST_DECL";
      48            0 :                 case ZEND_AST_CLASS_CONST_DECL: return "CLASS_CONST_DECL";
      49            0 :                 case ZEND_AST_NAME_LIST: return "NAME_LIST";
      50            0 :                 case ZEND_AST_TRAIT_ADAPTATIONS: return "TRAIT_ADAPTATIONS";
      51            0 :                 case ZEND_AST_USE: return "USE";
      52            0 :                 case ZEND_AST_TYPE_UNION: return "TYPE_UNION";
      53            0 :                 case ZEND_AST_TYPE_INTERSECTION: return "TYPE_INTERSECTION";
      54            0 :                 case ZEND_AST_ATTRIBUTE_LIST: return "ATTRIBUTE_LIST";
      55            0 :                 case ZEND_AST_ATTRIBUTE_GROUP: return "ATTRIBUTE_GROUP";
      56            0 :                 case ZEND_AST_MATCH_ARM_LIST: return "MATCH_ARM_LIST";
      57            0 :                 case ZEND_AST_MODIFIER_LIST: return "MODIFIER_LIST";
      58            0 :                 case ZEND_AST_MAGIC_CONST: return "MAGIC_CONST";
      59            0 :                 case ZEND_AST_TYPE: return "TYPE";
      60            0 :                 case ZEND_AST_CONSTANT_CLASS: return "CONSTANT_CLASS";
      61            0 :                 case ZEND_AST_CALLABLE_CONVERT: return "CALLABLE_CONVERT";
      62            0 :                 case ZEND_AST_VAR: return "VAR";
      63            0 :                 case ZEND_AST_CONST: return "CONST";
      64            0 :                 case ZEND_AST_UNPACK: return "UNPACK";
      65            0 :                 case ZEND_AST_UNARY_PLUS: return "UNARY_PLUS";
      66            0 :                 case ZEND_AST_UNARY_MINUS: return "UNARY_MINUS";
      67            0 :                 case ZEND_AST_CAST: return "CAST";
      68            0 :                 case ZEND_AST_CAST_VOID: return "CAST_VOID";
      69            0 :                 case ZEND_AST_EMPTY: return "EMPTY";
      70            0 :                 case ZEND_AST_ISSET: return "ISSET";
      71            0 :                 case ZEND_AST_SILENCE: return "SILENCE";
      72            0 :                 case ZEND_AST_SHELL_EXEC: return "SHELL_EXEC";
      73            0 :                 case ZEND_AST_PRINT: return "PRINT";
      74            0 :                 case ZEND_AST_INCLUDE_OR_EVAL: return "INCLUDE_OR_EVAL";
      75            0 :                 case ZEND_AST_UNARY_OP: return "UNARY_OP";
      76            0 :                 case ZEND_AST_PRE_INC: return "PRE_INC";
      77            0 :                 case ZEND_AST_PRE_DEC: return "PRE_DEC";
      78            0 :                 case ZEND_AST_POST_INC: return "POST_INC";
      79            0 :                 case ZEND_AST_POST_DEC: return "POST_DEC";
      80            0 :                 case ZEND_AST_YIELD_FROM: return "YIELD_FROM";
      81            0 :                 case ZEND_AST_CLASS_NAME: return "CLASS_NAME";
      82            0 :                 case ZEND_AST_GLOBAL: return "GLOBAL";
      83            0 :                 case ZEND_AST_UNSET: return "UNSET";
      84            4 :                 case ZEND_AST_RETURN: return "RETURN";
      85            0 :                 case ZEND_AST_LABEL: return "LABEL";
      86            0 :                 case ZEND_AST_REF: return "REF";
      87            0 :                 case ZEND_AST_HALT_COMPILER: return "HALT_COMPILER";
      88            0 :                 case ZEND_AST_ECHO: return "ECHO";
      89            0 :                 case ZEND_AST_THROW: return "THROW";
      90            0 :                 case ZEND_AST_GOTO: return "GOTO";
      91            0 :                 case ZEND_AST_BREAK: return "BREAK";
      92            0 :                 case ZEND_AST_CONTINUE: return "CONTINUE";
      93            0 :                 case ZEND_AST_PROPERTY_HOOK_SHORT_BODY: return "PROPERTY_HOOK_SHORT_BODY";
      94            0 :                 case ZEND_AST_DIM: return "DIM";
      95            0 :                 case ZEND_AST_PROP: return "PROP";
      96            0 :                 case ZEND_AST_NULLSAFE_PROP: return "NULLSAFE_PROP";
      97            0 :                 case ZEND_AST_STATIC_PROP: return "STATIC_PROP";
      98            0 :                 case ZEND_AST_CALL: return "CALL";
      99            0 :                 case ZEND_AST_CLASS_CONST: return "CLASS_CONST";
     100            0 :                 case ZEND_AST_ASSIGN: return "ASSIGN";
     101            0 :                 case ZEND_AST_ASSIGN_REF: return "ASSIGN_REF";
     102            0 :                 case ZEND_AST_ASSIGN_OP: return "ASSIGN_OP";
     103            0 :                 case ZEND_AST_BINARY_OP: return "BINARY_OP";
     104            0 :                 case ZEND_AST_GREATER: return "GREATER";
     105            0 :                 case ZEND_AST_GREATER_EQUAL: return "GREATER_EQUAL";
     106            0 :                 case ZEND_AST_AND: return "AND";
     107            0 :                 case ZEND_AST_OR: return "OR";
     108            0 :                 case ZEND_AST_ARRAY_ELEM: return "ARRAY_ELEM";
     109            0 :                 case ZEND_AST_NEW: return "NEW";
     110            0 :                 case ZEND_AST_INSTANCEOF: return "INSTANCEOF";
     111            0 :                 case ZEND_AST_YIELD: return "YIELD";
     112            0 :                 case ZEND_AST_COALESCE: return "COALESCE";
     113            0 :                 case ZEND_AST_ASSIGN_COALESCE: return "ASSIGN_COALESCE";
     114            0 :                 case ZEND_AST_STATIC: return "STATIC";
     115            0 :                 case ZEND_AST_WHILE: return "WHILE";
     116            0 :                 case ZEND_AST_DO_WHILE: return "DO_WHILE";
     117            0 :                 case ZEND_AST_IF_ELEM: return "IF_ELEM";
     118            0 :                 case ZEND_AST_SWITCH: return "SWITCH";
     119            0 :                 case ZEND_AST_SWITCH_CASE: return "SWITCH_CASE";
     120            0 :                 case ZEND_AST_DECLARE: return "DECLARE";
     121            0 :                 case ZEND_AST_USE_TRAIT: return "USE_TRAIT";
     122            0 :                 case ZEND_AST_TRAIT_PRECEDENCE: return "TRAIT_PRECEDENCE";
     123            0 :                 case ZEND_AST_METHOD_REFERENCE: return "METHOD_REFERENCE";
     124            0 :                 case ZEND_AST_NAMESPACE: return "NAMESPACE";
     125            0 :                 case ZEND_AST_USE_ELEM: return "USE_ELEM";
     126            0 :                 case ZEND_AST_TRAIT_ALIAS: return "TRAIT_ALIAS";
     127            0 :                 case ZEND_AST_GROUP_USE: return "GROUP_USE";
     128            0 :                 case ZEND_AST_ATTRIBUTE: return "ATTRIBUTE";
     129            0 :                 case ZEND_AST_MATCH: return "MATCH";
     130            0 :                 case ZEND_AST_MATCH_ARM: return "MATCH_ARM";
     131            0 :                 case ZEND_AST_NAMED_ARG: return "NAMED_ARG";
     132            0 :                 case ZEND_AST_PARENT_PROPERTY_HOOK_CALL: return "PARENT_PROPERTY_HOOK_CALL";
     133            0 :                 case ZEND_AST_PIPE: return "PIPE";
     134            0 :                 case ZEND_AST_METHOD_CALL: return "METHOD_CALL";
     135            0 :                 case ZEND_AST_NULLSAFE_METHOD_CALL: return "NULLSAFE_METHOD_CALL";
     136            0 :                 case ZEND_AST_STATIC_CALL: return "STATIC_CALL";
     137            0 :                 case ZEND_AST_CONDITIONAL: return "CONDITIONAL";
     138            0 :                 case ZEND_AST_TRY: return "TRY";
     139            0 :                 case ZEND_AST_CATCH: return "CATCH";
     140            0 :                 case ZEND_AST_PROP_GROUP: return "PROP_GROUP";
     141            0 :                 case ZEND_AST_CONST_ELEM: return "CONST_ELEM";
     142            0 :                 case ZEND_AST_CLASS_CONST_GROUP: return "CLASS_CONST_GROUP";
     143            0 :                 case ZEND_AST_FOR: return "FOR";
     144            0 :                 case ZEND_AST_FOREACH: return "FOREACH";
     145            0 :                 case ZEND_AST_ENUM_CASE: return "ENUM_CASE";
     146            0 :                 case ZEND_AST_PROP_ELEM: return "PROP_ELEM";
     147            0 :                 case ZEND_AST_CONST_ENUM_INIT: return "CONST_ENUM_INIT";
     148            0 :                 case ZEND_AST_PARAM: return "PARAM";
     149            0 :                 default: return "UNKNOWN";
     150              :         }
     151              : }
     152              : 
     153           20 : static inline bool lsp_latest_ast_is_decl(zend_ast *ast)
     154              : {
     155           20 :         return zend_ast_is_decl(ast);
     156              : }
     157              : 
     158         3084 : static inline bool lsp_latest_ast_is_opaque_node(zend_ast_kind kind)
     159              : {
     160         3084 :         return kind == ZEND_AST_OP_ARRAY || kind == ZEND_AST_ZNODE;
     161              : }
     162              : 
     163       455041 : static inline bool lsp_latest_string_equals_cstr(zend_string *value, const char *literal, size_t length)
     164              : {
     165       455041 :         return zend_string_equals_cstr(value, literal, length);
     166              : }
     167              : 
     168              : php_ver_abstract_t php_ver_abstract = {
     169              :         lsp_latest_ast_kind_name,
     170              :         lsp_latest_ast_is_decl,
     171              :         lsp_latest_ast_is_opaque_node,
     172              :         lsp_latest_string_equals_cstr
     173              : };
     174              : #elif PHP_VERSION_ID >= 80400 && PHP_VERSION_ID < 80500
     175              : # include "lsp_php84_abstraction.h"
     176              : 
     177              : php_ver_abstract_t php_ver_abstract = {
     178              :         lsp_php84_ast_kind_name,
     179              :         lsp_php84_ast_is_decl,
     180              :         lsp_php84_ast_is_opaque_node,
     181              :         lsp_php84_string_equals_cstr
     182              : };
     183              : #elif PHP_VERSION_ID >= 80300 && PHP_VERSION_ID < 80400
     184              : # include "lsp_php83_abstraction.h"
     185              : 
     186              : php_ver_abstract_t php_ver_abstract = {
     187              :         lsp_php83_ast_kind_name,
     188              :         lsp_php83_ast_is_decl,
     189              :         lsp_php83_ast_is_opaque_node,
     190              :         lsp_php83_string_equals_cstr
     191              : };
     192              : #elif PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80300
     193              : # include "lsp_php82_abstraction.h"
     194              : 
     195              : php_ver_abstract_t php_ver_abstract = {
     196              :         lsp_php82_ast_kind_name,
     197              :         lsp_php82_ast_is_decl,
     198              :         lsp_php82_ast_is_opaque_node,
     199              :         lsp_php82_string_equals_cstr
     200              : };
     201              : #elif PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80200
     202              : # include "lsp_php81_abstraction.h"
     203              : 
     204              : php_ver_abstract_t php_ver_abstract = {
     205              :         lsp_php81_ast_kind_name,
     206              :         lsp_php81_ast_is_decl,
     207              :         lsp_php81_ast_is_opaque_node,
     208              :         lsp_php81_string_equals_cstr
     209              : };
     210              : #elif PHP_VERSION_ID < 80100
     211              : # error "LSParrot requires PHP 8.1 or later"
     212              : #endif
        

Generated by: LCOV version 2.0-1