@@ -471,7 +471,7 @@ bool Prescanner::MustSkipToEndOfLine() const {
471471 if (inFixedForm_ && column_ > fixedFormColumnLimit_ && !tabInCurrentLine_) {
472472 return true ; // skip over ignored columns in right margin (73:80)
473473 } else if (*at_ == ' !' && !inCharLiteral_) {
474- return true ; // inline comment goes to end of source line
474+ return ! IsCompilerDirectiveSentinel (at_);
475475 } else {
476476 return false ;
477477 }
@@ -1380,32 +1380,12 @@ Prescanner::IsFixedFormCompilerDirectiveLine(const char *start) const {
13801380
13811381std::optional<Prescanner::LineClassification>
13821382Prescanner::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 }};
14071388 }
1408- sentinel[j] = ToLowerCaseLetter (*p);
14091389 }
14101390 return std::nullopt ;
14111391}
@@ -1450,6 +1430,28 @@ const char *Prescanner::IsCompilerDirectiveSentinel(CharBlock token) const {
14501430 return end > p && IsCompilerDirectiveSentinel (p, end - p) ? p : nullptr ;
14511431}
14521432
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+
14531455constexpr bool IsDirective (const char *match, const char *dir) {
14541456 for (; *match; ++match) {
14551457 if (*match != ToLowerCaseLetter (*dir++)) {
0 commit comments