@@ -471,7 +471,7 @@ bool Prescanner::MustSkipToEndOfLine() const {
471
471
if (inFixedForm_ && column_ > fixedFormColumnLimit_ && !tabInCurrentLine_) {
472
472
return true ; // skip over ignored columns in right margin (73:80)
473
473
} else if (*at_ == ' !' && !inCharLiteral_) {
474
- return true ; // inline comment goes to end of source line
474
+ return ! IsCompilerDirectiveSentinel (at_);
475
475
} else {
476
476
return false ;
477
477
}
@@ -1380,32 +1380,12 @@ Prescanner::IsFixedFormCompilerDirectiveLine(const char *start) const {
1380
1380
1381
1381
std::optional<Prescanner::LineClassification>
1382
1382
Prescanner::IsFreeFormCompilerDirectiveLine (const char *start) const {
1383
- char sentinel[8 ];
1384
- const char *p{SkipWhiteSpace (start)};
1385
- if (*p++ != ' !' ) {
1386
- return std::nullopt;
1387
- }
1388
- for (std::size_t j{0 }; j + 1 < sizeof sentinel; ++p, ++j) {
1389
- if (*p == ' \n ' ) {
1390
- break ;
1391
- }
1392
- if (*p == ' ' || *p == ' \t ' || *p == ' &' ) {
1393
- if (j == 0 ) {
1394
- break ;
1395
- }
1396
- sentinel[j] = ' \0 ' ;
1397
- p = SkipWhiteSpace (p + 1 );
1398
- if (*p == ' !' ) {
1399
- break ;
1400
- }
1401
- if (const char *sp{IsCompilerDirectiveSentinel (sentinel, j)}) {
1402
- std::size_t offset = p - start;
1403
- return {LineClassification{
1404
- LineClassification::Kind::CompilerDirective, offset, sp}};
1405
- }
1406
- break ;
1383
+ if (const char *p{SkipWhiteSpace (start)}; p && *p++ == ' !' ) {
1384
+ if (auto maybePair{IsCompilerDirectiveSentinel (p)}) {
1385
+ auto offset{static_cast <std::size_t >(maybePair->second - start)};
1386
+ return {LineClassification{LineClassification::Kind::CompilerDirective,
1387
+ offset, maybePair->first }};
1407
1388
}
1408
- sentinel[j] = ToLowerCaseLetter (*p);
1409
1389
}
1410
1390
return std::nullopt;
1411
1391
}
@@ -1450,6 +1430,28 @@ const char *Prescanner::IsCompilerDirectiveSentinel(CharBlock token) const {
1450
1430
return end > p && IsCompilerDirectiveSentinel (p, end - p) ? p : nullptr ;
1451
1431
}
1452
1432
1433
+ std::optional<std::pair<const char *, const char *>>
1434
+ Prescanner::IsCompilerDirectiveSentinel (const char *p) const {
1435
+ char sentinel[8 ];
1436
+ for (std::size_t j{0 }; j + 1 < sizeof sentinel && *p != ' \n ' ; ++p, ++j) {
1437
+ if (*p == ' ' || *p == ' \t ' || *p == ' &' ) {
1438
+ if (j > 0 ) {
1439
+ sentinel[j] = ' \0 ' ;
1440
+ p = SkipWhiteSpace (p + 1 );
1441
+ if (*p != ' !' ) {
1442
+ if (const char *sp{IsCompilerDirectiveSentinel (sentinel, j)}) {
1443
+ return std::make_pair (sp, p);
1444
+ }
1445
+ }
1446
+ }
1447
+ break ;
1448
+ } else {
1449
+ sentinel[j] = ToLowerCaseLetter (*p);
1450
+ }
1451
+ }
1452
+ return std::nullopt;
1453
+ }
1454
+
1453
1455
constexpr bool IsDirective (const char *match, const char *dir) {
1454
1456
for (; *match; ++match) {
1455
1457
if (*match != ToLowerCaseLetter (*dir++)) {
0 commit comments