clang  3.7.0
ASTCommon.h
Go to the documentation of this file.
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_LIB_SERIALIZATION_ASTCOMMON_H
15 #define LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H
16 
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/DeclFriend.h"
20 
21 namespace clang {
22 
23 namespace serialization {
24 
41 };
42 
43 TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
44 
45 template <typename IdxForTypeTy>
46 TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) {
47  if (T.isNull())
48  return PREDEF_TYPE_NULL_ID;
49 
50  unsigned FastQuals = T.getLocalFastQualifiers();
52 
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 
61  if (T == Context.AutoDeductTy)
62  return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals);
63  if (T == Context.AutoRRefDeductTy)
65  if (T == Context.VaListTagTy)
66  return TypeIdx(PREDEF_TYPE_VA_LIST_TAG).asTypeID(FastQuals);
67 
68  return IdxForType(T).asTypeID(FastQuals);
69 }
70 
71 unsigned ComputeHash(Selector Sel);
72 
73 /// \brief Retrieve the "definitive" declaration that provides all of the
74 /// visible entries for the given declaration context, if there is one.
75 ///
76 /// The "definitive" declaration is the only place where we need to look to
77 /// find information about the declarations within the given declaration
78 /// context. For example, C++ and Objective-C classes, C structs/unions, and
79 /// Objective-C protocols, categories, and extensions are all defined in a
80 /// single place in the source code, so they have definitive declarations
81 /// associated with them. C++ namespaces, on the other hand, can have
82 /// multiple definitions.
84 
85 /// \brief Determine whether the given declaration kind is redeclarable.
86 bool isRedeclarableDeclKind(unsigned Kind);
87 
88 /// \brief Determine whether the given declaration needs an anonymous
89 /// declaration number.
91 
92 /// \brief Visit each declaration within \c DC that needs an anonymous
93 /// declaration number and call \p Visit with the declaration and its number.
94 template<typename Fn> void numberAnonymousDeclsWithin(const DeclContext *DC,
95  Fn Visit) {
96  unsigned Index = 0;
97  for (Decl *LexicalD : DC->decls()) {
98  // For a friend decl, we care about the declaration within it, if any.
99  if (auto *FD = dyn_cast<FriendDecl>(LexicalD))
100  LexicalD = FD->getFriendDecl();
101 
102  auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD);
103  if (!ND || !needsAnonymousDeclarationNumber(ND))
104  continue;
105 
106  Visit(ND, Index++);
107  }
108 }
109 
110 } // namespace serialization
111 
112 } // namespace clang
113 
114 #endif
Defines the clang::ASTContext interface.
Smart pointer class that efficiently represents Objective-C method names.
bool isRedeclarableDeclKind(unsigned Kind)
Determine whether the given declaration kind is redeclarable.
Definition: ASTCommon.cpp:151
decl_range decls() const
Definition: DeclBase.h:1413
const DeclContext * getDefinitiveDeclContext(const DeclContext *DC)
Retrieve the "definitive" declaration that provides all of the visible entries for the given declarat...
Definition: ASTCommon.cpp:93
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType)
Definition: ASTCommon.h:46
ASTContext * Context
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:670
unsigned getLocalFastQualifiers() const
Definition: Type.h:596
Kind
const Type * getTypePtr() const
Definition: Type.h:5016
TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT)
Definition: ASTCommon.cpp:27
The __va_list_tag placeholder type.
Definition: ASTBitCodes.h:762
QualType AutoDeductTy
Definition: ASTContext.h:843
unsigned ComputeHash(Selector Sel)
Definition: ASTCommon.cpp:81
void removeLocalFastQualifiers()
Definition: Type.h:771
bool hasLocalNonFastQualifiers() const
Determine whether this particular QualType instance has any "non-fast" qualifiers, e.g., those that are stored in an ExtQualType instance.
Definition: Type.h:680
QualType AutoRRefDeductTy
Definition: ASTContext.h:844
TypeID asTypeID(unsigned FastQuals) const
Definition: ASTBitCodes.h:92
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
Definition: ASTCommon.cpp:231
QualType VaListTagTy
Definition: ASTContext.h:848
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:82
void numberAnonymousDeclsWithin(const DeclContext *DC, Fn Visit)
Visit each declaration within DC that needs an anonymous declaration number and call Visit with the d...
Definition: ASTCommon.h:94
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
Definition: Type.h:633
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:85