Sema.h revision a1eec4bd198b96ef40a7c15cd0e131ca94511ad8
128c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// 2fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar// 3fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar// The LLVM Compiler Infrastructure 4fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar// 5fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar// This file is distributed under the University of Illinois Open Source 6fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar// License. See LICENSE.TXT for details. 7fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar// 8fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar//===----------------------------------------------------------------------===// 9fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar// 1028c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar// This file defines the Sema class, which performs semantic analysis and 1128c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar// builds ASTs. 12fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar// 13fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar//===----------------------------------------------------------------------===// 148b67f774e9c38b7718b2b300b628388f966df4e0Chandler Carruth 15fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#ifndef LLVM_CLANG_SEMA_SEMA_H 16fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#define LLVM_CLANG_SEMA_SEMA_H 17684c593d05db0bd277268fc9d8c05bce138c745aChris Lattner 18fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#include "clang/Sema/Ownership.h" 19fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#include "clang/Sema/AnalysisBasedWarnings.h" 2015d170709608e2f1efcada74c297c10c8c71fdcfDaniel Dunbar#include "clang/Sema/IdentifierResolver.h" 2187392fde1f261fea161b48886fafbedddb18dcceDaniel Dunbar#include "clang/Sema/ObjCMethodList.h" 224f3e7aa154577c86791908e73a9fec075fdea0baChris Lattner#include "clang/Sema/DeclSpec.h" 23fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#include "clang/Sema/ExternalSemaSource.h" 2428c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar#include "clang/Sema/LocInfoType.h" 259643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar#include "clang/Sema/TypoCorrection.h" 2628c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar#include "clang/Sema/Weak.h" 27fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#include "clang/AST/Expr.h" 2828c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar#include "clang/AST/ExprObjC.h" 291aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar#include "clang/AST/DeclarationName.h" 301aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar#include "clang/AST/ExternalASTSource.h" 311aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar#include "clang/AST/TypeLoc.h" 321aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar#include "clang/AST/NSAPI.h" 33fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#include "clang/Lex/ModuleLoader.h" 349643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar#include "clang/Basic/Specifiers.h" 35fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#include "clang/Basic/TemplateKinds.h" 3628c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar#include "clang/Basic/TypeTraits.h" 379643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar#include "clang/Basic/ExpressionTraits.h" 389643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar#include "llvm/ADT/ArrayRef.h" 399643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar#include "llvm/ADT/OwningPtr.h" 409643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar#include "llvm/ADT/SetVector.h" 41fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#include "llvm/ADT/SmallPtrSet.h" 4228c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar#include "llvm/ADT/SmallVector.h" 439643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar#include <deque> 44fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar#include <string> 459643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 469643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbarnamespace llvm { 47fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class APSInt; 4828c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar template <typename ValueT> struct DenseMapInfo; 49fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar template <typename ValueT, typename ValueInfoT> class DenseSet; 509643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class SmallBitVector; 5187392fde1f261fea161b48886fafbedddb18dcceDaniel Dunbar} 5287392fde1f261fea161b48886fafbedddb18dcceDaniel Dunbar 5387392fde1f261fea161b48886fafbedddb18dcceDaniel Dunbarnamespace clang { 548cb9a3b13f3226b7e741768b69d26ecd6b5231f1Chris Lattner class ADLResult; 5587392fde1f261fea161b48886fafbedddb18dcceDaniel Dunbar class ASTConsumer; 5687392fde1f261fea161b48886fafbedddb18dcceDaniel Dunbar class ASTContext; 5787392fde1f261fea161b48886fafbedddb18dcceDaniel Dunbar class ASTMutationListener; 589643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ASTReader; 599643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ASTWriter; 609643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ArrayType; 61fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class AttributeList; 62fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class BlockDecl; 6315d170709608e2f1efcada74c297c10c8c71fdcfDaniel Dunbar class CXXBasePath; 64fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class CXXBasePaths; 65e00b011e6a2597fcc3da88da91a8ffda6eebfcdaDaniel Dunbar class CXXBindTemporaryExpr; 66fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 6715d170709608e2f1efcada74c297c10c8c71fdcfDaniel Dunbar class CXXConstructorDecl; 681aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class CXXConversionDecl; 6915d170709608e2f1efcada74c297c10c8c71fdcfDaniel Dunbar class CXXDestructorDecl; 7015d170709608e2f1efcada74c297c10c8c71fdcfDaniel Dunbar class CXXFieldCollector; 7115d170709608e2f1efcada74c297c10c8c71fdcfDaniel Dunbar class CXXMemberCallExpr; 72e00b011e6a2597fcc3da88da91a8ffda6eebfcdaDaniel Dunbar class CXXMethodDecl; 7315d170709608e2f1efcada74c297c10c8c71fdcfDaniel Dunbar class CXXScopeSpec; 749643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class CXXTemporary; 759643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class CXXTryStmt; 7628c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class CallExpr; 77fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class ClassTemplateDecl; 788cb9a3b13f3226b7e741768b69d26ecd6b5231f1Chris Lattner class ClassTemplatePartialSpecializationDecl; 798cb9a3b13f3226b7e741768b69d26ecd6b5231f1Chris Lattner class ClassTemplateSpecializationDecl; 808cb9a3b13f3226b7e741768b69d26ecd6b5231f1Chris Lattner class CodeCompleteConsumer; 818cb9a3b13f3226b7e741768b69d26ecd6b5231f1Chris Lattner class CodeCompletionAllocator; 828cb9a3b13f3226b7e741768b69d26ecd6b5231f1Chris Lattner class CodeCompletionTUInfo; 83fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class CodeCompletionResult; 8428c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class Decl; 8528c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class DeclAccessPair; 86fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class DeclContext; 87fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class DeclRefExpr; 889643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class DeclaratorDecl; 8928c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class DeducedTemplateArgument; 909643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class DependentDiagnostic; 919643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class DesignatedInitExpr; 929643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class Designation; 939643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class EnumConstantDecl; 949643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class Expr; 959643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ExtVectorType; 969643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ExternalSemaSource; 979643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class FormatAttr; 989643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class FriendDecl; 999643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class FunctionDecl; 1009643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class FunctionProtoType; 101fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class FunctionTemplateDecl; 102fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class ImplicitConversionSequence; 1039643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class InitListExpr; 1049643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class InitializationKind; 1059643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class InitializationSequence; 1069643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class InitializedEntity; 107fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class IntegerLiteral; 10828c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class LabelStmt; 109fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class LambdaExpr; 110fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class LangOptions; 11128c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class LocalInstantiationScope; 1121aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class LookupResult; 1131aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class MacroInfo; 1141aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class MultiLevelTemplateArgumentList; 1151aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class NamedDecl; 1161aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class NonNullAttr; 11728c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class ObjCCategoryDecl; 1189643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ObjCCategoryImplDecl; 119fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class ObjCCompatibleAliasDecl; 1209643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ObjCContainerDecl; 12128c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class ObjCImplDecl; 122fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class ObjCImplementationDecl; 1239643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ObjCInterfaceDecl; 1249643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ObjCIvarDecl; 1259643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar template <class T> class ObjCList; 1269643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ObjCMessageExpr; 1279643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ObjCMethodDecl; 1282928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar class ObjCPropertyDecl; 1297eb85194f2b07bc7ba3f274fc00dc389b77b63bfDaniel Dunbar class ObjCProtocolDecl; 1309643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class OverloadCandidateSet; 1319643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class OverloadExpr; 1329643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ParenListExpr; 1339643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ParmVarDecl; 1349643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class Preprocessor; 1359643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class PseudoDestructorTypeStorage; 1369643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class PseudoObjectExpr; 1379643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class QualType; 1389643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class StandardConversionSequence; 1399643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class Stmt; 140fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class StringLiteral; 14128c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class SwitchStmt; 142fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class TargetAttributesSema; 143fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class TemplateArgument; 14428c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class TemplateArgumentList; 14528c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class TemplateArgumentLoc; 146fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class TemplateDecl; 147fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class TemplateParameterList; 1481aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class TemplatePartialOrderingContext; 1491aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class TemplateTemplateParmDecl; 1501aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class Token; 1511aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar class TypeAliasDecl; 152fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class TypedefDecl; 153fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class TypedefNameDecl; 154fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class TypeLoc; 155fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class UnqualifiedId; 1569643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class UnresolvedLookupExpr; 157fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class UnresolvedMemberExpr; 1589643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class UnresolvedSetImpl; 15928c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar class UnresolvedSetIterator; 1609643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class UsingDecl; 1619643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class UsingShadowDecl; 1629643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class ValueDecl; 1639643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class VarDecl; 1649643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class VisibilityAttr; 1659643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class VisibleDeclConsumer; 1669643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class IndirectFieldDecl; 1679643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 1689643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbarnamespace sema { 1699643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class AccessedEntity; 1709643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class BlockScopeInfo; 1719643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class CapturingScopeInfo; 1729643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class CompoundScopeInfo; 1739643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class DelayedDiagnostic; 1749643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class DelayedDiagnosticPool; 175fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar class FunctionScopeInfo; 1769643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class LambdaScopeInfo; 1779643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class PossiblyUnreachableDiag; 1789643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar class TemplateDeductionInfo; 1799643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar} 1809643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 1819643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar// FIXME: No way to easily map from TemplateTypeParmTypes to 1829643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar// TemplateTypeParmDecls, so we have this horrible PointerUnion. 183fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbartypedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, 1849643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar SourceLocation> UnexpandedParameterPack; 185fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar 186fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar/// Sema - This implements semantic analysis and AST building for C. 1879643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbarclass Sema { 1889643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar Sema(const Sema&); // DO NOT IMPLEMENT 189fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar void operator=(const Sema&); // DO NOT IMPLEMENT 1909643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar mutable const TargetAttributesSema* TheTargetAttributesSema; 1919643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbarpublic: 1929643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 1939643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar typedef OpaquePtr<TemplateName> TemplateTy; 194fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar typedef OpaquePtr<QualType> TypeTy; 19528c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar 196fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar OpenCLOptions OpenCLFeatures; 197fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar FPOptions FPFeatures; 19828c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar 19928c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar const LangOptions &LangOpts; 200fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar Preprocessor &PP; 201fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar ASTContext &Context; 2021aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar ASTConsumer &Consumer; 2031aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar DiagnosticsEngine &Diags; 2041aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar SourceManager &SourceMgr; 2051aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar 2061aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar /// \brief Flag indicating whether or not to collect detailed statistics. 2071aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar bool CollectStats; 2081aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar 2091aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar /// \brief Source of additional semantic information. 2101aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar ExternalSemaSource *ExternalSource; 2111aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar 2121aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar /// \brief Code-completion consumer. 2131aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar CodeCompleteConsumer *CodeCompleter; 2141aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar 2151aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar /// CurContext - This is the current declaration context of parsing. 2161aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar DeclContext *CurContext; 2171aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar 2181aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar /// \brief Generally null except when we temporarily switch decl contexts, 2191aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar /// like in \see ActOnObjCTemporaryExitContainerContext. 220fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar DeclContext *OriginalLexicalContext; 221fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar 222fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar /// VAListTagName - The declaration name corresponding to __va_list_tag. 223fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar /// This is used as part of a hack to omit that class from ADL results. 2249643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar DeclarationName VAListTagName; 225fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar 2269643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// PackContext - Manages the stack for \#pragma pack. An alignment 22728c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar /// of 0 indicates default alignment. 2289643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar void *PackContext; // Really a "PragmaPackStack*" 2299643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2309643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar bool MSStructPragmaOn; // True when \#pragma ms_struct on 2319643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2329643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// VisContext - Manages the stack for \#pragma GCC visibility. 2339643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar void *VisContext; // Really a "PragmaVisStack*" 2349643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2359643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// ExprNeedsCleanups - True if the current evaluation context 2369643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// requires cleanups to be run at its conclusion. 2379643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar bool ExprNeedsCleanups; 2389643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2399643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// ExprCleanupObjects - This is the stack of objects requiring 2409643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// cleanup that are created by the current full expression. The 2419643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// element type here is ExprWithCleanups::Object. 2429643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar SmallVector<BlockDecl*, 8> ExprCleanupObjects; 2439643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2449643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar llvm::SmallPtrSet<Expr*, 8> MaybeODRUseExprs; 2459643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2469643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// \brief Stack containing information about each of the nested 2479643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// function, block, and method scopes that are currently active. 2489643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// 2499643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// This array is never empty. Clients should ignore the first 2509643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// element, which is used to cache a single FunctionScopeInfo 2519643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// that's used to parse every top-level function. 2529643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; 2539643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2549643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, 2559643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar &ExternalSemaSource::ReadExtVectorDecls, 2, 2> 2569643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar ExtVectorDeclsType; 2579643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2589643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// ExtVectorDecls - This is a list all the extended vector types. This allows 2599643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// us to associate a raw vector type with one of the ext_vector type names. 2609643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// This is only necessary for issuing pretty diagnostics. 2619643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar ExtVectorDeclsType ExtVectorDecls; 262fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar 2639643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// \brief The set of types for which we have already complained about the 2649643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// definitions being hidden. 2659643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// 2669643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// This set is used to suppress redundant diagnostics. 2679643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar llvm::SmallPtrSet<NamedDecl *, 4> HiddenDefinitions; 2689643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2699643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. 2709643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar OwningPtr<CXXFieldCollector> FieldCollector; 2719643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2729643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar typedef llvm::SmallSetVector<const NamedDecl*, 16> NamedDeclSetType; 2739643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2749643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// \brief Set containing all declared private fields that are not used. 2759643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar NamedDeclSetType UnusedPrivateFields; 2769643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2779643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; 2789643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2799643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// PureVirtualClassDiagSet - a set of class declarations which we have 2809643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// emitted a list of pure virtual functions. Used to prevent emitting the 2819643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// same list more than once. 2829643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet; 2839643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2849643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// ParsingInitForAutoVars - a set of declarations with auto types for which 2859643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// we are currently parsing the initializer. 2869643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; 2879643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar 2889643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// \brief A mapping from external names to the most recent 2899643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// locally-scoped external declaration with that name. 2909643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// 2919643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// This map contains external declarations introduced in local 2929643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// scoped, e.g., 2939643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// 2949643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// \code 2959643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// void f() { 2969643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// void foo(int, int); 2979643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// } 2989643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// \endcode 2999643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// 3009643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// Here, the name "foo" will be associated with the declaration on 3019643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// "foo" within f. This name is not visible outside of 3029643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// "f". However, we still find it in two cases: 3039643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// 3049643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// - If we are declaring another external with the name "foo", we 3059643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// can find "foo" as a previous declaration, so that the types 3069643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// of this external declaration can be checked for 3079643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// compatibility. 3089643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// 3099643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// - If we would implicitly declare "foo" (e.g., due to a call to 3109643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// "foo" in C when no prototype or definition is visible), then 311fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar /// we find this declaration of "foo" and complain that it is 3129643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// not visible. 313fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls; 314fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar 3151aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar /// \brief Look for a locally scoped external declaration by the given name. 3169643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar llvm::DenseMap<DeclarationName, NamedDecl *>::iterator 3171aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar findLocallyScopedExternalDecl(DeclarationName Name); 3181aa14aac4198bca0f44e4adad42bf6238cbf9757Daniel Dunbar 3199643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar typedef LazyVector<VarDecl *, ExternalSemaSource, 3209643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> 3219643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar TentativeDefinitionsType; 322fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar 3239643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar /// \brief All the tentative definitions encountered in the TU. 3249643ac55142d40da404caa8e5fedfef2cd7b4afcDaniel Dunbar TentativeDefinitionsType TentativeDefinitions; 325fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar 32628c251b54b0b311749f07babe0f6909e71e877bcDaniel Dunbar typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, 327fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> 328fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar UnusedFileScopedDeclsType; 329fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar 330fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar /// \brief The set of file scoped decls seen so far that have not been used 331fc6877aec9826fa830204d49eba7fac7412b841eDaniel Dunbar /// and must warn if not used. Only contains the first declaration. 332 UnusedFileScopedDeclsType UnusedFileScopedDecls; 333 334 typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, 335 &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> 336 DelegatingCtorDeclsType; 337 338 /// \brief All the delegating constructors seen so far in the file, used for 339 /// cycle detection at the end of the TU. 340 DelegatingCtorDeclsType DelegatingCtorDecls; 341 342 /// \brief All the destructors seen during a class definition that had their 343 /// exception spec computation delayed because it depended on an unparsed 344 /// exception spec. 345 SmallVector<CXXDestructorDecl*, 2> DelayedDestructorExceptionSpecs; 346 347 /// \brief All the overriding destructors seen during a class definition 348 /// (there could be multiple due to nested classes) that had their exception 349 /// spec checks delayed, plus the overridden destructor. 350 SmallVector<std::pair<const CXXDestructorDecl*, 351 const CXXDestructorDecl*>, 2> 352 DelayedDestructorExceptionSpecChecks; 353 354 /// \brief Callback to the parser to parse templated functions when needed. 355 typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD); 356 LateTemplateParserCB *LateTemplateParser; 357 void *OpaqueParser; 358 359 void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) { 360 LateTemplateParser = LTP; 361 OpaqueParser = P; 362 } 363 364 class DelayedDiagnostics; 365 366 class DelayedDiagnosticsState { 367 sema::DelayedDiagnosticPool *SavedPool; 368 friend class Sema::DelayedDiagnostics; 369 }; 370 typedef DelayedDiagnosticsState ParsingDeclState; 371 typedef DelayedDiagnosticsState ProcessingContextState; 372 373 /// A class which encapsulates the logic for delaying diagnostics 374 /// during parsing and other processing. 375 class DelayedDiagnostics { 376 /// \brief The current pool of diagnostics into which delayed 377 /// diagnostics should go. 378 sema::DelayedDiagnosticPool *CurPool; 379 380 public: 381 DelayedDiagnostics() : CurPool(0) {} 382 383 /// Adds a delayed diagnostic. 384 void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h 385 386 /// Determines whether diagnostics should be delayed. 387 bool shouldDelayDiagnostics() { return CurPool != 0; } 388 389 /// Returns the current delayed-diagnostics pool. 390 sema::DelayedDiagnosticPool *getCurrentPool() const { 391 return CurPool; 392 } 393 394 /// Enter a new scope. Access and deprecation diagnostics will be 395 /// collected in this pool. 396 DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { 397 DelayedDiagnosticsState state; 398 state.SavedPool = CurPool; 399 CurPool = &pool; 400 return state; 401 } 402 403 /// Leave a delayed-diagnostic state that was previously pushed. 404 /// Do not emit any of the diagnostics. This is performed as part 405 /// of the bookkeeping of popping a pool "properly". 406 void popWithoutEmitting(DelayedDiagnosticsState state) { 407 CurPool = state.SavedPool; 408 } 409 410 /// Enter a new scope where access and deprecation diagnostics are 411 /// not delayed. 412 DelayedDiagnosticsState pushUndelayed() { 413 DelayedDiagnosticsState state; 414 state.SavedPool = CurPool; 415 CurPool = 0; 416 return state; 417 } 418 419 /// Undo a previous pushUndelayed(). 420 void popUndelayed(DelayedDiagnosticsState state) { 421 assert(CurPool == NULL); 422 CurPool = state.SavedPool; 423 } 424 } DelayedDiagnostics; 425 426 /// A RAII object to temporarily push a declaration context. 427 class ContextRAII { 428 private: 429 Sema &S; 430 DeclContext *SavedContext; 431 ProcessingContextState SavedContextState; 432 QualType SavedCXXThisTypeOverride; 433 434 public: 435 ContextRAII(Sema &S, DeclContext *ContextToPush) 436 : S(S), SavedContext(S.CurContext), 437 SavedContextState(S.DelayedDiagnostics.pushUndelayed()), 438 SavedCXXThisTypeOverride(S.CXXThisTypeOverride) 439 { 440 assert(ContextToPush && "pushing null context"); 441 S.CurContext = ContextToPush; 442 } 443 444 void pop() { 445 if (!SavedContext) return; 446 S.CurContext = SavedContext; 447 S.DelayedDiagnostics.popUndelayed(SavedContextState); 448 S.CXXThisTypeOverride = SavedCXXThisTypeOverride; 449 SavedContext = 0; 450 } 451 452 ~ContextRAII() { 453 pop(); 454 } 455 }; 456 457 /// WeakUndeclaredIdentifiers - Identifiers contained in 458 /// \#pragma weak before declared. rare. may alias another 459 /// identifier, declared or undeclared 460 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers; 461 462 /// ExtnameUndeclaredIdentifiers - Identifiers contained in 463 /// \#pragma redefine_extname before declared. Used in Solaris system headers 464 /// to define functions that occur in multiple standards to call the version 465 /// in the currently selected standard. 466 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; 467 468 469 /// \brief Load weak undeclared identifiers from the external source. 470 void LoadExternalWeakUndeclaredIdentifiers(); 471 472 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by 473 /// \#pragma weak during processing of other Decls. 474 /// I couldn't figure out a clean way to generate these in-line, so 475 /// we store them here and handle separately -- which is a hack. 476 /// It would be best to refactor this. 477 SmallVector<Decl*,2> WeakTopLevelDecl; 478 479 IdentifierResolver IdResolver; 480 481 /// Translation Unit Scope - useful to Objective-C actions that need 482 /// to lookup file scope declarations in the "ordinary" C decl namespace. 483 /// For example, user-defined classes, built-in "id" type, etc. 484 Scope *TUScope; 485 486 /// \brief The C++ "std" namespace, where the standard library resides. 487 LazyDeclPtr StdNamespace; 488 489 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++ 490 /// standard library. 491 LazyDeclPtr StdBadAlloc; 492 493 /// \brief The C++ "std::initializer_list" template, which is defined in 494 /// \<initializer_list>. 495 ClassTemplateDecl *StdInitializerList; 496 497 /// \brief The C++ "type_info" declaration, which is defined in \<typeinfo>. 498 RecordDecl *CXXTypeInfoDecl; 499 500 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files. 501 RecordDecl *MSVCGuidDecl; 502 503 /// \brief Caches identifiers/selectors for NSFoundation APIs. 504 llvm::OwningPtr<NSAPI> NSAPIObj; 505 506 /// \brief The declaration of the Objective-C NSNumber class. 507 ObjCInterfaceDecl *NSNumberDecl; 508 509 /// \brief Pointer to NSNumber type (NSNumber *). 510 QualType NSNumberPointer; 511 512 /// \brief The Objective-C NSNumber methods used to create NSNumber literals. 513 ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; 514 515 /// \brief The declaration of the Objective-C NSString class. 516 ObjCInterfaceDecl *NSStringDecl; 517 518 /// \brief Pointer to NSString type (NSString *). 519 QualType NSStringPointer; 520 521 /// \brief The declaration of the stringWithUTF8String: method. 522 ObjCMethodDecl *StringWithUTF8StringMethod; 523 524 /// \brief The declaration of the Objective-C NSArray class. 525 ObjCInterfaceDecl *NSArrayDecl; 526 527 /// \brief The declaration of the arrayWithObjects:count: method. 528 ObjCMethodDecl *ArrayWithObjectsMethod; 529 530 /// \brief The declaration of the Objective-C NSDictionary class. 531 ObjCInterfaceDecl *NSDictionaryDecl; 532 533 /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method. 534 ObjCMethodDecl *DictionaryWithObjectsMethod; 535 536 /// \brief id<NSCopying> type. 537 QualType QIDNSCopying; 538 539 /// A flag to remember whether the implicit forms of operator new and delete 540 /// have been declared. 541 bool GlobalNewDeleteDeclared; 542 543 /// A flag that is set when parsing a -dealloc method and no [super dealloc] 544 /// call was found yet. 545 bool ObjCShouldCallSuperDealloc; 546 /// A flag that is set when parsing a -finalize method and no [super finalize] 547 /// call was found yet. 548 bool ObjCShouldCallSuperFinalize; 549 550 /// \brief Describes how the expressions currently being parsed are 551 /// evaluated at run-time, if at all. 552 enum ExpressionEvaluationContext { 553 /// \brief The current expression and its subexpressions occur within an 554 /// unevaluated operand (C++11 [expr]p7), such as the subexpression of 555 /// \c sizeof, where the type of the expression may be significant but 556 /// no code will be generated to evaluate the value of the expression at 557 /// run time. 558 Unevaluated, 559 560 /// \brief The current context is "potentially evaluated" in C++11 terms, 561 /// but the expression is evaluated at compile-time (like the values of 562 /// cases in a switch statment). 563 ConstantEvaluated, 564 565 /// \brief The current expression is potentially evaluated at run time, 566 /// which means that code may be generated to evaluate the value of the 567 /// expression at run time. 568 PotentiallyEvaluated, 569 570 /// \brief The current expression is potentially evaluated, but any 571 /// declarations referenced inside that expression are only used if 572 /// in fact the current expression is used. 573 /// 574 /// This value is used when parsing default function arguments, for which 575 /// we would like to provide diagnostics (e.g., passing non-POD arguments 576 /// through varargs) but do not want to mark declarations as "referenced" 577 /// until the default argument is used. 578 PotentiallyEvaluatedIfUsed 579 }; 580 581 /// \brief Data structure used to record current or nested 582 /// expression evaluation contexts. 583 struct ExpressionEvaluationContextRecord { 584 /// \brief The expression evaluation context. 585 ExpressionEvaluationContext Context; 586 587 /// \brief Whether the enclosing context needed a cleanup. 588 bool ParentNeedsCleanups; 589 590 /// \brief Whether we are in a decltype expression. 591 bool IsDecltype; 592 593 /// \brief The number of active cleanup objects when we entered 594 /// this expression evaluation context. 595 unsigned NumCleanupObjects; 596 597 llvm::SmallPtrSet<Expr*, 8> SavedMaybeODRUseExprs; 598 599 /// \brief The lambdas that are present within this context, if it 600 /// is indeed an unevaluated context. 601 llvm::SmallVector<LambdaExpr *, 2> Lambdas; 602 603 /// \brief The declaration that provides context for the lambda expression 604 /// if the normal declaration context does not suffice, e.g., in a 605 /// default function argument. 606 Decl *LambdaContextDecl; 607 608 /// \brief The context information used to mangle lambda expressions 609 /// within this context. 610 /// 611 /// This mangling information is allocated lazily, since most contexts 612 /// do not have lambda expressions. 613 LambdaMangleContext *LambdaMangle; 614 615 /// \brief If we are processing a decltype type, a set of call expressions 616 /// for which we have deferred checking the completeness of the return type. 617 llvm::SmallVector<CallExpr*, 8> DelayedDecltypeCalls; 618 619 /// \brief If we are processing a decltype type, a set of temporary binding 620 /// expressions for which we have deferred checking the destructor. 621 llvm::SmallVector<CXXBindTemporaryExpr*, 8> DelayedDecltypeBinds; 622 623 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, 624 unsigned NumCleanupObjects, 625 bool ParentNeedsCleanups, 626 Decl *LambdaContextDecl, 627 bool IsDecltype) 628 : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups), 629 IsDecltype(IsDecltype), NumCleanupObjects(NumCleanupObjects), 630 LambdaContextDecl(LambdaContextDecl), LambdaMangle() { } 631 632 ~ExpressionEvaluationContextRecord() { 633 delete LambdaMangle; 634 } 635 636 /// \brief Retrieve the mangling context for lambdas. 637 LambdaMangleContext &getLambdaMangleContext() { 638 assert(LambdaContextDecl && "Need to have a lambda context declaration"); 639 if (!LambdaMangle) 640 LambdaMangle = new LambdaMangleContext; 641 return *LambdaMangle; 642 } 643 }; 644 645 /// A stack of expression evaluation contexts. 646 SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; 647 648 /// SpecialMemberOverloadResult - The overloading result for a special member 649 /// function. 650 /// 651 /// This is basically a wrapper around PointerIntPair. The lowest bits of the 652 /// integer are used to determine whether overload resolution succeeded. 653 class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode { 654 public: 655 enum Kind { 656 NoMemberOrDeleted, 657 Ambiguous, 658 Success 659 }; 660 661 private: 662 llvm::PointerIntPair<CXXMethodDecl*, 2> Pair; 663 664 public: 665 SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID) 666 : FastFoldingSetNode(ID) 667 {} 668 669 CXXMethodDecl *getMethod() const { return Pair.getPointer(); } 670 void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } 671 672 Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } 673 void setKind(Kind K) { Pair.setInt(K); } 674 }; 675 676 /// \brief A cache of special member function overload resolution results 677 /// for C++ records. 678 llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache; 679 680 /// \brief The kind of translation unit we are processing. 681 /// 682 /// When we're processing a complete translation unit, Sema will perform 683 /// end-of-translation-unit semantic tasks (such as creating 684 /// initializers for tentative definitions in C) once parsing has 685 /// completed. Modules and precompiled headers perform different kinds of 686 /// checks. 687 TranslationUnitKind TUKind; 688 689 llvm::BumpPtrAllocator BumpAlloc; 690 691 /// \brief The number of SFINAE diagnostics that have been trapped. 692 unsigned NumSFINAEErrors; 693 694 typedef llvm::DenseMap<ParmVarDecl *, SmallVector<ParmVarDecl *, 1> > 695 UnparsedDefaultArgInstantiationsMap; 696 697 /// \brief A mapping from parameters with unparsed default arguments to the 698 /// set of instantiations of each parameter. 699 /// 700 /// This mapping is a temporary data structure used when parsing 701 /// nested class templates or nested classes of class templates, 702 /// where we might end up instantiating an inner class before the 703 /// default arguments of its methods have been parsed. 704 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; 705 706 // Contains the locations of the beginning of unparsed default 707 // argument locations. 708 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs; 709 710 /// UndefinedInternals - all the used, undefined objects with 711 /// internal linkage in this translation unit. 712 llvm::DenseMap<NamedDecl*, SourceLocation> UndefinedInternals; 713 714 typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods; 715 typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool; 716 717 /// Method Pool - allows efficient lookup when typechecking messages to "id". 718 /// We need to maintain a list, since selectors can have differing signatures 719 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% 720 /// of selectors are "overloaded"). 721 GlobalMethodPool MethodPool; 722 723 /// Method selectors used in a \@selector expression. Used for implementation 724 /// of -Wselector. 725 llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors; 726 727 void ReadMethodPool(Selector Sel); 728 729 /// Private Helper predicate to check for 'self'. 730 bool isSelfExpr(Expr *RExpr); 731 732 /// \brief Cause the active diagnostic on the DiagosticsEngine to be 733 /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and 734 /// should not be used elsewhere. 735 void EmitCurrentDiagnostic(unsigned DiagID); 736 737public: 738 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, 739 TranslationUnitKind TUKind = TU_Complete, 740 CodeCompleteConsumer *CompletionConsumer = 0); 741 ~Sema(); 742 743 /// \brief Perform initialization that occurs after the parser has been 744 /// initialized but before it parses anything. 745 void Initialize(); 746 747 const LangOptions &getLangOpts() const { return LangOpts; } 748 OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } 749 FPOptions &getFPOptions() { return FPFeatures; } 750 751 DiagnosticsEngine &getDiagnostics() const { return Diags; } 752 SourceManager &getSourceManager() const { return SourceMgr; } 753 const TargetAttributesSema &getTargetAttributesSema() const; 754 Preprocessor &getPreprocessor() const { return PP; } 755 ASTContext &getASTContext() const { return Context; } 756 ASTConsumer &getASTConsumer() const { return Consumer; } 757 ASTMutationListener *getASTMutationListener() const; 758 759 void PrintStats() const; 760 761 /// \brief Helper class that creates diagnostics with optional 762 /// template instantiation stacks. 763 /// 764 /// This class provides a wrapper around the basic DiagnosticBuilder 765 /// class that emits diagnostics. SemaDiagnosticBuilder is 766 /// responsible for emitting the diagnostic (as DiagnosticBuilder 767 /// does) and, if the diagnostic comes from inside a template 768 /// instantiation, printing the template instantiation stack as 769 /// well. 770 class SemaDiagnosticBuilder : public DiagnosticBuilder { 771 Sema &SemaRef; 772 unsigned DiagID; 773 774 public: 775 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) 776 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } 777 778 ~SemaDiagnosticBuilder() { 779 // If we aren't active, there is nothing to do. 780 if (!isActive()) return; 781 782 // Otherwise, we need to emit the diagnostic. First flush the underlying 783 // DiagnosticBuilder data, and clear the diagnostic builder itself so it 784 // won't emit the diagnostic in its own destructor. 785 // 786 // This seems wasteful, in that as written the DiagnosticBuilder dtor will 787 // do its own needless checks to see if the diagnostic needs to be 788 // emitted. However, because we take care to ensure that the builder 789 // objects never escape, a sufficiently smart compiler will be able to 790 // eliminate that code. 791 FlushCounts(); 792 Clear(); 793 794 // Dispatch to Sema to emit the diagnostic. 795 SemaRef.EmitCurrentDiagnostic(DiagID); 796 } 797 }; 798 799 /// \brief Emit a diagnostic. 800 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { 801 DiagnosticBuilder DB = Diags.Report(Loc, DiagID); 802 return SemaDiagnosticBuilder(DB, *this, DiagID); 803 } 804 805 /// \brief Emit a partial diagnostic. 806 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD); 807 808 /// \brief Build a partial diagnostic. 809 PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h 810 811 bool findMacroSpelling(SourceLocation &loc, StringRef name); 812 813 /// \brief Get a string to suggest for zero-initialization of a type. 814 std::string getFixItZeroInitializerForType(QualType T) const; 815 std::string getFixItZeroLiteralForType(QualType T) const; 816 817 ExprResult Owned(Expr* E) { return E; } 818 ExprResult Owned(ExprResult R) { return R; } 819 StmtResult Owned(Stmt* S) { return S; } 820 821 void ActOnEndOfTranslationUnit(); 822 823 void CheckDelegatingCtorCycles(); 824 825 Scope *getScopeForContext(DeclContext *Ctx); 826 827 void PushFunctionScope(); 828 void PushBlockScope(Scope *BlockScope, BlockDecl *Block); 829 void PushLambdaScope(CXXRecordDecl *Lambda, CXXMethodDecl *CallOperator); 830 void PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP =0, 831 const Decl *D = 0, const BlockExpr *blkExpr = 0); 832 833 sema::FunctionScopeInfo *getCurFunction() const { 834 return FunctionScopes.back(); 835 } 836 837 void PushCompoundScope(); 838 void PopCompoundScope(); 839 840 sema::CompoundScopeInfo &getCurCompoundScope() const; 841 842 bool hasAnyUnrecoverableErrorsInThisFunction() const; 843 844 /// \brief Retrieve the current block, if any. 845 sema::BlockScopeInfo *getCurBlock(); 846 847 /// \brief Retrieve the current lambda expression, if any. 848 sema::LambdaScopeInfo *getCurLambda(); 849 850 /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls 851 SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; } 852 853 void ActOnComment(SourceRange Comment); 854 855 //===--------------------------------------------------------------------===// 856 // Type Analysis / Processing: SemaType.cpp. 857 // 858 859 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs); 860 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) { 861 return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR)); 862 } 863 QualType BuildPointerType(QualType T, 864 SourceLocation Loc, DeclarationName Entity); 865 QualType BuildReferenceType(QualType T, bool LValueRef, 866 SourceLocation Loc, DeclarationName Entity); 867 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, 868 Expr *ArraySize, unsigned Quals, 869 SourceRange Brackets, DeclarationName Entity); 870 QualType BuildExtVectorType(QualType T, Expr *ArraySize, 871 SourceLocation AttrLoc); 872 QualType BuildFunctionType(QualType T, 873 QualType *ParamTypes, unsigned NumParamTypes, 874 bool Variadic, bool HasTrailingReturn, 875 unsigned Quals, RefQualifierKind RefQualifier, 876 SourceLocation Loc, DeclarationName Entity, 877 FunctionType::ExtInfo Info); 878 QualType BuildMemberPointerType(QualType T, QualType Class, 879 SourceLocation Loc, 880 DeclarationName Entity); 881 QualType BuildBlockPointerType(QualType T, 882 SourceLocation Loc, DeclarationName Entity); 883 QualType BuildParenType(QualType T); 884 QualType BuildAtomicType(QualType T, SourceLocation Loc); 885 886 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); 887 TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); 888 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T, 889 TypeSourceInfo *ReturnTypeInfo); 890 891 /// \brief Package the given type and TSI into a ParsedType. 892 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); 893 DeclarationNameInfo GetNameForDeclarator(Declarator &D); 894 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); 895 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0); 896 CanThrowResult canThrow(const Expr *E); 897 const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, 898 const FunctionProtoType *FPT); 899 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range); 900 bool CheckDistantExceptionSpec(QualType T); 901 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); 902 bool CheckEquivalentExceptionSpec( 903 const FunctionProtoType *Old, SourceLocation OldLoc, 904 const FunctionProtoType *New, SourceLocation NewLoc); 905 bool CheckEquivalentExceptionSpec( 906 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 907 const FunctionProtoType *Old, SourceLocation OldLoc, 908 const FunctionProtoType *New, SourceLocation NewLoc, 909 bool *MissingExceptionSpecification = 0, 910 bool *MissingEmptyExceptionSpecification = 0, 911 bool AllowNoexceptAllMatchWithNoSpec = false, 912 bool IsOperatorNew = false); 913 bool CheckExceptionSpecSubset( 914 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 915 const FunctionProtoType *Superset, SourceLocation SuperLoc, 916 const FunctionProtoType *Subset, SourceLocation SubLoc); 917 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID, 918 const FunctionProtoType *Target, SourceLocation TargetLoc, 919 const FunctionProtoType *Source, SourceLocation SourceLoc); 920 921 TypeResult ActOnTypeName(Scope *S, Declarator &D); 922 923 /// \brief The parser has parsed the context-sensitive type 'instancetype' 924 /// in an Objective-C message declaration. Return the appropriate type. 925 ParsedType ActOnObjCInstanceType(SourceLocation Loc); 926 927 /// \brief Abstract class used to diagnose incomplete types. 928 struct TypeDiagnoser { 929 bool Suppressed; 930 931 TypeDiagnoser(bool Suppressed = false) : Suppressed(Suppressed) { } 932 933 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; 934 virtual ~TypeDiagnoser() {} 935 }; 936 937 static int getPrintable(int I) { return I; } 938 static unsigned getPrintable(unsigned I) { return I; } 939 static bool getPrintable(bool B) { return B; } 940 static const char * getPrintable(const char *S) { return S; } 941 static StringRef getPrintable(StringRef S) { return S; } 942 static const std::string &getPrintable(const std::string &S) { return S; } 943 static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { 944 return II; 945 } 946 static DeclarationName getPrintable(DeclarationName N) { return N; } 947 static QualType getPrintable(QualType T) { return T; } 948 static SourceRange getPrintable(SourceRange R) { return R; } 949 static SourceRange getPrintable(SourceLocation L) { return L; } 950 static SourceRange getPrintable(Expr *E) { return E->getSourceRange(); } 951 static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} 952 953 template<typename T1> 954 class BoundTypeDiagnoser1 : public TypeDiagnoser { 955 unsigned DiagID; 956 const T1 &Arg1; 957 958 public: 959 BoundTypeDiagnoser1(unsigned DiagID, const T1 &Arg1) 960 : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { } 961 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { 962 if (Suppressed) return; 963 S.Diag(Loc, DiagID) << getPrintable(Arg1) << T; 964 } 965 966 virtual ~BoundTypeDiagnoser1() { } 967 }; 968 969 template<typename T1, typename T2> 970 class BoundTypeDiagnoser2 : public TypeDiagnoser { 971 unsigned DiagID; 972 const T1 &Arg1; 973 const T2 &Arg2; 974 975 public: 976 BoundTypeDiagnoser2(unsigned DiagID, const T1 &Arg1, 977 const T2 &Arg2) 978 : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), 979 Arg2(Arg2) { } 980 981 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { 982 if (Suppressed) return; 983 S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T; 984 } 985 986 virtual ~BoundTypeDiagnoser2() { } 987 }; 988 989 template<typename T1, typename T2, typename T3> 990 class BoundTypeDiagnoser3 : public TypeDiagnoser { 991 unsigned DiagID; 992 const T1 &Arg1; 993 const T2 &Arg2; 994 const T3 &Arg3; 995 996 public: 997 BoundTypeDiagnoser3(unsigned DiagID, const T1 &Arg1, 998 const T2 &Arg2, const T3 &Arg3) 999 : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), 1000 Arg2(Arg2), Arg3(Arg3) { } 1001 1002 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { 1003 if (Suppressed) return; 1004 S.Diag(Loc, DiagID) 1005 << getPrintable(Arg1) << getPrintable(Arg2) << getPrintable(Arg3) << T; 1006 } 1007 1008 virtual ~BoundTypeDiagnoser3() { } 1009 }; 1010 1011 bool RequireCompleteType(SourceLocation Loc, QualType T, 1012 TypeDiagnoser &Diagnoser); 1013 bool RequireCompleteType(SourceLocation Loc, QualType T, 1014 unsigned DiagID); 1015 1016 template<typename T1> 1017 bool RequireCompleteType(SourceLocation Loc, QualType T, 1018 unsigned DiagID, const T1 &Arg1) { 1019 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 1020 return RequireCompleteType(Loc, T, Diagnoser); 1021 } 1022 1023 template<typename T1, typename T2> 1024 bool RequireCompleteType(SourceLocation Loc, QualType T, 1025 unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { 1026 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 1027 return RequireCompleteType(Loc, T, Diagnoser); 1028 } 1029 1030 template<typename T1, typename T2, typename T3> 1031 bool RequireCompleteType(SourceLocation Loc, QualType T, 1032 unsigned DiagID, const T1 &Arg1, const T2 &Arg2, 1033 const T3 &Arg3) { 1034 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, 1035 Arg3); 1036 return RequireCompleteType(Loc, T, Diagnoser); 1037 } 1038 1039 bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser); 1040 bool RequireCompleteExprType(Expr *E, unsigned DiagID); 1041 1042 template<typename T1> 1043 bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) { 1044 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 1045 return RequireCompleteExprType(E, Diagnoser); 1046 } 1047 1048 template<typename T1, typename T2> 1049 bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1, 1050 const T2 &Arg2) { 1051 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 1052 return RequireCompleteExprType(E, Diagnoser); 1053 } 1054 1055 template<typename T1, typename T2, typename T3> 1056 bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1, 1057 const T2 &Arg2, const T3 &Arg3) { 1058 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, 1059 Arg3); 1060 return RequireCompleteExprType(E, Diagnoser); 1061 } 1062 1063 bool RequireLiteralType(SourceLocation Loc, QualType T, 1064 TypeDiagnoser &Diagnoser); 1065 bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); 1066 1067 template<typename T1> 1068 bool RequireLiteralType(SourceLocation Loc, QualType T, 1069 unsigned DiagID, const T1 &Arg1) { 1070 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 1071 return RequireLiteralType(Loc, T, Diagnoser); 1072 } 1073 1074 template<typename T1, typename T2> 1075 bool RequireLiteralType(SourceLocation Loc, QualType T, 1076 unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { 1077 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 1078 return RequireLiteralType(Loc, T, Diagnoser); 1079 } 1080 1081 template<typename T1, typename T2, typename T3> 1082 bool RequireLiteralType(SourceLocation Loc, QualType T, 1083 unsigned DiagID, const T1 &Arg1, const T2 &Arg2, 1084 const T3 &Arg3) { 1085 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, 1086 Arg3); 1087 return RequireLiteralType(Loc, T, Diagnoser); 1088 } 1089 1090 QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 1091 const CXXScopeSpec &SS, QualType T); 1092 1093 QualType BuildTypeofExprType(Expr *E, SourceLocation Loc); 1094 QualType BuildDecltypeType(Expr *E, SourceLocation Loc); 1095 QualType BuildUnaryTransformType(QualType BaseType, 1096 UnaryTransformType::UTTKind UKind, 1097 SourceLocation Loc); 1098 1099 //===--------------------------------------------------------------------===// 1100 // Symbol table / Decl tracking callbacks: SemaDecl.cpp. 1101 // 1102 1103 /// List of decls defined in a function prototype. This contains EnumConstants 1104 /// that incorrectly end up in translation unit scope because there is no 1105 /// function to pin them on. ActOnFunctionDeclarator reads this list and patches 1106 /// them into the FunctionDecl. 1107 std::vector<NamedDecl*> DeclsInPrototypeScope; 1108 /// Nonzero if we are currently parsing a function declarator. This is a counter 1109 /// as opposed to a boolean so we can deal with nested function declarators 1110 /// such as: 1111 /// void f(void (*g)(), ...) 1112 unsigned InFunctionDeclarator; 1113 1114 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0); 1115 1116 void DiagnoseUseOfUnimplementedSelectors(); 1117 1118 bool isSimpleTypeSpecifier(tok::TokenKind Kind) const; 1119 1120 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc, 1121 Scope *S, CXXScopeSpec *SS = 0, 1122 bool isClassName = false, 1123 bool HasTrailingDot = false, 1124 ParsedType ObjectType = ParsedType(), 1125 bool IsCtorOrDtorName = false, 1126 bool WantNontrivialTypeSourceInfo = false, 1127 IdentifierInfo **CorrectedII = 0); 1128 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); 1129 bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); 1130 bool DiagnoseUnknownTypeName(IdentifierInfo *&II, 1131 SourceLocation IILoc, 1132 Scope *S, 1133 CXXScopeSpec *SS, 1134 ParsedType &SuggestedType); 1135 1136 /// \brief Describes the result of the name lookup and resolution performed 1137 /// by \c ClassifyName(). 1138 enum NameClassificationKind { 1139 NC_Unknown, 1140 NC_Error, 1141 NC_Keyword, 1142 NC_Type, 1143 NC_Expression, 1144 NC_NestedNameSpecifier, 1145 NC_TypeTemplate, 1146 NC_FunctionTemplate 1147 }; 1148 1149 class NameClassification { 1150 NameClassificationKind Kind; 1151 ExprResult Expr; 1152 TemplateName Template; 1153 ParsedType Type; 1154 const IdentifierInfo *Keyword; 1155 1156 explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} 1157 1158 public: 1159 NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {} 1160 1161 NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} 1162 1163 NameClassification(const IdentifierInfo *Keyword) 1164 : Kind(NC_Keyword), Keyword(Keyword) { } 1165 1166 static NameClassification Error() { 1167 return NameClassification(NC_Error); 1168 } 1169 1170 static NameClassification Unknown() { 1171 return NameClassification(NC_Unknown); 1172 } 1173 1174 static NameClassification NestedNameSpecifier() { 1175 return NameClassification(NC_NestedNameSpecifier); 1176 } 1177 1178 static NameClassification TypeTemplate(TemplateName Name) { 1179 NameClassification Result(NC_TypeTemplate); 1180 Result.Template = Name; 1181 return Result; 1182 } 1183 1184 static NameClassification FunctionTemplate(TemplateName Name) { 1185 NameClassification Result(NC_FunctionTemplate); 1186 Result.Template = Name; 1187 return Result; 1188 } 1189 1190 NameClassificationKind getKind() const { return Kind; } 1191 1192 ParsedType getType() const { 1193 assert(Kind == NC_Type); 1194 return Type; 1195 } 1196 1197 ExprResult getExpression() const { 1198 assert(Kind == NC_Expression); 1199 return Expr; 1200 } 1201 1202 TemplateName getTemplateName() const { 1203 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate); 1204 return Template; 1205 } 1206 1207 TemplateNameKind getTemplateNameKind() const { 1208 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate); 1209 return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template; 1210 } 1211}; 1212 1213 /// \brief Perform name lookup on the given name, classifying it based on 1214 /// the results of name lookup and the following token. 1215 /// 1216 /// This routine is used by the parser to resolve identifiers and help direct 1217 /// parsing. When the identifier cannot be found, this routine will attempt 1218 /// to correct the typo and classify based on the resulting name. 1219 /// 1220 /// \param S The scope in which we're performing name lookup. 1221 /// 1222 /// \param SS The nested-name-specifier that precedes the name. 1223 /// 1224 /// \param Name The identifier. If typo correction finds an alternative name, 1225 /// this pointer parameter will be updated accordingly. 1226 /// 1227 /// \param NameLoc The location of the identifier. 1228 /// 1229 /// \param NextToken The token following the identifier. Used to help 1230 /// disambiguate the name. 1231 NameClassification ClassifyName(Scope *S, 1232 CXXScopeSpec &SS, 1233 IdentifierInfo *&Name, 1234 SourceLocation NameLoc, 1235 const Token &NextToken); 1236 1237 Decl *ActOnDeclarator(Scope *S, Declarator &D); 1238 1239 Decl *HandleDeclarator(Scope *S, Declarator &D, 1240 MultiTemplateParamsArg TemplateParameterLists); 1241 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, 1242 const LookupResult &Previous, 1243 Scope *S); 1244 bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); 1245 bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, 1246 DeclarationName Name, 1247 SourceLocation Loc); 1248 void DiagnoseFunctionSpecifiers(Declarator& D); 1249 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R); 1250 void CheckShadow(Scope *S, VarDecl *D); 1251 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); 1252 void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); 1253 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1254 TypeSourceInfo *TInfo, 1255 LookupResult &Previous); 1256 NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, 1257 LookupResult &Previous, bool &Redeclaration); 1258 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1259 TypeSourceInfo *TInfo, 1260 LookupResult &Previous, 1261 MultiTemplateParamsArg TemplateParamLists); 1262 // Returns true if the variable declaration is a redeclaration 1263 bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); 1264 void CheckCompleteVariableDeclaration(VarDecl *var); 1265 void ActOnStartFunctionDeclarator(); 1266 void ActOnEndFunctionDeclarator(); 1267 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1268 TypeSourceInfo *TInfo, 1269 LookupResult &Previous, 1270 MultiTemplateParamsArg TemplateParamLists, 1271 bool &AddToScope); 1272 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 1273 1274 bool CheckConstexprFunctionDecl(const FunctionDecl *FD); 1275 bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body); 1276 1277 void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 1278 // Returns true if the function declaration is a redeclaration 1279 bool CheckFunctionDeclaration(Scope *S, 1280 FunctionDecl *NewFD, LookupResult &Previous, 1281 bool IsExplicitSpecialization); 1282 void CheckMain(FunctionDecl *FD, const DeclSpec &D); 1283 Decl *ActOnParamDeclarator(Scope *S, Declarator &D); 1284 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, 1285 SourceLocation Loc, 1286 QualType T); 1287 ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, 1288 SourceLocation NameLoc, IdentifierInfo *Name, 1289 QualType T, TypeSourceInfo *TSInfo, 1290 StorageClass SC, StorageClass SCAsWritten); 1291 void ActOnParamDefaultArgument(Decl *param, 1292 SourceLocation EqualLoc, 1293 Expr *defarg); 1294 void ActOnParamUnparsedDefaultArgument(Decl *param, 1295 SourceLocation EqualLoc, 1296 SourceLocation ArgLoc); 1297 void ActOnParamDefaultArgumentError(Decl *param); 1298 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, 1299 SourceLocation EqualLoc); 1300 1301 void CheckSelfReference(Decl *OrigDecl, Expr *E); 1302 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit, 1303 bool TypeMayContainAuto); 1304 void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto); 1305 void ActOnInitializerError(Decl *Dcl); 1306 void ActOnCXXForRangeDecl(Decl *D); 1307 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); 1308 void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); 1309 void FinalizeDeclaration(Decl *D); 1310 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, 1311 Decl **Group, 1312 unsigned NumDecls); 1313 DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls, 1314 bool TypeMayContainAuto = true); 1315 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, 1316 SourceLocation LocAfterDecls); 1317 void CheckForFunctionRedefinition(FunctionDecl *FD); 1318 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D); 1319 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D); 1320 void ActOnStartOfObjCMethodOrCFunctionDef(Scope *S, Decl *D, 1321 bool parseMethod); 1322 bool isObjCMethodDecl(Decl *D) { 1323 return D && isa<ObjCMethodDecl>(D); 1324 } 1325 1326 void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); 1327 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); 1328 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); 1329 1330 /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an 1331 /// attribute for which parsing is delayed. 1332 void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); 1333 1334 /// \brief Diagnose any unused parameters in the given sequence of 1335 /// ParmVarDecl pointers. 1336 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin, 1337 ParmVarDecl * const *End); 1338 1339 /// \brief Diagnose whether the size of parameters or return value of a 1340 /// function or obj-c method definition is pass-by-value and larger than a 1341 /// specified threshold. 1342 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin, 1343 ParmVarDecl * const *End, 1344 QualType ReturnTy, 1345 NamedDecl *D); 1346 1347 void DiagnoseInvalidJumps(Stmt *Body); 1348 Decl *ActOnFileScopeAsmDecl(Expr *expr, 1349 SourceLocation AsmLoc, 1350 SourceLocation RParenLoc); 1351 1352 /// \brief The parser has processed a module import declaration. 1353 /// 1354 /// \param AtLoc The location of the '@' symbol, if any. 1355 /// 1356 /// \param ImportLoc The location of the 'import' keyword. 1357 /// 1358 /// \param Path The module access path. 1359 DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc, 1360 ModuleIdPath Path); 1361 1362 /// \brief Retrieve a suitable printing policy. 1363 PrintingPolicy getPrintingPolicy() const { 1364 return getPrintingPolicy(Context, PP); 1365 } 1366 1367 /// \brief Retrieve a suitable printing policy. 1368 static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, 1369 const Preprocessor &PP); 1370 1371 /// Scope actions. 1372 void ActOnPopScope(SourceLocation Loc, Scope *S); 1373 void ActOnTranslationUnitScope(Scope *S); 1374 1375 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 1376 DeclSpec &DS); 1377 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 1378 DeclSpec &DS, 1379 MultiTemplateParamsArg TemplateParams); 1380 1381 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, 1382 AccessSpecifier AS, 1383 RecordDecl *Record); 1384 1385 Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, 1386 RecordDecl *Record); 1387 1388 bool isAcceptableTagRedeclaration(const TagDecl *Previous, 1389 TagTypeKind NewTag, bool isDefinition, 1390 SourceLocation NewTagLoc, 1391 const IdentifierInfo &Name); 1392 1393 enum TagUseKind { 1394 TUK_Reference, // Reference to a tag: 'struct foo *X;' 1395 TUK_Declaration, // Fwd decl of a tag: 'struct foo;' 1396 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' 1397 TUK_Friend // Friend declaration: 'friend struct foo;' 1398 }; 1399 1400 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, 1401 SourceLocation KWLoc, CXXScopeSpec &SS, 1402 IdentifierInfo *Name, SourceLocation NameLoc, 1403 AttributeList *Attr, AccessSpecifier AS, 1404 SourceLocation ModulePrivateLoc, 1405 MultiTemplateParamsArg TemplateParameterLists, 1406 bool &OwnedDecl, bool &IsDependent, 1407 SourceLocation ScopedEnumKWLoc, 1408 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType); 1409 1410 Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, 1411 unsigned TagSpec, SourceLocation TagLoc, 1412 CXXScopeSpec &SS, 1413 IdentifierInfo *Name, SourceLocation NameLoc, 1414 AttributeList *Attr, 1415 MultiTemplateParamsArg TempParamLists); 1416 1417 TypeResult ActOnDependentTag(Scope *S, 1418 unsigned TagSpec, 1419 TagUseKind TUK, 1420 const CXXScopeSpec &SS, 1421 IdentifierInfo *Name, 1422 SourceLocation TagLoc, 1423 SourceLocation NameLoc); 1424 1425 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, 1426 IdentifierInfo *ClassName, 1427 SmallVectorImpl<Decl *> &Decls); 1428 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, 1429 Declarator &D, Expr *BitfieldWidth); 1430 1431 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, 1432 Declarator &D, Expr *BitfieldWidth, 1433 InClassInitStyle InitStyle, 1434 AccessSpecifier AS); 1435 1436 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, 1437 TypeSourceInfo *TInfo, 1438 RecordDecl *Record, SourceLocation Loc, 1439 bool Mutable, Expr *BitfieldWidth, 1440 InClassInitStyle InitStyle, 1441 SourceLocation TSSL, 1442 AccessSpecifier AS, NamedDecl *PrevDecl, 1443 Declarator *D = 0); 1444 1445 enum CXXSpecialMember { 1446 CXXDefaultConstructor, 1447 CXXCopyConstructor, 1448 CXXMoveConstructor, 1449 CXXCopyAssignment, 1450 CXXMoveAssignment, 1451 CXXDestructor, 1452 CXXInvalid 1453 }; 1454 bool CheckNontrivialField(FieldDecl *FD); 1455 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem); 1456 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD); 1457 void ActOnLastBitfield(SourceLocation DeclStart, 1458 SmallVectorImpl<Decl *> &AllIvarDecls); 1459 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, 1460 Declarator &D, Expr *BitfieldWidth, 1461 tok::ObjCKeywordKind visibility); 1462 1463 // This is used for both record definitions and ObjC interface declarations. 1464 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl, 1465 llvm::ArrayRef<Decl *> Fields, 1466 SourceLocation LBrac, SourceLocation RBrac, 1467 AttributeList *AttrList); 1468 1469 /// ActOnTagStartDefinition - Invoked when we have entered the 1470 /// scope of a tag's definition (e.g., for an enumeration, class, 1471 /// struct, or union). 1472 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); 1473 1474 Decl *ActOnObjCContainerStartDefinition(Decl *IDecl); 1475 1476 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a 1477 /// C++ record definition's base-specifiers clause and are starting its 1478 /// member declarations. 1479 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, 1480 SourceLocation FinalLoc, 1481 SourceLocation LBraceLoc); 1482 1483 /// ActOnTagFinishDefinition - Invoked once we have finished parsing 1484 /// the definition of a tag (enumeration, class, struct, or union). 1485 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, 1486 SourceLocation RBraceLoc); 1487 1488 void ActOnObjCContainerFinishDefinition(); 1489 1490 /// \brief Invoked when we must temporarily exit the objective-c container 1491 /// scope for parsing/looking-up C constructs. 1492 /// 1493 /// Must be followed by a call to \see ActOnObjCReenterContainerContext 1494 void ActOnObjCTemporaryExitContainerContext(DeclContext *DC); 1495 void ActOnObjCReenterContainerContext(DeclContext *DC); 1496 1497 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable 1498 /// error parsing the definition of a tag. 1499 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); 1500 1501 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, 1502 EnumConstantDecl *LastEnumConst, 1503 SourceLocation IdLoc, 1504 IdentifierInfo *Id, 1505 Expr *val); 1506 bool CheckEnumUnderlyingType(TypeSourceInfo *TI); 1507 bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, 1508 QualType EnumUnderlyingTy, const EnumDecl *Prev); 1509 1510 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, 1511 SourceLocation IdLoc, IdentifierInfo *Id, 1512 AttributeList *Attrs, 1513 SourceLocation EqualLoc, Expr *Val); 1514 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, 1515 SourceLocation RBraceLoc, Decl *EnumDecl, 1516 Decl **Elements, unsigned NumElements, 1517 Scope *S, AttributeList *Attr); 1518 1519 DeclContext *getContainingDC(DeclContext *DC); 1520 1521 /// Set the current declaration context until it gets popped. 1522 void PushDeclContext(Scope *S, DeclContext *DC); 1523 void PopDeclContext(); 1524 1525 /// EnterDeclaratorContext - Used when we must lookup names in the context 1526 /// of a declarator's nested name specifier. 1527 void EnterDeclaratorContext(Scope *S, DeclContext *DC); 1528 void ExitDeclaratorContext(Scope *S); 1529 1530 /// Push the parameters of D, which must be a function, into scope. 1531 void ActOnReenterFunctionContext(Scope* S, Decl* D); 1532 void ActOnExitFunctionContext(); 1533 1534 DeclContext *getFunctionLevelDeclContext(); 1535 1536 /// getCurFunctionDecl - If inside of a function body, this returns a pointer 1537 /// to the function decl for the function being parsed. If we're currently 1538 /// in a 'block', this returns the containing context. 1539 FunctionDecl *getCurFunctionDecl(); 1540 1541 /// getCurMethodDecl - If inside of a method body, this returns a pointer to 1542 /// the method decl for the method being parsed. If we're currently 1543 /// in a 'block', this returns the containing context. 1544 ObjCMethodDecl *getCurMethodDecl(); 1545 1546 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method 1547 /// or C function we're in, otherwise return null. If we're currently 1548 /// in a 'block', this returns the containing context. 1549 NamedDecl *getCurFunctionOrMethodDecl(); 1550 1551 /// Add this decl to the scope shadowed decl chains. 1552 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); 1553 1554 /// \brief Make the given externally-produced declaration visible at the 1555 /// top level scope. 1556 /// 1557 /// \param D The externally-produced declaration to push. 1558 /// 1559 /// \param Name The name of the externally-produced declaration. 1560 void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); 1561 1562 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true 1563 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns 1564 /// true if 'D' belongs to the given declaration context. 1565 /// 1566 /// \param ExplicitInstantiationOrSpecialization When true, we are checking 1567 /// whether the declaration is in scope for the purposes of explicit template 1568 /// instantiation or specialization. The default is false. 1569 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0, 1570 bool ExplicitInstantiationOrSpecialization = false); 1571 1572 /// Finds the scope corresponding to the given decl context, if it 1573 /// happens to be an enclosing scope. Otherwise return NULL. 1574 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); 1575 1576 /// Subroutines of ActOnDeclarator(). 1577 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, 1578 TypeSourceInfo *TInfo); 1579 bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); 1580 1581 /// Attribute merging methods. Return true if a new attribute was added. 1582 AvailabilityAttr *mergeAvailabilityAttr(Decl *D, SourceRange Range, 1583 IdentifierInfo *Platform, 1584 VersionTuple Introduced, 1585 VersionTuple Deprecated, 1586 VersionTuple Obsoleted, 1587 bool IsUnavailable, 1588 StringRef Message); 1589 VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range, 1590 VisibilityAttr::VisibilityType Vis); 1591 DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range); 1592 DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range); 1593 FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range, StringRef Format, 1594 int FormatIdx, int FirstArg); 1595 SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name); 1596 bool mergeDeclAttribute(Decl *New, InheritableAttr *Attr); 1597 1598 void mergeDeclAttributes(Decl *New, Decl *Old, bool MergeDeprecation = true); 1599 void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls); 1600 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old, Scope *S); 1601 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, 1602 Scope *S); 1603 void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); 1604 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls); 1605 void MergeVarDeclTypes(VarDecl *New, VarDecl *Old); 1606 void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); 1607 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); 1608 1609 // AssignmentAction - This is used by all the assignment diagnostic functions 1610 // to represent what is actually causing the operation 1611 enum AssignmentAction { 1612 AA_Assigning, 1613 AA_Passing, 1614 AA_Returning, 1615 AA_Converting, 1616 AA_Initializing, 1617 AA_Sending, 1618 AA_Casting 1619 }; 1620 1621 /// C++ Overloading. 1622 enum OverloadKind { 1623 /// This is a legitimate overload: the existing declarations are 1624 /// functions or function templates with different signatures. 1625 Ovl_Overload, 1626 1627 /// This is not an overload because the signature exactly matches 1628 /// an existing declaration. 1629 Ovl_Match, 1630 1631 /// This is not an overload because the lookup results contain a 1632 /// non-function. 1633 Ovl_NonFunction 1634 }; 1635 OverloadKind CheckOverload(Scope *S, 1636 FunctionDecl *New, 1637 const LookupResult &OldDecls, 1638 NamedDecl *&OldDecl, 1639 bool IsForUsingDecl); 1640 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl); 1641 1642 /// \brief Checks availability of the function depending on the current 1643 /// function context.Inside an unavailable function,unavailability is ignored. 1644 /// 1645 /// \returns true if \arg FD is unavailable and current context is inside 1646 /// an available function, false otherwise. 1647 bool isFunctionConsideredUnavailable(FunctionDecl *FD); 1648 1649 ImplicitConversionSequence 1650 TryImplicitConversion(Expr *From, QualType ToType, 1651 bool SuppressUserConversions, 1652 bool AllowExplicit, 1653 bool InOverloadResolution, 1654 bool CStyle, 1655 bool AllowObjCWritebackConversion); 1656 1657 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); 1658 bool IsFloatingPointPromotion(QualType FromType, QualType ToType); 1659 bool IsComplexPromotion(QualType FromType, QualType ToType); 1660 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, 1661 bool InOverloadResolution, 1662 QualType& ConvertedType, bool &IncompatibleObjC); 1663 bool isObjCPointerConversion(QualType FromType, QualType ToType, 1664 QualType& ConvertedType, bool &IncompatibleObjC); 1665 bool isObjCWritebackConversion(QualType FromType, QualType ToType, 1666 QualType &ConvertedType); 1667 bool IsBlockPointerConversion(QualType FromType, QualType ToType, 1668 QualType& ConvertedType); 1669 bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType, 1670 const FunctionProtoType *NewType, 1671 unsigned *ArgPos = 0); 1672 void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, 1673 QualType FromType, QualType ToType); 1674 1675 CastKind PrepareCastToObjCObjectPointer(ExprResult &E); 1676 bool CheckPointerConversion(Expr *From, QualType ToType, 1677 CastKind &Kind, 1678 CXXCastPath& BasePath, 1679 bool IgnoreBaseAccess); 1680 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, 1681 bool InOverloadResolution, 1682 QualType &ConvertedType); 1683 bool CheckMemberPointerConversion(Expr *From, QualType ToType, 1684 CastKind &Kind, 1685 CXXCastPath &BasePath, 1686 bool IgnoreBaseAccess); 1687 bool IsQualificationConversion(QualType FromType, QualType ToType, 1688 bool CStyle, bool &ObjCLifetimeConversion); 1689 bool IsNoReturnConversion(QualType FromType, QualType ToType, 1690 QualType &ResultTy); 1691 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); 1692 1693 1694 ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, 1695 const VarDecl *NRVOCandidate, 1696 QualType ResultType, 1697 Expr *Value, 1698 bool AllowNRVO = true); 1699 1700 bool CanPerformCopyInitialization(const InitializedEntity &Entity, 1701 ExprResult Init); 1702 ExprResult PerformCopyInitialization(const InitializedEntity &Entity, 1703 SourceLocation EqualLoc, 1704 ExprResult Init, 1705 bool TopLevelOfInitList = false, 1706 bool AllowExplicit = false); 1707 ExprResult PerformObjectArgumentInitialization(Expr *From, 1708 NestedNameSpecifier *Qualifier, 1709 NamedDecl *FoundDecl, 1710 CXXMethodDecl *Method); 1711 1712 ExprResult PerformContextuallyConvertToBool(Expr *From); 1713 ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); 1714 1715 /// Contexts in which a converted constant expression is required. 1716 enum CCEKind { 1717 CCEK_CaseValue, ///< Expression in a case label. 1718 CCEK_Enumerator, ///< Enumerator value with fixed underlying type. 1719 CCEK_TemplateArg ///< Value of a non-type template parameter. 1720 }; 1721 ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, 1722 llvm::APSInt &Value, CCEKind CCE); 1723 1724 /// \brief Abstract base class used to diagnose problems that occur while 1725 /// trying to convert an expression to integral or enumeration type. 1726 class ICEConvertDiagnoser { 1727 public: 1728 bool Suppress; 1729 bool SuppressConversion; 1730 1731 ICEConvertDiagnoser(bool Suppress = false, 1732 bool SuppressConversion = false) 1733 : Suppress(Suppress), SuppressConversion(SuppressConversion) { } 1734 1735 /// \brief Emits a diagnostic complaining that the expression does not have 1736 /// integral or enumeration type. 1737 virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, 1738 QualType T) = 0; 1739 1740 /// \brief Emits a diagnostic when the expression has incomplete class type. 1741 virtual DiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, 1742 QualType T) = 0; 1743 1744 /// \brief Emits a diagnostic when the only matching conversion function 1745 /// is explicit. 1746 virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, 1747 QualType T, 1748 QualType ConvTy) = 0; 1749 1750 /// \brief Emits a note for the explicit conversion function. 1751 virtual DiagnosticBuilder 1752 noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; 1753 1754 /// \brief Emits a diagnostic when there are multiple possible conversion 1755 /// functions. 1756 virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, 1757 QualType T) = 0; 1758 1759 /// \brief Emits a note for one of the candidate conversions. 1760 virtual DiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, 1761 QualType ConvTy) = 0; 1762 1763 /// \brief Emits a diagnostic when we picked a conversion function 1764 /// (for cases when we are not allowed to pick a conversion function). 1765 virtual DiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc, 1766 QualType T, 1767 QualType ConvTy) = 0; 1768 1769 virtual ~ICEConvertDiagnoser() {} 1770 }; 1771 1772 ExprResult 1773 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE, 1774 ICEConvertDiagnoser &Diagnoser, 1775 bool AllowScopedEnumerations); 1776 1777 enum ObjCSubscriptKind { 1778 OS_Array, 1779 OS_Dictionary, 1780 OS_Error 1781 }; 1782 ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); 1783 1784 ExprResult PerformObjectMemberConversion(Expr *From, 1785 NestedNameSpecifier *Qualifier, 1786 NamedDecl *FoundDecl, 1787 NamedDecl *Member); 1788 1789 // Members have to be NamespaceDecl* or TranslationUnitDecl*. 1790 // TODO: make this is a typesafe union. 1791 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet; 1792 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; 1793 1794 void AddOverloadCandidate(FunctionDecl *Function, 1795 DeclAccessPair FoundDecl, 1796 llvm::ArrayRef<Expr *> Args, 1797 OverloadCandidateSet& CandidateSet, 1798 bool SuppressUserConversions = false, 1799 bool PartialOverloading = false, 1800 bool AllowExplicit = false); 1801 void AddFunctionCandidates(const UnresolvedSetImpl &Functions, 1802 llvm::ArrayRef<Expr *> Args, 1803 OverloadCandidateSet& CandidateSet, 1804 bool SuppressUserConversions = false, 1805 TemplateArgumentListInfo *ExplicitTemplateArgs = 0); 1806 void AddMethodCandidate(DeclAccessPair FoundDecl, 1807 QualType ObjectType, 1808 Expr::Classification ObjectClassification, 1809 Expr **Args, unsigned NumArgs, 1810 OverloadCandidateSet& CandidateSet, 1811 bool SuppressUserConversion = false); 1812 void AddMethodCandidate(CXXMethodDecl *Method, 1813 DeclAccessPair FoundDecl, 1814 CXXRecordDecl *ActingContext, QualType ObjectType, 1815 Expr::Classification ObjectClassification, 1816 llvm::ArrayRef<Expr *> Args, 1817 OverloadCandidateSet& CandidateSet, 1818 bool SuppressUserConversions = false); 1819 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, 1820 DeclAccessPair FoundDecl, 1821 CXXRecordDecl *ActingContext, 1822 TemplateArgumentListInfo *ExplicitTemplateArgs, 1823 QualType ObjectType, 1824 Expr::Classification ObjectClassification, 1825 llvm::ArrayRef<Expr *> Args, 1826 OverloadCandidateSet& CandidateSet, 1827 bool SuppressUserConversions = false); 1828 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, 1829 DeclAccessPair FoundDecl, 1830 TemplateArgumentListInfo *ExplicitTemplateArgs, 1831 llvm::ArrayRef<Expr *> Args, 1832 OverloadCandidateSet& CandidateSet, 1833 bool SuppressUserConversions = false); 1834 void AddConversionCandidate(CXXConversionDecl *Conversion, 1835 DeclAccessPair FoundDecl, 1836 CXXRecordDecl *ActingContext, 1837 Expr *From, QualType ToType, 1838 OverloadCandidateSet& CandidateSet); 1839 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, 1840 DeclAccessPair FoundDecl, 1841 CXXRecordDecl *ActingContext, 1842 Expr *From, QualType ToType, 1843 OverloadCandidateSet &CandidateSet); 1844 void AddSurrogateCandidate(CXXConversionDecl *Conversion, 1845 DeclAccessPair FoundDecl, 1846 CXXRecordDecl *ActingContext, 1847 const FunctionProtoType *Proto, 1848 Expr *Object, llvm::ArrayRef<Expr*> Args, 1849 OverloadCandidateSet& CandidateSet); 1850 void AddMemberOperatorCandidates(OverloadedOperatorKind Op, 1851 SourceLocation OpLoc, 1852 Expr **Args, unsigned NumArgs, 1853 OverloadCandidateSet& CandidateSet, 1854 SourceRange OpRange = SourceRange()); 1855 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, 1856 Expr **Args, unsigned NumArgs, 1857 OverloadCandidateSet& CandidateSet, 1858 bool IsAssignmentOperator = false, 1859 unsigned NumContextualBoolArguments = 0); 1860 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, 1861 SourceLocation OpLoc, 1862 Expr **Args, unsigned NumArgs, 1863 OverloadCandidateSet& CandidateSet); 1864 void AddArgumentDependentLookupCandidates(DeclarationName Name, 1865 bool Operator, SourceLocation Loc, 1866 llvm::ArrayRef<Expr *> Args, 1867 TemplateArgumentListInfo *ExplicitTemplateArgs, 1868 OverloadCandidateSet& CandidateSet, 1869 bool PartialOverloading = false, 1870 bool StdNamespaceIsAssociated = false); 1871 1872 // Emit as a 'note' the specific overload candidate 1873 void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType()); 1874 1875 // Emit as a series of 'note's all template and non-templates 1876 // identified by the expression Expr 1877 void NoteAllOverloadCandidates(Expr* E, QualType DestType = QualType()); 1878 1879 // [PossiblyAFunctionType] --> [Return] 1880 // NonFunctionType --> NonFunctionType 1881 // R (A) --> R(A) 1882 // R (*)(A) --> R (A) 1883 // R (&)(A) --> R (A) 1884 // R (S::*)(A) --> R (A) 1885 QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); 1886 1887 FunctionDecl * 1888 ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, 1889 QualType TargetType, 1890 bool Complain, 1891 DeclAccessPair &Found, 1892 bool *pHadMultipleCandidates = 0); 1893 1894 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, 1895 bool Complain = false, 1896 DeclAccessPair* Found = 0); 1897 1898 bool ResolveAndFixSingleFunctionTemplateSpecialization( 1899 ExprResult &SrcExpr, 1900 bool DoFunctionPointerConverion = false, 1901 bool Complain = false, 1902 const SourceRange& OpRangeForComplaining = SourceRange(), 1903 QualType DestTypeForComplaining = QualType(), 1904 unsigned DiagIDForComplaining = 0); 1905 1906 1907 Expr *FixOverloadedFunctionReference(Expr *E, 1908 DeclAccessPair FoundDecl, 1909 FunctionDecl *Fn); 1910 ExprResult FixOverloadedFunctionReference(ExprResult, 1911 DeclAccessPair FoundDecl, 1912 FunctionDecl *Fn); 1913 1914 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, 1915 llvm::ArrayRef<Expr *> Args, 1916 OverloadCandidateSet &CandidateSet, 1917 bool PartialOverloading = false); 1918 1919 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, 1920 UnresolvedLookupExpr *ULE, 1921 SourceLocation LParenLoc, 1922 Expr **Args, unsigned NumArgs, 1923 SourceLocation RParenLoc, 1924 Expr *ExecConfig, 1925 bool AllowTypoCorrection=true); 1926 1927 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, 1928 unsigned Opc, 1929 const UnresolvedSetImpl &Fns, 1930 Expr *input); 1931 1932 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, 1933 unsigned Opc, 1934 const UnresolvedSetImpl &Fns, 1935 Expr *LHS, Expr *RHS); 1936 1937 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, 1938 SourceLocation RLoc, 1939 Expr *Base,Expr *Idx); 1940 1941 ExprResult 1942 BuildCallToMemberFunction(Scope *S, Expr *MemExpr, 1943 SourceLocation LParenLoc, Expr **Args, 1944 unsigned NumArgs, SourceLocation RParenLoc); 1945 ExprResult 1946 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, 1947 Expr **Args, unsigned NumArgs, 1948 SourceLocation RParenLoc); 1949 1950 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, 1951 SourceLocation OpLoc); 1952 1953 /// CheckCallReturnType - Checks that a call expression's return type is 1954 /// complete. Returns true on failure. The location passed in is the location 1955 /// that best represents the call. 1956 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, 1957 CallExpr *CE, FunctionDecl *FD); 1958 1959 /// Helpers for dealing with blocks and functions. 1960 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd, 1961 bool CheckParameterNames); 1962 void CheckCXXDefaultArguments(FunctionDecl *FD); 1963 void CheckExtraCXXDefaultArguments(Declarator &D); 1964 Scope *getNonFieldDeclScope(Scope *S); 1965 1966 /// \name Name lookup 1967 /// 1968 /// These routines provide name lookup that is used during semantic 1969 /// analysis to resolve the various kinds of names (identifiers, 1970 /// overloaded operator names, constructor names, etc.) into zero or 1971 /// more declarations within a particular scope. The major entry 1972 /// points are LookupName, which performs unqualified name lookup, 1973 /// and LookupQualifiedName, which performs qualified name lookup. 1974 /// 1975 /// All name lookup is performed based on some specific criteria, 1976 /// which specify what names will be visible to name lookup and how 1977 /// far name lookup should work. These criteria are important both 1978 /// for capturing language semantics (certain lookups will ignore 1979 /// certain names, for example) and for performance, since name 1980 /// lookup is often a bottleneck in the compilation of C++. Name 1981 /// lookup criteria is specified via the LookupCriteria enumeration. 1982 /// 1983 /// The results of name lookup can vary based on the kind of name 1984 /// lookup performed, the current language, and the translation 1985 /// unit. In C, for example, name lookup will either return nothing 1986 /// (no entity found) or a single declaration. In C++, name lookup 1987 /// can additionally refer to a set of overloaded functions or 1988 /// result in an ambiguity. All of the possible results of name 1989 /// lookup are captured by the LookupResult class, which provides 1990 /// the ability to distinguish among them. 1991 //@{ 1992 1993 /// @brief Describes the kind of name lookup to perform. 1994 enum LookupNameKind { 1995 /// Ordinary name lookup, which finds ordinary names (functions, 1996 /// variables, typedefs, etc.) in C and most kinds of names 1997 /// (functions, variables, members, types, etc.) in C++. 1998 LookupOrdinaryName = 0, 1999 /// Tag name lookup, which finds the names of enums, classes, 2000 /// structs, and unions. 2001 LookupTagName, 2002 /// Label name lookup. 2003 LookupLabel, 2004 /// Member name lookup, which finds the names of 2005 /// class/struct/union members. 2006 LookupMemberName, 2007 /// Look up of an operator name (e.g., operator+) for use with 2008 /// operator overloading. This lookup is similar to ordinary name 2009 /// lookup, but will ignore any declarations that are class members. 2010 LookupOperatorName, 2011 /// Look up of a name that precedes the '::' scope resolution 2012 /// operator in C++. This lookup completely ignores operator, object, 2013 /// function, and enumerator names (C++ [basic.lookup.qual]p1). 2014 LookupNestedNameSpecifierName, 2015 /// Look up a namespace name within a C++ using directive or 2016 /// namespace alias definition, ignoring non-namespace names (C++ 2017 /// [basic.lookup.udir]p1). 2018 LookupNamespaceName, 2019 /// Look up all declarations in a scope with the given name, 2020 /// including resolved using declarations. This is appropriate 2021 /// for checking redeclarations for a using declaration. 2022 LookupUsingDeclName, 2023 /// Look up an ordinary name that is going to be redeclared as a 2024 /// name with linkage. This lookup ignores any declarations that 2025 /// are outside of the current scope unless they have linkage. See 2026 /// C99 6.2.2p4-5 and C++ [basic.link]p6. 2027 LookupRedeclarationWithLinkage, 2028 /// Look up the name of an Objective-C protocol. 2029 LookupObjCProtocolName, 2030 /// Look up implicit 'self' parameter of an objective-c method. 2031 LookupObjCImplicitSelfParam, 2032 /// \brief Look up any declaration with any name. 2033 LookupAnyName 2034 }; 2035 2036 /// \brief Specifies whether (or how) name lookup is being performed for a 2037 /// redeclaration (vs. a reference). 2038 enum RedeclarationKind { 2039 /// \brief The lookup is a reference to this name that is not for the 2040 /// purpose of redeclaring the name. 2041 NotForRedeclaration = 0, 2042 /// \brief The lookup results will be used for redeclaration of a name, 2043 /// if an entity by that name already exists. 2044 ForRedeclaration 2045 }; 2046 2047 /// \brief The possible outcomes of name lookup for a literal operator. 2048 enum LiteralOperatorLookupResult { 2049 /// \brief The lookup resulted in an error. 2050 LOLR_Error, 2051 /// \brief The lookup found a single 'cooked' literal operator, which 2052 /// expects a normal literal to be built and passed to it. 2053 LOLR_Cooked, 2054 /// \brief The lookup found a single 'raw' literal operator, which expects 2055 /// a string literal containing the spelling of the literal token. 2056 LOLR_Raw, 2057 /// \brief The lookup found an overload set of literal operator templates, 2058 /// which expect the characters of the spelling of the literal token to be 2059 /// passed as a non-type template argument pack. 2060 LOLR_Template 2061 }; 2062 2063 SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D, 2064 CXXSpecialMember SM, 2065 bool ConstArg, 2066 bool VolatileArg, 2067 bool RValueThis, 2068 bool ConstThis, 2069 bool VolatileThis); 2070 2071private: 2072 bool CppLookupName(LookupResult &R, Scope *S); 2073 2074 // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls. 2075 // 2076 // The boolean value will be true to indicate that the namespace was loaded 2077 // from an AST/PCH file, or false otherwise. 2078 llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces; 2079 2080 /// \brief Whether we have already loaded known namespaces from an extenal 2081 /// source. 2082 bool LoadedExternalKnownNamespaces; 2083 2084public: 2085 /// \brief Look up a name, looking for a single declaration. Return 2086 /// null if the results were absent, ambiguous, or overloaded. 2087 /// 2088 /// It is preferable to use the elaborated form and explicitly handle 2089 /// ambiguity and overloaded. 2090 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, 2091 SourceLocation Loc, 2092 LookupNameKind NameKind, 2093 RedeclarationKind Redecl 2094 = NotForRedeclaration); 2095 bool LookupName(LookupResult &R, Scope *S, 2096 bool AllowBuiltinCreation = false); 2097 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, 2098 bool InUnqualifiedLookup = false); 2099 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, 2100 bool AllowBuiltinCreation = false, 2101 bool EnteringContext = false); 2102 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, 2103 RedeclarationKind Redecl 2104 = NotForRedeclaration); 2105 2106 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, 2107 QualType T1, QualType T2, 2108 UnresolvedSetImpl &Functions); 2109 2110 LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, 2111 SourceLocation GnuLabelLoc = SourceLocation()); 2112 2113 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); 2114 CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); 2115 CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, 2116 unsigned Quals); 2117 CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, 2118 bool RValueThis, unsigned ThisQuals); 2119 CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class); 2120 CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, bool RValueThis, 2121 unsigned ThisQuals); 2122 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); 2123 2124 LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, 2125 ArrayRef<QualType> ArgTys, 2126 bool AllowRawAndTemplate); 2127 bool isKnownName(StringRef name); 2128 2129 void ArgumentDependentLookup(DeclarationName Name, bool Operator, 2130 SourceLocation Loc, 2131 llvm::ArrayRef<Expr *> Args, 2132 ADLResult &Functions, 2133 bool StdNamespaceIsAssociated = false); 2134 2135 void LookupVisibleDecls(Scope *S, LookupNameKind Kind, 2136 VisibleDeclConsumer &Consumer, 2137 bool IncludeGlobalScope = true); 2138 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, 2139 VisibleDeclConsumer &Consumer, 2140 bool IncludeGlobalScope = true); 2141 2142 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 2143 Sema::LookupNameKind LookupKind, 2144 Scope *S, CXXScopeSpec *SS, 2145 CorrectionCandidateCallback &CCC, 2146 DeclContext *MemberContext = 0, 2147 bool EnteringContext = false, 2148 const ObjCObjectPointerType *OPT = 0); 2149 2150 void FindAssociatedClassesAndNamespaces(llvm::ArrayRef<Expr *> Args, 2151 AssociatedNamespaceSet &AssociatedNamespaces, 2152 AssociatedClassSet &AssociatedClasses); 2153 2154 void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, 2155 bool ConsiderLinkage, 2156 bool ExplicitInstantiationOrSpecialization); 2157 2158 bool DiagnoseAmbiguousLookup(LookupResult &Result); 2159 //@} 2160 2161 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, 2162 SourceLocation IdLoc, 2163 bool TypoCorrection = false); 2164 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, 2165 Scope *S, bool ForRedeclaration, 2166 SourceLocation Loc); 2167 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, 2168 Scope *S); 2169 void AddKnownFunctionAttributes(FunctionDecl *FD); 2170 2171 // More parsing and symbol table subroutines. 2172 2173 // Decl attributes - this routine is the top level dispatcher. 2174 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD, 2175 bool NonInheritable = true, bool Inheritable = true); 2176 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, 2177 bool NonInheritable = true, bool Inheritable = true); 2178 bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, 2179 const AttributeList *AttrList); 2180 2181 void checkUnusedDeclAttributes(Declarator &D); 2182 2183 bool CheckRegparmAttr(const AttributeList &attr, unsigned &value); 2184 bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC); 2185 bool CheckNoReturnAttr(const AttributeList &attr); 2186 2187 /// \brief Stmt attributes - this routine is the top level dispatcher. 2188 StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs, 2189 SourceRange Range); 2190 2191 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, 2192 bool &IncompleteImpl, unsigned DiagID); 2193 void WarnConflictingTypedMethods(ObjCMethodDecl *Method, 2194 ObjCMethodDecl *MethodDecl, 2195 bool IsProtocolMethodDecl); 2196 2197 void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, 2198 ObjCMethodDecl *Overridden, 2199 bool IsProtocolMethodDecl); 2200 2201 /// WarnExactTypedMethods - This routine issues a warning if method 2202 /// implementation declaration matches exactly that of its declaration. 2203 void WarnExactTypedMethods(ObjCMethodDecl *Method, 2204 ObjCMethodDecl *MethodDecl, 2205 bool IsProtocolMethodDecl); 2206 2207 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, 2208 ObjCInterfaceDecl *IDecl); 2209 2210 typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; 2211 typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap; 2212 2213 /// CheckProtocolMethodDefs - This routine checks unimplemented 2214 /// methods declared in protocol, and those referenced by it. 2215 void CheckProtocolMethodDefs(SourceLocation ImpLoc, 2216 ObjCProtocolDecl *PDecl, 2217 bool& IncompleteImpl, 2218 const SelectorSet &InsMap, 2219 const SelectorSet &ClsMap, 2220 ObjCContainerDecl *CDecl); 2221 2222 /// CheckImplementationIvars - This routine checks if the instance variables 2223 /// listed in the implelementation match those listed in the interface. 2224 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, 2225 ObjCIvarDecl **Fields, unsigned nIvars, 2226 SourceLocation Loc); 2227 2228 /// ImplMethodsVsClassMethods - This is main routine to warn if any method 2229 /// remains unimplemented in the class or category \@implementation. 2230 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, 2231 ObjCContainerDecl* IDecl, 2232 bool IncompleteImpl = false); 2233 2234 /// DiagnoseUnimplementedProperties - This routine warns on those properties 2235 /// which must be implemented by this implementation. 2236 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, 2237 ObjCContainerDecl *CDecl, 2238 const SelectorSet &InsMap); 2239 2240 /// DefaultSynthesizeProperties - This routine default synthesizes all 2241 /// properties which must be synthesized in the class's \@implementation. 2242 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, 2243 ObjCInterfaceDecl *IDecl); 2244 void DefaultSynthesizeProperties(Scope *S, Decl *D); 2245 2246 /// CollectImmediateProperties - This routine collects all properties in 2247 /// the class and its conforming protocols; but not those it its super class. 2248 void CollectImmediateProperties(ObjCContainerDecl *CDecl, 2249 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap, 2250 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap); 2251 2252 2253 /// LookupPropertyDecl - Looks up a property in the current class and all 2254 /// its protocols. 2255 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl, 2256 IdentifierInfo *II); 2257 2258 /// Called by ActOnProperty to handle \@property declarations in 2259 /// class extensions. 2260 Decl *HandlePropertyInClassExtension(Scope *S, 2261 SourceLocation AtLoc, 2262 SourceLocation LParenLoc, 2263 FieldDeclarator &FD, 2264 Selector GetterSel, 2265 Selector SetterSel, 2266 const bool isAssign, 2267 const bool isReadWrite, 2268 const unsigned Attributes, 2269 const unsigned AttributesAsWritten, 2270 bool *isOverridingProperty, 2271 TypeSourceInfo *T, 2272 tok::ObjCKeywordKind MethodImplKind); 2273 2274 /// Called by ActOnProperty and HandlePropertyInClassExtension to 2275 /// handle creating the ObjcPropertyDecl for a category or \@interface. 2276 ObjCPropertyDecl *CreatePropertyDecl(Scope *S, 2277 ObjCContainerDecl *CDecl, 2278 SourceLocation AtLoc, 2279 SourceLocation LParenLoc, 2280 FieldDeclarator &FD, 2281 Selector GetterSel, 2282 Selector SetterSel, 2283 const bool isAssign, 2284 const bool isReadWrite, 2285 const unsigned Attributes, 2286 const unsigned AttributesAsWritten, 2287 TypeSourceInfo *T, 2288 tok::ObjCKeywordKind MethodImplKind, 2289 DeclContext *lexicalDC = 0); 2290 2291 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via 2292 /// warning) when atomic property has one but not the other user-declared 2293 /// setter or getter. 2294 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, 2295 ObjCContainerDecl* IDecl); 2296 2297 void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); 2298 2299 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); 2300 2301 enum MethodMatchStrategy { 2302 MMS_loose, 2303 MMS_strict 2304 }; 2305 2306 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns 2307 /// true, or false, accordingly. 2308 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, 2309 const ObjCMethodDecl *PrevMethod, 2310 MethodMatchStrategy strategy = MMS_strict); 2311 2312 /// MatchAllMethodDeclarations - Check methods declaraed in interface or 2313 /// or protocol against those declared in their implementations. 2314 void MatchAllMethodDeclarations(const SelectorSet &InsMap, 2315 const SelectorSet &ClsMap, 2316 SelectorSet &InsMapSeen, 2317 SelectorSet &ClsMapSeen, 2318 ObjCImplDecl* IMPDecl, 2319 ObjCContainerDecl* IDecl, 2320 bool &IncompleteImpl, 2321 bool ImmediateClass, 2322 bool WarnCategoryMethodImpl=false); 2323 2324 /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in 2325 /// category matches with those implemented in its primary class and 2326 /// warns each time an exact match is found. 2327 void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); 2328 2329 /// \brief Add the given method to the list of globally-known methods. 2330 void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); 2331 2332private: 2333 /// AddMethodToGlobalPool - Add an instance or factory method to the global 2334 /// pool. See descriptoin of AddInstanceMethodToGlobalPool. 2335 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); 2336 2337 /// LookupMethodInGlobalPool - Returns the instance or factory method and 2338 /// optionally warns if there are multiple signatures. 2339 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, 2340 bool receiverIdOrClass, 2341 bool warn, bool instance); 2342 2343public: 2344 /// AddInstanceMethodToGlobalPool - All instance methods in a translation 2345 /// unit are added to a global pool. This allows us to efficiently associate 2346 /// a selector with a method declaraation for purposes of typechecking 2347 /// messages sent to "id" (where the class of the object is unknown). 2348 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 2349 AddMethodToGlobalPool(Method, impl, /*instance*/true); 2350 } 2351 2352 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. 2353 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 2354 AddMethodToGlobalPool(Method, impl, /*instance*/false); 2355 } 2356 2357 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global 2358 /// pool. 2359 void AddAnyMethodToGlobalPool(Decl *D); 2360 2361 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if 2362 /// there are multiple signatures. 2363 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, 2364 bool receiverIdOrClass=false, 2365 bool warn=true) { 2366 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 2367 warn, /*instance*/true); 2368 } 2369 2370 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if 2371 /// there are multiple signatures. 2372 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, 2373 bool receiverIdOrClass=false, 2374 bool warn=true) { 2375 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 2376 warn, /*instance*/false); 2377 } 2378 2379 /// LookupImplementedMethodInGlobalPool - Returns the method which has an 2380 /// implementation. 2381 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); 2382 2383 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require 2384 /// initialization. 2385 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, 2386 SmallVectorImpl<ObjCIvarDecl*> &Ivars); 2387 2388 //===--------------------------------------------------------------------===// 2389 // Statement Parsing Callbacks: SemaStmt.cpp. 2390public: 2391 class FullExprArg { 2392 public: 2393 FullExprArg(Sema &actions) : E(0) { } 2394 2395 // FIXME: The const_cast here is ugly. RValue references would make this 2396 // much nicer (or we could duplicate a bunch of the move semantics 2397 // emulation code from Ownership.h). 2398 FullExprArg(const FullExprArg& Other) : E(Other.E) {} 2399 2400 ExprResult release() { 2401 return move(E); 2402 } 2403 2404 Expr *get() const { return E; } 2405 2406 Expr *operator->() { 2407 return E; 2408 } 2409 2410 private: 2411 // FIXME: No need to make the entire Sema class a friend when it's just 2412 // Sema::MakeFullExpr that needs access to the constructor below. 2413 friend class Sema; 2414 2415 explicit FullExprArg(Expr *expr) : E(expr) {} 2416 2417 Expr *E; 2418 }; 2419 2420 FullExprArg MakeFullExpr(Expr *Arg) { 2421 return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); 2422 } 2423 FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { 2424 return FullExprArg(ActOnFinishFullExpr(Arg, CC).release()); 2425 } 2426 2427 StmtResult ActOnExprStmt(FullExprArg Expr); 2428 2429 StmtResult ActOnNullStmt(SourceLocation SemiLoc, 2430 bool HasLeadingEmptyMacro = false); 2431 2432 void ActOnStartOfCompoundStmt(); 2433 void ActOnFinishOfCompoundStmt(); 2434 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, 2435 MultiStmtArg Elts, 2436 bool isStmtExpr); 2437 2438 /// \brief A RAII object to enter scope of a compound statement. 2439 class CompoundScopeRAII { 2440 public: 2441 CompoundScopeRAII(Sema &S): S(S) { 2442 S.ActOnStartOfCompoundStmt(); 2443 } 2444 2445 ~CompoundScopeRAII() { 2446 S.ActOnFinishOfCompoundStmt(); 2447 } 2448 2449 private: 2450 Sema &S; 2451 }; 2452 2453 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, 2454 SourceLocation StartLoc, 2455 SourceLocation EndLoc); 2456 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); 2457 StmtResult ActOnForEachLValueExpr(Expr *E); 2458 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, 2459 SourceLocation DotDotDotLoc, Expr *RHSVal, 2460 SourceLocation ColonLoc); 2461 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); 2462 2463 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, 2464 SourceLocation ColonLoc, 2465 Stmt *SubStmt, Scope *CurScope); 2466 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, 2467 SourceLocation ColonLoc, Stmt *SubStmt); 2468 2469 StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs, 2470 Stmt *SubStmt); 2471 2472 StmtResult ActOnIfStmt(SourceLocation IfLoc, 2473 FullExprArg CondVal, Decl *CondVar, 2474 Stmt *ThenVal, 2475 SourceLocation ElseLoc, Stmt *ElseVal); 2476 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, 2477 Expr *Cond, 2478 Decl *CondVar); 2479 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 2480 Stmt *Switch, Stmt *Body); 2481 StmtResult ActOnWhileStmt(SourceLocation WhileLoc, 2482 FullExprArg Cond, 2483 Decl *CondVar, Stmt *Body); 2484 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, 2485 SourceLocation WhileLoc, 2486 SourceLocation CondLParen, Expr *Cond, 2487 SourceLocation CondRParen); 2488 2489 StmtResult ActOnForStmt(SourceLocation ForLoc, 2490 SourceLocation LParenLoc, 2491 Stmt *First, FullExprArg Second, 2492 Decl *SecondVar, 2493 FullExprArg Third, 2494 SourceLocation RParenLoc, 2495 Stmt *Body); 2496 ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, 2497 Expr *collection); 2498 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 2499 SourceLocation LParenLoc, 2500 Stmt *First, Expr *collection, 2501 SourceLocation RParenLoc); 2502 StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); 2503 2504 StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, 2505 SourceLocation LParenLoc, Stmt *LoopVar, 2506 SourceLocation ColonLoc, Expr *Collection, 2507 SourceLocation RParenLoc); 2508 StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, 2509 SourceLocation ColonLoc, 2510 Stmt *RangeDecl, Stmt *BeginEndDecl, 2511 Expr *Cond, Expr *Inc, 2512 Stmt *LoopVarDecl, 2513 SourceLocation RParenLoc); 2514 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); 2515 2516 StmtResult ActOnGotoStmt(SourceLocation GotoLoc, 2517 SourceLocation LabelLoc, 2518 LabelDecl *TheDecl); 2519 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, 2520 SourceLocation StarLoc, 2521 Expr *DestExp); 2522 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); 2523 StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope); 2524 2525 const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E, 2526 bool AllowFunctionParameters); 2527 2528 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2529 StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2530 2531 StmtResult ActOnAsmStmt(SourceLocation AsmLoc, 2532 bool IsSimple, bool IsVolatile, 2533 unsigned NumOutputs, unsigned NumInputs, 2534 IdentifierInfo **Names, 2535 MultiExprArg Constraints, 2536 MultiExprArg Exprs, 2537 Expr *AsmString, 2538 MultiExprArg Clobbers, 2539 SourceLocation RParenLoc, 2540 bool MSAsm = false); 2541 2542 StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, 2543 std::string &AsmString, 2544 SourceLocation EndLoc); 2545 2546 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, 2547 SourceLocation StartLoc, 2548 SourceLocation IdLoc, IdentifierInfo *Id, 2549 bool Invalid = false); 2550 2551 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); 2552 2553 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, 2554 Decl *Parm, Stmt *Body); 2555 2556 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); 2557 2558 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, 2559 MultiStmtArg Catch, Stmt *Finally); 2560 2561 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); 2562 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, 2563 Scope *CurScope); 2564 ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, 2565 Expr *operand); 2566 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, 2567 Expr *SynchExpr, 2568 Stmt *SynchBody); 2569 2570 StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); 2571 2572 VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, 2573 SourceLocation StartLoc, 2574 SourceLocation IdLoc, 2575 IdentifierInfo *Id); 2576 2577 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); 2578 2579 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, 2580 Decl *ExDecl, Stmt *HandlerBlock); 2581 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, 2582 MultiStmtArg Handlers); 2583 2584 StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? 2585 SourceLocation TryLoc, 2586 Stmt *TryBlock, 2587 Stmt *Handler); 2588 2589 StmtResult ActOnSEHExceptBlock(SourceLocation Loc, 2590 Expr *FilterExpr, 2591 Stmt *Block); 2592 2593 StmtResult ActOnSEHFinallyBlock(SourceLocation Loc, 2594 Stmt *Block); 2595 2596 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); 2597 2598 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; 2599 2600 /// \brief If it's a file scoped decl that must warn if not used, keep track 2601 /// of it. 2602 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); 2603 2604 /// DiagnoseUnusedExprResult - If the statement passed in is an expression 2605 /// whose result is unused, warn. 2606 void DiagnoseUnusedExprResult(const Stmt *S); 2607 void DiagnoseUnusedDecl(const NamedDecl *ND); 2608 2609 /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null 2610 /// statement as a \p Body, and it is located on the same line. 2611 /// 2612 /// This helps prevent bugs due to typos, such as: 2613 /// if (condition); 2614 /// do_stuff(); 2615 void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, 2616 const Stmt *Body, 2617 unsigned DiagID); 2618 2619 /// Warn if a for/while loop statement \p S, which is followed by 2620 /// \p PossibleBody, has a suspicious null statement as a body. 2621 void DiagnoseEmptyLoopBody(const Stmt *S, 2622 const Stmt *PossibleBody); 2623 2624 ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { 2625 return DelayedDiagnostics.push(pool); 2626 } 2627 void PopParsingDeclaration(ParsingDeclState state, Decl *decl); 2628 2629 typedef ProcessingContextState ParsingClassState; 2630 ParsingClassState PushParsingClass() { 2631 return DelayedDiagnostics.pushUndelayed(); 2632 } 2633 void PopParsingClass(ParsingClassState state) { 2634 DelayedDiagnostics.popUndelayed(state); 2635 } 2636 2637 void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); 2638 2639 void EmitDeprecationWarning(NamedDecl *D, StringRef Message, 2640 SourceLocation Loc, 2641 const ObjCInterfaceDecl *UnknownObjCClass=0); 2642 2643 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 2644 2645 bool makeUnavailableInSystemHeader(SourceLocation loc, 2646 StringRef message); 2647 2648 //===--------------------------------------------------------------------===// 2649 // Expression Parsing Callbacks: SemaExpr.cpp. 2650 2651 bool CanUseDecl(NamedDecl *D); 2652 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, 2653 const ObjCInterfaceDecl *UnknownObjCClass=0); 2654 void NoteDeletedFunction(FunctionDecl *FD); 2655 std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); 2656 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 2657 ObjCMethodDecl *Getter, 2658 SourceLocation Loc); 2659 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, 2660 Expr **Args, unsigned NumArgs); 2661 2662 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, 2663 Decl *LambdaContextDecl = 0, 2664 bool IsDecltype = false); 2665 2666 void PopExpressionEvaluationContext(); 2667 2668 void DiscardCleanupsInEvaluationContext(); 2669 2670 ExprResult TranformToPotentiallyEvaluated(Expr *E); 2671 ExprResult HandleExprEvaluationContextForTypeof(Expr *E); 2672 2673 ExprResult ActOnConstantExpression(ExprResult Res); 2674 2675 // Functions for marking a declaration referenced. These functions also 2676 // contain the relevant logic for marking if a reference to a function or 2677 // variable is an odr-use (in the C++11 sense). There are separate variants 2678 // for expressions referring to a decl; these exist because odr-use marking 2679 // needs to be delayed for some constant variables when we build one of the 2680 // named expressions. 2681 void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D); 2682 void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func); 2683 void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); 2684 void MarkDeclRefReferenced(DeclRefExpr *E); 2685 void MarkMemberReferenced(MemberExpr *E); 2686 2687 void UpdateMarkingForLValueToRValue(Expr *E); 2688 void CleanupVarDeclMarking(); 2689 2690 enum TryCaptureKind { 2691 TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef 2692 }; 2693 2694 /// \brief Try to capture the given variable. 2695 /// 2696 /// \param Var The variable to capture. 2697 /// 2698 /// \param Loc The location at which the capture occurs. 2699 /// 2700 /// \param Kind The kind of capture, which may be implicit (for either a 2701 /// block or a lambda), or explicit by-value or by-reference (for a lambda). 2702 /// 2703 /// \param EllipsisLoc The location of the ellipsis, if one is provided in 2704 /// an explicit lambda capture. 2705 /// 2706 /// \param BuildAndDiagnose Whether we are actually supposed to add the 2707 /// captures or diagnose errors. If false, this routine merely check whether 2708 /// the capture can occur without performing the capture itself or complaining 2709 /// if the variable cannot be captured. 2710 /// 2711 /// \param CaptureType Will be set to the type of the field used to capture 2712 /// this variable in the innermost block or lambda. Only valid when the 2713 /// variable can be captured. 2714 /// 2715 /// \param DeclRefType Will be set to the type of a reference to the capture 2716 /// from within the current scope. Only valid when the variable can be 2717 /// captured. 2718 /// 2719 /// \returns true if an error occurred (i.e., the variable cannot be 2720 /// captured) and false if the capture succeeded. 2721 bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, 2722 SourceLocation EllipsisLoc, bool BuildAndDiagnose, 2723 QualType &CaptureType, 2724 QualType &DeclRefType); 2725 2726 /// \brief Try to capture the given variable. 2727 bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, 2728 TryCaptureKind Kind = TryCapture_Implicit, 2729 SourceLocation EllipsisLoc = SourceLocation()); 2730 2731 /// \brief Given a variable, determine the type that a reference to that 2732 /// variable will have in the given scope. 2733 QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc); 2734 2735 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); 2736 void MarkDeclarationsReferencedInExpr(Expr *E, 2737 bool SkipLocalVariables = false); 2738 2739 /// \brief Try to recover by turning the given expression into a 2740 /// call. Returns true if recovery was attempted or an error was 2741 /// emitted; this may also leave the ExprResult invalid. 2742 bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, 2743 bool ForceComplain = false, 2744 bool (*IsPlausibleResult)(QualType) = 0); 2745 2746 /// \brief Figure out if an expression could be turned into a call. 2747 bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy, 2748 UnresolvedSetImpl &NonTemplateOverloads); 2749 2750 /// \brief Conditionally issue a diagnostic based on the current 2751 /// evaluation context. 2752 /// 2753 /// \param Statement If Statement is non-null, delay reporting the 2754 /// diagnostic until the function body is parsed, and then do a basic 2755 /// reachability analysis to determine if the statement is reachable. 2756 /// If it is unreachable, the diagnostic will not be emitted. 2757 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, 2758 const PartialDiagnostic &PD); 2759 2760 // Primary Expressions. 2761 SourceRange getExprRange(Expr *E) const; 2762 2763 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, 2764 SourceLocation TemplateKWLoc, 2765 UnqualifiedId &Id, 2766 bool HasTrailingLParen, bool IsAddressOfOperand, 2767 CorrectionCandidateCallback *CCC = 0); 2768 2769 void DecomposeUnqualifiedId(const UnqualifiedId &Id, 2770 TemplateArgumentListInfo &Buffer, 2771 DeclarationNameInfo &NameInfo, 2772 const TemplateArgumentListInfo *&TemplateArgs); 2773 2774 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, 2775 CorrectionCandidateCallback &CCC, 2776 TemplateArgumentListInfo *ExplicitTemplateArgs = 0, 2777 llvm::ArrayRef<Expr *> Args = llvm::ArrayRef<Expr *>()); 2778 2779 ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, 2780 IdentifierInfo *II, 2781 bool AllowBuiltinCreation=false); 2782 2783 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, 2784 SourceLocation TemplateKWLoc, 2785 const DeclarationNameInfo &NameInfo, 2786 bool isAddressOfOperand, 2787 const TemplateArgumentListInfo *TemplateArgs); 2788 2789 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2790 ExprValueKind VK, 2791 SourceLocation Loc, 2792 const CXXScopeSpec *SS = 0); 2793 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2794 ExprValueKind VK, 2795 const DeclarationNameInfo &NameInfo, 2796 const CXXScopeSpec *SS = 0); 2797 ExprResult 2798 BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, 2799 SourceLocation nameLoc, 2800 IndirectFieldDecl *indirectField, 2801 Expr *baseObjectExpr = 0, 2802 SourceLocation opLoc = SourceLocation()); 2803 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, 2804 SourceLocation TemplateKWLoc, 2805 LookupResult &R, 2806 const TemplateArgumentListInfo *TemplateArgs); 2807 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, 2808 SourceLocation TemplateKWLoc, 2809 LookupResult &R, 2810 const TemplateArgumentListInfo *TemplateArgs, 2811 bool IsDefiniteInstance); 2812 bool UseArgumentDependentLookup(const CXXScopeSpec &SS, 2813 const LookupResult &R, 2814 bool HasTrailingLParen); 2815 2816 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, 2817 const DeclarationNameInfo &NameInfo); 2818 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, 2819 SourceLocation TemplateKWLoc, 2820 const DeclarationNameInfo &NameInfo, 2821 const TemplateArgumentListInfo *TemplateArgs); 2822 2823 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2824 LookupResult &R, 2825 bool NeedsADL); 2826 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2827 const DeclarationNameInfo &NameInfo, 2828 NamedDecl *D); 2829 2830 ExprResult BuildLiteralOperatorCall(LookupResult &R, 2831 DeclarationNameInfo &SuffixInfo, 2832 ArrayRef<Expr*> Args, 2833 SourceLocation LitEndLoc, 2834 TemplateArgumentListInfo *ExplicitTemplateArgs = 0); 2835 2836 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); 2837 ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); 2838 ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = 0); 2839 ExprResult ActOnCharacterConstant(const Token &Tok, Scope *UDLScope = 0); 2840 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); 2841 ExprResult ActOnParenListExpr(SourceLocation L, 2842 SourceLocation R, 2843 MultiExprArg Val); 2844 2845 /// ActOnStringLiteral - The specified tokens were lexed as pasted string 2846 /// fragments (e.g. "foo" "bar" L"baz"). 2847 ExprResult ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks, 2848 Scope *UDLScope = 0); 2849 2850 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, 2851 SourceLocation DefaultLoc, 2852 SourceLocation RParenLoc, 2853 Expr *ControllingExpr, 2854 MultiTypeArg ArgTypes, 2855 MultiExprArg ArgExprs); 2856 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, 2857 SourceLocation DefaultLoc, 2858 SourceLocation RParenLoc, 2859 Expr *ControllingExpr, 2860 TypeSourceInfo **Types, 2861 Expr **Exprs, 2862 unsigned NumAssocs); 2863 2864 // Binary/Unary Operators. 'Tok' is the token for the operator. 2865 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, 2866 Expr *InputExpr); 2867 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, 2868 UnaryOperatorKind Opc, Expr *Input); 2869 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, 2870 tok::TokenKind Op, Expr *Input); 2871 2872 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, 2873 SourceLocation OpLoc, 2874 UnaryExprOrTypeTrait ExprKind, 2875 SourceRange R); 2876 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, 2877 UnaryExprOrTypeTrait ExprKind); 2878 ExprResult 2879 ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, 2880 UnaryExprOrTypeTrait ExprKind, 2881 bool IsType, void *TyOrEx, 2882 const SourceRange &ArgRange); 2883 2884 ExprResult CheckPlaceholderExpr(Expr *E); 2885 bool CheckVecStepExpr(Expr *E); 2886 2887 bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); 2888 bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, 2889 SourceRange ExprRange, 2890 UnaryExprOrTypeTrait ExprKind); 2891 ExprResult ActOnSizeofParameterPackExpr(Scope *S, 2892 SourceLocation OpLoc, 2893 IdentifierInfo &Name, 2894 SourceLocation NameLoc, 2895 SourceLocation RParenLoc); 2896 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, 2897 tok::TokenKind Kind, Expr *Input); 2898 2899 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, 2900 Expr *Idx, SourceLocation RLoc); 2901 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, 2902 Expr *Idx, SourceLocation RLoc); 2903 2904 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2905 SourceLocation OpLoc, bool IsArrow, 2906 CXXScopeSpec &SS, 2907 SourceLocation TemplateKWLoc, 2908 NamedDecl *FirstQualifierInScope, 2909 const DeclarationNameInfo &NameInfo, 2910 const TemplateArgumentListInfo *TemplateArgs); 2911 2912 // This struct is for use by ActOnMemberAccess to allow 2913 // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after 2914 // changing the access operator from a '.' to a '->' (to see if that is the 2915 // change needed to fix an error about an unknown member, e.g. when the class 2916 // defines a custom operator->). 2917 struct ActOnMemberAccessExtraArgs { 2918 Scope *S; 2919 UnqualifiedId &Id; 2920 Decl *ObjCImpDecl; 2921 bool HasTrailingLParen; 2922 }; 2923 2924 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2925 SourceLocation OpLoc, bool IsArrow, 2926 const CXXScopeSpec &SS, 2927 SourceLocation TemplateKWLoc, 2928 NamedDecl *FirstQualifierInScope, 2929 LookupResult &R, 2930 const TemplateArgumentListInfo *TemplateArgs, 2931 bool SuppressQualifierCheck = false, 2932 ActOnMemberAccessExtraArgs *ExtraArgs = 0); 2933 2934 ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); 2935 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base, 2936 bool &IsArrow, SourceLocation OpLoc, 2937 CXXScopeSpec &SS, 2938 Decl *ObjCImpDecl, 2939 bool HasTemplateArgs); 2940 2941 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, 2942 const CXXScopeSpec &SS, 2943 const LookupResult &R); 2944 2945 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, 2946 bool IsArrow, SourceLocation OpLoc, 2947 const CXXScopeSpec &SS, 2948 SourceLocation TemplateKWLoc, 2949 NamedDecl *FirstQualifierInScope, 2950 const DeclarationNameInfo &NameInfo, 2951 const TemplateArgumentListInfo *TemplateArgs); 2952 2953 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, 2954 SourceLocation OpLoc, 2955 tok::TokenKind OpKind, 2956 CXXScopeSpec &SS, 2957 SourceLocation TemplateKWLoc, 2958 UnqualifiedId &Member, 2959 Decl *ObjCImpDecl, 2960 bool HasTrailingLParen); 2961 2962 void ActOnDefaultCtorInitializers(Decl *CDtorDecl); 2963 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, 2964 FunctionDecl *FDecl, 2965 const FunctionProtoType *Proto, 2966 Expr **Args, unsigned NumArgs, 2967 SourceLocation RParenLoc, 2968 bool ExecConfig = false); 2969 void CheckStaticArrayArgument(SourceLocation CallLoc, 2970 ParmVarDecl *Param, 2971 const Expr *ArgExpr); 2972 2973 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. 2974 /// This provides the location of the left/right parens and a list of comma 2975 /// locations. 2976 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 2977 MultiExprArg ArgExprs, SourceLocation RParenLoc, 2978 Expr *ExecConfig = 0, bool IsExecConfig = false); 2979 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, 2980 SourceLocation LParenLoc, 2981 Expr **Args, unsigned NumArgs, 2982 SourceLocation RParenLoc, 2983 Expr *Config = 0, 2984 bool IsExecConfig = false); 2985 2986 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, 2987 MultiExprArg ExecConfig, 2988 SourceLocation GGGLoc); 2989 2990 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, 2991 Declarator &D, ParsedType &Ty, 2992 SourceLocation RParenLoc, Expr *CastExpr); 2993 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, 2994 TypeSourceInfo *Ty, 2995 SourceLocation RParenLoc, 2996 Expr *Op); 2997 CastKind PrepareScalarCast(ExprResult &src, QualType destType); 2998 2999 /// \brief Build an altivec or OpenCL literal. 3000 ExprResult BuildVectorLiteral(SourceLocation LParenLoc, 3001 SourceLocation RParenLoc, Expr *E, 3002 TypeSourceInfo *TInfo); 3003 3004 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); 3005 3006 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, 3007 ParsedType Ty, 3008 SourceLocation RParenLoc, 3009 Expr *InitExpr); 3010 3011 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, 3012 TypeSourceInfo *TInfo, 3013 SourceLocation RParenLoc, 3014 Expr *LiteralExpr); 3015 3016 ExprResult ActOnInitList(SourceLocation LBraceLoc, 3017 MultiExprArg InitArgList, 3018 SourceLocation RBraceLoc); 3019 3020 ExprResult ActOnDesignatedInitializer(Designation &Desig, 3021 SourceLocation Loc, 3022 bool GNUSyntax, 3023 ExprResult Init); 3024 3025 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, 3026 tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); 3027 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, 3028 BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); 3029 ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, 3030 Expr *LHSExpr, Expr *RHSExpr); 3031 3032 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null 3033 /// in the case of a the GNU conditional expr extension. 3034 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, 3035 SourceLocation ColonLoc, 3036 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); 3037 3038 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". 3039 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, 3040 LabelDecl *TheDecl); 3041 3042 void ActOnStartStmtExpr(); 3043 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, 3044 SourceLocation RPLoc); // "({..})" 3045 void ActOnStmtExprError(); 3046 3047 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 3048 struct OffsetOfComponent { 3049 SourceLocation LocStart, LocEnd; 3050 bool isBrackets; // true if [expr], false if .ident 3051 union { 3052 IdentifierInfo *IdentInfo; 3053 Expr *E; 3054 } U; 3055 }; 3056 3057 /// __builtin_offsetof(type, a.b[123][456].c) 3058 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, 3059 TypeSourceInfo *TInfo, 3060 OffsetOfComponent *CompPtr, 3061 unsigned NumComponents, 3062 SourceLocation RParenLoc); 3063 ExprResult ActOnBuiltinOffsetOf(Scope *S, 3064 SourceLocation BuiltinLoc, 3065 SourceLocation TypeLoc, 3066 ParsedType ParsedArgTy, 3067 OffsetOfComponent *CompPtr, 3068 unsigned NumComponents, 3069 SourceLocation RParenLoc); 3070 3071 // __builtin_choose_expr(constExpr, expr1, expr2) 3072 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, 3073 Expr *CondExpr, Expr *LHSExpr, 3074 Expr *RHSExpr, SourceLocation RPLoc); 3075 3076 // __builtin_va_arg(expr, type) 3077 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, 3078 SourceLocation RPLoc); 3079 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, 3080 TypeSourceInfo *TInfo, SourceLocation RPLoc); 3081 3082 // __null 3083 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); 3084 3085 bool CheckCaseExpression(Expr *E); 3086 3087 /// \brief Describes the result of an "if-exists" condition check. 3088 enum IfExistsResult { 3089 /// \brief The symbol exists. 3090 IER_Exists, 3091 3092 /// \brief The symbol does not exist. 3093 IER_DoesNotExist, 3094 3095 /// \brief The name is a dependent name, so the results will differ 3096 /// from one instantiation to the next. 3097 IER_Dependent, 3098 3099 /// \brief An error occurred. 3100 IER_Error 3101 }; 3102 3103 IfExistsResult 3104 CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, 3105 const DeclarationNameInfo &TargetNameInfo); 3106 3107 IfExistsResult 3108 CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, 3109 bool IsIfExists, CXXScopeSpec &SS, 3110 UnqualifiedId &Name); 3111 3112 StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, 3113 bool IsIfExists, 3114 NestedNameSpecifierLoc QualifierLoc, 3115 DeclarationNameInfo NameInfo, 3116 Stmt *Nested); 3117 StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, 3118 bool IsIfExists, 3119 CXXScopeSpec &SS, UnqualifiedId &Name, 3120 Stmt *Nested); 3121 3122 //===------------------------- "Block" Extension ------------------------===// 3123 3124 /// ActOnBlockStart - This callback is invoked when a block literal is 3125 /// started. 3126 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); 3127 3128 /// ActOnBlockArguments - This callback allows processing of block arguments. 3129 /// If there are no arguments, this is still invoked. 3130 void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, 3131 Scope *CurScope); 3132 3133 /// ActOnBlockError - If there is an error parsing a block, this callback 3134 /// is invoked to pop the information about the block from the action impl. 3135 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); 3136 3137 /// ActOnBlockStmtExpr - This is called when the body of a block statement 3138 /// literal was successfully completed. ^(int x){...} 3139 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, 3140 Scope *CurScope); 3141 3142 //===---------------------------- OpenCL Features -----------------------===// 3143 3144 /// __builtin_astype(...) 3145 ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, 3146 SourceLocation BuiltinLoc, 3147 SourceLocation RParenLoc); 3148 3149 //===---------------------------- C++ Features --------------------------===// 3150 3151 // Act on C++ namespaces 3152 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, 3153 SourceLocation NamespaceLoc, 3154 SourceLocation IdentLoc, 3155 IdentifierInfo *Ident, 3156 SourceLocation LBrace, 3157 AttributeList *AttrList); 3158 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); 3159 3160 NamespaceDecl *getStdNamespace() const; 3161 NamespaceDecl *getOrCreateStdNamespace(); 3162 3163 CXXRecordDecl *getStdBadAlloc() const; 3164 3165 /// \brief Tests whether Ty is an instance of std::initializer_list and, if 3166 /// it is and Element is not NULL, assigns the element type to Element. 3167 bool isStdInitializerList(QualType Ty, QualType *Element); 3168 3169 /// \brief Looks for the std::initializer_list template and instantiates it 3170 /// with Element, or emits an error if it's not found. 3171 /// 3172 /// \returns The instantiated template, or null on error. 3173 QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); 3174 3175 /// \brief Determine whether Ctor is an initializer-list constructor, as 3176 /// defined in [dcl.init.list]p2. 3177 bool isInitListConstructor(const CXXConstructorDecl *Ctor); 3178 3179 Decl *ActOnUsingDirective(Scope *CurScope, 3180 SourceLocation UsingLoc, 3181 SourceLocation NamespcLoc, 3182 CXXScopeSpec &SS, 3183 SourceLocation IdentLoc, 3184 IdentifierInfo *NamespcName, 3185 AttributeList *AttrList); 3186 3187 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); 3188 3189 Decl *ActOnNamespaceAliasDef(Scope *CurScope, 3190 SourceLocation NamespaceLoc, 3191 SourceLocation AliasLoc, 3192 IdentifierInfo *Alias, 3193 CXXScopeSpec &SS, 3194 SourceLocation IdentLoc, 3195 IdentifierInfo *Ident); 3196 3197 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); 3198 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, 3199 const LookupResult &PreviousDecls); 3200 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, 3201 NamedDecl *Target); 3202 3203 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, 3204 bool isTypeName, 3205 const CXXScopeSpec &SS, 3206 SourceLocation NameLoc, 3207 const LookupResult &Previous); 3208 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, 3209 const CXXScopeSpec &SS, 3210 SourceLocation NameLoc); 3211 3212 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, 3213 SourceLocation UsingLoc, 3214 CXXScopeSpec &SS, 3215 const DeclarationNameInfo &NameInfo, 3216 AttributeList *AttrList, 3217 bool IsInstantiation, 3218 bool IsTypeName, 3219 SourceLocation TypenameLoc); 3220 3221 bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); 3222 3223 Decl *ActOnUsingDeclaration(Scope *CurScope, 3224 AccessSpecifier AS, 3225 bool HasUsingKeyword, 3226 SourceLocation UsingLoc, 3227 CXXScopeSpec &SS, 3228 UnqualifiedId &Name, 3229 AttributeList *AttrList, 3230 bool IsTypeName, 3231 SourceLocation TypenameLoc); 3232 Decl *ActOnAliasDeclaration(Scope *CurScope, 3233 AccessSpecifier AS, 3234 MultiTemplateParamsArg TemplateParams, 3235 SourceLocation UsingLoc, 3236 UnqualifiedId &Name, 3237 TypeResult Type); 3238 3239 /// InitializeVarWithConstructor - Creates an CXXConstructExpr 3240 /// and sets it as the initializer for the the passed in VarDecl. 3241 bool InitializeVarWithConstructor(VarDecl *VD, 3242 CXXConstructorDecl *Constructor, 3243 MultiExprArg Exprs, 3244 bool HadMultipleCandidates); 3245 3246 /// BuildCXXConstructExpr - Creates a complete call to a constructor, 3247 /// including handling of its default argument expressions. 3248 /// 3249 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind 3250 ExprResult 3251 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3252 CXXConstructorDecl *Constructor, MultiExprArg Exprs, 3253 bool HadMultipleCandidates, bool RequiresZeroInit, 3254 unsigned ConstructKind, SourceRange ParenRange); 3255 3256 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if 3257 // the constructor can be elidable? 3258 ExprResult 3259 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3260 CXXConstructorDecl *Constructor, bool Elidable, 3261 MultiExprArg Exprs, bool HadMultipleCandidates, 3262 bool RequiresZeroInit, unsigned ConstructKind, 3263 SourceRange ParenRange); 3264 3265 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating 3266 /// the default expr if needed. 3267 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, 3268 FunctionDecl *FD, 3269 ParmVarDecl *Param); 3270 3271 /// FinalizeVarWithDestructor - Prepare for calling destructor on the 3272 /// constructed variable. 3273 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); 3274 3275 /// \brief Helper class that collects exception specifications for 3276 /// implicitly-declared special member functions. 3277 class ImplicitExceptionSpecification { 3278 // Pointer to allow copying 3279 Sema *Self; 3280 // We order exception specifications thus: 3281 // noexcept is the most restrictive, but is only used in C++0x. 3282 // throw() comes next. 3283 // Then a throw(collected exceptions) 3284 // Finally no specification. 3285 // throw(...) is used instead if any called function uses it. 3286 // 3287 // If this exception specification cannot be known yet (for instance, 3288 // because this is the exception specification for a defaulted default 3289 // constructor and we haven't finished parsing the deferred parts of the 3290 // class yet), the C++0x standard does not specify how to behave. We 3291 // record this as an 'unknown' exception specification, which overrules 3292 // any other specification (even 'none', to keep this rule simple). 3293 ExceptionSpecificationType ComputedEST; 3294 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; 3295 SmallVector<QualType, 4> Exceptions; 3296 3297 void ClearExceptions() { 3298 ExceptionsSeen.clear(); 3299 Exceptions.clear(); 3300 } 3301 3302 public: 3303 explicit ImplicitExceptionSpecification(Sema &Self) 3304 : Self(&Self), ComputedEST(EST_BasicNoexcept) { 3305 if (!Self.Context.getLangOpts().CPlusPlus0x) 3306 ComputedEST = EST_DynamicNone; 3307 } 3308 3309 /// \brief Get the computed exception specification type. 3310 ExceptionSpecificationType getExceptionSpecType() const { 3311 assert(ComputedEST != EST_ComputedNoexcept && 3312 "noexcept(expr) should not be a possible result"); 3313 return ComputedEST; 3314 } 3315 3316 /// \brief The number of exceptions in the exception specification. 3317 unsigned size() const { return Exceptions.size(); } 3318 3319 /// \brief The set of exceptions in the exception specification. 3320 const QualType *data() const { return Exceptions.data(); } 3321 3322 /// \brief Integrate another called method into the collected data. 3323 void CalledDecl(SourceLocation CallLoc, CXXMethodDecl *Method); 3324 3325 /// \brief Integrate an invoked expression into the collected data. 3326 void CalledExpr(Expr *E); 3327 3328 /// \brief Specify that the exception specification can't be detemined yet. 3329 void SetDelayed() { 3330 ClearExceptions(); 3331 ComputedEST = EST_Delayed; 3332 } 3333 3334 /// \brief Have we been unable to compute this exception specification? 3335 bool isDelayed() { 3336 return ComputedEST == EST_Delayed; 3337 } 3338 3339 /// \brief Overwrite an EPI's exception specification with this 3340 /// computed exception specification. 3341 void getEPI(FunctionProtoType::ExtProtoInfo &EPI) const { 3342 EPI.ExceptionSpecType = getExceptionSpecType(); 3343 EPI.NumExceptions = size(); 3344 EPI.Exceptions = data(); 3345 } 3346 FunctionProtoType::ExtProtoInfo getEPI() const { 3347 FunctionProtoType::ExtProtoInfo EPI; 3348 getEPI(EPI); 3349 return EPI; 3350 } 3351 }; 3352 3353 /// \brief Determine what sort of exception specification a defaulted 3354 /// copy constructor of a class will have. 3355 ImplicitExceptionSpecification 3356 ComputeDefaultedDefaultCtorExceptionSpec(CXXRecordDecl *ClassDecl); 3357 3358 /// \brief Determine what sort of exception specification a defaulted 3359 /// default constructor of a class will have, and whether the parameter 3360 /// will be const. 3361 std::pair<ImplicitExceptionSpecification, bool> 3362 ComputeDefaultedCopyCtorExceptionSpecAndConst(CXXRecordDecl *ClassDecl); 3363 3364 /// \brief Determine what sort of exception specification a defautled 3365 /// copy assignment operator of a class will have, and whether the 3366 /// parameter will be const. 3367 std::pair<ImplicitExceptionSpecification, bool> 3368 ComputeDefaultedCopyAssignmentExceptionSpecAndConst(CXXRecordDecl *ClassDecl); 3369 3370 /// \brief Determine what sort of exception specification a defaulted move 3371 /// constructor of a class will have. 3372 ImplicitExceptionSpecification 3373 ComputeDefaultedMoveCtorExceptionSpec(CXXRecordDecl *ClassDecl); 3374 3375 /// \brief Determine what sort of exception specification a defaulted move 3376 /// assignment operator of a class will have. 3377 ImplicitExceptionSpecification 3378 ComputeDefaultedMoveAssignmentExceptionSpec(CXXRecordDecl *ClassDecl); 3379 3380 /// \brief Determine what sort of exception specification a defaulted 3381 /// destructor of a class will have. 3382 ImplicitExceptionSpecification 3383 ComputeDefaultedDtorExceptionSpec(CXXRecordDecl *ClassDecl); 3384 3385 /// \brief Check the given exception-specification and update the 3386 /// extended prototype information with the results. 3387 void checkExceptionSpecification(ExceptionSpecificationType EST, 3388 ArrayRef<ParsedType> DynamicExceptions, 3389 ArrayRef<SourceRange> DynamicExceptionRanges, 3390 Expr *NoexceptExpr, 3391 llvm::SmallVectorImpl<QualType> &Exceptions, 3392 FunctionProtoType::ExtProtoInfo &EPI); 3393 3394 /// \brief Determine if a special member function should have a deleted 3395 /// definition when it is defaulted. 3396 bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, 3397 bool Diagnose = false); 3398 3399 /// \brief Declare the implicit default constructor for the given class. 3400 /// 3401 /// \param ClassDecl The class declaration into which the implicit 3402 /// default constructor will be added. 3403 /// 3404 /// \returns The implicitly-declared default constructor. 3405 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 3406 CXXRecordDecl *ClassDecl); 3407 3408 /// DefineImplicitDefaultConstructor - Checks for feasibility of 3409 /// defining this constructor as the default constructor. 3410 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 3411 CXXConstructorDecl *Constructor); 3412 3413 /// \brief Declare the implicit destructor for the given class. 3414 /// 3415 /// \param ClassDecl The class declaration into which the implicit 3416 /// destructor will be added. 3417 /// 3418 /// \returns The implicitly-declared destructor. 3419 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 3420 3421 /// DefineImplicitDestructor - Checks for feasibility of 3422 /// defining this destructor as the default destructor. 3423 void DefineImplicitDestructor(SourceLocation CurrentLocation, 3424 CXXDestructorDecl *Destructor); 3425 3426 /// \brief Build an exception spec for destructors that don't have one. 3427 /// 3428 /// C++11 says that user-defined destructors with no exception spec get one 3429 /// that looks as if the destructor was implicitly declared. 3430 void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl, 3431 CXXDestructorDecl *Destructor, 3432 bool WasDelayed = false); 3433 3434 /// \brief Declare all inherited constructors for the given class. 3435 /// 3436 /// \param ClassDecl The class declaration into which the inherited 3437 /// constructors will be added. 3438 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl); 3439 3440 /// \brief Declare the implicit copy constructor for the given class. 3441 /// 3442 /// \param ClassDecl The class declaration into which the implicit 3443 /// copy constructor will be added. 3444 /// 3445 /// \returns The implicitly-declared copy constructor. 3446 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 3447 3448 /// DefineImplicitCopyConstructor - Checks for feasibility of 3449 /// defining this constructor as the copy constructor. 3450 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 3451 CXXConstructorDecl *Constructor); 3452 3453 /// \brief Declare the implicit move constructor for the given class. 3454 /// 3455 /// \param ClassDecl The Class declaration into which the implicit 3456 /// move constructor will be added. 3457 /// 3458 /// \returns The implicitly-declared move constructor, or NULL if it wasn't 3459 /// declared. 3460 CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); 3461 3462 /// DefineImplicitMoveConstructor - Checks for feasibility of 3463 /// defining this constructor as the move constructor. 3464 void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, 3465 CXXConstructorDecl *Constructor); 3466 3467 /// \brief Declare the implicit copy assignment operator for the given class. 3468 /// 3469 /// \param ClassDecl The class declaration into which the implicit 3470 /// copy assignment operator will be added. 3471 /// 3472 /// \returns The implicitly-declared copy assignment operator. 3473 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 3474 3475 /// \brief Defines an implicitly-declared copy assignment operator. 3476 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 3477 CXXMethodDecl *MethodDecl); 3478 3479 /// \brief Declare the implicit move assignment operator for the given class. 3480 /// 3481 /// \param ClassDecl The Class declaration into which the implicit 3482 /// move assignment operator will be added. 3483 /// 3484 /// \returns The implicitly-declared move assignment operator, or NULL if it 3485 /// wasn't declared. 3486 CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); 3487 3488 /// \brief Defines an implicitly-declared move assignment operator. 3489 void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, 3490 CXXMethodDecl *MethodDecl); 3491 3492 /// \brief Force the declaration of any implicitly-declared members of this 3493 /// class. 3494 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 3495 3496 /// \brief Determine whether the given function is an implicitly-deleted 3497 /// special member function. 3498 bool isImplicitlyDeleted(FunctionDecl *FD); 3499 3500 /// \brief Check whether 'this' shows up in the type of a static member 3501 /// function after the (naturally empty) cv-qualifier-seq would be. 3502 /// 3503 /// \returns true if an error occurred. 3504 bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); 3505 3506 /// \brief Whether this' shows up in the exception specification of a static 3507 /// member function. 3508 bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); 3509 3510 /// \brief Check whether 'this' shows up in the attributes of the given 3511 /// static member function. 3512 /// 3513 /// \returns true if an error occurred. 3514 bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); 3515 3516 /// MaybeBindToTemporary - If the passed in expression has a record type with 3517 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 3518 /// it simply returns the passed in expression. 3519 ExprResult MaybeBindToTemporary(Expr *E); 3520 3521 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 3522 MultiExprArg ArgsPtr, 3523 SourceLocation Loc, 3524 ASTOwningVector<Expr*> &ConvertedArgs, 3525 bool AllowExplicit = false); 3526 3527 ParsedType getDestructorName(SourceLocation TildeLoc, 3528 IdentifierInfo &II, SourceLocation NameLoc, 3529 Scope *S, CXXScopeSpec &SS, 3530 ParsedType ObjectType, 3531 bool EnteringContext); 3532 3533 ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType); 3534 3535 // Checks that reinterpret casts don't have undefined behavior. 3536 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, 3537 bool IsDereference, SourceRange Range); 3538 3539 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 3540 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 3541 tok::TokenKind Kind, 3542 SourceLocation LAngleBracketLoc, 3543 Declarator &D, 3544 SourceLocation RAngleBracketLoc, 3545 SourceLocation LParenLoc, 3546 Expr *E, 3547 SourceLocation RParenLoc); 3548 3549 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 3550 tok::TokenKind Kind, 3551 TypeSourceInfo *Ty, 3552 Expr *E, 3553 SourceRange AngleBrackets, 3554 SourceRange Parens); 3555 3556 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3557 SourceLocation TypeidLoc, 3558 TypeSourceInfo *Operand, 3559 SourceLocation RParenLoc); 3560 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3561 SourceLocation TypeidLoc, 3562 Expr *Operand, 3563 SourceLocation RParenLoc); 3564 3565 /// ActOnCXXTypeid - Parse typeid( something ). 3566 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 3567 SourceLocation LParenLoc, bool isType, 3568 void *TyOrExpr, 3569 SourceLocation RParenLoc); 3570 3571 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3572 SourceLocation TypeidLoc, 3573 TypeSourceInfo *Operand, 3574 SourceLocation RParenLoc); 3575 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3576 SourceLocation TypeidLoc, 3577 Expr *Operand, 3578 SourceLocation RParenLoc); 3579 3580 /// ActOnCXXUuidof - Parse __uuidof( something ). 3581 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 3582 SourceLocation LParenLoc, bool isType, 3583 void *TyOrExpr, 3584 SourceLocation RParenLoc); 3585 3586 3587 //// ActOnCXXThis - Parse 'this' pointer. 3588 ExprResult ActOnCXXThis(SourceLocation loc); 3589 3590 /// \brief Try to retrieve the type of the 'this' pointer. 3591 /// 3592 /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. 3593 QualType getCurrentThisType(); 3594 3595 /// \brief When non-NULL, the C++ 'this' expression is allowed despite the 3596 /// current context not being a non-static member function. In such cases, 3597 /// this provides the type used for 'this'. 3598 QualType CXXThisTypeOverride; 3599 3600 /// \brief RAII object used to temporarily allow the C++ 'this' expression 3601 /// to be used, with the given qualifiers on the current class type. 3602 class CXXThisScopeRAII { 3603 Sema &S; 3604 QualType OldCXXThisTypeOverride; 3605 bool Enabled; 3606 3607 public: 3608 /// \brief Introduce a new scope where 'this' may be allowed (when enabled), 3609 /// using the given declaration (which is either a class template or a 3610 /// class) along with the given qualifiers. 3611 /// along with the qualifiers placed on '*this'. 3612 CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals, 3613 bool Enabled = true); 3614 3615 ~CXXThisScopeRAII(); 3616 }; 3617 3618 /// \brief Make sure the value of 'this' is actually available in the current 3619 /// context, if it is a potentially evaluated context. 3620 /// 3621 /// \param Loc The location at which the capture of 'this' occurs. 3622 /// 3623 /// \param Explicit Whether 'this' is explicitly captured in a lambda 3624 /// capture list. 3625 void CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false); 3626 3627 /// \brief Determine whether the given type is the type of *this that is used 3628 /// outside of the body of a member function for a type that is currently 3629 /// being defined. 3630 bool isThisOutsideMemberFunctionBody(QualType BaseType); 3631 3632 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 3633 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3634 3635 3636 /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. 3637 ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3638 3639 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 3640 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 3641 3642 //// ActOnCXXThrow - Parse throw expressions. 3643 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); 3644 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, 3645 bool IsThrownVarInScope); 3646 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E, 3647 bool IsThrownVarInScope); 3648 3649 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 3650 /// Can be interpreted either as function-style casting ("int(x)") 3651 /// or class type construction ("ClassType(x,y,z)") 3652 /// or creation of a value-initialized type ("int()"). 3653 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 3654 SourceLocation LParenLoc, 3655 MultiExprArg Exprs, 3656 SourceLocation RParenLoc); 3657 3658 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 3659 SourceLocation LParenLoc, 3660 MultiExprArg Exprs, 3661 SourceLocation RParenLoc); 3662 3663 /// ActOnCXXNew - Parsed a C++ 'new' expression. 3664 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 3665 SourceLocation PlacementLParen, 3666 MultiExprArg PlacementArgs, 3667 SourceLocation PlacementRParen, 3668 SourceRange TypeIdParens, Declarator &D, 3669 Expr *Initializer); 3670 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, 3671 SourceLocation PlacementLParen, 3672 MultiExprArg PlacementArgs, 3673 SourceLocation PlacementRParen, 3674 SourceRange TypeIdParens, 3675 QualType AllocType, 3676 TypeSourceInfo *AllocTypeInfo, 3677 Expr *ArraySize, 3678 SourceRange DirectInitRange, 3679 Expr *Initializer, 3680 bool TypeMayContainAuto = true); 3681 3682 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 3683 SourceRange R); 3684 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 3685 bool UseGlobal, QualType AllocType, bool IsArray, 3686 Expr **PlaceArgs, unsigned NumPlaceArgs, 3687 FunctionDecl *&OperatorNew, 3688 FunctionDecl *&OperatorDelete); 3689 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 3690 DeclarationName Name, Expr** Args, 3691 unsigned NumArgs, DeclContext *Ctx, 3692 bool AllowMissing, FunctionDecl *&Operator, 3693 bool Diagnose = true); 3694 void DeclareGlobalNewDelete(); 3695 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 3696 QualType Argument, 3697 bool addMallocAttr = false); 3698 3699 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 3700 DeclarationName Name, FunctionDecl* &Operator, 3701 bool Diagnose = true); 3702 3703 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 3704 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 3705 bool UseGlobal, bool ArrayForm, 3706 Expr *Operand); 3707 3708 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 3709 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 3710 SourceLocation StmtLoc, 3711 bool ConvertToBoolean); 3712 3713 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 3714 Expr *Operand, SourceLocation RParen); 3715 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 3716 SourceLocation RParen); 3717 3718 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 3719 /// pseudo-functions. 3720 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 3721 SourceLocation KWLoc, 3722 ParsedType Ty, 3723 SourceLocation RParen); 3724 3725 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 3726 SourceLocation KWLoc, 3727 TypeSourceInfo *T, 3728 SourceLocation RParen); 3729 3730 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support 3731 /// pseudo-functions. 3732 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT, 3733 SourceLocation KWLoc, 3734 ParsedType LhsTy, 3735 ParsedType RhsTy, 3736 SourceLocation RParen); 3737 3738 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT, 3739 SourceLocation KWLoc, 3740 TypeSourceInfo *LhsT, 3741 TypeSourceInfo *RhsT, 3742 SourceLocation RParen); 3743 3744 /// \brief Parsed one of the type trait support pseudo-functions. 3745 ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3746 ArrayRef<ParsedType> Args, 3747 SourceLocation RParenLoc); 3748 ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3749 ArrayRef<TypeSourceInfo *> Args, 3750 SourceLocation RParenLoc); 3751 3752 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support 3753 /// pseudo-functions. 3754 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, 3755 SourceLocation KWLoc, 3756 ParsedType LhsTy, 3757 Expr *DimExpr, 3758 SourceLocation RParen); 3759 3760 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, 3761 SourceLocation KWLoc, 3762 TypeSourceInfo *TSInfo, 3763 Expr *DimExpr, 3764 SourceLocation RParen); 3765 3766 /// ActOnExpressionTrait - Parsed one of the unary type trait support 3767 /// pseudo-functions. 3768 ExprResult ActOnExpressionTrait(ExpressionTrait OET, 3769 SourceLocation KWLoc, 3770 Expr *Queried, 3771 SourceLocation RParen); 3772 3773 ExprResult BuildExpressionTrait(ExpressionTrait OET, 3774 SourceLocation KWLoc, 3775 Expr *Queried, 3776 SourceLocation RParen); 3777 3778 ExprResult ActOnStartCXXMemberReference(Scope *S, 3779 Expr *Base, 3780 SourceLocation OpLoc, 3781 tok::TokenKind OpKind, 3782 ParsedType &ObjectType, 3783 bool &MayBePseudoDestructor); 3784 3785 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 3786 3787 ExprResult BuildPseudoDestructorExpr(Expr *Base, 3788 SourceLocation OpLoc, 3789 tok::TokenKind OpKind, 3790 const CXXScopeSpec &SS, 3791 TypeSourceInfo *ScopeType, 3792 SourceLocation CCLoc, 3793 SourceLocation TildeLoc, 3794 PseudoDestructorTypeStorage DestroyedType, 3795 bool HasTrailingLParen); 3796 3797 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3798 SourceLocation OpLoc, 3799 tok::TokenKind OpKind, 3800 CXXScopeSpec &SS, 3801 UnqualifiedId &FirstTypeName, 3802 SourceLocation CCLoc, 3803 SourceLocation TildeLoc, 3804 UnqualifiedId &SecondTypeName, 3805 bool HasTrailingLParen); 3806 3807 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3808 SourceLocation OpLoc, 3809 tok::TokenKind OpKind, 3810 SourceLocation TildeLoc, 3811 const DeclSpec& DS, 3812 bool HasTrailingLParen); 3813 3814 /// MaybeCreateExprWithCleanups - If the current full-expression 3815 /// requires any cleanups, surround it with a ExprWithCleanups node. 3816 /// Otherwise, just returns the passed-in expression. 3817 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); 3818 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); 3819 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); 3820 3821 ExprResult ActOnFinishFullExpr(Expr *Expr) { 3822 return ActOnFinishFullExpr(Expr, Expr ? Expr->getExprLoc() 3823 : SourceLocation()); 3824 } 3825 ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC); 3826 StmtResult ActOnFinishFullStmt(Stmt *Stmt); 3827 3828 // Marks SS invalid if it represents an incomplete type. 3829 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 3830 3831 DeclContext *computeDeclContext(QualType T); 3832 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 3833 bool EnteringContext = false); 3834 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 3835 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 3836 bool isUnknownSpecialization(const CXXScopeSpec &SS); 3837 3838 /// \brief The parser has parsed a global nested-name-specifier '::'. 3839 /// 3840 /// \param S The scope in which this nested-name-specifier occurs. 3841 /// 3842 /// \param CCLoc The location of the '::'. 3843 /// 3844 /// \param SS The nested-name-specifier, which will be updated in-place 3845 /// to reflect the parsed nested-name-specifier. 3846 /// 3847 /// \returns true if an error occurred, false otherwise. 3848 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc, 3849 CXXScopeSpec &SS); 3850 3851 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 3852 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 3853 3854 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 3855 SourceLocation IdLoc, 3856 IdentifierInfo &II, 3857 ParsedType ObjectType); 3858 3859 bool BuildCXXNestedNameSpecifier(Scope *S, 3860 IdentifierInfo &Identifier, 3861 SourceLocation IdentifierLoc, 3862 SourceLocation CCLoc, 3863 QualType ObjectType, 3864 bool EnteringContext, 3865 CXXScopeSpec &SS, 3866 NamedDecl *ScopeLookupResult, 3867 bool ErrorRecoveryLookup); 3868 3869 /// \brief The parser has parsed a nested-name-specifier 'identifier::'. 3870 /// 3871 /// \param S The scope in which this nested-name-specifier occurs. 3872 /// 3873 /// \param Identifier The identifier preceding the '::'. 3874 /// 3875 /// \param IdentifierLoc The location of the identifier. 3876 /// 3877 /// \param CCLoc The location of the '::'. 3878 /// 3879 /// \param ObjectType The type of the object, if we're parsing 3880 /// nested-name-specifier in a member access expression. 3881 /// 3882 /// \param EnteringContext Whether we're entering the context nominated by 3883 /// this nested-name-specifier. 3884 /// 3885 /// \param SS The nested-name-specifier, which is both an input 3886 /// parameter (the nested-name-specifier before this type) and an 3887 /// output parameter (containing the full nested-name-specifier, 3888 /// including this new type). 3889 /// 3890 /// \returns true if an error occurred, false otherwise. 3891 bool ActOnCXXNestedNameSpecifier(Scope *S, 3892 IdentifierInfo &Identifier, 3893 SourceLocation IdentifierLoc, 3894 SourceLocation CCLoc, 3895 ParsedType ObjectType, 3896 bool EnteringContext, 3897 CXXScopeSpec &SS); 3898 3899 ExprResult ActOnDecltypeExpression(Expr *E); 3900 3901 bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, 3902 const DeclSpec &DS, 3903 SourceLocation ColonColonLoc); 3904 3905 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 3906 IdentifierInfo &Identifier, 3907 SourceLocation IdentifierLoc, 3908 SourceLocation ColonLoc, 3909 ParsedType ObjectType, 3910 bool EnteringContext); 3911 3912 /// \brief The parser has parsed a nested-name-specifier 3913 /// 'template[opt] template-name < template-args >::'. 3914 /// 3915 /// \param S The scope in which this nested-name-specifier occurs. 3916 /// 3917 /// \param SS The nested-name-specifier, which is both an input 3918 /// parameter (the nested-name-specifier before this type) and an 3919 /// output parameter (containing the full nested-name-specifier, 3920 /// including this new type). 3921 /// 3922 /// \param TemplateKWLoc the location of the 'template' keyword, if any. 3923 /// \param TemplateName the template name. 3924 /// \param TemplateNameLoc The location of the template name. 3925 /// \param LAngleLoc The location of the opening angle bracket ('<'). 3926 /// \param TemplateArgs The template arguments. 3927 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3928 /// \param CCLoc The location of the '::'. 3929 /// 3930 /// \param EnteringContext Whether we're entering the context of the 3931 /// nested-name-specifier. 3932 /// 3933 /// 3934 /// \returns true if an error occurred, false otherwise. 3935 bool ActOnCXXNestedNameSpecifier(Scope *S, 3936 CXXScopeSpec &SS, 3937 SourceLocation TemplateKWLoc, 3938 TemplateTy TemplateName, 3939 SourceLocation TemplateNameLoc, 3940 SourceLocation LAngleLoc, 3941 ASTTemplateArgsPtr TemplateArgs, 3942 SourceLocation RAngleLoc, 3943 SourceLocation CCLoc, 3944 bool EnteringContext); 3945 3946 /// \brief Given a C++ nested-name-specifier, produce an annotation value 3947 /// that the parser can use later to reconstruct the given 3948 /// nested-name-specifier. 3949 /// 3950 /// \param SS A nested-name-specifier. 3951 /// 3952 /// \returns A pointer containing all of the information in the 3953 /// nested-name-specifier \p SS. 3954 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); 3955 3956 /// \brief Given an annotation pointer for a nested-name-specifier, restore 3957 /// the nested-name-specifier structure. 3958 /// 3959 /// \param Annotation The annotation pointer, produced by 3960 /// \c SaveNestedNameSpecifierAnnotation(). 3961 /// 3962 /// \param AnnotationRange The source range corresponding to the annotation. 3963 /// 3964 /// \param SS The nested-name-specifier that will be updated with the contents 3965 /// of the annotation pointer. 3966 void RestoreNestedNameSpecifierAnnotation(void *Annotation, 3967 SourceRange AnnotationRange, 3968 CXXScopeSpec &SS); 3969 3970 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3971 3972 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 3973 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 3974 /// After this method is called, according to [C++ 3.4.3p3], names should be 3975 /// looked up in the declarator-id's scope, until the declarator is parsed and 3976 /// ActOnCXXExitDeclaratorScope is called. 3977 /// The 'SS' should be a non-empty valid CXXScopeSpec. 3978 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 3979 3980 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 3981 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 3982 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 3983 /// Used to indicate that names should revert to being looked up in the 3984 /// defining scope. 3985 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3986 3987 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 3988 /// initializer for the declaration 'Dcl'. 3989 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 3990 /// static data member of class X, names should be looked up in the scope of 3991 /// class X. 3992 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 3993 3994 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 3995 /// initializer for the declaration 'Dcl'. 3996 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); 3997 3998 /// \brief Create a new lambda closure type. 3999 CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, 4000 bool KnownDependent = false); 4001 4002 /// \brief Start the definition of a lambda expression. 4003 CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class, 4004 SourceRange IntroducerRange, 4005 TypeSourceInfo *MethodType, 4006 SourceLocation EndLoc, 4007 llvm::ArrayRef<ParmVarDecl *> Params, 4008 llvm::Optional<unsigned> ManglingNumber 4009 = llvm::Optional<unsigned>(), 4010 Decl *ContextDecl = 0); 4011 4012 /// \brief Introduce the scope for a lambda expression. 4013 sema::LambdaScopeInfo *enterLambdaScope(CXXMethodDecl *CallOperator, 4014 SourceRange IntroducerRange, 4015 LambdaCaptureDefault CaptureDefault, 4016 bool ExplicitParams, 4017 bool ExplicitResultType, 4018 bool Mutable); 4019 4020 /// \brief Note that we have finished the explicit captures for the 4021 /// given lambda. 4022 void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); 4023 4024 /// \brief Introduce the lambda parameters into scope. 4025 void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope); 4026 4027 /// \brief Deduce a block or lambda's return type based on the return 4028 /// statements present in the body. 4029 void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); 4030 4031 /// ActOnStartOfLambdaDefinition - This is called just before we start 4032 /// parsing the body of a lambda; it analyzes the explicit captures and 4033 /// arguments, and sets up various data-structures for the body of the 4034 /// lambda. 4035 void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, 4036 Declarator &ParamInfo, Scope *CurScope); 4037 4038 /// ActOnLambdaError - If there is an error parsing a lambda, this callback 4039 /// is invoked to pop the information about the lambda. 4040 void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, 4041 bool IsInstantiation = false); 4042 4043 /// ActOnLambdaExpr - This is called when the body of a lambda expression 4044 /// was successfully completed. 4045 ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, 4046 Scope *CurScope, 4047 bool IsInstantiation = false); 4048 4049 /// \brief Define the "body" of the conversion from a lambda object to a 4050 /// function pointer. 4051 /// 4052 /// This routine doesn't actually define a sensible body; rather, it fills 4053 /// in the initialization expression needed to copy the lambda object into 4054 /// the block, and IR generation actually generates the real body of the 4055 /// block pointer conversion. 4056 void DefineImplicitLambdaToFunctionPointerConversion( 4057 SourceLocation CurrentLoc, CXXConversionDecl *Conv); 4058 4059 /// \brief Define the "body" of the conversion from a lambda object to a 4060 /// block pointer. 4061 /// 4062 /// This routine doesn't actually define a sensible body; rather, it fills 4063 /// in the initialization expression needed to copy the lambda object into 4064 /// the block, and IR generation actually generates the real body of the 4065 /// block pointer conversion. 4066 void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, 4067 CXXConversionDecl *Conv); 4068 4069 ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, 4070 SourceLocation ConvLocation, 4071 CXXConversionDecl *Conv, 4072 Expr *Src); 4073 4074 // ParseObjCStringLiteral - Parse Objective-C string literals. 4075 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 4076 Expr **Strings, 4077 unsigned NumStrings); 4078 4079 ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); 4080 4081 /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the 4082 /// numeric literal expression. Type of the expression will be "NSNumber *" 4083 /// or "id" if NSNumber is unavailable. 4084 ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); 4085 ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, 4086 bool Value); 4087 ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); 4088 4089 /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the 4090 /// '@' prefixed parenthesized expression. The type of the expression will 4091 /// either be "NSNumber *" or "NSString *" depending on the type of 4092 /// ValueType, which is allowed to be a built-in numeric type or 4093 /// "char *" or "const char *". 4094 ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); 4095 4096 ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, 4097 Expr *IndexExpr, 4098 ObjCMethodDecl *getterMethod, 4099 ObjCMethodDecl *setterMethod); 4100 4101 ExprResult BuildObjCDictionaryLiteral(SourceRange SR, 4102 ObjCDictionaryElement *Elements, 4103 unsigned NumElements); 4104 4105 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, 4106 TypeSourceInfo *EncodedTypeInfo, 4107 SourceLocation RParenLoc); 4108 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, 4109 CXXConversionDecl *Method, 4110 bool HadMultipleCandidates); 4111 4112 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 4113 SourceLocation EncodeLoc, 4114 SourceLocation LParenLoc, 4115 ParsedType Ty, 4116 SourceLocation RParenLoc); 4117 4118 /// ParseObjCSelectorExpression - Build selector expression for \@selector 4119 ExprResult ParseObjCSelectorExpression(Selector Sel, 4120 SourceLocation AtLoc, 4121 SourceLocation SelLoc, 4122 SourceLocation LParenLoc, 4123 SourceLocation RParenLoc); 4124 4125 /// ParseObjCProtocolExpression - Build protocol expression for \@protocol 4126 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 4127 SourceLocation AtLoc, 4128 SourceLocation ProtoLoc, 4129 SourceLocation LParenLoc, 4130 SourceLocation ProtoIdLoc, 4131 SourceLocation RParenLoc); 4132 4133 //===--------------------------------------------------------------------===// 4134 // C++ Declarations 4135 // 4136 Decl *ActOnStartLinkageSpecification(Scope *S, 4137 SourceLocation ExternLoc, 4138 SourceLocation LangLoc, 4139 StringRef Lang, 4140 SourceLocation LBraceLoc); 4141 Decl *ActOnFinishLinkageSpecification(Scope *S, 4142 Decl *LinkageSpec, 4143 SourceLocation RBraceLoc); 4144 4145 4146 //===--------------------------------------------------------------------===// 4147 // C++ Classes 4148 // 4149 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 4150 const CXXScopeSpec *SS = 0); 4151 4152 bool ActOnAccessSpecifier(AccessSpecifier Access, 4153 SourceLocation ASLoc, 4154 SourceLocation ColonLoc, 4155 AttributeList *Attrs = 0); 4156 4157 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 4158 Declarator &D, 4159 MultiTemplateParamsArg TemplateParameterLists, 4160 Expr *BitfieldWidth, const VirtSpecifiers &VS, 4161 InClassInitStyle InitStyle); 4162 void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, 4163 Expr *Init); 4164 4165 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 4166 Scope *S, 4167 CXXScopeSpec &SS, 4168 IdentifierInfo *MemberOrBase, 4169 ParsedType TemplateTypeTy, 4170 const DeclSpec &DS, 4171 SourceLocation IdLoc, 4172 SourceLocation LParenLoc, 4173 Expr **Args, unsigned NumArgs, 4174 SourceLocation RParenLoc, 4175 SourceLocation EllipsisLoc); 4176 4177 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 4178 Scope *S, 4179 CXXScopeSpec &SS, 4180 IdentifierInfo *MemberOrBase, 4181 ParsedType TemplateTypeTy, 4182 const DeclSpec &DS, 4183 SourceLocation IdLoc, 4184 Expr *InitList, 4185 SourceLocation EllipsisLoc); 4186 4187 MemInitResult BuildMemInitializer(Decl *ConstructorD, 4188 Scope *S, 4189 CXXScopeSpec &SS, 4190 IdentifierInfo *MemberOrBase, 4191 ParsedType TemplateTypeTy, 4192 const DeclSpec &DS, 4193 SourceLocation IdLoc, 4194 Expr *Init, 4195 SourceLocation EllipsisLoc); 4196 4197 MemInitResult BuildMemberInitializer(ValueDecl *Member, 4198 Expr *Init, 4199 SourceLocation IdLoc); 4200 4201 MemInitResult BuildBaseInitializer(QualType BaseType, 4202 TypeSourceInfo *BaseTInfo, 4203 Expr *Init, 4204 CXXRecordDecl *ClassDecl, 4205 SourceLocation EllipsisLoc); 4206 4207 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, 4208 Expr *Init, 4209 CXXRecordDecl *ClassDecl); 4210 4211 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, 4212 CXXCtorInitializer *Initializer); 4213 4214 bool SetCtorInitializers(CXXConstructorDecl *Constructor, 4215 CXXCtorInitializer **Initializers, 4216 unsigned NumInitializers, bool AnyErrors); 4217 4218 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 4219 4220 4221 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 4222 /// mark all the non-trivial destructors of its members and bases as 4223 /// referenced. 4224 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 4225 CXXRecordDecl *Record); 4226 4227 /// \brief The list of classes whose vtables have been used within 4228 /// this translation unit, and the source locations at which the 4229 /// first use occurred. 4230 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; 4231 4232 /// \brief The list of vtables that are required but have not yet been 4233 /// materialized. 4234 SmallVector<VTableUse, 16> VTableUses; 4235 4236 /// \brief The set of classes whose vtables have been used within 4237 /// this translation unit, and a bit that will be true if the vtable is 4238 /// required to be emitted (otherwise, it should be emitted only if needed 4239 /// by code generation). 4240 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 4241 4242 /// \brief Load any externally-stored vtable uses. 4243 void LoadExternalVTableUses(); 4244 4245 typedef LazyVector<CXXRecordDecl *, ExternalSemaSource, 4246 &ExternalSemaSource::ReadDynamicClasses, 2, 2> 4247 DynamicClassesType; 4248 4249 /// \brief A list of all of the dynamic classes in this translation 4250 /// unit. 4251 DynamicClassesType DynamicClasses; 4252 4253 /// \brief Note that the vtable for the given class was used at the 4254 /// given location. 4255 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 4256 bool DefinitionRequired = false); 4257 4258 /// MarkVirtualMembersReferenced - Will mark all members of the given 4259 /// CXXRecordDecl referenced. 4260 void MarkVirtualMembersReferenced(SourceLocation Loc, 4261 const CXXRecordDecl *RD); 4262 4263 /// \brief Define all of the vtables that have been used in this 4264 /// translation unit and reference any virtual members used by those 4265 /// vtables. 4266 /// 4267 /// \returns true if any work was done, false otherwise. 4268 bool DefineUsedVTables(); 4269 4270 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 4271 4272 void ActOnMemInitializers(Decl *ConstructorDecl, 4273 SourceLocation ColonLoc, 4274 CXXCtorInitializer **MemInits, 4275 unsigned NumMemInits, 4276 bool AnyErrors); 4277 4278 void CheckCompletedCXXClass(CXXRecordDecl *Record); 4279 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 4280 Decl *TagDecl, 4281 SourceLocation LBrac, 4282 SourceLocation RBrac, 4283 AttributeList *AttrList); 4284 void ActOnFinishCXXMemberDecls(); 4285 4286 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 4287 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 4288 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 4289 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 4290 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 4291 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 4292 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 4293 void ActOnFinishDelayedMemberInitializers(Decl *Record); 4294 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 4295 bool IsInsideALocalClassWithinATemplateFunction(); 4296 4297 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 4298 Expr *AssertExpr, 4299 Expr *AssertMessageExpr, 4300 SourceLocation RParenLoc); 4301 4302 FriendDecl *CheckFriendTypeDecl(SourceLocation Loc, 4303 SourceLocation FriendLoc, 4304 TypeSourceInfo *TSInfo); 4305 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 4306 MultiTemplateParamsArg TemplateParams); 4307 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, 4308 MultiTemplateParamsArg TemplateParams); 4309 4310 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 4311 StorageClass& SC); 4312 void CheckConstructor(CXXConstructorDecl *Constructor); 4313 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 4314 StorageClass& SC); 4315 bool CheckDestructor(CXXDestructorDecl *Destructor); 4316 void CheckConversionDeclarator(Declarator &D, QualType &R, 4317 StorageClass& SC); 4318 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 4319 4320 void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record); 4321 void CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD); 4322 4323 //===--------------------------------------------------------------------===// 4324 // C++ Derived Classes 4325 // 4326 4327 /// ActOnBaseSpecifier - Parsed a base specifier 4328 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 4329 SourceRange SpecifierRange, 4330 bool Virtual, AccessSpecifier Access, 4331 TypeSourceInfo *TInfo, 4332 SourceLocation EllipsisLoc); 4333 4334 BaseResult ActOnBaseSpecifier(Decl *classdecl, 4335 SourceRange SpecifierRange, 4336 bool Virtual, AccessSpecifier Access, 4337 ParsedType basetype, 4338 SourceLocation BaseLoc, 4339 SourceLocation EllipsisLoc); 4340 4341 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 4342 unsigned NumBases); 4343 void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases, 4344 unsigned NumBases); 4345 4346 bool IsDerivedFrom(QualType Derived, QualType Base); 4347 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 4348 4349 // FIXME: I don't like this name. 4350 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 4351 4352 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 4353 4354 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 4355 SourceLocation Loc, SourceRange Range, 4356 CXXCastPath *BasePath = 0, 4357 bool IgnoreAccess = false); 4358 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 4359 unsigned InaccessibleBaseID, 4360 unsigned AmbigiousBaseConvID, 4361 SourceLocation Loc, SourceRange Range, 4362 DeclarationName Name, 4363 CXXCastPath *BasePath); 4364 4365 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 4366 4367 /// CheckOverridingFunctionReturnType - Checks whether the return types are 4368 /// covariant, according to C++ [class.virtual]p5. 4369 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 4370 const CXXMethodDecl *Old); 4371 4372 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 4373 /// spec is a subset of base spec. 4374 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 4375 const CXXMethodDecl *Old); 4376 4377 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 4378 4379 /// CheckOverrideControl - Check C++0x override control semantics. 4380 void CheckOverrideControl(const Decl *D); 4381 4382 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 4383 /// overrides a virtual member function marked 'final', according to 4384 /// C++0x [class.virtual]p3. 4385 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 4386 const CXXMethodDecl *Old); 4387 4388 4389 //===--------------------------------------------------------------------===// 4390 // C++ Access Control 4391 // 4392 4393 enum AccessResult { 4394 AR_accessible, 4395 AR_inaccessible, 4396 AR_dependent, 4397 AR_delayed 4398 }; 4399 4400 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 4401 NamedDecl *PrevMemberDecl, 4402 AccessSpecifier LexicalAS); 4403 4404 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 4405 DeclAccessPair FoundDecl); 4406 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 4407 DeclAccessPair FoundDecl); 4408 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 4409 SourceRange PlacementRange, 4410 CXXRecordDecl *NamingClass, 4411 DeclAccessPair FoundDecl, 4412 bool Diagnose = true); 4413 AccessResult CheckConstructorAccess(SourceLocation Loc, 4414 CXXConstructorDecl *D, 4415 const InitializedEntity &Entity, 4416 AccessSpecifier Access, 4417 bool IsCopyBindingRefToTemp = false); 4418 AccessResult CheckConstructorAccess(SourceLocation Loc, 4419 CXXConstructorDecl *D, 4420 const InitializedEntity &Entity, 4421 AccessSpecifier Access, 4422 const PartialDiagnostic &PDiag); 4423 AccessResult CheckDestructorAccess(SourceLocation Loc, 4424 CXXDestructorDecl *Dtor, 4425 const PartialDiagnostic &PDiag, 4426 QualType objectType = QualType()); 4427 AccessResult CheckDirectMemberAccess(SourceLocation Loc, 4428 NamedDecl *D, 4429 const PartialDiagnostic &PDiag); 4430 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 4431 Expr *ObjectExpr, 4432 Expr *ArgExpr, 4433 DeclAccessPair FoundDecl); 4434 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 4435 DeclAccessPair FoundDecl); 4436 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 4437 QualType Base, QualType Derived, 4438 const CXXBasePath &Path, 4439 unsigned DiagID, 4440 bool ForceCheck = false, 4441 bool ForceUnprivileged = false); 4442 void CheckLookupAccess(const LookupResult &R); 4443 bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx); 4444 bool isSpecialMemberAccessibleForDeletion(CXXMethodDecl *decl, 4445 AccessSpecifier access, 4446 QualType objectType); 4447 4448 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 4449 const MultiLevelTemplateArgumentList &TemplateArgs); 4450 void PerformDependentDiagnostics(const DeclContext *Pattern, 4451 const MultiLevelTemplateArgumentList &TemplateArgs); 4452 4453 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 4454 4455 /// \brief When true, access checking violations are treated as SFINAE 4456 /// failures rather than hard errors. 4457 bool AccessCheckingSFINAE; 4458 4459 enum AbstractDiagSelID { 4460 AbstractNone = -1, 4461 AbstractReturnType, 4462 AbstractParamType, 4463 AbstractVariableType, 4464 AbstractFieldType, 4465 AbstractArrayType 4466 }; 4467 4468 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4469 TypeDiagnoser &Diagnoser); 4470 template<typename T1> 4471 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4472 unsigned DiagID, 4473 const T1 &Arg1) { 4474 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 4475 return RequireNonAbstractType(Loc, T, Diagnoser); 4476 } 4477 4478 template<typename T1, typename T2> 4479 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4480 unsigned DiagID, 4481 const T1 &Arg1, const T2 &Arg2) { 4482 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 4483 return RequireNonAbstractType(Loc, T, Diagnoser); 4484 } 4485 4486 template<typename T1, typename T2, typename T3> 4487 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4488 unsigned DiagID, 4489 const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) { 4490 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, Arg3); 4491 return RequireNonAbstractType(Loc, T, Diagnoser); 4492 } 4493 4494 void DiagnoseAbstractType(const CXXRecordDecl *RD); 4495 4496 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 4497 AbstractDiagSelID SelID = AbstractNone); 4498 4499 //===--------------------------------------------------------------------===// 4500 // C++ Overloaded Operators [C++ 13.5] 4501 // 4502 4503 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 4504 4505 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 4506 4507 //===--------------------------------------------------------------------===// 4508 // C++ Templates [C++ 14] 4509 // 4510 void FilterAcceptableTemplateNames(LookupResult &R, 4511 bool AllowFunctionTemplates = true); 4512 bool hasAnyAcceptableTemplateNames(LookupResult &R, 4513 bool AllowFunctionTemplates = true); 4514 4515 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 4516 QualType ObjectType, bool EnteringContext, 4517 bool &MemberOfUnknownSpecialization); 4518 4519 TemplateNameKind isTemplateName(Scope *S, 4520 CXXScopeSpec &SS, 4521 bool hasTemplateKeyword, 4522 UnqualifiedId &Name, 4523 ParsedType ObjectType, 4524 bool EnteringContext, 4525 TemplateTy &Template, 4526 bool &MemberOfUnknownSpecialization); 4527 4528 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 4529 SourceLocation IILoc, 4530 Scope *S, 4531 const CXXScopeSpec *SS, 4532 TemplateTy &SuggestedTemplate, 4533 TemplateNameKind &SuggestedKind); 4534 4535 void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 4536 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 4537 4538 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 4539 SourceLocation EllipsisLoc, 4540 SourceLocation KeyLoc, 4541 IdentifierInfo *ParamName, 4542 SourceLocation ParamNameLoc, 4543 unsigned Depth, unsigned Position, 4544 SourceLocation EqualLoc, 4545 ParsedType DefaultArg); 4546 4547 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 4548 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 4549 unsigned Depth, 4550 unsigned Position, 4551 SourceLocation EqualLoc, 4552 Expr *DefaultArg); 4553 Decl *ActOnTemplateTemplateParameter(Scope *S, 4554 SourceLocation TmpLoc, 4555 TemplateParameterList *Params, 4556 SourceLocation EllipsisLoc, 4557 IdentifierInfo *ParamName, 4558 SourceLocation ParamNameLoc, 4559 unsigned Depth, 4560 unsigned Position, 4561 SourceLocation EqualLoc, 4562 ParsedTemplateArgument DefaultArg); 4563 4564 TemplateParameterList * 4565 ActOnTemplateParameterList(unsigned Depth, 4566 SourceLocation ExportLoc, 4567 SourceLocation TemplateLoc, 4568 SourceLocation LAngleLoc, 4569 Decl **Params, unsigned NumParams, 4570 SourceLocation RAngleLoc); 4571 4572 /// \brief The context in which we are checking a template parameter 4573 /// list. 4574 enum TemplateParamListContext { 4575 TPC_ClassTemplate, 4576 TPC_FunctionTemplate, 4577 TPC_ClassTemplateMember, 4578 TPC_FriendFunctionTemplate, 4579 TPC_FriendFunctionTemplateDefinition, 4580 TPC_TypeAliasTemplate 4581 }; 4582 4583 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 4584 TemplateParameterList *OldParams, 4585 TemplateParamListContext TPC); 4586 TemplateParameterList * 4587 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 4588 SourceLocation DeclLoc, 4589 const CXXScopeSpec &SS, 4590 TemplateParameterList **ParamLists, 4591 unsigned NumParamLists, 4592 bool IsFriend, 4593 bool &IsExplicitSpecialization, 4594 bool &Invalid); 4595 4596 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 4597 SourceLocation KWLoc, CXXScopeSpec &SS, 4598 IdentifierInfo *Name, SourceLocation NameLoc, 4599 AttributeList *Attr, 4600 TemplateParameterList *TemplateParams, 4601 AccessSpecifier AS, 4602 SourceLocation ModulePrivateLoc, 4603 unsigned NumOuterTemplateParamLists, 4604 TemplateParameterList **OuterTemplateParamLists); 4605 4606 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 4607 TemplateArgumentListInfo &Out); 4608 4609 void NoteAllFoundTemplates(TemplateName Name); 4610 4611 QualType CheckTemplateIdType(TemplateName Template, 4612 SourceLocation TemplateLoc, 4613 TemplateArgumentListInfo &TemplateArgs); 4614 4615 TypeResult 4616 ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, 4617 TemplateTy Template, SourceLocation TemplateLoc, 4618 SourceLocation LAngleLoc, 4619 ASTTemplateArgsPtr TemplateArgs, 4620 SourceLocation RAngleLoc, 4621 bool IsCtorOrDtorName = false); 4622 4623 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 4624 /// such as \c class T::template apply<U>. 4625 /// 4626 /// \param TUK 4627 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 4628 TypeSpecifierType TagSpec, 4629 SourceLocation TagLoc, 4630 CXXScopeSpec &SS, 4631 SourceLocation TemplateKWLoc, 4632 TemplateTy TemplateD, 4633 SourceLocation TemplateLoc, 4634 SourceLocation LAngleLoc, 4635 ASTTemplateArgsPtr TemplateArgsIn, 4636 SourceLocation RAngleLoc); 4637 4638 4639 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 4640 SourceLocation TemplateKWLoc, 4641 LookupResult &R, 4642 bool RequiresADL, 4643 const TemplateArgumentListInfo *TemplateArgs); 4644 4645 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 4646 SourceLocation TemplateKWLoc, 4647 const DeclarationNameInfo &NameInfo, 4648 const TemplateArgumentListInfo *TemplateArgs); 4649 4650 TemplateNameKind ActOnDependentTemplateName(Scope *S, 4651 CXXScopeSpec &SS, 4652 SourceLocation TemplateKWLoc, 4653 UnqualifiedId &Name, 4654 ParsedType ObjectType, 4655 bool EnteringContext, 4656 TemplateTy &Template); 4657 4658 DeclResult 4659 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 4660 SourceLocation KWLoc, 4661 SourceLocation ModulePrivateLoc, 4662 CXXScopeSpec &SS, 4663 TemplateTy Template, 4664 SourceLocation TemplateNameLoc, 4665 SourceLocation LAngleLoc, 4666 ASTTemplateArgsPtr TemplateArgs, 4667 SourceLocation RAngleLoc, 4668 AttributeList *Attr, 4669 MultiTemplateParamsArg TemplateParameterLists); 4670 4671 Decl *ActOnTemplateDeclarator(Scope *S, 4672 MultiTemplateParamsArg TemplateParameterLists, 4673 Declarator &D); 4674 4675 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 4676 MultiTemplateParamsArg TemplateParameterLists, 4677 Declarator &D); 4678 4679 bool 4680 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 4681 TemplateSpecializationKind NewTSK, 4682 NamedDecl *PrevDecl, 4683 TemplateSpecializationKind PrevTSK, 4684 SourceLocation PrevPtOfInstantiation, 4685 bool &SuppressNew); 4686 4687 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 4688 const TemplateArgumentListInfo &ExplicitTemplateArgs, 4689 LookupResult &Previous); 4690 4691 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 4692 TemplateArgumentListInfo *ExplicitTemplateArgs, 4693 LookupResult &Previous); 4694 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 4695 4696 DeclResult 4697 ActOnExplicitInstantiation(Scope *S, 4698 SourceLocation ExternLoc, 4699 SourceLocation TemplateLoc, 4700 unsigned TagSpec, 4701 SourceLocation KWLoc, 4702 const CXXScopeSpec &SS, 4703 TemplateTy Template, 4704 SourceLocation TemplateNameLoc, 4705 SourceLocation LAngleLoc, 4706 ASTTemplateArgsPtr TemplateArgs, 4707 SourceLocation RAngleLoc, 4708 AttributeList *Attr); 4709 4710 DeclResult 4711 ActOnExplicitInstantiation(Scope *S, 4712 SourceLocation ExternLoc, 4713 SourceLocation TemplateLoc, 4714 unsigned TagSpec, 4715 SourceLocation KWLoc, 4716 CXXScopeSpec &SS, 4717 IdentifierInfo *Name, 4718 SourceLocation NameLoc, 4719 AttributeList *Attr); 4720 4721 DeclResult ActOnExplicitInstantiation(Scope *S, 4722 SourceLocation ExternLoc, 4723 SourceLocation TemplateLoc, 4724 Declarator &D); 4725 4726 TemplateArgumentLoc 4727 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 4728 SourceLocation TemplateLoc, 4729 SourceLocation RAngleLoc, 4730 Decl *Param, 4731 SmallVectorImpl<TemplateArgument> &Converted); 4732 4733 /// \brief Specifies the context in which a particular template 4734 /// argument is being checked. 4735 enum CheckTemplateArgumentKind { 4736 /// \brief The template argument was specified in the code or was 4737 /// instantiated with some deduced template arguments. 4738 CTAK_Specified, 4739 4740 /// \brief The template argument was deduced via template argument 4741 /// deduction. 4742 CTAK_Deduced, 4743 4744 /// \brief The template argument was deduced from an array bound 4745 /// via template argument deduction. 4746 CTAK_DeducedFromArrayBound 4747 }; 4748 4749 bool CheckTemplateArgument(NamedDecl *Param, 4750 const TemplateArgumentLoc &Arg, 4751 NamedDecl *Template, 4752 SourceLocation TemplateLoc, 4753 SourceLocation RAngleLoc, 4754 unsigned ArgumentPackIndex, 4755 SmallVectorImpl<TemplateArgument> &Converted, 4756 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4757 4758 /// \brief Check that the given template arguments can be be provided to 4759 /// the given template, converting the arguments along the way. 4760 /// 4761 /// \param Template The template to which the template arguments are being 4762 /// provided. 4763 /// 4764 /// \param TemplateLoc The location of the template name in the source. 4765 /// 4766 /// \param TemplateArgs The list of template arguments. If the template is 4767 /// a template template parameter, this function may extend the set of 4768 /// template arguments to also include substituted, defaulted template 4769 /// arguments. 4770 /// 4771 /// \param PartialTemplateArgs True if the list of template arguments is 4772 /// intentionally partial, e.g., because we're checking just the initial 4773 /// set of template arguments. 4774 /// 4775 /// \param Converted Will receive the converted, canonicalized template 4776 /// arguments. 4777 /// 4778 /// 4779 /// \param ExpansionIntoFixedList If non-NULL, will be set true to indicate 4780 /// when the template arguments contain a pack expansion that is being 4781 /// expanded into a fixed parameter list. 4782 /// 4783 /// \returns True if an error occurred, false otherwise. 4784 bool CheckTemplateArgumentList(TemplateDecl *Template, 4785 SourceLocation TemplateLoc, 4786 TemplateArgumentListInfo &TemplateArgs, 4787 bool PartialTemplateArgs, 4788 SmallVectorImpl<TemplateArgument> &Converted, 4789 bool *ExpansionIntoFixedList = 0); 4790 4791 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 4792 const TemplateArgumentLoc &Arg, 4793 SmallVectorImpl<TemplateArgument> &Converted); 4794 4795 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 4796 TypeSourceInfo *Arg); 4797 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 4798 QualType InstantiatedParamType, Expr *Arg, 4799 TemplateArgument &Converted, 4800 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4801 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 4802 const TemplateArgumentLoc &Arg); 4803 4804 ExprResult 4805 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 4806 QualType ParamType, 4807 SourceLocation Loc); 4808 ExprResult 4809 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 4810 SourceLocation Loc); 4811 4812 /// \brief Enumeration describing how template parameter lists are compared 4813 /// for equality. 4814 enum TemplateParameterListEqualKind { 4815 /// \brief We are matching the template parameter lists of two templates 4816 /// that might be redeclarations. 4817 /// 4818 /// \code 4819 /// template<typename T> struct X; 4820 /// template<typename T> struct X; 4821 /// \endcode 4822 TPL_TemplateMatch, 4823 4824 /// \brief We are matching the template parameter lists of two template 4825 /// template parameters as part of matching the template parameter lists 4826 /// of two templates that might be redeclarations. 4827 /// 4828 /// \code 4829 /// template<template<int I> class TT> struct X; 4830 /// template<template<int Value> class Other> struct X; 4831 /// \endcode 4832 TPL_TemplateTemplateParmMatch, 4833 4834 /// \brief We are matching the template parameter lists of a template 4835 /// template argument against the template parameter lists of a template 4836 /// template parameter. 4837 /// 4838 /// \code 4839 /// template<template<int Value> class Metafun> struct X; 4840 /// template<int Value> struct integer_c; 4841 /// X<integer_c> xic; 4842 /// \endcode 4843 TPL_TemplateTemplateArgumentMatch 4844 }; 4845 4846 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 4847 TemplateParameterList *Old, 4848 bool Complain, 4849 TemplateParameterListEqualKind Kind, 4850 SourceLocation TemplateArgLoc 4851 = SourceLocation()); 4852 4853 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 4854 4855 /// \brief Called when the parser has parsed a C++ typename 4856 /// specifier, e.g., "typename T::type". 4857 /// 4858 /// \param S The scope in which this typename type occurs. 4859 /// \param TypenameLoc the location of the 'typename' keyword 4860 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 4861 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 4862 /// \param IdLoc the location of the identifier. 4863 TypeResult 4864 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 4865 const CXXScopeSpec &SS, const IdentifierInfo &II, 4866 SourceLocation IdLoc); 4867 4868 /// \brief Called when the parser has parsed a C++ typename 4869 /// specifier that ends in a template-id, e.g., 4870 /// "typename MetaFun::template apply<T1, T2>". 4871 /// 4872 /// \param S The scope in which this typename type occurs. 4873 /// \param TypenameLoc the location of the 'typename' keyword 4874 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 4875 /// \param TemplateLoc the location of the 'template' keyword, if any. 4876 /// \param TemplateName The template name. 4877 /// \param TemplateNameLoc The location of the template name. 4878 /// \param LAngleLoc The location of the opening angle bracket ('<'). 4879 /// \param TemplateArgs The template arguments. 4880 /// \param RAngleLoc The location of the closing angle bracket ('>'). 4881 TypeResult 4882 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 4883 const CXXScopeSpec &SS, 4884 SourceLocation TemplateLoc, 4885 TemplateTy TemplateName, 4886 SourceLocation TemplateNameLoc, 4887 SourceLocation LAngleLoc, 4888 ASTTemplateArgsPtr TemplateArgs, 4889 SourceLocation RAngleLoc); 4890 4891 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 4892 SourceLocation KeywordLoc, 4893 NestedNameSpecifierLoc QualifierLoc, 4894 const IdentifierInfo &II, 4895 SourceLocation IILoc); 4896 4897 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 4898 SourceLocation Loc, 4899 DeclarationName Name); 4900 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 4901 4902 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 4903 bool RebuildTemplateParamsInCurrentInstantiation( 4904 TemplateParameterList *Params); 4905 4906 std::string 4907 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 4908 const TemplateArgumentList &Args); 4909 4910 std::string 4911 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 4912 const TemplateArgument *Args, 4913 unsigned NumArgs); 4914 4915 //===--------------------------------------------------------------------===// 4916 // C++ Variadic Templates (C++0x [temp.variadic]) 4917 //===--------------------------------------------------------------------===// 4918 4919 /// \brief The context in which an unexpanded parameter pack is 4920 /// being diagnosed. 4921 /// 4922 /// Note that the values of this enumeration line up with the first 4923 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 4924 enum UnexpandedParameterPackContext { 4925 /// \brief An arbitrary expression. 4926 UPPC_Expression = 0, 4927 4928 /// \brief The base type of a class type. 4929 UPPC_BaseType, 4930 4931 /// \brief The type of an arbitrary declaration. 4932 UPPC_DeclarationType, 4933 4934 /// \brief The type of a data member. 4935 UPPC_DataMemberType, 4936 4937 /// \brief The size of a bit-field. 4938 UPPC_BitFieldWidth, 4939 4940 /// \brief The expression in a static assertion. 4941 UPPC_StaticAssertExpression, 4942 4943 /// \brief The fixed underlying type of an enumeration. 4944 UPPC_FixedUnderlyingType, 4945 4946 /// \brief The enumerator value. 4947 UPPC_EnumeratorValue, 4948 4949 /// \brief A using declaration. 4950 UPPC_UsingDeclaration, 4951 4952 /// \brief A friend declaration. 4953 UPPC_FriendDeclaration, 4954 4955 /// \brief A declaration qualifier. 4956 UPPC_DeclarationQualifier, 4957 4958 /// \brief An initializer. 4959 UPPC_Initializer, 4960 4961 /// \brief A default argument. 4962 UPPC_DefaultArgument, 4963 4964 /// \brief The type of a non-type template parameter. 4965 UPPC_NonTypeTemplateParameterType, 4966 4967 /// \brief The type of an exception. 4968 UPPC_ExceptionType, 4969 4970 /// \brief Partial specialization. 4971 UPPC_PartialSpecialization, 4972 4973 /// \brief Microsoft __if_exists. 4974 UPPC_IfExists, 4975 4976 /// \brief Microsoft __if_not_exists. 4977 UPPC_IfNotExists, 4978 4979 /// \brief Lambda expression. 4980 UPPC_Lambda, 4981 4982 /// \brief Block expression, 4983 UPPC_Block 4984}; 4985 4986 /// \brief Diagnose unexpanded parameter packs. 4987 /// 4988 /// \param Loc The location at which we should emit the diagnostic. 4989 /// 4990 /// \param UPPC The context in which we are diagnosing unexpanded 4991 /// parameter packs. 4992 /// 4993 /// \param Unexpanded the set of unexpanded parameter packs. 4994 void DiagnoseUnexpandedParameterPacks(SourceLocation Loc, 4995 UnexpandedParameterPackContext UPPC, 4996 ArrayRef<UnexpandedParameterPack> Unexpanded); 4997 4998 /// \brief If the given type contains an unexpanded parameter pack, 4999 /// diagnose the error. 5000 /// 5001 /// \param Loc The source location where a diagnostc should be emitted. 5002 /// 5003 /// \param T The type that is being checked for unexpanded parameter 5004 /// packs. 5005 /// 5006 /// \returns true if an error occurred, false otherwise. 5007 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 5008 UnexpandedParameterPackContext UPPC); 5009 5010 /// \brief If the given expression contains an unexpanded parameter 5011 /// pack, diagnose the error. 5012 /// 5013 /// \param E The expression that is being checked for unexpanded 5014 /// parameter packs. 5015 /// 5016 /// \returns true if an error occurred, false otherwise. 5017 bool DiagnoseUnexpandedParameterPack(Expr *E, 5018 UnexpandedParameterPackContext UPPC = UPPC_Expression); 5019 5020 /// \brief If the given nested-name-specifier contains an unexpanded 5021 /// parameter pack, diagnose the error. 5022 /// 5023 /// \param SS The nested-name-specifier that is being checked for 5024 /// unexpanded parameter packs. 5025 /// 5026 /// \returns true if an error occurred, false otherwise. 5027 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 5028 UnexpandedParameterPackContext UPPC); 5029 5030 /// \brief If the given name contains an unexpanded parameter pack, 5031 /// diagnose the error. 5032 /// 5033 /// \param NameInfo The name (with source location information) that 5034 /// is being checked for unexpanded parameter packs. 5035 /// 5036 /// \returns true if an error occurred, false otherwise. 5037 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 5038 UnexpandedParameterPackContext UPPC); 5039 5040 /// \brief If the given template name contains an unexpanded parameter pack, 5041 /// diagnose the error. 5042 /// 5043 /// \param Loc The location of the template name. 5044 /// 5045 /// \param Template The template name that is being checked for unexpanded 5046 /// parameter packs. 5047 /// 5048 /// \returns true if an error occurred, false otherwise. 5049 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 5050 TemplateName Template, 5051 UnexpandedParameterPackContext UPPC); 5052 5053 /// \brief If the given template argument contains an unexpanded parameter 5054 /// pack, diagnose the error. 5055 /// 5056 /// \param Arg The template argument that is being checked for unexpanded 5057 /// parameter packs. 5058 /// 5059 /// \returns true if an error occurred, false otherwise. 5060 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 5061 UnexpandedParameterPackContext UPPC); 5062 5063 /// \brief Collect the set of unexpanded parameter packs within the given 5064 /// template argument. 5065 /// 5066 /// \param Arg The template argument that will be traversed to find 5067 /// unexpanded parameter packs. 5068 void collectUnexpandedParameterPacks(TemplateArgument Arg, 5069 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5070 5071 /// \brief Collect the set of unexpanded parameter packs within the given 5072 /// template argument. 5073 /// 5074 /// \param Arg The template argument that will be traversed to find 5075 /// unexpanded parameter packs. 5076 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 5077 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5078 5079 /// \brief Collect the set of unexpanded parameter packs within the given 5080 /// type. 5081 /// 5082 /// \param T The type that will be traversed to find 5083 /// unexpanded parameter packs. 5084 void collectUnexpandedParameterPacks(QualType T, 5085 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5086 5087 /// \brief Collect the set of unexpanded parameter packs within the given 5088 /// type. 5089 /// 5090 /// \param TL The type that will be traversed to find 5091 /// unexpanded parameter packs. 5092 void collectUnexpandedParameterPacks(TypeLoc TL, 5093 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5094 5095 /// \brief Collect the set of unexpanded parameter packs within the given 5096 /// nested-name-specifier. 5097 /// 5098 /// \param SS The nested-name-specifier that will be traversed to find 5099 /// unexpanded parameter packs. 5100 void collectUnexpandedParameterPacks(CXXScopeSpec &SS, 5101 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5102 5103 /// \brief Collect the set of unexpanded parameter packs within the given 5104 /// name. 5105 /// 5106 /// \param NameInfo The name that will be traversed to find 5107 /// unexpanded parameter packs. 5108 void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, 5109 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5110 5111 /// \brief Invoked when parsing a template argument followed by an 5112 /// ellipsis, which creates a pack expansion. 5113 /// 5114 /// \param Arg The template argument preceding the ellipsis, which 5115 /// may already be invalid. 5116 /// 5117 /// \param EllipsisLoc The location of the ellipsis. 5118 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 5119 SourceLocation EllipsisLoc); 5120 5121 /// \brief Invoked when parsing a type followed by an ellipsis, which 5122 /// creates a pack expansion. 5123 /// 5124 /// \param Type The type preceding the ellipsis, which will become 5125 /// the pattern of the pack expansion. 5126 /// 5127 /// \param EllipsisLoc The location of the ellipsis. 5128 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 5129 5130 /// \brief Construct a pack expansion type from the pattern of the pack 5131 /// expansion. 5132 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 5133 SourceLocation EllipsisLoc, 5134 llvm::Optional<unsigned> NumExpansions); 5135 5136 /// \brief Construct a pack expansion type from the pattern of the pack 5137 /// expansion. 5138 QualType CheckPackExpansion(QualType Pattern, 5139 SourceRange PatternRange, 5140 SourceLocation EllipsisLoc, 5141 llvm::Optional<unsigned> NumExpansions); 5142 5143 /// \brief Invoked when parsing an expression followed by an ellipsis, which 5144 /// creates a pack expansion. 5145 /// 5146 /// \param Pattern The expression preceding the ellipsis, which will become 5147 /// the pattern of the pack expansion. 5148 /// 5149 /// \param EllipsisLoc The location of the ellipsis. 5150 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 5151 5152 /// \brief Invoked when parsing an expression followed by an ellipsis, which 5153 /// creates a pack expansion. 5154 /// 5155 /// \param Pattern The expression preceding the ellipsis, which will become 5156 /// the pattern of the pack expansion. 5157 /// 5158 /// \param EllipsisLoc The location of the ellipsis. 5159 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 5160 llvm::Optional<unsigned> NumExpansions); 5161 5162 /// \brief Determine whether we could expand a pack expansion with the 5163 /// given set of parameter packs into separate arguments by repeatedly 5164 /// transforming the pattern. 5165 /// 5166 /// \param EllipsisLoc The location of the ellipsis that identifies the 5167 /// pack expansion. 5168 /// 5169 /// \param PatternRange The source range that covers the entire pattern of 5170 /// the pack expansion. 5171 /// 5172 /// \param Unexpanded The set of unexpanded parameter packs within the 5173 /// pattern. 5174 /// 5175 /// \param ShouldExpand Will be set to \c true if the transformer should 5176 /// expand the corresponding pack expansions into separate arguments. When 5177 /// set, \c NumExpansions must also be set. 5178 /// 5179 /// \param RetainExpansion Whether the caller should add an unexpanded 5180 /// pack expansion after all of the expanded arguments. This is used 5181 /// when extending explicitly-specified template argument packs per 5182 /// C++0x [temp.arg.explicit]p9. 5183 /// 5184 /// \param NumExpansions The number of separate arguments that will be in 5185 /// the expanded form of the corresponding pack expansion. This is both an 5186 /// input and an output parameter, which can be set by the caller if the 5187 /// number of expansions is known a priori (e.g., due to a prior substitution) 5188 /// and will be set by the callee when the number of expansions is known. 5189 /// The callee must set this value when \c ShouldExpand is \c true; it may 5190 /// set this value in other cases. 5191 /// 5192 /// \returns true if an error occurred (e.g., because the parameter packs 5193 /// are to be instantiated with arguments of different lengths), false 5194 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 5195 /// must be set. 5196 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 5197 SourceRange PatternRange, 5198 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, 5199 const MultiLevelTemplateArgumentList &TemplateArgs, 5200 bool &ShouldExpand, 5201 bool &RetainExpansion, 5202 llvm::Optional<unsigned> &NumExpansions); 5203 5204 /// \brief Determine the number of arguments in the given pack expansion 5205 /// type. 5206 /// 5207 /// This routine already assumes that the pack expansion type can be 5208 /// expanded and that the number of arguments in the expansion is 5209 /// consistent across all of the unexpanded parameter packs in its pattern. 5210 unsigned getNumArgumentsInExpansion(QualType T, 5211 const MultiLevelTemplateArgumentList &TemplateArgs); 5212 5213 /// \brief Determine whether the given declarator contains any unexpanded 5214 /// parameter packs. 5215 /// 5216 /// This routine is used by the parser to disambiguate function declarators 5217 /// with an ellipsis prior to the ')', e.g., 5218 /// 5219 /// \code 5220 /// void f(T...); 5221 /// \endcode 5222 /// 5223 /// To determine whether we have an (unnamed) function parameter pack or 5224 /// a variadic function. 5225 /// 5226 /// \returns true if the declarator contains any unexpanded parameter packs, 5227 /// false otherwise. 5228 bool containsUnexpandedParameterPacks(Declarator &D); 5229 5230 //===--------------------------------------------------------------------===// 5231 // C++ Template Argument Deduction (C++ [temp.deduct]) 5232 //===--------------------------------------------------------------------===// 5233 5234 /// \brief Describes the result of template argument deduction. 5235 /// 5236 /// The TemplateDeductionResult enumeration describes the result of 5237 /// template argument deduction, as returned from 5238 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 5239 /// structure provides additional information about the results of 5240 /// template argument deduction, e.g., the deduced template argument 5241 /// list (if successful) or the specific template parameters or 5242 /// deduced arguments that were involved in the failure. 5243 enum TemplateDeductionResult { 5244 /// \brief Template argument deduction was successful. 5245 TDK_Success = 0, 5246 /// \brief Template argument deduction exceeded the maximum template 5247 /// instantiation depth (which has already been diagnosed). 5248 TDK_InstantiationDepth, 5249 /// \brief Template argument deduction did not deduce a value 5250 /// for every template parameter. 5251 TDK_Incomplete, 5252 /// \brief Template argument deduction produced inconsistent 5253 /// deduced values for the given template parameter. 5254 TDK_Inconsistent, 5255 /// \brief Template argument deduction failed due to inconsistent 5256 /// cv-qualifiers on a template parameter type that would 5257 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 5258 /// but were given a non-const "X". 5259 TDK_Underqualified, 5260 /// \brief Substitution of the deduced template argument values 5261 /// resulted in an error. 5262 TDK_SubstitutionFailure, 5263 /// \brief Substitution of the deduced template argument values 5264 /// into a non-deduced context produced a type or value that 5265 /// produces a type that does not match the original template 5266 /// arguments provided. 5267 TDK_NonDeducedMismatch, 5268 /// \brief When performing template argument deduction for a function 5269 /// template, there were too many call arguments. 5270 TDK_TooManyArguments, 5271 /// \brief When performing template argument deduction for a function 5272 /// template, there were too few call arguments. 5273 TDK_TooFewArguments, 5274 /// \brief The explicitly-specified template arguments were not valid 5275 /// template arguments for the given template. 5276 TDK_InvalidExplicitArguments, 5277 /// \brief The arguments included an overloaded function name that could 5278 /// not be resolved to a suitable function. 5279 TDK_FailedOverloadResolution 5280 }; 5281 5282 TemplateDeductionResult 5283 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 5284 const TemplateArgumentList &TemplateArgs, 5285 sema::TemplateDeductionInfo &Info); 5286 5287 TemplateDeductionResult 5288 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5289 TemplateArgumentListInfo &ExplicitTemplateArgs, 5290 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 5291 SmallVectorImpl<QualType> &ParamTypes, 5292 QualType *FunctionType, 5293 sema::TemplateDeductionInfo &Info); 5294 5295 /// brief A function argument from which we performed template argument 5296 // deduction for a call. 5297 struct OriginalCallArg { 5298 OriginalCallArg(QualType OriginalParamType, 5299 unsigned ArgIdx, 5300 QualType OriginalArgType) 5301 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx), 5302 OriginalArgType(OriginalArgType) { } 5303 5304 QualType OriginalParamType; 5305 unsigned ArgIdx; 5306 QualType OriginalArgType; 5307 }; 5308 5309 TemplateDeductionResult 5310 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 5311 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 5312 unsigned NumExplicitlySpecified, 5313 FunctionDecl *&Specialization, 5314 sema::TemplateDeductionInfo &Info, 5315 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0); 5316 5317 TemplateDeductionResult 5318 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5319 TemplateArgumentListInfo *ExplicitTemplateArgs, 5320 llvm::ArrayRef<Expr *> Args, 5321 FunctionDecl *&Specialization, 5322 sema::TemplateDeductionInfo &Info); 5323 5324 TemplateDeductionResult 5325 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5326 TemplateArgumentListInfo *ExplicitTemplateArgs, 5327 QualType ArgFunctionType, 5328 FunctionDecl *&Specialization, 5329 sema::TemplateDeductionInfo &Info); 5330 5331 TemplateDeductionResult 5332 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5333 QualType ToType, 5334 CXXConversionDecl *&Specialization, 5335 sema::TemplateDeductionInfo &Info); 5336 5337 TemplateDeductionResult 5338 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5339 TemplateArgumentListInfo *ExplicitTemplateArgs, 5340 FunctionDecl *&Specialization, 5341 sema::TemplateDeductionInfo &Info); 5342 5343 /// \brief Result type of DeduceAutoType. 5344 enum DeduceAutoResult { 5345 DAR_Succeeded, 5346 DAR_Failed, 5347 DAR_FailedAlreadyDiagnosed 5348 }; 5349 5350 DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, 5351 TypeSourceInfo *&Result); 5352 void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); 5353 5354 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 5355 FunctionTemplateDecl *FT2, 5356 SourceLocation Loc, 5357 TemplatePartialOrderingContext TPOC, 5358 unsigned NumCallArguments); 5359 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 5360 UnresolvedSetIterator SEnd, 5361 TemplatePartialOrderingContext TPOC, 5362 unsigned NumCallArguments, 5363 SourceLocation Loc, 5364 const PartialDiagnostic &NoneDiag, 5365 const PartialDiagnostic &AmbigDiag, 5366 const PartialDiagnostic &CandidateDiag, 5367 bool Complain = true, 5368 QualType TargetType = QualType()); 5369 5370 ClassTemplatePartialSpecializationDecl * 5371 getMoreSpecializedPartialSpecialization( 5372 ClassTemplatePartialSpecializationDecl *PS1, 5373 ClassTemplatePartialSpecializationDecl *PS2, 5374 SourceLocation Loc); 5375 5376 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 5377 bool OnlyDeduced, 5378 unsigned Depth, 5379 llvm::SmallBitVector &Used); 5380 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 5381 llvm::SmallBitVector &Deduced) { 5382 return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); 5383 } 5384 static void MarkDeducedTemplateParameters(ASTContext &Ctx, 5385 FunctionTemplateDecl *FunctionTemplate, 5386 llvm::SmallBitVector &Deduced); 5387 5388 //===--------------------------------------------------------------------===// 5389 // C++ Template Instantiation 5390 // 5391 5392 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 5393 const TemplateArgumentList *Innermost = 0, 5394 bool RelativeToPrimary = false, 5395 const FunctionDecl *Pattern = 0); 5396 5397 /// \brief A template instantiation that is currently in progress. 5398 struct ActiveTemplateInstantiation { 5399 /// \brief The kind of template instantiation we are performing 5400 enum InstantiationKind { 5401 /// We are instantiating a template declaration. The entity is 5402 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 5403 TemplateInstantiation, 5404 5405 /// We are instantiating a default argument for a template 5406 /// parameter. The Entity is the template, and 5407 /// TemplateArgs/NumTemplateArguments provides the template 5408 /// arguments as specified. 5409 /// FIXME: Use a TemplateArgumentList 5410 DefaultTemplateArgumentInstantiation, 5411 5412 /// We are instantiating a default argument for a function. 5413 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 5414 /// provides the template arguments as specified. 5415 DefaultFunctionArgumentInstantiation, 5416 5417 /// We are substituting explicit template arguments provided for 5418 /// a function template. The entity is a FunctionTemplateDecl. 5419 ExplicitTemplateArgumentSubstitution, 5420 5421 /// We are substituting template argument determined as part of 5422 /// template argument deduction for either a class template 5423 /// partial specialization or a function template. The 5424 /// Entity is either a ClassTemplatePartialSpecializationDecl or 5425 /// a FunctionTemplateDecl. 5426 DeducedTemplateArgumentSubstitution, 5427 5428 /// We are substituting prior template arguments into a new 5429 /// template parameter. The template parameter itself is either a 5430 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 5431 PriorTemplateArgumentSubstitution, 5432 5433 /// We are checking the validity of a default template argument that 5434 /// has been used when naming a template-id. 5435 DefaultTemplateArgumentChecking, 5436 5437 /// We are instantiating the exception specification for a function 5438 /// template which was deferred until it was needed. 5439 ExceptionSpecInstantiation 5440 } Kind; 5441 5442 /// \brief The point of instantiation within the source code. 5443 SourceLocation PointOfInstantiation; 5444 5445 /// \brief The template (or partial specialization) in which we are 5446 /// performing the instantiation, for substitutions of prior template 5447 /// arguments. 5448 NamedDecl *Template; 5449 5450 /// \brief The entity that is being instantiated. 5451 uintptr_t Entity; 5452 5453 /// \brief The list of template arguments we are substituting, if they 5454 /// are not part of the entity. 5455 const TemplateArgument *TemplateArgs; 5456 5457 /// \brief The number of template arguments in TemplateArgs. 5458 unsigned NumTemplateArgs; 5459 5460 /// \brief The template deduction info object associated with the 5461 /// substitution or checking of explicit or deduced template arguments. 5462 sema::TemplateDeductionInfo *DeductionInfo; 5463 5464 /// \brief The source range that covers the construct that cause 5465 /// the instantiation, e.g., the template-id that causes a class 5466 /// template instantiation. 5467 SourceRange InstantiationRange; 5468 5469 ActiveTemplateInstantiation() 5470 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 5471 NumTemplateArgs(0), DeductionInfo(0) {} 5472 5473 /// \brief Determines whether this template is an actual instantiation 5474 /// that should be counted toward the maximum instantiation depth. 5475 bool isInstantiationRecord() const; 5476 5477 friend bool operator==(const ActiveTemplateInstantiation &X, 5478 const ActiveTemplateInstantiation &Y) { 5479 if (X.Kind != Y.Kind) 5480 return false; 5481 5482 if (X.Entity != Y.Entity) 5483 return false; 5484 5485 switch (X.Kind) { 5486 case TemplateInstantiation: 5487 case ExceptionSpecInstantiation: 5488 return true; 5489 5490 case PriorTemplateArgumentSubstitution: 5491 case DefaultTemplateArgumentChecking: 5492 if (X.Template != Y.Template) 5493 return false; 5494 5495 // Fall through 5496 5497 case DefaultTemplateArgumentInstantiation: 5498 case ExplicitTemplateArgumentSubstitution: 5499 case DeducedTemplateArgumentSubstitution: 5500 case DefaultFunctionArgumentInstantiation: 5501 return X.TemplateArgs == Y.TemplateArgs; 5502 5503 } 5504 5505 llvm_unreachable("Invalid InstantiationKind!"); 5506 } 5507 5508 friend bool operator!=(const ActiveTemplateInstantiation &X, 5509 const ActiveTemplateInstantiation &Y) { 5510 return !(X == Y); 5511 } 5512 }; 5513 5514 /// \brief List of active template instantiations. 5515 /// 5516 /// This vector is treated as a stack. As one template instantiation 5517 /// requires another template instantiation, additional 5518 /// instantiations are pushed onto the stack up to a 5519 /// user-configurable limit LangOptions::InstantiationDepth. 5520 SmallVector<ActiveTemplateInstantiation, 16> 5521 ActiveTemplateInstantiations; 5522 5523 /// \brief Whether we are in a SFINAE context that is not associated with 5524 /// template instantiation. 5525 /// 5526 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 5527 /// of a template instantiation or template argument deduction. 5528 bool InNonInstantiationSFINAEContext; 5529 5530 /// \brief The number of ActiveTemplateInstantiation entries in 5531 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 5532 /// therefore, should not be counted as part of the instantiation depth. 5533 unsigned NonInstantiationEntries; 5534 5535 /// \brief The last template from which a template instantiation 5536 /// error or warning was produced. 5537 /// 5538 /// This value is used to suppress printing of redundant template 5539 /// instantiation backtraces when there are multiple errors in the 5540 /// same instantiation. FIXME: Does this belong in Sema? It's tough 5541 /// to implement it anywhere else. 5542 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 5543 5544 /// \brief The current index into pack expansion arguments that will be 5545 /// used for substitution of parameter packs. 5546 /// 5547 /// The pack expansion index will be -1 to indicate that parameter packs 5548 /// should be instantiated as themselves. Otherwise, the index specifies 5549 /// which argument within the parameter pack will be used for substitution. 5550 int ArgumentPackSubstitutionIndex; 5551 5552 /// \brief RAII object used to change the argument pack substitution index 5553 /// within a \c Sema object. 5554 /// 5555 /// See \c ArgumentPackSubstitutionIndex for more information. 5556 class ArgumentPackSubstitutionIndexRAII { 5557 Sema &Self; 5558 int OldSubstitutionIndex; 5559 5560 public: 5561 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 5562 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 5563 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 5564 } 5565 5566 ~ArgumentPackSubstitutionIndexRAII() { 5567 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 5568 } 5569 }; 5570 5571 friend class ArgumentPackSubstitutionRAII; 5572 5573 /// \brief The stack of calls expression undergoing template instantiation. 5574 /// 5575 /// The top of this stack is used by a fixit instantiating unresolved 5576 /// function calls to fix the AST to match the textual change it prints. 5577 SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 5578 5579 /// \brief For each declaration that involved template argument deduction, the 5580 /// set of diagnostics that were suppressed during that template argument 5581 /// deduction. 5582 /// 5583 /// FIXME: Serialize this structure to the AST file. 5584 llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > 5585 SuppressedDiagnostics; 5586 5587 /// \brief A stack object to be created when performing template 5588 /// instantiation. 5589 /// 5590 /// Construction of an object of type \c InstantiatingTemplate 5591 /// pushes the current instantiation onto the stack of active 5592 /// instantiations. If the size of this stack exceeds the maximum 5593 /// number of recursive template instantiations, construction 5594 /// produces an error and evaluates true. 5595 /// 5596 /// Destruction of this object will pop the named instantiation off 5597 /// the stack. 5598 struct InstantiatingTemplate { 5599 /// \brief Note that we are instantiating a class template, 5600 /// function template, or a member thereof. 5601 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5602 Decl *Entity, 5603 SourceRange InstantiationRange = SourceRange()); 5604 5605 struct ExceptionSpecification {}; 5606 /// \brief Note that we are instantiating an exception specification 5607 /// of a function template. 5608 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5609 FunctionDecl *Entity, ExceptionSpecification, 5610 SourceRange InstantiationRange = SourceRange()); 5611 5612 /// \brief Note that we are instantiating a default argument in a 5613 /// template-id. 5614 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5615 TemplateDecl *Template, 5616 const TemplateArgument *TemplateArgs, 5617 unsigned NumTemplateArgs, 5618 SourceRange InstantiationRange = SourceRange()); 5619 5620 /// \brief Note that we are instantiating a default argument in a 5621 /// template-id. 5622 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5623 FunctionTemplateDecl *FunctionTemplate, 5624 const TemplateArgument *TemplateArgs, 5625 unsigned NumTemplateArgs, 5626 ActiveTemplateInstantiation::InstantiationKind Kind, 5627 sema::TemplateDeductionInfo &DeductionInfo, 5628 SourceRange InstantiationRange = SourceRange()); 5629 5630 /// \brief Note that we are instantiating as part of template 5631 /// argument deduction for a class template partial 5632 /// specialization. 5633 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5634 ClassTemplatePartialSpecializationDecl *PartialSpec, 5635 const TemplateArgument *TemplateArgs, 5636 unsigned NumTemplateArgs, 5637 sema::TemplateDeductionInfo &DeductionInfo, 5638 SourceRange InstantiationRange = SourceRange()); 5639 5640 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5641 ParmVarDecl *Param, 5642 const TemplateArgument *TemplateArgs, 5643 unsigned NumTemplateArgs, 5644 SourceRange InstantiationRange = SourceRange()); 5645 5646 /// \brief Note that we are substituting prior template arguments into a 5647 /// non-type or template template parameter. 5648 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5649 NamedDecl *Template, 5650 NonTypeTemplateParmDecl *Param, 5651 const TemplateArgument *TemplateArgs, 5652 unsigned NumTemplateArgs, 5653 SourceRange InstantiationRange); 5654 5655 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5656 NamedDecl *Template, 5657 TemplateTemplateParmDecl *Param, 5658 const TemplateArgument *TemplateArgs, 5659 unsigned NumTemplateArgs, 5660 SourceRange InstantiationRange); 5661 5662 /// \brief Note that we are checking the default template argument 5663 /// against the template parameter for a given template-id. 5664 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5665 TemplateDecl *Template, 5666 NamedDecl *Param, 5667 const TemplateArgument *TemplateArgs, 5668 unsigned NumTemplateArgs, 5669 SourceRange InstantiationRange); 5670 5671 5672 /// \brief Note that we have finished instantiating this template. 5673 void Clear(); 5674 5675 ~InstantiatingTemplate() { Clear(); } 5676 5677 /// \brief Determines whether we have exceeded the maximum 5678 /// recursive template instantiations. 5679 operator bool() const { return Invalid; } 5680 5681 private: 5682 Sema &SemaRef; 5683 bool Invalid; 5684 bool SavedInNonInstantiationSFINAEContext; 5685 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 5686 SourceRange InstantiationRange); 5687 5688 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented 5689 5690 InstantiatingTemplate& 5691 operator=(const InstantiatingTemplate&); // not implemented 5692 }; 5693 5694 void PrintInstantiationStack(); 5695 5696 /// \brief Determines whether we are currently in a context where 5697 /// template argument substitution failures are not considered 5698 /// errors. 5699 /// 5700 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 5701 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 5702 /// template-deduction context object, which can be used to capture 5703 /// diagnostics that will be suppressed. 5704 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 5705 5706 /// \brief RAII class used to determine whether SFINAE has 5707 /// trapped any errors that occur during template argument 5708 /// deduction.` 5709 class SFINAETrap { 5710 Sema &SemaRef; 5711 unsigned PrevSFINAEErrors; 5712 bool PrevInNonInstantiationSFINAEContext; 5713 bool PrevAccessCheckingSFINAE; 5714 5715 public: 5716 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 5717 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 5718 PrevInNonInstantiationSFINAEContext( 5719 SemaRef.InNonInstantiationSFINAEContext), 5720 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 5721 { 5722 if (!SemaRef.isSFINAEContext()) 5723 SemaRef.InNonInstantiationSFINAEContext = true; 5724 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 5725 } 5726 5727 ~SFINAETrap() { 5728 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 5729 SemaRef.InNonInstantiationSFINAEContext 5730 = PrevInNonInstantiationSFINAEContext; 5731 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 5732 } 5733 5734 /// \brief Determine whether any SFINAE errors have been trapped. 5735 bool hasErrorOccurred() const { 5736 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 5737 } 5738 }; 5739 5740 /// \brief The current instantiation scope used to store local 5741 /// variables. 5742 LocalInstantiationScope *CurrentInstantiationScope; 5743 5744 /// \brief The number of typos corrected by CorrectTypo. 5745 unsigned TyposCorrected; 5746 5747 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection> 5748 UnqualifiedTyposCorrectedMap; 5749 5750 /// \brief A cache containing the results of typo correction for unqualified 5751 /// name lookup. 5752 /// 5753 /// The string is the string that we corrected to (which may be empty, if 5754 /// there was no correction), while the boolean will be true when the 5755 /// string represents a keyword. 5756 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 5757 5758 /// \brief Worker object for performing CFG-based warnings. 5759 sema::AnalysisBasedWarnings AnalysisWarnings; 5760 5761 /// \brief An entity for which implicit template instantiation is required. 5762 /// 5763 /// The source location associated with the declaration is the first place in 5764 /// the source code where the declaration was "used". It is not necessarily 5765 /// the point of instantiation (which will be either before or after the 5766 /// namespace-scope declaration that triggered this implicit instantiation), 5767 /// However, it is the location that diagnostics should generally refer to, 5768 /// because users will need to know what code triggered the instantiation. 5769 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 5770 5771 /// \brief The queue of implicit template instantiations that are required 5772 /// but have not yet been performed. 5773 std::deque<PendingImplicitInstantiation> PendingInstantiations; 5774 5775 /// \brief The queue of implicit template instantiations that are required 5776 /// and must be performed within the current local scope. 5777 /// 5778 /// This queue is only used for member functions of local classes in 5779 /// templates, which must be instantiated in the same scope as their 5780 /// enclosing function, so that they can reference function-local 5781 /// types, static variables, enumerators, etc. 5782 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 5783 5784 void PerformPendingInstantiations(bool LocalOnly = false); 5785 5786 TypeSourceInfo *SubstType(TypeSourceInfo *T, 5787 const MultiLevelTemplateArgumentList &TemplateArgs, 5788 SourceLocation Loc, DeclarationName Entity); 5789 5790 QualType SubstType(QualType T, 5791 const MultiLevelTemplateArgumentList &TemplateArgs, 5792 SourceLocation Loc, DeclarationName Entity); 5793 5794 TypeSourceInfo *SubstType(TypeLoc TL, 5795 const MultiLevelTemplateArgumentList &TemplateArgs, 5796 SourceLocation Loc, DeclarationName Entity); 5797 5798 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 5799 const MultiLevelTemplateArgumentList &TemplateArgs, 5800 SourceLocation Loc, 5801 DeclarationName Entity, 5802 CXXRecordDecl *ThisContext, 5803 unsigned ThisTypeQuals); 5804 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 5805 const MultiLevelTemplateArgumentList &TemplateArgs, 5806 int indexAdjustment, 5807 llvm::Optional<unsigned> NumExpansions, 5808 bool ExpectParameterPack); 5809 bool SubstParmTypes(SourceLocation Loc, 5810 ParmVarDecl **Params, unsigned NumParams, 5811 const MultiLevelTemplateArgumentList &TemplateArgs, 5812 SmallVectorImpl<QualType> &ParamTypes, 5813 SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 5814 ExprResult SubstExpr(Expr *E, 5815 const MultiLevelTemplateArgumentList &TemplateArgs); 5816 5817 /// \brief Substitute the given template arguments into a list of 5818 /// expressions, expanding pack expansions if required. 5819 /// 5820 /// \param Exprs The list of expressions to substitute into. 5821 /// 5822 /// \param NumExprs The number of expressions in \p Exprs. 5823 /// 5824 /// \param IsCall Whether this is some form of call, in which case 5825 /// default arguments will be dropped. 5826 /// 5827 /// \param TemplateArgs The set of template arguments to substitute. 5828 /// 5829 /// \param Outputs Will receive all of the substituted arguments. 5830 /// 5831 /// \returns true if an error occurred, false otherwise. 5832 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 5833 const MultiLevelTemplateArgumentList &TemplateArgs, 5834 SmallVectorImpl<Expr *> &Outputs); 5835 5836 StmtResult SubstStmt(Stmt *S, 5837 const MultiLevelTemplateArgumentList &TemplateArgs); 5838 5839 Decl *SubstDecl(Decl *D, DeclContext *Owner, 5840 const MultiLevelTemplateArgumentList &TemplateArgs); 5841 5842 ExprResult SubstInitializer(Expr *E, 5843 const MultiLevelTemplateArgumentList &TemplateArgs, 5844 bool CXXDirectInit); 5845 5846 bool 5847 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 5848 CXXRecordDecl *Pattern, 5849 const MultiLevelTemplateArgumentList &TemplateArgs); 5850 5851 bool 5852 InstantiateClass(SourceLocation PointOfInstantiation, 5853 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 5854 const MultiLevelTemplateArgumentList &TemplateArgs, 5855 TemplateSpecializationKind TSK, 5856 bool Complain = true); 5857 5858 bool InstantiateEnum(SourceLocation PointOfInstantiation, 5859 EnumDecl *Instantiation, EnumDecl *Pattern, 5860 const MultiLevelTemplateArgumentList &TemplateArgs, 5861 TemplateSpecializationKind TSK); 5862 5863 struct LateInstantiatedAttribute { 5864 const Attr *TmplAttr; 5865 LocalInstantiationScope *Scope; 5866 Decl *NewDecl; 5867 5868 LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, 5869 Decl *D) 5870 : TmplAttr(A), Scope(S), NewDecl(D) 5871 { } 5872 }; 5873 typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; 5874 5875 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 5876 const Decl *Pattern, Decl *Inst, 5877 LateInstantiatedAttrVec *LateAttrs = 0, 5878 LocalInstantiationScope *OuterMostScope = 0); 5879 5880 bool 5881 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 5882 ClassTemplateSpecializationDecl *ClassTemplateSpec, 5883 TemplateSpecializationKind TSK, 5884 bool Complain = true); 5885 5886 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 5887 CXXRecordDecl *Instantiation, 5888 const MultiLevelTemplateArgumentList &TemplateArgs, 5889 TemplateSpecializationKind TSK); 5890 5891 void InstantiateClassTemplateSpecializationMembers( 5892 SourceLocation PointOfInstantiation, 5893 ClassTemplateSpecializationDecl *ClassTemplateSpec, 5894 TemplateSpecializationKind TSK); 5895 5896 NestedNameSpecifierLoc 5897 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 5898 const MultiLevelTemplateArgumentList &TemplateArgs); 5899 5900 DeclarationNameInfo 5901 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 5902 const MultiLevelTemplateArgumentList &TemplateArgs); 5903 TemplateName 5904 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 5905 SourceLocation Loc, 5906 const MultiLevelTemplateArgumentList &TemplateArgs); 5907 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 5908 TemplateArgumentListInfo &Result, 5909 const MultiLevelTemplateArgumentList &TemplateArgs); 5910 5911 void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, 5912 FunctionDecl *Function); 5913 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 5914 FunctionDecl *Function, 5915 bool Recursive = false, 5916 bool DefinitionRequired = false); 5917 void InstantiateStaticDataMemberDefinition( 5918 SourceLocation PointOfInstantiation, 5919 VarDecl *Var, 5920 bool Recursive = false, 5921 bool DefinitionRequired = false); 5922 5923 void InstantiateMemInitializers(CXXConstructorDecl *New, 5924 const CXXConstructorDecl *Tmpl, 5925 const MultiLevelTemplateArgumentList &TemplateArgs); 5926 5927 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 5928 const MultiLevelTemplateArgumentList &TemplateArgs); 5929 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 5930 const MultiLevelTemplateArgumentList &TemplateArgs); 5931 5932 // Objective-C declarations. 5933 enum ObjCContainerKind { 5934 OCK_None = -1, 5935 OCK_Interface = 0, 5936 OCK_Protocol, 5937 OCK_Category, 5938 OCK_ClassExtension, 5939 OCK_Implementation, 5940 OCK_CategoryImplementation 5941 }; 5942 ObjCContainerKind getObjCContainerKind() const; 5943 5944 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 5945 IdentifierInfo *ClassName, 5946 SourceLocation ClassLoc, 5947 IdentifierInfo *SuperName, 5948 SourceLocation SuperLoc, 5949 Decl * const *ProtoRefs, 5950 unsigned NumProtoRefs, 5951 const SourceLocation *ProtoLocs, 5952 SourceLocation EndProtoLoc, 5953 AttributeList *AttrList); 5954 5955 Decl *ActOnCompatiblityAlias( 5956 SourceLocation AtCompatibilityAliasLoc, 5957 IdentifierInfo *AliasName, SourceLocation AliasLocation, 5958 IdentifierInfo *ClassName, SourceLocation ClassLocation); 5959 5960 bool CheckForwardProtocolDeclarationForCircularDependency( 5961 IdentifierInfo *PName, 5962 SourceLocation &PLoc, SourceLocation PrevLoc, 5963 const ObjCList<ObjCProtocolDecl> &PList); 5964 5965 Decl *ActOnStartProtocolInterface( 5966 SourceLocation AtProtoInterfaceLoc, 5967 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 5968 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 5969 const SourceLocation *ProtoLocs, 5970 SourceLocation EndProtoLoc, 5971 AttributeList *AttrList); 5972 5973 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 5974 IdentifierInfo *ClassName, 5975 SourceLocation ClassLoc, 5976 IdentifierInfo *CategoryName, 5977 SourceLocation CategoryLoc, 5978 Decl * const *ProtoRefs, 5979 unsigned NumProtoRefs, 5980 const SourceLocation *ProtoLocs, 5981 SourceLocation EndProtoLoc); 5982 5983 Decl *ActOnStartClassImplementation( 5984 SourceLocation AtClassImplLoc, 5985 IdentifierInfo *ClassName, SourceLocation ClassLoc, 5986 IdentifierInfo *SuperClassname, 5987 SourceLocation SuperClassLoc); 5988 5989 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 5990 IdentifierInfo *ClassName, 5991 SourceLocation ClassLoc, 5992 IdentifierInfo *CatName, 5993 SourceLocation CatLoc); 5994 5995 DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, 5996 ArrayRef<Decl *> Decls); 5997 5998 DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, 5999 IdentifierInfo **IdentList, 6000 SourceLocation *IdentLocs, 6001 unsigned NumElts); 6002 6003 DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 6004 const IdentifierLocPair *IdentList, 6005 unsigned NumElts, 6006 AttributeList *attrList); 6007 6008 void FindProtocolDeclaration(bool WarnOnDeclarations, 6009 const IdentifierLocPair *ProtocolId, 6010 unsigned NumProtocols, 6011 SmallVectorImpl<Decl *> &Protocols); 6012 6013 /// Ensure attributes are consistent with type. 6014 /// \param [in, out] Attributes The attributes to check; they will 6015 /// be modified to be consistent with \arg PropertyTy. 6016 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 6017 SourceLocation Loc, 6018 unsigned &Attributes, 6019 bool propertyInPrimaryClass); 6020 6021 /// Process the specified property declaration and create decls for the 6022 /// setters and getters as needed. 6023 /// \param property The property declaration being processed 6024 /// \param CD The semantic container for the property 6025 /// \param redeclaredProperty Declaration for property if redeclared 6026 /// in class extension. 6027 /// \param lexicalDC Container for redeclaredProperty. 6028 void ProcessPropertyDecl(ObjCPropertyDecl *property, 6029 ObjCContainerDecl *CD, 6030 ObjCPropertyDecl *redeclaredProperty = 0, 6031 ObjCContainerDecl *lexicalDC = 0); 6032 6033 6034 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 6035 ObjCPropertyDecl *SuperProperty, 6036 const IdentifierInfo *Name); 6037 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 6038 6039 6040 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 6041 6042 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 6043 ObjCInterfaceDecl *ID); 6044 6045 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 6046 ObjCProtocolDecl *PDecl); 6047 6048 Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, 6049 Decl **allMethods = 0, unsigned allNum = 0, 6050 Decl **allProperties = 0, unsigned pNum = 0, 6051 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 6052 6053 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 6054 SourceLocation LParenLoc, 6055 FieldDeclarator &FD, ObjCDeclSpec &ODS, 6056 Selector GetterSel, Selector SetterSel, 6057 bool *OverridingProperty, 6058 tok::ObjCKeywordKind MethodImplKind, 6059 DeclContext *lexicalDC = 0); 6060 6061 Decl *ActOnPropertyImplDecl(Scope *S, 6062 SourceLocation AtLoc, 6063 SourceLocation PropertyLoc, 6064 bool ImplKind, 6065 IdentifierInfo *PropertyId, 6066 IdentifierInfo *PropertyIvar, 6067 SourceLocation PropertyIvarLoc); 6068 6069 enum ObjCSpecialMethodKind { 6070 OSMK_None, 6071 OSMK_Alloc, 6072 OSMK_New, 6073 OSMK_Copy, 6074 OSMK_RetainingInit, 6075 OSMK_NonRetainingInit 6076 }; 6077 6078 struct ObjCArgInfo { 6079 IdentifierInfo *Name; 6080 SourceLocation NameLoc; 6081 // The Type is null if no type was specified, and the DeclSpec is invalid 6082 // in this case. 6083 ParsedType Type; 6084 ObjCDeclSpec DeclSpec; 6085 6086 /// ArgAttrs - Attribute list for this argument. 6087 AttributeList *ArgAttrs; 6088 }; 6089 6090 Decl *ActOnMethodDeclaration( 6091 Scope *S, 6092 SourceLocation BeginLoc, // location of the + or -. 6093 SourceLocation EndLoc, // location of the ; or {. 6094 tok::TokenKind MethodType, 6095 ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 6096 ArrayRef<SourceLocation> SelectorLocs, Selector Sel, 6097 // optional arguments. The number of types/arguments is obtained 6098 // from the Sel.getNumArgs(). 6099 ObjCArgInfo *ArgInfo, 6100 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 6101 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 6102 bool isVariadic, bool MethodDefinition); 6103 6104 // Helper method for ActOnClassMethod/ActOnInstanceMethod. 6105 // Will search "local" class/category implementations for a method decl. 6106 // Will also search in class's root looking for instance method. 6107 // Returns 0 if no method is found. 6108 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, 6109 ObjCInterfaceDecl *CDecl); 6110 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, 6111 ObjCInterfaceDecl *ClassDecl); 6112 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 6113 const ObjCObjectPointerType *OPT, 6114 bool IsInstance); 6115 ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, 6116 bool IsInstance); 6117 6118 bool inferObjCARCLifetime(ValueDecl *decl); 6119 6120 ExprResult 6121 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 6122 Expr *BaseExpr, 6123 SourceLocation OpLoc, 6124 DeclarationName MemberName, 6125 SourceLocation MemberLoc, 6126 SourceLocation SuperLoc, QualType SuperType, 6127 bool Super); 6128 6129 ExprResult 6130 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 6131 IdentifierInfo &propertyName, 6132 SourceLocation receiverNameLoc, 6133 SourceLocation propertyNameLoc); 6134 6135 ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); 6136 6137 /// \brief Describes the kind of message expression indicated by a message 6138 /// send that starts with an identifier. 6139 enum ObjCMessageKind { 6140 /// \brief The message is sent to 'super'. 6141 ObjCSuperMessage, 6142 /// \brief The message is an instance message. 6143 ObjCInstanceMessage, 6144 /// \brief The message is a class message, and the identifier is a type 6145 /// name. 6146 ObjCClassMessage 6147 }; 6148 6149 ObjCMessageKind getObjCMessageKind(Scope *S, 6150 IdentifierInfo *Name, 6151 SourceLocation NameLoc, 6152 bool IsSuper, 6153 bool HasTrailingDot, 6154 ParsedType &ReceiverType); 6155 6156 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 6157 Selector Sel, 6158 SourceLocation LBracLoc, 6159 ArrayRef<SourceLocation> SelectorLocs, 6160 SourceLocation RBracLoc, 6161 MultiExprArg Args); 6162 6163 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 6164 QualType ReceiverType, 6165 SourceLocation SuperLoc, 6166 Selector Sel, 6167 ObjCMethodDecl *Method, 6168 SourceLocation LBracLoc, 6169 ArrayRef<SourceLocation> SelectorLocs, 6170 SourceLocation RBracLoc, 6171 MultiExprArg Args, 6172 bool isImplicit = false); 6173 6174 ExprResult BuildClassMessageImplicit(QualType ReceiverType, 6175 bool isSuperReceiver, 6176 SourceLocation Loc, 6177 Selector Sel, 6178 ObjCMethodDecl *Method, 6179 MultiExprArg Args); 6180 6181 ExprResult ActOnClassMessage(Scope *S, 6182 ParsedType Receiver, 6183 Selector Sel, 6184 SourceLocation LBracLoc, 6185 ArrayRef<SourceLocation> SelectorLocs, 6186 SourceLocation RBracLoc, 6187 MultiExprArg Args); 6188 6189 ExprResult BuildInstanceMessage(Expr *Receiver, 6190 QualType ReceiverType, 6191 SourceLocation SuperLoc, 6192 Selector Sel, 6193 ObjCMethodDecl *Method, 6194 SourceLocation LBracLoc, 6195 ArrayRef<SourceLocation> SelectorLocs, 6196 SourceLocation RBracLoc, 6197 MultiExprArg Args, 6198 bool isImplicit = false); 6199 6200 ExprResult BuildInstanceMessageImplicit(Expr *Receiver, 6201 QualType ReceiverType, 6202 SourceLocation Loc, 6203 Selector Sel, 6204 ObjCMethodDecl *Method, 6205 MultiExprArg Args); 6206 6207 ExprResult ActOnInstanceMessage(Scope *S, 6208 Expr *Receiver, 6209 Selector Sel, 6210 SourceLocation LBracLoc, 6211 ArrayRef<SourceLocation> SelectorLocs, 6212 SourceLocation RBracLoc, 6213 MultiExprArg Args); 6214 6215 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, 6216 ObjCBridgeCastKind Kind, 6217 SourceLocation BridgeKeywordLoc, 6218 TypeSourceInfo *TSInfo, 6219 Expr *SubExpr); 6220 6221 ExprResult ActOnObjCBridgedCast(Scope *S, 6222 SourceLocation LParenLoc, 6223 ObjCBridgeCastKind Kind, 6224 SourceLocation BridgeKeywordLoc, 6225 ParsedType Type, 6226 SourceLocation RParenLoc, 6227 Expr *SubExpr); 6228 6229 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); 6230 6231 /// \brief Check whether the given new method is a valid override of the 6232 /// given overridden method, and set any properties that should be inherited. 6233 void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 6234 const ObjCMethodDecl *Overridden, 6235 bool IsImplementation); 6236 6237 /// \brief Describes the compatibility of a result type with its method. 6238 enum ResultTypeCompatibilityKind { 6239 RTC_Compatible, 6240 RTC_Incompatible, 6241 RTC_Unknown 6242 }; 6243 6244 void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, 6245 ObjCInterfaceDecl *CurrentClass, 6246 ResultTypeCompatibilityKind RTC); 6247 6248 enum PragmaOptionsAlignKind { 6249 POAK_Native, // #pragma options align=native 6250 POAK_Natural, // #pragma options align=natural 6251 POAK_Packed, // #pragma options align=packed 6252 POAK_Power, // #pragma options align=power 6253 POAK_Mac68k, // #pragma options align=mac68k 6254 POAK_Reset // #pragma options align=reset 6255 }; 6256 6257 /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. 6258 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 6259 SourceLocation PragmaLoc, 6260 SourceLocation KindLoc); 6261 6262 enum PragmaPackKind { 6263 PPK_Default, // #pragma pack([n]) 6264 PPK_Show, // #pragma pack(show), only supported by MSVC. 6265 PPK_Push, // #pragma pack(push, [identifier], [n]) 6266 PPK_Pop // #pragma pack(pop, [identifier], [n]) 6267 }; 6268 6269 enum PragmaMSStructKind { 6270 PMSST_OFF, // #pragms ms_struct off 6271 PMSST_ON // #pragms ms_struct on 6272 }; 6273 6274 /// ActOnPragmaPack - Called on well formed \#pragma pack(...). 6275 void ActOnPragmaPack(PragmaPackKind Kind, 6276 IdentifierInfo *Name, 6277 Expr *Alignment, 6278 SourceLocation PragmaLoc, 6279 SourceLocation LParenLoc, 6280 SourceLocation RParenLoc); 6281 6282 /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. 6283 void ActOnPragmaMSStruct(PragmaMSStructKind Kind); 6284 6285 /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. 6286 void ActOnPragmaUnused(const Token &Identifier, 6287 Scope *curScope, 6288 SourceLocation PragmaLoc); 6289 6290 /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . 6291 void ActOnPragmaVisibility(const IdentifierInfo* VisType, 6292 SourceLocation PragmaLoc); 6293 6294 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, 6295 SourceLocation Loc); 6296 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 6297 6298 /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. 6299 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 6300 SourceLocation PragmaLoc, 6301 SourceLocation WeakNameLoc); 6302 6303 /// ActOnPragmaRedefineExtname - Called on well formed 6304 /// \#pragma redefine_extname oldname newname. 6305 void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, 6306 IdentifierInfo* AliasName, 6307 SourceLocation PragmaLoc, 6308 SourceLocation WeakNameLoc, 6309 SourceLocation AliasNameLoc); 6310 6311 /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. 6312 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 6313 IdentifierInfo* AliasName, 6314 SourceLocation PragmaLoc, 6315 SourceLocation WeakNameLoc, 6316 SourceLocation AliasNameLoc); 6317 6318 /// ActOnPragmaFPContract - Called on well formed 6319 /// \#pragma {STDC,OPENCL} FP_CONTRACT 6320 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 6321 6322 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 6323 /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. 6324 void AddAlignmentAttributesForRecord(RecordDecl *RD); 6325 6326 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. 6327 void AddMsStructLayoutForRecord(RecordDecl *RD); 6328 6329 /// FreePackedContext - Deallocate and null out PackContext. 6330 void FreePackedContext(); 6331 6332 /// PushNamespaceVisibilityAttr - Note that we've entered a 6333 /// namespace with a visibility attribute. 6334 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, 6335 SourceLocation Loc); 6336 6337 /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, 6338 /// add an appropriate visibility attribute. 6339 void AddPushedVisibilityAttribute(Decl *RD); 6340 6341 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 6342 /// for '\#pragma GCC visibility' and visibility attributes on namespaces. 6343 void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); 6344 6345 /// FreeVisContext - Deallocate and null out VisContext. 6346 void FreeVisContext(); 6347 6348 /// AddCFAuditedAttribute - Check whether we're currently within 6349 /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding 6350 /// the appropriate attribute. 6351 void AddCFAuditedAttribute(Decl *D); 6352 6353 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 6354 void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, 6355 bool isDeclSpec); 6356 void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T, 6357 bool isDeclSpec); 6358 6359 /// \brief The kind of conversion being performed. 6360 enum CheckedConversionKind { 6361 /// \brief An implicit conversion. 6362 CCK_ImplicitConversion, 6363 /// \brief A C-style cast. 6364 CCK_CStyleCast, 6365 /// \brief A functional-style cast. 6366 CCK_FunctionalCast, 6367 /// \brief A cast other than a C-style cast. 6368 CCK_OtherCast 6369 }; 6370 6371 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 6372 /// cast. If there is already an implicit cast, merge into the existing one. 6373 /// If isLvalue, the result of the cast is an lvalue. 6374 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 6375 ExprValueKind VK = VK_RValue, 6376 const CXXCastPath *BasePath = 0, 6377 CheckedConversionKind CCK 6378 = CCK_ImplicitConversion); 6379 6380 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 6381 /// to the conversion from scalar type ScalarTy to the Boolean type. 6382 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 6383 6384 /// IgnoredValueConversions - Given that an expression's result is 6385 /// syntactically ignored, perform any conversions that are 6386 /// required. 6387 ExprResult IgnoredValueConversions(Expr *E); 6388 6389 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 6390 // functions and arrays to their respective pointers (C99 6.3.2.1). 6391 ExprResult UsualUnaryConversions(Expr *E); 6392 6393 // DefaultFunctionArrayConversion - converts functions and arrays 6394 // to their respective pointers (C99 6.3.2.1). 6395 ExprResult DefaultFunctionArrayConversion(Expr *E); 6396 6397 // DefaultFunctionArrayLvalueConversion - converts functions and 6398 // arrays to their respective pointers and performs the 6399 // lvalue-to-rvalue conversion. 6400 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 6401 6402 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 6403 // the operand. This is DefaultFunctionArrayLvalueConversion, 6404 // except that it assumes the operand isn't of function or array 6405 // type. 6406 ExprResult DefaultLvalueConversion(Expr *E); 6407 6408 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 6409 // do not have a prototype. Integer promotions are performed on each 6410 // argument, and arguments that have type float are promoted to double. 6411 ExprResult DefaultArgumentPromotion(Expr *E); 6412 6413 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 6414 enum VariadicCallType { 6415 VariadicFunction, 6416 VariadicBlock, 6417 VariadicMethod, 6418 VariadicConstructor, 6419 VariadicDoesNotApply 6420 }; 6421 6422 VariadicCallType getVariadicCallType(FunctionDecl *FDecl, 6423 const FunctionProtoType *Proto, 6424 Expr *Fn); 6425 6426 // Used for determining in which context a type is allowed to be passed to a 6427 // vararg function. 6428 enum VarArgKind { 6429 VAK_Valid, 6430 VAK_ValidInCXX11, 6431 VAK_Invalid 6432 }; 6433 6434 // Determines which VarArgKind fits an expression. 6435 VarArgKind isValidVarArgType(const QualType &Ty); 6436 6437 /// GatherArgumentsForCall - Collector argument expressions for various 6438 /// form of call prototypes. 6439 bool GatherArgumentsForCall(SourceLocation CallLoc, 6440 FunctionDecl *FDecl, 6441 const FunctionProtoType *Proto, 6442 unsigned FirstProtoArg, 6443 Expr **Args, unsigned NumArgs, 6444 SmallVector<Expr *, 8> &AllArgs, 6445 VariadicCallType CallType = VariadicDoesNotApply, 6446 bool AllowExplicit = false); 6447 6448 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 6449 // will return ExprError() if the resulting type is not a POD type. 6450 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 6451 FunctionDecl *FDecl); 6452 6453 /// Checks to see if the given expression is a valid argument to a variadic 6454 /// function, issuing a diagnostic and returning NULL if not. 6455 bool variadicArgumentPODCheck(const Expr *E, VariadicCallType CT); 6456 6457 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 6458 // operands and then handles various conversions that are common to binary 6459 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 6460 // routine returns the first non-arithmetic type found. The client is 6461 // responsible for emitting appropriate error diagnostics. 6462 QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, 6463 bool IsCompAssign = false); 6464 6465 /// AssignConvertType - All of the 'assignment' semantic checks return this 6466 /// enum to indicate whether the assignment was allowed. These checks are 6467 /// done for simple assignments, as well as initialization, return from 6468 /// function, argument passing, etc. The query is phrased in terms of a 6469 /// source and destination type. 6470 enum AssignConvertType { 6471 /// Compatible - the types are compatible according to the standard. 6472 Compatible, 6473 6474 /// PointerToInt - The assignment converts a pointer to an int, which we 6475 /// accept as an extension. 6476 PointerToInt, 6477 6478 /// IntToPointer - The assignment converts an int to a pointer, which we 6479 /// accept as an extension. 6480 IntToPointer, 6481 6482 /// FunctionVoidPointer - The assignment is between a function pointer and 6483 /// void*, which the standard doesn't allow, but we accept as an extension. 6484 FunctionVoidPointer, 6485 6486 /// IncompatiblePointer - The assignment is between two pointers types that 6487 /// are not compatible, but we accept them as an extension. 6488 IncompatiblePointer, 6489 6490 /// IncompatiblePointer - The assignment is between two pointers types which 6491 /// point to integers which have a different sign, but are otherwise 6492 /// identical. This is a subset of the above, but broken out because it's by 6493 /// far the most common case of incompatible pointers. 6494 IncompatiblePointerSign, 6495 6496 /// CompatiblePointerDiscardsQualifiers - The assignment discards 6497 /// c/v/r qualifiers, which we accept as an extension. 6498 CompatiblePointerDiscardsQualifiers, 6499 6500 /// IncompatiblePointerDiscardsQualifiers - The assignment 6501 /// discards qualifiers that we don't permit to be discarded, 6502 /// like address spaces. 6503 IncompatiblePointerDiscardsQualifiers, 6504 6505 /// IncompatibleNestedPointerQualifiers - The assignment is between two 6506 /// nested pointer types, and the qualifiers other than the first two 6507 /// levels differ e.g. char ** -> const char **, but we accept them as an 6508 /// extension. 6509 IncompatibleNestedPointerQualifiers, 6510 6511 /// IncompatibleVectors - The assignment is between two vector types that 6512 /// have the same size, which we accept as an extension. 6513 IncompatibleVectors, 6514 6515 /// IntToBlockPointer - The assignment converts an int to a block 6516 /// pointer. We disallow this. 6517 IntToBlockPointer, 6518 6519 /// IncompatibleBlockPointer - The assignment is between two block 6520 /// pointers types that are not compatible. 6521 IncompatibleBlockPointer, 6522 6523 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 6524 /// id type and something else (that is incompatible with it). For example, 6525 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 6526 IncompatibleObjCQualifiedId, 6527 6528 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an 6529 /// object with __weak qualifier. 6530 IncompatibleObjCWeakRef, 6531 6532 /// Incompatible - We reject this conversion outright, it is invalid to 6533 /// represent it in the AST. 6534 Incompatible 6535 }; 6536 6537 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 6538 /// assignment conversion type specified by ConvTy. This returns true if the 6539 /// conversion was invalid or false if the conversion was accepted. 6540 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 6541 SourceLocation Loc, 6542 QualType DstType, QualType SrcType, 6543 Expr *SrcExpr, AssignmentAction Action, 6544 bool *Complained = 0); 6545 6546 /// CheckAssignmentConstraints - Perform type checking for assignment, 6547 /// argument passing, variable initialization, and function return values. 6548 /// C99 6.5.16. 6549 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 6550 QualType LHSType, 6551 QualType RHSType); 6552 6553 /// Check assignment constraints and prepare for a conversion of the 6554 /// RHS to the LHS type. 6555 AssignConvertType CheckAssignmentConstraints(QualType LHSType, 6556 ExprResult &RHS, 6557 CastKind &Kind); 6558 6559 // CheckSingleAssignmentConstraints - Currently used by 6560 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 6561 // this routine performs the default function/array converions. 6562 AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, 6563 ExprResult &RHS, 6564 bool Diagnose = true); 6565 6566 // \brief If the lhs type is a transparent union, check whether we 6567 // can initialize the transparent union with the given expression. 6568 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, 6569 ExprResult &RHS); 6570 6571 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 6572 6573 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 6574 6575 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6576 AssignmentAction Action, 6577 bool AllowExplicit = false); 6578 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6579 AssignmentAction Action, 6580 bool AllowExplicit, 6581 ImplicitConversionSequence& ICS); 6582 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6583 const ImplicitConversionSequence& ICS, 6584 AssignmentAction Action, 6585 CheckedConversionKind CCK 6586 = CCK_ImplicitConversion); 6587 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6588 const StandardConversionSequence& SCS, 6589 AssignmentAction Action, 6590 CheckedConversionKind CCK); 6591 6592 /// the following "Check" methods will return a valid/converted QualType 6593 /// or a null QualType (indicating an error diagnostic was issued). 6594 6595 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 6596 QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, 6597 ExprResult &RHS); 6598 QualType CheckPointerToMemberOperands( // C++ 5.5 6599 ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, 6600 SourceLocation OpLoc, bool isIndirect); 6601 QualType CheckMultiplyDivideOperands( // C99 6.5.5 6602 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, 6603 bool IsDivide); 6604 QualType CheckRemainderOperands( // C99 6.5.5 6605 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6606 bool IsCompAssign = false); 6607 QualType CheckAdditionOperands( // C99 6.5.6 6608 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6609 QualType* CompLHSTy = 0); 6610 QualType CheckSubtractionOperands( // C99 6.5.6 6611 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6612 QualType* CompLHSTy = 0); 6613 QualType CheckShiftOperands( // C99 6.5.7 6614 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6615 bool IsCompAssign = false); 6616 QualType CheckCompareOperands( // C99 6.5.8/9 6617 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc, 6618 bool isRelational); 6619 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 6620 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6621 bool IsCompAssign = false); 6622 QualType CheckLogicalOperands( // C99 6.5.[13,14] 6623 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc); 6624 // CheckAssignmentOperands is used for both simple and compound assignment. 6625 // For simple assignment, pass both expressions and a null converted type. 6626 // For compound assignment, pass both expressions and the converted type. 6627 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 6628 Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType); 6629 6630 ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, 6631 UnaryOperatorKind Opcode, Expr *Op); 6632 ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, 6633 BinaryOperatorKind Opcode, 6634 Expr *LHS, Expr *RHS); 6635 ExprResult checkPseudoObjectRValue(Expr *E); 6636 Expr *recreateSyntacticForm(PseudoObjectExpr *E); 6637 6638 QualType CheckConditionalOperands( // C99 6.5.15 6639 ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, 6640 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); 6641 QualType CXXCheckConditionalOperands( // C++ 5.16 6642 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 6643 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 6644 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 6645 bool *NonStandardCompositeType = 0); 6646 QualType FindCompositePointerType(SourceLocation Loc, 6647 ExprResult &E1, ExprResult &E2, 6648 bool *NonStandardCompositeType = 0) { 6649 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 6650 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, 6651 NonStandardCompositeType); 6652 E1 = Owned(E1Tmp); 6653 E2 = Owned(E2Tmp); 6654 return Composite; 6655 } 6656 6657 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 6658 SourceLocation QuestionLoc); 6659 6660 bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, 6661 SourceLocation QuestionLoc); 6662 6663 /// type checking for vector binary operators. 6664 QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, 6665 SourceLocation Loc, bool IsCompAssign); 6666 QualType GetSignedVectorType(QualType V); 6667 QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, 6668 SourceLocation Loc, bool isRelational); 6669 QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, 6670 SourceLocation Loc); 6671 6672 /// type checking declaration initializers (C99 6.7.8) 6673 bool CheckForConstantInitializer(Expr *e, QualType t); 6674 6675 // type checking C++ declaration initializers (C++ [dcl.init]). 6676 6677 /// ReferenceCompareResult - Expresses the result of comparing two 6678 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 6679 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 6680 enum ReferenceCompareResult { 6681 /// Ref_Incompatible - The two types are incompatible, so direct 6682 /// reference binding is not possible. 6683 Ref_Incompatible = 0, 6684 /// Ref_Related - The two types are reference-related, which means 6685 /// that their unqualified forms (T1 and T2) are either the same 6686 /// or T1 is a base class of T2. 6687 Ref_Related, 6688 /// Ref_Compatible_With_Added_Qualification - The two types are 6689 /// reference-compatible with added qualification, meaning that 6690 /// they are reference-compatible and the qualifiers on T1 (cv1) 6691 /// are greater than the qualifiers on T2 (cv2). 6692 Ref_Compatible_With_Added_Qualification, 6693 /// Ref_Compatible - The two types are reference-compatible and 6694 /// have equivalent qualifiers (cv1 == cv2). 6695 Ref_Compatible 6696 }; 6697 6698 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 6699 QualType T1, QualType T2, 6700 bool &DerivedToBase, 6701 bool &ObjCConversion, 6702 bool &ObjCLifetimeConversion); 6703 6704 ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, 6705 Expr *CastExpr, CastKind &CastKind, 6706 ExprValueKind &VK, CXXCastPath &Path); 6707 6708 /// \brief Force an expression with unknown-type to an expression of the 6709 /// given type. 6710 ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); 6711 6712 // CheckVectorCast - check type constraints for vectors. 6713 // Since vectors are an extension, there are no C standard reference for this. 6714 // We allow casting between vectors and integer datatypes of the same size. 6715 // returns true if the cast is invalid 6716 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 6717 CastKind &Kind); 6718 6719 // CheckExtVectorCast - check type constraints for extended vectors. 6720 // Since vectors are an extension, there are no C standard reference for this. 6721 // We allow casting between vectors and integer datatypes of the same size, 6722 // or vectors and the element type of that vector. 6723 // returns the cast expr 6724 ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, 6725 CastKind &Kind); 6726 6727 ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 6728 SourceLocation LParenLoc, 6729 Expr *CastExpr, 6730 SourceLocation RParenLoc); 6731 6732 enum ARCConversionResult { ACR_okay, ACR_unbridged }; 6733 6734 /// \brief Checks for invalid conversions and casts between 6735 /// retainable pointers and other pointer kinds. 6736 ARCConversionResult CheckObjCARCConversion(SourceRange castRange, 6737 QualType castType, Expr *&op, 6738 CheckedConversionKind CCK); 6739 6740 Expr *stripARCUnbridgedCast(Expr *e); 6741 void diagnoseARCUnbridgedCast(Expr *e); 6742 6743 bool CheckObjCARCUnavailableWeakConversion(QualType castType, 6744 QualType ExprType); 6745 6746 /// checkRetainCycles - Check whether an Objective-C message send 6747 /// might create an obvious retain cycle. 6748 void checkRetainCycles(ObjCMessageExpr *msg); 6749 void checkRetainCycles(Expr *receiver, Expr *argument); 6750 6751 /// checkUnsafeAssigns - Check whether +1 expr is being assigned 6752 /// to weak/__unsafe_unretained type. 6753 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); 6754 6755 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned 6756 /// to weak/__unsafe_unretained expression. 6757 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); 6758 6759 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 6760 /// \param Method - May be null. 6761 /// \param [out] ReturnType - The return type of the send. 6762 /// \return true iff there were any incompatible types. 6763 bool CheckMessageArgumentTypes(QualType ReceiverType, 6764 Expr **Args, unsigned NumArgs, Selector Sel, 6765 ObjCMethodDecl *Method, bool isClassMessage, 6766 bool isSuperMessage, 6767 SourceLocation lbrac, SourceLocation rbrac, 6768 QualType &ReturnType, ExprValueKind &VK); 6769 6770 /// \brief Determine the result of a message send expression based on 6771 /// the type of the receiver, the method expected to receive the message, 6772 /// and the form of the message send. 6773 QualType getMessageSendResultType(QualType ReceiverType, 6774 ObjCMethodDecl *Method, 6775 bool isClassMessage, bool isSuperMessage); 6776 6777 /// \brief If the given expression involves a message send to a method 6778 /// with a related result type, emit a note describing what happened. 6779 void EmitRelatedResultTypeNote(const Expr *E); 6780 6781 /// CheckBooleanCondition - Diagnose problems involving the use of 6782 /// the given expression as a boolean condition (e.g. in an if 6783 /// statement). Also performs the standard function and array 6784 /// decays, possibly changing the input variable. 6785 /// 6786 /// \param Loc - A location associated with the condition, e.g. the 6787 /// 'if' keyword. 6788 /// \return true iff there were any errors 6789 ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc); 6790 6791 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 6792 Expr *SubExpr); 6793 6794 /// DiagnoseAssignmentAsCondition - Given that an expression is 6795 /// being used as a boolean condition, warn if it's an assignment. 6796 void DiagnoseAssignmentAsCondition(Expr *E); 6797 6798 /// \brief Redundant parentheses over an equality comparison can indicate 6799 /// that the user intended an assignment used as condition. 6800 void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); 6801 6802 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 6803 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 6804 6805 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 6806 /// the specified width and sign. If an overflow occurs, detect it and emit 6807 /// the specified diagnostic. 6808 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 6809 unsigned NewWidth, bool NewSign, 6810 SourceLocation Loc, unsigned DiagID); 6811 6812 /// Checks that the Objective-C declaration is declared in the global scope. 6813 /// Emits an error and marks the declaration as invalid if it's not declared 6814 /// in the global scope. 6815 bool CheckObjCDeclScope(Decl *D); 6816 6817 /// \brief Abstract base class used for diagnosing integer constant 6818 /// expression violations. 6819 class VerifyICEDiagnoser { 6820 public: 6821 bool Suppress; 6822 6823 VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } 6824 6825 virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) =0; 6826 virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR); 6827 virtual ~VerifyICEDiagnoser() { } 6828 }; 6829 6830 /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, 6831 /// and reports the appropriate diagnostics. Returns false on success. 6832 /// Can optionally return the value of the expression. 6833 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 6834 VerifyICEDiagnoser &Diagnoser, 6835 bool AllowFold = true); 6836 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 6837 unsigned DiagID, 6838 bool AllowFold = true); 6839 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result=0); 6840 6841 /// VerifyBitField - verifies that a bit field expression is an ICE and has 6842 /// the correct width, and that the field type is valid. 6843 /// Returns false on success. 6844 /// Can optionally return whether the bit-field is of width 0 6845 ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 6846 QualType FieldTy, Expr *BitWidth, 6847 bool *ZeroWidth = 0); 6848 6849 enum CUDAFunctionTarget { 6850 CFT_Device, 6851 CFT_Global, 6852 CFT_Host, 6853 CFT_HostDevice 6854 }; 6855 6856 CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D); 6857 6858 bool CheckCUDATarget(CUDAFunctionTarget CallerTarget, 6859 CUDAFunctionTarget CalleeTarget); 6860 6861 bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) { 6862 return CheckCUDATarget(IdentifyCUDATarget(Caller), 6863 IdentifyCUDATarget(Callee)); 6864 } 6865 6866 /// \name Code completion 6867 //@{ 6868 /// \brief Describes the context in which code completion occurs. 6869 enum ParserCompletionContext { 6870 /// \brief Code completion occurs at top-level or namespace context. 6871 PCC_Namespace, 6872 /// \brief Code completion occurs within a class, struct, or union. 6873 PCC_Class, 6874 /// \brief Code completion occurs within an Objective-C interface, protocol, 6875 /// or category. 6876 PCC_ObjCInterface, 6877 /// \brief Code completion occurs within an Objective-C implementation or 6878 /// category implementation 6879 PCC_ObjCImplementation, 6880 /// \brief Code completion occurs within the list of instance variables 6881 /// in an Objective-C interface, protocol, category, or implementation. 6882 PCC_ObjCInstanceVariableList, 6883 /// \brief Code completion occurs following one or more template 6884 /// headers. 6885 PCC_Template, 6886 /// \brief Code completion occurs following one or more template 6887 /// headers within a class. 6888 PCC_MemberTemplate, 6889 /// \brief Code completion occurs within an expression. 6890 PCC_Expression, 6891 /// \brief Code completion occurs within a statement, which may 6892 /// also be an expression or a declaration. 6893 PCC_Statement, 6894 /// \brief Code completion occurs at the beginning of the 6895 /// initialization statement (or expression) in a for loop. 6896 PCC_ForInit, 6897 /// \brief Code completion occurs within the condition of an if, 6898 /// while, switch, or for statement. 6899 PCC_Condition, 6900 /// \brief Code completion occurs within the body of a function on a 6901 /// recovery path, where we do not have a specific handle on our position 6902 /// in the grammar. 6903 PCC_RecoveryInFunction, 6904 /// \brief Code completion occurs where only a type is permitted. 6905 PCC_Type, 6906 /// \brief Code completion occurs in a parenthesized expression, which 6907 /// might also be a type cast. 6908 PCC_ParenthesizedExpression, 6909 /// \brief Code completion occurs within a sequence of declaration 6910 /// specifiers within a function, method, or block. 6911 PCC_LocalDeclarationSpecifiers 6912 }; 6913 6914 void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); 6915 void CodeCompleteOrdinaryName(Scope *S, 6916 ParserCompletionContext CompletionContext); 6917 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 6918 bool AllowNonIdentifiers, 6919 bool AllowNestedNameSpecifiers); 6920 6921 struct CodeCompleteExpressionData; 6922 void CodeCompleteExpression(Scope *S, 6923 const CodeCompleteExpressionData &Data); 6924 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 6925 SourceLocation OpLoc, 6926 bool IsArrow); 6927 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 6928 void CodeCompleteTag(Scope *S, unsigned TagSpec); 6929 void CodeCompleteTypeQualifiers(DeclSpec &DS); 6930 void CodeCompleteCase(Scope *S); 6931 void CodeCompleteCall(Scope *S, Expr *Fn, llvm::ArrayRef<Expr *> Args); 6932 void CodeCompleteInitializer(Scope *S, Decl *D); 6933 void CodeCompleteReturn(Scope *S); 6934 void CodeCompleteAfterIf(Scope *S); 6935 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 6936 6937 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 6938 bool EnteringContext); 6939 void CodeCompleteUsing(Scope *S); 6940 void CodeCompleteUsingDirective(Scope *S); 6941 void CodeCompleteNamespaceDecl(Scope *S); 6942 void CodeCompleteNamespaceAliasDecl(Scope *S); 6943 void CodeCompleteOperatorName(Scope *S); 6944 void CodeCompleteConstructorInitializer(Decl *Constructor, 6945 CXXCtorInitializer** Initializers, 6946 unsigned NumInitializers); 6947 void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, 6948 bool AfterAmpersand); 6949 6950 void CodeCompleteObjCAtDirective(Scope *S); 6951 void CodeCompleteObjCAtVisibility(Scope *S); 6952 void CodeCompleteObjCAtStatement(Scope *S); 6953 void CodeCompleteObjCAtExpression(Scope *S); 6954 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 6955 void CodeCompleteObjCPropertyGetter(Scope *S); 6956 void CodeCompleteObjCPropertySetter(Scope *S); 6957 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 6958 bool IsParameter); 6959 void CodeCompleteObjCMessageReceiver(Scope *S); 6960 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 6961 IdentifierInfo **SelIdents, 6962 unsigned NumSelIdents, 6963 bool AtArgumentExpression); 6964 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 6965 IdentifierInfo **SelIdents, 6966 unsigned NumSelIdents, 6967 bool AtArgumentExpression, 6968 bool IsSuper = false); 6969 void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, 6970 IdentifierInfo **SelIdents, 6971 unsigned NumSelIdents, 6972 bool AtArgumentExpression, 6973 ObjCInterfaceDecl *Super = 0); 6974 void CodeCompleteObjCForCollection(Scope *S, 6975 DeclGroupPtrTy IterationVar); 6976 void CodeCompleteObjCSelector(Scope *S, 6977 IdentifierInfo **SelIdents, 6978 unsigned NumSelIdents); 6979 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 6980 unsigned NumProtocols); 6981 void CodeCompleteObjCProtocolDecl(Scope *S); 6982 void CodeCompleteObjCInterfaceDecl(Scope *S); 6983 void CodeCompleteObjCSuperclass(Scope *S, 6984 IdentifierInfo *ClassName, 6985 SourceLocation ClassNameLoc); 6986 void CodeCompleteObjCImplementationDecl(Scope *S); 6987 void CodeCompleteObjCInterfaceCategory(Scope *S, 6988 IdentifierInfo *ClassName, 6989 SourceLocation ClassNameLoc); 6990 void CodeCompleteObjCImplementationCategory(Scope *S, 6991 IdentifierInfo *ClassName, 6992 SourceLocation ClassNameLoc); 6993 void CodeCompleteObjCPropertyDefinition(Scope *S); 6994 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 6995 IdentifierInfo *PropertyName); 6996 void CodeCompleteObjCMethodDecl(Scope *S, 6997 bool IsInstanceMethod, 6998 ParsedType ReturnType); 6999 void CodeCompleteObjCMethodDeclSelector(Scope *S, 7000 bool IsInstanceMethod, 7001 bool AtParameterName, 7002 ParsedType ReturnType, 7003 IdentifierInfo **SelIdents, 7004 unsigned NumSelIdents); 7005 void CodeCompletePreprocessorDirective(bool InConditional); 7006 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 7007 void CodeCompletePreprocessorMacroName(bool IsDefinition); 7008 void CodeCompletePreprocessorExpression(); 7009 void CodeCompletePreprocessorMacroArgument(Scope *S, 7010 IdentifierInfo *Macro, 7011 MacroInfo *MacroInfo, 7012 unsigned Argument); 7013 void CodeCompleteNaturalLanguage(); 7014 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 7015 CodeCompletionTUInfo &CCTUInfo, 7016 SmallVectorImpl<CodeCompletionResult> &Results); 7017 //@} 7018 7019 //===--------------------------------------------------------------------===// 7020 // Extra semantic analysis beyond the C type system 7021 7022public: 7023 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 7024 unsigned ByteNo) const; 7025 7026private: 7027 void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, 7028 const ArraySubscriptExpr *ASE=0, 7029 bool AllowOnePastEnd=true, bool IndexNegated=false); 7030 void CheckArrayAccess(const Expr *E); 7031 // Used to grab the relevant information from a FormatAttr and a 7032 // FunctionDeclaration. 7033 struct FormatStringInfo { 7034 unsigned FormatIdx; 7035 unsigned FirstDataArg; 7036 bool HasVAListArg; 7037 }; 7038 7039 bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, 7040 FormatStringInfo *FSI); 7041 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, 7042 const FunctionProtoType *Proto); 7043 bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, 7044 Expr **Args, unsigned NumArgs); 7045 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall, 7046 const FunctionProtoType *Proto); 7047 void CheckConstructorCall(FunctionDecl *FDecl, 7048 Expr **Args, 7049 unsigned NumArgs, 7050 const FunctionProtoType *Proto, 7051 SourceLocation Loc); 7052 7053 void checkCall(NamedDecl *FDecl, Expr **Args, unsigned NumArgs, 7054 unsigned NumProtoArgs, bool IsMemberFunction, 7055 SourceLocation Loc, SourceRange Range, 7056 VariadicCallType CallType); 7057 7058 7059 bool CheckObjCString(Expr *Arg); 7060 7061 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 7062 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 7063 7064 bool SemaBuiltinVAStart(CallExpr *TheCall); 7065 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 7066 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 7067 7068public: 7069 // Used by C++ template instantiation. 7070 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 7071 7072private: 7073 bool SemaBuiltinPrefetch(CallExpr *TheCall); 7074 bool SemaBuiltinObjectSize(CallExpr *TheCall); 7075 bool SemaBuiltinLongjmp(CallExpr *TheCall); 7076 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 7077 ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, 7078 AtomicExpr::AtomicOp Op); 7079 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 7080 llvm::APSInt &Result); 7081 7082 enum FormatStringType { 7083 FST_Scanf, 7084 FST_Printf, 7085 FST_NSString, 7086 FST_Strftime, 7087 FST_Strfmon, 7088 FST_Kprintf, 7089 FST_Unknown 7090 }; 7091 static FormatStringType GetFormatStringType(const FormatAttr *Format); 7092 7093 enum StringLiteralCheckType { 7094 SLCT_NotALiteral, 7095 SLCT_UncheckedLiteral, 7096 SLCT_CheckedLiteral 7097 }; 7098 7099 StringLiteralCheckType checkFormatStringExpr(const Expr *E, 7100 Expr **Args, unsigned NumArgs, 7101 bool HasVAListArg, 7102 unsigned format_idx, 7103 unsigned firstDataArg, 7104 FormatStringType Type, 7105 bool inFunctionCall = true); 7106 7107 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 7108 Expr **Args, unsigned NumArgs, bool HasVAListArg, 7109 unsigned format_idx, unsigned firstDataArg, 7110 FormatStringType Type, bool inFunctionCall); 7111 7112 bool CheckFormatArguments(const FormatAttr *Format, CallExpr *TheCall); 7113 bool CheckFormatArguments(const FormatAttr *Format, Expr **Args, 7114 unsigned NumArgs, bool IsCXXMember, 7115 SourceLocation Loc, SourceRange Range); 7116 bool CheckFormatArguments(Expr **Args, unsigned NumArgs, 7117 bool HasVAListArg, unsigned format_idx, 7118 unsigned firstDataArg, FormatStringType Type, 7119 SourceLocation Loc, SourceRange range); 7120 7121 void CheckNonNullArguments(const NonNullAttr *NonNull, 7122 const Expr * const *ExprArgs, 7123 SourceLocation CallSiteLoc); 7124 7125 void CheckMemaccessArguments(const CallExpr *Call, 7126 unsigned BId, 7127 IdentifierInfo *FnName); 7128 7129 void CheckStrlcpycatArguments(const CallExpr *Call, 7130 IdentifierInfo *FnName); 7131 7132 void CheckStrncatArguments(const CallExpr *Call, 7133 IdentifierInfo *FnName); 7134 7135 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 7136 SourceLocation ReturnLoc); 7137 void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS); 7138 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 7139 7140 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 7141 Expr *Init); 7142 7143 /// \brief The parser's current scope. 7144 /// 7145 /// The parser maintains this state here. 7146 Scope *CurScope; 7147 7148protected: 7149 friend class Parser; 7150 friend class InitializationSequence; 7151 friend class ASTReader; 7152 friend class ASTWriter; 7153 7154public: 7155 /// \brief Retrieve the parser's current scope. 7156 /// 7157 /// This routine must only be used when it is certain that semantic analysis 7158 /// and the parser are in precisely the same context, which is not the case 7159 /// when, e.g., we are performing any kind of template instantiation. 7160 /// Therefore, the only safe places to use this scope are in the parser 7161 /// itself and in routines directly invoked from the parser and *never* from 7162 /// template substitution or instantiation. 7163 Scope *getCurScope() const { return CurScope; } 7164 7165 Decl *getObjCDeclContext() const; 7166 7167 DeclContext *getCurLexicalContext() const { 7168 return OriginalLexicalContext ? OriginalLexicalContext : CurContext; 7169 } 7170 7171 AvailabilityResult getCurContextAvailability() const; 7172}; 7173 7174/// \brief RAII object that enters a new expression evaluation context. 7175class EnterExpressionEvaluationContext { 7176 Sema &Actions; 7177 7178public: 7179 EnterExpressionEvaluationContext(Sema &Actions, 7180 Sema::ExpressionEvaluationContext NewContext, 7181 Decl *LambdaContextDecl = 0, 7182 bool IsDecltype = false) 7183 : Actions(Actions) { 7184 Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl, 7185 IsDecltype); 7186 } 7187 7188 ~EnterExpressionEvaluationContext() { 7189 Actions.PopExpressionEvaluationContext(); 7190 } 7191}; 7192 7193} // end namespace clang 7194 7195#endif 7196