[PATCH] D20809: [include-fixer] Show better messages on unfound symbols.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue May 31 04:49:25 PDT 2016


hokein created this revision.
hokein added a reviewer: bkramer.
hokein added a subscriber: cfe-commits.

Also some misc tweaks.

http://reviews.llvm.org/D20809

Files:
  include-fixer/IncludeFixer.cpp
  include-fixer/IncludeFixerContext.h
  include-fixer/tool/ClangIncludeFixer.cpp
  include-fixer/tool/clang-include-fixer.py

Index: include-fixer/tool/clang-include-fixer.py
===================================================================
--- include-fixer/tool/clang-include-fixer.py
+++ include-fixer/tool/clang-include-fixer.py
@@ -74,12 +74,17 @@
   text = '\n'.join(buf)
 
   # Run command to get all headers.
-  command = [binary, "-stdin", "-output-headers", "-db="+args.db, "-input="+args.input, "-debug",
-             vim.current.buffer.name]
+  command = [binary, "-stdin", "-output-headers", "-db="+args.db,
+             "-input="+args.input, vim.current.buffer.name]
   stdout, stderr = execute(command, text)
   lines = stdout.splitlines()
-  if len(lines) < 2:
-    print "No header is included.\n"
+
+  if len(lines) == 0:
+    print "The file is fine, no need to add a header.\n"
+    return;
+
+  if len(lines) == 1:
+    print "Couldn't find a header for {0}.\n".format(lines[0])
     return
 
   # The first line is the symbol name.
Index: include-fixer/tool/ClangIncludeFixer.cpp
===================================================================
--- include-fixer/tool/ClangIncludeFixer.cpp
+++ include-fixer/tool/ClangIncludeFixer.cpp
@@ -190,8 +190,10 @@
   }
 
   if (OutputHeaders) {
+    if (Context.SymbolIdentifier.empty())
+      return 0;
     // FIXME: Output IncludeFixerContext as YAML.
-    llvm::outs() << Context.SymbolIdentifer << "\n";
+    llvm::outs() << Context.SymbolIdentifier << "\n";
     for (const auto &Header : Context.Headers)
       llvm::outs() << Header << "\n";
     return 0;
Index: include-fixer/IncludeFixerContext.h
===================================================================
--- include-fixer/IncludeFixerContext.h
+++ include-fixer/IncludeFixerContext.h
@@ -19,7 +19,7 @@
 /// \brief A context for the symbol being queried.
 struct IncludeFixerContext {
   /// \brief The symbol name.
-  std::string SymbolIdentifer;
+  std::string SymbolIdentifier;
   /// \brief The headers which have SymbolIdentifier definitions.
   std::vector<std::string> Headers;
   /// \brief The insertion point for new include header.
Index: include-fixer/IncludeFixer.cpp
===================================================================
--- include-fixer/IncludeFixer.cpp
+++ include-fixer/IncludeFixer.cpp
@@ -241,10 +241,7 @@
   getIncludeFixerContext(const clang::SourceManager &SourceManager,
                          clang::HeaderSearch &HeaderSearch) {
     IncludeFixerContext FixerContext;
-    if (SymbolQueryResults.empty())
-      return FixerContext;
-
-    FixerContext.SymbolIdentifer = QuerySymbol;
+    FixerContext.SymbolIdentifier = QuerySymbol;
     FixerContext.FirstIncludeOffset = FirstIncludeOffset;
     for (const auto &Header : SymbolQueryResults)
       FixerContext.Headers.push_back(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20809.59041.patch
Type: text/x-patch
Size: 2744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160531/b0654f5e/attachment.bin>


More information about the cfe-commits mailing list