ASTCommon.cpp revision 736104a7619c53ef92553780273d7357a3cdde81
1//===--- ASTCommon.cpp - Common stuff for ASTReader/ASTWriter----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines common functions that both ASTReader and ASTWriter use. 11// 12//===----------------------------------------------------------------------===// 13 14#include "ASTCommon.h" 15#include "clang/Basic/IdentifierTable.h" 16#include "clang/Serialization/ASTDeserializationListener.h" 17#include "llvm/ADT/StringExtras.h" 18 19using namespace clang; 20 21// Give ASTDeserializationListener's VTable a home. 22ASTDeserializationListener::~ASTDeserializationListener() { } 23 24serialization::TypeIdx 25serialization::TypeIdxFromBuiltin(const BuiltinType *BT) { 26 unsigned ID = 0; 27 switch (BT->getKind()) { 28 case BuiltinType::Void: ID = PREDEF_TYPE_VOID_ID; break; 29 case BuiltinType::Bool: ID = PREDEF_TYPE_BOOL_ID; break; 30 case BuiltinType::Char_U: ID = PREDEF_TYPE_CHAR_U_ID; break; 31 case BuiltinType::UChar: ID = PREDEF_TYPE_UCHAR_ID; break; 32 case BuiltinType::UShort: ID = PREDEF_TYPE_USHORT_ID; break; 33 case BuiltinType::UInt: ID = PREDEF_TYPE_UINT_ID; break; 34 case BuiltinType::ULong: ID = PREDEF_TYPE_ULONG_ID; break; 35 case BuiltinType::ULongLong: ID = PREDEF_TYPE_ULONGLONG_ID; break; 36 case BuiltinType::UInt128: ID = PREDEF_TYPE_UINT128_ID; break; 37 case BuiltinType::Char_S: ID = PREDEF_TYPE_CHAR_S_ID; break; 38 case BuiltinType::SChar: ID = PREDEF_TYPE_SCHAR_ID; break; 39 case BuiltinType::WChar_S: 40 case BuiltinType::WChar_U: ID = PREDEF_TYPE_WCHAR_ID; break; 41 case BuiltinType::Short: ID = PREDEF_TYPE_SHORT_ID; break; 42 case BuiltinType::Int: ID = PREDEF_TYPE_INT_ID; break; 43 case BuiltinType::Long: ID = PREDEF_TYPE_LONG_ID; break; 44 case BuiltinType::LongLong: ID = PREDEF_TYPE_LONGLONG_ID; break; 45 case BuiltinType::Int128: ID = PREDEF_TYPE_INT128_ID; break; 46 case BuiltinType::Half: ID = PREDEF_TYPE_HALF_ID; break; 47 case BuiltinType::Float: ID = PREDEF_TYPE_FLOAT_ID; break; 48 case BuiltinType::Double: ID = PREDEF_TYPE_DOUBLE_ID; break; 49 case BuiltinType::LongDouble: ID = PREDEF_TYPE_LONGDOUBLE_ID; break; 50 case BuiltinType::NullPtr: ID = PREDEF_TYPE_NULLPTR_ID; break; 51 case BuiltinType::Char16: ID = PREDEF_TYPE_CHAR16_ID; break; 52 case BuiltinType::Char32: ID = PREDEF_TYPE_CHAR32_ID; break; 53 case BuiltinType::Overload: ID = PREDEF_TYPE_OVERLOAD_ID; break; 54 case BuiltinType::BoundMember:ID = PREDEF_TYPE_BOUND_MEMBER; break; 55 case BuiltinType::PseudoObject:ID = PREDEF_TYPE_PSEUDO_OBJECT;break; 56 case BuiltinType::Dependent: ID = PREDEF_TYPE_DEPENDENT_ID; break; 57 case BuiltinType::UnknownAny: ID = PREDEF_TYPE_UNKNOWN_ANY; break; 58 case BuiltinType::ARCUnbridgedCast: 59 ID = PREDEF_TYPE_ARC_UNBRIDGED_CAST; break; 60 case BuiltinType::ObjCId: ID = PREDEF_TYPE_OBJC_ID; break; 61 case BuiltinType::ObjCClass: ID = PREDEF_TYPE_OBJC_CLASS; break; 62 case BuiltinType::ObjCSel: ID = PREDEF_TYPE_OBJC_SEL; break; 63 case BuiltinType::OCLImage1d: ID = PREDEF_TYPE_IMAGE1D_ID; break; 64 case BuiltinType::OCLImage1dArray: ID = PREDEF_TYPE_IMAGE1D_ARR_ID; break; 65 case BuiltinType::OCLImage1dBuffer: ID = PREDEF_TYPE_IMAGE1D_BUFF_ID; break; 66 case BuiltinType::OCLImage2d: ID = PREDEF_TYPE_IMAGE2D_ID; break; 67 case BuiltinType::OCLImage2dArray: ID = PREDEF_TYPE_IMAGE2D_ARR_ID; break; 68 case BuiltinType::OCLImage3d: ID = PREDEF_TYPE_IMAGE3D_ID; break; 69 case BuiltinType::BuiltinFn: 70 ID = PREDEF_TYPE_BUILTIN_FN; break; 71 72 } 73 74 return TypeIdx(ID); 75} 76 77unsigned serialization::ComputeHash(Selector Sel) { 78 unsigned N = Sel.getNumArgs(); 79 if (N == 0) 80 ++N; 81 unsigned R = 5381; 82 for (unsigned I = 0; I != N; ++I) 83 if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I)) 84 R = llvm::HashString(II->getName(), R); 85 return R; 86} 87