Commit b3c5fde
committed
Parse declaration attributes within #if...#endif blocks.
Introduce support for parsing declaration attributes that occur within
example:
#if hasAttribute(frozen)
@Frozen
#endif
public struct X { ... }
will apply to "frozen" attribute to the struct `X`, but only when the
compiler supports the "frozen" attribute.
Correctly determining whether a particular `#if` block contains
attributes to be associated with the following declaration vs.
starting a new declaration requires arbitrary lookahead. The parser
will ensure that at least one of the branches of the `#if` contains an
attribute, and that none of the branches contains something that does
not fit the attribute grammar, before committing to parsing the `#if`
clause as part of the declaration attributes. This lookahead does
occur at the top level (e.g., in the parsing of top-level declarations
and code), but should only need to scan past the first `#if` line to
the following token in the common case.
Unlike other `#if` when used to wrap statements or declarations, we
make no attempt to record the `#if` not taken anywhere in the AST.
This reflects a change in attitude in the design of the AST, because
we have found that trying to represent this information there (e.g.,
via `IfConfigDecl`) complicates clients while providing little value.
This information is best kept in the syntax tree, only.1 parent 7a75dda commit b3c5fde
File tree
6 files changed
+308
-50
lines changed- include/swift/Parse
- lib/Parse
- test/attr
6 files changed
+308
-50
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
| |||
684 | 694 | | |
685 | 695 | | |
686 | 696 | | |
687 | | - | |
| 697 | + | |
| 698 | + | |
688 | 699 | | |
689 | 700 | | |
690 | 701 | | |
| |||
945 | 956 | | |
946 | 957 | | |
947 | 958 | | |
948 | | - | |
| 959 | + | |
949 | 960 | | |
950 | 961 | | |
951 | 962 | | |
| |||
982 | 993 | | |
983 | 994 | | |
984 | 995 | | |
| 996 | + | |
985 | 997 | | |
986 | 998 | | |
987 | 999 | | |
| |||
1004 | 1016 | | |
1005 | 1017 | | |
1006 | 1018 | | |
1007 | | - | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
1008 | 1032 | | |
1009 | 1033 | | |
1010 | 1034 | | |
1011 | 1035 | | |
1012 | 1036 | | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
1013 | 1042 | | |
1014 | 1043 | | |
1015 | 1044 | | |
| |||
1020 | 1049 | | |
1021 | 1050 | | |
1022 | 1051 | | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
1023 | 1062 | | |
1024 | | - | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
1025 | 1072 | | |
1026 | 1073 | | |
1027 | 1074 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3793 | 3793 | | |
3794 | 3794 | | |
3795 | 3795 | | |
| 3796 | + | |
| 3797 | + | |
| 3798 | + | |
| 3799 | + | |
| 3800 | + | |
| 3801 | + | |
| 3802 | + | |
| 3803 | + | |
| 3804 | + | |
| 3805 | + | |
| 3806 | + | |
| 3807 | + | |
| 3808 | + | |
| 3809 | + | |
| 3810 | + | |
| 3811 | + | |
| 3812 | + | |
| 3813 | + | |
| 3814 | + | |
| 3815 | + | |
3796 | 3816 | | |
3797 | 3817 | | |
3798 | 3818 | | |
3799 | 3819 | | |
3800 | 3820 | | |
3801 | 3821 | | |
3802 | 3822 | | |
3803 | | - | |
3804 | | - | |
| 3823 | + | |
| 3824 | + | |
| 3825 | + | |
3805 | 3826 | | |
3806 | 3827 | | |
3807 | 3828 | | |
3808 | | - | |
3809 | 3829 | | |
3810 | | - | |
3811 | | - | |
3812 | | - | |
3813 | | - | |
3814 | | - | |
3815 | | - | |
| 3830 | + | |
3816 | 3831 | | |
3817 | 3832 | | |
3818 | 3833 | | |
| |||
3902 | 3917 | | |
3903 | 3918 | | |
3904 | 3919 | | |
3905 | | - | |
| 3920 | + | |
| 3921 | + | |
3906 | 3922 | | |
3907 | 3923 | | |
3908 | 3924 | | |
| |||
4273 | 4289 | | |
4274 | 4290 | | |
4275 | 4291 | | |
4276 | | - | |
| 4292 | + | |
4277 | 4293 | | |
4278 | 4294 | | |
4279 | 4295 | | |
| |||
4307 | 4323 | | |
4308 | 4324 | | |
4309 | 4325 | | |
4310 | | - | |
| 4326 | + | |
4311 | 4327 | | |
4312 | 4328 | | |
4313 | 4329 | | |
| |||
4318 | 4334 | | |
4319 | 4335 | | |
4320 | 4336 | | |
4321 | | - | |
| 4337 | + | |
| 4338 | + | |
4322 | 4339 | | |
4323 | 4340 | | |
4324 | | - | |
| 4341 | + | |
| 4342 | + | |
| 4343 | + | |
| 4344 | + | |
| 4345 | + | |
| 4346 | + | |
| 4347 | + | |
| 4348 | + | |
| 4349 | + | |
| 4350 | + | |
4325 | 4351 | | |
4326 | 4352 | | |
4327 | 4353 | | |
| |||
4343 | 4369 | | |
4344 | 4370 | | |
4345 | 4371 | | |
4346 | | - | |
| 4372 | + | |
4347 | 4373 | | |
4348 | 4374 | | |
4349 | 4375 | | |
4350 | 4376 | | |
4351 | 4377 | | |
4352 | | - | |
| 4378 | + | |
4353 | 4379 | | |
4354 | 4380 | | |
4355 | 4381 | | |
| |||
4376 | 4402 | | |
4377 | 4403 | | |
4378 | 4404 | | |
4379 | | - | |
| 4405 | + | |
4380 | 4406 | | |
4381 | 4407 | | |
4382 | 4408 | | |
| |||
4388 | 4414 | | |
4389 | 4415 | | |
4390 | 4416 | | |
4391 | | - | |
| 4417 | + | |
4392 | 4418 | | |
4393 | 4419 | | |
4394 | 4420 | | |
| |||
4399 | 4425 | | |
4400 | 4426 | | |
4401 | 4427 | | |
4402 | | - | |
| 4428 | + | |
4403 | 4429 | | |
4404 | 4430 | | |
4405 | 4431 | | |
| |||
4510 | 4536 | | |
4511 | 4537 | | |
4512 | 4538 | | |
| 4539 | + | |
4513 | 4540 | | |
4514 | 4541 | | |
4515 | 4542 | | |
4516 | 4543 | | |
4517 | 4544 | | |
4518 | | - | |
| 4545 | + | |
4519 | 4546 | | |
4520 | 4547 | | |
4521 | 4548 | | |
| |||
4574 | 4601 | | |
4575 | 4602 | | |
4576 | 4603 | | |
4577 | | - | |
| 4604 | + | |
| 4605 | + | |
4578 | 4606 | | |
4579 | 4607 | | |
4580 | 4608 | | |
| |||
5356 | 5384 | | |
5357 | 5385 | | |
5358 | 5386 | | |
5359 | | - | |
| 5387 | + | |
| 5388 | + | |
| 5389 | + | |
5360 | 5390 | | |
5361 | 5391 | | |
5362 | 5392 | | |
| |||
6200 | 6230 | | |
6201 | 6231 | | |
6202 | 6232 | | |
6203 | | - | |
| 6233 | + | |
| 6234 | + | |
6204 | 6235 | | |
6205 | 6236 | | |
6206 | 6237 | | |
| |||
0 commit comments