[PATCH] D20959: [clang-format] make header guard identification stricter (with Lexer).

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 3 06:43:22 PDT 2016


djasper added inline comments.

================
Comment at: lib/Format/Format.cpp:1441
@@ +1440,3 @@
+void skipComments(Lexer &Lex, Token &Tok) {
+  while (!Lex.LexFromRawLexer(Tok))
+    if (Tok.isNot(tok::comment))
----------------
I'd modify this to:

  while (Tok.is(comment))
    if (Lex.LexFromRawLexer(Tok))
      return;

So it skips tokens until it finds a non-comment token.

================
Comment at: lib/Format/Format.cpp:1452
@@ +1451,3 @@
+  assert(Tok.is(tok::hash) && "If-directive must start with hash!");
+  return !Lex.LexFromRawLexer(Tok) && Tok.is(tok::raw_identifier) &&
+         Tok.getRawIdentifier() == Name && !Lex.LexFromRawLexer(Tok) &&
----------------
Store this value in a bool and call another Lex.LexFromRawLexer afterwards. Both calls do this next.

================
Comment at: lib/Format/Format.cpp:1501
@@ +1500,3 @@
+  bool HeaderGuardFound = false;
+  if (Tok.is(tok::hash) && isDirectiveWithName(Lex, "ifndef", Tok) &&
+      !Lex.LexFromRawLexer(Tok)) {
----------------
Move the Tok.is(hash) check into isDirectiveWithName and replace the assert there.


http://reviews.llvm.org/D20959





More information about the cfe-commits mailing list