[PATCH] D51675: [Sema] Store MacroInfo in CodeCompletionResult for macro results.

Eric Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 5 08:00:41 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL341476: [Sema] Store MacroInfo in CodeCompletionResult for macro results. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D51675

Files:
  cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/tools/libclang/CXCursor.cpp


Index: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
===================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
@@ -17,6 +17,7 @@
 #include "clang-c/Index.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Lex/MacroInfo.h"
 #include "clang/Sema/CodeCompleteOptions.h"
 #include "clang/Sema/DeclSpec.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -843,6 +844,11 @@
   /// corresponding `using decl::qualified::name;` nearby.
   const UsingShadowDecl *ShadowDecl = nullptr;
 
+  /// If the result is RK_Macro, this can store the information about the macro
+  /// definition. This should be set in most cases but can be missing when
+  /// the macro has been undefined.
+  const MacroInfo *MacroDefInfo = nullptr;
+
   /// Build a result that refers to a declaration.
   CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority,
                        NestedNameSpecifier *Qualifier = nullptr,
@@ -867,11 +873,13 @@
 
   /// Build a result that refers to a macro.
   CodeCompletionResult(const IdentifierInfo *Macro,
+                       const MacroInfo *MI = nullptr,
                        unsigned Priority = CCP_Macro)
       : Macro(Macro), Priority(Priority), Kind(RK_Macro),
         CursorKind(CXCursor_MacroDefinition), Hidden(false),
         QualifierIsInformative(false), StartsNestedNameSpecifier(false),
-        AllParametersAreInformative(false), DeclaringEntity(false) {}
+        AllParametersAreInformative(false), DeclaringEntity(false),
+        MacroDefInfo(MI) {}
 
   /// Build a result that refers to a pattern.
   CodeCompletionResult(CodeCompletionString *Pattern,
Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -3313,14 +3313,14 @@
        M != MEnd; ++M) {
     auto MD = PP.getMacroDefinition(M->first);
     if (IncludeUndefined || MD) {
-      if (MacroInfo *MI = MD.getMacroInfo())
-        if (MI->isUsedForHeaderGuard())
-          continue;
+      MacroInfo *MI = MD.getMacroInfo();
+      if (MI && MI->isUsedForHeaderGuard())
+        continue;
 
-      Results.AddResult(Result(M->first,
-                             getMacroUsagePriority(M->first->getName(),
-                                                   PP.getLangOpts(),
-                                                   TargetTypeIsPointer)));
+      Results.AddResult(
+          Result(M->first, MI,
+                 getMacroUsagePriority(M->first->getName(), PP.getLangOpts(),
+                                       TargetTypeIsPointer)));
     }
   }
 
Index: cfe/trunk/tools/libclang/CXCursor.cpp
===================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp
+++ cfe/trunk/tools/libclang/CXCursor.cpp
@@ -1412,16 +1412,16 @@
     }
   } else if (kind == CXCursor_MacroDefinition) {
     const MacroDefinitionRecord *definition = getCursorMacroDefinition(cursor);
-    const IdentifierInfo *MacroInfo = definition->getName();
+    const IdentifierInfo *Macro = definition->getName();
     ASTUnit *unit = getCursorASTUnit(cursor);
-    CodeCompletionResult Result(MacroInfo);
-    CodeCompletionString *String
-      = Result.CreateCodeCompletionString(unit->getASTContext(),
-                                          unit->getPreprocessor(),
-                                          CodeCompletionContext::CCC_Other,
-                                 unit->getCodeCompletionTUInfo().getAllocator(),
-                                 unit->getCodeCompletionTUInfo(),
-                                 false);
+    CodeCompletionResult Result(
+        Macro,
+        unit->getPreprocessor().getMacroDefinition(Macro).getMacroInfo());
+    CodeCompletionString *String = Result.CreateCodeCompletionString(
+        unit->getASTContext(), unit->getPreprocessor(),
+        CodeCompletionContext::CCC_Other,
+        unit->getCodeCompletionTUInfo().getAllocator(),
+        unit->getCodeCompletionTUInfo(), false);
     return String;
   }
   return nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51675.164045.patch
Type: text/x-patch
Size: 4237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180905/e5af7a0f/attachment.bin>


More information about the llvm-commits mailing list