-//===-- CanonicalType.h - C Language Family Type Representation -*- C++ -*-===//
+//===- CanonicalType.h - C Language Family Type Representation --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
#define LLVM_CLANG_AST_CANONICALTYPE_H
#include "clang/AST/Type.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Support/Casting.h"
+#include "llvm/Support/PointerLikeTypeTraits.h"
+#include <cassert>
+#include <iterator>
+#include <type_traits>
namespace clang {
template<typename T> class CanProxy;
template<typename T> struct CanProxyAdaptor;
+class CXXRecordDecl;
+class EnumDecl;
+class Expr;
+class IdentifierInfo;
+class ObjCInterfaceDecl;
+class RecordDecl;
+class TagDecl;
+class TemplateTypeParmDecl;
//----------------------------------------------------------------------------//
// Canonical, qualified type template
/// converted to @c CanQual<ReferenceType>. Note that any @c CanQual type can
/// be implicitly converted to a QualType, but the reverse operation requires
/// a call to ASTContext::getCanonicalType().
-///
-///
template<typename T = Type>
class CanQual {
/// \brief The actual, canonical type.
public:
/// \brief Constructs a NULL canonical type.
- CanQual() : Stored() { }
+ CanQual() = default;
/// \brief Converting constructor that permits implicit upcasting of
/// canonical type pointers.
/// \brief Retrieve the underlying type pointer, which refers to a
/// canonical type.
///
- /// The underlying pointer must not be NULL.
+ /// The underlying pointer must not be nullptr.
const T *getTypePtr() const { return cast<T>(Stored.getTypePtr()); }
/// \brief Retrieve the underlying type pointer, which refers to a
- /// canonical type, or NULL.
- ///
+ /// canonical type, or nullptr.
const T *getTypePtrOrNull() const {
return cast_or_null<T>(Stored.getTypePtrOrNull());
}
bool isConstQualified() const {
return Stored.isLocalConstQualified();
}
+
bool isVolatileQualified() const {
return Stored.isLocalVolatileQualified();
}
+
bool isRestrictQualified() const {
return Stored.isLocalRestrictQualified();
}
}
/// \brief Represents a canonical, potentially-qualified type.
-typedef CanQual<Type> CanQualType;
+using CanQualType = CanQual<Type>;
inline CanQualType Type::getCanonicalTypeUnqualified() const {
return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
/// than the more typical @c QualType, to propagate the notion of "canonical"
/// through the system.
template<typename T>
-struct CanProxyAdaptor : CanProxyBase<T> { };
+struct CanProxyAdaptor : CanProxyBase<T> {};
/// \brief Canonical proxy type returned when retrieving the members of a
/// canonical type or as the result of the @c CanQual<T>::getAs member
class CanProxy : public CanProxyAdaptor<T> {
public:
/// \brief Build a NULL proxy.
- CanProxy() { }
+ CanProxy() = default;
/// \brief Build a proxy to the given canonical type.
CanProxy(CanQual<T> Stored) { this->Stored = Stored; }
operator CanQual<T>() const { return this->Stored; }
};
-} // end namespace clang
+} // namespace clang
namespace llvm {
/// CanQual<T> to a specific Type class. We're prefer isa/dyn_cast/cast/etc.
/// to return smart pointer (proxies?).
template<typename T>
-struct simplify_type< ::clang::CanQual<T> > {
- typedef const T *SimpleType;
+struct simplify_type< ::clang::CanQual<T>> {
+ using SimpleType = const T *;
+
static SimpleType getSimplifiedValue(::clang::CanQual<T> Val) {
return Val.getTypePtr();
}
// Teach SmallPtrSet that CanQual<T> is "basically a pointer".
template<typename T>
-struct PointerLikeTypeTraits<clang::CanQual<T> > {
- static inline void *getAsVoidPointer(clang::CanQual<T> P) {
+struct PointerLikeTypeTraits<clang::CanQual<T>> {
+ static void *getAsVoidPointer(clang::CanQual<T> P) {
return P.getAsOpaquePtr();
}
- static inline clang::CanQual<T> getFromVoidPointer(void *P) {
+
+ static clang::CanQual<T> getFromVoidPointer(void *P) {
return clang::CanQual<T>::getFromOpaquePtr(P);
}
+
// qualifier information is encoded in the low bits.
enum { NumLowBitsAvailable = 0 };
};
-} // end namespace llvm
+} // namespace llvm
namespace clang {
CanQualType,
typename std::iterator_traits<InputIterator>::difference_type,
CanProxy<Type>, CanQualType> {
- CanTypeIterator() {}
+ CanTypeIterator() = default;
explicit CanTypeIterator(InputIterator Iter)
: CanTypeIterator::iterator_adaptor_base(std::move(Iter)) {}
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasExtParameterInfos)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(
ArrayRef<FunctionProtoType::ExtParameterInfo>, getExtParameterInfos)
+
CanQualType getParamType(unsigned i) const {
return CanQualType::CreateUnsafe(this->getTypePtr()->getParamType(i));
}
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariadic)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getTypeQuals)
- typedef CanTypeIterator<FunctionProtoType::param_type_iterator>
- param_type_iterator;
+ using param_type_iterator =
+ CanTypeIterator<FunctionProtoType::param_type_iterator>;
param_type_iterator param_type_begin() const {
return param_type_iterator(this->getTypePtr()->param_type_begin());
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedId)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClass)
- typedef ObjCObjectPointerType::qual_iterator qual_iterator;
+ using qual_iterator = ObjCObjectPointerType::qual_iterator;
+
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, qual_empty)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedIdType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClassType)
- typedef ObjCObjectPointerType::qual_iterator qual_iterator;
+ using qual_iterator = ObjCObjectPointerType::qual_iterator;
+
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, qual_empty)
return CanProxy<Type>(*this);
}
-}
-
+} // namespace clang
-#endif
+#endif // LLVM_CLANG_AST_CANONICALTYPE_H
-//===-- DeclBase.h - Base Classes for representing declarations -*- C++ -*-===//
+//===- DeclBase.h - Base Classes for representing declarations --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
#include "clang/AST/AttrIterator.h"
#include "clang/AST/DeclarationName.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/VersionTuple.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/PrettyStackTrace.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <iterator>
+#include <string>
+#include <type_traits>
+#include <utility>
namespace clang {
+
+class ASTContext;
class ASTMutationListener;
-class BlockDecl;
-class CXXRecordDecl;
-class CompoundStmt;
+class Attr;
class DeclContext;
-class DeclarationName;
-class DependentDiagnostic;
-class EnumDecl;
-class ExportDecl;
class ExternalSourceSymbolAttr;
class FunctionDecl;
class FunctionType;
+class IdentifierInfo;
enum Linkage : unsigned char;
-class LinkageComputer;
class LinkageSpecDecl;
class Module;
class NamedDecl;
-class NamespaceDecl;
class ObjCCategoryDecl;
class ObjCCategoryImplDecl;
class ObjCContainerDecl;
class ObjCProtocolDecl;
struct PrintingPolicy;
class RecordDecl;
+class SourceManager;
class Stmt;
class StoredDeclsMap;
class TemplateDecl;
class TranslationUnitDecl;
class UsingDirectiveDecl;
-}
-namespace clang {
-
- /// \brief Captures the result of checking the availability of a
- /// declaration.
- enum AvailabilityResult {
- AR_Available = 0,
- AR_NotYetIntroduced,
- AR_Deprecated,
- AR_Unavailable
- };
+/// \brief Captures the result of checking the availability of a
+/// declaration.
+enum AvailabilityResult {
+ AR_Available = 0,
+ AR_NotYetIntroduced,
+ AR_Deprecated,
+ AR_Unavailable
+};
/// Decl - This represents one declaration (or definition), e.g. a variable,
/// typedef, function, struct, etc.
/// \brief A placeholder type used to construct an empty shell of a
/// decl-derived type that will be filled in later (e.g., by some
/// deserialization method).
- struct EmptyShell { };
+ struct EmptyShell {};
/// IdentifierNamespace - The different namespaces in which
/// declarations may appear. According to C99 6.2.3, there are
enum class ModuleOwnershipKind : unsigned {
/// This declaration is not owned by a module.
Unowned,
+
/// This declaration has an owning module, but is globally visible
/// (typically because its owning module is visible and we know that
/// modules cannot later become hidden in this compilation).
/// After serialization and deserialization, this will be converted
/// to VisibleWhenImported.
Visible,
+
/// This declaration has an owning module, and is visible when that
/// module is imported.
VisibleWhenImported,
+
/// This declaration has an owning module, but is only visible to
/// lookups that occur within that module.
ModulePrivate
DeclContext *LexicalDC;
};
-
/// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
/// For declarations that don't contain C++ scope specifiers, it contains
/// the DeclContext where the Decl was declared.
/// // LexicalDC == global namespace
llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
- inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
- inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
- inline MultipleDC *getMultipleDC() const {
+ bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
+ bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
+
+ MultipleDC *getMultipleDC() const {
return DeclCtx.get<MultipleDC*>();
}
- inline DeclContext *getSemanticDC() const {
+
+ DeclContext *getSemanticDC() const {
return DeclCtx.get<DeclContext*>();
}
static bool StatisticsEnabled;
protected:
+ friend class ASTDeclReader;
+ friend class ASTDeclWriter;
+ friend class ASTReader;
+ friend class CXXClassMemberWrapper;
+ friend class LinkageComputer;
+ template<typename decl_type> friend class Redeclarable;
+
/// Access - Used by C++ decls for the access specifier.
// NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
unsigned Access : 2;
- friend class CXXClassMemberWrapper;
/// \brief Whether this declaration was loaded from an AST file.
unsigned FromASTFile : 1;
/// Otherwise, it is the linkage + 1.
mutable unsigned CacheValidAndLinkage : 3;
- friend class ASTDeclWriter;
- friend class ASTDeclReader;
- friend class ASTReader;
- friend class LinkageComputer;
-
- template<typename decl_type> friend class Redeclarable;
-
/// \brief Allocate memory for a deserialized declaration.
///
/// This routine must be used to allocate memory for any declaration that is
protected:
Decl(Kind DK, DeclContext *DC, SourceLocation L)
: NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
- DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(0), HasAttrs(false),
+ DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
Implicit(false), Used(false), Referenced(false),
TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
}
Decl(Kind DK, EmptyShell Empty)
- : NextInContextAndBits(), DeclKind(DK), InvalidDecl(0), HasAttrs(false),
- Implicit(false), Used(false), Referenced(false),
- TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+ : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+ Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+ Access(AS_none), FromASTFile(0),
IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
CacheValidAndLinkage(0) {
if (StatisticsEnabled) add(DK);
}
public:
-
/// \brief Source range that this declaration covers.
virtual SourceRange getSourceRange() const LLVM_READONLY {
return SourceRange(getLocation(), getLocation());
}
+
SourceLocation getLocStart() const LLVM_READONLY {
return getSourceRange().getBegin();
}
+
SourceLocation getLocEnd() const LLVM_READONLY {
return getSourceRange().getEnd();
}
}
bool hasAttrs() const { return HasAttrs; }
+
void setAttrs(const AttrVec& Attrs) {
return setAttrsImpl(Attrs, getASTContext());
}
+
AttrVec &getAttrs() {
return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs());
}
+
const AttrVec &getAttrs() const;
void dropAttrs();
setAttrs(AttrVec(1, A));
}
- typedef AttrVec::const_iterator attr_iterator;
- typedef llvm::iterator_range<attr_iterator> attr_range;
+ using attr_iterator = AttrVec::const_iterator;
+ using attr_range = llvm::iterator_range<attr_iterator>;
attr_range attrs() const {
return attr_range(attr_begin(), attr_end());
specific_attr_iterator<T> specific_attr_begin() const {
return specific_attr_iterator<T>(attr_begin());
}
+
template <typename T>
specific_attr_iterator<T> specific_attr_end() const {
return specific_attr_iterator<T>(attr_end());
template<typename T> T *getAttr() const {
return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : nullptr;
}
+
template<typename T> bool hasAttr() const {
return hasAttrs() && hasSpecificAttr<T>(getAttrs());
}
}
public:
-
/// \brief Determine the availability of the given declaration.
///
/// This routine will determine the most restrictive availability of
private:
Module *getOwningModuleSlow() const;
+
protected:
bool hasLocalOwningModuleStorage() const;
unsigned getIdentifierNamespace() const {
return IdentifierNamespace;
}
+
bool isInIdentifierNamespace(unsigned NS) const {
return getIdentifierNamespace() & NS;
}
+
static unsigned getIdentifierNamespaceForKind(Kind DK);
bool hasTagIdentifierNamespace() const {
return isTagIdentifierNamespace(getIdentifierNamespace());
}
+
static bool isTagIdentifierNamespace(unsigned NS) {
// TagDecls have Tag and Type set and may also have TagFriend.
return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type);
/// \brief Iterates through all the redeclarations of the same decl.
class redecl_iterator {
/// Current - The current declaration.
- Decl *Current;
+ Decl *Current = nullptr;
Decl *Starter;
public:
- typedef Decl *value_type;
- typedef const value_type &reference;
- typedef const value_type *pointer;
- typedef std::forward_iterator_tag iterator_category;
- typedef std::ptrdiff_t difference_type;
+ using value_type = Decl *;
+ using reference = const value_type &;
+ using pointer = const value_type *;
+ using iterator_category = std::forward_iterator_tag;
+ using difference_type = std::ptrdiff_t;
- redecl_iterator() : Current(nullptr) { }
- explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { }
+ redecl_iterator() = default;
+ explicit redecl_iterator(Decl *C) : Current(C), Starter(C) {}
reference operator*() const { return Current; }
value_type operator->() const { return Current; }
friend bool operator==(redecl_iterator x, redecl_iterator y) {
return x.Current == y.Current;
}
+
friend bool operator!=(redecl_iterator x, redecl_iterator y) {
return x.Current != y.Current;
}
};
- typedef llvm::iterator_range<redecl_iterator> redecl_range;
+ using redecl_range = llvm::iterator_range<redecl_iterator>;
/// \brief Returns an iterator range for all the redeclarations of the same
/// decl. It will iterate at least once (when this decl is the only one).
redecl_iterator redecls_begin() const {
return redecl_iterator(const_cast<Decl *>(this));
}
+
redecl_iterator redecls_end() const { return redecl_iterator(); }
/// \brief Retrieve the previous declaration that declares the same entity
static void printGroup(Decl** Begin, unsigned NumDecls,
raw_ostream &Out, const PrintingPolicy &Policy,
unsigned Indentation = 0);
+
// Debuggers don't usually respect default arguments.
void dump() const;
+
// Same as dump(), but forces color printing.
void dumpColor() const;
+
void dump(raw_ostream &Out, bool Deserialize = false) const;
/// \brief Looks through the Decl's underlying type to extract a FunctionType
SourceLocation Loc;
SourceManager &SM;
const char *Message;
+
public:
PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L,
SourceManager &sm, const char *Msg)
- : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {}
+ : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {}
void print(raw_ostream &OS) const override;
};
/// single result (with no stable storage) or a collection of results (with
/// stable storage provided by the lookup table).
class DeclContextLookupResult {
- typedef ArrayRef<NamedDecl *> ResultTy;
+ using ResultTy = ArrayRef<NamedDecl *>;
+
ResultTy Result;
+
// If there is only one lookup result, it would be invalidated by
// reallocations of the name table, so store it separately.
- NamedDecl *Single;
+ NamedDecl *Single = nullptr;
static NamedDecl *const SingleElementDummyList;
public:
- DeclContextLookupResult() : Result(), Single() {}
+ DeclContextLookupResult() = default;
DeclContextLookupResult(ArrayRef<NamedDecl *> Result)
- : Result(Result), Single() {}
+ : Result(Result) {}
DeclContextLookupResult(NamedDecl *Single)
: Result(SingleElementDummyList), Single(Single) {}
class iterator;
- typedef llvm::iterator_adaptor_base<iterator, ResultTy::iterator,
- std::random_access_iterator_tag,
- NamedDecl *const> IteratorBase;
+
+ using IteratorBase =
+ llvm::iterator_adaptor_base<iterator, ResultTy::iterator,
+ std::random_access_iterator_tag,
+ NamedDecl *const>;
+
class iterator : public IteratorBase {
value_type SingleElement;
public:
- iterator() : IteratorBase(), SingleElement() {}
+ iterator() = default;
explicit iterator(pointer Pos, value_type Single = nullptr)
: IteratorBase(Pos), SingleElement(Single) {}
return SingleElement ? SingleElement : IteratorBase::operator*();
}
};
- typedef iterator const_iterator;
- typedef iterator::pointer pointer;
- typedef iterator::reference reference;
+
+ using const_iterator = iterator;
+ using pointer = iterator::pointer;
+ using reference = iterator::reference;
iterator begin() const { return iterator(Result.begin(), Single); }
iterator end() const { return iterator(Result.end(), Single); }
/// ExportDecl
/// BlockDecl
/// OMPDeclareReductionDecl
-///
class DeclContext {
/// DeclKind - This indicates which class this is.
unsigned DeclKind : 8;
/// contains an entry for a DeclarationName (and we haven't lazily
/// omitted anything), then it contains all relevant entries for that
/// name (modulo the hasExternalDecls() flag).
- mutable StoredDeclsMap *LookupPtr;
+ mutable StoredDeclsMap *LookupPtr = nullptr;
protected:
+ friend class ASTDeclReader;
+ friend class ASTWriter;
+ friend class ExternalASTSource;
+
/// FirstDecl - The first declaration stored within this declaration
/// context.
- mutable Decl *FirstDecl;
+ mutable Decl *FirstDecl = nullptr;
/// LastDecl - The last declaration stored within this declaration
/// context. FIXME: We could probably cache this value somewhere
/// outside of the DeclContext, to reduce the size of DeclContext by
/// another pointer.
- mutable Decl *LastDecl;
-
- friend class ExternalASTSource;
- friend class ASTDeclReader;
- friend class ASTWriter;
+ mutable Decl *LastDecl = nullptr;
/// \brief Build up a chain of declarations.
///
ExternalVisibleStorage(false),
NeedToReconcileExternalVisibleStorage(false),
HasLazyLocalLexicalLookups(false), HasLazyExternalLexicalLookups(false),
- UseQualifiedLookup(false),
- LookupPtr(nullptr), FirstDecl(nullptr), LastDecl(nullptr) {}
+ UseQualifiedLookup(false) {}
public:
~DeclContext();
Decl::Kind getDeclKind() const {
return static_cast<Decl::Kind>(DeclKind);
}
+
const char *getDeclKindName() const;
/// getParent - Returns the containing DeclContext.
/// within this context.
class decl_iterator {
/// Current - The current declaration.
- Decl *Current;
+ Decl *Current = nullptr;
public:
- typedef Decl *value_type;
- typedef const value_type &reference;
- typedef const value_type *pointer;
- typedef std::forward_iterator_tag iterator_category;
- typedef std::ptrdiff_t difference_type;
+ using value_type = Decl *;
+ using reference = const value_type &;
+ using pointer = const value_type *;
+ using iterator_category = std::forward_iterator_tag;
+ using difference_type = std::ptrdiff_t;
- decl_iterator() : Current(nullptr) { }
- explicit decl_iterator(Decl *C) : Current(C) { }
+ decl_iterator() = default;
+ explicit decl_iterator(Decl *C) : Current(C) {}
reference operator*() const { return Current; }
+
// This doesn't meet the iterator requirements, but it's convenient
value_type operator->() const { return Current; }
friend bool operator==(decl_iterator x, decl_iterator y) {
return x.Current == y.Current;
}
+
friend bool operator!=(decl_iterator x, decl_iterator y) {
return x.Current != y.Current;
}
};
- typedef llvm::iterator_range<decl_iterator> decl_range;
+ using decl_range = llvm::iterator_range<decl_iterator>;
/// decls_begin/decls_end - Iterate over the declarations stored in
/// this context.
}
public:
- typedef SpecificDecl *value_type;
- // TODO: Add reference and pointer typedefs (with some appropriate proxy
- // type) if we ever have a need for them.
- typedef void reference;
- typedef void pointer;
- typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
- difference_type;
- typedef std::forward_iterator_tag iterator_category;
+ using value_type = SpecificDecl *;
+ // TODO: Add reference and pointer types (with some appropriate proxy type)
+ // if we ever have a need for them.
+ using reference = void;
+ using pointer = void;
+ using difference_type =
+ std::iterator_traits<DeclContext::decl_iterator>::difference_type;
+ using iterator_category = std::forward_iterator_tag;
- specific_decl_iterator() : Current() { }
+ specific_decl_iterator() = default;
/// specific_decl_iterator - Construct a new iterator over a
/// subset of the declarations the range [C,
}
value_type operator*() const { return cast<SpecificDecl>(*Current); }
+
// This doesn't meet the iterator requirements, but it's convenient
value_type operator->() const { return **this; }
}
public:
- typedef SpecificDecl *value_type;
- // TODO: Add reference and pointer typedefs (with some appropriate proxy
- // type) if we ever have a need for them.
- typedef void reference;
- typedef void pointer;
- typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
- difference_type;
- typedef std::forward_iterator_tag iterator_category;
+ using value_type = SpecificDecl *;
+ // TODO: Add reference and pointer types (with some appropriate proxy type)
+ // if we ever have a need for them.
+ using reference = void;
+ using pointer = void;
+ using difference_type =
+ std::iterator_traits<DeclContext::decl_iterator>::difference_type;
+ using iterator_category = std::forward_iterator_tag;
- filtered_decl_iterator() : Current() { }
+ filtered_decl_iterator() = default;
/// filtered_decl_iterator - Construct a new iterator over a
/// subset of the declarations the range [C,
/// @brief Checks whether a declaration is in this context.
bool containsDecl(Decl *D) const;
- typedef DeclContextLookupResult lookup_result;
- typedef lookup_result::iterator lookup_iterator;
+ using lookup_result = DeclContextLookupResult;
+ using lookup_iterator = lookup_result::iterator;
/// lookup - Find the declarations (if any) with the given Name in
/// this context. Returns a range of iterators that contains all of
/// of looking up every possible name.
class all_lookups_iterator;
- typedef llvm::iterator_range<all_lookups_iterator> lookups_range;
+ using lookups_range = llvm::iterator_range<all_lookups_iterator>;
lookups_range lookups() const;
lookups_range noload_lookups() const;
all_lookups_iterator noload_lookups_end() const;
struct udir_iterator;
- typedef llvm::iterator_adaptor_base<udir_iterator, lookup_iterator,
- std::random_access_iterator_tag,
- UsingDirectiveDecl *> udir_iterator_base;
+
+ using udir_iterator_base =
+ llvm::iterator_adaptor_base<udir_iterator, lookup_iterator,
+ std::random_access_iterator_tag,
+ UsingDirectiveDecl *>;
+
struct udir_iterator : udir_iterator_base {
udir_iterator(lookup_iterator I) : udir_iterator_base(I) {}
+
UsingDirectiveDecl *operator*() const;
};
- typedef llvm::iterator_range<udir_iterator> udir_range;
+ using udir_range = llvm::iterator_range<udir_iterator>;
udir_range using_directives() const;
// These are all defined in DependentDiagnostic.h.
class ddiag_iterator;
- typedef llvm::iterator_range<DeclContext::ddiag_iterator> ddiag_range;
+
+ using ddiag_range = llvm::iterator_range<DeclContext::ddiag_iterator>;
inline ddiag_range ddiags() const;
bool Deserialize = false) const;
private:
+ friend class DependentDiagnostic;
+
void reconcileExternalVisibleStorage() const;
bool LoadLexicalDeclsFromExternalStorage() const;
/// use of addDeclInternal().
void makeDeclVisibleInContextInternal(NamedDecl *D);
- friend class DependentDiagnostic;
StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const;
void buildLookupImpl(DeclContext *DCtx, bool Internal);
}
};
-
-} // end clang.
+} // namespace clang
namespace llvm {
return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
}
};
+
template<class ToTy>
struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> {
static ToTy &doit(::clang::DeclContext &Val) {
return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
}
};
+
template<class ToTy>
struct cast_convert_val<ToTy,
const ::clang::DeclContext*, const ::clang::DeclContext*> {
return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
}
};
+
template<class ToTy>
struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> {
static ToTy *doit(::clang::DeclContext *Val) {
}
};
-} // end namespace llvm
+} // namespace llvm
-#endif
+#endif // LLVM_CLANG_AST_DECLBASE_H
-//===--- ExternalASTSource.h - Abstract External AST Interface --*- C++ -*-===//
+//===- ExternalASTSource.h - Abstract External AST Interface ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// construction of AST nodes from some external source.
//
//===----------------------------------------------------------------------===//
+
#ifndef LLVM_CLANG_AST_EXTERNALASTSOURCE_H
#define LLVM_CLANG_AST_EXTERNALASTSOURCE_H
#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclBase.h"
+#include "clang/Basic/LLVM.h"
#include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator.h"
+#include "llvm/Support/PointerLikeTypeTraits.h"
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <iterator>
+#include <string>
+#include <utility>
namespace clang {
class ASTConsumer;
+class ASTContext;
class CXXBaseSpecifier;
class CXXCtorInitializer;
+class CXXRecordDecl;
class DeclarationName;
-class ExternalSemaSource; // layering violation required for downcasting
class FieldDecl;
-class Module;
+class IdentifierInfo;
class NamedDecl;
+class ObjCInterfaceDecl;
class RecordDecl;
class Selector;
class Stmt;
/// actual type and declaration nodes, and read parts of declaration
/// contexts.
class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
+ friend class ExternalSemaSource;
+
/// Generation number for this external AST source. Must be increased
/// whenever we might have added new redeclarations for existing decls.
- uint32_t CurrentGeneration;
+ uint32_t CurrentGeneration = 0;
/// \brief Whether this AST source also provides information for
/// semantic analysis.
- bool SemaSource;
-
- friend class ExternalSemaSource;
+ bool SemaSource = false;
public:
- ExternalASTSource() : CurrentGeneration(0), SemaSource(false) { }
-
+ ExternalASTSource() = default;
virtual ~ExternalASTSource();
/// \brief RAII class for safely pairing a StartedDeserializing call
/// with FinishedDeserializing.
class Deserializing {
ExternalASTSource *Source;
+
public:
explicit Deserializing(ExternalASTSource *source) : Source(source) {
assert(Source);
Source->StartedDeserializing();
}
+
~Deserializing() {
Source->FinishedDeserializing();
}
virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
/// \brief Update an out-of-date identifier.
- virtual void updateOutOfDateIdentifier(IdentifierInfo &II) { }
+ virtual void updateOutOfDateIdentifier(IdentifierInfo &II) {}
/// \brief Find all declarations with the given name in the given context,
/// and add them to the context by calling SetExternalVisibleDeclsForName
const Module *ClangModule = nullptr;
public:
- ASTSourceDescriptor(){};
+ ASTSourceDescriptor() = default;
ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
ASTFileSignature Signature)
: PCHModuleName(std::move(Name)), Path(std::move(Path)),
- ASTFile(std::move(ASTFile)), Signature(Signature){};
+ ASTFile(std::move(ASTFile)), Signature(Signature) {}
ASTSourceDescriptor(const Module &M);
+
std::string getModuleName() const;
StringRef getPath() const { return Path; }
StringRef getASTFile() const { return ASTFile; }
/// The default implementation of this method is a no-op.
virtual void PrintStats();
-
/// \brief Perform layout on the given record.
///
/// This routine allows the external AST source to provide an specific
size_t mmap_bytes;
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
- : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
+ : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
};
/// Return the amount of memory used by memory buffers, breaking down
///
/// If the low bit is clear, a pointer to the AST node. If the low
/// bit is set, the upper 63 bits are the offset.
- mutable uint64_t Ptr;
+ mutable uint64_t Ptr = 0;
public:
- LazyOffsetPtr() : Ptr(0) { }
+ LazyOffsetPtr() = default;
+ explicit LazyOffsetPtr(T *Ptr) : Ptr(reinterpret_cast<uint64_t>(Ptr)) {}
- explicit LazyOffsetPtr(T *Ptr) : Ptr(reinterpret_cast<uint64_t>(Ptr)) { }
explicit LazyOffsetPtr(uint64_t Offset) : Ptr((Offset << 1) | 0x01) {
assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
if (Offset == 0)
/// A cache of the value of this pointer, in the most recent generation in
/// which we queried it.
struct LazyData {
- LazyData(ExternalASTSource *Source, T Value)
- : ExternalSource(Source), LastGeneration(0), LastValue(Value) {}
ExternalASTSource *ExternalSource;
- uint32_t LastGeneration;
+ uint32_t LastGeneration = 0;
T LastValue;
+
+ LazyData(ExternalASTSource *Source, T Value)
+ : ExternalSource(Source), LastValue(Value) {}
};
// Our value is represented as simply T if there is no external AST source.
- typedef llvm::PointerUnion<T, LazyData*> ValueType;
+ using ValueType = llvm::PointerUnion<T, LazyData*>;
ValueType Value;
LazyGenerationalUpdatePtr(ValueType V) : Value(V) {}
return LazyGenerationalUpdatePtr(ValueType::getFromOpaqueValue(Ptr));
}
};
-} // end namespace clang
+
+} // namespace clang
/// Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be
/// placed into a PointerUnion.
namespace llvm {
+
template<typename Owner, typename T,
void (clang::ExternalASTSource::*Update)(Owner)>
struct PointerLikeTypeTraits<
clang::LazyGenerationalUpdatePtr<Owner, T, Update>> {
- typedef clang::LazyGenerationalUpdatePtr<Owner, T, Update> Ptr;
+ using Ptr = clang::LazyGenerationalUpdatePtr<Owner, T, Update>;
+
static void *getAsVoidPointer(Ptr P) { return P.getOpaqueValue(); }
static Ptr getFromVoidPointer(void *P) { return Ptr::getFromOpaqueValue(P); }
+
enum {
NumLowBitsAvailable = PointerLikeTypeTraits<T>::NumLowBitsAvailable - 1
};
};
-}
+
+} // namespace llvm
namespace clang {
+
/// \brief Represents a lazily-loaded vector of data.
///
/// The lazily-loaded vector of data contains data that is partially loaded
class iterator
: public llvm::iterator_adaptor_base<
iterator, int, std::random_access_iterator_tag, T, int, T *, T &> {
+ friend class LazyVector;
+
LazyVector *Self;
iterator(LazyVector *Self, int Position)
: iterator::iterator_adaptor_base(Position), Self(Self) {}
bool isLoaded() const { return this->I < 0; }
- friend class LazyVector;
public:
iterator() : iterator(nullptr, 0) {}
};
/// \brief A lazy pointer to a statement.
-typedef LazyOffsetPtr<Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt>
- LazyDeclStmtPtr;
+using LazyDeclStmtPtr =
+ LazyOffsetPtr<Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt>;
/// \brief A lazy pointer to a declaration.
-typedef LazyOffsetPtr<Decl, uint32_t, &ExternalASTSource::GetExternalDecl>
- LazyDeclPtr;
+using LazyDeclPtr =
+ LazyOffsetPtr<Decl, uint32_t, &ExternalASTSource::GetExternalDecl>;
/// \brief A lazy pointer to a set of CXXCtorInitializers.
-typedef LazyOffsetPtr<CXXCtorInitializer *, uint64_t,
- &ExternalASTSource::GetExternalCXXCtorInitializers>
- LazyCXXCtorInitializersPtr;
+using LazyCXXCtorInitializersPtr =
+ LazyOffsetPtr<CXXCtorInitializer *, uint64_t,
+ &ExternalASTSource::GetExternalCXXCtorInitializers>;
/// \brief A lazy pointer to a set of CXXBaseSpecifiers.
-typedef LazyOffsetPtr<CXXBaseSpecifier, uint64_t,
- &ExternalASTSource::GetExternalCXXBaseSpecifiers>
- LazyCXXBaseSpecifiersPtr;
+using LazyCXXBaseSpecifiersPtr =
+ LazyOffsetPtr<CXXBaseSpecifier, uint64_t,
+ &ExternalASTSource::GetExternalCXXBaseSpecifiers>;
-} // end namespace clang
+} // namespace clang
-#endif
+#endif // LLVM_CLANG_AST_EXTERNALASTSOURCE_H