blob: 9f4d7a9acddeb5464c5b8384003aa5655f4952c2 [file] [log] [blame]
Argyrios Kyrtzidis4bd97102010-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 Gregoreda8e122011-08-09 15:13:55 +000017#include "clang/AST/ASTContext.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/Serialization/ASTBitCodes.h"
Argyrios Kyrtzidis082e4612010-08-20 16:04:20 +000019
Argyrios Kyrtzidis4bd97102010-08-20 16:03:52 +000020namespace clang {
Argyrios Kyrtzidis4bd97102010-08-20 16:03:52 +000021
22namespace serialization {
23
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +000024enum DeclUpdateKind {
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +000025 UPD_CXX_ADDED_IMPLICIT_MEMBER,
Sebastian Redlfa1f3702011-04-24 16:28:13 +000026 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION,
Sebastian Redl2ac2c722011-04-29 08:19:30 +000027 UPD_CXX_ADDED_ANONYMOUS_NAMESPACE,
Richard Smith1fa5d642013-05-11 05:45:24 +000028 UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER,
Richard Smith564417a2014-03-20 21:47:22 +000029 UPD_CXX_RESOLVED_EXCEPTION_SPEC,
Eli Friedman276dd182013-09-05 00:02:25 +000030 UPD_CXX_DEDUCED_RETURN_TYPE,
Richard Smith5652c0f2014-03-21 01:48:23 +000031 UPD_DECL_MARKED_USED,
32 UPD_MANGLING_NUMBER,
33 UPD_STATIC_LOCAL_NUMBER
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +000034};
35
Argyrios Kyrtzidis082e4612010-08-20 16:04:20 +000036TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
37
38template <typename IdxForTypeTy>
Douglas Gregoreda8e122011-08-09 15:13:55 +000039TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) {
Argyrios Kyrtzidis082e4612010-08-20 16:04:20 +000040 if (T.isNull())
41 return PREDEF_TYPE_NULL_ID;
42
43 unsigned FastQuals = T.getLocalFastQualifiers();
John McCall717d9b02010-12-10 11:01:00 +000044 T.removeLocalFastQualifiers();
Argyrios Kyrtzidis082e4612010-08-20 16:04:20 +000045
46 if (T.hasLocalNonFastQualifiers())
47 return IdxForType(T).asTypeID(FastQuals);
48
49 assert(!T.hasLocalQualifiers());
50
51 if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
52 return TypeIdxFromBuiltin(BT).asTypeID(FastQuals);
53
Douglas Gregoreda8e122011-08-09 15:13:55 +000054 if (T == Context.AutoDeductTy)
55 return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals);
56 if (T == Context.AutoRRefDeductTy)
57 return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals);
Meador Ingecfb60902012-07-01 15:57:25 +000058 if (T == Context.VaListTagTy)
59 return TypeIdx(PREDEF_TYPE_VA_LIST_TAG).asTypeID(FastQuals);
Douglas Gregoreda8e122011-08-09 15:13:55 +000060
Argyrios Kyrtzidis082e4612010-08-20 16:04:20 +000061 return IdxForType(T).asTypeID(FastQuals);
62}
63
Argyrios Kyrtzidis4bd97102010-08-20 16:03:52 +000064unsigned ComputeHash(Selector Sel);
65
Douglas Gregor9f782892013-01-21 15:25:38 +000066/// \brief Retrieve the "definitive" declaration that provides all of the
67/// visible entries for the given declaration context, if there is one.
68///
69/// The "definitive" declaration is the only place where we need to look to
70/// find information about the declarations within the given declaration
71/// context. For example, C++ and Objective-C classes, C structs/unions, and
72/// Objective-C protocols, categories, and extensions are all defined in a
73/// single place in the source code, so they have definitive declarations
74/// associated with them. C++ namespaces, on the other hand, can have
75/// multiple definitions.
Douglas Gregor7a6e2002013-01-22 17:08:30 +000076const DeclContext *getDefinitiveDeclContext(const DeclContext *DC);
Douglas Gregor9f782892013-01-21 15:25:38 +000077
Douglas Gregorfe732d52013-01-21 16:16:40 +000078/// \brief Determine whether the given declaration kind is redeclarable.
79bool isRedeclarableDeclKind(unsigned Kind);
80
Argyrios Kyrtzidis4bd97102010-08-20 16:03:52 +000081} // namespace serialization
82
83} // namespace clang
84
85#endif