Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 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" |
Argyrios Kyrtzidis | 336d43a | 2010-10-14 20:14:28 +0000 | [diff] [blame] | 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "clang/Basic/IdentifierTable.h" |
| 17 | #include "llvm/ADT/StringExtras.h" |
| 18 | |
| 19 | using namespace clang; |
| 20 | |
Argyrios Kyrtzidis | 336d43a | 2010-10-14 20:14:28 +0000 | [diff] [blame] | 21 | // Give ASTDeserializationListener's VTable a home. |
| 22 | ASTDeserializationListener::~ASTDeserializationListener() { } |
| 23 | |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 24 | serialization::TypeIdx |
| 25 | serialization::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; |
Chris Lattner | 3f59c97 | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 39 | case BuiltinType::WChar_S: |
| 40 | case BuiltinType::WChar_U: ID = PREDEF_TYPE_WCHAR_ID; break; |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 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; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame^] | 46 | case BuiltinType::Half: ID = PREDEF_TYPE_HALF_ID; break; |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 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; |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 54 | case BuiltinType::BoundMember:ID = PREDEF_TYPE_BOUND_MEMBER; break; |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 55 | case BuiltinType::Dependent: ID = PREDEF_TYPE_DEPENDENT_ID; break; |
John McCall | 1de4d4e | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 56 | case BuiltinType::UnknownAny: ID = PREDEF_TYPE_UNKNOWN_ANY; break; |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 57 | case BuiltinType::ObjCId: ID = PREDEF_TYPE_OBJC_ID; break; |
| 58 | case BuiltinType::ObjCClass: ID = PREDEF_TYPE_OBJC_CLASS; break; |
| 59 | case BuiltinType::ObjCSel: ID = PREDEF_TYPE_OBJC_SEL; break; |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | return TypeIdx(ID); |
| 63 | } |
| 64 | |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 65 | unsigned serialization::ComputeHash(Selector Sel) { |
| 66 | unsigned N = Sel.getNumArgs(); |
| 67 | if (N == 0) |
| 68 | ++N; |
| 69 | unsigned R = 5381; |
| 70 | for (unsigned I = 0; I != N; ++I) |
| 71 | if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I)) |
| 72 | R = llvm::HashString(II->getName(), R); |
| 73 | return R; |
| 74 | } |