]> granicus.if.org Git - clang/commitdiff
Revert my changes that try to avoid creating StringMap entries for
authorDouglas Gregor <dgregor@apple.com>
Sat, 25 Apr 2009 20:26:24 +0000 (20:26 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 25 Apr 2009 20:26:24 +0000 (20:26 +0000)
identifiers. They don't yet work, but will inhibit future
optimizations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70071 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/IdentifierTable.h
include/clang/Frontend/PCHReader.h
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp

index 99580a17fe4ddbc0fc434d1deffee049581f76b2..235c19081cda208942ddcf27818fc14660fde339 100644 (file)
@@ -293,6 +293,34 @@ public:
     return *II;
   }
   
+  /// \brief Creates a new IdentifierInfo from the given string.
+  ///
+  /// This is a lower-level version of get() that requires that this
+  /// identifier not be known previously and that does not consult an
+  /// external source for identifiers. In particular, external
+  /// identifier sources can use this routine to build IdentifierInfo
+  /// nodes and then introduce additional information about those
+  /// identifiers.
+  IdentifierInfo &CreateIdentifierInfo(const char *NameStart, 
+                                       const char *NameEnd) {
+    llvm::StringMapEntry<IdentifierInfo*> &Entry =
+      HashTable.GetOrCreateValue(NameStart, NameEnd);
+    
+    IdentifierInfo *II = Entry.getValue();
+    assert(!II && "IdentifierInfo already exists");
+    
+    // Lookups failed, make a new IdentifierInfo.
+    void *Mem = getAllocator().Allocate<IdentifierInfo>();
+    II = new (Mem) IdentifierInfo();
+    Entry.setValue(II);
+
+    // Make sure getName() knows how to find the IdentifierInfo
+    // contents.
+    II->Entry = &Entry;
+
+    return *II;
+  }
+
   IdentifierInfo &get(const char *Name) {
     return get(Name, Name+strlen(Name));
   }
index c6f7ad9301cde14f28dd02cac252828f8d7f1c90..0c8520ceb44fa5db27dc60a8b32e610475163c1a 100644 (file)
@@ -27,7 +27,6 @@
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Bitcode/BitstreamReader.h"
-#include "llvm/Support/Allocator.h"
 #include "llvm/Support/DataTypes.h"
 #include <map>
 #include <string>
@@ -86,9 +85,6 @@ private:
   /// \brief The bitstream reader from which we'll read the PCH file.
   llvm::BitstreamReader Stream;
 
-  /// \brief Allocator used for IdentifierInfo objects.
-  llvm::BumpPtrAllocator Alloc;
-
   /// \brief The file name of the PCH file.
   std::string FileName;
 
@@ -374,13 +370,6 @@ public:
   IdentifierInfo *GetIdentifierInfo(const RecordData &Record, unsigned &Idx) {
     return DecodeIdentifierInfo(Record[Idx++]);
   }
-
-  /// \brief Builds a new IdentifierInfo object that refers to a
-  /// string stored within the PCH file.
-  ///
-  /// \brief Str must be a pointer into the start of a string within
-  /// IdentifierTableData.
-  IdentifierInfo &BuildIdentifierInfoInsidePCH(const unsigned char *Str);
   
   Selector DecodeSelector(unsigned Idx);
   
index 918fd93fdd347236d30d084ce92154a1a607774d..005436dccf2eacfdc619d5214e5606612310d707 100644 (file)
@@ -1245,8 +1245,8 @@ public:
   static std::pair<unsigned, unsigned>
   ReadKeyDataLength(const unsigned char*& d) {
     using namespace clang::io;
-    unsigned DataLen = ReadUnalignedLE16(d);
     unsigned KeyLen = ReadUnalignedLE16(d);
+    unsigned DataLen = ReadUnalignedLE16(d);
     return std::make_pair(KeyLen, DataLen);
   }
     
@@ -1282,7 +1282,8 @@ public:
     // the new IdentifierInfo.
     IdentifierInfo *II = KnownII;
     if (!II)
-      II = &Reader.BuildIdentifierInfoInsidePCH((const unsigned char *)k.first);
+      II = &Reader.getIdentifierTable().CreateIdentifierInfo(
+                                                 k.first, k.first + k.second);
     Reader.SetIdentifierInfo(ID, II);
 
     // Set or check the various bits in the IdentifierInfo structure.
@@ -2848,19 +2849,6 @@ IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) {
   return IdentifiersLoaded[ID - 1];
 }
 
-IdentifierInfo &
-PCHReader::BuildIdentifierInfoInsidePCH(const unsigned char *Str) {
-  // Allocate the object.
-  std::pair<IdentifierInfo,const unsigned char*> *Mem =
-    Alloc.Allocate<std::pair<IdentifierInfo,const unsigned char*> >();
-
-  // Build the IdentifierInfo itself.
-  Mem->second = Str;
-  assert(Str[0] != '\0');
-  IdentifierInfo *II = new ((void*) Mem) IdentifierInfo();
-  return *II;
-}
-
 Selector PCHReader::DecodeSelector(unsigned ID) {
   if (ID == 0)
     return Selector();
index 7eb398c1663fd973a1f8093aa54d3551bb900c01..4ac836419eb836d307fe84d5b96d0cfe72b840dd 100644 (file)
@@ -2013,6 +2013,7 @@ public:
     EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II, 
                       pch::IdentID ID) {
     unsigned KeyLen = strlen(II->getName()) + 1;
+    clang::io::Emit16(Out, KeyLen);
     unsigned DataLen = 4 + 4; // 4 bytes for token ID, builtin, flags
                               // 4 bytes for the persistent ID
     if (II->hasMacroDefinition() && 
@@ -2022,14 +2023,7 @@ public:
                                    DEnd = IdentifierResolver::end();
          D != DEnd; ++D)
       DataLen += sizeof(pch::DeclID);
-
-    // We emit the data length before the key length, because we want
-    // the key length to immediately precede the actual string
-    // data. This is so that our identifier length + key layout
-    // matches that of the identifier hash table for pretokenized
-    // headers.
     clang::io::Emit16(Out, DataLen);
-    clang::io::Emit16(Out, KeyLen);
     return std::make_pair(KeyLen, DataLen);
   }