]> granicus.if.org Git - clang/commitdiff
Share the common code of ComputeHash(Selector Sel) instead of keeping 2 copies in...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 20 Aug 2010 16:03:52 +0000 (16:03 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 20 Aug 2010 16:03:52 +0000 (16:03 +0000)
No functionality change.

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

lib/Serialization/ASTCommon.cpp [new file with mode: 0644]
lib/Serialization/ASTCommon.h [new file with mode: 0644]
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp
lib/Serialization/CMakeLists.txt

diff --git a/lib/Serialization/ASTCommon.cpp b/lib/Serialization/ASTCommon.cpp
new file mode 100644 (file)
index 0000000..0eaf7a5
--- /dev/null
@@ -0,0 +1,29 @@
+//===--- ASTCommon.cpp - Common stuff for ASTReader/ASTWriter----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines common functions that both ASTReader and ASTWriter use.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ASTCommon.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "llvm/ADT/StringExtras.h"
+
+using namespace clang;
+
+unsigned serialization::ComputeHash(Selector Sel) {
+  unsigned N = Sel.getNumArgs();
+  if (N == 0)
+    ++N;
+  unsigned R = 5381;
+  for (unsigned I = 0; I != N; ++I)
+    if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
+      R = llvm::HashString(II->getName(), R);
+  return R;
+}
diff --git a/lib/Serialization/ASTCommon.h b/lib/Serialization/ASTCommon.h
new file mode 100644 (file)
index 0000000..8c94674
--- /dev/null
@@ -0,0 +1,28 @@
+//===- ASTCommon.h - Common stuff for ASTReader/ASTWriter -*- C++ -*-=========//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines common functions that both ASTReader and ASTWriter use.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SERIALIZATION_LIB_AST_COMMON_H
+#define LLVM_CLANG_SERIALIZATION_LIB_AST_COMMON_H
+
+namespace clang {
+  class Selector;
+
+namespace serialization {
+
+unsigned ComputeHash(Selector Sel);
+
+} // namespace serialization
+
+} // namespace clang
+
+#endif
index fb26851e3a3e59f2e716bbd023a5e7c51f9d6a7a..238ce3f5ed883bc9b9889324a2d59f2828ac9575 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTDeserializationListener.h"
+#include "ASTCommon.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Sema/Sema.h"
@@ -477,14 +478,7 @@ public:
   }
 
   static unsigned ComputeHash(Selector Sel) {
-    unsigned N = Sel.getNumArgs();
-    if (N == 0)
-      ++N;
-    unsigned R = 5381;
-    for (unsigned I = 0; I != N; ++I)
-      if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
-        R = llvm::HashString(II->getName(), R);
-    return R;
+    return serialization::ComputeHash(Sel);
   }
 
   // This hopefully will just get inlined and removed by the optimizer.
index e4d636dcf773386b71597d567806240b680fced8..b305fffbc8b0437b9e24f0b9f7d3a060a58762c5 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Serialization/ASTWriter.h"
+#include "ASTCommon.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/IdentifierResolver.h"
 #include "clang/AST/ASTContext.h"
@@ -1571,14 +1572,7 @@ public:
   explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { }
 
   static unsigned ComputeHash(Selector Sel) {
-    unsigned N = Sel.getNumArgs();
-    if (N == 0)
-      ++N;
-    unsigned R = 5381;
-    for (unsigned I = 0; I != N; ++I)
-      if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
-        R = llvm::HashString(II->getName(), R);
-    return R;
+    return serialization::ComputeHash(Sel);
   }
 
   std::pair<unsigned,unsigned>
index b03bd14eabd1566416b0935fe278f3e67821b732..d863c179bed29e93e81684a28703f890861a1a0f 100644 (file)
@@ -2,6 +2,7 @@ set(LLVM_NO_RTTI 1)
 
 add_clang_library(clangSerialization
   GeneratePCH.cpp
+  ASTCommon.cpp
   ASTReader.cpp
   ASTReaderDecl.cpp
   ASTReaderStmt.cpp