diff options
Diffstat (limited to 'include/clang/AST/ASTContext.h')
| -rw-r--r-- | include/clang/AST/ASTContext.h | 97 |
1 files changed, 59 insertions, 38 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index a9ab687a8de9..13870116c7fd 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_AST_ASTCONTEXT_H #define LLVM_CLANG_AST_ASTCONTEXT_H +#include "clang/AST/ASTContextAllocate.h" #include "clang/AST/ASTTypeTraits.h" #include "clang/AST/CanonicalType.h" #include "clang/AST/CommentCommandTraits.h" @@ -22,6 +23,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" +#include "clang/AST/Expr.h" #include "clang/AST/ExternalASTSource.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/PrettyPrinter.h" @@ -30,6 +32,7 @@ #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/AttrKinds.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" @@ -79,6 +82,7 @@ struct fltSemantics; namespace clang { +class APFixedPoint; class APValue; class ASTMutationListener; class ASTRecordLayout; @@ -92,6 +96,7 @@ class CXXMethodDecl; class CXXRecordDecl; class DiagnosticsEngine; class Expr; +class FixedPointSemantics; class MangleContext; class MangleNumberingContext; class MaterializeTemporaryExpr; @@ -148,6 +153,22 @@ struct TypeInfo { /// Holds long-lived AST nodes (such as types and decls) that can be /// referred to throughout the semantic analysis of a file. class ASTContext : public RefCountedBase<ASTContext> { +public: + /// Copy initialization expr of a __block variable and a boolean flag that + /// indicates whether the expression can throw. + struct BlockVarCopyInit { + BlockVarCopyInit() = default; + BlockVarCopyInit(Expr *CopyExpr, bool CanThrow) + : ExprAndFlag(CopyExpr, CanThrow) {} + void setExprAndFlag(Expr *CopyExpr, bool CanThrow) { + ExprAndFlag.setPointerAndInt(CopyExpr, CanThrow); + } + Expr *getCopyExpr() const { return ExprAndFlag.getPointer(); } + bool canThrow() const { return ExprAndFlag.getInt(); } + llvm::PointerIntPair<Expr *, 1, bool> ExprAndFlag; + }; + +private: friend class NestedNameSpecifier; mutable SmallVector<Type *, 0> Types; @@ -242,8 +263,8 @@ class ASTContext : public RefCountedBase<ASTContext> { /// interface. llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls; - /// Mapping from __block VarDecls to their copy initialization expr. - llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits; + /// Mapping from __block VarDecls to BlockVarCopyInit. + llvm::DenseMap<const VarDecl *, BlockVarCopyInit> BlockVarCopyInits; /// Mapping from class scope functions specialization to their /// template patterns. @@ -316,7 +337,7 @@ class ASTContext : public RefCountedBase<ASTContext> { mutable IdentifierInfo *BoolName = nullptr; /// The identifier 'NSObject'. - IdentifierInfo *NSObjectName = nullptr; + mutable IdentifierInfo *NSObjectName = nullptr; /// The identifier 'NSCopying'. IdentifierInfo *NSCopyingName = nullptr; @@ -549,26 +570,6 @@ public: IntrusiveRefCntPtr<ExternalASTSource> ExternalSource; ASTMutationListener *Listener = nullptr; - /// Contains parents of a node. - using ParentVector = llvm::SmallVector<ast_type_traits::DynTypedNode, 2>; - - /// Maps from a node to its parents. This is used for nodes that have - /// pointer identity only, which are more common and we can save space by - /// only storing a unique pointer to them. - using ParentMapPointers = - llvm::DenseMap<const void *, - llvm::PointerUnion4<const Decl *, const Stmt *, - ast_type_traits::DynTypedNode *, - ParentVector *>>; - - /// Parent map for nodes without pointer identity. We store a full - /// DynTypedNode for all keys. - using ParentMapOtherNodes = - llvm::DenseMap<ast_type_traits::DynTypedNode, - llvm::PointerUnion4<const Decl *, const Stmt *, - ast_type_traits::DynTypedNode *, - ParentVector *>>; - /// Container for either a single DynTypedNode or for an ArrayRef to /// DynTypedNode. For use with ParentMap. class DynTypedNodeList { @@ -610,7 +611,17 @@ public: } }; - /// Returns the parents of the given node. + // A traversal scope limits the parts of the AST visible to certain analyses. + // RecursiveASTVisitor::TraverseAST will only visit reachable nodes, and + // getParents() will only observe reachable parent edges. + // + // The scope is defined by a set of "top-level" declarations. + // Initially, it is the entire TU: {getTranslationUnitDecl()}. + // Changing the scope clears the parent cache, which is expensive to rebuild. + std::vector<Decl *> getTraversalScope() const { return TraversalScope; } + void setTraversalScope(const std::vector<Decl *> &); + + /// Returns the parents of the given node (within the traversal scope). /// /// Note that this will lazily compute the parents of all nodes /// and store them for later retrieval. Thus, the first call is O(n) @@ -977,7 +988,8 @@ public: /// Get the additional modules in which the definition \p Def has /// been merged. ArrayRef<Module*> getModulesWithMergedDefinition(const NamedDecl *Def) { - auto MergedIt = MergedDefModules.find(Def); + auto MergedIt = + MergedDefModules.find(cast<NamedDecl>(Def->getCanonicalDecl())); if (MergedIt == MergedDefModules.end()) return None; return MergedIt->second; @@ -1041,6 +1053,9 @@ public: CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy; CanQualType OCLQueueTy, OCLReserveIDTy; CanQualType OMPArraySectionTy; +#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ + CanQualType Id##Ty; +#include "clang/Basic/OpenCLExtensionTypes.def" // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. @@ -1403,7 +1418,7 @@ public: QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; - QualType getAttributedType(AttributedType::Kind attrKind, + QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType); @@ -1656,7 +1671,7 @@ public: } /// Retrieve the identifier 'NSObject'. - IdentifierInfo *getNSObjectName() { + IdentifierInfo *getNSObjectName() const { if (!NSObjectName) { NSObjectName = &Idents.get("NSObject"); } @@ -1961,6 +1976,9 @@ public: unsigned char getFixedPointScale(QualType Ty) const; unsigned char getFixedPointIBits(QualType Ty) const; + FixedPointSemantics getFixedPointSemantics(QualType Ty) const; + APFixedPoint getFixedPointMax(QualType Ty) const; + APFixedPoint getFixedPointMin(QualType Ty) const; DeclarationNameInfo getNameForTemplate(TemplateName Name, SourceLocation NameLoc) const; @@ -2488,6 +2506,8 @@ public: unsigned getTargetAddressSpace(LangAS AS) const; + LangAS getLangASForBuiltinAddressSpace(unsigned AS) const; + /// Get target-dependent integer value for null pointer which is used for /// constant folding. uint64_t getTargetNullPointerValue(QualType QT) const; @@ -2657,12 +2677,13 @@ public: /// otherwise returns null. const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const; - /// Set the copy inialization expression of a block var decl. - void setBlockVarCopyInits(VarDecl*VD, Expr* Init); + /// Set the copy inialization expression of a block var decl. \p CanThrow + /// indicates whether the copy expression can throw or not. + void setBlockVarCopyInit(const VarDecl* VD, Expr *CopyExpr, bool CanThrow); /// Get the copy initialization expression of the VarDecl \p VD, or /// nullptr if none exists. - Expr *getBlockVarCopyInits(const VarDecl* VD); + BlockVarCopyInit getBlockVarCopyInit(const VarDecl* VD) const; /// Allocate an uninitialized TypeSourceInfo. /// @@ -2718,7 +2739,7 @@ public: /// predicate. void forEachMultiversionedFunctionVersion( const FunctionDecl *FD, - llvm::function_ref<void(const FunctionDecl *)> Pred) const; + llvm::function_ref<void(FunctionDecl *)> Pred) const; const CXXConstructorDecl * getCopyConstructorForExceptionObject(CXXRecordDecl *RD); @@ -2894,13 +2915,13 @@ private: // but we include it here so that ASTContext can quickly deallocate them. llvm::PointerIntPair<StoredDeclsMap *, 1> LastSDM; - std::unique_ptr<ParentMapPointers> PointerParents; - std::unique_ptr<ParentMapOtherNodes> OtherParents; + std::vector<Decl *> TraversalScope; + class ParentMap; + std::unique_ptr<ParentMap> Parents; std::unique_ptr<VTableContextBase> VTContext; void ReleaseDeclContextMaps(); - void ReleaseParentMapEntries(); public: enum PragmaSectionFlag : unsigned { @@ -2949,8 +2970,8 @@ inline Selector GetUnarySelector(StringRef name, ASTContext &Ctx) { /// This placement form of operator new uses the ASTContext's allocator for /// obtaining memory. /// -/// IMPORTANT: These are also declared in clang/AST/AttrIterator.h! Any changes -/// here need to also be made there. +/// IMPORTANT: These are also declared in clang/AST/ASTContextAllocate.h! +/// Any changes here need to also be made there. /// /// We intentionally avoid using a nothrow specification here so that the calls /// to this operator will not perform a null check on the result -- the @@ -2973,7 +2994,7 @@ inline Selector GetUnarySelector(StringRef name, ASTContext &Ctx) { /// allocator supports it). /// @return The allocated memory. Could be nullptr. inline void *operator new(size_t Bytes, const clang::ASTContext &C, - size_t Alignment) { + size_t Alignment /* = 8 */) { return C.Allocate(Bytes, Alignment); } @@ -3011,7 +3032,7 @@ inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) { /// allocator supports it). /// @return The allocated memory. Could be nullptr. inline void *operator new[](size_t Bytes, const clang::ASTContext& C, - size_t Alignment = 8) { + size_t Alignment /* = 8 */) { return C.Allocate(Bytes, Alignment); } |
