1313use PHPUnit \Framework \Attributes \CoversNothing ;
1414use PHPUnit \Framework \Attributes \DataProvider ;
1515
16- /**
17- * Checks the attributes of `resources/grammar/attributes.pp3` in every
18- * syntax and in every position: a header is compared as the list of its
19- * declarations printed as S-expressions, where an attribute is printed in
20- * its own syntax, `[[gnu::aligned(8)]]`, and the attributes inside a
21- * declarator wrap the type, `(attr _Nonnull (ptr int))`.
22- */
2316#[CoversNothing]
2417final class AttributesTest extends TestCase
2518{
@@ -28,7 +21,6 @@ final class AttributesTest extends TestCase
2821 */
2922 public static function syntaxesDataProvider (): iterable
3023 {
31- // C23
3224 yield 'standard attribute ' => ['[[deprecated]]; ' , '(attributes [[deprecated]]) ' ];
3325 yield 'prefixed attribute ' => ['[[gnu::packed]]; ' , '(attributes [[gnu::packed]]) ' ];
3426 yield 'several attributes ' => ['[[a, b::c]]; ' , '(attributes [[a]] [[b::c]]) ' ];
@@ -44,7 +36,6 @@ public static function syntaxesDataProvider(): iterable
4436 yield 'keyword as a prefix ' => ['[[int::x]]; ' , '(attributes [[int::x]]) ' ];
4537 yield 'reserved keyword as a name ' => ['[[fallthrough, default]]; ' , '(attributes [[fallthrough]] [[default]]) ' ];
4638
47- // GCC
4839 yield 'attribute of GCC ' => ['__attribute__((packed)); ' , '(attributes __attribute__((packed))) ' ];
4940 yield 'short spelling of GCC ' => ['__attribute((packed)); ' , '(attributes __attribute__((packed))) ' ];
5041 yield 'several attributes of GCC ' => [
@@ -62,15 +53,13 @@ public static function syntaxesDataProvider(): iterable
6253 '(attributes __attribute__((const)) __attribute__((__const__))) ' ,
6354 ];
6455
65- // MSVC
6656 yield '__declspec ' => ['__declspec(dllimport); ' , '(attributes __declspec(dllimport)) ' ];
6757 yield '__declspec of several attributes ' => [
6858 '__declspec(dllimport align(16) noreturn); ' ,
6959 '(attributes __declspec(dllimport) __declspec(align(16)) __declspec(noreturn)) ' ,
7060 ];
7161 yield 'empty __declspec ' => ['__declspec(); ' , '(attributes ) ' ];
7262
73- // Keywords allowed among the specifiers
7463 foreach ([
7564 '__cdecl ' , '__stdcall ' , '__fastcall ' , '__thiscall ' , '__vectorcall ' , '__ptr32 ' , '__ptr64 ' , '__w64 ' ,
7665 '__forceinline ' ,
@@ -151,7 +140,6 @@ public function testArgumentIsAnExpressionOrTheTokens(): void
151140 */
152141 public static function positionsDataProvider (): iterable
153142 {
154- // Among the specifiers
155143 yield 'before the specifiers ' => ['[[a]] int x; ' , ['(variable [[a]] int x) ' ]];
156144 yield 'after the specifiers ' => ['int [[a]] x; ' , ['(variable [[a]] int x) ' ]];
157145 yield 'among the specifiers ' => [
@@ -197,7 +185,6 @@ public static function positionsDataProvider(): iterable
197185 '(variable int x = (sizeof {[[a]] int})) ' ,
198186 ]];
199187
200- // A declarator
201188 yield 'after the name ' => ['int x [[a]]; ' , ['(variable int x [[a]]) ' ]];
202189 yield 'after the name and before an array ' => ['int x [[a]] [3]; ' , ['(variable (array int 3) x [[a]]) ' ]];
203190 yield 'after the name of a function ' => ['int f [[a]] (void); ' , ['(function (fn int (void)) f [[a]]) ' ]];
@@ -230,7 +217,6 @@ public static function positionsDataProvider(): iterable
230217 '(variable [[a]] int x [[b]] __attribute__((c)) = 1) ' ,
231218 ]];
232219
233- // Inside a declarator
234220 yield 'after a pointer ' => ['int * [[a]] p; ' , ['(variable (ptr int [[a]]) p) ' ]];
235221 yield 'after a pointer and its qualifiers ' => ['int * [[a]] const _Nonnull p; ' , [
236222 '(variable [const (ptr int [[a]] _Nonnull)] p) ' ,
@@ -248,8 +234,6 @@ public static function positionsDataProvider(): iterable
248234 'int (*f [[a]] (void) [[b]])(int) [[c]]; ' ,
249235 ['(function (fn (ptr (fn int (int) [[c]])) (void) [[b]]) f [[a]]) ' ],
250236 ];
251- // A function wrapped into attributes is not told from an object, as
252- // a function of a typedef name is not
253237 yield 'at the start of a parenthesized function declarator ' => ['void (__stdcall f)(int); ' , [
254238 '(variable (attr __stdcall (fn void (int))) f) ' ,
255239 ]];
@@ -271,7 +255,6 @@ public static function positionsDataProvider(): iterable
271255 ['(typedef typedef (ptr (attr __cdecl (fn void (int)))) F) ' ],
272256 ];
273257
274- // Parameters
275258 yield 'parameter ' => ['void f([[a]] int x __attribute__((unused)), int y[2] [[b]]); ' , [
276259 '(function (fn void ([[a]] int x __attribute__((unused)), (array int 2 [[b]]) y)) f) ' ,
277260 ]];
@@ -299,7 +282,6 @@ public static function positionsDataProvider(): iterable
299282 '(variable int x = (sizeof (ptr (attr __cdecl (fn void (void)))))) ' ,
300283 ]];
301284
302- // Tags
303285 yield 'after struct ' => ['struct [[a]] S; ' , ['(tag struct [[a]] S) ' ]];
304286 yield 'after struct and before the body ' => ['struct __attribute__((packed)) { int a; } s; ' , [
305287 '(variable struct __attribute__((packed)) _ { int a } s) ' ,
@@ -320,7 +302,6 @@ public static function positionsDataProvider(): iterable
320302 '(tag enum E { A [[deprecated]]=1, B __attribute__((deprecated)), C }) ' ,
321303 ]];
322304
323- // Members
324305 yield 'members ' => ['struct S { [[a]] int x [[b]], y __attribute__((c)); }; ' , [
325306 '(tag struct S { [[a]] int x [[b]]; [[a]] int y __attribute__((c)) }) ' ,
326307 ]];
@@ -398,10 +379,6 @@ public static function offsetsDataProvider(): iterable
398379 }
399380
400381 /**
401- * Every attribute starts at its prefix or name, and a list of the
402- * attributes at its first attribute or, empty in an attribute
403- * declaration, where the declaration does.
404- *
405382 * @param list<non-empty-string> $expected
406383 */
407384 #[DataProvider('offsetsDataProvider ' )]
@@ -431,14 +408,11 @@ public static function invalidAttributesDataProvider(): iterable
431408 yield 'assembler label of a member ' => ['struct S { int a __asm__("a"); }; ' , 17 , '__asm__ ' ];
432409 yield 'two assembler labels ' => ['int f(void) __asm__("a") __asm__("b"); ' , 25 , '__asm__ ' ];
433410 yield 'attributes after struct alone ' => ['struct [[a]]; ' , 12 , '; ' ];
434- // GCC allows its attributes in a parenthesized declarator only at
435- // the start of it
436411 yield 'attribute of GCC after an array in a parenthesized declarator ' => [
437412 'int (*a[3] __attribute__((x))); ' ,
438413 11 ,
439414 '__attribute__ ' ,
440415 ];
441- // Positions C23 has no attributes in
442416 yield 'attribute in the brackets of an array ' => ['int a[[[x]] 3]; ' , 7 , '[ ' ];
443417 yield 'attribute after a parenthesized declarator ' => ['int (*f) [[x]] (int); ' , 15 , '( ' ];
444418 yield 'attribute in a subscript ' => ['int x = y[[z]]; ' , 9 , '[[ ' ];
0 commit comments