blob: fa3ef58a1c0808ce865811721258b9fd27e3b794 [file] [log] [blame]
Argyrios Kyrtzidis0eca89e2010-08-20 16:03:52 +00001//===- 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 Gregor3b8043b2011-08-09 15:13:55 +000017#include "clang/AST/ASTContext.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000018#include "clang/Serialization/ASTBitCodes.h"
Argyrios Kyrtzidiseb3f04e2010-08-20 16:04:20 +000019
Argyrios Kyrtzidis0eca89e2010-08-20 16:03:52 +000020namespace clang {
Argyrios Kyrtzidis0eca89e2010-08-20 16:03:52 +000021
22namespace serialization {
23
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +000024enum DeclUpdateKind {
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +000025 UPD_CXX_ADDED_IMPLICIT_MEMBER,
Sebastian Redl7c0837f2011-04-24 16:28:13 +000026 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION,
Sebastian Redlf79a7192011-04-29 08:19:30 +000027 UPD_CXX_ADDED_ANONYMOUS_NAMESPACE,
Richard Smith9dadfab2013-05-11 05:45:24 +000028 UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER,
29 UPD_CXX_DEDUCED_RETURN_TYPE
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +000030};
31
Argyrios Kyrtzidiseb3f04e2010-08-20 16:04:20 +000032TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
33
34template <typename IdxForTypeTy>
Douglas Gregor3b8043b2011-08-09 15:13:55 +000035TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) {
Argyrios Kyrtzidiseb3f04e2010-08-20 16:04:20 +000036 if (T.isNull())
37 return PREDEF_TYPE_NULL_ID;
38
39 unsigned FastQuals = T.getLocalFastQualifiers();
John McCall49f4e1c2010-12-10 11:01:00 +000040 T.removeLocalFastQualifiers();
Argyrios Kyrtzidiseb3f04e2010-08-20 16:04:20 +000041
42 if (T.hasLocalNonFastQualifiers())
43 return IdxForType(T).asTypeID(FastQuals);
44
45 assert(!T.hasLocalQualifiers());
46
47 if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
48 return TypeIdxFromBuiltin(BT).asTypeID(FastQuals);
49
Douglas Gregor3b8043b2011-08-09 15:13:55 +000050 if (T == Context.AutoDeductTy)
51 return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals);
52 if (T == Context.AutoRRefDeductTy)
53 return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals);
Meador Ingefb40e3f2012-07-01 15:57:25 +000054 if (T == Context.VaListTagTy)
55 return TypeIdx(PREDEF_TYPE_VA_LIST_TAG).asTypeID(FastQuals);
Douglas Gregor3b8043b2011-08-09 15:13:55 +000056
Argyrios Kyrtzidiseb3f04e2010-08-20 16:04:20 +000057 return IdxForType(T).asTypeID(FastQuals);
58}
59
Argyrios Kyrtzidis0eca89e2010-08-20 16:03:52 +000060unsigned ComputeHash(Selector Sel);
61
Douglas Gregor5a04f9f2013-01-21 15:25:38 +000062/// \brief Retrieve the "definitive" declaration that provides all of the
63/// visible entries for the given declaration context, if there is one.
64///
65/// The "definitive" declaration is the only place where we need to look to
66/// find information about the declarations within the given declaration
67/// context. For example, C++ and Objective-C classes, C structs/unions, and
68/// Objective-C protocols, categories, and extensions are all defined in a
69/// single place in the source code, so they have definitive declarations
70/// associated with them. C++ namespaces, on the other hand, can have
71/// multiple definitions.
Douglas Gregore0d20662013-01-22 17:08:30 +000072const DeclContext *getDefinitiveDeclContext(const DeclContext *DC);
Douglas Gregor5a04f9f2013-01-21 15:25:38 +000073
Douglas Gregor9cfdc032013-01-21 16:16:40 +000074/// \brief Determine whether the given declaration kind is redeclarable.
75bool isRedeclarableDeclKind(unsigned Kind);
76
Argyrios Kyrtzidis0eca89e2010-08-20 16:03:52 +000077} // namespace serialization
78
79} // namespace clang
80
81#endif