Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 1 | //===- ASTCommon.h - 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 | #ifndef LLVM_CLANG_SERIALIZATION_LIB_AST_COMMON_H |
| 15 | #define LLVM_CLANG_SERIALIZATION_LIB_AST_COMMON_H |
| 16 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "clang/Serialization/ASTBitCodes.h" |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 19 | |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 20 | namespace clang { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 21 | |
| 22 | namespace serialization { |
| 23 | |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 24 | enum DeclUpdateKind { |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 25 | UPD_CXX_ADDED_IMPLICIT_MEMBER, |
Sebastian Redl | 7c0837f | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 26 | UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 27 | UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, |
Douglas Gregor | cc32b44 | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 28 | UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 31 | TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT); |
| 32 | |
| 33 | template <typename IdxForTypeTy> |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 34 | TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) { |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 35 | if (T.isNull()) |
| 36 | return PREDEF_TYPE_NULL_ID; |
| 37 | |
| 38 | unsigned FastQuals = T.getLocalFastQualifiers(); |
John McCall | 49f4e1c | 2010-12-10 11:01:00 +0000 | [diff] [blame] | 39 | T.removeLocalFastQualifiers(); |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 40 | |
| 41 | if (T.hasLocalNonFastQualifiers()) |
| 42 | return IdxForType(T).asTypeID(FastQuals); |
| 43 | |
| 44 | assert(!T.hasLocalQualifiers()); |
| 45 | |
| 46 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr())) |
| 47 | return TypeIdxFromBuiltin(BT).asTypeID(FastQuals); |
| 48 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 49 | if (T == Context.AutoDeductTy) |
| 50 | return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals); |
| 51 | if (T == Context.AutoRRefDeductTy) |
| 52 | return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals); |
Meador Inge | fb40e3f | 2012-07-01 15:57:25 +0000 | [diff] [blame] | 53 | if (T == Context.VaListTagTy) |
| 54 | return TypeIdx(PREDEF_TYPE_VA_LIST_TAG).asTypeID(FastQuals); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 55 | |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 56 | return IdxForType(T).asTypeID(FastQuals); |
| 57 | } |
| 58 | |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 59 | unsigned ComputeHash(Selector Sel); |
| 60 | |
Douglas Gregor | 5a04f9f | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 61 | /// \brief Retrieve the "definitive" declaration that provides all of the |
| 62 | /// visible entries for the given declaration context, if there is one. |
| 63 | /// |
| 64 | /// The "definitive" declaration is the only place where we need to look to |
| 65 | /// find information about the declarations within the given declaration |
| 66 | /// context. For example, C++ and Objective-C classes, C structs/unions, and |
| 67 | /// Objective-C protocols, categories, and extensions are all defined in a |
| 68 | /// single place in the source code, so they have definitive declarations |
| 69 | /// associated with them. C++ namespaces, on the other hand, can have |
| 70 | /// multiple definitions. |
Douglas Gregor | e0d2066 | 2013-01-22 17:08:30 +0000 | [diff] [blame] | 71 | const DeclContext *getDefinitiveDeclContext(const DeclContext *DC); |
Douglas Gregor | 5a04f9f | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 72 | |
Douglas Gregor | 9cfdc03 | 2013-01-21 16:16:40 +0000 | [diff] [blame] | 73 | /// \brief Determine whether the given declaration kind is redeclarable. |
| 74 | bool isRedeclarableDeclKind(unsigned Kind); |
| 75 | |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 76 | } // namespace serialization |
| 77 | |
| 78 | } // namespace clang |
| 79 | |
| 80 | #endif |