]> granicus.if.org Git - php/commitdiff
Support specifying linkage for generate-function-entries
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 2 Oct 2020 15:21:16 +0000 (17:21 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 2 Oct 2020 15:21:16 +0000 (17:21 +0200)
The linkage can be specified as the argument to the
@generate-function-entries tag. Test this on zend_test.

build/gen_stub.php
ext/zend_test/test.c
ext/zend_test/test.stub.php
ext/zend_test/test_arginfo.h

index e2c6bb2eb225b31b42eaee5119ea883a987434a7..56106dec9028493324b610a559c1b3bda2e9c7d0 100755 (executable)
@@ -624,6 +624,8 @@ class FileInfo {
     public $classInfos = [];
     /** @var bool */
     public $generateFunctionEntries = false;
+    /** @var string */
+    public $declarationPrefix = "";
 
     /**
      * @return iterable<FuncInfo>
@@ -941,8 +943,12 @@ function parseStubFile(string $code): FileInfo {
     $fileInfo = new FileInfo;
     $fileDocComment = getFileDocComment($stmts);
     if ($fileDocComment) {
-        if (strpos($fileDocComment->getText(), '@generate-function-entries') !== false) {
-            $fileInfo->generateFunctionEntries = true;
+        $fileTags = parseDocComment($fileDocComment);
+        foreach ($fileTags as $tag) {
+            if ($tag->name === 'generate-function-entries') {
+                $fileInfo->generateFunctionEntries = true;
+                $fileInfo->declarationPrefix = $tag->value ? $tag->value . " " : "";
+            }
         }
     }
 
@@ -1110,15 +1116,14 @@ function generateArgInfoCode(FileInfo $fileInfo, string $stubHash): string {
         $generatedFunctionDeclarations = [];
         $code .= generateCodeWithConditions(
             $fileInfo->getAllFuncInfos(), "",
-            function (FuncInfo $funcInfo) use(&$generatedFunctionDeclarations) {
+            function (FuncInfo $funcInfo) use($fileInfo, &$generatedFunctionDeclarations) {
                 $key = $funcInfo->getDeclarationKey();
                 if (isset($generatedFunctionDeclarations[$key])) {
                     return null;
                 }
 
                 $generatedFunctionDeclarations[$key] = true;
-
-                return $funcInfo->getDeclaration();
+                return $fileInfo->declarationPrefix . $funcInfo->getDeclaration();
             }
         );
 
index 92b8e4cf6a8158b17348316b9871a527999b6644..13781e32be75f85db15ee65b2fe4bc402fd59abb 100644 (file)
@@ -51,7 +51,7 @@ static zend_class_entry *zend_test_trait;
 static zend_class_entry *zend_test_attribute;
 static zend_object_handlers zend_test_class_handlers;
 
-ZEND_FUNCTION(zend_test_func)
+static ZEND_FUNCTION(zend_test_func)
 {
        RETVAL_STR_COPY(EX(func)->common.function_name);
 
@@ -62,23 +62,23 @@ ZEND_FUNCTION(zend_test_func)
        EX(func) = NULL;
 }
 
-ZEND_FUNCTION(zend_test_array_return)
+static ZEND_FUNCTION(zend_test_array_return)
 {
        ZEND_PARSE_PARAMETERS_NONE();
 }
 
-ZEND_FUNCTION(zend_test_nullable_array_return)
+static ZEND_FUNCTION(zend_test_nullable_array_return)
 {
        ZEND_PARSE_PARAMETERS_NONE();
 }
 
-ZEND_FUNCTION(zend_test_void_return)
+static ZEND_FUNCTION(zend_test_void_return)
 {
        /* dummy */
        ZEND_PARSE_PARAMETERS_NONE();
 }
 
-ZEND_FUNCTION(zend_test_deprecated)
+static ZEND_FUNCTION(zend_test_deprecated)
 {
        zval *arg1;
 
@@ -88,7 +88,7 @@ ZEND_FUNCTION(zend_test_deprecated)
 /* Create a string without terminating null byte. Must be terminated with
  * zend_terminate_string() before destruction, otherwise a warning is issued
  * in debug builds. */
-ZEND_FUNCTION(zend_create_unterminated_string)
+static ZEND_FUNCTION(zend_create_unterminated_string)
 {
        zend_string *str, *res;
 
@@ -104,7 +104,7 @@ ZEND_FUNCTION(zend_create_unterminated_string)
 }
 
 /* Enforce terminate null byte on string. This avoids a warning in debug builds. */
-ZEND_FUNCTION(zend_terminate_string)
+static ZEND_FUNCTION(zend_terminate_string)
 {
        zend_string *str;
 
@@ -116,7 +116,7 @@ ZEND_FUNCTION(zend_terminate_string)
 }
 
 /* {{{ Cause an intentional memory leak, for testing/debugging purposes */
-ZEND_FUNCTION(zend_leak_bytes)
+static ZEND_FUNCTION(zend_leak_bytes)
 {
        zend_long leakbytes = 3;
 
@@ -129,7 +129,7 @@ ZEND_FUNCTION(zend_leak_bytes)
 /* }}} */
 
 /* {{{ Leak a refcounted variable */
-ZEND_FUNCTION(zend_leak_variable)
+static ZEND_FUNCTION(zend_leak_variable)
 {
        zval *zv;
 
@@ -147,7 +147,7 @@ ZEND_FUNCTION(zend_leak_variable)
 /* }}} */
 
 /* Tests Z_PARAM_OBJ_OR_STR */
-ZEND_FUNCTION(zend_string_or_object)
+static ZEND_FUNCTION(zend_string_or_object)
 {
        zend_string *str;
        zend_object *object;
@@ -165,7 +165,7 @@ ZEND_FUNCTION(zend_string_or_object)
 /* }}} */
 
 /* Tests Z_PARAM_OBJ_OR_STR_OR_NULL */
-ZEND_FUNCTION(zend_string_or_object_or_null)
+static ZEND_FUNCTION(zend_string_or_object_or_null)
 {
        zend_string *str;
        zend_object *object;
@@ -185,7 +185,7 @@ ZEND_FUNCTION(zend_string_or_object_or_null)
 /* }}} */
 
 /* Tests Z_PARAM_OBJ_OF_CLASS_OR_STR */
-ZEND_FUNCTION(zend_string_or_stdclass)
+static ZEND_FUNCTION(zend_string_or_stdclass)
 {
        zend_string *str;
        zend_object *object;
@@ -203,7 +203,7 @@ ZEND_FUNCTION(zend_string_or_stdclass)
 /* }}} */
 
 /* Tests Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL */
-ZEND_FUNCTION(zend_string_or_stdclass_or_null)
+static ZEND_FUNCTION(zend_string_or_stdclass_or_null)
 {
        zend_string *str;
        zend_object *object;
@@ -223,7 +223,7 @@ ZEND_FUNCTION(zend_string_or_stdclass_or_null)
 /* }}} */
 
 /* TESTS Z_PARAM_ITERABLE and Z_PARAM_ITERABLE_OR_NULL */
-ZEND_FUNCTION(zend_iterable)
+static ZEND_FUNCTION(zend_iterable)
 {
        zval *arg1, *arg2;
 
@@ -292,18 +292,18 @@ void zend_attribute_validate_zendtestattribute(zend_attribute *attr, uint32_t ta
        }
 }
 
-ZEND_METHOD(_ZendTestClass, __toString) /* {{{ */ {
+static ZEND_METHOD(_ZendTestClass, __toString) /* {{{ */ {
        RETURN_EMPTY_STRING();
 }
 /* }}} */
 
 /* Internal function returns bool, we return int. */
-ZEND_METHOD(_ZendTestClass, is_object) /* {{{ */ {
+static ZEND_METHOD(_ZendTestClass, is_object) /* {{{ */ {
        RETURN_LONG(42);
 }
 /* }}} */
 
-ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ {
+static ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ {
        RETURN_TRUE;
 }
 /* }}} */
index 1dd0cfec4e5b179c1b2f9bce898133d5a11d4dd7..96e7b5692112839ab57a47c042209c0d61a8c581 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-/** @generate-function-entries */
+/** @generate-function-entries static */
 
 class _ZendTestClass {
     public static function is_object(): int {}
index bd8d477b42b165c3a9e439b7de4186f88964fc51..80e89c6fe05e34560acfb7d7baec6ce0cec5c792 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 87c9d71b08c538c28b4f9bad01d7a7a3a3b191ef */
+ * Stub hash: 1aa8e876ff9efb99c61603216eed267b0d225221 */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
 ZEND_END_ARG_INFO()
@@ -61,22 +61,22 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestTrait_testMethod,
 ZEND_END_ARG_INFO()
 
 
-ZEND_FUNCTION(zend_test_array_return);
-ZEND_FUNCTION(zend_test_nullable_array_return);
-ZEND_FUNCTION(zend_test_void_return);
-ZEND_FUNCTION(zend_test_deprecated);
-ZEND_FUNCTION(zend_create_unterminated_string);
-ZEND_FUNCTION(zend_terminate_string);
-ZEND_FUNCTION(zend_leak_variable);
-ZEND_FUNCTION(zend_leak_bytes);
-ZEND_FUNCTION(zend_string_or_object);
-ZEND_FUNCTION(zend_string_or_object_or_null);
-ZEND_FUNCTION(zend_string_or_stdclass);
-ZEND_FUNCTION(zend_string_or_stdclass_or_null);
-ZEND_FUNCTION(zend_iterable);
-ZEND_METHOD(_ZendTestClass, is_object);
-ZEND_METHOD(_ZendTestClass, __toString);
-ZEND_METHOD(_ZendTestTrait, testMethod);
+static ZEND_FUNCTION(zend_test_array_return);
+static ZEND_FUNCTION(zend_test_nullable_array_return);
+static ZEND_FUNCTION(zend_test_void_return);
+static ZEND_FUNCTION(zend_test_deprecated);
+static ZEND_FUNCTION(zend_create_unterminated_string);
+static ZEND_FUNCTION(zend_terminate_string);
+static ZEND_FUNCTION(zend_leak_variable);
+static ZEND_FUNCTION(zend_leak_bytes);
+static ZEND_FUNCTION(zend_string_or_object);
+static ZEND_FUNCTION(zend_string_or_object_or_null);
+static ZEND_FUNCTION(zend_string_or_stdclass);
+static ZEND_FUNCTION(zend_string_or_stdclass_or_null);
+static ZEND_FUNCTION(zend_iterable);
+static ZEND_METHOD(_ZendTestClass, is_object);
+static ZEND_METHOD(_ZendTestClass, __toString);
+static ZEND_METHOD(_ZendTestTrait, testMethod);
 
 
 static const zend_function_entry ext_functions[] = {