ASTCommon.cpp revision 336d43a368cee30549dc21a94e25fb03f887a27e
10ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//===--- ASTCommon.cpp - Common stuff for ASTReader/ASTWriter----*- C++ -*-===//
20ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
30ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//                     The LLVM Compiler Infrastructure
40ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
50ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// This file is distributed under the University of Illinois Open Source
60ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// License. See LICENSE.TXT for details.
70ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
80ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//===----------------------------------------------------------------------===//
90ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//  This file defines common functions that both ASTReader and ASTWriter use.
110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//===----------------------------------------------------------------------===//
130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "ASTCommon.h"
150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "clang/Serialization/ASTDeserializationListener.h"
160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "clang/Basic/IdentifierTable.h"
170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "llvm/ADT/StringExtras.h"
180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieusing namespace clang;
200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Give ASTDeserializationListener's VTable a home.
220ee85db398be8ea33d67cc42f99a1468cd6c8180François GaffieASTDeserializationListener::~ASTDeserializationListener() { }
230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieserialization::TypeIdx
250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieserialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  unsigned ID = 0;
270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  switch (BT->getKind()) {
280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Void:       ID = PREDEF_TYPE_VOID_ID;       break;
290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Bool:       ID = PREDEF_TYPE_BOOL_ID;       break;
300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Char_U:     ID = PREDEF_TYPE_CHAR_U_ID;     break;
310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::UChar:      ID = PREDEF_TYPE_UCHAR_ID;      break;
320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::UShort:     ID = PREDEF_TYPE_USHORT_ID;     break;
330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::UInt:       ID = PREDEF_TYPE_UINT_ID;       break;
340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::ULong:      ID = PREDEF_TYPE_ULONG_ID;      break;
350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::ULongLong:  ID = PREDEF_TYPE_ULONGLONG_ID;  break;
360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::UInt128:    ID = PREDEF_TYPE_UINT128_ID;    break;
370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Char_S:     ID = PREDEF_TYPE_CHAR_S_ID;     break;
380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::SChar:      ID = PREDEF_TYPE_SCHAR_ID;      break;
390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::WChar:      ID = PREDEF_TYPE_WCHAR_ID;      break;
400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Short:      ID = PREDEF_TYPE_SHORT_ID;      break;
410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Int:        ID = PREDEF_TYPE_INT_ID;        break;
420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Long:       ID = PREDEF_TYPE_LONG_ID;       break;
430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::LongLong:   ID = PREDEF_TYPE_LONGLONG_ID;   break;
440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Int128:     ID = PREDEF_TYPE_INT128_ID;     break;
450ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Float:      ID = PREDEF_TYPE_FLOAT_ID;      break;
460ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Double:     ID = PREDEF_TYPE_DOUBLE_ID;     break;
470ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::LongDouble: ID = PREDEF_TYPE_LONGDOUBLE_ID; break;
480ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::NullPtr:    ID = PREDEF_TYPE_NULLPTR_ID;    break;
490ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Char16:     ID = PREDEF_TYPE_CHAR16_ID;     break;
500ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Char32:     ID = PREDEF_TYPE_CHAR32_ID;     break;
510ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Overload:   ID = PREDEF_TYPE_OVERLOAD_ID;   break;
520ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::Dependent:  ID = PREDEF_TYPE_DEPENDENT_ID;  break;
530ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::ObjCId:     ID = PREDEF_TYPE_OBJC_ID;       break;
540ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::ObjCClass:  ID = PREDEF_TYPE_OBJC_CLASS;    break;
550ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::ObjCSel:    ID = PREDEF_TYPE_OBJC_SEL;      break;
560ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  case BuiltinType::UndeducedAuto:
570ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    assert(0 && "Should not see undeduced auto here");
580ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    break;
590ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
600ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
610ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  return TypeIdx(ID);
620ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
630ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
640ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieunsigned serialization::ComputeHash(Selector Sel) {
650ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  unsigned N = Sel.getNumArgs();
660ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  if (N == 0)
670ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    ++N;
680ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  unsigned R = 5381;
690ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  for (unsigned I = 0; I != N; ++I)
700ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
710ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      R = llvm::HashString(II->getName(), R);
720ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  return R;
730ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
740ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie