diff options
author | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-11-30 22:33:48 +0000 |
---|---|---|
committer | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-11-30 22:33:48 +0000 |
commit | e0a9480f64277460bf76a6683debe15cd4ab1aac (patch) | |
tree | f9f5064936165613e15cd5d6fe03548f4995266d | |
parent | 02fb715d1f7a37697625ee0d562acd097a9f268a (diff) |
[AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319487 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/CXXInheritance.h | 93 | ||||
-rw-r--r-- | include/clang/AST/DeclLookups.h | 23 | ||||
-rw-r--r-- | include/clang/AST/ExprObjC.h | 477 | ||||
-rw-r--r-- | lib/AST/CXXInheritance.cpp | 57 | ||||
-rw-r--r-- | lib/AST/ExprObjC.cpp | 12 |
5 files changed, 374 insertions, 288 deletions
diff --git a/include/clang/AST/CXXInheritance.h b/include/clang/AST/CXXInheritance.h index 980608570f..11fb229f0c 100644 --- a/include/clang/AST/CXXInheritance.h +++ b/include/clang/AST/CXXInheritance.h @@ -1,4 +1,4 @@ -//===------ CXXInheritance.h - C++ Inheritance ------------------*- C++ -*-===// +//===- CXXInheritance.h - C++ Inheritance -----------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -16,19 +16,23 @@ #include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclarationName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeOrdering.h" +#include "clang/Basic/Specifiers.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" -#include <cassert> +#include "llvm/ADT/iterator_range.h" #include <list> +#include <memory> +#include <utility> namespace clang { - -class CXXBaseSpecifier; -class CXXMethodDecl; -class CXXRecordDecl; + +class ASTContext; class NamedDecl; /// \brief Represents an element in a path from a derived class to a @@ -66,12 +70,12 @@ struct CXXBasePathElement { /// subobject is being used. class CXXBasePath : public SmallVector<CXXBasePathElement, 4> { public: - CXXBasePath() : Access(AS_public) {} - /// \brief The access along this inheritance path. This is only /// calculated when recording paths. AS_none is a special value /// used to indicate a path which permits no legal access. - AccessSpecifier Access; + AccessSpecifier Access = AS_public; + + CXXBasePath() = default; /// \brief The set of declarations found inside this base class /// subobject. @@ -113,8 +117,10 @@ public: /// refer to the same base class subobject of type A (the virtual /// one), there is no ambiguity. class CXXBasePaths { + friend class CXXRecordDecl; + /// \brief The type from which this search originated. - CXXRecordDecl *Origin; + CXXRecordDecl *Origin = nullptr; /// Paths - The actual set of paths that can be taken from the /// derived class to the same base class. @@ -152,15 +158,13 @@ class CXXBasePaths { CXXBasePath ScratchPath; /// DetectedVirtual - The base class that is virtual. - const RecordType *DetectedVirtual; + const RecordType *DetectedVirtual = nullptr; /// \brief Array of the declarations that have been found. This /// array is constructed only if needed, e.g., to iterate over the /// results within LookupResult. std::unique_ptr<NamedDecl *[]> DeclsFound; - unsigned NumDeclsFound; - - friend class CXXRecordDecl; + unsigned NumDeclsFound = 0; void ComputeDeclsFound(); @@ -169,17 +173,16 @@ class CXXBasePaths { bool LookupInDependent = false); public: - typedef std::list<CXXBasePath>::iterator paths_iterator; - typedef std::list<CXXBasePath>::const_iterator const_paths_iterator; - typedef NamedDecl **decl_iterator; + using paths_iterator = std::list<CXXBasePath>::iterator; + using const_paths_iterator = std::list<CXXBasePath>::const_iterator; + using decl_iterator = NamedDecl **; /// BasePaths - Construct a new BasePaths structure to record the /// paths for a derived-to-base search. explicit CXXBasePaths(bool FindAmbiguities = true, bool RecordPaths = true, bool DetectVirtual = true) - : Origin(), FindAmbiguities(FindAmbiguities), RecordPaths(RecordPaths), - DetectVirtual(DetectVirtual), DetectedVirtual(nullptr), - NumDeclsFound(0) {} + : FindAmbiguities(FindAmbiguities), RecordPaths(RecordPaths), + DetectVirtual(DetectVirtual) {} paths_iterator begin() { return Paths.begin(); } paths_iterator end() { return Paths.end(); } @@ -189,7 +192,8 @@ public: CXXBasePath& front() { return Paths.front(); } const CXXBasePath& front() const { return Paths.front(); } - typedef llvm::iterator_range<decl_iterator> decl_range; + using decl_range = llvm::iterator_range<decl_iterator>; + decl_range found_decls(); /// \brief Determine whether the path from the most-derived type to the @@ -231,25 +235,24 @@ public: /// \brief Uniquely identifies a virtual method within a class /// hierarchy by the method itself and a class subobject number. struct UniqueVirtualMethod { - UniqueVirtualMethod() - : Method(nullptr), Subobject(0), InVirtualSubobject(nullptr) { } - - UniqueVirtualMethod(CXXMethodDecl *Method, unsigned Subobject, - const CXXRecordDecl *InVirtualSubobject) - : Method(Method), Subobject(Subobject), - InVirtualSubobject(InVirtualSubobject) { } - /// \brief The overriding virtual method. - CXXMethodDecl *Method; + CXXMethodDecl *Method = nullptr; /// \brief The subobject in which the overriding virtual method /// resides. - unsigned Subobject; + unsigned Subobject = 0; /// \brief The virtual base class subobject of which this overridden /// virtual method is a part. Note that this records the closest /// derived virtual base class subobject. - const CXXRecordDecl *InVirtualSubobject; + const CXXRecordDecl *InVirtualSubobject = nullptr; + + UniqueVirtualMethod() = default; + + UniqueVirtualMethod(CXXMethodDecl *Method, unsigned Subobject, + const CXXRecordDecl *InVirtualSubobject) + : Method(Method), Subobject(Subobject), + InVirtualSubobject(InVirtualSubobject) {} friend bool operator==(const UniqueVirtualMethod &X, const UniqueVirtualMethod &Y) { @@ -271,14 +274,16 @@ struct UniqueVirtualMethod { /// pair is the virtual method that overrides it (including the /// subobject in which that virtual function occurs). class OverridingMethods { - typedef SmallVector<UniqueVirtualMethod, 4> ValuesT; - typedef llvm::MapVector<unsigned, ValuesT> MapType; + using ValuesT = SmallVector<UniqueVirtualMethod, 4>; + using MapType = llvm::MapVector<unsigned, ValuesT>; + MapType Overrides; public: // Iterate over the set of subobjects that have overriding methods. - typedef MapType::iterator iterator; - typedef MapType::const_iterator const_iterator; + using iterator = MapType::iterator; + using const_iterator = MapType::const_iterator; + iterator begin() { return Overrides.begin(); } const_iterator begin() const { return Overrides.begin(); } iterator end() { return Overrides.end(); } @@ -287,10 +292,10 @@ public: // Iterate over the set of overriding virtual methods in a given // subobject. - typedef SmallVectorImpl<UniqueVirtualMethod>::iterator - overriding_iterator; - typedef SmallVectorImpl<UniqueVirtualMethod>::const_iterator - overriding_const_iterator; + using overriding_iterator = + SmallVectorImpl<UniqueVirtualMethod>::iterator; + using overriding_const_iterator = + SmallVectorImpl<UniqueVirtualMethod>::const_iterator; // Add a new overriding method for a particular subobject. void add(unsigned OverriddenSubobject, UniqueVirtualMethod Overriding); @@ -357,12 +362,12 @@ public: /// subobject numbers greater than 0 refer to non-virtual base class /// subobjects of that type. class CXXFinalOverriderMap - : public llvm::MapVector<const CXXMethodDecl *, OverridingMethods> { }; + : public llvm::MapVector<const CXXMethodDecl *, OverridingMethods> {}; /// \brief A set of all the primary bases for a class. class CXXIndirectPrimaryBaseSet - : public llvm::SmallSet<const CXXRecordDecl*, 32> { }; + : public llvm::SmallSet<const CXXRecordDecl*, 32> {}; -} // end namespace clang +} // namespace clang -#endif +#endif // LLVM_CLANG_AST_CXXINHERITANCE_H diff --git a/include/clang/AST/DeclLookups.h b/include/clang/AST/DeclLookups.h index eba2266724..2fff055825 100644 --- a/include/clang/AST/DeclLookups.h +++ b/include/clang/AST/DeclLookups.h @@ -1,4 +1,4 @@ -//===-- DeclLookups.h - Low-level interface to all names in a DC-*- C++ -*-===// +//===- DeclLookups.h - Low-level interface to all names in a DC -*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -18,6 +18,9 @@ #include "clang/AST/DeclBase.h" #include "clang/AST/DeclContextInternals.h" #include "clang/AST/DeclarationName.h" +#include "clang/AST/ExternalASTSource.h" +#include <cstddef> +#include <iterator> namespace clang { @@ -25,14 +28,15 @@ namespace clang { /// of looking up every possible name. class DeclContext::all_lookups_iterator { StoredDeclsMap::iterator It, End; + public: - typedef lookup_result value_type; - typedef lookup_result reference; - typedef lookup_result pointer; - typedef std::forward_iterator_tag iterator_category; - typedef std::ptrdiff_t difference_type; + using value_type = lookup_result; + using reference = lookup_result; + using pointer = lookup_result; + using iterator_category = std::forward_iterator_tag; + using difference_type = std::ptrdiff_t; - all_lookups_iterator() {} + all_lookups_iterator() = default; all_lookups_iterator(StoredDeclsMap::iterator It, StoredDeclsMap::iterator End) : It(It), End(End) {} @@ -63,6 +67,7 @@ public: friend bool operator==(all_lookups_iterator x, all_lookups_iterator y) { return x.It == y.It; } + friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y) { return x.It != y.It; } @@ -110,6 +115,6 @@ DeclContext::all_lookups_iterator DeclContext::noload_lookups_end() const { return noload_lookups().end(); } -} // end namespace clang +} // namespace clang -#endif +#endif // LLVM_CLANG_AST_DECLLOOKUPS_H diff --git a/include/clang/AST/ExprObjC.h b/include/clang/AST/ExprObjC.h index cd93817586..ab2df8a348 100644 --- a/include/clang/AST/ExprObjC.h +++ b/include/clang/AST/ExprObjC.h @@ -1,4 +1,4 @@ -//===--- ExprObjC.h - Classes for representing ObjC expressions -*- C++ -*-===// +//===- ExprObjC.h - Classes for representing ObjC expressions ---*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -14,28 +14,51 @@ #ifndef LLVM_CLANG_AST_EXPROBJC_H #define LLVM_CLANG_AST_EXPROBJC_H +#include "clang/AST/Decl.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/Expr.h" +#include "clang/AST/OperationKinds.h" #include "clang/AST/SelectorLocationsKind.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/Type.h" #include "clang/Basic/IdentifierTable.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/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/PointerIntPair.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/TrailingObjects.h" +#include "llvm/Support/type_traits.h" +#include <cassert> +#include <cstddef> +#include <cstdint> namespace clang { - class IdentifierInfo; - class ASTContext; + +class ASTContext; +class CXXBaseSpecifier; /// ObjCStringLiteral, used for Objective-C string literals /// i.e. @"foo". class ObjCStringLiteral : public Expr { Stmt *String; SourceLocation AtLoc; + public: ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L) - : Expr(ObjCStringLiteralClass, T, VK_RValue, OK_Ordinary, false, false, - false, false), - String(SL), AtLoc(L) {} + : Expr(ObjCStringLiteralClass, T, VK_RValue, OK_Ordinary, false, false, + false, false), + String(SL), AtLoc(L) {} explicit ObjCStringLiteral(EmptyShell Empty) - : Expr(ObjCStringLiteralClass, Empty) {} + : Expr(ObjCStringLiteralClass, Empty) {} StringLiteral *getString() { return cast<StringLiteral>(String); } const StringLiteral *getString() const { return cast<StringLiteral>(String); } @@ -47,26 +70,26 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } SourceLocation getLocEnd() const LLVM_READONLY { return String->getLocEnd(); } + // Iterators + child_range children() { return child_range(&String, &String+1); } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCStringLiteralClass; } - - // Iterators - child_range children() { return child_range(&String, &String+1); } }; /// ObjCBoolLiteralExpr - Objective-C Boolean Literal. -/// class ObjCBoolLiteralExpr : public Expr { bool Value; SourceLocation Loc; + public: - ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : - Expr(ObjCBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, - false, false), Value(val), Loc(l) {} - + ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) + : Expr(ObjCBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, + false, false), + Value(val), Loc(l) {} explicit ObjCBoolLiteralExpr(EmptyShell Empty) - : Expr(ObjCBoolLiteralExprClass, Empty) { } + : Expr(ObjCBoolLiteralExprClass, Empty) {} bool getValue() const { return Value; } void setValue(bool V) { Value = V; } @@ -77,14 +100,14 @@ public: SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCBoolLiteralExprClass; - } - // Iterators child_range children() { return child_range(child_iterator(), child_iterator()); } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCBoolLiteralExprClass; + } }; /// ObjCBoxedExpr - used for generalized expression boxing. @@ -95,15 +118,19 @@ class ObjCBoxedExpr : public Expr { Stmt *SubExpr; ObjCMethodDecl *BoxingMethod; SourceRange Range; + public: + friend class ASTStmtReader; + ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *method, SourceRange R) - : Expr(ObjCBoxedExprClass, T, VK_RValue, OK_Ordinary, - E->isTypeDependent(), E->isValueDependent(), - E->isInstantiationDependent(), E->containsUnexpandedParameterPack()), - SubExpr(E), BoxingMethod(method), Range(R) {} + : Expr(ObjCBoxedExprClass, T, VK_RValue, OK_Ordinary, + E->isTypeDependent(), E->isValueDependent(), + E->isInstantiationDependent(), + E->containsUnexpandedParameterPack()), + SubExpr(E), BoxingMethod(method), Range(R) {} explicit ObjCBoxedExpr(EmptyShell Empty) - : Expr(ObjCBoxedExprClass, Empty) {} + : Expr(ObjCBoxedExprClass, Empty) {} Expr *getSubExpr() { return cast<Expr>(SubExpr); } const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } @@ -116,27 +143,27 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } + SourceRange getSourceRange() const LLVM_READONLY { return Range; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCBoxedExprClass; - } - // Iterators child_range children() { return child_range(&SubExpr, &SubExpr+1); } - typedef ConstExprIterator const_arg_iterator; + using const_arg_iterator = ConstExprIterator; const_arg_iterator arg_begin() const { return reinterpret_cast<Stmt const * const*>(&SubExpr); } + const_arg_iterator arg_end() const { return reinterpret_cast<Stmt const * const*>(&SubExpr + 1); } - - friend class ASTStmtReader; + + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCBoxedExprClass; + } }; /// ObjCArrayLiteral - used for objective-c array containers; as in: @@ -153,9 +180,12 @@ class ObjCArrayLiteral final SourceRange SR); explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements) - : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {} + : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {} public: + friend class ASTStmtReader; + friend TrailingObjects; + static ObjCArrayLiteral *Create(const ASTContext &C, ArrayRef<Expr *> Elements, QualType T, ObjCMethodDecl * Method, @@ -168,10 +198,6 @@ public: SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } SourceRange getSourceRange() const LLVM_READONLY { return Range; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCArrayLiteralClass; - } - /// \brief Retrieve elements of array of literals. Expr **getElements() { return getTrailingObjects<Expr *>(); } @@ -183,7 +209,7 @@ public: /// getNumElements - Return number of elements of objective-c array literal. unsigned getNumElements() const { return NumElements; } - /// getExpr - Return the Expr at the specified index. + /// getElement - Return the Element at the specified index. Expr *getElement(unsigned Index) { assert((Index < NumElements) && "Arg access out of range!"); return cast<Expr>(getElements()[Index]); @@ -203,8 +229,9 @@ public: reinterpret_cast<Stmt **>(getElements()) + NumElements); } - friend TrailingObjects; - friend class ASTStmtReader; + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCArrayLiteralClass; + } }; /// \brief An element in an Objective-C dictionary literal. @@ -226,13 +253,17 @@ struct ObjCDictionaryElement { /// \brief Determines whether this dictionary element is a pack expansion. bool isPackExpansion() const { return EllipsisLoc.isValid(); } }; -} // end namespace clang + +} // namespace clang namespace llvm { + template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {}; -} + +} // namespace llvm namespace clang { + /// \brief Internal struct for storing Key/value pair. struct ObjCDictionaryLiteral_KeyValuePair { Expr *Key; @@ -274,12 +305,8 @@ class ObjCDictionaryLiteral final SourceRange Range; ObjCMethodDecl *DictWithObjectsMethod; - typedef ObjCDictionaryLiteral_KeyValuePair KeyValuePair; - typedef ObjCDictionaryLiteral_ExpansionData ExpansionData; - - size_t numTrailingObjects(OverloadToken<KeyValuePair>) const { - return NumElements; - } + using KeyValuePair = ObjCDictionaryLiteral_KeyValuePair; + using ExpansionData = ObjCDictionaryLiteral_ExpansionData; ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, bool HasPackExpansions, @@ -288,10 +315,18 @@ class ObjCDictionaryLiteral final explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements, bool HasPackExpansions) - : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements), - HasPackExpansions(HasPackExpansions) {} + : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements), + HasPackExpansions(HasPackExpansions) {} + + size_t numTrailingObjects(OverloadToken<KeyValuePair>) const { + return NumElements; + } public: + friend class ASTStmtReader; + friend class ASTStmtWriter; + friend TrailingObjects; + static ObjCDictionaryLiteral *Create(const ASTContext &C, ArrayRef<ObjCDictionaryElement> VK, bool HasPackExpansions, @@ -320,17 +355,14 @@ public: return Result; } - ObjCMethodDecl *getDictWithObjectsMethod() const - { return DictWithObjectsMethod; } + ObjCMethodDecl *getDictWithObjectsMethod() const { + return DictWithObjectsMethod; + } SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } SourceRange getSourceRange() const LLVM_READONLY { return Range; } - - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCDictionaryLiteralClass; - } - + // Iterators child_range children() { // Note: we're taking advantage of the layout of the KeyValuePair struct @@ -342,12 +374,11 @@ public: reinterpret_cast<Stmt **>(getTrailingObjects<KeyValuePair>()) + NumElements * 2); } - - friend class ASTStmtReader; - friend class ASTStmtWriter; - friend TrailingObjects; -}; + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCDictionaryLiteralClass; + } +}; /// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same /// type and behavior as StringLiteral except that the string initializer is @@ -355,19 +386,19 @@ public: class ObjCEncodeExpr : public Expr { TypeSourceInfo *EncodedType; SourceLocation AtLoc, RParenLoc; + public: ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType, SourceLocation at, SourceLocation rp) - : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary, - EncodedType->getType()->isDependentType(), - EncodedType->getType()->isDependentType(), - EncodedType->getType()->isInstantiationDependentType(), - EncodedType->getType()->containsUnexpandedParameterPack()), - EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {} + : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary, + EncodedType->getType()->isDependentType(), + EncodedType->getType()->isDependentType(), + EncodedType->getType()->isInstantiationDependentType(), + EncodedType->getType()->containsUnexpandedParameterPack()), + EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {} explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){} - SourceLocation getAtLoc() const { return AtLoc; } void setAtLoc(SourceLocation L) { AtLoc = L; } SourceLocation getRParenLoc() const { return RParenLoc; } @@ -376,6 +407,7 @@ public: QualType getEncodedType() const { return EncodedType->getType(); } TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; } + void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { EncodedType = EncType; } @@ -383,28 +415,29 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCEncodeExprClass; - } - // Iterators child_range children() { return child_range(child_iterator(), child_iterator()); } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCEncodeExprClass; + } }; /// ObjCSelectorExpr used for \@selector in Objective-C. class ObjCSelectorExpr : public Expr { Selector SelName; SourceLocation AtLoc, RParenLoc; + public: ObjCSelectorExpr(QualType T, Selector selInfo, SourceLocation at, SourceLocation rp) - : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, - false, false), - SelName(selInfo), AtLoc(at), RParenLoc(rp){} + : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, + false, false), + SelName(selInfo), AtLoc(at), RParenLoc(rp) {} explicit ObjCSelectorExpr(EmptyShell Empty) - : Expr(ObjCSelectorExprClass, Empty) {} + : Expr(ObjCSelectorExprClass, Empty) {} Selector getSelector() const { return SelName; } void setSelector(Selector S) { SelName = S; } @@ -420,14 +453,14 @@ public: /// getNumArgs - Return the number of actual arguments to this call. unsigned getNumArgs() const { return SelName.getNumArgs(); } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCSelectorExprClass; - } - // Iterators child_range children() { return child_range(child_iterator(), child_iterator()); } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCSelectorExprClass; + } }; /// ObjCProtocolExpr used for protocol expression in Objective-C. @@ -441,14 +474,18 @@ public: class ObjCProtocolExpr : public Expr { ObjCProtocolDecl *TheProtocol; SourceLocation AtLoc, ProtoLoc, RParenLoc; + public: + friend class ASTStmtReader; + friend class ASTStmtWriter; + ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, SourceLocation at, SourceLocation protoLoc, SourceLocation rp) - : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false, - false, false), - TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {} + : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false, + false, false), + TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {} explicit ObjCProtocolExpr(EmptyShell Empty) - : Expr(ObjCProtocolExprClass, Empty) {} + : Expr(ObjCProtocolExprClass, Empty) {} ObjCProtocolDecl *getProtocol() const { return TheProtocol; } void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; } @@ -462,17 +499,14 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCProtocolExprClass; - } - // Iterators child_range children() { return child_range(child_iterator(), child_iterator()); } - friend class ASTStmtReader; - friend class ASTStmtWriter; + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCProtocolExprClass; + } }; /// ObjCIvarRefExpr - A reference to an ObjC instance variable. @@ -480,27 +514,31 @@ class ObjCIvarRefExpr : public Expr { ObjCIvarDecl *D; Stmt *Base; SourceLocation Loc; + /// OpLoc - This is the location of '.' or '->' SourceLocation OpLoc; - - bool IsArrow:1; // True if this is "X->F", false if this is "X.F". - bool IsFreeIvar:1; // True if ivar reference has no base (self assumed). + + // True if this is "X->F", false if this is "X.F". + bool IsArrow : 1; + + // True if ivar reference has no base (self assumed). + bool IsFreeIvar : 1; public: ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, SourceLocation l, SourceLocation oploc, Expr *base, - bool arrow = false, bool freeIvar = false) : - Expr(ObjCIvarRefExprClass, t, VK_LValue, - d->isBitField() ? OK_BitField : OK_Ordinary, - /*TypeDependent=*/false, base->isValueDependent(), - base->isInstantiationDependent(), - base->containsUnexpandedParameterPack()), - D(d), Base(base), Loc(l), OpLoc(oploc), - IsArrow(arrow), IsFreeIvar(freeIvar) {} + bool arrow = false, bool freeIvar = false) + : Expr(ObjCIvarRefExprClass, t, VK_LValue, + d->isBitField() ? OK_BitField : OK_Ordinary, + /*TypeDependent=*/false, base->isValueDependent(), + base->isInstantiationDependent(), + base->containsUnexpandedParameterPack()), + D(d), Base(base), Loc(l), OpLoc(oploc), IsArrow(arrow), + IsFreeIvar(freeIvar) {} explicit ObjCIvarRefExpr(EmptyShell Empty) - : Expr(ObjCIvarRefExprClass, Empty) {} + : Expr(ObjCIvarRefExprClass, Empty) {} ObjCIvarDecl *getDecl() { return D; } const ObjCIvarDecl *getDecl() const { return D; } @@ -526,12 +564,12 @@ public: SourceLocation getOpLoc() const { return OpLoc; } void setOpLoc(SourceLocation L) { OpLoc = L; } + // Iterators + child_range children() { return child_range(&Base, &Base+1); } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCIvarRefExprClass; } - - // Iterators - child_range children() { return child_range(&Base, &Base+1); } }; /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC @@ -542,7 +580,7 @@ private: /// pointer is an (optional) ObjCMethodDecl and Setter may be set. /// if the bool is false, this is an explicit property reference; /// the pointer is an ObjCPropertyDecl and Setter is always null. - llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter; + llvm::PointerIntPair<NamedDecl *, 1, bool> PropertyOrGetter; /// \brief Indicates whether the property reference will result in a message /// to the getter, the setter, or both. @@ -567,40 +605,39 @@ private: /// the location of the 'super' keyword. When it's an interface, /// this is that interface. SourceLocation ReceiverLoc; - llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver; + llvm::PointerUnion3<Stmt *, const Type *, ObjCInterfaceDecl *> Receiver; public: ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, Expr *base) - : Expr(ObjCPropertyRefExprClass, t, VK, OK, - /*TypeDependent=*/false, base->isValueDependent(), - base->isInstantiationDependent(), - base->containsUnexpandedParameterPack()), - PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), - IdLoc(l), ReceiverLoc(), Receiver(base) { + : Expr(ObjCPropertyRefExprClass, t, VK, OK, + /*TypeDependent=*/false, base->isValueDependent(), + base->isInstantiationDependent(), + base->containsUnexpandedParameterPack()), + PropertyOrGetter(PD, false), IdLoc(l), Receiver(base) { assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); } ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, SourceLocation sl, QualType st) - : Expr(ObjCPropertyRefExprClass, t, VK, OK, - /*TypeDependent=*/false, false, st->isInstantiationDependentType(), - st->containsUnexpandedParameterPack()), - PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), - IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) { + : Expr(ObjCPropertyRefExprClass, t, VK, OK, + /*TypeDependent=*/false, false, st->isInstantiationDependentType(), + st->containsUnexpandedParameterPack()), + PropertyOrGetter(PD, false), IdLoc(l), ReceiverLoc(sl), + Receiver(st.getTypePtr()) { assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); } ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation IdLoc, Expr *Base) - : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, - Base->isValueDependent(), Base->isInstantiationDependent(), - Base->containsUnexpandedParameterPack()), - PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), - IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) { + : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, + Base->isValueDependent(), Base->isInstantiationDependent(), + Base->containsUnexpandedParameterPack()), + PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), + IdLoc(IdLoc), Receiver(Base) { assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); } @@ -608,9 +645,9 @@ public: QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation IdLoc, SourceLocation SuperLoc, QualType SuperTy) - : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), - PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), - IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) { + : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), + PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), + IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) { assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); } @@ -618,14 +655,14 @@ public: QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation IdLoc, SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver) - : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), - PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), - IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) { + : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), + PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), + IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) { assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); } explicit ObjCPropertyRefExpr(EmptyShell Empty) - : Expr(ObjCPropertyRefExprClass, Empty) {} + : Expr(ObjCPropertyRefExprClass, Empty) {} bool isImplicitProperty() const { return PropertyOrGetter.getInt(); } bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); } @@ -689,6 +726,7 @@ public: SourceLocation getLocation() const { return IdLoc; } SourceLocation getReceiverLocation() const { return ReceiverLoc; } + QualType getSuperReceiverType() const { return QualType(Receiver.get<const Type*>(), 0); } @@ -696,6 +734,7 @@ public: ObjCInterfaceDecl *getClassReceiver() const { return Receiver.get<ObjCInterfaceDecl*>(); } + bool isObjectReceiver() const { return Receiver.is<Stmt*>(); } bool isSuperReceiver() const { return Receiver.is<const Type*>(); } bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); } @@ -706,11 +745,8 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation(); } - SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCPropertyRefExprClass; - } + SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; } // Iterators child_range children() { @@ -721,15 +757,21 @@ public: return child_range(child_iterator(), child_iterator()); } + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCPropertyRefExprClass; + } + private: friend class ASTStmtReader; friend class ASTStmtWriter; + void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) { PropertyOrGetter.setPointer(D); PropertyOrGetter.setInt(false); SetterAndMethodRefFlags.setPointer(nullptr); SetterAndMethodRefFlags.setInt(methRefFlags); } + void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, unsigned methRefFlags) { PropertyOrGetter.setPointer(Getter); @@ -737,6 +779,7 @@ private: SetterAndMethodRefFlags.setPointer(Setter); SetterAndMethodRefFlags.setInt(methRefFlags); } + void setBase(Expr *Base) { Receiver = Base; } void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); } void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; } @@ -756,10 +799,10 @@ private: /// ObjCSubscriptRefExpr - used for array and dictionary subscripting. /// array[4] = array[3]; dictionary[key] = dictionary[alt_key]; -/// class ObjCSubscriptRefExpr : public Expr { // Location of ']' in an indexing expression. SourceLocation RBracket; + // array/dictionary base expression. // for arrays, this is a numeric expression. For dictionaries, this is // an objective-c object pointer expression. @@ -773,24 +816,24 @@ class ObjCSubscriptRefExpr : public Expr { ObjCMethodDecl *SetAtIndexMethodDecl; public: - ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T, ExprValueKind VK, ExprObjectKind OK, ObjCMethodDecl *getMethod, ObjCMethodDecl *setMethod, SourceLocation RB) - : Expr(ObjCSubscriptRefExprClass, T, VK, OK, - base->isTypeDependent() || key->isTypeDependent(), - base->isValueDependent() || key->isValueDependent(), - base->isInstantiationDependent() || key->isInstantiationDependent(), - (base->containsUnexpandedParameterPack() || - key->containsUnexpandedParameterPack())), - RBracket(RB), - GetAtIndexMethodDecl(getMethod), - SetAtIndexMethodDecl(setMethod) - {SubExprs[BASE] = base; SubExprs[KEY] = key;} + : Expr(ObjCSubscriptRefExprClass, T, VK, OK, + base->isTypeDependent() || key->isTypeDependent(), + base->isValueDependent() || key->isValueDependent(), + (base->isInstantiationDependent() || + key->isInstantiationDependent()), + (base->containsUnexpandedParameterPack() || + key->containsUnexpandedParameterPack())), + RBracket(RB), GetAtIndexMethodDecl(getMethod), + SetAtIndexMethodDecl(setMethod) { + SubExprs[BASE] = base; SubExprs[KEY] = key; + } explicit ObjCSubscriptRefExpr(EmptyShell Empty) - : Expr(ObjCSubscriptRefExprClass, Empty) {} + : Expr(ObjCSubscriptRefExprClass, Empty) {} SourceLocation getRBracket() const { return RBracket; } void setRBracket(SourceLocation RB) { RBracket = RB; } @@ -798,11 +841,8 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return SubExprs[BASE]->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCSubscriptRefExprClass; - } + SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; } Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); } void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; } @@ -825,10 +865,14 @@ public: child_range children() { return child_range(SubExprs, SubExprs+END_EXPR); } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCSubscriptRefExprClass; + } + private: friend class ASTStmtReader; }; - /// \brief An expression that sends a message to the given Objective-C /// object or class. @@ -856,14 +900,13 @@ private: /// The "void *" trailing objects are actually ONE void * (the /// receiver pointer), and NumArgs Expr *. But due to the /// implementation of children(), these must be together contiguously. - class ObjCMessageExpr final : public Expr, private llvm::TrailingObjects<ObjCMessageExpr, void *, SourceLocation> { /// \brief Stores either the selector that this message is sending /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer /// referring to the method that we type-checked against. - uintptr_t SelectorOrMethod; + uintptr_t SelectorOrMethod = 0; enum { NumArgsBitWidth = 16 }; @@ -904,16 +947,9 @@ class ObjCMessageExpr final /// brackets ('[' and ']', respectively). SourceLocation LBracLoc, RBracLoc; - size_t numTrailingObjects(OverloadToken<void *>) const { return NumArgs + 1; } - - void setNumArgs(unsigned Num) { - assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!"); - NumArgs = Num; - } - ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs) - : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0), - HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) { + : Expr(ObjCMessageExprClass, Empty), Kind(0), HasMethod(false), + IsDelegateInitCall(false), IsImplicit(false), SelLocsKind(0) { setNumArgs(NumArgs); } @@ -950,6 +986,13 @@ class ObjCMessageExpr final SourceLocation RBracLoc, bool isImplicit); + size_t numTrailingObjects(OverloadToken<void *>) const { return NumArgs + 1; } + + void setNumArgs(unsigned Num) { + assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!"); + NumArgs = Num; + } + void initArgsAndSelLocs(ArrayRef<Expr *> Args, ArrayRef<SourceLocation> SelLocs, SelectorLocationsKind SelLocsK); @@ -965,6 +1008,7 @@ class ObjCMessageExpr final SelectorLocationsKind getSelLocsKind() const { return (SelectorLocationsKind)SelLocsKind; } + bool hasStandardSelLocs() const { return getSelLocsKind() != SelLoc_NonStandard; } @@ -997,14 +1041,21 @@ class ObjCMessageExpr final unsigned NumStoredSelLocs); public: + friend class ASTStmtReader; + friend class ASTStmtWriter; + friend TrailingObjects; + /// \brief The kind of receiver this message is sending to. enum ReceiverKind { /// \brief The receiver is a class. Class = 0, + /// \brief The receiver is an object instance. Instance, + /// \brief The receiver is a superclass. SuperClass, + /// \brief The receiver is the instance of the superclass object. SuperInstance }; @@ -1029,7 +1080,7 @@ public: /// \param Sel The selector used to determine which method gets called. /// /// \param Method The Objective-C method against which this message - /// send was type-checked. May be NULL. + /// send was type-checked. May be nullptr. /// /// \param Args The message send arguments. /// @@ -1065,7 +1116,7 @@ public: /// \param Sel The selector used to determine which method gets called. /// /// \param Method The Objective-C method against which this message - /// send was type-checked. May be NULL. + /// send was type-checked. May be nullptr. /// /// \param Args The message send arguments. /// @@ -1099,7 +1150,7 @@ public: /// \param Sel The selector used to determine which method gets called. /// /// \param Method The Objective-C method against which this message - /// send was type-checked. May be NULL. + /// send was type-checked. May be nullptr. /// /// \param Args The message send arguments. /// @@ -1175,11 +1226,11 @@ public: if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo()) return TSInfo->getType(); - return QualType(); + return {}; } /// \brief Returns a type-source information of a class message - /// send, or NULL if the message is not a class message. + /// send, or nullptr if the message is not a class message. TypeSourceInfo *getClassReceiverTypeInfo() const { if (getReceiverKind() == Class) return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer()); @@ -1220,7 +1271,7 @@ public: /// whether the message is a class or an instance method, whether it /// is a send to super or not, etc. /// - /// \returns The Objective-C interface if known, otherwise NULL. + /// \returns The Objective-C interface if known, otherwise nullptr. ObjCInterfaceDecl *getReceiverInterface() const; /// \brief Retrieve the type referred to by 'super'. @@ -1295,6 +1346,7 @@ public: assert(Arg < NumArgs && "Arg access out of range!"); return getArgs()[Arg]; } + /// setArg - Set the specified argument. void setArg(unsigned Arg, Expr *ArgExpr) { assert(Arg < NumArgs && "Arg access out of range!"); @@ -1315,6 +1367,7 @@ public: return getLocStart(); return getSelectorLoc(0); } + SourceLocation getSelectorLoc(unsigned Index) const { assert(Index < getNumSelectorLocs() && "Index out of range!"); if (hasStandardSelLocs()) @@ -1341,18 +1394,15 @@ public: LBracLoc = R.getBegin(); RBracLoc = R.getEnd(); } + SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; } SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == ObjCMessageExprClass; - } - // Iterators child_range children(); - typedef ExprIterator arg_iterator; - typedef ConstExprIterator const_arg_iterator; + using arg_iterator = ExprIterator; + using const_arg_iterator = ConstExprIterator; llvm::iterator_range<arg_iterator> arguments() { return llvm::make_range(arg_begin(), arg_end()); @@ -1363,19 +1413,22 @@ public: } arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); } + arg_iterator arg_end() { return reinterpret_cast<Stmt **>(getArgs() + NumArgs); } + const_arg_iterator arg_begin() const { return reinterpret_cast<Stmt const * const*>(getArgs()); } + const_arg_iterator arg_end() const { return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs); } - friend TrailingObjects; - friend class ASTStmtReader; - friend class ASTStmtWriter; + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCMessageExprClass; + } }; /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type. @@ -1392,17 +1445,18 @@ class ObjCIsaExpr : public Expr { /// IsArrow - True if this is "X->F", false if this is "X.F". bool IsArrow; + public: ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc, QualType ty) - : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary, - /*TypeDependent=*/false, base->isValueDependent(), - base->isInstantiationDependent(), - /*ContainsUnexpandedParameterPack=*/false), - Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {} + : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary, + /*TypeDependent=*/false, base->isValueDependent(), + base->isInstantiationDependent(), + /*ContainsUnexpandedParameterPack=*/false), + Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {} /// \brief Build an empty expression. - explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { } + explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) {} void setBase(Expr *E) { Base = E; } Expr *getBase() const { return cast<Expr>(Base); } @@ -1430,15 +1484,14 @@ public: SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; } + // Iterators + child_range children() { return child_range(&Base, &Base+1); } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCIsaExprClass; } - - // Iterators - child_range children() { return child_range(&Base, &Base+1); } }; - /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function /// argument by indirect copy-restore in ARC. This is used to support /// passing indirect arguments with the wrong lifetime, e.g. when @@ -1462,27 +1515,27 @@ public: /// __autoreleasing; this qualifier is ignored when initializing /// the value. class ObjCIndirectCopyRestoreExpr : public Expr { + friend class ASTReader; + friend class ASTStmtReader; + Stmt *Operand; // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1; - friend class ASTReader; - friend class ASTStmtReader; + explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty) + : Expr(ObjCIndirectCopyRestoreExprClass, Empty) {} void setShouldCopy(bool shouldCopy) { ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy; } - explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty) - : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { } - public: ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy) - : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary, - operand->isTypeDependent(), operand->isValueDependent(), - operand->isInstantiationDependent(), - operand->containsUnexpandedParameterPack()), - Operand(operand) { + : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary, + operand->isTypeDependent(), operand->isValueDependent(), + operand->isInstantiationDependent(), + operand->containsUnexpandedParameterPack()), + Operand(operand) { setShouldCopy(shouldCopy); } @@ -1519,26 +1572,26 @@ public: class ObjCBridgedCastExpr final : public ExplicitCastExpr, private llvm::TrailingObjects<ObjCBridgedCastExpr, CXXBaseSpecifier *> { + friend class ASTStmtReader; + friend class ASTStmtWriter; + friend class CastExpr; + friend TrailingObjects; + SourceLocation LParenLoc; SourceLocation BridgeKeywordLoc; unsigned Kind : 2; - friend TrailingObjects; - friend class CastExpr; - friend class ASTStmtReader; - friend class ASTStmtWriter; - public: ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, CastKind CK, SourceLocation BridgeKeywordLoc, TypeSourceInfo *TSInfo, Expr *Operand) - : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue, - CK, Operand, 0, TSInfo), - LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { } + : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue, + CK, Operand, 0, TSInfo), + LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) {} /// \brief Construct an empty Objective-C bridged cast. explicit ObjCBridgedCastExpr(EmptyShell Shell) - : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { } + : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) {} SourceLocation getLParenLoc() const { return LParenLoc; } @@ -1554,6 +1607,7 @@ public: SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; } SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return getSubExpr()->getLocEnd(); } @@ -1577,10 +1631,11 @@ public: /// expressions. /// class ObjCAvailabilityCheckExpr : public Expr { + friend class ASTStmtReader; + VersionTuple VersionToCheck; SourceLocation AtLoc, RParen; - friend class ASTStmtReader; public: ObjCAvailabilityCheckExpr(VersionTuple VersionToCheck, SourceLocation AtLoc, SourceLocation RParen, QualType Ty) @@ -1608,6 +1663,6 @@ public: } }; -} // end namespace clang +} // namespace clang -#endif +#endif // LLVM_CLANG_AST_EXPROBJC_H diff --git a/lib/AST/CXXInheritance.cpp b/lib/AST/CXXInheritance.cpp index fc4d8b1373..4f9f1da95f 100644 --- a/lib/AST/CXXInheritance.cpp +++ b/lib/AST/CXXInheritance.cpp @@ -1,4 +1,4 @@ -//===------ CXXInheritance.cpp - C++ Inheritance ----------------*- C++ -*-===// +//===- CXXInheritance.cpp - C++ Inheritance -------------------------------===// // // The LLVM Compiler Infrastructure // @@ -10,13 +10,27 @@ // This file provides routines that help analyzing C++ inheritance hierarchies. // //===----------------------------------------------------------------------===// + #include "clang/AST/CXXInheritance.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/RecordLayout.h" +#include "clang/AST/TemplateName.h" +#include "clang/AST/Type.h" +#include "clang/Basic/LLVM.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Support/Casting.h" #include <algorithm> +#include <utility> +#include <cassert> +#include <vector> using namespace clang; @@ -26,7 +40,7 @@ void CXXBasePaths::ComputeDeclsFound() { assert(NumDeclsFound == 0 && !DeclsFound && "Already computed the set of declarations"); - llvm::SetVector<NamedDecl *, SmallVector<NamedDecl *, 8> > Decls; + llvm::SetVector<NamedDecl *, SmallVector<NamedDecl *, 8>> Decls; for (paths_iterator Path = begin(), PathEnd = end(); Path != PathEnd; ++Path) Decls.insert(Path->Decls.front()); @@ -419,8 +433,8 @@ bool CXXRecordDecl::FindTagMember(const CXXBaseSpecifier *Specifier, static bool findOrdinaryMember(RecordDecl *BaseRecord, CXXBasePath &Path, DeclarationName Name) { - const unsigned IDNS = clang::Decl::IDNS_Ordinary | clang::Decl::IDNS_Tag | - clang::Decl::IDNS_Member; + const unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag | + Decl::IDNS_Member; for (Path.Decls = BaseRecord->lookup(Name); !Path.Decls.empty(); Path.Decls = Path.Decls.slice(1)) { @@ -550,26 +564,27 @@ void OverridingMethods::replaceAll(UniqueVirtualMethod Overriding) { } } - namespace { - class FinalOverriderCollector { - /// \brief The number of subobjects of a given class type that - /// occur within the class hierarchy. - llvm::DenseMap<const CXXRecordDecl *, unsigned> SubobjectCount; - /// \brief Overriders for each virtual base subobject. - llvm::DenseMap<const CXXRecordDecl *, CXXFinalOverriderMap *> VirtualOverriders; +class FinalOverriderCollector { + /// \brief The number of subobjects of a given class type that + /// occur within the class hierarchy. + llvm::DenseMap<const CXXRecordDecl *, unsigned> SubobjectCount; - CXXFinalOverriderMap FinalOverriders; + /// \brief Overriders for each virtual base subobject. + llvm::DenseMap<const CXXRecordDecl *, CXXFinalOverriderMap *> VirtualOverriders; - public: - ~FinalOverriderCollector(); + CXXFinalOverriderMap FinalOverriders; - void Collect(const CXXRecordDecl *RD, bool VirtualBase, - const CXXRecordDecl *InVirtualSubobject, - CXXFinalOverriderMap &Overriders); - }; -} +public: + ~FinalOverriderCollector(); + + void Collect(const CXXRecordDecl *RD, bool VirtualBase, + const CXXRecordDecl *InVirtualSubobject, + CXXFinalOverriderMap &Overriders); +}; + +} // namespace void FinalOverriderCollector::Collect(const CXXRecordDecl *RD, bool VirtualBase, @@ -656,8 +671,8 @@ void FinalOverriderCollector::Collect(const CXXRecordDecl *RD, // overrider. To do so, we dig down to the original virtual // functions using data recursion and update all of the methods it // overrides. - typedef llvm::iterator_range<CXXMethodDecl::method_iterator> - OverriddenMethods; + using OverriddenMethods = + llvm::iterator_range<CXXMethodDecl::method_iterator>; SmallVector<OverriddenMethods, 4> Stack; Stack.push_back(llvm::make_range(CanonM->begin_overridden_methods(), CanonM->end_overridden_methods())); diff --git a/lib/AST/ExprObjC.cpp b/lib/AST/ExprObjC.cpp index 31c1b3f156..e1a23f5985 100644 --- a/lib/AST/ExprObjC.cpp +++ b/lib/AST/ExprObjC.cpp @@ -1,4 +1,4 @@ -//===--- ExprObjC.cpp - (ObjC) Expression AST Node Implementation ---------===// +//===- ExprObjC.cpp - (ObjC) Expression AST Node Implementation -----------===// // // The LLVM Compiler Infrastructure // @@ -12,8 +12,15 @@ //===----------------------------------------------------------------------===// #include "clang/AST/ExprObjC.h" - #include "clang/AST/ASTContext.h" +#include "clang/AST/SelectorLocationsKind.h" +#include "clang/AST/Type.h" +#include "clang/AST/TypeLoc.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/ErrorHandling.h" +#include <algorithm> +#include <cassert> +#include <cstdint> using namespace clang; @@ -45,7 +52,6 @@ ObjCArrayLiteral *ObjCArrayLiteral::Create(const ASTContext &C, ObjCArrayLiteral *ObjCArrayLiteral::CreateEmpty(const ASTContext &C, unsigned NumElements) { - void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumElements)); return new (Mem) ObjCArrayLiteral(EmptyShell(), NumElements); } |