================
@@ -1350,40 +1351,66 @@ static bool isC78ParameterDecl(const FormatToken *Tok,
const FormatToken *Next,
return Tok->Previous && Tok->Previous->isOneOf(tok::l_paren, tok::comma);
}
-bool UnwrappedLineParser::parseModuleImport() {
- assert(FormatTok->is(Keywords.kw_import) && "'import' expected");
+bool UnwrappedLineParser::parseModuleDecl() {
+ assert(IsCpp);
+ assert(FormatTok->is(Keywords.kw_module));
- if (auto Token = Tokens->peekNextToken(/*SkipComment=*/true);
- !Token->Tok.getIdentifierInfo() &&
- Token->isNoneOf(tok::colon, tok::less, tok::string_literal)) {
+ if (Style.Language == FormatStyle::LK_C ||
+ Style.Standard < FormatStyle::LS_Cpp20) {
return false;
}
nextToken();
- while (!eof()) {
- if (FormatTok->is(tok::colon)) {
+ if (FormatTok->isNot(tok::identifier))
+ return false;
+
+ for (nextToken(); FormatTok->isNoneOf(tok::semi, tok::eof); nextToken())
+ if (FormatTok->is(tok::colon))
FormatTok->setFinalizedType(TT_ModulePartitionColon);
- }
+
+ nextToken();
+ Line->IsModuleOrImportDecl = true;
+ addUnwrappedLine();
+ return true;
+}
+
+bool UnwrappedLineParser::parseImportDecl() {
+ assert(IsCpp);
+ assert(FormatTok->is(Keywords.kw_import) && "'import' expected");
+
+ if (Style.Language == FormatStyle::LK_C ||
+ Style.Standard < FormatStyle::LS_Cpp20) {
+ return false;
+ }
+
+ nextToken();
+ if (FormatTok->is(tok::colon)) {
+ FormatTok->setFinalizedType(TT_ModulePartitionColon);
+ nextToken();
+ }
+ if (FormatTok->isNoneOf(tok::identifier, tok::less, tok::string_literal))
+ return false;
+
+ for (;; nextToken()) {
// Handle import <foo/bar.h> as we would an include statement.
- else if (FormatTok->is(tok::less)) {
- nextToken();
- while (FormatTok->isNoneOf(tok::semi, tok::greater) && !eof()) {
- // Mark tokens up to the trailing line comments as implicit string
- // literals.
- if (FormatTok->isNot(tok::comment) &&
- !FormatTok->TokenText.starts_with("//")) {
- FormatTok->setFinalizedType(TT_ImplicitStringLiteral);
+ if (FormatTok->is(tok::less)) {
+ for (nextToken(); FormatTok->isNoneOf(tok::semi, tok::eof); nextToken())
{
+ if (FormatTok->is(tok::greater)) {
+ nextToken();
+ break;
}
----------------
owenca wrote:
```suggestion
for (nextToken(); FormatTok->isNoneOf(tok::greater, tok::semi, tok::eof);
nextToken()) {
```
https://github.com/llvm/llvm-project/pull/199459
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits