summaryrefslogtreecommitdiffstats
path: root/clang/Basic/IdentifierTable.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-08 19:52:41 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-08 19:52:41 +0000
commitda4c6c183d86944db8ef3d848429d06ce4bf66be (patch)
treef089de31d3e12521c7b93e41b6b1480d29b6e257 /clang/Basic/IdentifierTable.cpp
parent67135ebaff6428757c108f5187a05948ea01a831 (diff)
downloadbcm5719-llvm-da4c6c183d86944db8ef3d848429d06ce4bf66be.tar.gz
bcm5719-llvm-da4c6c183d86944db8ef3d848429d06ce4bf66be.zip
Rewrote serialization of IdentifierInfo and IdentifierTable to use methods Emit
and Materialize/Read instead of using specializations of SerializeTrait<>. The resulting code is much cleaner. We are also setting the stage so that only the parts of the IdentifierTable that are ever referenced within the ASTs are serialized, and not the whole table. llvm-svn: 43904
Diffstat (limited to 'clang/Basic/IdentifierTable.cpp')
-rw-r--r--clang/Basic/IdentifierTable.cpp108
1 files changed, 63 insertions, 45 deletions
diff --git a/clang/Basic/IdentifierTable.cpp b/clang/Basic/IdentifierTable.cpp
index 01c2c17240d..a69e65fe199 100644
--- a/clang/Basic/IdentifierTable.cpp
+++ b/clang/Basic/IdentifierTable.cpp
@@ -382,63 +382,81 @@ SelectorTable::~SelectorTable() {
// Serialization for IdentifierInfo and IdentifierTable.
//===----------------------------------------------------------------------===//
-void llvm::SerializeTrait<IdentifierInfo>::Emit(llvm::Serializer& S,
- const IdentifierInfo& I) {
-
- S.EmitInt(I.getTokenID());
- S.EmitInt(I.getBuiltinID());
- S.EmitInt(I.getObjCKeywordID());
- S.EmitBool(I.hasMacroDefinition());
- S.EmitBool(I.isExtensionToken());
- S.EmitBool(I.isPoisoned());
- S.EmitBool(I.isOtherTargetMacro());
- S.EmitBool(I.isCPlusPlusOperatorKeyword());
- S.EmitBool(I.isNonPortableBuiltin());
+void IdentifierInfo::Emit(llvm::Serializer& S) const {
+ S.EmitInt(getTokenID());
+ S.EmitInt(getBuiltinID());
+ S.EmitInt(getObjCKeywordID());
+ S.EmitBool(hasMacroDefinition());
+ S.EmitBool(isExtensionToken());
+ S.EmitBool(isPoisoned());
+ S.EmitBool(isOtherTargetMacro());
+ S.EmitBool(isCPlusPlusOperatorKeyword());
+ S.EmitBool(isNonPortableBuiltin());
+ // FIXME: FETokenInfo
}
-void llvm::SerializeTrait<IdentifierInfo>::Read(llvm::Deserializer& D,
- IdentifierInfo& I) {
- I.setTokenID((tok::TokenKind) D.ReadInt());
- I.setBuiltinID(D.ReadInt());
- I.setObjCKeywordID((tok::ObjCKeywordKind) D.ReadInt());
- I.setHasMacroDefinition(D.ReadBool());
- I.setIsExtensionToken(D.ReadBool());
- I.setIsPoisoned(D.ReadBool());
- I.setIsOtherTargetMacro(D.ReadBool());
- I.setIsCPlusPlusOperatorKeyword(D.ReadBool());
- I.setNonPortableBuiltin(D.ReadBool());
+void IdentifierInfo::Read(llvm::Deserializer& D) {
+ setTokenID((tok::TokenKind) D.ReadInt());
+ setBuiltinID(D.ReadInt());
+ setObjCKeywordID((tok::ObjCKeywordKind) D.ReadInt());
+ setHasMacroDefinition(D.ReadBool());
+ setIsExtensionToken(D.ReadBool());
+ setIsPoisoned(D.ReadBool());
+ setIsOtherTargetMacro(D.ReadBool());
+ setIsCPlusPlusOperatorKeyword(D.ReadBool());
+ setNonPortableBuiltin(D.ReadBool());
+ // FIXME: FETokenInfo
}
-void llvm::SerializeTrait<IdentifierTable>::Emit(llvm::Serializer& S,
- const IdentifierTable& T){
- S.Emit<unsigned>(T.size());
+void IdentifierTable::Emit(llvm::Serializer& S) const {
+ S.EnterBlock();
- for (clang::IdentifierTable::iterator I=T.begin(), E=T.end(); I != E; ++I) {
- S.EmitCStr(I->getKeyData());
- S.EmitPtr(&I->getValue());
- S.Emit(I->getValue());
+ for (iterator I=begin(), E=end(); I != E; ++I) {
+ const char* Key = I->getKeyData();
+ const IdentifierInfo* Info = &I->getValue();
+
+ bool KeyRegistered = true; // FIXME: S.isRegistered(Key);
+ bool InfoRegistered = true; // FIXME: S.isRegistered(Info);
+
+ if (KeyRegistered || InfoRegistered) {
+ // These acrobatics are so that we don't incur the cost of registering
+ // a pointer with the backpatcher during deserialization if nobody
+ // references the object.
+ S.EmitPtr(InfoRegistered ? Info : NULL);
+ S.EmitPtr(KeyRegistered ? Key : NULL);
+ S.EmitCStr(Key);
+ S.Emit(*Info);
+ }
}
+
+ S.ExitBlock();
}
-void llvm::SerializeTrait<IdentifierTable>::Read(llvm::Deserializer& D,
- IdentifierTable& T) {
- unsigned len = D.ReadInt();
+IdentifierTable* IdentifierTable::Materialize(llvm::Deserializer& D) {
+ llvm::Deserializer::Location BLoc = D.GetCurrentBlockLocation();
+
std::vector<char> buff;
buff.reserve(200);
+
+ IdentifierTable* t = new IdentifierTable();
- for (unsigned i = 0; i < len; ++i) {
+ while (!D.FinishedBlock(BLoc)) {
+ llvm::SerializedPtrID InfoPtrID = D.ReadPtrID();
+ llvm::SerializedPtrID KeyPtrID = D.ReadPtrID();
+
D.ReadCStr(buff);
- IdentifierInfo& Info = T.get(&buff[0],&buff[0]+buff.size());
- D.RegisterPtr(&Info);
- D.Read(Info);
+
+ llvm::StringMapEntry<IdentifierInfo>& Entry =
+ t->HashTable.GetOrCreateValue(&buff[0],&buff[0]+buff.size());
+
+ D.Read(Entry.getValue());
+
+ if (InfoPtrID)
+ D.RegisterRef(InfoPtrID,Entry.getValue());
+
+ if (KeyPtrID)
+ D.RegisterPtr(KeyPtrID,Entry.getKeyData());
}
-}
-
-IdentifierTable*
-llvm::SerializeTrait<IdentifierTable>::Materialize(llvm::Deserializer& D)
-{
- IdentifierTable* t = new IdentifierTable();
- D.Read(*t);
+
return t;
}
-
OpenPOWER on IntegriCloud