[PATCH] D20898: [clang-format] skip empty lines and comments in the top of the code when inserting new headers.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 3 01:52:44 PDT 2016


djasper added inline comments.

================
Comment at: lib/Format/Format.cpp:1484
@@ +1483,3 @@
+      Environment::CreateVirtualEnvironment(Code, FileName, /*Ranges=*/{});
+  FormatTokenLexer Lexer(Env->getSourceManager(), Env->getFileID(), Style,
+                         encoding::detectEncoding(Code));
----------------
Thinking about this some more, I think the FormatTokenLexer already does too much. Maybe just use a regular lexer?

  const SourceManager& SourceMgr = Env->getSourceManager();
  Lexer Lex(Env->getFileID(), SourceMgr.getBuffer(Env->getFileID()), SourceMgr,
            getFormattingLangOpts(Style));
  Token Tok;
  int MinInsertOffset = Code.size();
  while (Lex.LexFromRawLexer(&Tok)) {
    if (Tok.isNot(tok::comment)) {
      MinInsertOffset = SourceMgr.getFileOffset(Tok.getLocation());
      break;
    }
  } 


http://reviews.llvm.org/D20898





More information about the cfe-commits mailing list