From cf2274b779f5ffee476cfe40994e6963a51c6428 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Fri, 17 Jul 2020 11:21:08 -0700 Subject: [flang] Allow ! and // comments after some preprocessing directives Old-style C /*comments*/ are omitted from preprocessor directive token sequences by the prescanner, but line-ending C++ and Fortran free-form comments are not since their handling might depend on the directive. Add code to skip these line-ending comments as appropriate in place of existing code that just skipped blanks. Reviewed By: sscalpone Differential Revision: https://reviews.llvm.org/D84061 --- flang/lib/Parser/token-sequence.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'flang/lib/Parser/token-sequence.cpp') diff --git a/flang/lib/Parser/token-sequence.cpp b/flang/lib/Parser/token-sequence.cpp index ce94f26..07c5b12 100644 --- a/flang/lib/Parser/token-sequence.cpp +++ b/flang/lib/Parser/token-sequence.cpp @@ -56,6 +56,31 @@ std::size_t TokenSequence::SkipBlanks(std::size_t at) const { return tokens; // even if at > tokens } +// C-style /*comments*/ are removed from preprocessing directive +// token sequences by the prescanner, but not C++ or Fortran +// free-form line-ending comments (//... and !...) because +// ignoring them is directive-specific. +bool TokenSequence::IsAnythingLeft(std::size_t at) const { + std::size_t tokens{start_.size()}; + for (; at < tokens; ++at) { + auto tok{TokenAt(at)}; + const char *end{tok.end()}; + for (const char *p{tok.begin()}; p < end; ++p) { + switch (*p) { + case '/': + return p + 1 >= end || p[1] != '/'; + case '!': + return false; + case ' ': + break; + default: + return true; + } + } + } + return false; +} + void TokenSequence::RemoveLastToken() { CHECK(!start_.empty()); CHECK(nextStart_ > start_.back()); -- cgit v1.1