@@ -1185,8 +1185,11 @@ class FuncInfo {
1185
1185
public int $ numRequiredArgs ;
1186
1186
public ?string $ cond ;
1187
1187
public bool $ isUndocumentable ;
1188
+ /** @var AttributeInfo[] */
1189
+ public array $ attributes ;
1188
1190
1189
1191
/**
1192
+ * @param AttributeInfo[] $attributes
1190
1193
* @param ArgInfo[] $args
1191
1194
*/
1192
1195
public function __construct (
@@ -1202,7 +1205,8 @@ public function __construct(
1202
1205
ReturnInfo $ return ,
1203
1206
int $ numRequiredArgs ,
1204
1207
?string $ cond ,
1205
- bool $ isUndocumentable
1208
+ bool $ isUndocumentable ,
1209
+ array $ attributes
1206
1210
) {
1207
1211
$ this ->name = $ name ;
1208
1212
$ this ->classFlags = $ classFlags ;
@@ -1217,6 +1221,7 @@ public function __construct(
1217
1221
$ this ->numRequiredArgs = $ numRequiredArgs ;
1218
1222
$ this ->cond = $ cond ;
1219
1223
$ this ->isUndocumentable = $ isUndocumentable ;
1224
+ $ this ->attributes = $ attributes ;
1220
1225
}
1221
1226
1222
1227
public function isMethod (): bool
@@ -1412,6 +1417,7 @@ public function getOptimizerInfo(): ?string {
1412
1417
}
1413
1418
1414
1419
public function discardInfoForOldPhpVersions (): void {
1420
+ $ this ->attributes = [];
1415
1421
$ this ->return ->type = null ;
1416
1422
foreach ($ this ->args as $ arg ) {
1417
1423
$ arg ->type = null ;
@@ -3221,17 +3227,24 @@ function parseFunctionLike(
3221
3227
}
3222
3228
}
3223
3229
3230
+ $ attributes = [];
3231
+ foreach ($ func ->attrGroups as $ attrGroup ) {
3232
+ foreach ($ attrGroup ->attrs as $ attr ) {
3233
+ $ attributes [] = new AttributeInfo ($ attr ->name ->toString (), $ attr ->args );
3234
+ }
3235
+ }
3236
+
3224
3237
$ varNameSet = [];
3225
3238
$ args = [];
3226
3239
$ numRequiredArgs = 0 ;
3227
3240
$ foundVariadic = false ;
3228
3241
foreach ($ func ->getParams () as $ i => $ param ) {
3229
3242
$ varName = $ param ->var ->name ;
3230
3243
$ preferRef = !empty ($ paramMeta [$ varName ]['prefer-ref ' ]);
3231
- $ attributes = [];
3244
+ $ paramAttributes = [];
3232
3245
foreach ($ param ->attrGroups as $ attrGroup ) {
3233
3246
foreach ($ attrGroup ->attrs as $ attr ) {
3234
- $ attributes [] = new AttributeInfo ($ attr ->name ->toString (), $ attr ->args );
3247
+ $ paramAttributes [] = new AttributeInfo ($ attr ->name ->toString (), $ attr ->args );
3235
3248
}
3236
3249
}
3237
3250
unset($ paramMeta [$ varName ]);
@@ -3281,7 +3294,7 @@ function parseFunctionLike(
3281
3294
$ type ,
3282
3295
isset ($ docParamTypes [$ varName ]) ? Type::fromString ($ docParamTypes [$ varName ]) : null ,
3283
3296
$ param ->default ? $ prettyPrinter ->prettyPrintExpr ($ param ->default ) : null ,
3284
- $ attributes
3297
+ $ paramAttributes
3285
3298
);
3286
3299
if (!$ param ->default && !$ param ->variadic ) {
3287
3300
$ numRequiredArgs = $ i + 1 ;
@@ -3318,7 +3331,8 @@ function parseFunctionLike(
3318
3331
$ return ,
3319
3332
$ numRequiredArgs ,
3320
3333
$ cond ,
3321
- $ isUndocumentable
3334
+ $ isUndocumentable ,
3335
+ $ attributes
3322
3336
);
3323
3337
} catch (Exception $ e ) {
3324
3338
throw new Exception ($ name . "(): " .$ e ->getMessage ());
@@ -4040,13 +4054,17 @@ function generateAttributeInitialization(iterable $funcInfos, iterable $allConst
4040
4054
static function (FuncInfo $ funcInfo ) use ($ allConstInfos ) {
4041
4055
$ code = null ;
4042
4056
4043
- foreach ($ funcInfo ->args as $ index => $ arg ) {
4044
- if ($ funcInfo ->name instanceof MethodName) {
4045
- $ functionTable = "&class_entry->function_table " ;
4046
- } else {
4047
- $ functionTable = "CG(function_table) " ;
4048
- }
4057
+ if ($ funcInfo ->name instanceof MethodName) {
4058
+ $ functionTable = "&class_entry->function_table " ;
4059
+ } else {
4060
+ $ functionTable = "CG(function_table) " ;
4061
+ }
4062
+
4063
+ foreach ($ funcInfo ->attributes as $ attribute ) {
4064
+ $ code .= $ attribute ->generateCode ("zend_add_function_attribute(zend_hash_str_find_ptr( $ functionTable, \"" . $ funcInfo ->name ->getNameForAttributes () . "\", sizeof( \"" . $ funcInfo ->name ->getNameForAttributes () . "\") - 1) " , $ funcInfo ->name ->getMethodSynopsisFilename (), $ allConstInfos );
4065
+ }
4049
4066
4067
+ foreach ($ funcInfo ->args as $ index => $ arg ) {
4050
4068
foreach ($ arg ->attributes as $ attribute ) {
4051
4069
$ code .= $ attribute ->generateCode ("zend_add_parameter_attribute(zend_hash_str_find_ptr( $ functionTable, \"" . $ funcInfo ->name ->getNameForAttributes () . "\", sizeof( \"" . $ funcInfo ->name ->getNameForAttributes () . "\") - 1), $ index " , "{$ funcInfo ->name ->getMethodSynopsisFilename ()}_arg {$ index }" , $ allConstInfos );
4052
4070
}
0 commit comments