VitaNuo updated this revision to Diff 493870.
VitaNuo added a comment.

Revert all changes to generator.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142092/new/

https://reviews.llvm.org/D142092

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/tools/include-mapping/test.py

Index: clang/tools/include-mapping/test.py
===================================================================
--- clang/tools/include-mapping/test.py
+++ clang/tools/include-mapping/test.py
@@ -53,7 +53,7 @@
   </tr>
 </tbody></table>
 """
-    self.assertEqual(_ParseSymbolPage(html, 'foo'), set(['<cmath>']))
+    self.assertEqual(_ParseSymbolPage(html, 'foo', ""), set(['<cmath>']))
 
 
   def testParseSymbolPage_MulHeaders(self):
@@ -94,7 +94,7 @@
   </tr>
 </tbody></table>
 """
-    self.assertEqual(_ParseSymbolPage(html, "foo"),
+    self.assertEqual(_ParseSymbolPage(html, "foo", ""),
                      set(['<cstdio>', '<cstdlib>']))
 
 
@@ -121,7 +121,7 @@
 </tr>
 </tbody></table>
 """
-    self.assertEqual(_ParseSymbolPage(html, "foo"),
+    self.assertEqual(_ParseSymbolPage(html, "foo", ""),
                      set(['<algorithm>', '<utility>']))
 
   def testParseSymbolPage_MulSymbolsInSameTd(self):
@@ -145,9 +145,9 @@
 </tr>
 </tbody></table>
 """
-    self.assertEqual(_ParseSymbolPage(html, "int8_t"),
+    self.assertEqual(_ParseSymbolPage(html, "int8_t", ""),
                      set(['<cstdint>']))
-    self.assertEqual(_ParseSymbolPage(html, "int16_t"),
+    self.assertEqual(_ParseSymbolPage(html, "int16_t", ""),
                      set(['<cstdint>']))
 
 
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===================================================================
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "clang/AST/Decl.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 
@@ -17,7 +18,7 @@
 
 static llvm::StringRef *HeaderNames;
 static std::pair<llvm::StringRef, llvm::StringRef> *SymbolNames;
-static unsigned *SymbolHeaderIDs;
+static llvm::SmallVector<unsigned> *SymbolHeaderIDs;
 static llvm::DenseMap<llvm::StringRef, unsigned> *HeaderIDs;
 // Maps symbol name -> Symbol::ID, within a namespace.
 using NSSymbolMap = llvm::DenseMap<llvm::StringRef, unsigned>;
@@ -29,6 +30,8 @@
 #include "clang/Tooling/Inclusions/CSymbolMap.inc"
 #include "clang/Tooling/Inclusions/StdSymbolMap.inc"
 #undef SYMBOL
+  // Allocates more space than necessary since multiple SYMBOLs might correspond
+  // to the same qualified name.
   SymbolNames = new std::remove_reference_t<decltype(*SymbolNames)>[SymCount];
   SymbolHeaderIDs =
       new std::remove_reference_t<decltype(*SymbolHeaderIDs)>[SymCount];
@@ -46,18 +49,26 @@
     return HeaderIDs->try_emplace(Header, HeaderIDs->size()).first->second;
   };
 
-  auto Add = [&, SymIndex(0)](llvm::StringRef Name, llvm::StringRef NS,
-                              llvm::StringRef HeaderName) mutable {
+  auto Add = [&, SymIndex(-1)](llvm::StringRef Name, llvm::StringRef NS,
+                               llvm::StringRef HeaderName) mutable {
     if (NS == "None")
       NS = "";
 
+    // Determine whether the symbol is new. This relies on symbols being
+    // ordered alpahbetically in the map.
+    if (SymIndex >= 0 && SymbolNames[SymIndex].first == NS &&
+        SymbolNames[SymIndex].second == Name) {
+      // Not a new symbol, use the same index.
+    } else {
+      // First symbol or new symbol, increment next available index.
+      ++SymIndex;
+    }
+
     SymbolNames[SymIndex] = {NS, Name};
-    SymbolHeaderIDs[SymIndex] = AddHeader(HeaderName);
+    SymbolHeaderIDs[SymIndex].emplace_back(AddHeader(HeaderName));
 
     NSSymbolMap &NSSymbols = AddNS(NS);
     NSSymbols.try_emplace(Name, SymIndex);
-
-    ++SymIndex;
   };
 #define SYMBOL(Name, NS, Header) Add(#Name, #NS, #Header);
 #include "clang/Tooling/Inclusions/CSymbolMap.inc"
@@ -87,7 +98,7 @@
 llvm::StringRef Symbol::scope() const { return SymbolNames[ID].first; }
 llvm::StringRef Symbol::name() const { return SymbolNames[ID].second; }
 std::optional<Symbol> Symbol::named(llvm::StringRef Scope,
-                                     llvm::StringRef Name) {
+                                    llvm::StringRef Name) {
   ensureInitialized();
   if (NSSymbolMap *NSSymbols = NamespaceSymbols->lookup(Scope)) {
     auto It = NSSymbols->find(Name);
@@ -96,9 +107,14 @@
   }
   return std::nullopt;
 }
-Header Symbol::header() const { return Header(SymbolHeaderIDs[ID]); }
+
+Header Symbol::header() const { return Header(SymbolHeaderIDs[ID][0]); }
 llvm::SmallVector<Header> Symbol::headers() const {
-  return {header()}; // FIXME: multiple in case of ambiguity
+  llvm::SmallVector<Header> result;
+  for (auto HeaderID : SymbolHeaderIDs[ID]) {
+    result.emplace_back(Header(HeaderID));
+  }
+  return result;
 }
 
 Recognizer::Recognizer() { ensureInitialized(); }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to