@@ -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
}
@@ -1345,32 +1345,12 @@ Prescanner::IsFixedFormCompilerDirectiveLine(const char *start) const {
1345
1345
1346
1346
std::optional<Prescanner::LineClassification>
1347
1347
Prescanner::IsFreeFormCompilerDirectiveLine (const char *start) const {
1348
- char sentinel[8 ];
1349
- const char *p{SkipWhiteSpace (start)};
1350
- if (*p++ != ' !' ) {
1351
- return std::nullopt;
1352
- }
1353
- for (std::size_t j{0 }; j + 1 < sizeof sentinel; ++p, ++j) {
1354
- if (*p == ' \n ' ) {
1355
- break ;
1356
- }
1357
- if (*p == ' ' || *p == ' \t ' || *p == ' &' ) {
1358
- if (j == 0 ) {
1359
- break ;
1360
- }
1361
- sentinel[j] = ' \0 ' ;
1362
- p = SkipWhiteSpace (p + 1 );
1363
- if (*p == ' !' ) {
1364
- break ;
1365
- }
1366
- if (const char *sp{IsCompilerDirectiveSentinel (sentinel, j)}) {
1367
- std::size_t offset = p - start;
1368
- return {LineClassification{
1369
- LineClassification::Kind::CompilerDirective, offset, sp}};
1370
- }
1371
- break ;
1348
+ if (const char *p{SkipWhiteSpace (start)}; p && *p++ == ' !' ) {
1349
+ if (auto maybePair{IsCompilerDirectiveSentinel (p)}) {
1350
+ auto offset{static_cast <std::size_t >(maybePair->second - start)};
1351
+ return {LineClassification{LineClassification::Kind::CompilerDirective,
1352
+ offset, maybePair->first }};
1372
1353
}
1373
- sentinel[j] = ToLowerCaseLetter (*p);
1374
1354
}
1375
1355
return std::nullopt;
1376
1356
}
@@ -1415,6 +1395,28 @@ const char *Prescanner::IsCompilerDirectiveSentinel(CharBlock token) const {
1415
1395
return end > p && IsCompilerDirectiveSentinel (p, end - p) ? p : nullptr ;
1416
1396
}
1417
1397
1398
+ std::optional<std::pair<const char *, const char *>>
1399
+ Prescanner::IsCompilerDirectiveSentinel (const char *p) const {
1400
+ char sentinel[8 ];
1401
+ for (std::size_t j{0 }; j + 1 < sizeof sentinel && *p != ' \n ' ; ++p, ++j) {
1402
+ if (*p == ' ' || *p == ' \t ' || *p == ' &' ) {
1403
+ if (j > 0 ) {
1404
+ sentinel[j] = ' \0 ' ;
1405
+ p = SkipWhiteSpace (p + 1 );
1406
+ if (*p != ' !' ) {
1407
+ if (const char *sp{IsCompilerDirectiveSentinel (sentinel, j)}) {
1408
+ return std::make_pair (sp, p);
1409
+ }
1410
+ }
1411
+ }
1412
+ break ;
1413
+ } else {
1414
+ sentinel[j] = ToLowerCaseLetter (*p);
1415
+ }
1416
+ }
1417
+ return std::nullopt;
1418
+ }
1419
+
1418
1420
constexpr bool IsDirective (const char *match, const char *dir) {
1419
1421
for (; *match; ++match) {
1420
1422
if (*match != ToLowerCaseLetter (*dir++)) {
0 commit comments