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