ASTCommon.cpp revision 7f92f2d8d9b7a07900c030183bc13a9ff60057cc
17f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//===--- ASTCommon.cpp - Common stuff for ASTReader/ASTWriter----*- C++ -*-===//
27f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//
37f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//                     The LLVM Compiler Infrastructure
47f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//
57f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// This file is distributed under the University of Illinois Open Source
67f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// License. See LICENSE.TXT for details.
77f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//
87f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//===----------------------------------------------------------------------===//
97f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//
107f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//  This file defines common functions that both ASTReader and ASTWriter use.
117f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//
127f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//===----------------------------------------------------------------------===//
137f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei
147f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include "ASTCommon.h"
157f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include "clang/Basic/IdentifierTable.h"
167f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include "clang/Serialization/ASTDeserializationListener.h"
177f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include "llvm/ADT/StringExtras.h"
187f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei
197f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiusing namespace clang;
207f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei
217f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// Give ASTDeserializationListener's VTable a home.
227f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy BenyeiASTDeserializationListener::~ASTDeserializationListener() { }
237f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei
247f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiserialization::TypeIdx
257f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiserialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
267f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  unsigned ID = 0;
277f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  switch (BT->getKind()) {
287f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Void:       ID = PREDEF_TYPE_VOID_ID;       break;
297f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Bool:       ID = PREDEF_TYPE_BOOL_ID;       break;
307f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Char_U:     ID = PREDEF_TYPE_CHAR_U_ID;     break;
317f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::UChar:      ID = PREDEF_TYPE_UCHAR_ID;      break;
327f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::UShort:     ID = PREDEF_TYPE_USHORT_ID;     break;
337f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::UInt:       ID = PREDEF_TYPE_UINT_ID;       break;
347f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::ULong:      ID = PREDEF_TYPE_ULONG_ID;      break;
357f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::ULongLong:  ID = PREDEF_TYPE_ULONGLONG_ID;  break;
367f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::UInt128:    ID = PREDEF_TYPE_UINT128_ID;    break;
377f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Char_S:     ID = PREDEF_TYPE_CHAR_S_ID;     break;
387f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::SChar:      ID = PREDEF_TYPE_SCHAR_ID;      break;
397f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::WChar_S:
407f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::WChar_U:    ID = PREDEF_TYPE_WCHAR_ID;      break;
417f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Short:      ID = PREDEF_TYPE_SHORT_ID;      break;
427f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Int:        ID = PREDEF_TYPE_INT_ID;        break;
437f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Long:       ID = PREDEF_TYPE_LONG_ID;       break;
447f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::LongLong:   ID = PREDEF_TYPE_LONGLONG_ID;   break;
457f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Int128:     ID = PREDEF_TYPE_INT128_ID;     break;
467f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Half:       ID = PREDEF_TYPE_HALF_ID;       break;
477f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Float:      ID = PREDEF_TYPE_FLOAT_ID;      break;
487f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Double:     ID = PREDEF_TYPE_DOUBLE_ID;     break;
497f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::LongDouble: ID = PREDEF_TYPE_LONGDOUBLE_ID; break;
507f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::NullPtr:    ID = PREDEF_TYPE_NULLPTR_ID;    break;
517f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Char16:     ID = PREDEF_TYPE_CHAR16_ID;     break;
527f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Char32:     ID = PREDEF_TYPE_CHAR32_ID;     break;
537f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Overload:   ID = PREDEF_TYPE_OVERLOAD_ID;   break;
547f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::BoundMember:ID = PREDEF_TYPE_BOUND_MEMBER;  break;
557f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::PseudoObject:ID = PREDEF_TYPE_PSEUDO_OBJECT;break;
567f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::Dependent:  ID = PREDEF_TYPE_DEPENDENT_ID;  break;
577f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::UnknownAny: ID = PREDEF_TYPE_UNKNOWN_ANY;   break;
587f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::ARCUnbridgedCast:
597f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei                                ID = PREDEF_TYPE_ARC_UNBRIDGED_CAST; break;
607f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::ObjCId:     ID = PREDEF_TYPE_OBJC_ID;       break;
617f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::ObjCClass:  ID = PREDEF_TYPE_OBJC_CLASS;    break;
627f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::ObjCSel:    ID = PREDEF_TYPE_OBJC_SEL;      break;
637f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  case BuiltinType::BuiltinFn:
647f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei                                ID = PREDEF_TYPE_BUILTIN_FN; break;
657f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei
667f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  }
677f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei
687f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  return TypeIdx(ID);
697f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei}
707f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei
717f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiunsigned serialization::ComputeHash(Selector Sel) {
727f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  unsigned N = Sel.getNumArgs();
737f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  if (N == 0)
747f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei    ++N;
757f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  unsigned R = 5381;
767f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  for (unsigned I = 0; I != N; ++I)
777f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei    if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
787f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei      R = llvm::HashString(II->getName(), R);
797f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei  return R;
807f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei}
81