File tree 6 files changed +43
-19
lines changed
6 files changed +43
-19
lines changed Original file line number Diff line number Diff line change @@ -630,22 +630,32 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
630
630
preventHollerith_ = false ;
631
631
} else if (IsLegalInIdentifier (*at_)) {
632
632
int parts{1 };
633
+ const char *afterLast{nullptr };
633
634
do {
634
635
EmitChar (tokens, *at_);
635
636
++at_, ++column_;
637
+ afterLast = at_;
636
638
if (SkipToNextSignificantCharacter () && IsLegalIdentifierStart (*at_)) {
637
639
tokens.CloseToken ();
638
640
++parts;
639
641
}
640
642
} while (IsLegalInIdentifier (*at_));
641
643
if (parts >= 3 ) {
642
644
// Subtlety: When an identifier is split across three or more continuation
643
- // lines, its parts are kept as distinct pp-tokens so that macro
644
- // operates on them independently. This trick accommodates the historic
645
- // practice of using line continuation for token pasting after
646
- // replacement.
645
+ // lines (or two continuation lines, immediately preceded or followed
646
+ // by '&' free form continuation line markers, its parts are kept as
647
+ // distinct pp-tokens so that macro operates on them independently.
648
+ // This trick accommodates the historic practice of using line
649
+ // continuation for token pasting after replacement.
647
650
} else if (parts == 2 ) {
648
- tokens.ReopenLastToken ();
651
+ if ((start > start_ && start[-1 ] == ' &' ) ||
652
+ (afterLast < limit_ && (*afterLast == ' &' || *afterLast == ' \n ' ))) {
653
+ // call & call foo& call foo&
654
+ // &MACRO& OR &MACRO& OR &MACRO
655
+ // &foo(...) &(...)
656
+ } else {
657
+ tokens.ReopenLastToken ();
658
+ }
649
659
}
650
660
if (InFixedFormSource ()) {
651
661
SkipSpaces ();
Original file line number Diff line number Diff line change 1
1
! RUN: %flang - E %s 2 >&1 | FileCheck %s
2
- ! CHECK: res = 777
2
+ ! CHECK: res = ( 777 )
3
3
* KWM split across continuation, implicit padding
4
4
integer , parameter :: KWM = 666
5
5
#define KWM 777
6
6
integer :: res
7
- res = KW
8
- + M
7
+ res = ( KW
8
+ + M)
9
9
if (res .eq. 777 ) then
10
10
print * , ' pp005.F yes'
11
11
else
Original file line number Diff line number Diff line change 1
1
! RUN: %flang - E %s 2 >&1 | FileCheck %s
2
- ! CHECK: res = 777
2
+ ! CHECK: res = ( 777 )
3
3
* ditto, but with intervening *comment line
4
4
integer , parameter :: KWM = 666
5
5
#define KWM 777
6
6
integer :: res
7
- res = KW
7
+ res = ( KW
8
8
* comment
9
- + M
9
+ + M)
10
10
if (res .eq. 777 ) then
11
11
print * , ' pp006.F yes'
12
12
else
Original file line number Diff line number Diff line change 1
1
! RUN: %flang -E %s 2>&1 | FileCheck %s
2
- ! CHECK: res = 777
2
+ ! CHECK: res = ( 777)
3
3
! KWM call name split across continuation, with leading &
4
4
integer , parameter :: KWM = 666
5
5
#define KWM 777
6
6
integer :: res
7
- res = KW&
8
- &M
7
+ res = ( KW&
8
+ &M)
9
9
if (res .eq. 777 ) then
10
10
print * , ' pp105.F90 yes'
11
11
else
Original file line number Diff line number Diff line change 1
1
! RUN: %flang -E %s 2>&1 | FileCheck %s
2
- ! CHECK: res = 777
2
+ ! CHECK: res = ( 777)
3
3
! ditto, with & ! comment
4
4
integer , parameter :: KWM = 666
5
5
#define KWM 777
6
6
integer :: res
7
- res = KW& ! comment
8
- &M
7
+ res = ( KW& ! comment
8
+ &M)
9
9
if (res .eq. 777 ) then
10
10
print * , ' pp106.F90 yes'
11
11
else
Original file line number Diff line number Diff line change 1
1
! RUN: %flang -E %s 2>&1 | FileCheck %s
2
- ! CHECK: print *, ADC
2
+ ! CHECK: print *, ADC, 1
3
+ ! CHECK: print *, AD, 1
4
+ ! CHECK: print *, DC, 1
5
+ ! CHECK: print *, AD
6
+ ! CHECK: print *, AB
3
7
#define B D
4
8
implicit none
5
9
real ADC
6
10
print * , A&
7
11
&B&
8
- &C
12
+ &C, 1
13
+ print * , A&
14
+ &B&
15
+ &, 1
16
+ print * , &
17
+ &B&
18
+ &C, 1
19
+ print * , A&
20
+ &B
21
+ print * , A&
22
+ &B ! but not this
9
23
end
You can’t perform that action at this time.
0 commit comments