| Argyrios Kyrtzidis | 4bd9710 | 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 |  | 
| Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H | 
|  | 15 | #define LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H | 
| Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 |  | 
| Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" | 
| Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclFriend.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "clang/Serialization/ASTBitCodes.h" | 
| Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 20 |  | 
| Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 21 | namespace clang { | 
| Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 22 |  | 
|  | 23 | namespace serialization { | 
|  | 24 |  | 
| Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 25 | enum DeclUpdateKind { | 
| Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 26 | UPD_CXX_ADDED_IMPLICIT_MEMBER, | 
| Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 27 | UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, | 
| Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 28 | UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, | 
| Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 29 | UPD_CXX_ADDED_FUNCTION_DEFINITION, | 
| Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 30 | UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 31 | UPD_CXX_INSTANTIATED_CLASS_DEFINITION, | 
| Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 32 | UPD_CXX_RESOLVED_DTOR_DELETE, | 
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 33 | UPD_CXX_RESOLVED_EXCEPTION_SPEC, | 
| Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 34 | UPD_CXX_DEDUCED_RETURN_TYPE, | 
| Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 35 | UPD_DECL_MARKED_USED, | 
|  | 36 | UPD_MANGLING_NUMBER, | 
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 37 | UPD_STATIC_LOCAL_NUMBER, | 
| Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 38 | UPD_DECL_MARKED_OPENMP_THREADPRIVATE, | 
| Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 39 | UPD_DECL_EXPORTED, | 
|  | 40 | UPD_ADDED_ATTR_TO_RECORD | 
| Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 41 | }; | 
|  | 42 |  | 
| Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 43 | TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT); | 
|  | 44 |  | 
|  | 45 | template <typename IdxForTypeTy> | 
| Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 46 | TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) { | 
| Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 47 | if (T.isNull()) | 
|  | 48 | return PREDEF_TYPE_NULL_ID; | 
|  | 49 |  | 
|  | 50 | unsigned FastQuals = T.getLocalFastQualifiers(); | 
| John McCall | 717d9b0 | 2010-12-10 11:01:00 +0000 | [diff] [blame] | 51 | T.removeLocalFastQualifiers(); | 
| Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 52 |  | 
|  | 53 | if (T.hasLocalNonFastQualifiers()) | 
|  | 54 | return IdxForType(T).asTypeID(FastQuals); | 
|  | 55 |  | 
|  | 56 | assert(!T.hasLocalQualifiers()); | 
|  | 57 |  | 
|  | 58 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr())) | 
|  | 59 | return TypeIdxFromBuiltin(BT).asTypeID(FastQuals); | 
|  | 60 |  | 
| Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 61 | if (T == Context.AutoDeductTy) | 
|  | 62 | return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals); | 
|  | 63 | if (T == Context.AutoRRefDeductTy) | 
|  | 64 | return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals); | 
|  | 65 |  | 
| Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 66 | return IdxForType(T).asTypeID(FastQuals); | 
|  | 67 | } | 
|  | 68 |  | 
| Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 69 | unsigned ComputeHash(Selector Sel); | 
|  | 70 |  | 
| Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 71 | /// \brief Retrieve the "definitive" declaration that provides all of the | 
|  | 72 | /// visible entries for the given declaration context, if there is one. | 
|  | 73 | /// | 
|  | 74 | /// The "definitive" declaration is the only place where we need to look to | 
|  | 75 | /// find information about the declarations within the given declaration | 
|  | 76 | /// context. For example, C++ and Objective-C classes, C structs/unions, and | 
|  | 77 | /// Objective-C protocols, categories, and extensions are all defined in a | 
|  | 78 | /// single place in the source code, so they have definitive declarations | 
|  | 79 | /// associated with them. C++ namespaces, on the other hand, can have | 
|  | 80 | /// multiple definitions. | 
| Douglas Gregor | 7a6e200 | 2013-01-22 17:08:30 +0000 | [diff] [blame] | 81 | const DeclContext *getDefinitiveDeclContext(const DeclContext *DC); | 
| Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 82 |  | 
| Douglas Gregor | fe732d5 | 2013-01-21 16:16:40 +0000 | [diff] [blame] | 83 | /// \brief Determine whether the given declaration kind is redeclarable. | 
|  | 84 | bool isRedeclarableDeclKind(unsigned Kind); | 
|  | 85 |  | 
| Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 86 | /// \brief Determine whether the given declaration needs an anonymous | 
|  | 87 | /// declaration number. | 
|  | 88 | bool needsAnonymousDeclarationNumber(const NamedDecl *D); | 
|  | 89 |  | 
| Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 90 | /// \brief Visit each declaration within \c DC that needs an anonymous | 
|  | 91 | /// declaration number and call \p Visit with the declaration and its number. | 
|  | 92 | template<typename Fn> void numberAnonymousDeclsWithin(const DeclContext *DC, | 
|  | 93 | Fn Visit) { | 
|  | 94 | unsigned Index = 0; | 
|  | 95 | for (Decl *LexicalD : DC->decls()) { | 
|  | 96 | // For a friend decl, we care about the declaration within it, if any. | 
|  | 97 | if (auto *FD = dyn_cast<FriendDecl>(LexicalD)) | 
|  | 98 | LexicalD = FD->getFriendDecl(); | 
|  | 99 |  | 
|  | 100 | auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD); | 
|  | 101 | if (!ND || !needsAnonymousDeclarationNumber(ND)) | 
|  | 102 | continue; | 
|  | 103 |  | 
|  | 104 | Visit(ND, Index++); | 
|  | 105 | } | 
|  | 106 | } | 
|  | 107 |  | 
| Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 108 | } // namespace serialization | 
|  | 109 |  | 
|  | 110 | } // namespace clang | 
|  | 111 |  | 
|  | 112 | #endif |