Sema.h revision 0129b561a1452bf057f6b18b6a1de815d487ab81
10e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// 20e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// 30e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// The LLVM Compiler Infrastructure 40e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// 50e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// This file is distributed under the University of Illinois Open Source 60e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// License. See LICENSE.TXT for details. 70e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// 80e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//===----------------------------------------------------------------------===// 90e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// 100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// This file defines the Sema class, which performs semantic analysis and 110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// builds ASTs. 120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// 130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//===----------------------------------------------------------------------===// 140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#ifndef LLVM_CLANG_SEMA_SEMA_H 160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#define LLVM_CLANG_SEMA_SEMA_H 170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Sema/Ownership.h" 190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Sema/AnalysisBasedWarnings.h" 200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Sema/IdentifierResolver.h" 210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Sema/ObjCMethodList.h" 220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Sema/DeclSpec.h" 230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Sema/ExternalSemaSource.h" 240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Sema/LocInfoType.h" 250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Sema/TypoCorrection.h" 260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/AST/Expr.h" 270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/AST/DeclarationName.h" 280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/AST/ExternalASTSource.h" 290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/AST/TypeLoc.h" 300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Basic/Specifiers.h" 310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Basic/TemplateKinds.h" 320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "clang/Basic/TypeTraits.h" 33cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "clang/Basic/ExpressionTraits.h" 34cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "llvm/ADT/OwningPtr.h" 35cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "llvm/ADT/SmallPtrSet.h" 360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "llvm/ADT/SmallVector.h" 370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <deque> 380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <string> 390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace llvm { 410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class APSInt; 420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org template <typename ValueT> struct DenseMapInfo; 430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org template <typename ValueT, typename ValueInfoT> class DenseSet; 440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org} 452a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org 460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace clang { 470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ADLResult; 480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ASTConsumer; 490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ASTContext; 500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ASTMutationListener; 510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ASTReader; 520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ASTWriter; 530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ArrayType; 540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class AttributeList; 550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class BlockDecl; 560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXBasePath; 570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXBasePaths; 580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXConstructorDecl; 600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXConversionDecl; 610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXDestructorDecl; 620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXFieldCollector; 630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXMemberCallExpr; 640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXMethodDecl; 650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXScopeSpec; 660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXTemporary; 670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CXXTryStmt; 680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CallExpr; 690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ClassTemplateDecl; 700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ClassTemplatePartialSpecializationDecl; 710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ClassTemplateSpecializationDecl; 722a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org class CodeCompleteConsumer; 730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CodeCompletionAllocator; 740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class CodeCompletionResult; 750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class Decl; 760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class DeclAccessPair; 770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class DeclContext; 780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class DeclRefExpr; 790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class DeclaratorDecl; 802a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org class DeducedTemplateArgument; 810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class DependentDiagnostic; 820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class DesignatedInitExpr; 830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class Designation; 840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class EnumConstantDecl; 850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class Expr; 860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ExtVectorType; 870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ExternalSemaSource; 880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class FormatAttr; 890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class FriendDecl; 900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class FunctionDecl; 910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class FunctionProtoType; 920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class FunctionTemplateDecl; 930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ImplicitConversionSequence; 940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class InitListExpr; 950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class InitializationKind; 960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class InitializationSequence; 970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class InitializedEntity; 980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class IntegerLiteral; 990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class LabelStmt; 1000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class LangOptions; 1010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class LocalInstantiationScope; 1020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class LookupResult; 1030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class MacroInfo; 1040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class MultiLevelTemplateArgumentList; 1050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class NamedDecl; 1060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class NonNullAttr; 1070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCCategoryDecl; 1080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCCategoryImplDecl; 1090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCCompatibleAliasDecl; 1100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCContainerDecl; 1110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCImplDecl; 1120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCImplementationDecl; 1130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCInterfaceDecl; 1140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCIvarDecl; 1150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org template <class T> class ObjCList; 1160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCMessageExpr; 1170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCMethodDecl; 1180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCPropertyDecl; 1190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ObjCProtocolDecl; 1200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class OverloadCandidateSet; 1210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class OverloadExpr; 1222a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org class ParenListExpr; 1230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class ParmVarDecl; 1240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class Preprocessor; 1250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class PseudoDestructorTypeStorage; 1260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class QualType; 1270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class StandardConversionSequence; 1280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class Stmt; 1290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class StringLiteral; 1300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class SwitchStmt; 1310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class TargetAttributesSema; 1320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class TemplateArgument; 1330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class TemplateArgumentList; 134 class TemplateArgumentLoc; 135 class TemplateDecl; 136 class TemplateParameterList; 137 class TemplatePartialOrderingContext; 138 class TemplateTemplateParmDecl; 139 class Token; 140 class TypeAliasDecl; 141 class TypedefDecl; 142 class TypedefNameDecl; 143 class TypeLoc; 144 class UnqualifiedId; 145 class UnresolvedLookupExpr; 146 class UnresolvedMemberExpr; 147 class UnresolvedSetImpl; 148 class UnresolvedSetIterator; 149 class UsingDecl; 150 class UsingShadowDecl; 151 class ValueDecl; 152 class VarDecl; 153 class VisibilityAttr; 154 class VisibleDeclConsumer; 155 class IndirectFieldDecl; 156 157namespace sema { 158 class AccessedEntity; 159 class BlockScopeInfo; 160 class DelayedDiagnostic; 161 class FunctionScopeInfo; 162 class TemplateDeductionInfo; 163} 164 165// FIXME: No way to easily map from TemplateTypeParmTypes to 166// TemplateTypeParmDecls, so we have this horrible PointerUnion. 167typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, 168 SourceLocation> UnexpandedParameterPack; 169 170/// Sema - This implements semantic analysis and AST building for C. 171class Sema { 172 Sema(const Sema&); // DO NOT IMPLEMENT 173 void operator=(const Sema&); // DO NOT IMPLEMENT 174 mutable const TargetAttributesSema* TheTargetAttributesSema; 175public: 176 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 177 typedef OpaquePtr<TemplateName> TemplateTy; 178 typedef OpaquePtr<QualType> TypeTy; 179 typedef Attr AttrTy; 180 typedef CXXBaseSpecifier BaseTy; 181 typedef CXXCtorInitializer MemInitTy; 182 typedef Expr ExprTy; 183 typedef Stmt StmtTy; 184 typedef TemplateParameterList TemplateParamsTy; 185 typedef NestedNameSpecifier CXXScopeTy; 186 187 OpenCLOptions OpenCLFeatures; 188 FPOptions FPFeatures; 189 190 const LangOptions &LangOpts; 191 Preprocessor &PP; 192 ASTContext &Context; 193 ASTConsumer &Consumer; 194 Diagnostic &Diags; 195 SourceManager &SourceMgr; 196 197 /// \brief Flag indicating whether or not to collect detailed statistics. 198 bool CollectStats; 199 200 /// \brief Source of additional semantic information. 201 ExternalSemaSource *ExternalSource; 202 203 /// \brief Code-completion consumer. 204 CodeCompleteConsumer *CodeCompleter; 205 206 /// CurContext - This is the current declaration context of parsing. 207 DeclContext *CurContext; 208 209 /// VAListTagName - The declaration name corresponding to __va_list_tag. 210 /// This is used as part of a hack to omit that class from ADL results. 211 DeclarationName VAListTagName; 212 213 /// PackContext - Manages the stack for #pragma pack. An alignment 214 /// of 0 indicates default alignment. 215 void *PackContext; // Really a "PragmaPackStack*" 216 217 bool MSStructPragmaOn; // True when #pragma ms_struct on 218 219 /// VisContext - Manages the stack for #pragma GCC visibility. 220 void *VisContext; // Really a "PragmaVisStack*" 221 222 /// ExprNeedsCleanups - True if the current evaluation context 223 /// requires cleanups to be run at its conclusion. 224 bool ExprNeedsCleanups; 225 226 /// \brief Stack containing information about each of the nested 227 /// function, block, and method scopes that are currently active. 228 /// 229 /// This array is never empty. Clients should ignore the first 230 /// element, which is used to cache a single FunctionScopeInfo 231 /// that's used to parse every top-level function. 232 SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; 233 234 /// ExprTemporaries - This is the stack of temporaries that are created by 235 /// the current full expression. 236 SmallVector<CXXTemporary*, 8> ExprTemporaries; 237 238 /// ExtVectorDecls - This is a list all the extended vector types. This allows 239 /// us to associate a raw vector type with one of the ext_vector type names. 240 /// This is only necessary for issuing pretty diagnostics. 241 SmallVector<TypedefNameDecl*, 24> ExtVectorDecls; 242 243 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. 244 llvm::OwningPtr<CXXFieldCollector> FieldCollector; 245 246 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; 247 248 /// PureVirtualClassDiagSet - a set of class declarations which we have 249 /// emitted a list of pure virtual functions. Used to prevent emitting the 250 /// same list more than once. 251 llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet; 252 253 /// ParsingInitForAutoVars - a set of declarations with auto types for which 254 /// we are currently parsing the initializer. 255 llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; 256 257 /// \brief A mapping from external names to the most recent 258 /// locally-scoped external declaration with that name. 259 /// 260 /// This map contains external declarations introduced in local 261 /// scoped, e.g., 262 /// 263 /// \code 264 /// void f() { 265 /// void foo(int, int); 266 /// } 267 /// \endcode 268 /// 269 /// Here, the name "foo" will be associated with the declaration on 270 /// "foo" within f. This name is not visible outside of 271 /// "f". However, we still find it in two cases: 272 /// 273 /// - If we are declaring another external with the name "foo", we 274 /// can find "foo" as a previous declaration, so that the types 275 /// of this external declaration can be checked for 276 /// compatibility. 277 /// 278 /// - If we would implicitly declare "foo" (e.g., due to a call to 279 /// "foo" in C when no prototype or definition is visible), then 280 /// we find this declaration of "foo" and complain that it is 281 /// not visible. 282 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls; 283 284 typedef LazyVector<VarDecl *, ExternalSemaSource, 285 &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> 286 TentativeDefinitionsType; 287 288 /// \brief All the tentative definitions encountered in the TU. 289 TentativeDefinitionsType TentativeDefinitions; 290 291 typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, 292 &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> 293 UnusedFileScopedDeclsType; 294 295 /// \brief The set of file scoped decls seen so far that have not been used 296 /// and must warn if not used. Only contains the first declaration. 297 UnusedFileScopedDeclsType UnusedFileScopedDecls; 298 299 typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, 300 &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> 301 DelegatingCtorDeclsType; 302 303 /// \brief All the delegating constructors seen so far in the file, used for 304 /// cycle detection at the end of the TU. 305 DelegatingCtorDeclsType DelegatingCtorDecls; 306 307 /// \brief All the overriding destructors seen during a class definition 308 /// (there could be multiple due to nested classes) that had their exception 309 /// spec checks delayed, plus the overridden destructor. 310 SmallVector<std::pair<const CXXDestructorDecl*, 311 const CXXDestructorDecl*>, 2> 312 DelayedDestructorExceptionSpecChecks; 313 314 /// \brief Callback to the parser to parse templated functions when needed. 315 typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD); 316 LateTemplateParserCB *LateTemplateParser; 317 void *OpaqueParser; 318 319 void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) { 320 LateTemplateParser = LTP; 321 OpaqueParser = P; 322 } 323 324 class DelayedDiagnostics; 325 326 class ParsingDeclState { 327 unsigned SavedStackSize; 328 friend class Sema::DelayedDiagnostics; 329 }; 330 331 class ProcessingContextState { 332 unsigned SavedParsingDepth; 333 unsigned SavedActiveStackBase; 334 friend class Sema::DelayedDiagnostics; 335 }; 336 337 /// A class which encapsulates the logic for delaying diagnostics 338 /// during parsing and other processing. 339 class DelayedDiagnostics { 340 /// \brief The stack of diagnostics that were delayed due to being 341 /// produced during the parsing of a declaration. 342 sema::DelayedDiagnostic *Stack; 343 344 /// \brief The number of objects on the delayed-diagnostics stack. 345 unsigned StackSize; 346 347 /// \brief The current capacity of the delayed-diagnostics stack. 348 unsigned StackCapacity; 349 350 /// \brief The index of the first "active" delayed diagnostic in 351 /// the stack. When parsing class definitions, we ignore active 352 /// delayed diagnostics from the surrounding context. 353 unsigned ActiveStackBase; 354 355 /// \brief The depth of the declarations we're currently parsing. 356 /// This gets saved and reset whenever we enter a class definition. 357 unsigned ParsingDepth; 358 359 public: 360 DelayedDiagnostics() : Stack(0), StackSize(0), StackCapacity(0), 361 ActiveStackBase(0), ParsingDepth(0) {} 362 363 ~DelayedDiagnostics() { 364 delete[] reinterpret_cast<char*>(Stack); 365 } 366 367 /// Adds a delayed diagnostic. 368 void add(const sema::DelayedDiagnostic &diag); 369 370 /// Determines whether diagnostics should be delayed. 371 bool shouldDelayDiagnostics() { return ParsingDepth > 0; } 372 373 /// Observe that we've started parsing a declaration. Access and 374 /// deprecation diagnostics will be delayed; when the declaration 375 /// is completed, all active delayed diagnostics will be evaluated 376 /// in its context, and then active diagnostics stack will be 377 /// popped down to the saved depth. 378 ParsingDeclState pushParsingDecl() { 379 ParsingDepth++; 380 381 ParsingDeclState state; 382 state.SavedStackSize = StackSize; 383 return state; 384 } 385 386 /// Observe that we're completed parsing a declaration. 387 static void popParsingDecl(Sema &S, ParsingDeclState state, Decl *decl); 388 389 /// Observe that we've started processing a different context, the 390 /// contents of which are semantically separate from the 391 /// declarations it may lexically appear in. This sets aside the 392 /// current stack of active diagnostics and starts afresh. 393 ProcessingContextState pushContext() { 394 assert(StackSize >= ActiveStackBase); 395 396 ProcessingContextState state; 397 state.SavedParsingDepth = ParsingDepth; 398 state.SavedActiveStackBase = ActiveStackBase; 399 400 ActiveStackBase = StackSize; 401 ParsingDepth = 0; 402 403 return state; 404 } 405 406 /// Observe that we've stopped processing a context. This 407 /// restores the previous stack of active diagnostics. 408 void popContext(ProcessingContextState state) { 409 assert(ActiveStackBase == StackSize); 410 assert(ParsingDepth == 0); 411 ActiveStackBase = state.SavedActiveStackBase; 412 ParsingDepth = state.SavedParsingDepth; 413 } 414 } DelayedDiagnostics; 415 416 /// A RAII object to temporarily push a declaration context. 417 class ContextRAII { 418 private: 419 Sema &S; 420 DeclContext *SavedContext; 421 ProcessingContextState SavedContextState; 422 423 public: 424 ContextRAII(Sema &S, DeclContext *ContextToPush) 425 : S(S), SavedContext(S.CurContext), 426 SavedContextState(S.DelayedDiagnostics.pushContext()) 427 { 428 assert(ContextToPush && "pushing null context"); 429 S.CurContext = ContextToPush; 430 } 431 432 void pop() { 433 if (!SavedContext) return; 434 S.CurContext = SavedContext; 435 S.DelayedDiagnostics.popContext(SavedContextState); 436 SavedContext = 0; 437 } 438 439 ~ContextRAII() { 440 pop(); 441 } 442 }; 443 444 /// WeakUndeclaredIdentifiers - Identifiers contained in 445 /// #pragma weak before declared. rare. may alias another 446 /// identifier, declared or undeclared 447 class WeakInfo { 448 IdentifierInfo *alias; // alias (optional) 449 SourceLocation loc; // for diagnostics 450 bool used; // identifier later declared? 451 public: 452 WeakInfo() 453 : alias(0), loc(SourceLocation()), used(false) {} 454 WeakInfo(IdentifierInfo *Alias, SourceLocation Loc) 455 : alias(Alias), loc(Loc), used(false) {} 456 inline IdentifierInfo * getAlias() const { return alias; } 457 inline SourceLocation getLocation() const { return loc; } 458 void setUsed(bool Used=true) { used = Used; } 459 inline bool getUsed() { return used; } 460 bool operator==(WeakInfo RHS) const { 461 return alias == RHS.getAlias() && loc == RHS.getLocation(); 462 } 463 bool operator!=(WeakInfo RHS) const { return !(*this == RHS); } 464 }; 465 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers; 466 467 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by 468 /// #pragma weak during processing of other Decls. 469 /// I couldn't figure out a clean way to generate these in-line, so 470 /// we store them here and handle separately -- which is a hack. 471 /// It would be best to refactor this. 472 SmallVector<Decl*,2> WeakTopLevelDecl; 473 474 IdentifierResolver IdResolver; 475 476 /// Translation Unit Scope - useful to Objective-C actions that need 477 /// to lookup file scope declarations in the "ordinary" C decl namespace. 478 /// For example, user-defined classes, built-in "id" type, etc. 479 Scope *TUScope; 480 481 /// \brief The C++ "std" namespace, where the standard library resides. 482 LazyDeclPtr StdNamespace; 483 484 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++ 485 /// standard library. 486 LazyDeclPtr StdBadAlloc; 487 488 /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>. 489 RecordDecl *CXXTypeInfoDecl; 490 491 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files. 492 RecordDecl *MSVCGuidDecl; 493 494 /// A flag to remember whether the implicit forms of operator new and delete 495 /// have been declared. 496 bool GlobalNewDeleteDeclared; 497 498 /// \brief The set of declarations that have been referenced within 499 /// a potentially evaluated expression. 500 typedef SmallVector<std::pair<SourceLocation, Decl *>, 10> 501 PotentiallyReferencedDecls; 502 503 /// \brief A set of diagnostics that may be emitted. 504 typedef SmallVector<std::pair<SourceLocation, PartialDiagnostic>, 10> 505 PotentiallyEmittedDiagnostics; 506 507 /// \brief Describes how the expressions currently being parsed are 508 /// evaluated at run-time, if at all. 509 enum ExpressionEvaluationContext { 510 /// \brief The current expression and its subexpressions occur within an 511 /// unevaluated operand (C++0x [expr]p8), such as a constant expression 512 /// or the subexpression of \c sizeof, where the type or the value of the 513 /// expression may be significant but no code will be generated to evaluate 514 /// the value of the expression at run time. 515 Unevaluated, 516 517 /// \brief The current expression is potentially evaluated at run time, 518 /// which means that code may be generated to evaluate the value of the 519 /// expression at run time. 520 PotentiallyEvaluated, 521 522 /// \brief The current expression may be potentially evaluated or it may 523 /// be unevaluated, but it is impossible to tell from the lexical context. 524 /// This evaluation context is used primary for the operand of the C++ 525 /// \c typeid expression, whose argument is potentially evaluated only when 526 /// it is an lvalue of polymorphic class type (C++ [basic.def.odr]p2). 527 PotentiallyPotentiallyEvaluated, 528 529 /// \brief The current expression is potentially evaluated, but any 530 /// declarations referenced inside that expression are only used if 531 /// in fact the current expression is used. 532 /// 533 /// This value is used when parsing default function arguments, for which 534 /// we would like to provide diagnostics (e.g., passing non-POD arguments 535 /// through varargs) but do not want to mark declarations as "referenced" 536 /// until the default argument is used. 537 PotentiallyEvaluatedIfUsed 538 }; 539 540 /// \brief Data structure used to record current or nested 541 /// expression evaluation contexts. 542 struct ExpressionEvaluationContextRecord { 543 /// \brief The expression evaluation context. 544 ExpressionEvaluationContext Context; 545 546 /// \brief Whether the enclosing context needed a cleanup. 547 bool ParentNeedsCleanups; 548 549 /// \brief The number of temporaries that were active when we 550 /// entered this expression evaluation context. 551 unsigned NumTemporaries; 552 553 /// \brief The set of declarations referenced within a 554 /// potentially potentially-evaluated context. 555 /// 556 /// When leaving a potentially potentially-evaluated context, each 557 /// of these elements will be as referenced if the corresponding 558 /// potentially potentially evaluated expression is potentially 559 /// evaluated. 560 PotentiallyReferencedDecls *PotentiallyReferenced; 561 562 /// \brief The set of diagnostics to emit should this potentially 563 /// potentially-evaluated context become evaluated. 564 PotentiallyEmittedDiagnostics *PotentiallyDiagnosed; 565 566 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, 567 unsigned NumTemporaries, 568 bool ParentNeedsCleanups) 569 : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups), 570 NumTemporaries(NumTemporaries), 571 PotentiallyReferenced(0), PotentiallyDiagnosed(0) { } 572 573 void addReferencedDecl(SourceLocation Loc, Decl *Decl) { 574 if (!PotentiallyReferenced) 575 PotentiallyReferenced = new PotentiallyReferencedDecls; 576 PotentiallyReferenced->push_back(std::make_pair(Loc, Decl)); 577 } 578 579 void addDiagnostic(SourceLocation Loc, const PartialDiagnostic &PD) { 580 if (!PotentiallyDiagnosed) 581 PotentiallyDiagnosed = new PotentiallyEmittedDiagnostics; 582 PotentiallyDiagnosed->push_back(std::make_pair(Loc, PD)); 583 } 584 585 void Destroy() { 586 delete PotentiallyReferenced; 587 delete PotentiallyDiagnosed; 588 PotentiallyReferenced = 0; 589 PotentiallyDiagnosed = 0; 590 } 591 }; 592 593 /// A stack of expression evaluation contexts. 594 SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; 595 596 /// SpecialMemberOverloadResult - The overloading result for a special member 597 /// function. 598 /// 599 /// This is basically a wrapper around PointerIntPair. The lowest bit of the 600 /// integer is used to determine whether we have a parameter qualification 601 /// match, the second-lowest is whether we had success in resolving the 602 /// overload to a unique non-deleted function. 603 /// 604 /// The ConstParamMatch bit represents whether, when looking up a copy 605 /// constructor or assignment operator, we found a potential copy 606 /// constructor/assignment operator whose first parameter is const-qualified. 607 /// This is used for determining parameter types of other objects and is 608 /// utterly meaningless on other types of special members. 609 class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode { 610 llvm::PointerIntPair<CXXMethodDecl*, 2> Pair; 611 public: 612 SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID) 613 : FastFoldingSetNode(ID) 614 {} 615 616 CXXMethodDecl *getMethod() const { return Pair.getPointer(); } 617 void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } 618 619 bool hasSuccess() const { return Pair.getInt() & 0x1; } 620 void setSuccess(bool B) { 621 Pair.setInt(unsigned(B) | hasConstParamMatch() << 1); 622 } 623 624 bool hasConstParamMatch() const { return Pair.getInt() & 0x2; } 625 void setConstParamMatch(bool B) { 626 Pair.setInt(B << 1 | unsigned(hasSuccess())); 627 } 628 }; 629 630 /// \brief A cache of special member function overload resolution results 631 /// for C++ records. 632 llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache; 633 634 /// \brief Whether the code handled by Sema should be considered a 635 /// complete translation unit or not. 636 /// 637 /// When true (which is generally the case), Sema will perform 638 /// end-of-translation-unit semantic tasks (such as creating 639 /// initializers for tentative definitions in C) once parsing has 640 /// completed. This flag will be false when building PCH files, 641 /// since a PCH file is by definition not a complete translation 642 /// unit. 643 bool CompleteTranslationUnit; 644 645 llvm::BumpPtrAllocator BumpAlloc; 646 647 /// \brief The number of SFINAE diagnostics that have been trapped. 648 unsigned NumSFINAEErrors; 649 650 typedef llvm::DenseMap<ParmVarDecl *, SmallVector<ParmVarDecl *, 1> > 651 UnparsedDefaultArgInstantiationsMap; 652 653 /// \brief A mapping from parameters with unparsed default arguments to the 654 /// set of instantiations of each parameter. 655 /// 656 /// This mapping is a temporary data structure used when parsing 657 /// nested class templates or nested classes of class templates, 658 /// where we might end up instantiating an inner class before the 659 /// default arguments of its methods have been parsed. 660 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; 661 662 // Contains the locations of the beginning of unparsed default 663 // argument locations. 664 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs; 665 666 /// UndefinedInternals - all the used, undefined objects with 667 /// internal linkage in this translation unit. 668 llvm::DenseMap<NamedDecl*, SourceLocation> UndefinedInternals; 669 670 typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods; 671 typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool; 672 673 /// Method Pool - allows efficient lookup when typechecking messages to "id". 674 /// We need to maintain a list, since selectors can have differing signatures 675 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% 676 /// of selectors are "overloaded"). 677 GlobalMethodPool MethodPool; 678 679 /// Method selectors used in a @selector expression. Used for implementation 680 /// of -Wselector. 681 llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors; 682 683 GlobalMethodPool::iterator ReadMethodPool(Selector Sel); 684 685 /// Private Helper predicate to check for 'self'. 686 bool isSelfExpr(Expr *RExpr); 687public: 688 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, 689 bool CompleteTranslationUnit = true, 690 CodeCompleteConsumer *CompletionConsumer = 0); 691 ~Sema(); 692 693 /// \brief Perform initialization that occurs after the parser has been 694 /// initialized but before it parses anything. 695 void Initialize(); 696 697 const LangOptions &getLangOptions() const { return LangOpts; } 698 OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } 699 FPOptions &getFPOptions() { return FPFeatures; } 700 701 Diagnostic &getDiagnostics() const { return Diags; } 702 SourceManager &getSourceManager() const { return SourceMgr; } 703 const TargetAttributesSema &getTargetAttributesSema() const; 704 Preprocessor &getPreprocessor() const { return PP; } 705 ASTContext &getASTContext() const { return Context; } 706 ASTConsumer &getASTConsumer() const { return Consumer; } 707 ASTMutationListener *getASTMutationListener() const; 708 709 void PrintStats() const; 710 711 /// \brief Helper class that creates diagnostics with optional 712 /// template instantiation stacks. 713 /// 714 /// This class provides a wrapper around the basic DiagnosticBuilder 715 /// class that emits diagnostics. SemaDiagnosticBuilder is 716 /// responsible for emitting the diagnostic (as DiagnosticBuilder 717 /// does) and, if the diagnostic comes from inside a template 718 /// instantiation, printing the template instantiation stack as 719 /// well. 720 class SemaDiagnosticBuilder : public DiagnosticBuilder { 721 Sema &SemaRef; 722 unsigned DiagID; 723 724 public: 725 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) 726 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } 727 728 explicit SemaDiagnosticBuilder(Sema &SemaRef) 729 : DiagnosticBuilder(DiagnosticBuilder::Suppress), SemaRef(SemaRef) { } 730 731 ~SemaDiagnosticBuilder(); 732 }; 733 734 /// \brief Emit a diagnostic. 735 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 736 737 /// \brief Emit a partial diagnostic. 738 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD); 739 740 /// \brief Build a partial diagnostic. 741 PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h 742 743 bool findMacroSpelling(SourceLocation &loc, StringRef name); 744 745 ExprResult Owned(Expr* E) { return E; } 746 ExprResult Owned(ExprResult R) { return R; } 747 StmtResult Owned(Stmt* S) { return S; } 748 749 void ActOnEndOfTranslationUnit(); 750 751 void CheckDelegatingCtorCycles(); 752 753 Scope *getScopeForContext(DeclContext *Ctx); 754 755 void PushFunctionScope(); 756 void PushBlockScope(Scope *BlockScope, BlockDecl *Block); 757 void PopFunctionOrBlockScope(const sema::AnalysisBasedWarnings::Policy *WP =0, 758 const Decl *D = 0, const BlockExpr *blkExpr = 0); 759 760 sema::FunctionScopeInfo *getCurFunction() const { 761 return FunctionScopes.back(); 762 } 763 764 bool hasAnyUnrecoverableErrorsInThisFunction() const; 765 766 /// \brief Retrieve the current block, if any. 767 sema::BlockScopeInfo *getCurBlock(); 768 769 /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls 770 SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; } 771 772 //===--------------------------------------------------------------------===// 773 // Type Analysis / Processing: SemaType.cpp. 774 // 775 776 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs); 777 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) { 778 return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR)); 779 } 780 QualType BuildPointerType(QualType T, 781 SourceLocation Loc, DeclarationName Entity); 782 QualType BuildReferenceType(QualType T, bool LValueRef, 783 SourceLocation Loc, DeclarationName Entity); 784 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, 785 Expr *ArraySize, unsigned Quals, 786 SourceRange Brackets, DeclarationName Entity); 787 QualType BuildExtVectorType(QualType T, Expr *ArraySize, 788 SourceLocation AttrLoc); 789 QualType BuildFunctionType(QualType T, 790 QualType *ParamTypes, unsigned NumParamTypes, 791 bool Variadic, unsigned Quals, 792 RefQualifierKind RefQualifier, 793 SourceLocation Loc, DeclarationName Entity, 794 FunctionType::ExtInfo Info); 795 QualType BuildMemberPointerType(QualType T, QualType Class, 796 SourceLocation Loc, 797 DeclarationName Entity); 798 QualType BuildBlockPointerType(QualType T, 799 SourceLocation Loc, DeclarationName Entity); 800 QualType BuildParenType(QualType T); 801 802 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); 803 TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); 804 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T, 805 TypeSourceInfo *ReturnTypeInfo); 806 /// \brief Package the given type and TSI into a ParsedType. 807 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); 808 DeclarationNameInfo GetNameForDeclarator(Declarator &D); 809 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); 810 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0); 811 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range); 812 bool CheckDistantExceptionSpec(QualType T); 813 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); 814 bool CheckEquivalentExceptionSpec( 815 const FunctionProtoType *Old, SourceLocation OldLoc, 816 const FunctionProtoType *New, SourceLocation NewLoc); 817 bool CheckEquivalentExceptionSpec( 818 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 819 const FunctionProtoType *Old, SourceLocation OldLoc, 820 const FunctionProtoType *New, SourceLocation NewLoc, 821 bool *MissingExceptionSpecification = 0, 822 bool *MissingEmptyExceptionSpecification = 0, 823 bool AllowNoexceptAllMatchWithNoSpec = false, 824 bool IsOperatorNew = false); 825 bool CheckExceptionSpecSubset( 826 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 827 const FunctionProtoType *Superset, SourceLocation SuperLoc, 828 const FunctionProtoType *Subset, SourceLocation SubLoc); 829 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID, 830 const FunctionProtoType *Target, SourceLocation TargetLoc, 831 const FunctionProtoType *Source, SourceLocation SourceLoc); 832 833 TypeResult ActOnTypeName(Scope *S, Declarator &D); 834 835 bool RequireCompleteType(SourceLocation Loc, QualType T, 836 const PartialDiagnostic &PD, 837 std::pair<SourceLocation, PartialDiagnostic> Note); 838 bool RequireCompleteType(SourceLocation Loc, QualType T, 839 const PartialDiagnostic &PD); 840 bool RequireCompleteType(SourceLocation Loc, QualType T, 841 unsigned DiagID); 842 bool RequireCompleteExprType(Expr *E, const PartialDiagnostic &PD, 843 std::pair<SourceLocation, 844 PartialDiagnostic> Note); 845 846 847 QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 848 const CXXScopeSpec &SS, QualType T); 849 850 QualType BuildTypeofExprType(Expr *E, SourceLocation Loc); 851 QualType BuildDecltypeType(Expr *E, SourceLocation Loc); 852 QualType BuildUnaryTransformType(QualType BaseType, 853 UnaryTransformType::UTTKind UKind, 854 SourceLocation Loc); 855 856 //===--------------------------------------------------------------------===// 857 // Symbol table / Decl tracking callbacks: SemaDecl.cpp. 858 // 859 860 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0); 861 862 void DiagnoseUseOfUnimplementedSelectors(); 863 864 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc, 865 Scope *S, CXXScopeSpec *SS = 0, 866 bool isClassName = false, 867 bool HasTrailingDot = false, 868 ParsedType ObjectType = ParsedType(), 869 bool WantNontrivialTypeSourceInfo = false); 870 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); 871 bool isMicrosoftMissingTypename(const CXXScopeSpec *SS); 872 bool DiagnoseUnknownTypeName(const IdentifierInfo &II, 873 SourceLocation IILoc, 874 Scope *S, 875 CXXScopeSpec *SS, 876 ParsedType &SuggestedType); 877 878 /// \brief Describes the result of the name lookup and resolution performed 879 /// by \c ClassifyName(). 880 enum NameClassificationKind { 881 NC_Unknown, 882 NC_Error, 883 NC_Keyword, 884 NC_Type, 885 NC_Expression, 886 NC_NestedNameSpecifier, 887 NC_TypeTemplate, 888 NC_FunctionTemplate 889 }; 890 891 class NameClassification { 892 NameClassificationKind Kind; 893 ExprResult Expr; 894 TemplateName Template; 895 ParsedType Type; 896 const IdentifierInfo *Keyword; 897 898 explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} 899 900 public: 901 NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {} 902 903 NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} 904 905 NameClassification(const IdentifierInfo *Keyword) 906 : Kind(NC_Keyword), Keyword(Keyword) { } 907 908 static NameClassification Error() { 909 return NameClassification(NC_Error); 910 } 911 912 static NameClassification Unknown() { 913 return NameClassification(NC_Unknown); 914 } 915 916 static NameClassification NestedNameSpecifier() { 917 return NameClassification(NC_NestedNameSpecifier); 918 } 919 920 static NameClassification TypeTemplate(TemplateName Name) { 921 NameClassification Result(NC_TypeTemplate); 922 Result.Template = Name; 923 return Result; 924 } 925 926 static NameClassification FunctionTemplate(TemplateName Name) { 927 NameClassification Result(NC_FunctionTemplate); 928 Result.Template = Name; 929 return Result; 930 } 931 932 NameClassificationKind getKind() const { return Kind; } 933 934 ParsedType getType() const { 935 assert(Kind == NC_Type); 936 return Type; 937 } 938 939 ExprResult getExpression() const { 940 assert(Kind == NC_Expression); 941 return Expr; 942 } 943 944 TemplateName getTemplateName() const { 945 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate); 946 return Template; 947 } 948 949 TemplateNameKind getTemplateNameKind() const { 950 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate); 951 return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template; 952 } 953}; 954 955 /// \brief Perform name lookup on the given name, classifying it based on 956 /// the results of name lookup and the following token. 957 /// 958 /// This routine is used by the parser to resolve identifiers and help direct 959 /// parsing. When the identifier cannot be found, this routine will attempt 960 /// to correct the typo and classify based on the resulting name. 961 /// 962 /// \param S The scope in which we're performing name lookup. 963 /// 964 /// \param SS The nested-name-specifier that precedes the name. 965 /// 966 /// \param Name The identifier. If typo correction finds an alternative name, 967 /// this pointer parameter will be updated accordingly. 968 /// 969 /// \param NameLoc The location of the identifier. 970 /// 971 /// \param NextToken The token following the identifier. Used to help 972 /// disambiguate the name. 973 NameClassification ClassifyName(Scope *S, 974 CXXScopeSpec &SS, 975 IdentifierInfo *&Name, 976 SourceLocation NameLoc, 977 const Token &NextToken); 978 979 Decl *ActOnDeclarator(Scope *S, Declarator &D); 980 981 Decl *HandleDeclarator(Scope *S, Declarator &D, 982 MultiTemplateParamsArg TemplateParameterLists, 983 bool IsFunctionDefinition); 984 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, 985 const LookupResult &Previous, 986 Scope *S); 987 bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); 988 void DiagnoseFunctionSpecifiers(Declarator& D); 989 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R); 990 void CheckShadow(Scope *S, VarDecl *D); 991 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); 992 void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); 993 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, 994 QualType R, TypeSourceInfo *TInfo, 995 LookupResult &Previous, bool &Redeclaration); 996 NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, 997 LookupResult &Previous, bool &Redeclaration); 998 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, 999 QualType R, TypeSourceInfo *TInfo, 1000 LookupResult &Previous, 1001 MultiTemplateParamsArg TemplateParamLists, 1002 bool &Redeclaration); 1003 void CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous, 1004 bool &Redeclaration); 1005 void CheckCompleteVariableDeclaration(VarDecl *var); 1006 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1007 QualType R, TypeSourceInfo *TInfo, 1008 LookupResult &Previous, 1009 MultiTemplateParamsArg TemplateParamLists, 1010 bool IsFunctionDefinition, 1011 bool &Redeclaration); 1012 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 1013 void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 1014 void CheckFunctionDeclaration(Scope *S, 1015 FunctionDecl *NewFD, LookupResult &Previous, 1016 bool IsExplicitSpecialization, 1017 bool &Redeclaration); 1018 void CheckMain(FunctionDecl *FD); 1019 Decl *ActOnParamDeclarator(Scope *S, Declarator &D); 1020 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, 1021 SourceLocation Loc, 1022 QualType T); 1023 ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, 1024 SourceLocation NameLoc, IdentifierInfo *Name, 1025 QualType T, TypeSourceInfo *TSInfo, 1026 StorageClass SC, StorageClass SCAsWritten); 1027 void ActOnParamDefaultArgument(Decl *param, 1028 SourceLocation EqualLoc, 1029 Expr *defarg); 1030 void ActOnParamUnparsedDefaultArgument(Decl *param, 1031 SourceLocation EqualLoc, 1032 SourceLocation ArgLoc); 1033 void ActOnParamDefaultArgumentError(Decl *param); 1034 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, 1035 SourceLocation EqualLoc); 1036 1037 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit, 1038 bool TypeMayContainAuto); 1039 void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto); 1040 void ActOnInitializerError(Decl *Dcl); 1041 void ActOnCXXForRangeDecl(Decl *D); 1042 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); 1043 void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); 1044 void FinalizeDeclaration(Decl *D); 1045 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, 1046 Decl **Group, 1047 unsigned NumDecls); 1048 DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls, 1049 bool TypeMayContainAuto = true); 1050 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, 1051 SourceLocation LocAfterDecls); 1052 void CheckForFunctionRedefinition(FunctionDecl *FD); 1053 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D); 1054 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D); 1055 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); 1056 1057 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); 1058 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); 1059 1060 /// \brief Diagnose any unused parameters in the given sequence of 1061 /// ParmVarDecl pointers. 1062 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin, 1063 ParmVarDecl * const *End); 1064 1065 /// \brief Diagnose whether the size of parameters or return value of a 1066 /// function or obj-c method definition is pass-by-value and larger than a 1067 /// specified threshold. 1068 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin, 1069 ParmVarDecl * const *End, 1070 QualType ReturnTy, 1071 NamedDecl *D); 1072 1073 void DiagnoseInvalidJumps(Stmt *Body); 1074 Decl *ActOnFileScopeAsmDecl(Expr *expr, 1075 SourceLocation AsmLoc, 1076 SourceLocation RParenLoc); 1077 1078 /// Scope actions. 1079 void ActOnPopScope(SourceLocation Loc, Scope *S); 1080 void ActOnTranslationUnitScope(Scope *S); 1081 1082 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 1083 DeclSpec &DS); 1084 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 1085 DeclSpec &DS, 1086 MultiTemplateParamsArg TemplateParams); 1087 1088 StmtResult ActOnVlaStmt(const DeclSpec &DS); 1089 1090 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, 1091 AccessSpecifier AS, 1092 RecordDecl *Record); 1093 1094 Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, 1095 RecordDecl *Record); 1096 1097 bool isAcceptableTagRedeclaration(const TagDecl *Previous, 1098 TagTypeKind NewTag, bool isDefinition, 1099 SourceLocation NewTagLoc, 1100 const IdentifierInfo &Name); 1101 1102 enum TagUseKind { 1103 TUK_Reference, // Reference to a tag: 'struct foo *X;' 1104 TUK_Declaration, // Fwd decl of a tag: 'struct foo;' 1105 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' 1106 TUK_Friend // Friend declaration: 'friend struct foo;' 1107 }; 1108 1109 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, 1110 SourceLocation KWLoc, CXXScopeSpec &SS, 1111 IdentifierInfo *Name, SourceLocation NameLoc, 1112 AttributeList *Attr, AccessSpecifier AS, 1113 MultiTemplateParamsArg TemplateParameterLists, 1114 bool &OwnedDecl, bool &IsDependent, bool ScopedEnum, 1115 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType); 1116 1117 Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, 1118 unsigned TagSpec, SourceLocation TagLoc, 1119 CXXScopeSpec &SS, 1120 IdentifierInfo *Name, SourceLocation NameLoc, 1121 AttributeList *Attr, 1122 MultiTemplateParamsArg TempParamLists); 1123 1124 TypeResult ActOnDependentTag(Scope *S, 1125 unsigned TagSpec, 1126 TagUseKind TUK, 1127 const CXXScopeSpec &SS, 1128 IdentifierInfo *Name, 1129 SourceLocation TagLoc, 1130 SourceLocation NameLoc); 1131 1132 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, 1133 IdentifierInfo *ClassName, 1134 SmallVectorImpl<Decl *> &Decls); 1135 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, 1136 Declarator &D, Expr *BitfieldWidth); 1137 1138 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, 1139 Declarator &D, Expr *BitfieldWidth, bool HasInit, 1140 AccessSpecifier AS); 1141 1142 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, 1143 TypeSourceInfo *TInfo, 1144 RecordDecl *Record, SourceLocation Loc, 1145 bool Mutable, Expr *BitfieldWidth, bool HasInit, 1146 SourceLocation TSSL, 1147 AccessSpecifier AS, NamedDecl *PrevDecl, 1148 Declarator *D = 0); 1149 1150 enum CXXSpecialMember { 1151 CXXDefaultConstructor, 1152 CXXCopyConstructor, 1153 CXXMoveConstructor, 1154 CXXCopyAssignment, 1155 CXXMoveAssignment, 1156 CXXDestructor, 1157 CXXInvalid 1158 }; 1159 bool CheckNontrivialField(FieldDecl *FD); 1160 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem); 1161 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD); 1162 void ActOnLastBitfield(SourceLocation DeclStart, Decl *IntfDecl, 1163 SmallVectorImpl<Decl *> &AllIvarDecls); 1164 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Decl *IntfDecl, 1165 Declarator &D, Expr *BitfieldWidth, 1166 tok::ObjCKeywordKind visibility); 1167 1168 // This is used for both record definitions and ObjC interface declarations. 1169 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl, 1170 Decl **Fields, unsigned NumFields, 1171 SourceLocation LBrac, SourceLocation RBrac, 1172 AttributeList *AttrList); 1173 1174 /// ActOnTagStartDefinition - Invoked when we have entered the 1175 /// scope of a tag's definition (e.g., for an enumeration, class, 1176 /// struct, or union). 1177 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); 1178 1179 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a 1180 /// C++ record definition's base-specifiers clause and are starting its 1181 /// member declarations. 1182 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, 1183 SourceLocation FinalLoc, 1184 SourceLocation LBraceLoc); 1185 1186 /// ActOnTagFinishDefinition - Invoked once we have finished parsing 1187 /// the definition of a tag (enumeration, class, struct, or union). 1188 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, 1189 SourceLocation RBraceLoc); 1190 1191 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable 1192 /// error parsing the definition of a tag. 1193 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); 1194 1195 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, 1196 EnumConstantDecl *LastEnumConst, 1197 SourceLocation IdLoc, 1198 IdentifierInfo *Id, 1199 Expr *val); 1200 1201 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, 1202 SourceLocation IdLoc, IdentifierInfo *Id, 1203 AttributeList *Attrs, 1204 SourceLocation EqualLoc, Expr *Val); 1205 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, 1206 SourceLocation RBraceLoc, Decl *EnumDecl, 1207 Decl **Elements, unsigned NumElements, 1208 Scope *S, AttributeList *Attr); 1209 1210 DeclContext *getContainingDC(DeclContext *DC); 1211 1212 /// Set the current declaration context until it gets popped. 1213 void PushDeclContext(Scope *S, DeclContext *DC); 1214 void PopDeclContext(); 1215 1216 /// EnterDeclaratorContext - Used when we must lookup names in the context 1217 /// of a declarator's nested name specifier. 1218 void EnterDeclaratorContext(Scope *S, DeclContext *DC); 1219 void ExitDeclaratorContext(Scope *S); 1220 1221 DeclContext *getFunctionLevelDeclContext(); 1222 1223 /// getCurFunctionDecl - If inside of a function body, this returns a pointer 1224 /// to the function decl for the function being parsed. If we're currently 1225 /// in a 'block', this returns the containing context. 1226 FunctionDecl *getCurFunctionDecl(); 1227 1228 /// getCurMethodDecl - If inside of a method body, this returns a pointer to 1229 /// the method decl for the method being parsed. If we're currently 1230 /// in a 'block', this returns the containing context. 1231 ObjCMethodDecl *getCurMethodDecl(); 1232 1233 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method 1234 /// or C function we're in, otherwise return null. If we're currently 1235 /// in a 'block', this returns the containing context. 1236 NamedDecl *getCurFunctionOrMethodDecl(); 1237 1238 /// Add this decl to the scope shadowed decl chains. 1239 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); 1240 1241 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true 1242 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns 1243 /// true if 'D' belongs to the given declaration context. 1244 /// 1245 /// \param ExplicitInstantiationOrSpecialization When true, we are checking 1246 /// whether the declaration is in scope for the purposes of explicit template 1247 /// instantiation or specialization. The default is false. 1248 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0, 1249 bool ExplicitInstantiationOrSpecialization = false); 1250 1251 /// Finds the scope corresponding to the given decl context, if it 1252 /// happens to be an enclosing scope. Otherwise return NULL. 1253 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); 1254 1255 /// Subroutines of ActOnDeclarator(). 1256 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, 1257 TypeSourceInfo *TInfo); 1258 void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls); 1259 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old); 1260 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old); 1261 void mergeObjCMethodDecls(ObjCMethodDecl *New, const ObjCMethodDecl *Old); 1262 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls); 1263 void MergeVarDeclTypes(VarDecl *New, VarDecl *Old); 1264 void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); 1265 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old); 1266 1267 // AssignmentAction - This is used by all the assignment diagnostic functions 1268 // to represent what is actually causing the operation 1269 enum AssignmentAction { 1270 AA_Assigning, 1271 AA_Passing, 1272 AA_Returning, 1273 AA_Converting, 1274 AA_Initializing, 1275 AA_Sending, 1276 AA_Casting 1277 }; 1278 1279 /// C++ Overloading. 1280 enum OverloadKind { 1281 /// This is a legitimate overload: the existing declarations are 1282 /// functions or function templates with different signatures. 1283 Ovl_Overload, 1284 1285 /// This is not an overload because the signature exactly matches 1286 /// an existing declaration. 1287 Ovl_Match, 1288 1289 /// This is not an overload because the lookup results contain a 1290 /// non-function. 1291 Ovl_NonFunction 1292 }; 1293 OverloadKind CheckOverload(Scope *S, 1294 FunctionDecl *New, 1295 const LookupResult &OldDecls, 1296 NamedDecl *&OldDecl, 1297 bool IsForUsingDecl); 1298 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl); 1299 1300 /// \brief Checks availability of the function depending on the current 1301 /// function context.Inside an unavailable function,unavailability is ignored. 1302 /// 1303 /// \returns true if \arg FD is unavailable and current context is inside 1304 /// an available function, false otherwise. 1305 bool isFunctionConsideredUnavailable(FunctionDecl *FD); 1306 1307 ImplicitConversionSequence 1308 TryImplicitConversion(Expr *From, QualType ToType, 1309 bool SuppressUserConversions, 1310 bool AllowExplicit, 1311 bool InOverloadResolution, 1312 bool CStyle, 1313 bool AllowObjCWritebackConversion); 1314 1315 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); 1316 bool IsFloatingPointPromotion(QualType FromType, QualType ToType); 1317 bool IsComplexPromotion(QualType FromType, QualType ToType); 1318 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, 1319 bool InOverloadResolution, 1320 QualType& ConvertedType, bool &IncompatibleObjC); 1321 bool isObjCPointerConversion(QualType FromType, QualType ToType, 1322 QualType& ConvertedType, bool &IncompatibleObjC); 1323 bool isObjCWritebackConversion(QualType FromType, QualType ToType, 1324 QualType &ConvertedType); 1325 bool IsBlockPointerConversion(QualType FromType, QualType ToType, 1326 QualType& ConvertedType); 1327 bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType, 1328 const FunctionProtoType *NewType); 1329 1330 bool CheckPointerConversion(Expr *From, QualType ToType, 1331 CastKind &Kind, 1332 CXXCastPath& BasePath, 1333 bool IgnoreBaseAccess); 1334 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, 1335 bool InOverloadResolution, 1336 QualType &ConvertedType); 1337 bool CheckMemberPointerConversion(Expr *From, QualType ToType, 1338 CastKind &Kind, 1339 CXXCastPath &BasePath, 1340 bool IgnoreBaseAccess); 1341 bool IsQualificationConversion(QualType FromType, QualType ToType, 1342 bool CStyle, bool &ObjCLifetimeConversion); 1343 bool IsNoReturnConversion(QualType FromType, QualType ToType, 1344 QualType &ResultTy); 1345 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); 1346 1347 1348 ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, 1349 const VarDecl *NRVOCandidate, 1350 QualType ResultType, 1351 Expr *Value, 1352 bool AllowNRVO = true); 1353 1354 bool CanPerformCopyInitialization(const InitializedEntity &Entity, 1355 ExprResult Init); 1356 ExprResult PerformCopyInitialization(const InitializedEntity &Entity, 1357 SourceLocation EqualLoc, 1358 ExprResult Init, 1359 bool TopLevelOfInitList = false); 1360 ExprResult PerformObjectArgumentInitialization(Expr *From, 1361 NestedNameSpecifier *Qualifier, 1362 NamedDecl *FoundDecl, 1363 CXXMethodDecl *Method); 1364 1365 ExprResult PerformContextuallyConvertToBool(Expr *From); 1366 ExprResult PerformContextuallyConvertToObjCId(Expr *From); 1367 1368 ExprResult 1369 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE, 1370 const PartialDiagnostic &NotIntDiag, 1371 const PartialDiagnostic &IncompleteDiag, 1372 const PartialDiagnostic &ExplicitConvDiag, 1373 const PartialDiagnostic &ExplicitConvNote, 1374 const PartialDiagnostic &AmbigDiag, 1375 const PartialDiagnostic &AmbigNote, 1376 const PartialDiagnostic &ConvDiag); 1377 1378 ExprResult PerformObjectMemberConversion(Expr *From, 1379 NestedNameSpecifier *Qualifier, 1380 NamedDecl *FoundDecl, 1381 NamedDecl *Member); 1382 1383 // Members have to be NamespaceDecl* or TranslationUnitDecl*. 1384 // TODO: make this is a typesafe union. 1385 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet; 1386 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; 1387 1388 void AddOverloadCandidate(NamedDecl *Function, 1389 DeclAccessPair FoundDecl, 1390 Expr **Args, unsigned NumArgs, 1391 OverloadCandidateSet &CandidateSet); 1392 1393 void AddOverloadCandidate(FunctionDecl *Function, 1394 DeclAccessPair FoundDecl, 1395 Expr **Args, unsigned NumArgs, 1396 OverloadCandidateSet& CandidateSet, 1397 bool SuppressUserConversions = false, 1398 bool PartialOverloading = false); 1399 void AddFunctionCandidates(const UnresolvedSetImpl &Functions, 1400 Expr **Args, unsigned NumArgs, 1401 OverloadCandidateSet& CandidateSet, 1402 bool SuppressUserConversions = false); 1403 void AddMethodCandidate(DeclAccessPair FoundDecl, 1404 QualType ObjectType, 1405 Expr::Classification ObjectClassification, 1406 Expr **Args, unsigned NumArgs, 1407 OverloadCandidateSet& CandidateSet, 1408 bool SuppressUserConversion = false); 1409 void AddMethodCandidate(CXXMethodDecl *Method, 1410 DeclAccessPair FoundDecl, 1411 CXXRecordDecl *ActingContext, QualType ObjectType, 1412 Expr::Classification ObjectClassification, 1413 Expr **Args, unsigned NumArgs, 1414 OverloadCandidateSet& CandidateSet, 1415 bool SuppressUserConversions = false); 1416 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, 1417 DeclAccessPair FoundDecl, 1418 CXXRecordDecl *ActingContext, 1419 TemplateArgumentListInfo *ExplicitTemplateArgs, 1420 QualType ObjectType, 1421 Expr::Classification ObjectClassification, 1422 Expr **Args, unsigned NumArgs, 1423 OverloadCandidateSet& CandidateSet, 1424 bool SuppressUserConversions = false); 1425 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, 1426 DeclAccessPair FoundDecl, 1427 TemplateArgumentListInfo *ExplicitTemplateArgs, 1428 Expr **Args, unsigned NumArgs, 1429 OverloadCandidateSet& CandidateSet, 1430 bool SuppressUserConversions = false); 1431 void AddConversionCandidate(CXXConversionDecl *Conversion, 1432 DeclAccessPair FoundDecl, 1433 CXXRecordDecl *ActingContext, 1434 Expr *From, QualType ToType, 1435 OverloadCandidateSet& CandidateSet); 1436 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, 1437 DeclAccessPair FoundDecl, 1438 CXXRecordDecl *ActingContext, 1439 Expr *From, QualType ToType, 1440 OverloadCandidateSet &CandidateSet); 1441 void AddSurrogateCandidate(CXXConversionDecl *Conversion, 1442 DeclAccessPair FoundDecl, 1443 CXXRecordDecl *ActingContext, 1444 const FunctionProtoType *Proto, 1445 Expr *Object, Expr **Args, unsigned NumArgs, 1446 OverloadCandidateSet& CandidateSet); 1447 void AddMemberOperatorCandidates(OverloadedOperatorKind Op, 1448 SourceLocation OpLoc, 1449 Expr **Args, unsigned NumArgs, 1450 OverloadCandidateSet& CandidateSet, 1451 SourceRange OpRange = SourceRange()); 1452 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, 1453 Expr **Args, unsigned NumArgs, 1454 OverloadCandidateSet& CandidateSet, 1455 bool IsAssignmentOperator = false, 1456 unsigned NumContextualBoolArguments = 0); 1457 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, 1458 SourceLocation OpLoc, 1459 Expr **Args, unsigned NumArgs, 1460 OverloadCandidateSet& CandidateSet); 1461 void AddArgumentDependentLookupCandidates(DeclarationName Name, 1462 bool Operator, 1463 Expr **Args, unsigned NumArgs, 1464 TemplateArgumentListInfo *ExplicitTemplateArgs, 1465 OverloadCandidateSet& CandidateSet, 1466 bool PartialOverloading = false, 1467 bool StdNamespaceIsAssociated = false); 1468 1469 // Emit as a 'note' the specific overload candidate 1470 void NoteOverloadCandidate(FunctionDecl *Fn); 1471 1472 // Emit as a series of 'note's all template and non-templates 1473 // identified by the expression Expr 1474 void NoteAllOverloadCandidates(Expr* E); 1475 1476 // [PossiblyAFunctionType] --> [Return] 1477 // NonFunctionType --> NonFunctionType 1478 // R (A) --> R(A) 1479 // R (*)(A) --> R (A) 1480 // R (&)(A) --> R (A) 1481 // R (S::*)(A) --> R (A) 1482 QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); 1483 1484 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType, 1485 bool Complain, 1486 DeclAccessPair &Found); 1487 1488 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, 1489 bool Complain = false, 1490 DeclAccessPair* Found = 0); 1491 1492 ExprResult ResolveAndFixSingleFunctionTemplateSpecialization( 1493 Expr *SrcExpr, bool DoFunctionPointerConverion = false, 1494 bool Complain = false, 1495 const SourceRange& OpRangeForComplaining = SourceRange(), 1496 QualType DestTypeForComplaining = QualType(), 1497 unsigned DiagIDForComplaining = 0); 1498 1499 1500 Expr *FixOverloadedFunctionReference(Expr *E, 1501 DeclAccessPair FoundDecl, 1502 FunctionDecl *Fn); 1503 ExprResult FixOverloadedFunctionReference(ExprResult, 1504 DeclAccessPair FoundDecl, 1505 FunctionDecl *Fn); 1506 1507 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, 1508 Expr **Args, unsigned NumArgs, 1509 OverloadCandidateSet &CandidateSet, 1510 bool PartialOverloading = false); 1511 1512 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, 1513 UnresolvedLookupExpr *ULE, 1514 SourceLocation LParenLoc, 1515 Expr **Args, unsigned NumArgs, 1516 SourceLocation RParenLoc, 1517 Expr *ExecConfig); 1518 1519 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, 1520 unsigned Opc, 1521 const UnresolvedSetImpl &Fns, 1522 Expr *input); 1523 1524 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, 1525 unsigned Opc, 1526 const UnresolvedSetImpl &Fns, 1527 Expr *LHS, Expr *RHS); 1528 1529 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, 1530 SourceLocation RLoc, 1531 Expr *Base,Expr *Idx); 1532 1533 ExprResult 1534 BuildCallToMemberFunction(Scope *S, Expr *MemExpr, 1535 SourceLocation LParenLoc, Expr **Args, 1536 unsigned NumArgs, SourceLocation RParenLoc); 1537 ExprResult 1538 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, 1539 Expr **Args, unsigned NumArgs, 1540 SourceLocation RParenLoc); 1541 1542 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, 1543 SourceLocation OpLoc); 1544 1545 /// CheckCallReturnType - Checks that a call expression's return type is 1546 /// complete. Returns true on failure. The location passed in is the location 1547 /// that best represents the call. 1548 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, 1549 CallExpr *CE, FunctionDecl *FD); 1550 1551 /// Helpers for dealing with blocks and functions. 1552 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd, 1553 bool CheckParameterNames); 1554 void CheckCXXDefaultArguments(FunctionDecl *FD); 1555 void CheckExtraCXXDefaultArguments(Declarator &D); 1556 Scope *getNonFieldDeclScope(Scope *S); 1557 1558 /// \name Name lookup 1559 /// 1560 /// These routines provide name lookup that is used during semantic 1561 /// analysis to resolve the various kinds of names (identifiers, 1562 /// overloaded operator names, constructor names, etc.) into zero or 1563 /// more declarations within a particular scope. The major entry 1564 /// points are LookupName, which performs unqualified name lookup, 1565 /// and LookupQualifiedName, which performs qualified name lookup. 1566 /// 1567 /// All name lookup is performed based on some specific criteria, 1568 /// which specify what names will be visible to name lookup and how 1569 /// far name lookup should work. These criteria are important both 1570 /// for capturing language semantics (certain lookups will ignore 1571 /// certain names, for example) and for performance, since name 1572 /// lookup is often a bottleneck in the compilation of C++. Name 1573 /// lookup criteria is specified via the LookupCriteria enumeration. 1574 /// 1575 /// The results of name lookup can vary based on the kind of name 1576 /// lookup performed, the current language, and the translation 1577 /// unit. In C, for example, name lookup will either return nothing 1578 /// (no entity found) or a single declaration. In C++, name lookup 1579 /// can additionally refer to a set of overloaded functions or 1580 /// result in an ambiguity. All of the possible results of name 1581 /// lookup are captured by the LookupResult class, which provides 1582 /// the ability to distinguish among them. 1583 //@{ 1584 1585 /// @brief Describes the kind of name lookup to perform. 1586 enum LookupNameKind { 1587 /// Ordinary name lookup, which finds ordinary names (functions, 1588 /// variables, typedefs, etc.) in C and most kinds of names 1589 /// (functions, variables, members, types, etc.) in C++. 1590 LookupOrdinaryName = 0, 1591 /// Tag name lookup, which finds the names of enums, classes, 1592 /// structs, and unions. 1593 LookupTagName, 1594 /// Label name lookup. 1595 LookupLabel, 1596 /// Member name lookup, which finds the names of 1597 /// class/struct/union members. 1598 LookupMemberName, 1599 /// Look up of an operator name (e.g., operator+) for use with 1600 /// operator overloading. This lookup is similar to ordinary name 1601 /// lookup, but will ignore any declarations that are class members. 1602 LookupOperatorName, 1603 /// Look up of a name that precedes the '::' scope resolution 1604 /// operator in C++. This lookup completely ignores operator, object, 1605 /// function, and enumerator names (C++ [basic.lookup.qual]p1). 1606 LookupNestedNameSpecifierName, 1607 /// Look up a namespace name within a C++ using directive or 1608 /// namespace alias definition, ignoring non-namespace names (C++ 1609 /// [basic.lookup.udir]p1). 1610 LookupNamespaceName, 1611 /// Look up all declarations in a scope with the given name, 1612 /// including resolved using declarations. This is appropriate 1613 /// for checking redeclarations for a using declaration. 1614 LookupUsingDeclName, 1615 /// Look up an ordinary name that is going to be redeclared as a 1616 /// name with linkage. This lookup ignores any declarations that 1617 /// are outside of the current scope unless they have linkage. See 1618 /// C99 6.2.2p4-5 and C++ [basic.link]p6. 1619 LookupRedeclarationWithLinkage, 1620 /// Look up the name of an Objective-C protocol. 1621 LookupObjCProtocolName, 1622 /// Look up implicit 'self' parameter of an objective-c method. 1623 LookupObjCImplicitSelfParam, 1624 /// \brief Look up any declaration with any name. 1625 LookupAnyName 1626 }; 1627 1628 /// \brief Specifies whether (or how) name lookup is being performed for a 1629 /// redeclaration (vs. a reference). 1630 enum RedeclarationKind { 1631 /// \brief The lookup is a reference to this name that is not for the 1632 /// purpose of redeclaring the name. 1633 NotForRedeclaration = 0, 1634 /// \brief The lookup results will be used for redeclaration of a name, 1635 /// if an entity by that name already exists. 1636 ForRedeclaration 1637 }; 1638 1639private: 1640 bool CppLookupName(LookupResult &R, Scope *S); 1641 1642 SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D, 1643 CXXSpecialMember SM, 1644 bool ConstArg, 1645 bool VolatileArg, 1646 bool RValueThis, 1647 bool ConstThis, 1648 bool VolatileThis); 1649 1650 // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls. 1651 // 1652 // The boolean value will be true to indicate that the namespace was loaded 1653 // from an AST/PCH file, or false otherwise. 1654 llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces; 1655 1656 /// \brief Whether we have already loaded known namespaces from an extenal 1657 /// source. 1658 bool LoadedExternalKnownNamespaces; 1659 1660public: 1661 /// \brief Look up a name, looking for a single declaration. Return 1662 /// null if the results were absent, ambiguous, or overloaded. 1663 /// 1664 /// It is preferable to use the elaborated form and explicitly handle 1665 /// ambiguity and overloaded. 1666 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, 1667 SourceLocation Loc, 1668 LookupNameKind NameKind, 1669 RedeclarationKind Redecl 1670 = NotForRedeclaration); 1671 bool LookupName(LookupResult &R, Scope *S, 1672 bool AllowBuiltinCreation = false); 1673 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, 1674 bool InUnqualifiedLookup = false); 1675 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, 1676 bool AllowBuiltinCreation = false, 1677 bool EnteringContext = false); 1678 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc); 1679 1680 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, 1681 QualType T1, QualType T2, 1682 UnresolvedSetImpl &Functions); 1683 1684 LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, 1685 SourceLocation GnuLabelLoc = SourceLocation()); 1686 1687 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); 1688 CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); 1689 CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, 1690 unsigned Quals, 1691 bool *ConstParam = 0); 1692 CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, 1693 bool RValueThis, unsigned ThisQuals, 1694 bool *ConstParam = 0); 1695 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); 1696 1697 void ArgumentDependentLookup(DeclarationName Name, bool Operator, 1698 Expr **Args, unsigned NumArgs, 1699 ADLResult &Functions, 1700 bool StdNamespaceIsAssociated = false); 1701 1702 void LookupVisibleDecls(Scope *S, LookupNameKind Kind, 1703 VisibleDeclConsumer &Consumer, 1704 bool IncludeGlobalScope = true); 1705 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, 1706 VisibleDeclConsumer &Consumer, 1707 bool IncludeGlobalScope = true); 1708 1709 /// \brief The context in which typo-correction occurs. 1710 /// 1711 /// The typo-correction context affects which keywords (if any) are 1712 /// considered when trying to correct for typos. 1713 enum CorrectTypoContext { 1714 /// \brief An unknown context, where any keyword might be valid. 1715 CTC_Unknown, 1716 /// \brief A context where no keywords are used (e.g. we expect an actual 1717 /// name). 1718 CTC_NoKeywords, 1719 /// \brief A context where we're correcting a type name. 1720 CTC_Type, 1721 /// \brief An expression context. 1722 CTC_Expression, 1723 /// \brief A type cast, or anything else that can be followed by a '<'. 1724 CTC_CXXCasts, 1725 /// \brief A member lookup context. 1726 CTC_MemberLookup, 1727 /// \brief An Objective-C ivar lookup context (e.g., self->ivar). 1728 CTC_ObjCIvarLookup, 1729 /// \brief An Objective-C property lookup context (e.g., self.prop). 1730 CTC_ObjCPropertyLookup, 1731 /// \brief The receiver of an Objective-C message send within an 1732 /// Objective-C method where 'super' is a valid keyword. 1733 CTC_ObjCMessageReceiver 1734 }; 1735 1736 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 1737 Sema::LookupNameKind LookupKind, 1738 Scope *S, CXXScopeSpec *SS, 1739 DeclContext *MemberContext = NULL, 1740 bool EnteringContext = false, 1741 CorrectTypoContext CTC = CTC_Unknown, 1742 const ObjCObjectPointerType *OPT = NULL); 1743 1744 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs, 1745 AssociatedNamespaceSet &AssociatedNamespaces, 1746 AssociatedClassSet &AssociatedClasses); 1747 1748 void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, 1749 bool ConsiderLinkage, 1750 bool ExplicitInstantiationOrSpecialization); 1751 1752 bool DiagnoseAmbiguousLookup(LookupResult &Result); 1753 //@} 1754 1755 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, 1756 SourceLocation IdLoc, 1757 bool TypoCorrection = false); 1758 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, 1759 Scope *S, bool ForRedeclaration, 1760 SourceLocation Loc); 1761 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, 1762 Scope *S); 1763 void AddKnownFunctionAttributes(FunctionDecl *FD); 1764 1765 // More parsing and symbol table subroutines. 1766 1767 // Decl attributes - this routine is the top level dispatcher. 1768 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD, 1769 bool NonInheritable = true, bool Inheritable = true); 1770 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, 1771 bool NonInheritable = true, bool Inheritable = true); 1772 1773 bool CheckRegparmAttr(const AttributeList &attr, unsigned &value); 1774 bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC); 1775 bool CheckNoReturnAttr(const AttributeList &attr); 1776 1777 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, 1778 bool &IncompleteImpl, unsigned DiagID); 1779 void WarnConflictingTypedMethods(ObjCMethodDecl *Method, 1780 ObjCMethodDecl *MethodDecl, 1781 bool IsProtocolMethodDecl, 1782 bool IsDeclaration = false); 1783 1784 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, 1785 ObjCInterfaceDecl *IDecl); 1786 1787 typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet; 1788 1789 /// CheckProtocolMethodDefs - This routine checks unimplemented 1790 /// methods declared in protocol, and those referenced by it. 1791 /// \param IDecl - Used for checking for methods which may have been 1792 /// inherited. 1793 void CheckProtocolMethodDefs(SourceLocation ImpLoc, 1794 ObjCProtocolDecl *PDecl, 1795 bool& IncompleteImpl, 1796 const SelectorSet &InsMap, 1797 const SelectorSet &ClsMap, 1798 ObjCContainerDecl *CDecl); 1799 1800 /// CheckImplementationIvars - This routine checks if the instance variables 1801 /// listed in the implelementation match those listed in the interface. 1802 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, 1803 ObjCIvarDecl **Fields, unsigned nIvars, 1804 SourceLocation Loc); 1805 1806 /// \brief Determine whether we can synthesize a provisional ivar for the 1807 /// given name. 1808 ObjCPropertyDecl *canSynthesizeProvisionalIvar(IdentifierInfo *II); 1809 1810 /// \brief Determine whether we can synthesize a provisional ivar for the 1811 /// given property. 1812 bool canSynthesizeProvisionalIvar(ObjCPropertyDecl *Property); 1813 1814 /// ImplMethodsVsClassMethods - This is main routine to warn if any method 1815 /// remains unimplemented in the class or category @implementation. 1816 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, 1817 ObjCContainerDecl* IDecl, 1818 bool IncompleteImpl = false); 1819 1820 /// DiagnoseUnimplementedProperties - This routine warns on those properties 1821 /// which must be implemented by this implementation. 1822 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, 1823 ObjCContainerDecl *CDecl, 1824 const SelectorSet &InsMap); 1825 1826 /// DefaultSynthesizeProperties - This routine default synthesizes all 1827 /// properties which must be synthesized in class's @implementation. 1828 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, 1829 ObjCInterfaceDecl *IDecl); 1830 1831 /// CollectImmediateProperties - This routine collects all properties in 1832 /// the class and its conforming protocols; but not those it its super class. 1833 void CollectImmediateProperties(ObjCContainerDecl *CDecl, 1834 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap, 1835 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap); 1836 1837 1838 /// LookupPropertyDecl - Looks up a property in the current class and all 1839 /// its protocols. 1840 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl, 1841 IdentifierInfo *II); 1842 1843 /// Called by ActOnProperty to handle @property declarations in 1844 //// class extensions. 1845 Decl *HandlePropertyInClassExtension(Scope *S, 1846 ObjCCategoryDecl *CDecl, 1847 SourceLocation AtLoc, 1848 FieldDeclarator &FD, 1849 Selector GetterSel, 1850 Selector SetterSel, 1851 const bool isAssign, 1852 const bool isReadWrite, 1853 const unsigned Attributes, 1854 bool *isOverridingProperty, 1855 TypeSourceInfo *T, 1856 tok::ObjCKeywordKind MethodImplKind); 1857 1858 /// Called by ActOnProperty and HandlePropertyInClassExtension to 1859 /// handle creating the ObjcPropertyDecl for a category or @interface. 1860 ObjCPropertyDecl *CreatePropertyDecl(Scope *S, 1861 ObjCContainerDecl *CDecl, 1862 SourceLocation AtLoc, 1863 FieldDeclarator &FD, 1864 Selector GetterSel, 1865 Selector SetterSel, 1866 const bool isAssign, 1867 const bool isReadWrite, 1868 const unsigned Attributes, 1869 TypeSourceInfo *T, 1870 tok::ObjCKeywordKind MethodImplKind, 1871 DeclContext *lexicalDC = 0); 1872 1873 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via 1874 /// warning) when atomic property has one but not the other user-declared 1875 /// setter or getter. 1876 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, 1877 ObjCContainerDecl* IDecl); 1878 1879 void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); 1880 1881 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); 1882 1883 enum MethodMatchStrategy { 1884 MMS_loose, 1885 MMS_strict 1886 }; 1887 1888 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns 1889 /// true, or false, accordingly. 1890 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, 1891 const ObjCMethodDecl *PrevMethod, 1892 MethodMatchStrategy strategy = MMS_strict); 1893 1894 /// MatchAllMethodDeclarations - Check methods declaraed in interface or 1895 /// or protocol against those declared in their implementations. 1896 void MatchAllMethodDeclarations(const SelectorSet &InsMap, 1897 const SelectorSet &ClsMap, 1898 SelectorSet &InsMapSeen, 1899 SelectorSet &ClsMapSeen, 1900 ObjCImplDecl* IMPDecl, 1901 ObjCContainerDecl* IDecl, 1902 bool &IncompleteImpl, 1903 bool ImmediateClass); 1904 1905 /// MatchMethodsInClassAndItsProtocol - Check that any redeclaration of 1906 /// method in protocol in its qualified class match in their type and 1907 /// issue warnings otherwise. 1908 void MatchMethodsInClassAndItsProtocol(const ObjCInterfaceDecl *CDecl); 1909 1910private: 1911 /// AddMethodToGlobalPool - Add an instance or factory method to the global 1912 /// pool. See descriptoin of AddInstanceMethodToGlobalPool. 1913 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); 1914 1915 /// LookupMethodInGlobalPool - Returns the instance or factory method and 1916 /// optionally warns if there are multiple signatures. 1917 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, 1918 bool receiverIdOrClass, 1919 bool warn, bool instance); 1920 1921public: 1922 /// AddInstanceMethodToGlobalPool - All instance methods in a translation 1923 /// unit are added to a global pool. This allows us to efficiently associate 1924 /// a selector with a method declaraation for purposes of typechecking 1925 /// messages sent to "id" (where the class of the object is unknown). 1926 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 1927 AddMethodToGlobalPool(Method, impl, /*instance*/true); 1928 } 1929 1930 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. 1931 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 1932 AddMethodToGlobalPool(Method, impl, /*instance*/false); 1933 } 1934 1935 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if 1936 /// there are multiple signatures. 1937 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, 1938 bool receiverIdOrClass=false, 1939 bool warn=true) { 1940 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 1941 warn, /*instance*/true); 1942 } 1943 1944 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if 1945 /// there are multiple signatures. 1946 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, 1947 bool receiverIdOrClass=false, 1948 bool warn=true) { 1949 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 1950 warn, /*instance*/false); 1951 } 1952 1953 /// LookupImplementedMethodInGlobalPool - Returns the method which has an 1954 /// implementation. 1955 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); 1956 1957 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require 1958 /// initialization. 1959 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, 1960 SmallVectorImpl<ObjCIvarDecl*> &Ivars); 1961 1962 //===--------------------------------------------------------------------===// 1963 // Statement Parsing Callbacks: SemaStmt.cpp. 1964public: 1965 class FullExprArg { 1966 public: 1967 FullExprArg(Sema &actions) : E(0) { } 1968 1969 // FIXME: The const_cast here is ugly. RValue references would make this 1970 // much nicer (or we could duplicate a bunch of the move semantics 1971 // emulation code from Ownership.h). 1972 FullExprArg(const FullExprArg& Other) : E(Other.E) {} 1973 1974 ExprResult release() { 1975 return move(E); 1976 } 1977 1978 Expr *get() const { return E; } 1979 1980 Expr *operator->() { 1981 return E; 1982 } 1983 1984 private: 1985 // FIXME: No need to make the entire Sema class a friend when it's just 1986 // Sema::MakeFullExpr that needs access to the constructor below. 1987 friend class Sema; 1988 1989 explicit FullExprArg(Expr *expr) : E(expr) {} 1990 1991 Expr *E; 1992 }; 1993 1994 FullExprArg MakeFullExpr(Expr *Arg) { 1995 return FullExprArg(ActOnFinishFullExpr(Arg).release()); 1996 } 1997 1998 StmtResult ActOnExprStmt(FullExprArg Expr); 1999 2000 StmtResult ActOnNullStmt(SourceLocation SemiLoc, 2001 SourceLocation LeadingEmptyMacroLoc = SourceLocation()); 2002 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, 2003 MultiStmtArg Elts, 2004 bool isStmtExpr); 2005 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, 2006 SourceLocation StartLoc, 2007 SourceLocation EndLoc); 2008 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); 2009 StmtResult ActOnForEachLValueExpr(Expr *E); 2010 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, 2011 SourceLocation DotDotDotLoc, Expr *RHSVal, 2012 SourceLocation ColonLoc); 2013 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); 2014 2015 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, 2016 SourceLocation ColonLoc, 2017 Stmt *SubStmt, Scope *CurScope); 2018 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, 2019 SourceLocation ColonLoc, Stmt *SubStmt); 2020 2021 StmtResult ActOnIfStmt(SourceLocation IfLoc, 2022 FullExprArg CondVal, Decl *CondVar, 2023 Stmt *ThenVal, 2024 SourceLocation ElseLoc, Stmt *ElseVal); 2025 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, 2026 Expr *Cond, 2027 Decl *CondVar); 2028 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 2029 Stmt *Switch, Stmt *Body); 2030 StmtResult ActOnWhileStmt(SourceLocation WhileLoc, 2031 FullExprArg Cond, 2032 Decl *CondVar, Stmt *Body); 2033 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, 2034 SourceLocation WhileLoc, 2035 SourceLocation CondLParen, Expr *Cond, 2036 SourceLocation CondRParen); 2037 2038 StmtResult ActOnForStmt(SourceLocation ForLoc, 2039 SourceLocation LParenLoc, 2040 Stmt *First, FullExprArg Second, 2041 Decl *SecondVar, 2042 FullExprArg Third, 2043 SourceLocation RParenLoc, 2044 Stmt *Body); 2045 ExprResult ActOnObjCForCollectionOperand(SourceLocation forLoc, 2046 Expr *collection); 2047 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 2048 SourceLocation LParenLoc, 2049 Stmt *First, Expr *Second, 2050 SourceLocation RParenLoc, Stmt *Body); 2051 StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, 2052 SourceLocation LParenLoc, Stmt *LoopVar, 2053 SourceLocation ColonLoc, Expr *Collection, 2054 SourceLocation RParenLoc); 2055 StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, 2056 SourceLocation ColonLoc, 2057 Stmt *RangeDecl, Stmt *BeginEndDecl, 2058 Expr *Cond, Expr *Inc, 2059 Stmt *LoopVarDecl, 2060 SourceLocation RParenLoc); 2061 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); 2062 2063 StmtResult ActOnGotoStmt(SourceLocation GotoLoc, 2064 SourceLocation LabelLoc, 2065 LabelDecl *TheDecl); 2066 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, 2067 SourceLocation StarLoc, 2068 Expr *DestExp); 2069 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); 2070 StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope); 2071 2072 const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E, 2073 bool AllowFunctionParameters); 2074 2075 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2076 StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2077 2078 StmtResult ActOnAsmStmt(SourceLocation AsmLoc, 2079 bool IsSimple, bool IsVolatile, 2080 unsigned NumOutputs, unsigned NumInputs, 2081 IdentifierInfo **Names, 2082 MultiExprArg Constraints, 2083 MultiExprArg Exprs, 2084 Expr *AsmString, 2085 MultiExprArg Clobbers, 2086 SourceLocation RParenLoc, 2087 bool MSAsm = false); 2088 2089 2090 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, 2091 SourceLocation StartLoc, 2092 SourceLocation IdLoc, IdentifierInfo *Id, 2093 bool Invalid = false); 2094 2095 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); 2096 2097 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, 2098 Decl *Parm, Stmt *Body); 2099 2100 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); 2101 2102 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, 2103 MultiStmtArg Catch, Stmt *Finally); 2104 2105 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); 2106 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, 2107 Scope *CurScope); 2108 ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, 2109 Expr *operand); 2110 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, 2111 Expr *SynchExpr, 2112 Stmt *SynchBody); 2113 2114 StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); 2115 2116 VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, 2117 SourceLocation StartLoc, 2118 SourceLocation IdLoc, 2119 IdentifierInfo *Id); 2120 2121 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); 2122 2123 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, 2124 Decl *ExDecl, Stmt *HandlerBlock); 2125 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, 2126 MultiStmtArg Handlers); 2127 2128 StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? 2129 SourceLocation TryLoc, 2130 Stmt *TryBlock, 2131 Stmt *Handler); 2132 2133 StmtResult ActOnSEHExceptBlock(SourceLocation Loc, 2134 Expr *FilterExpr, 2135 Stmt *Block); 2136 2137 StmtResult ActOnSEHFinallyBlock(SourceLocation Loc, 2138 Stmt *Block); 2139 2140 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); 2141 2142 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; 2143 2144 /// \brief If it's a file scoped decl that must warn if not used, keep track 2145 /// of it. 2146 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); 2147 2148 /// DiagnoseUnusedExprResult - If the statement passed in is an expression 2149 /// whose result is unused, warn. 2150 void DiagnoseUnusedExprResult(const Stmt *S); 2151 void DiagnoseUnusedDecl(const NamedDecl *ND); 2152 2153 ParsingDeclState PushParsingDeclaration() { 2154 return DelayedDiagnostics.pushParsingDecl(); 2155 } 2156 void PopParsingDeclaration(ParsingDeclState state, Decl *decl) { 2157 DelayedDiagnostics::popParsingDecl(*this, state, decl); 2158 } 2159 2160 typedef ProcessingContextState ParsingClassState; 2161 ParsingClassState PushParsingClass() { 2162 return DelayedDiagnostics.pushContext(); 2163 } 2164 void PopParsingClass(ParsingClassState state) { 2165 DelayedDiagnostics.popContext(state); 2166 } 2167 2168 void EmitDeprecationWarning(NamedDecl *D, StringRef Message, 2169 SourceLocation Loc, 2170 const ObjCInterfaceDecl *UnknownObjCClass=0); 2171 2172 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 2173 2174 bool makeUnavailableInSystemHeader(SourceLocation loc, 2175 StringRef message); 2176 2177 //===--------------------------------------------------------------------===// 2178 // Expression Parsing Callbacks: SemaExpr.cpp. 2179 2180 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, 2181 const ObjCInterfaceDecl *UnknownObjCClass=0); 2182 std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); 2183 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 2184 ObjCMethodDecl *Getter, 2185 SourceLocation Loc); 2186 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, 2187 Expr **Args, unsigned NumArgs); 2188 2189 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext); 2190 2191 void PopExpressionEvaluationContext(); 2192 2193 void DiscardCleanupsInEvaluationContext(); 2194 2195 void MarkDeclarationReferenced(SourceLocation Loc, Decl *D); 2196 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); 2197 void MarkDeclarationsReferencedInExpr(Expr *E); 2198 2199 /// \brief Figure out if an expression could be turned into a call. 2200 bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy, 2201 UnresolvedSetImpl &NonTemplateOverloads); 2202 /// \brief Give notes for a set of overloads. 2203 void NoteOverloads(const UnresolvedSetImpl &Overloads, 2204 const SourceLocation FinalNoteLoc); 2205 2206 /// \brief Conditionally issue a diagnostic based on the current 2207 /// evaluation context. 2208 /// 2209 /// \param stmt - If stmt is non-null, delay reporting the diagnostic until 2210 /// the function body is parsed, and then do a basic reachability analysis to 2211 /// determine if the statement is reachable. If it is unreachable, the 2212 /// diagnostic will not be emitted. 2213 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *stmt, 2214 const PartialDiagnostic &PD); 2215 2216 // Primary Expressions. 2217 SourceRange getExprRange(Expr *E) const; 2218 2219 ObjCIvarDecl *SynthesizeProvisionalIvar(LookupResult &Lookup, 2220 IdentifierInfo *II, 2221 SourceLocation NameLoc); 2222 2223 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Name, 2224 bool HasTrailingLParen, bool IsAddressOfOperand); 2225 2226 void DecomposeUnqualifiedId(const UnqualifiedId &Id, 2227 TemplateArgumentListInfo &Buffer, 2228 DeclarationNameInfo &NameInfo, 2229 const TemplateArgumentListInfo *&TemplateArgs); 2230 2231 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, 2232 CorrectTypoContext CTC = CTC_Unknown); 2233 2234 ExprResult LookupInObjCMethod(LookupResult &R, Scope *S, IdentifierInfo *II, 2235 bool AllowBuiltinCreation=false); 2236 2237 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, 2238 const DeclarationNameInfo &NameInfo, 2239 bool isAddressOfOperand, 2240 const TemplateArgumentListInfo *TemplateArgs); 2241 2242 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2243 ExprValueKind VK, 2244 SourceLocation Loc, 2245 const CXXScopeSpec *SS = 0); 2246 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2247 ExprValueKind VK, 2248 const DeclarationNameInfo &NameInfo, 2249 const CXXScopeSpec *SS = 0); 2250 ExprResult 2251 BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, 2252 SourceLocation nameLoc, 2253 IndirectFieldDecl *indirectField, 2254 Expr *baseObjectExpr = 0, 2255 SourceLocation opLoc = SourceLocation()); 2256 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, 2257 LookupResult &R, 2258 const TemplateArgumentListInfo *TemplateArgs); 2259 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, 2260 LookupResult &R, 2261 const TemplateArgumentListInfo *TemplateArgs, 2262 bool IsDefiniteInstance); 2263 bool UseArgumentDependentLookup(const CXXScopeSpec &SS, 2264 const LookupResult &R, 2265 bool HasTrailingLParen); 2266 2267 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, 2268 const DeclarationNameInfo &NameInfo); 2269 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, 2270 const DeclarationNameInfo &NameInfo, 2271 const TemplateArgumentListInfo *TemplateArgs); 2272 2273 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2274 LookupResult &R, 2275 bool ADL); 2276 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2277 const DeclarationNameInfo &NameInfo, 2278 NamedDecl *D); 2279 2280 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); 2281 ExprResult ActOnNumericConstant(const Token &); 2282 ExprResult ActOnCharacterConstant(const Token &); 2283 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *Val); 2284 ExprResult ActOnParenOrParenListExpr(SourceLocation L, 2285 SourceLocation R, 2286 MultiExprArg Val); 2287 2288 /// ActOnStringLiteral - The specified tokens were lexed as pasted string 2289 /// fragments (e.g. "foo" "bar" L"baz"). 2290 ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks); 2291 2292 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, 2293 SourceLocation DefaultLoc, 2294 SourceLocation RParenLoc, 2295 Expr *ControllingExpr, 2296 MultiTypeArg Types, 2297 MultiExprArg Exprs); 2298 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, 2299 SourceLocation DefaultLoc, 2300 SourceLocation RParenLoc, 2301 Expr *ControllingExpr, 2302 TypeSourceInfo **Types, 2303 Expr **Exprs, 2304 unsigned NumAssocs); 2305 2306 // Binary/Unary Operators. 'Tok' is the token for the operator. 2307 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, 2308 Expr *InputArg); 2309 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, 2310 UnaryOperatorKind Opc, Expr *input); 2311 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, 2312 tok::TokenKind Op, Expr *Input); 2313 2314 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *T, 2315 SourceLocation OpLoc, 2316 UnaryExprOrTypeTrait ExprKind, 2317 SourceRange R); 2318 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, 2319 UnaryExprOrTypeTrait ExprKind); 2320 ExprResult 2321 ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, 2322 UnaryExprOrTypeTrait ExprKind, 2323 bool isType, void *TyOrEx, 2324 const SourceRange &ArgRange); 2325 2326 ExprResult CheckPlaceholderExpr(Expr *E); 2327 bool CheckVecStepExpr(Expr *E); 2328 2329 bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); 2330 bool CheckUnaryExprOrTypeTraitOperand(QualType type, SourceLocation OpLoc, 2331 SourceRange R, 2332 UnaryExprOrTypeTrait ExprKind); 2333 ExprResult ActOnSizeofParameterPackExpr(Scope *S, 2334 SourceLocation OpLoc, 2335 IdentifierInfo &Name, 2336 SourceLocation NameLoc, 2337 SourceLocation RParenLoc); 2338 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, 2339 tok::TokenKind Kind, Expr *Input); 2340 2341 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, 2342 Expr *Idx, SourceLocation RLoc); 2343 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, 2344 Expr *Idx, SourceLocation RLoc); 2345 2346 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2347 SourceLocation OpLoc, bool IsArrow, 2348 CXXScopeSpec &SS, 2349 NamedDecl *FirstQualifierInScope, 2350 const DeclarationNameInfo &NameInfo, 2351 const TemplateArgumentListInfo *TemplateArgs); 2352 2353 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2354 SourceLocation OpLoc, bool IsArrow, 2355 const CXXScopeSpec &SS, 2356 NamedDecl *FirstQualifierInScope, 2357 LookupResult &R, 2358 const TemplateArgumentListInfo *TemplateArgs, 2359 bool SuppressQualifierCheck = false); 2360 2361 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base, 2362 bool &IsArrow, SourceLocation OpLoc, 2363 CXXScopeSpec &SS, 2364 Decl *ObjCImpDecl, 2365 bool HasTemplateArgs); 2366 2367 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, 2368 const CXXScopeSpec &SS, 2369 const LookupResult &R); 2370 2371 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, 2372 bool IsArrow, SourceLocation OpLoc, 2373 const CXXScopeSpec &SS, 2374 NamedDecl *FirstQualifierInScope, 2375 const DeclarationNameInfo &NameInfo, 2376 const TemplateArgumentListInfo *TemplateArgs); 2377 2378 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, 2379 SourceLocation OpLoc, 2380 tok::TokenKind OpKind, 2381 CXXScopeSpec &SS, 2382 UnqualifiedId &Member, 2383 Decl *ObjCImpDecl, 2384 bool HasTrailingLParen); 2385 2386 void ActOnDefaultCtorInitializers(Decl *CDtorDecl); 2387 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, 2388 FunctionDecl *FDecl, 2389 const FunctionProtoType *Proto, 2390 Expr **Args, unsigned NumArgs, 2391 SourceLocation RParenLoc); 2392 2393 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. 2394 /// This provides the location of the left/right parens and a list of comma 2395 /// locations. 2396 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 2397 MultiExprArg Args, SourceLocation RParenLoc, 2398 Expr *ExecConfig = 0); 2399 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, 2400 SourceLocation LParenLoc, 2401 Expr **Args, unsigned NumArgs, 2402 SourceLocation RParenLoc, 2403 Expr *ExecConfig = 0); 2404 2405 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, 2406 MultiExprArg ExecConfig, SourceLocation GGGLoc); 2407 2408 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, 2409 Declarator &D, ParsedType &Ty, 2410 SourceLocation RParenLoc, Expr *Op); 2411 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, 2412 TypeSourceInfo *Ty, 2413 SourceLocation RParenLoc, 2414 Expr *Op); 2415 2416 /// \brief Build an altivec or OpenCL literal. 2417 ExprResult BuildVectorLiteral(SourceLocation LParenLoc, 2418 SourceLocation RParenLoc, Expr *E, 2419 TypeSourceInfo *TInfo); 2420 2421 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); 2422 2423 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, 2424 ParsedType Ty, 2425 SourceLocation RParenLoc, 2426 Expr *Op); 2427 2428 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, 2429 TypeSourceInfo *TInfo, 2430 SourceLocation RParenLoc, 2431 Expr *InitExpr); 2432 2433 ExprResult ActOnInitList(SourceLocation LParenLoc, 2434 MultiExprArg InitList, 2435 SourceLocation RParenLoc); 2436 2437 ExprResult ActOnDesignatedInitializer(Designation &Desig, 2438 SourceLocation Loc, 2439 bool GNUSyntax, 2440 ExprResult Init); 2441 2442 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, 2443 tok::TokenKind Kind, Expr *LHS, Expr *RHS); 2444 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, 2445 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs); 2446 ExprResult CreateBuiltinBinOp(SourceLocation TokLoc, 2447 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs); 2448 2449 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null 2450 /// in the case of a the GNU conditional expr extension. 2451 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, 2452 SourceLocation ColonLoc, 2453 Expr *Cond, Expr *LHS, Expr *RHS); 2454 2455 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". 2456 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, 2457 LabelDecl *LD); 2458 2459 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, 2460 SourceLocation RPLoc); // "({..})" 2461 2462 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 2463 struct OffsetOfComponent { 2464 SourceLocation LocStart, LocEnd; 2465 bool isBrackets; // true if [expr], false if .ident 2466 union { 2467 IdentifierInfo *IdentInfo; 2468 ExprTy *E; 2469 } U; 2470 }; 2471 2472 /// __builtin_offsetof(type, a.b[123][456].c) 2473 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, 2474 TypeSourceInfo *TInfo, 2475 OffsetOfComponent *CompPtr, 2476 unsigned NumComponents, 2477 SourceLocation RParenLoc); 2478 ExprResult ActOnBuiltinOffsetOf(Scope *S, 2479 SourceLocation BuiltinLoc, 2480 SourceLocation TypeLoc, 2481 ParsedType Arg1, 2482 OffsetOfComponent *CompPtr, 2483 unsigned NumComponents, 2484 SourceLocation RParenLoc); 2485 2486 // __builtin_choose_expr(constExpr, expr1, expr2) 2487 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, 2488 Expr *cond, Expr *expr1, 2489 Expr *expr2, SourceLocation RPLoc); 2490 2491 // __builtin_va_arg(expr, type) 2492 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, 2493 Expr *expr, ParsedType type, 2494 SourceLocation RPLoc); 2495 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, 2496 Expr *expr, TypeSourceInfo *TInfo, 2497 SourceLocation RPLoc); 2498 2499 // __null 2500 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); 2501 2502 bool CheckCaseExpression(Expr *expr); 2503 2504 bool CheckMicrosoftIfExistsSymbol(CXXScopeSpec &SS, UnqualifiedId &Name); 2505 2506 //===------------------------- "Block" Extension ------------------------===// 2507 2508 /// ActOnBlockStart - This callback is invoked when a block literal is 2509 /// started. 2510 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); 2511 2512 /// ActOnBlockArguments - This callback allows processing of block arguments. 2513 /// If there are no arguments, this is still invoked. 2514 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope); 2515 2516 /// ActOnBlockError - If there is an error parsing a block, this callback 2517 /// is invoked to pop the information about the block from the action impl. 2518 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); 2519 2520 /// ActOnBlockStmtExpr - This is called when the body of a block statement 2521 /// literal was successfully completed. ^(int x){...} 2522 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, 2523 Stmt *Body, Scope *CurScope); 2524 2525 //===---------------------------- OpenCL Features -----------------------===// 2526 2527 /// __builtin_astype(...) 2528 ExprResult ActOnAsTypeExpr(Expr *expr, ParsedType DestTy, 2529 SourceLocation BuiltinLoc, 2530 SourceLocation RParenLoc); 2531 2532 //===---------------------------- C++ Features --------------------------===// 2533 2534 // Act on C++ namespaces 2535 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, 2536 SourceLocation NamespaceLoc, 2537 SourceLocation IdentLoc, 2538 IdentifierInfo *Ident, 2539 SourceLocation LBrace, 2540 AttributeList *AttrList); 2541 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); 2542 2543 NamespaceDecl *getStdNamespace() const; 2544 NamespaceDecl *getOrCreateStdNamespace(); 2545 2546 CXXRecordDecl *getStdBadAlloc() const; 2547 2548 Decl *ActOnUsingDirective(Scope *CurScope, 2549 SourceLocation UsingLoc, 2550 SourceLocation NamespcLoc, 2551 CXXScopeSpec &SS, 2552 SourceLocation IdentLoc, 2553 IdentifierInfo *NamespcName, 2554 AttributeList *AttrList); 2555 2556 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); 2557 2558 Decl *ActOnNamespaceAliasDef(Scope *CurScope, 2559 SourceLocation NamespaceLoc, 2560 SourceLocation AliasLoc, 2561 IdentifierInfo *Alias, 2562 CXXScopeSpec &SS, 2563 SourceLocation IdentLoc, 2564 IdentifierInfo *Ident); 2565 2566 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); 2567 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, 2568 const LookupResult &PreviousDecls); 2569 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, 2570 NamedDecl *Target); 2571 2572 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, 2573 bool isTypeName, 2574 const CXXScopeSpec &SS, 2575 SourceLocation NameLoc, 2576 const LookupResult &Previous); 2577 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, 2578 const CXXScopeSpec &SS, 2579 SourceLocation NameLoc); 2580 2581 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, 2582 SourceLocation UsingLoc, 2583 CXXScopeSpec &SS, 2584 const DeclarationNameInfo &NameInfo, 2585 AttributeList *AttrList, 2586 bool IsInstantiation, 2587 bool IsTypeName, 2588 SourceLocation TypenameLoc); 2589 2590 bool CheckInheritedConstructorUsingDecl(UsingDecl *UD); 2591 2592 Decl *ActOnUsingDeclaration(Scope *CurScope, 2593 AccessSpecifier AS, 2594 bool HasUsingKeyword, 2595 SourceLocation UsingLoc, 2596 CXXScopeSpec &SS, 2597 UnqualifiedId &Name, 2598 AttributeList *AttrList, 2599 bool IsTypeName, 2600 SourceLocation TypenameLoc); 2601 Decl *ActOnAliasDeclaration(Scope *CurScope, 2602 AccessSpecifier AS, 2603 MultiTemplateParamsArg TemplateParams, 2604 SourceLocation UsingLoc, 2605 UnqualifiedId &Name, 2606 TypeResult Type); 2607 2608 /// AddCXXDirectInitializerToDecl - This action is called immediately after 2609 /// ActOnDeclarator, when a C++ direct initializer is present. 2610 /// e.g: "int x(1);" 2611 void AddCXXDirectInitializerToDecl(Decl *Dcl, 2612 SourceLocation LParenLoc, 2613 MultiExprArg Exprs, 2614 SourceLocation RParenLoc, 2615 bool TypeMayContainAuto); 2616 2617 /// InitializeVarWithConstructor - Creates an CXXConstructExpr 2618 /// and sets it as the initializer for the the passed in VarDecl. 2619 bool InitializeVarWithConstructor(VarDecl *VD, 2620 CXXConstructorDecl *Constructor, 2621 MultiExprArg Exprs); 2622 2623 /// BuildCXXConstructExpr - Creates a complete call to a constructor, 2624 /// including handling of its default argument expressions. 2625 /// 2626 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind 2627 ExprResult 2628 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 2629 CXXConstructorDecl *Constructor, MultiExprArg Exprs, 2630 bool RequiresZeroInit, unsigned ConstructKind, 2631 SourceRange ParenRange); 2632 2633 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if 2634 // the constructor can be elidable? 2635 ExprResult 2636 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 2637 CXXConstructorDecl *Constructor, bool Elidable, 2638 MultiExprArg Exprs, bool RequiresZeroInit, 2639 unsigned ConstructKind, 2640 SourceRange ParenRange); 2641 2642 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating 2643 /// the default expr if needed. 2644 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, 2645 FunctionDecl *FD, 2646 ParmVarDecl *Param); 2647 2648 /// FinalizeVarWithDestructor - Prepare for calling destructor on the 2649 /// constructed variable. 2650 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); 2651 2652 /// \brief Helper class that collects exception specifications for 2653 /// implicitly-declared special member functions. 2654 class ImplicitExceptionSpecification { 2655 // Pointer to allow copying 2656 ASTContext *Context; 2657 // We order exception specifications thus: 2658 // noexcept is the most restrictive, but is only used in C++0x. 2659 // throw() comes next. 2660 // Then a throw(collected exceptions) 2661 // Finally no specification. 2662 // throw(...) is used instead if any called function uses it. 2663 // 2664 // If this exception specification cannot be known yet (for instance, 2665 // because this is the exception specification for a defaulted default 2666 // constructor and we haven't finished parsing the deferred parts of the 2667 // class yet), the C++0x standard does not specify how to behave. We 2668 // record this as an 'unknown' exception specification, which overrules 2669 // any other specification (even 'none', to keep this rule simple). 2670 ExceptionSpecificationType ComputedEST; 2671 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; 2672 SmallVector<QualType, 4> Exceptions; 2673 2674 void ClearExceptions() { 2675 ExceptionsSeen.clear(); 2676 Exceptions.clear(); 2677 } 2678 2679 public: 2680 explicit ImplicitExceptionSpecification(ASTContext &Context) 2681 : Context(&Context), ComputedEST(EST_BasicNoexcept) { 2682 if (!Context.getLangOptions().CPlusPlus0x) 2683 ComputedEST = EST_DynamicNone; 2684 } 2685 2686 /// \brief Get the computed exception specification type. 2687 ExceptionSpecificationType getExceptionSpecType() const { 2688 assert(ComputedEST != EST_ComputedNoexcept && 2689 "noexcept(expr) should not be a possible result"); 2690 return ComputedEST; 2691 } 2692 2693 /// \brief The number of exceptions in the exception specification. 2694 unsigned size() const { return Exceptions.size(); } 2695 2696 /// \brief The set of exceptions in the exception specification. 2697 const QualType *data() const { return Exceptions.data(); } 2698 2699 /// \brief Integrate another called method into the collected data. 2700 void CalledDecl(CXXMethodDecl *Method); 2701 2702 /// \brief Integrate an invoked expression into the collected data. 2703 void CalledExpr(Expr *E); 2704 2705 /// \brief Specify that the exception specification can't be detemined yet. 2706 void SetDelayed() { 2707 ClearExceptions(); 2708 ComputedEST = EST_Delayed; 2709 } 2710 2711 FunctionProtoType::ExtProtoInfo getEPI() const { 2712 FunctionProtoType::ExtProtoInfo EPI; 2713 EPI.ExceptionSpecType = getExceptionSpecType(); 2714 EPI.NumExceptions = size(); 2715 EPI.Exceptions = data(); 2716 return EPI; 2717 } 2718 }; 2719 2720 /// \brief Determine what sort of exception specification a defaulted 2721 /// copy constructor of a class will have. 2722 ImplicitExceptionSpecification 2723 ComputeDefaultedDefaultCtorExceptionSpec(CXXRecordDecl *ClassDecl); 2724 2725 /// \brief Determine what sort of exception specification a defaulted 2726 /// default constructor of a class will have, and whether the parameter 2727 /// will be const. 2728 std::pair<ImplicitExceptionSpecification, bool> 2729 ComputeDefaultedCopyCtorExceptionSpecAndConst(CXXRecordDecl *ClassDecl); 2730 2731 /// \brief Determine what sort of exception specification a defautled 2732 /// copy assignment operator of a class will have, and whether the 2733 /// parameter will be const. 2734 std::pair<ImplicitExceptionSpecification, bool> 2735 ComputeDefaultedCopyAssignmentExceptionSpecAndConst(CXXRecordDecl *ClassDecl); 2736 2737 /// \brief Determine what sort of exception specification a defaulted 2738 /// destructor of a class will have. 2739 ImplicitExceptionSpecification 2740 ComputeDefaultedDtorExceptionSpec(CXXRecordDecl *ClassDecl); 2741 2742 /// \brief Determine if a defaulted default constructor ought to be 2743 /// deleted. 2744 bool ShouldDeleteDefaultConstructor(CXXConstructorDecl *CD); 2745 2746 /// \brief Determine if a defaulted copy constructor ought to be 2747 /// deleted. 2748 bool ShouldDeleteCopyConstructor(CXXConstructorDecl *CD); 2749 2750 /// \brief Determine if a defaulted copy assignment operator ought to be 2751 /// deleted. 2752 bool ShouldDeleteCopyAssignmentOperator(CXXMethodDecl *MD); 2753 2754 /// \brief Determine if a defaulted destructor ought to be deleted. 2755 bool ShouldDeleteDestructor(CXXDestructorDecl *DD); 2756 2757 /// \brief Declare the implicit default constructor for the given class. 2758 /// 2759 /// \param ClassDecl The class declaration into which the implicit 2760 /// default constructor will be added. 2761 /// 2762 /// \returns The implicitly-declared default constructor. 2763 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 2764 CXXRecordDecl *ClassDecl); 2765 2766 /// DefineImplicitDefaultConstructor - Checks for feasibility of 2767 /// defining this constructor as the default constructor. 2768 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 2769 CXXConstructorDecl *Constructor); 2770 2771 /// \brief Declare the implicit destructor for the given class. 2772 /// 2773 /// \param ClassDecl The class declaration into which the implicit 2774 /// destructor will be added. 2775 /// 2776 /// \returns The implicitly-declared destructor. 2777 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 2778 2779 /// DefineImplicitDestructor - Checks for feasibility of 2780 /// defining this destructor as the default destructor. 2781 void DefineImplicitDestructor(SourceLocation CurrentLocation, 2782 CXXDestructorDecl *Destructor); 2783 2784 /// \brief Build an exception spec for destructors that don't have one. 2785 /// 2786 /// C++11 says that user-defined destructors with no exception spec get one 2787 /// that looks as if the destructor was implicitly declared. 2788 void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl, 2789 CXXDestructorDecl *Destructor); 2790 2791 /// \brief Declare all inherited constructors for the given class. 2792 /// 2793 /// \param ClassDecl The class declaration into which the inherited 2794 /// constructors will be added. 2795 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl); 2796 2797 /// \brief Declare the implicit copy constructor for the given class. 2798 /// 2799 /// \param S The scope of the class, which may be NULL if this is a 2800 /// template instantiation. 2801 /// 2802 /// \param ClassDecl The class declaration into which the implicit 2803 /// copy constructor will be added. 2804 /// 2805 /// \returns The implicitly-declared copy constructor. 2806 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 2807 2808 /// DefineImplicitCopyConstructor - Checks for feasibility of 2809 /// defining this constructor as the copy constructor. 2810 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 2811 CXXConstructorDecl *Constructor); 2812 2813 /// \brief Declare the implicit copy assignment operator for the given class. 2814 /// 2815 /// \param S The scope of the class, which may be NULL if this is a 2816 /// template instantiation. 2817 /// 2818 /// \param ClassDecl The class declaration into which the implicit 2819 /// copy-assignment operator will be added. 2820 /// 2821 /// \returns The implicitly-declared copy assignment operator. 2822 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 2823 2824 /// \brief Defined an implicitly-declared copy assignment operator. 2825 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 2826 CXXMethodDecl *MethodDecl); 2827 2828 /// \brief Force the declaration of any implicitly-declared members of this 2829 /// class. 2830 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 2831 2832 /// MaybeBindToTemporary - If the passed in expression has a record type with 2833 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 2834 /// it simply returns the passed in expression. 2835 ExprResult MaybeBindToTemporary(Expr *E); 2836 2837 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 2838 MultiExprArg ArgsPtr, 2839 SourceLocation Loc, 2840 ASTOwningVector<Expr*> &ConvertedArgs); 2841 2842 ParsedType getDestructorName(SourceLocation TildeLoc, 2843 IdentifierInfo &II, SourceLocation NameLoc, 2844 Scope *S, CXXScopeSpec &SS, 2845 ParsedType ObjectType, 2846 bool EnteringContext); 2847 2848 // Checks that reinterpret casts don't have undefined behavior. 2849 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, 2850 bool IsDereference, SourceRange Range); 2851 2852 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 2853 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 2854 tok::TokenKind Kind, 2855 SourceLocation LAngleBracketLoc, 2856 Declarator &D, 2857 SourceLocation RAngleBracketLoc, 2858 SourceLocation LParenLoc, 2859 Expr *E, 2860 SourceLocation RParenLoc); 2861 2862 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 2863 tok::TokenKind Kind, 2864 TypeSourceInfo *Ty, 2865 Expr *E, 2866 SourceRange AngleBrackets, 2867 SourceRange Parens); 2868 2869 ExprResult BuildCXXTypeId(QualType TypeInfoType, 2870 SourceLocation TypeidLoc, 2871 TypeSourceInfo *Operand, 2872 SourceLocation RParenLoc); 2873 ExprResult BuildCXXTypeId(QualType TypeInfoType, 2874 SourceLocation TypeidLoc, 2875 Expr *Operand, 2876 SourceLocation RParenLoc); 2877 2878 /// ActOnCXXTypeid - Parse typeid( something ). 2879 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 2880 SourceLocation LParenLoc, bool isType, 2881 void *TyOrExpr, 2882 SourceLocation RParenLoc); 2883 2884 ExprResult BuildCXXUuidof(QualType TypeInfoType, 2885 SourceLocation TypeidLoc, 2886 TypeSourceInfo *Operand, 2887 SourceLocation RParenLoc); 2888 ExprResult BuildCXXUuidof(QualType TypeInfoType, 2889 SourceLocation TypeidLoc, 2890 Expr *Operand, 2891 SourceLocation RParenLoc); 2892 2893 /// ActOnCXXUuidof - Parse __uuidof( something ). 2894 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 2895 SourceLocation LParenLoc, bool isType, 2896 void *TyOrExpr, 2897 SourceLocation RParenLoc); 2898 2899 2900 //// ActOnCXXThis - Parse 'this' pointer. 2901 ExprResult ActOnCXXThis(SourceLocation loc); 2902 2903 /// getAndCaptureCurrentThisType - Try to capture a 'this' pointer. Returns 2904 /// the type of the 'this' pointer, or a null type if this is not possible. 2905 QualType getAndCaptureCurrentThisType(); 2906 2907 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 2908 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 2909 2910 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 2911 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 2912 2913 //// ActOnCXXThrow - Parse throw expressions. 2914 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); 2915 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, 2916 bool IsThrownVarInScope); 2917 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E, 2918 bool IsThrownVarInScope); 2919 2920 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 2921 /// Can be interpreted either as function-style casting ("int(x)") 2922 /// or class type construction ("ClassType(x,y,z)") 2923 /// or creation of a value-initialized type ("int()"). 2924 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 2925 SourceLocation LParenLoc, 2926 MultiExprArg Exprs, 2927 SourceLocation RParenLoc); 2928 2929 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 2930 SourceLocation LParenLoc, 2931 MultiExprArg Exprs, 2932 SourceLocation RParenLoc); 2933 2934 /// ActOnCXXNew - Parsed a C++ 'new' expression. 2935 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 2936 SourceLocation PlacementLParen, 2937 MultiExprArg PlacementArgs, 2938 SourceLocation PlacementRParen, 2939 SourceRange TypeIdParens, Declarator &D, 2940 SourceLocation ConstructorLParen, 2941 MultiExprArg ConstructorArgs, 2942 SourceLocation ConstructorRParen); 2943 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, 2944 SourceLocation PlacementLParen, 2945 MultiExprArg PlacementArgs, 2946 SourceLocation PlacementRParen, 2947 SourceRange TypeIdParens, 2948 QualType AllocType, 2949 TypeSourceInfo *AllocTypeInfo, 2950 Expr *ArraySize, 2951 SourceLocation ConstructorLParen, 2952 MultiExprArg ConstructorArgs, 2953 SourceLocation ConstructorRParen, 2954 bool TypeMayContainAuto = true); 2955 2956 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 2957 SourceRange R); 2958 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 2959 bool UseGlobal, QualType AllocType, bool IsArray, 2960 Expr **PlaceArgs, unsigned NumPlaceArgs, 2961 FunctionDecl *&OperatorNew, 2962 FunctionDecl *&OperatorDelete); 2963 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 2964 DeclarationName Name, Expr** Args, 2965 unsigned NumArgs, DeclContext *Ctx, 2966 bool AllowMissing, FunctionDecl *&Operator, 2967 bool Diagnose = true); 2968 void DeclareGlobalNewDelete(); 2969 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 2970 QualType Argument, 2971 bool addMallocAttr = false); 2972 2973 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 2974 DeclarationName Name, FunctionDecl* &Operator, 2975 bool Diagnose = true); 2976 2977 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 2978 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 2979 bool UseGlobal, bool ArrayForm, 2980 Expr *Operand); 2981 2982 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 2983 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 2984 SourceLocation StmtLoc, 2985 bool ConvertToBoolean); 2986 2987 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 2988 Expr *Operand, SourceLocation RParen); 2989 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 2990 SourceLocation RParen); 2991 2992 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 2993 /// pseudo-functions. 2994 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 2995 SourceLocation KWLoc, 2996 ParsedType Ty, 2997 SourceLocation RParen); 2998 2999 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 3000 SourceLocation KWLoc, 3001 TypeSourceInfo *T, 3002 SourceLocation RParen); 3003 3004 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support 3005 /// pseudo-functions. 3006 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT, 3007 SourceLocation KWLoc, 3008 ParsedType LhsTy, 3009 ParsedType RhsTy, 3010 SourceLocation RParen); 3011 3012 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT, 3013 SourceLocation KWLoc, 3014 TypeSourceInfo *LhsT, 3015 TypeSourceInfo *RhsT, 3016 SourceLocation RParen); 3017 3018 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support 3019 /// pseudo-functions. 3020 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, 3021 SourceLocation KWLoc, 3022 ParsedType LhsTy, 3023 Expr *DimExpr, 3024 SourceLocation RParen); 3025 3026 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, 3027 SourceLocation KWLoc, 3028 TypeSourceInfo *TSInfo, 3029 Expr *DimExpr, 3030 SourceLocation RParen); 3031 3032 /// ActOnExpressionTrait - Parsed one of the unary type trait support 3033 /// pseudo-functions. 3034 ExprResult ActOnExpressionTrait(ExpressionTrait OET, 3035 SourceLocation KWLoc, 3036 Expr *Queried, 3037 SourceLocation RParen); 3038 3039 ExprResult BuildExpressionTrait(ExpressionTrait OET, 3040 SourceLocation KWLoc, 3041 Expr *Queried, 3042 SourceLocation RParen); 3043 3044 ExprResult ActOnStartCXXMemberReference(Scope *S, 3045 Expr *Base, 3046 SourceLocation OpLoc, 3047 tok::TokenKind OpKind, 3048 ParsedType &ObjectType, 3049 bool &MayBePseudoDestructor); 3050 3051 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 3052 3053 ExprResult BuildPseudoDestructorExpr(Expr *Base, 3054 SourceLocation OpLoc, 3055 tok::TokenKind OpKind, 3056 const CXXScopeSpec &SS, 3057 TypeSourceInfo *ScopeType, 3058 SourceLocation CCLoc, 3059 SourceLocation TildeLoc, 3060 PseudoDestructorTypeStorage DestroyedType, 3061 bool HasTrailingLParen); 3062 3063 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3064 SourceLocation OpLoc, 3065 tok::TokenKind OpKind, 3066 CXXScopeSpec &SS, 3067 UnqualifiedId &FirstTypeName, 3068 SourceLocation CCLoc, 3069 SourceLocation TildeLoc, 3070 UnqualifiedId &SecondTypeName, 3071 bool HasTrailingLParen); 3072 3073 /// MaybeCreateExprWithCleanups - If the current full-expression 3074 /// requires any cleanups, surround it with a ExprWithCleanups node. 3075 /// Otherwise, just returns the passed-in expression. 3076 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); 3077 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); 3078 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); 3079 3080 ExprResult ActOnFinishFullExpr(Expr *Expr); 3081 StmtResult ActOnFinishFullStmt(Stmt *Stmt); 3082 3083 // Marks SS invalid if it represents an incomplete type. 3084 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 3085 3086 DeclContext *computeDeclContext(QualType T); 3087 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 3088 bool EnteringContext = false); 3089 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 3090 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 3091 bool isUnknownSpecialization(const CXXScopeSpec &SS); 3092 3093 /// \brief The parser has parsed a global nested-name-specifier '::'. 3094 /// 3095 /// \param S The scope in which this nested-name-specifier occurs. 3096 /// 3097 /// \param CCLoc The location of the '::'. 3098 /// 3099 /// \param SS The nested-name-specifier, which will be updated in-place 3100 /// to reflect the parsed nested-name-specifier. 3101 /// 3102 /// \returns true if an error occurred, false otherwise. 3103 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc, 3104 CXXScopeSpec &SS); 3105 3106 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 3107 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 3108 3109 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 3110 SourceLocation IdLoc, 3111 IdentifierInfo &II, 3112 ParsedType ObjectType); 3113 3114 bool BuildCXXNestedNameSpecifier(Scope *S, 3115 IdentifierInfo &Identifier, 3116 SourceLocation IdentifierLoc, 3117 SourceLocation CCLoc, 3118 QualType ObjectType, 3119 bool EnteringContext, 3120 CXXScopeSpec &SS, 3121 NamedDecl *ScopeLookupResult, 3122 bool ErrorRecoveryLookup); 3123 3124 /// \brief The parser has parsed a nested-name-specifier 'identifier::'. 3125 /// 3126 /// \param S The scope in which this nested-name-specifier occurs. 3127 /// 3128 /// \param Identifier The identifier preceding the '::'. 3129 /// 3130 /// \param IdentifierLoc The location of the identifier. 3131 /// 3132 /// \param CCLoc The location of the '::'. 3133 /// 3134 /// \param ObjectType The type of the object, if we're parsing 3135 /// nested-name-specifier in a member access expression. 3136 /// 3137 /// \param EnteringContext Whether we're entering the context nominated by 3138 /// this nested-name-specifier. 3139 /// 3140 /// \param SS The nested-name-specifier, which is both an input 3141 /// parameter (the nested-name-specifier before this type) and an 3142 /// output parameter (containing the full nested-name-specifier, 3143 /// including this new type). 3144 /// 3145 /// \returns true if an error occurred, false otherwise. 3146 bool ActOnCXXNestedNameSpecifier(Scope *S, 3147 IdentifierInfo &Identifier, 3148 SourceLocation IdentifierLoc, 3149 SourceLocation CCLoc, 3150 ParsedType ObjectType, 3151 bool EnteringContext, 3152 CXXScopeSpec &SS); 3153 3154 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 3155 IdentifierInfo &Identifier, 3156 SourceLocation IdentifierLoc, 3157 SourceLocation ColonLoc, 3158 ParsedType ObjectType, 3159 bool EnteringContext); 3160 3161 /// \brief The parser has parsed a nested-name-specifier 3162 /// 'template[opt] template-name < template-args >::'. 3163 /// 3164 /// \param S The scope in which this nested-name-specifier occurs. 3165 /// 3166 /// \param TemplateLoc The location of the 'template' keyword, if any. 3167 /// 3168 /// \param SS The nested-name-specifier, which is both an input 3169 /// parameter (the nested-name-specifier before this type) and an 3170 /// output parameter (containing the full nested-name-specifier, 3171 /// including this new type). 3172 /// 3173 /// \param TemplateLoc the location of the 'template' keyword, if any. 3174 /// \param TemplateName The template name. 3175 /// \param TemplateNameLoc The location of the template name. 3176 /// \param LAngleLoc The location of the opening angle bracket ('<'). 3177 /// \param TemplateArgs The template arguments. 3178 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3179 /// \param CCLoc The location of the '::'. 3180 3181 /// \param EnteringContext Whether we're entering the context of the 3182 /// nested-name-specifier. 3183 /// 3184 /// 3185 /// \returns true if an error occurred, false otherwise. 3186 bool ActOnCXXNestedNameSpecifier(Scope *S, 3187 SourceLocation TemplateLoc, 3188 CXXScopeSpec &SS, 3189 TemplateTy Template, 3190 SourceLocation TemplateNameLoc, 3191 SourceLocation LAngleLoc, 3192 ASTTemplateArgsPtr TemplateArgs, 3193 SourceLocation RAngleLoc, 3194 SourceLocation CCLoc, 3195 bool EnteringContext); 3196 3197 /// \brief Given a C++ nested-name-specifier, produce an annotation value 3198 /// that the parser can use later to reconstruct the given 3199 /// nested-name-specifier. 3200 /// 3201 /// \param SS A nested-name-specifier. 3202 /// 3203 /// \returns A pointer containing all of the information in the 3204 /// nested-name-specifier \p SS. 3205 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); 3206 3207 /// \brief Given an annotation pointer for a nested-name-specifier, restore 3208 /// the nested-name-specifier structure. 3209 /// 3210 /// \param Annotation The annotation pointer, produced by 3211 /// \c SaveNestedNameSpecifierAnnotation(). 3212 /// 3213 /// \param AnnotationRange The source range corresponding to the annotation. 3214 /// 3215 /// \param SS The nested-name-specifier that will be updated with the contents 3216 /// of the annotation pointer. 3217 void RestoreNestedNameSpecifierAnnotation(void *Annotation, 3218 SourceRange AnnotationRange, 3219 CXXScopeSpec &SS); 3220 3221 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3222 3223 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 3224 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 3225 /// After this method is called, according to [C++ 3.4.3p3], names should be 3226 /// looked up in the declarator-id's scope, until the declarator is parsed and 3227 /// ActOnCXXExitDeclaratorScope is called. 3228 /// The 'SS' should be a non-empty valid CXXScopeSpec. 3229 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 3230 3231 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 3232 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 3233 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 3234 /// Used to indicate that names should revert to being looked up in the 3235 /// defining scope. 3236 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3237 3238 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 3239 /// initializer for the declaration 'Dcl'. 3240 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 3241 /// static data member of class X, names should be looked up in the scope of 3242 /// class X. 3243 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 3244 3245 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 3246 /// initializer for the declaration 'Dcl'. 3247 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); 3248 3249 // ParseObjCStringLiteral - Parse Objective-C string literals. 3250 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 3251 Expr **Strings, 3252 unsigned NumStrings); 3253 3254 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, 3255 TypeSourceInfo *EncodedTypeInfo, 3256 SourceLocation RParenLoc); 3257 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, 3258 CXXMethodDecl *Method); 3259 3260 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 3261 SourceLocation EncodeLoc, 3262 SourceLocation LParenLoc, 3263 ParsedType Ty, 3264 SourceLocation RParenLoc); 3265 3266 // ParseObjCSelectorExpression - Build selector expression for @selector 3267 ExprResult ParseObjCSelectorExpression(Selector Sel, 3268 SourceLocation AtLoc, 3269 SourceLocation SelLoc, 3270 SourceLocation LParenLoc, 3271 SourceLocation RParenLoc); 3272 3273 // ParseObjCProtocolExpression - Build protocol expression for @protocol 3274 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 3275 SourceLocation AtLoc, 3276 SourceLocation ProtoLoc, 3277 SourceLocation LParenLoc, 3278 SourceLocation RParenLoc); 3279 3280 //===--------------------------------------------------------------------===// 3281 // C++ Declarations 3282 // 3283 Decl *ActOnStartLinkageSpecification(Scope *S, 3284 SourceLocation ExternLoc, 3285 SourceLocation LangLoc, 3286 StringRef Lang, 3287 SourceLocation LBraceLoc); 3288 Decl *ActOnFinishLinkageSpecification(Scope *S, 3289 Decl *LinkageSpec, 3290 SourceLocation RBraceLoc); 3291 3292 3293 //===--------------------------------------------------------------------===// 3294 // C++ Classes 3295 // 3296 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 3297 const CXXScopeSpec *SS = 0); 3298 3299 Decl *ActOnAccessSpecifier(AccessSpecifier Access, 3300 SourceLocation ASLoc, 3301 SourceLocation ColonLoc); 3302 3303 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 3304 Declarator &D, 3305 MultiTemplateParamsArg TemplateParameterLists, 3306 Expr *BitfieldWidth, const VirtSpecifiers &VS, 3307 Expr *Init, bool HasDeferredInit, 3308 bool IsDefinition); 3309 void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, 3310 Expr *Init); 3311 3312 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 3313 Scope *S, 3314 CXXScopeSpec &SS, 3315 IdentifierInfo *MemberOrBase, 3316 ParsedType TemplateTypeTy, 3317 SourceLocation IdLoc, 3318 SourceLocation LParenLoc, 3319 Expr **Args, unsigned NumArgs, 3320 SourceLocation RParenLoc, 3321 SourceLocation EllipsisLoc); 3322 3323 MemInitResult BuildMemberInitializer(ValueDecl *Member, Expr **Args, 3324 unsigned NumArgs, SourceLocation IdLoc, 3325 SourceLocation LParenLoc, 3326 SourceLocation RParenLoc); 3327 3328 MemInitResult BuildBaseInitializer(QualType BaseType, 3329 TypeSourceInfo *BaseTInfo, 3330 Expr **Args, unsigned NumArgs, 3331 SourceLocation LParenLoc, 3332 SourceLocation RParenLoc, 3333 CXXRecordDecl *ClassDecl, 3334 SourceLocation EllipsisLoc); 3335 3336 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, 3337 Expr **Args, unsigned NumArgs, 3338 SourceLocation BaseLoc, 3339 SourceLocation RParenLoc, 3340 SourceLocation LParenLoc, 3341 CXXRecordDecl *ClassDecl); 3342 3343 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, 3344 CXXCtorInitializer *Initializer); 3345 3346 bool SetCtorInitializers(CXXConstructorDecl *Constructor, 3347 CXXCtorInitializer **Initializers, 3348 unsigned NumInitializers, bool AnyErrors); 3349 3350 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 3351 3352 3353 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 3354 /// mark all the non-trivial destructors of its members and bases as 3355 /// referenced. 3356 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 3357 CXXRecordDecl *Record); 3358 3359 /// \brief The list of classes whose vtables have been used within 3360 /// this translation unit, and the source locations at which the 3361 /// first use occurred. 3362 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; 3363 3364 /// \brief The list of vtables that are required but have not yet been 3365 /// materialized. 3366 SmallVector<VTableUse, 16> VTableUses; 3367 3368 /// \brief The set of classes whose vtables have been used within 3369 /// this translation unit, and a bit that will be true if the vtable is 3370 /// required to be emitted (otherwise, it should be emitted only if needed 3371 /// by code generation). 3372 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 3373 3374 /// \brief A list of all of the dynamic classes in this translation 3375 /// unit. 3376 SmallVector<CXXRecordDecl *, 16> DynamicClasses; 3377 3378 /// \brief Note that the vtable for the given class was used at the 3379 /// given location. 3380 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 3381 bool DefinitionRequired = false); 3382 3383 /// MarkVirtualMembersReferenced - Will mark all members of the given 3384 /// CXXRecordDecl referenced. 3385 void MarkVirtualMembersReferenced(SourceLocation Loc, 3386 const CXXRecordDecl *RD); 3387 3388 /// \brief Define all of the vtables that have been used in this 3389 /// translation unit and reference any virtual members used by those 3390 /// vtables. 3391 /// 3392 /// \returns true if any work was done, false otherwise. 3393 bool DefineUsedVTables(); 3394 3395 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 3396 3397 void ActOnMemInitializers(Decl *ConstructorDecl, 3398 SourceLocation ColonLoc, 3399 MemInitTy **MemInits, unsigned NumMemInits, 3400 bool AnyErrors); 3401 3402 void CheckCompletedCXXClass(CXXRecordDecl *Record); 3403 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 3404 Decl *TagDecl, 3405 SourceLocation LBrac, 3406 SourceLocation RBrac, 3407 AttributeList *AttrList); 3408 3409 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 3410 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 3411 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 3412 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 3413 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 3414 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 3415 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 3416 void ActOnFinishDelayedMemberInitializers(Decl *Record); 3417 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 3418 bool IsInsideALocalClassWithinATemplateFunction(); 3419 3420 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 3421 Expr *AssertExpr, 3422 Expr *AssertMessageExpr, 3423 SourceLocation RParenLoc); 3424 3425 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc, 3426 TypeSourceInfo *TSInfo); 3427 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 3428 MultiTemplateParamsArg TemplateParams); 3429 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition, 3430 MultiTemplateParamsArg TemplateParams); 3431 3432 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 3433 StorageClass& SC); 3434 void CheckConstructor(CXXConstructorDecl *Constructor); 3435 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 3436 StorageClass& SC); 3437 bool CheckDestructor(CXXDestructorDecl *Destructor); 3438 void CheckConversionDeclarator(Declarator &D, QualType &R, 3439 StorageClass& SC); 3440 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 3441 3442 void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record); 3443 void CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *Ctor); 3444 void CheckExplicitlyDefaultedCopyConstructor(CXXConstructorDecl *Ctor); 3445 void CheckExplicitlyDefaultedCopyAssignment(CXXMethodDecl *Method); 3446 void CheckExplicitlyDefaultedDestructor(CXXDestructorDecl *Dtor); 3447 3448 //===--------------------------------------------------------------------===// 3449 // C++ Derived Classes 3450 // 3451 3452 /// ActOnBaseSpecifier - Parsed a base specifier 3453 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 3454 SourceRange SpecifierRange, 3455 bool Virtual, AccessSpecifier Access, 3456 TypeSourceInfo *TInfo, 3457 SourceLocation EllipsisLoc); 3458 3459 BaseResult ActOnBaseSpecifier(Decl *classdecl, 3460 SourceRange SpecifierRange, 3461 bool Virtual, AccessSpecifier Access, 3462 ParsedType basetype, 3463 SourceLocation BaseLoc, 3464 SourceLocation EllipsisLoc); 3465 3466 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 3467 unsigned NumBases); 3468 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases); 3469 3470 bool IsDerivedFrom(QualType Derived, QualType Base); 3471 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 3472 3473 // FIXME: I don't like this name. 3474 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 3475 3476 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 3477 3478 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3479 SourceLocation Loc, SourceRange Range, 3480 CXXCastPath *BasePath = 0, 3481 bool IgnoreAccess = false); 3482 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3483 unsigned InaccessibleBaseID, 3484 unsigned AmbigiousBaseConvID, 3485 SourceLocation Loc, SourceRange Range, 3486 DeclarationName Name, 3487 CXXCastPath *BasePath); 3488 3489 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 3490 3491 /// CheckOverridingFunctionReturnType - Checks whether the return types are 3492 /// covariant, according to C++ [class.virtual]p5. 3493 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 3494 const CXXMethodDecl *Old); 3495 3496 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 3497 /// spec is a subset of base spec. 3498 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 3499 const CXXMethodDecl *Old); 3500 3501 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 3502 3503 /// CheckOverrideControl - Check C++0x override control semantics. 3504 void CheckOverrideControl(const Decl *D); 3505 3506 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 3507 /// overrides a virtual member function marked 'final', according to 3508 /// C++0x [class.virtual]p3. 3509 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 3510 const CXXMethodDecl *Old); 3511 3512 3513 //===--------------------------------------------------------------------===// 3514 // C++ Access Control 3515 // 3516 3517 enum AccessResult { 3518 AR_accessible, 3519 AR_inaccessible, 3520 AR_dependent, 3521 AR_delayed 3522 }; 3523 3524 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 3525 NamedDecl *PrevMemberDecl, 3526 AccessSpecifier LexicalAS); 3527 3528 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 3529 DeclAccessPair FoundDecl); 3530 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 3531 DeclAccessPair FoundDecl); 3532 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 3533 SourceRange PlacementRange, 3534 CXXRecordDecl *NamingClass, 3535 DeclAccessPair FoundDecl, 3536 bool Diagnose = true); 3537 AccessResult CheckConstructorAccess(SourceLocation Loc, 3538 CXXConstructorDecl *D, 3539 const InitializedEntity &Entity, 3540 AccessSpecifier Access, 3541 bool IsCopyBindingRefToTemp = false); 3542 AccessResult CheckConstructorAccess(SourceLocation Loc, 3543 CXXConstructorDecl *D, 3544 AccessSpecifier Access, 3545 PartialDiagnostic PD); 3546 AccessResult CheckDestructorAccess(SourceLocation Loc, 3547 CXXDestructorDecl *Dtor, 3548 const PartialDiagnostic &PDiag); 3549 AccessResult CheckDirectMemberAccess(SourceLocation Loc, 3550 NamedDecl *D, 3551 const PartialDiagnostic &PDiag); 3552 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 3553 Expr *ObjectExpr, 3554 Expr *ArgExpr, 3555 DeclAccessPair FoundDecl); 3556 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 3557 DeclAccessPair FoundDecl); 3558 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 3559 QualType Base, QualType Derived, 3560 const CXXBasePath &Path, 3561 unsigned DiagID, 3562 bool ForceCheck = false, 3563 bool ForceUnprivileged = false); 3564 void CheckLookupAccess(const LookupResult &R); 3565 3566 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 3567 const MultiLevelTemplateArgumentList &TemplateArgs); 3568 void PerformDependentDiagnostics(const DeclContext *Pattern, 3569 const MultiLevelTemplateArgumentList &TemplateArgs); 3570 3571 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 3572 3573 /// A flag to suppress access checking. 3574 bool SuppressAccessChecking; 3575 3576 /// \brief When true, access checking violations are treated as SFINAE 3577 /// failures rather than hard errors. 3578 bool AccessCheckingSFINAE; 3579 3580 void ActOnStartSuppressingAccessChecks(); 3581 void ActOnStopSuppressingAccessChecks(); 3582 3583 enum AbstractDiagSelID { 3584 AbstractNone = -1, 3585 AbstractReturnType, 3586 AbstractParamType, 3587 AbstractVariableType, 3588 AbstractFieldType, 3589 AbstractArrayType 3590 }; 3591 3592 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 3593 const PartialDiagnostic &PD); 3594 void DiagnoseAbstractType(const CXXRecordDecl *RD); 3595 3596 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 3597 AbstractDiagSelID SelID = AbstractNone); 3598 3599 //===--------------------------------------------------------------------===// 3600 // C++ Overloaded Operators [C++ 13.5] 3601 // 3602 3603 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 3604 3605 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 3606 3607 //===--------------------------------------------------------------------===// 3608 // C++ Templates [C++ 14] 3609 // 3610 void FilterAcceptableTemplateNames(LookupResult &R); 3611 bool hasAnyAcceptableTemplateNames(LookupResult &R); 3612 3613 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 3614 QualType ObjectType, bool EnteringContext, 3615 bool &MemberOfUnknownSpecialization); 3616 3617 TemplateNameKind isTemplateName(Scope *S, 3618 CXXScopeSpec &SS, 3619 bool hasTemplateKeyword, 3620 UnqualifiedId &Name, 3621 ParsedType ObjectType, 3622 bool EnteringContext, 3623 TemplateTy &Template, 3624 bool &MemberOfUnknownSpecialization); 3625 3626 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 3627 SourceLocation IILoc, 3628 Scope *S, 3629 const CXXScopeSpec *SS, 3630 TemplateTy &SuggestedTemplate, 3631 TemplateNameKind &SuggestedKind); 3632 3633 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 3634 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 3635 3636 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 3637 SourceLocation EllipsisLoc, 3638 SourceLocation KeyLoc, 3639 IdentifierInfo *ParamName, 3640 SourceLocation ParamNameLoc, 3641 unsigned Depth, unsigned Position, 3642 SourceLocation EqualLoc, 3643 ParsedType DefaultArg); 3644 3645 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 3646 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 3647 unsigned Depth, 3648 unsigned Position, 3649 SourceLocation EqualLoc, 3650 Expr *DefaultArg); 3651 Decl *ActOnTemplateTemplateParameter(Scope *S, 3652 SourceLocation TmpLoc, 3653 TemplateParamsTy *Params, 3654 SourceLocation EllipsisLoc, 3655 IdentifierInfo *ParamName, 3656 SourceLocation ParamNameLoc, 3657 unsigned Depth, 3658 unsigned Position, 3659 SourceLocation EqualLoc, 3660 ParsedTemplateArgument DefaultArg); 3661 3662 TemplateParamsTy * 3663 ActOnTemplateParameterList(unsigned Depth, 3664 SourceLocation ExportLoc, 3665 SourceLocation TemplateLoc, 3666 SourceLocation LAngleLoc, 3667 Decl **Params, unsigned NumParams, 3668 SourceLocation RAngleLoc); 3669 3670 /// \brief The context in which we are checking a template parameter 3671 /// list. 3672 enum TemplateParamListContext { 3673 TPC_ClassTemplate, 3674 TPC_FunctionTemplate, 3675 TPC_ClassTemplateMember, 3676 TPC_FriendFunctionTemplate, 3677 TPC_FriendFunctionTemplateDefinition, 3678 TPC_TypeAliasTemplate 3679 }; 3680 3681 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 3682 TemplateParameterList *OldParams, 3683 TemplateParamListContext TPC); 3684 TemplateParameterList * 3685 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 3686 SourceLocation DeclLoc, 3687 const CXXScopeSpec &SS, 3688 TemplateParameterList **ParamLists, 3689 unsigned NumParamLists, 3690 bool IsFriend, 3691 bool &IsExplicitSpecialization, 3692 bool &Invalid); 3693 3694 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 3695 SourceLocation KWLoc, CXXScopeSpec &SS, 3696 IdentifierInfo *Name, SourceLocation NameLoc, 3697 AttributeList *Attr, 3698 TemplateParameterList *TemplateParams, 3699 AccessSpecifier AS, 3700 unsigned NumOuterTemplateParamLists, 3701 TemplateParameterList **OuterTemplateParamLists); 3702 3703 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 3704 TemplateArgumentListInfo &Out); 3705 3706 void NoteAllFoundTemplates(TemplateName Name); 3707 3708 QualType CheckTemplateIdType(TemplateName Template, 3709 SourceLocation TemplateLoc, 3710 TemplateArgumentListInfo &TemplateArgs); 3711 3712 TypeResult 3713 ActOnTemplateIdType(CXXScopeSpec &SS, 3714 TemplateTy Template, SourceLocation TemplateLoc, 3715 SourceLocation LAngleLoc, 3716 ASTTemplateArgsPtr TemplateArgs, 3717 SourceLocation RAngleLoc); 3718 3719 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 3720 /// such as \c class T::template apply<U>. 3721 /// 3722 /// \param TUK 3723 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 3724 TypeSpecifierType TagSpec, 3725 SourceLocation TagLoc, 3726 CXXScopeSpec &SS, 3727 TemplateTy TemplateD, 3728 SourceLocation TemplateLoc, 3729 SourceLocation LAngleLoc, 3730 ASTTemplateArgsPtr TemplateArgsIn, 3731 SourceLocation RAngleLoc); 3732 3733 3734 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 3735 LookupResult &R, 3736 bool RequiresADL, 3737 const TemplateArgumentListInfo &TemplateArgs); 3738 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 3739 const DeclarationNameInfo &NameInfo, 3740 const TemplateArgumentListInfo &TemplateArgs); 3741 3742 TemplateNameKind ActOnDependentTemplateName(Scope *S, 3743 SourceLocation TemplateKWLoc, 3744 CXXScopeSpec &SS, 3745 UnqualifiedId &Name, 3746 ParsedType ObjectType, 3747 bool EnteringContext, 3748 TemplateTy &Template); 3749 3750 DeclResult 3751 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 3752 SourceLocation KWLoc, 3753 CXXScopeSpec &SS, 3754 TemplateTy Template, 3755 SourceLocation TemplateNameLoc, 3756 SourceLocation LAngleLoc, 3757 ASTTemplateArgsPtr TemplateArgs, 3758 SourceLocation RAngleLoc, 3759 AttributeList *Attr, 3760 MultiTemplateParamsArg TemplateParameterLists); 3761 3762 Decl *ActOnTemplateDeclarator(Scope *S, 3763 MultiTemplateParamsArg TemplateParameterLists, 3764 Declarator &D); 3765 3766 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 3767 MultiTemplateParamsArg TemplateParameterLists, 3768 Declarator &D); 3769 3770 bool 3771 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 3772 TemplateSpecializationKind NewTSK, 3773 NamedDecl *PrevDecl, 3774 TemplateSpecializationKind PrevTSK, 3775 SourceLocation PrevPtOfInstantiation, 3776 bool &SuppressNew); 3777 3778 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 3779 const TemplateArgumentListInfo &ExplicitTemplateArgs, 3780 LookupResult &Previous); 3781 3782 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 3783 TemplateArgumentListInfo *ExplicitTemplateArgs, 3784 LookupResult &Previous); 3785 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 3786 3787 DeclResult 3788 ActOnExplicitInstantiation(Scope *S, 3789 SourceLocation ExternLoc, 3790 SourceLocation TemplateLoc, 3791 unsigned TagSpec, 3792 SourceLocation KWLoc, 3793 const CXXScopeSpec &SS, 3794 TemplateTy Template, 3795 SourceLocation TemplateNameLoc, 3796 SourceLocation LAngleLoc, 3797 ASTTemplateArgsPtr TemplateArgs, 3798 SourceLocation RAngleLoc, 3799 AttributeList *Attr); 3800 3801 DeclResult 3802 ActOnExplicitInstantiation(Scope *S, 3803 SourceLocation ExternLoc, 3804 SourceLocation TemplateLoc, 3805 unsigned TagSpec, 3806 SourceLocation KWLoc, 3807 CXXScopeSpec &SS, 3808 IdentifierInfo *Name, 3809 SourceLocation NameLoc, 3810 AttributeList *Attr); 3811 3812 DeclResult ActOnExplicitInstantiation(Scope *S, 3813 SourceLocation ExternLoc, 3814 SourceLocation TemplateLoc, 3815 Declarator &D); 3816 3817 TemplateArgumentLoc 3818 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 3819 SourceLocation TemplateLoc, 3820 SourceLocation RAngleLoc, 3821 Decl *Param, 3822 SmallVectorImpl<TemplateArgument> &Converted); 3823 3824 /// \brief Specifies the context in which a particular template 3825 /// argument is being checked. 3826 enum CheckTemplateArgumentKind { 3827 /// \brief The template argument was specified in the code or was 3828 /// instantiated with some deduced template arguments. 3829 CTAK_Specified, 3830 3831 /// \brief The template argument was deduced via template argument 3832 /// deduction. 3833 CTAK_Deduced, 3834 3835 /// \brief The template argument was deduced from an array bound 3836 /// via template argument deduction. 3837 CTAK_DeducedFromArrayBound 3838 }; 3839 3840 bool CheckTemplateArgument(NamedDecl *Param, 3841 const TemplateArgumentLoc &Arg, 3842 NamedDecl *Template, 3843 SourceLocation TemplateLoc, 3844 SourceLocation RAngleLoc, 3845 unsigned ArgumentPackIndex, 3846 SmallVectorImpl<TemplateArgument> &Converted, 3847 CheckTemplateArgumentKind CTAK = CTAK_Specified); 3848 3849 /// \brief Check that the given template arguments can be be provided to 3850 /// the given template, converting the arguments along the way. 3851 /// 3852 /// \param Template The template to which the template arguments are being 3853 /// provided. 3854 /// 3855 /// \param TemplateLoc The location of the template name in the source. 3856 /// 3857 /// \param TemplateArgs The list of template arguments. If the template is 3858 /// a template template parameter, this function may extend the set of 3859 /// template arguments to also include substituted, defaulted template 3860 /// arguments. 3861 /// 3862 /// \param PartialTemplateArgs True if the list of template arguments is 3863 /// intentionally partial, e.g., because we're checking just the initial 3864 /// set of template arguments. 3865 /// 3866 /// \param Converted Will receive the converted, canonicalized template 3867 /// arguments. 3868 /// 3869 /// \returns True if an error occurred, false otherwise. 3870 bool CheckTemplateArgumentList(TemplateDecl *Template, 3871 SourceLocation TemplateLoc, 3872 TemplateArgumentListInfo &TemplateArgs, 3873 bool PartialTemplateArgs, 3874 SmallVectorImpl<TemplateArgument> &Converted); 3875 3876 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 3877 const TemplateArgumentLoc &Arg, 3878 SmallVectorImpl<TemplateArgument> &Converted); 3879 3880 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 3881 TypeSourceInfo *Arg); 3882 bool CheckTemplateArgumentPointerToMember(Expr *Arg, 3883 TemplateArgument &Converted); 3884 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 3885 QualType InstantiatedParamType, Expr *Arg, 3886 TemplateArgument &Converted, 3887 CheckTemplateArgumentKind CTAK = CTAK_Specified); 3888 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 3889 const TemplateArgumentLoc &Arg); 3890 3891 ExprResult 3892 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 3893 QualType ParamType, 3894 SourceLocation Loc); 3895 ExprResult 3896 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 3897 SourceLocation Loc); 3898 3899 /// \brief Enumeration describing how template parameter lists are compared 3900 /// for equality. 3901 enum TemplateParameterListEqualKind { 3902 /// \brief We are matching the template parameter lists of two templates 3903 /// that might be redeclarations. 3904 /// 3905 /// \code 3906 /// template<typename T> struct X; 3907 /// template<typename T> struct X; 3908 /// \endcode 3909 TPL_TemplateMatch, 3910 3911 /// \brief We are matching the template parameter lists of two template 3912 /// template parameters as part of matching the template parameter lists 3913 /// of two templates that might be redeclarations. 3914 /// 3915 /// \code 3916 /// template<template<int I> class TT> struct X; 3917 /// template<template<int Value> class Other> struct X; 3918 /// \endcode 3919 TPL_TemplateTemplateParmMatch, 3920 3921 /// \brief We are matching the template parameter lists of a template 3922 /// template argument against the template parameter lists of a template 3923 /// template parameter. 3924 /// 3925 /// \code 3926 /// template<template<int Value> class Metafun> struct X; 3927 /// template<int Value> struct integer_c; 3928 /// X<integer_c> xic; 3929 /// \endcode 3930 TPL_TemplateTemplateArgumentMatch 3931 }; 3932 3933 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 3934 TemplateParameterList *Old, 3935 bool Complain, 3936 TemplateParameterListEqualKind Kind, 3937 SourceLocation TemplateArgLoc 3938 = SourceLocation()); 3939 3940 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 3941 3942 /// \brief Called when the parser has parsed a C++ typename 3943 /// specifier, e.g., "typename T::type". 3944 /// 3945 /// \param S The scope in which this typename type occurs. 3946 /// \param TypenameLoc the location of the 'typename' keyword 3947 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3948 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 3949 /// \param IdLoc the location of the identifier. 3950 TypeResult 3951 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3952 const CXXScopeSpec &SS, const IdentifierInfo &II, 3953 SourceLocation IdLoc); 3954 3955 /// \brief Called when the parser has parsed a C++ typename 3956 /// specifier that ends in a template-id, e.g., 3957 /// "typename MetaFun::template apply<T1, T2>". 3958 /// 3959 /// \param S The scope in which this typename type occurs. 3960 /// \param TypenameLoc the location of the 'typename' keyword 3961 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3962 /// \param TemplateLoc the location of the 'template' keyword, if any. 3963 /// \param TemplateName The template name. 3964 /// \param TemplateNameLoc The location of the template name. 3965 /// \param LAngleLoc The location of the opening angle bracket ('<'). 3966 /// \param TemplateArgs The template arguments. 3967 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3968 TypeResult 3969 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3970 const CXXScopeSpec &SS, 3971 SourceLocation TemplateLoc, 3972 TemplateTy Template, 3973 SourceLocation TemplateNameLoc, 3974 SourceLocation LAngleLoc, 3975 ASTTemplateArgsPtr TemplateArgs, 3976 SourceLocation RAngleLoc); 3977 3978 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 3979 SourceLocation KeywordLoc, 3980 NestedNameSpecifierLoc QualifierLoc, 3981 const IdentifierInfo &II, 3982 SourceLocation IILoc); 3983 3984 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 3985 SourceLocation Loc, 3986 DeclarationName Name); 3987 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 3988 3989 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 3990 3991 std::string 3992 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3993 const TemplateArgumentList &Args); 3994 3995 std::string 3996 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3997 const TemplateArgument *Args, 3998 unsigned NumArgs); 3999 4000 //===--------------------------------------------------------------------===// 4001 // C++ Variadic Templates (C++0x [temp.variadic]) 4002 //===--------------------------------------------------------------------===// 4003 4004 /// \brief The context in which an unexpanded parameter pack is 4005 /// being diagnosed. 4006 /// 4007 /// Note that the values of this enumeration line up with the first 4008 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 4009 enum UnexpandedParameterPackContext { 4010 /// \brief An arbitrary expression. 4011 UPPC_Expression = 0, 4012 4013 /// \brief The base type of a class type. 4014 UPPC_BaseType, 4015 4016 /// \brief The type of an arbitrary declaration. 4017 UPPC_DeclarationType, 4018 4019 /// \brief The type of a data member. 4020 UPPC_DataMemberType, 4021 4022 /// \brief The size of a bit-field. 4023 UPPC_BitFieldWidth, 4024 4025 /// \brief The expression in a static assertion. 4026 UPPC_StaticAssertExpression, 4027 4028 /// \brief The fixed underlying type of an enumeration. 4029 UPPC_FixedUnderlyingType, 4030 4031 /// \brief The enumerator value. 4032 UPPC_EnumeratorValue, 4033 4034 /// \brief A using declaration. 4035 UPPC_UsingDeclaration, 4036 4037 /// \brief A friend declaration. 4038 UPPC_FriendDeclaration, 4039 4040 /// \brief A declaration qualifier. 4041 UPPC_DeclarationQualifier, 4042 4043 /// \brief An initializer. 4044 UPPC_Initializer, 4045 4046 /// \brief A default argument. 4047 UPPC_DefaultArgument, 4048 4049 /// \brief The type of a non-type template parameter. 4050 UPPC_NonTypeTemplateParameterType, 4051 4052 /// \brief The type of an exception. 4053 UPPC_ExceptionType, 4054 4055 /// \brief Partial specialization. 4056 UPPC_PartialSpecialization 4057 }; 4058 4059 /// \brief If the given type contains an unexpanded parameter pack, 4060 /// diagnose the error. 4061 /// 4062 /// \param Loc The source location where a diagnostc should be emitted. 4063 /// 4064 /// \param T The type that is being checked for unexpanded parameter 4065 /// packs. 4066 /// 4067 /// \returns true if an error occurred, false otherwise. 4068 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 4069 UnexpandedParameterPackContext UPPC); 4070 4071 /// \brief If the given expression contains an unexpanded parameter 4072 /// pack, diagnose the error. 4073 /// 4074 /// \param E The expression that is being checked for unexpanded 4075 /// parameter packs. 4076 /// 4077 /// \returns true if an error occurred, false otherwise. 4078 bool DiagnoseUnexpandedParameterPack(Expr *E, 4079 UnexpandedParameterPackContext UPPC = UPPC_Expression); 4080 4081 /// \brief If the given nested-name-specifier contains an unexpanded 4082 /// parameter pack, diagnose the error. 4083 /// 4084 /// \param SS The nested-name-specifier that is being checked for 4085 /// unexpanded parameter packs. 4086 /// 4087 /// \returns true if an error occurred, false otherwise. 4088 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 4089 UnexpandedParameterPackContext UPPC); 4090 4091 /// \brief If the given name contains an unexpanded parameter pack, 4092 /// diagnose the error. 4093 /// 4094 /// \param NameInfo The name (with source location information) that 4095 /// is being checked for unexpanded parameter packs. 4096 /// 4097 /// \returns true if an error occurred, false otherwise. 4098 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 4099 UnexpandedParameterPackContext UPPC); 4100 4101 /// \brief If the given template name contains an unexpanded parameter pack, 4102 /// diagnose the error. 4103 /// 4104 /// \param Loc The location of the template name. 4105 /// 4106 /// \param Template The template name that is being checked for unexpanded 4107 /// parameter packs. 4108 /// 4109 /// \returns true if an error occurred, false otherwise. 4110 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 4111 TemplateName Template, 4112 UnexpandedParameterPackContext UPPC); 4113 4114 /// \brief If the given template argument contains an unexpanded parameter 4115 /// pack, diagnose the error. 4116 /// 4117 /// \param Arg The template argument that is being checked for unexpanded 4118 /// parameter packs. 4119 /// 4120 /// \returns true if an error occurred, false otherwise. 4121 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 4122 UnexpandedParameterPackContext UPPC); 4123 4124 /// \brief Collect the set of unexpanded parameter packs within the given 4125 /// template argument. 4126 /// 4127 /// \param Arg The template argument that will be traversed to find 4128 /// unexpanded parameter packs. 4129 void collectUnexpandedParameterPacks(TemplateArgument Arg, 4130 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4131 4132 /// \brief Collect the set of unexpanded parameter packs within the given 4133 /// template argument. 4134 /// 4135 /// \param Arg The template argument that will be traversed to find 4136 /// unexpanded parameter packs. 4137 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 4138 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4139 4140 /// \brief Collect the set of unexpanded parameter packs within the given 4141 /// type. 4142 /// 4143 /// \param T The type that will be traversed to find 4144 /// unexpanded parameter packs. 4145 void collectUnexpandedParameterPacks(QualType T, 4146 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4147 4148 /// \brief Collect the set of unexpanded parameter packs within the given 4149 /// type. 4150 /// 4151 /// \param TL The type that will be traversed to find 4152 /// unexpanded parameter packs. 4153 void collectUnexpandedParameterPacks(TypeLoc TL, 4154 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4155 4156 /// \brief Invoked when parsing a template argument followed by an 4157 /// ellipsis, which creates a pack expansion. 4158 /// 4159 /// \param Arg The template argument preceding the ellipsis, which 4160 /// may already be invalid. 4161 /// 4162 /// \param EllipsisLoc The location of the ellipsis. 4163 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 4164 SourceLocation EllipsisLoc); 4165 4166 /// \brief Invoked when parsing a type followed by an ellipsis, which 4167 /// creates a pack expansion. 4168 /// 4169 /// \param Type The type preceding the ellipsis, which will become 4170 /// the pattern of the pack expansion. 4171 /// 4172 /// \param EllipsisLoc The location of the ellipsis. 4173 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 4174 4175 /// \brief Construct a pack expansion type from the pattern of the pack 4176 /// expansion. 4177 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 4178 SourceLocation EllipsisLoc, 4179 llvm::Optional<unsigned> NumExpansions); 4180 4181 /// \brief Construct a pack expansion type from the pattern of the pack 4182 /// expansion. 4183 QualType CheckPackExpansion(QualType Pattern, 4184 SourceRange PatternRange, 4185 SourceLocation EllipsisLoc, 4186 llvm::Optional<unsigned> NumExpansions); 4187 4188 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4189 /// creates a pack expansion. 4190 /// 4191 /// \param Pattern The expression preceding the ellipsis, which will become 4192 /// the pattern of the pack expansion. 4193 /// 4194 /// \param EllipsisLoc The location of the ellipsis. 4195 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 4196 4197 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4198 /// creates a pack expansion. 4199 /// 4200 /// \param Pattern The expression preceding the ellipsis, which will become 4201 /// the pattern of the pack expansion. 4202 /// 4203 /// \param EllipsisLoc The location of the ellipsis. 4204 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 4205 llvm::Optional<unsigned> NumExpansions); 4206 4207 /// \brief Determine whether we could expand a pack expansion with the 4208 /// given set of parameter packs into separate arguments by repeatedly 4209 /// transforming the pattern. 4210 /// 4211 /// \param EllipsisLoc The location of the ellipsis that identifies the 4212 /// pack expansion. 4213 /// 4214 /// \param PatternRange The source range that covers the entire pattern of 4215 /// the pack expansion. 4216 /// 4217 /// \param Unexpanded The set of unexpanded parameter packs within the 4218 /// pattern. 4219 /// 4220 /// \param NumUnexpanded The number of unexpanded parameter packs in 4221 /// \p Unexpanded. 4222 /// 4223 /// \param ShouldExpand Will be set to \c true if the transformer should 4224 /// expand the corresponding pack expansions into separate arguments. When 4225 /// set, \c NumExpansions must also be set. 4226 /// 4227 /// \param RetainExpansion Whether the caller should add an unexpanded 4228 /// pack expansion after all of the expanded arguments. This is used 4229 /// when extending explicitly-specified template argument packs per 4230 /// C++0x [temp.arg.explicit]p9. 4231 /// 4232 /// \param NumExpansions The number of separate arguments that will be in 4233 /// the expanded form of the corresponding pack expansion. This is both an 4234 /// input and an output parameter, which can be set by the caller if the 4235 /// number of expansions is known a priori (e.g., due to a prior substitution) 4236 /// and will be set by the callee when the number of expansions is known. 4237 /// The callee must set this value when \c ShouldExpand is \c true; it may 4238 /// set this value in other cases. 4239 /// 4240 /// \returns true if an error occurred (e.g., because the parameter packs 4241 /// are to be instantiated with arguments of different lengths), false 4242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 4243 /// must be set. 4244 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 4245 SourceRange PatternRange, 4246 const UnexpandedParameterPack *Unexpanded, 4247 unsigned NumUnexpanded, 4248 const MultiLevelTemplateArgumentList &TemplateArgs, 4249 bool &ShouldExpand, 4250 bool &RetainExpansion, 4251 llvm::Optional<unsigned> &NumExpansions); 4252 4253 /// \brief Determine the number of arguments in the given pack expansion 4254 /// type. 4255 /// 4256 /// This routine already assumes that the pack expansion type can be 4257 /// expanded and that the number of arguments in the expansion is 4258 /// consistent across all of the unexpanded parameter packs in its pattern. 4259 unsigned getNumArgumentsInExpansion(QualType T, 4260 const MultiLevelTemplateArgumentList &TemplateArgs); 4261 4262 /// \brief Determine whether the given declarator contains any unexpanded 4263 /// parameter packs. 4264 /// 4265 /// This routine is used by the parser to disambiguate function declarators 4266 /// with an ellipsis prior to the ')', e.g., 4267 /// 4268 /// \code 4269 /// void f(T...); 4270 /// \endcode 4271 /// 4272 /// To determine whether we have an (unnamed) function parameter pack or 4273 /// a variadic function. 4274 /// 4275 /// \returns true if the declarator contains any unexpanded parameter packs, 4276 /// false otherwise. 4277 bool containsUnexpandedParameterPacks(Declarator &D); 4278 4279 //===--------------------------------------------------------------------===// 4280 // C++ Template Argument Deduction (C++ [temp.deduct]) 4281 //===--------------------------------------------------------------------===// 4282 4283 /// \brief Describes the result of template argument deduction. 4284 /// 4285 /// The TemplateDeductionResult enumeration describes the result of 4286 /// template argument deduction, as returned from 4287 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 4288 /// structure provides additional information about the results of 4289 /// template argument deduction, e.g., the deduced template argument 4290 /// list (if successful) or the specific template parameters or 4291 /// deduced arguments that were involved in the failure. 4292 enum TemplateDeductionResult { 4293 /// \brief Template argument deduction was successful. 4294 TDK_Success = 0, 4295 /// \brief Template argument deduction exceeded the maximum template 4296 /// instantiation depth (which has already been diagnosed). 4297 TDK_InstantiationDepth, 4298 /// \brief Template argument deduction did not deduce a value 4299 /// for every template parameter. 4300 TDK_Incomplete, 4301 /// \brief Template argument deduction produced inconsistent 4302 /// deduced values for the given template parameter. 4303 TDK_Inconsistent, 4304 /// \brief Template argument deduction failed due to inconsistent 4305 /// cv-qualifiers on a template parameter type that would 4306 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 4307 /// but were given a non-const "X". 4308 TDK_Underqualified, 4309 /// \brief Substitution of the deduced template argument values 4310 /// resulted in an error. 4311 TDK_SubstitutionFailure, 4312 /// \brief Substitution of the deduced template argument values 4313 /// into a non-deduced context produced a type or value that 4314 /// produces a type that does not match the original template 4315 /// arguments provided. 4316 TDK_NonDeducedMismatch, 4317 /// \brief When performing template argument deduction for a function 4318 /// template, there were too many call arguments. 4319 TDK_TooManyArguments, 4320 /// \brief When performing template argument deduction for a function 4321 /// template, there were too few call arguments. 4322 TDK_TooFewArguments, 4323 /// \brief The explicitly-specified template arguments were not valid 4324 /// template arguments for the given template. 4325 TDK_InvalidExplicitArguments, 4326 /// \brief The arguments included an overloaded function name that could 4327 /// not be resolved to a suitable function. 4328 TDK_FailedOverloadResolution 4329 }; 4330 4331 TemplateDeductionResult 4332 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 4333 const TemplateArgumentList &TemplateArgs, 4334 sema::TemplateDeductionInfo &Info); 4335 4336 TemplateDeductionResult 4337 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4338 TemplateArgumentListInfo &ExplicitTemplateArgs, 4339 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 4340 SmallVectorImpl<QualType> &ParamTypes, 4341 QualType *FunctionType, 4342 sema::TemplateDeductionInfo &Info); 4343 4344 /// brief A function argument from which we performed template argument 4345 // deduction for a call. 4346 struct OriginalCallArg { 4347 OriginalCallArg(QualType OriginalParamType, 4348 unsigned ArgIdx, 4349 QualType OriginalArgType) 4350 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx), 4351 OriginalArgType(OriginalArgType) { } 4352 4353 QualType OriginalParamType; 4354 unsigned ArgIdx; 4355 QualType OriginalArgType; 4356 }; 4357 4358 TemplateDeductionResult 4359 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 4360 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 4361 unsigned NumExplicitlySpecified, 4362 FunctionDecl *&Specialization, 4363 sema::TemplateDeductionInfo &Info, 4364 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0); 4365 4366 TemplateDeductionResult 4367 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4368 TemplateArgumentListInfo *ExplicitTemplateArgs, 4369 Expr **Args, unsigned NumArgs, 4370 FunctionDecl *&Specialization, 4371 sema::TemplateDeductionInfo &Info); 4372 4373 TemplateDeductionResult 4374 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4375 TemplateArgumentListInfo *ExplicitTemplateArgs, 4376 QualType ArgFunctionType, 4377 FunctionDecl *&Specialization, 4378 sema::TemplateDeductionInfo &Info); 4379 4380 TemplateDeductionResult 4381 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4382 QualType ToType, 4383 CXXConversionDecl *&Specialization, 4384 sema::TemplateDeductionInfo &Info); 4385 4386 TemplateDeductionResult 4387 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4388 TemplateArgumentListInfo *ExplicitTemplateArgs, 4389 FunctionDecl *&Specialization, 4390 sema::TemplateDeductionInfo &Info); 4391 4392 bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer, 4393 TypeSourceInfo *&Result); 4394 4395 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 4396 FunctionTemplateDecl *FT2, 4397 SourceLocation Loc, 4398 TemplatePartialOrderingContext TPOC, 4399 unsigned NumCallArguments); 4400 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 4401 UnresolvedSetIterator SEnd, 4402 TemplatePartialOrderingContext TPOC, 4403 unsigned NumCallArguments, 4404 SourceLocation Loc, 4405 const PartialDiagnostic &NoneDiag, 4406 const PartialDiagnostic &AmbigDiag, 4407 const PartialDiagnostic &CandidateDiag, 4408 bool Complain = true); 4409 4410 ClassTemplatePartialSpecializationDecl * 4411 getMoreSpecializedPartialSpecialization( 4412 ClassTemplatePartialSpecializationDecl *PS1, 4413 ClassTemplatePartialSpecializationDecl *PS2, 4414 SourceLocation Loc); 4415 4416 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 4417 bool OnlyDeduced, 4418 unsigned Depth, 4419 SmallVectorImpl<bool> &Used); 4420 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 4421 SmallVectorImpl<bool> &Deduced); 4422 4423 //===--------------------------------------------------------------------===// 4424 // C++ Template Instantiation 4425 // 4426 4427 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 4428 const TemplateArgumentList *Innermost = 0, 4429 bool RelativeToPrimary = false, 4430 const FunctionDecl *Pattern = 0); 4431 4432 /// \brief A template instantiation that is currently in progress. 4433 struct ActiveTemplateInstantiation { 4434 /// \brief The kind of template instantiation we are performing 4435 enum InstantiationKind { 4436 /// We are instantiating a template declaration. The entity is 4437 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 4438 TemplateInstantiation, 4439 4440 /// We are instantiating a default argument for a template 4441 /// parameter. The Entity is the template, and 4442 /// TemplateArgs/NumTemplateArguments provides the template 4443 /// arguments as specified. 4444 /// FIXME: Use a TemplateArgumentList 4445 DefaultTemplateArgumentInstantiation, 4446 4447 /// We are instantiating a default argument for a function. 4448 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 4449 /// provides the template arguments as specified. 4450 DefaultFunctionArgumentInstantiation, 4451 4452 /// We are substituting explicit template arguments provided for 4453 /// a function template. The entity is a FunctionTemplateDecl. 4454 ExplicitTemplateArgumentSubstitution, 4455 4456 /// We are substituting template argument determined as part of 4457 /// template argument deduction for either a class template 4458 /// partial specialization or a function template. The 4459 /// Entity is either a ClassTemplatePartialSpecializationDecl or 4460 /// a FunctionTemplateDecl. 4461 DeducedTemplateArgumentSubstitution, 4462 4463 /// We are substituting prior template arguments into a new 4464 /// template parameter. The template parameter itself is either a 4465 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 4466 PriorTemplateArgumentSubstitution, 4467 4468 /// We are checking the validity of a default template argument that 4469 /// has been used when naming a template-id. 4470 DefaultTemplateArgumentChecking 4471 } Kind; 4472 4473 /// \brief The point of instantiation within the source code. 4474 SourceLocation PointOfInstantiation; 4475 4476 /// \brief The template (or partial specialization) in which we are 4477 /// performing the instantiation, for substitutions of prior template 4478 /// arguments. 4479 NamedDecl *Template; 4480 4481 /// \brief The entity that is being instantiated. 4482 uintptr_t Entity; 4483 4484 /// \brief The list of template arguments we are substituting, if they 4485 /// are not part of the entity. 4486 const TemplateArgument *TemplateArgs; 4487 4488 /// \brief The number of template arguments in TemplateArgs. 4489 unsigned NumTemplateArgs; 4490 4491 /// \brief The template deduction info object associated with the 4492 /// substitution or checking of explicit or deduced template arguments. 4493 sema::TemplateDeductionInfo *DeductionInfo; 4494 4495 /// \brief The source range that covers the construct that cause 4496 /// the instantiation, e.g., the template-id that causes a class 4497 /// template instantiation. 4498 SourceRange InstantiationRange; 4499 4500 ActiveTemplateInstantiation() 4501 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 4502 NumTemplateArgs(0), DeductionInfo(0) {} 4503 4504 /// \brief Determines whether this template is an actual instantiation 4505 /// that should be counted toward the maximum instantiation depth. 4506 bool isInstantiationRecord() const; 4507 4508 friend bool operator==(const ActiveTemplateInstantiation &X, 4509 const ActiveTemplateInstantiation &Y) { 4510 if (X.Kind != Y.Kind) 4511 return false; 4512 4513 if (X.Entity != Y.Entity) 4514 return false; 4515 4516 switch (X.Kind) { 4517 case TemplateInstantiation: 4518 return true; 4519 4520 case PriorTemplateArgumentSubstitution: 4521 case DefaultTemplateArgumentChecking: 4522 if (X.Template != Y.Template) 4523 return false; 4524 4525 // Fall through 4526 4527 case DefaultTemplateArgumentInstantiation: 4528 case ExplicitTemplateArgumentSubstitution: 4529 case DeducedTemplateArgumentSubstitution: 4530 case DefaultFunctionArgumentInstantiation: 4531 return X.TemplateArgs == Y.TemplateArgs; 4532 4533 } 4534 4535 return true; 4536 } 4537 4538 friend bool operator!=(const ActiveTemplateInstantiation &X, 4539 const ActiveTemplateInstantiation &Y) { 4540 return !(X == Y); 4541 } 4542 }; 4543 4544 /// \brief List of active template instantiations. 4545 /// 4546 /// This vector is treated as a stack. As one template instantiation 4547 /// requires another template instantiation, additional 4548 /// instantiations are pushed onto the stack up to a 4549 /// user-configurable limit LangOptions::InstantiationDepth. 4550 SmallVector<ActiveTemplateInstantiation, 16> 4551 ActiveTemplateInstantiations; 4552 4553 /// \brief Whether we are in a SFINAE context that is not associated with 4554 /// template instantiation. 4555 /// 4556 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 4557 /// of a template instantiation or template argument deduction. 4558 bool InNonInstantiationSFINAEContext; 4559 4560 /// \brief The number of ActiveTemplateInstantiation entries in 4561 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 4562 /// therefore, should not be counted as part of the instantiation depth. 4563 unsigned NonInstantiationEntries; 4564 4565 /// \brief The last template from which a template instantiation 4566 /// error or warning was produced. 4567 /// 4568 /// This value is used to suppress printing of redundant template 4569 /// instantiation backtraces when there are multiple errors in the 4570 /// same instantiation. FIXME: Does this belong in Sema? It's tough 4571 /// to implement it anywhere else. 4572 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 4573 4574 /// \brief The current index into pack expansion arguments that will be 4575 /// used for substitution of parameter packs. 4576 /// 4577 /// The pack expansion index will be -1 to indicate that parameter packs 4578 /// should be instantiated as themselves. Otherwise, the index specifies 4579 /// which argument within the parameter pack will be used for substitution. 4580 int ArgumentPackSubstitutionIndex; 4581 4582 /// \brief RAII object used to change the argument pack substitution index 4583 /// within a \c Sema object. 4584 /// 4585 /// See \c ArgumentPackSubstitutionIndex for more information. 4586 class ArgumentPackSubstitutionIndexRAII { 4587 Sema &Self; 4588 int OldSubstitutionIndex; 4589 4590 public: 4591 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 4592 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 4593 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 4594 } 4595 4596 ~ArgumentPackSubstitutionIndexRAII() { 4597 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 4598 } 4599 }; 4600 4601 friend class ArgumentPackSubstitutionRAII; 4602 4603 /// \brief The stack of calls expression undergoing template instantiation. 4604 /// 4605 /// The top of this stack is used by a fixit instantiating unresolved 4606 /// function calls to fix the AST to match the textual change it prints. 4607 SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 4608 4609 /// \brief For each declaration that involved template argument deduction, the 4610 /// set of diagnostics that were suppressed during that template argument 4611 /// deduction. 4612 /// 4613 /// FIXME: Serialize this structure to the AST file. 4614 llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > 4615 SuppressedDiagnostics; 4616 4617 /// \brief A stack object to be created when performing template 4618 /// instantiation. 4619 /// 4620 /// Construction of an object of type \c InstantiatingTemplate 4621 /// pushes the current instantiation onto the stack of active 4622 /// instantiations. If the size of this stack exceeds the maximum 4623 /// number of recursive template instantiations, construction 4624 /// produces an error and evaluates true. 4625 /// 4626 /// Destruction of this object will pop the named instantiation off 4627 /// the stack. 4628 struct InstantiatingTemplate { 4629 /// \brief Note that we are instantiating a class template, 4630 /// function template, or a member thereof. 4631 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4632 Decl *Entity, 4633 SourceRange InstantiationRange = SourceRange()); 4634 4635 /// \brief Note that we are instantiating a default argument in a 4636 /// template-id. 4637 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4638 TemplateDecl *Template, 4639 const TemplateArgument *TemplateArgs, 4640 unsigned NumTemplateArgs, 4641 SourceRange InstantiationRange = SourceRange()); 4642 4643 /// \brief Note that we are instantiating a default argument in a 4644 /// template-id. 4645 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4646 FunctionTemplateDecl *FunctionTemplate, 4647 const TemplateArgument *TemplateArgs, 4648 unsigned NumTemplateArgs, 4649 ActiveTemplateInstantiation::InstantiationKind Kind, 4650 sema::TemplateDeductionInfo &DeductionInfo, 4651 SourceRange InstantiationRange = SourceRange()); 4652 4653 /// \brief Note that we are instantiating as part of template 4654 /// argument deduction for a class template partial 4655 /// specialization. 4656 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4657 ClassTemplatePartialSpecializationDecl *PartialSpec, 4658 const TemplateArgument *TemplateArgs, 4659 unsigned NumTemplateArgs, 4660 sema::TemplateDeductionInfo &DeductionInfo, 4661 SourceRange InstantiationRange = SourceRange()); 4662 4663 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4664 ParmVarDecl *Param, 4665 const TemplateArgument *TemplateArgs, 4666 unsigned NumTemplateArgs, 4667 SourceRange InstantiationRange = SourceRange()); 4668 4669 /// \brief Note that we are substituting prior template arguments into a 4670 /// non-type or template template parameter. 4671 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4672 NamedDecl *Template, 4673 NonTypeTemplateParmDecl *Param, 4674 const TemplateArgument *TemplateArgs, 4675 unsigned NumTemplateArgs, 4676 SourceRange InstantiationRange); 4677 4678 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4679 NamedDecl *Template, 4680 TemplateTemplateParmDecl *Param, 4681 const TemplateArgument *TemplateArgs, 4682 unsigned NumTemplateArgs, 4683 SourceRange InstantiationRange); 4684 4685 /// \brief Note that we are checking the default template argument 4686 /// against the template parameter for a given template-id. 4687 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4688 TemplateDecl *Template, 4689 NamedDecl *Param, 4690 const TemplateArgument *TemplateArgs, 4691 unsigned NumTemplateArgs, 4692 SourceRange InstantiationRange); 4693 4694 4695 /// \brief Note that we have finished instantiating this template. 4696 void Clear(); 4697 4698 ~InstantiatingTemplate() { Clear(); } 4699 4700 /// \brief Determines whether we have exceeded the maximum 4701 /// recursive template instantiations. 4702 operator bool() const { return Invalid; } 4703 4704 private: 4705 Sema &SemaRef; 4706 bool Invalid; 4707 bool SavedInNonInstantiationSFINAEContext; 4708 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 4709 SourceRange InstantiationRange); 4710 4711 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented 4712 4713 InstantiatingTemplate& 4714 operator=(const InstantiatingTemplate&); // not implemented 4715 }; 4716 4717 void PrintInstantiationStack(); 4718 4719 /// \brief Determines whether we are currently in a context where 4720 /// template argument substitution failures are not considered 4721 /// errors. 4722 /// 4723 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 4724 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 4725 /// template-deduction context object, which can be used to capture 4726 /// diagnostics that will be suppressed. 4727 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 4728 4729 /// \brief RAII class used to determine whether SFINAE has 4730 /// trapped any errors that occur during template argument 4731 /// deduction.` 4732 class SFINAETrap { 4733 Sema &SemaRef; 4734 unsigned PrevSFINAEErrors; 4735 bool PrevInNonInstantiationSFINAEContext; 4736 bool PrevAccessCheckingSFINAE; 4737 4738 public: 4739 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 4740 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 4741 PrevInNonInstantiationSFINAEContext( 4742 SemaRef.InNonInstantiationSFINAEContext), 4743 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 4744 { 4745 if (!SemaRef.isSFINAEContext()) 4746 SemaRef.InNonInstantiationSFINAEContext = true; 4747 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 4748 } 4749 4750 ~SFINAETrap() { 4751 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 4752 SemaRef.InNonInstantiationSFINAEContext 4753 = PrevInNonInstantiationSFINAEContext; 4754 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 4755 } 4756 4757 /// \brief Determine whether any SFINAE errors have been trapped. 4758 bool hasErrorOccurred() const { 4759 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 4760 } 4761 }; 4762 4763 /// \brief The current instantiation scope used to store local 4764 /// variables. 4765 LocalInstantiationScope *CurrentInstantiationScope; 4766 4767 /// \brief The number of typos corrected by CorrectTypo. 4768 unsigned TyposCorrected; 4769 4770 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection> 4771 UnqualifiedTyposCorrectedMap; 4772 4773 /// \brief A cache containing the results of typo correction for unqualified 4774 /// name lookup. 4775 /// 4776 /// The string is the string that we corrected to (which may be empty, if 4777 /// there was no correction), while the boolean will be true when the 4778 /// string represents a keyword. 4779 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 4780 4781 /// \brief Worker object for performing CFG-based warnings. 4782 sema::AnalysisBasedWarnings AnalysisWarnings; 4783 4784 /// \brief An entity for which implicit template instantiation is required. 4785 /// 4786 /// The source location associated with the declaration is the first place in 4787 /// the source code where the declaration was "used". It is not necessarily 4788 /// the point of instantiation (which will be either before or after the 4789 /// namespace-scope declaration that triggered this implicit instantiation), 4790 /// However, it is the location that diagnostics should generally refer to, 4791 /// because users will need to know what code triggered the instantiation. 4792 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 4793 4794 /// \brief The queue of implicit template instantiations that are required 4795 /// but have not yet been performed. 4796 std::deque<PendingImplicitInstantiation> PendingInstantiations; 4797 4798 /// \brief The queue of implicit template instantiations that are required 4799 /// and must be performed within the current local scope. 4800 /// 4801 /// This queue is only used for member functions of local classes in 4802 /// templates, which must be instantiated in the same scope as their 4803 /// enclosing function, so that they can reference function-local 4804 /// types, static variables, enumerators, etc. 4805 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 4806 4807 void PerformPendingInstantiations(bool LocalOnly = false); 4808 4809 TypeSourceInfo *SubstType(TypeSourceInfo *T, 4810 const MultiLevelTemplateArgumentList &TemplateArgs, 4811 SourceLocation Loc, DeclarationName Entity); 4812 4813 QualType SubstType(QualType T, 4814 const MultiLevelTemplateArgumentList &TemplateArgs, 4815 SourceLocation Loc, DeclarationName Entity); 4816 4817 TypeSourceInfo *SubstType(TypeLoc TL, 4818 const MultiLevelTemplateArgumentList &TemplateArgs, 4819 SourceLocation Loc, DeclarationName Entity); 4820 4821 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 4822 const MultiLevelTemplateArgumentList &TemplateArgs, 4823 SourceLocation Loc, 4824 DeclarationName Entity); 4825 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 4826 const MultiLevelTemplateArgumentList &TemplateArgs, 4827 int indexAdjustment, 4828 llvm::Optional<unsigned> NumExpansions); 4829 bool SubstParmTypes(SourceLocation Loc, 4830 ParmVarDecl **Params, unsigned NumParams, 4831 const MultiLevelTemplateArgumentList &TemplateArgs, 4832 SmallVectorImpl<QualType> &ParamTypes, 4833 SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 4834 ExprResult SubstExpr(Expr *E, 4835 const MultiLevelTemplateArgumentList &TemplateArgs); 4836 4837 /// \brief Substitute the given template arguments into a list of 4838 /// expressions, expanding pack expansions if required. 4839 /// 4840 /// \param Exprs The list of expressions to substitute into. 4841 /// 4842 /// \param NumExprs The number of expressions in \p Exprs. 4843 /// 4844 /// \param IsCall Whether this is some form of call, in which case 4845 /// default arguments will be dropped. 4846 /// 4847 /// \param TemplateArgs The set of template arguments to substitute. 4848 /// 4849 /// \param Outputs Will receive all of the substituted arguments. 4850 /// 4851 /// \returns true if an error occurred, false otherwise. 4852 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 4853 const MultiLevelTemplateArgumentList &TemplateArgs, 4854 SmallVectorImpl<Expr *> &Outputs); 4855 4856 StmtResult SubstStmt(Stmt *S, 4857 const MultiLevelTemplateArgumentList &TemplateArgs); 4858 4859 Decl *SubstDecl(Decl *D, DeclContext *Owner, 4860 const MultiLevelTemplateArgumentList &TemplateArgs); 4861 4862 bool 4863 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 4864 CXXRecordDecl *Pattern, 4865 const MultiLevelTemplateArgumentList &TemplateArgs); 4866 4867 bool 4868 InstantiateClass(SourceLocation PointOfInstantiation, 4869 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 4870 const MultiLevelTemplateArgumentList &TemplateArgs, 4871 TemplateSpecializationKind TSK, 4872 bool Complain = true); 4873 4874 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 4875 const Decl *Pattern, Decl *Inst); 4876 4877 bool 4878 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 4879 ClassTemplateSpecializationDecl *ClassTemplateSpec, 4880 TemplateSpecializationKind TSK, 4881 bool Complain = true); 4882 4883 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 4884 CXXRecordDecl *Instantiation, 4885 const MultiLevelTemplateArgumentList &TemplateArgs, 4886 TemplateSpecializationKind TSK); 4887 4888 void InstantiateClassTemplateSpecializationMembers( 4889 SourceLocation PointOfInstantiation, 4890 ClassTemplateSpecializationDecl *ClassTemplateSpec, 4891 TemplateSpecializationKind TSK); 4892 4893 NestedNameSpecifierLoc 4894 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 4895 const MultiLevelTemplateArgumentList &TemplateArgs); 4896 4897 DeclarationNameInfo 4898 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 4899 const MultiLevelTemplateArgumentList &TemplateArgs); 4900 TemplateName 4901 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 4902 SourceLocation Loc, 4903 const MultiLevelTemplateArgumentList &TemplateArgs); 4904 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 4905 TemplateArgumentListInfo &Result, 4906 const MultiLevelTemplateArgumentList &TemplateArgs); 4907 4908 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 4909 FunctionDecl *Function, 4910 bool Recursive = false, 4911 bool DefinitionRequired = false); 4912 void InstantiateStaticDataMemberDefinition( 4913 SourceLocation PointOfInstantiation, 4914 VarDecl *Var, 4915 bool Recursive = false, 4916 bool DefinitionRequired = false); 4917 4918 void InstantiateMemInitializers(CXXConstructorDecl *New, 4919 const CXXConstructorDecl *Tmpl, 4920 const MultiLevelTemplateArgumentList &TemplateArgs); 4921 bool InstantiateInitializer(Expr *Init, 4922 const MultiLevelTemplateArgumentList &TemplateArgs, 4923 SourceLocation &LParenLoc, 4924 ASTOwningVector<Expr*> &NewArgs, 4925 SourceLocation &RParenLoc); 4926 4927 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 4928 const MultiLevelTemplateArgumentList &TemplateArgs); 4929 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 4930 const MultiLevelTemplateArgumentList &TemplateArgs); 4931 4932 // Objective-C declarations. 4933 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 4934 IdentifierInfo *ClassName, 4935 SourceLocation ClassLoc, 4936 IdentifierInfo *SuperName, 4937 SourceLocation SuperLoc, 4938 Decl * const *ProtoRefs, 4939 unsigned NumProtoRefs, 4940 const SourceLocation *ProtoLocs, 4941 SourceLocation EndProtoLoc, 4942 AttributeList *AttrList); 4943 4944 Decl *ActOnCompatiblityAlias( 4945 SourceLocation AtCompatibilityAliasLoc, 4946 IdentifierInfo *AliasName, SourceLocation AliasLocation, 4947 IdentifierInfo *ClassName, SourceLocation ClassLocation); 4948 4949 bool CheckForwardProtocolDeclarationForCircularDependency( 4950 IdentifierInfo *PName, 4951 SourceLocation &PLoc, SourceLocation PrevLoc, 4952 const ObjCList<ObjCProtocolDecl> &PList); 4953 4954 Decl *ActOnStartProtocolInterface( 4955 SourceLocation AtProtoInterfaceLoc, 4956 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 4957 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 4958 const SourceLocation *ProtoLocs, 4959 SourceLocation EndProtoLoc, 4960 AttributeList *AttrList); 4961 4962 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 4963 IdentifierInfo *ClassName, 4964 SourceLocation ClassLoc, 4965 IdentifierInfo *CategoryName, 4966 SourceLocation CategoryLoc, 4967 Decl * const *ProtoRefs, 4968 unsigned NumProtoRefs, 4969 const SourceLocation *ProtoLocs, 4970 SourceLocation EndProtoLoc); 4971 4972 Decl *ActOnStartClassImplementation( 4973 SourceLocation AtClassImplLoc, 4974 IdentifierInfo *ClassName, SourceLocation ClassLoc, 4975 IdentifierInfo *SuperClassname, 4976 SourceLocation SuperClassLoc); 4977 4978 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 4979 IdentifierInfo *ClassName, 4980 SourceLocation ClassLoc, 4981 IdentifierInfo *CatName, 4982 SourceLocation CatLoc); 4983 4984 Decl *ActOnForwardClassDeclaration(SourceLocation Loc, 4985 IdentifierInfo **IdentList, 4986 SourceLocation *IdentLocs, 4987 unsigned NumElts); 4988 4989 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 4990 const IdentifierLocPair *IdentList, 4991 unsigned NumElts, 4992 AttributeList *attrList); 4993 4994 void FindProtocolDeclaration(bool WarnOnDeclarations, 4995 const IdentifierLocPair *ProtocolId, 4996 unsigned NumProtocols, 4997 SmallVectorImpl<Decl *> &Protocols); 4998 4999 /// Ensure attributes are consistent with type. 5000 /// \param [in, out] Attributes The attributes to check; they will 5001 /// be modified to be consistent with \arg PropertyTy. 5002 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 5003 SourceLocation Loc, 5004 unsigned &Attributes); 5005 5006 /// Process the specified property declaration and create decls for the 5007 /// setters and getters as needed. 5008 /// \param property The property declaration being processed 5009 /// \param DC The semantic container for the property 5010 /// \param redeclaredProperty Declaration for property if redeclared 5011 /// in class extension. 5012 /// \param lexicalDC Container for redeclaredProperty. 5013 void ProcessPropertyDecl(ObjCPropertyDecl *property, 5014 ObjCContainerDecl *DC, 5015 ObjCPropertyDecl *redeclaredProperty = 0, 5016 ObjCContainerDecl *lexicalDC = 0); 5017 5018 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 5019 ObjCPropertyDecl *SuperProperty, 5020 const IdentifierInfo *Name); 5021 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 5022 5023 void CompareMethodParamsInBaseAndSuper(Decl *IDecl, 5024 ObjCMethodDecl *MethodDecl, 5025 bool IsInstance); 5026 5027 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 5028 5029 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 5030 ObjCInterfaceDecl *ID); 5031 5032 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 5033 ObjCProtocolDecl *PDecl); 5034 5035 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl, 5036 Decl **allMethods = 0, unsigned allNum = 0, 5037 Decl **allProperties = 0, unsigned pNum = 0, 5038 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 5039 5040 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 5041 FieldDeclarator &FD, ObjCDeclSpec &ODS, 5042 Selector GetterSel, Selector SetterSel, 5043 Decl *ClassCategory, 5044 bool *OverridingProperty, 5045 tok::ObjCKeywordKind MethodImplKind, 5046 DeclContext *lexicalDC = 0); 5047 5048 Decl *ActOnPropertyImplDecl(Scope *S, 5049 SourceLocation AtLoc, 5050 SourceLocation PropertyLoc, 5051 bool ImplKind,Decl *ClassImplDecl, 5052 IdentifierInfo *PropertyId, 5053 IdentifierInfo *PropertyIvar, 5054 SourceLocation PropertyIvarLoc); 5055 5056 enum ObjCSpecialMethodKind { 5057 OSMK_None, 5058 OSMK_Alloc, 5059 OSMK_New, 5060 OSMK_Copy, 5061 OSMK_RetainingInit, 5062 OSMK_NonRetainingInit 5063 }; 5064 5065 struct ObjCArgInfo { 5066 IdentifierInfo *Name; 5067 SourceLocation NameLoc; 5068 // The Type is null if no type was specified, and the DeclSpec is invalid 5069 // in this case. 5070 ParsedType Type; 5071 ObjCDeclSpec DeclSpec; 5072 5073 /// ArgAttrs - Attribute list for this argument. 5074 AttributeList *ArgAttrs; 5075 }; 5076 5077 Decl *ActOnMethodDeclaration( 5078 Scope *S, 5079 SourceLocation BeginLoc, // location of the + or -. 5080 SourceLocation EndLoc, // location of the ; or {. 5081 tok::TokenKind MethodType, 5082 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 5083 SourceLocation SelectorStartLoc, Selector Sel, 5084 // optional arguments. The number of types/arguments is obtained 5085 // from the Sel.getNumArgs(). 5086 ObjCArgInfo *ArgInfo, 5087 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 5088 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 5089 bool isVariadic, bool MethodDefinition); 5090 5091 // Helper method for ActOnClassMethod/ActOnInstanceMethod. 5092 // Will search "local" class/category implementations for a method decl. 5093 // Will also search in class's root looking for instance method. 5094 // Returns 0 if no method is found. 5095 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, 5096 ObjCInterfaceDecl *CDecl); 5097 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, 5098 ObjCInterfaceDecl *ClassDecl); 5099 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 5100 const ObjCObjectPointerType *OPT, 5101 bool IsInstance); 5102 5103 bool inferObjCARCLifetime(ValueDecl *decl); 5104 5105 ExprResult 5106 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 5107 Expr *BaseExpr, 5108 SourceLocation OpLoc, 5109 DeclarationName MemberName, 5110 SourceLocation MemberLoc, 5111 SourceLocation SuperLoc, QualType SuperType, 5112 bool Super); 5113 5114 ExprResult 5115 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 5116 IdentifierInfo &propertyName, 5117 SourceLocation receiverNameLoc, 5118 SourceLocation propertyNameLoc); 5119 5120 ObjCMethodDecl *tryCaptureObjCSelf(); 5121 5122 /// \brief Describes the kind of message expression indicated by a message 5123 /// send that starts with an identifier. 5124 enum ObjCMessageKind { 5125 /// \brief The message is sent to 'super'. 5126 ObjCSuperMessage, 5127 /// \brief The message is an instance message. 5128 ObjCInstanceMessage, 5129 /// \brief The message is a class message, and the identifier is a type 5130 /// name. 5131 ObjCClassMessage 5132 }; 5133 5134 ObjCMessageKind getObjCMessageKind(Scope *S, 5135 IdentifierInfo *Name, 5136 SourceLocation NameLoc, 5137 bool IsSuper, 5138 bool HasTrailingDot, 5139 ParsedType &ReceiverType); 5140 5141 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 5142 Selector Sel, 5143 SourceLocation LBracLoc, 5144 SourceLocation SelectorLoc, 5145 SourceLocation RBracLoc, 5146 MultiExprArg Args); 5147 5148 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 5149 QualType ReceiverType, 5150 SourceLocation SuperLoc, 5151 Selector Sel, 5152 ObjCMethodDecl *Method, 5153 SourceLocation LBracLoc, 5154 SourceLocation SelectorLoc, 5155 SourceLocation RBracLoc, 5156 MultiExprArg Args); 5157 5158 ExprResult ActOnClassMessage(Scope *S, 5159 ParsedType Receiver, 5160 Selector Sel, 5161 SourceLocation LBracLoc, 5162 SourceLocation SelectorLoc, 5163 SourceLocation RBracLoc, 5164 MultiExprArg Args); 5165 5166 ExprResult BuildInstanceMessage(Expr *Receiver, 5167 QualType ReceiverType, 5168 SourceLocation SuperLoc, 5169 Selector Sel, 5170 ObjCMethodDecl *Method, 5171 SourceLocation LBracLoc, 5172 SourceLocation SelectorLoc, 5173 SourceLocation RBracLoc, 5174 MultiExprArg Args); 5175 5176 ExprResult ActOnInstanceMessage(Scope *S, 5177 Expr *Receiver, 5178 Selector Sel, 5179 SourceLocation LBracLoc, 5180 SourceLocation SelectorLoc, 5181 SourceLocation RBracLoc, 5182 MultiExprArg Args); 5183 5184 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, 5185 ObjCBridgeCastKind Kind, 5186 SourceLocation BridgeKeywordLoc, 5187 TypeSourceInfo *TSInfo, 5188 Expr *SubExpr); 5189 5190 ExprResult ActOnObjCBridgedCast(Scope *S, 5191 SourceLocation LParenLoc, 5192 ObjCBridgeCastKind Kind, 5193 SourceLocation BridgeKeywordLoc, 5194 ParsedType Type, 5195 SourceLocation RParenLoc, 5196 Expr *SubExpr); 5197 5198 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); 5199 5200 /// \brief Check whether the given new method is a valid override of the 5201 /// given overridden method, and set any properties that should be inherited. 5202 /// 5203 /// \returns True if an error occurred. 5204 bool CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 5205 const ObjCMethodDecl *Overridden, 5206 bool IsImplementation); 5207 5208 /// \brief Check whether the given method overrides any methods in its class, 5209 /// calling \c CheckObjCMethodOverride for each overridden method. 5210 bool CheckObjCMethodOverrides(ObjCMethodDecl *NewMethod, DeclContext *DC); 5211 5212 enum PragmaOptionsAlignKind { 5213 POAK_Native, // #pragma options align=native 5214 POAK_Natural, // #pragma options align=natural 5215 POAK_Packed, // #pragma options align=packed 5216 POAK_Power, // #pragma options align=power 5217 POAK_Mac68k, // #pragma options align=mac68k 5218 POAK_Reset // #pragma options align=reset 5219 }; 5220 5221 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align. 5222 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 5223 SourceLocation PragmaLoc, 5224 SourceLocation KindLoc); 5225 5226 enum PragmaPackKind { 5227 PPK_Default, // #pragma pack([n]) 5228 PPK_Show, // #pragma pack(show), only supported by MSVC. 5229 PPK_Push, // #pragma pack(push, [identifier], [n]) 5230 PPK_Pop // #pragma pack(pop, [identifier], [n]) 5231 }; 5232 5233 enum PragmaMSStructKind { 5234 PMSST_OFF, // #pragms ms_struct off 5235 PMSST_ON // #pragms ms_struct on 5236 }; 5237 5238 /// ActOnPragmaPack - Called on well formed #pragma pack(...). 5239 void ActOnPragmaPack(PragmaPackKind Kind, 5240 IdentifierInfo *Name, 5241 Expr *Alignment, 5242 SourceLocation PragmaLoc, 5243 SourceLocation LParenLoc, 5244 SourceLocation RParenLoc); 5245 5246 /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off]. 5247 void ActOnPragmaMSStruct(PragmaMSStructKind Kind); 5248 5249 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. 5250 void ActOnPragmaUnused(const Token &Identifier, 5251 Scope *curScope, 5252 SourceLocation PragmaLoc); 5253 5254 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... . 5255 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType, 5256 SourceLocation PragmaLoc); 5257 5258 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II); 5259 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 5260 5261 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident. 5262 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 5263 SourceLocation PragmaLoc, 5264 SourceLocation WeakNameLoc); 5265 5266 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident. 5267 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 5268 IdentifierInfo* AliasName, 5269 SourceLocation PragmaLoc, 5270 SourceLocation WeakNameLoc, 5271 SourceLocation AliasNameLoc); 5272 5273 /// ActOnPragmaFPContract - Called on well formed 5274 /// #pragma {STDC,OPENCL} FP_CONTRACT 5275 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 5276 5277 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 5278 /// a the record decl, to handle '#pragma pack' and '#pragma options align'. 5279 void AddAlignmentAttributesForRecord(RecordDecl *RD); 5280 5281 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. 5282 void AddMsStructLayoutForRecord(RecordDecl *RD); 5283 5284 /// FreePackedContext - Deallocate and null out PackContext. 5285 void FreePackedContext(); 5286 5287 /// PushNamespaceVisibilityAttr - Note that we've entered a 5288 /// namespace with a visibility attribute. 5289 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr); 5290 5291 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, 5292 /// add an appropriate visibility attribute. 5293 void AddPushedVisibilityAttribute(Decl *RD); 5294 5295 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 5296 /// for '#pragma GCC visibility' and visibility attributes on namespaces. 5297 void PopPragmaVisibility(); 5298 5299 /// FreeVisContext - Deallocate and null out VisContext. 5300 void FreeVisContext(); 5301 5302 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 5303 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E); 5304 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T); 5305 5306 /// CastCategory - Get the correct forwarded implicit cast result category 5307 /// from the inner expression. 5308 ExprValueKind CastCategory(Expr *E); 5309 5310 /// \brief The kind of conversion being performed. 5311 enum CheckedConversionKind { 5312 /// \brief An implicit conversion. 5313 CCK_ImplicitConversion, 5314 /// \brief A C-style cast. 5315 CCK_CStyleCast, 5316 /// \brief A functional-style cast. 5317 CCK_FunctionalCast, 5318 /// \brief A cast other than a C-style cast. 5319 CCK_OtherCast 5320 }; 5321 5322 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 5323 /// cast. If there is already an implicit cast, merge into the existing one. 5324 /// If isLvalue, the result of the cast is an lvalue. 5325 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 5326 ExprValueKind VK = VK_RValue, 5327 const CXXCastPath *BasePath = 0, 5328 CheckedConversionKind CCK 5329 = CCK_ImplicitConversion); 5330 5331 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 5332 /// to the conversion from scalar type ScalarTy to the Boolean type. 5333 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 5334 5335 /// IgnoredValueConversions - Given that an expression's result is 5336 /// syntactically ignored, perform any conversions that are 5337 /// required. 5338 ExprResult IgnoredValueConversions(Expr *E); 5339 5340 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 5341 // functions and arrays to their respective pointers (C99 6.3.2.1). 5342 ExprResult UsualUnaryConversions(Expr *E); 5343 5344 // DefaultFunctionArrayConversion - converts functions and arrays 5345 // to their respective pointers (C99 6.3.2.1). 5346 ExprResult DefaultFunctionArrayConversion(Expr *E); 5347 5348 // DefaultFunctionArrayLvalueConversion - converts functions and 5349 // arrays to their respective pointers and performs the 5350 // lvalue-to-rvalue conversion. 5351 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 5352 5353 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 5354 // the operand. This is DefaultFunctionArrayLvalueConversion, 5355 // except that it assumes the operand isn't of function or array 5356 // type. 5357 ExprResult DefaultLvalueConversion(Expr *E); 5358 5359 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 5360 // do not have a prototype. Integer promotions are performed on each 5361 // argument, and arguments that have type float are promoted to double. 5362 ExprResult DefaultArgumentPromotion(Expr *E); 5363 5364 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 5365 enum VariadicCallType { 5366 VariadicFunction, 5367 VariadicBlock, 5368 VariadicMethod, 5369 VariadicConstructor, 5370 VariadicDoesNotApply 5371 }; 5372 5373 /// GatherArgumentsForCall - Collector argument expressions for various 5374 /// form of call prototypes. 5375 bool GatherArgumentsForCall(SourceLocation CallLoc, 5376 FunctionDecl *FDecl, 5377 const FunctionProtoType *Proto, 5378 unsigned FirstProtoArg, 5379 Expr **Args, unsigned NumArgs, 5380 SmallVector<Expr *, 8> &AllArgs, 5381 VariadicCallType CallType = VariadicDoesNotApply); 5382 5383 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 5384 // will warn if the resulting type is not a POD type. 5385 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 5386 FunctionDecl *FDecl); 5387 5388 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 5389 // operands and then handles various conversions that are common to binary 5390 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 5391 // routine returns the first non-arithmetic type found. The client is 5392 // responsible for emitting appropriate error diagnostics. 5393 QualType UsualArithmeticConversions(ExprResult &lExpr, ExprResult &rExpr, 5394 bool isCompAssign = false); 5395 5396 /// AssignConvertType - All of the 'assignment' semantic checks return this 5397 /// enum to indicate whether the assignment was allowed. These checks are 5398 /// done for simple assignments, as well as initialization, return from 5399 /// function, argument passing, etc. The query is phrased in terms of a 5400 /// source and destination type. 5401 enum AssignConvertType { 5402 /// Compatible - the types are compatible according to the standard. 5403 Compatible, 5404 5405 /// PointerToInt - The assignment converts a pointer to an int, which we 5406 /// accept as an extension. 5407 PointerToInt, 5408 5409 /// IntToPointer - The assignment converts an int to a pointer, which we 5410 /// accept as an extension. 5411 IntToPointer, 5412 5413 /// FunctionVoidPointer - The assignment is between a function pointer and 5414 /// void*, which the standard doesn't allow, but we accept as an extension. 5415 FunctionVoidPointer, 5416 5417 /// IncompatiblePointer - The assignment is between two pointers types that 5418 /// are not compatible, but we accept them as an extension. 5419 IncompatiblePointer, 5420 5421 /// IncompatiblePointer - The assignment is between two pointers types which 5422 /// point to integers which have a different sign, but are otherwise identical. 5423 /// This is a subset of the above, but broken out because it's by far the most 5424 /// common case of incompatible pointers. 5425 IncompatiblePointerSign, 5426 5427 /// CompatiblePointerDiscardsQualifiers - The assignment discards 5428 /// c/v/r qualifiers, which we accept as an extension. 5429 CompatiblePointerDiscardsQualifiers, 5430 5431 /// IncompatiblePointerDiscardsQualifiers - The assignment 5432 /// discards qualifiers that we don't permit to be discarded, 5433 /// like address spaces. 5434 IncompatiblePointerDiscardsQualifiers, 5435 5436 /// IncompatibleNestedPointerQualifiers - The assignment is between two 5437 /// nested pointer types, and the qualifiers other than the first two 5438 /// levels differ e.g. char ** -> const char **, but we accept them as an 5439 /// extension. 5440 IncompatibleNestedPointerQualifiers, 5441 5442 /// IncompatibleVectors - The assignment is between two vector types that 5443 /// have the same size, which we accept as an extension. 5444 IncompatibleVectors, 5445 5446 /// IntToBlockPointer - The assignment converts an int to a block 5447 /// pointer. We disallow this. 5448 IntToBlockPointer, 5449 5450 /// IncompatibleBlockPointer - The assignment is between two block 5451 /// pointers types that are not compatible. 5452 IncompatibleBlockPointer, 5453 5454 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 5455 /// id type and something else (that is incompatible with it). For example, 5456 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 5457 IncompatibleObjCQualifiedId, 5458 5459 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an 5460 /// object with __weak qualifier. 5461 IncompatibleObjCWeakRef, 5462 5463 /// Incompatible - We reject this conversion outright, it is invalid to 5464 /// represent it in the AST. 5465 Incompatible 5466 }; 5467 5468 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 5469 /// assignment conversion type specified by ConvTy. This returns true if the 5470 /// conversion was invalid or false if the conversion was accepted. 5471 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 5472 SourceLocation Loc, 5473 QualType DstType, QualType SrcType, 5474 Expr *SrcExpr, AssignmentAction Action, 5475 bool *Complained = 0); 5476 5477 /// CheckAssignmentConstraints - Perform type checking for assignment, 5478 /// argument passing, variable initialization, and function return values. 5479 /// C99 6.5.16. 5480 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 5481 QualType lhs, QualType rhs); 5482 5483 /// Check assignment constraints and prepare for a conversion of the 5484 /// RHS to the LHS type. 5485 AssignConvertType CheckAssignmentConstraints(QualType lhs, ExprResult &rhs, 5486 CastKind &Kind); 5487 5488 // CheckSingleAssignmentConstraints - Currently used by 5489 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 5490 // this routine performs the default function/array converions. 5491 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, 5492 ExprResult &rExprRes); 5493 5494 // \brief If the lhs type is a transparent union, check whether we 5495 // can initialize the transparent union with the given expression. 5496 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs, 5497 ExprResult &rExpr); 5498 5499 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 5500 5501 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 5502 5503 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5504 AssignmentAction Action, 5505 bool AllowExplicit = false); 5506 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5507 AssignmentAction Action, 5508 bool AllowExplicit, 5509 ImplicitConversionSequence& ICS); 5510 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5511 const ImplicitConversionSequence& ICS, 5512 AssignmentAction Action, 5513 CheckedConversionKind CCK 5514 = CCK_ImplicitConversion); 5515 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5516 const StandardConversionSequence& SCS, 5517 AssignmentAction Action, 5518 CheckedConversionKind CCK); 5519 5520 /// the following "Check" methods will return a valid/converted QualType 5521 /// or a null QualType (indicating an error diagnostic was issued). 5522 5523 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 5524 QualType InvalidOperands(SourceLocation l, ExprResult &lex, ExprResult &rex); 5525 QualType CheckPointerToMemberOperands( // C++ 5.5 5526 ExprResult &lex, ExprResult &rex, ExprValueKind &VK, 5527 SourceLocation OpLoc, bool isIndirect); 5528 QualType CheckMultiplyDivideOperands( // C99 6.5.5 5529 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign, 5530 bool isDivide); 5531 QualType CheckRemainderOperands( // C99 6.5.5 5532 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false); 5533 QualType CheckAdditionOperands( // C99 6.5.6 5534 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 5535 QualType CheckSubtractionOperands( // C99 6.5.6 5536 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 5537 QualType CheckShiftOperands( // C99 6.5.7 5538 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc, 5539 bool isCompAssign = false); 5540 QualType CheckCompareOperands( // C99 6.5.8/9 5541 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc, 5542 bool isRelational); 5543 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 5544 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false); 5545 QualType CheckLogicalOperands( // C99 6.5.[13,14] 5546 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc); 5547 // CheckAssignmentOperands is used for both simple and compound assignment. 5548 // For simple assignment, pass both expressions and a null converted type. 5549 // For compound assignment, pass both expressions and the converted type. 5550 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 5551 Expr *lex, ExprResult &rex, SourceLocation OpLoc, QualType convertedType); 5552 5553 void ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS, QualType& LHSTy); 5554 ExprResult ConvertPropertyForRValue(Expr *E); 5555 5556 QualType CheckConditionalOperands( // C99 6.5.15 5557 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 5558 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 5559 QualType CXXCheckConditionalOperands( // C++ 5.16 5560 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 5561 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 5562 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 5563 bool *NonStandardCompositeType = 0); 5564 QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1, ExprResult &E2, 5565 bool *NonStandardCompositeType = 0) { 5566 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 5567 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, NonStandardCompositeType); 5568 E1 = Owned(E1Tmp); 5569 E2 = Owned(E2Tmp); 5570 return Composite; 5571 } 5572 5573 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 5574 SourceLocation questionLoc); 5575 5576 bool DiagnoseConditionalForNull(Expr *LHS, Expr *RHS, 5577 SourceLocation QuestionLoc); 5578 5579 /// type checking for vector binary operators. 5580 QualType CheckVectorOperands(ExprResult &lex, ExprResult &rex, 5581 SourceLocation Loc, bool isCompAssign); 5582 QualType CheckVectorCompareOperands(ExprResult &lex, ExprResult &rx, 5583 SourceLocation l, bool isRel); 5584 5585 /// type checking declaration initializers (C99 6.7.8) 5586 bool CheckInitList(const InitializedEntity &Entity, 5587 InitListExpr *&InitList, QualType &DeclType); 5588 bool CheckForConstantInitializer(Expr *e, QualType t); 5589 5590 // type checking C++ declaration initializers (C++ [dcl.init]). 5591 5592 /// ReferenceCompareResult - Expresses the result of comparing two 5593 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 5594 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 5595 enum ReferenceCompareResult { 5596 /// Ref_Incompatible - The two types are incompatible, so direct 5597 /// reference binding is not possible. 5598 Ref_Incompatible = 0, 5599 /// Ref_Related - The two types are reference-related, which means 5600 /// that their unqualified forms (T1 and T2) are either the same 5601 /// or T1 is a base class of T2. 5602 Ref_Related, 5603 /// Ref_Compatible_With_Added_Qualification - The two types are 5604 /// reference-compatible with added qualification, meaning that 5605 /// they are reference-compatible and the qualifiers on T1 (cv1) 5606 /// are greater than the qualifiers on T2 (cv2). 5607 Ref_Compatible_With_Added_Qualification, 5608 /// Ref_Compatible - The two types are reference-compatible and 5609 /// have equivalent qualifiers (cv1 == cv2). 5610 Ref_Compatible 5611 }; 5612 5613 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 5614 QualType T1, QualType T2, 5615 bool &DerivedToBase, 5616 bool &ObjCConversion, 5617 bool &ObjCLifetimeConversion); 5618 5619 /// CheckCastTypes - Check type constraints for casting between types under 5620 /// C semantics, or forward to CXXCheckCStyleCast in C++. 5621 ExprResult CheckCastTypes(SourceLocation CastStartLoc, SourceRange TyRange, 5622 QualType CastTy, Expr *CastExpr, CastKind &Kind, 5623 ExprValueKind &VK, CXXCastPath &BasePath, 5624 bool FunctionalStyle = false); 5625 5626 ExprResult checkUnknownAnyCast(SourceRange TyRange, QualType castType, 5627 Expr *castExpr, CastKind &castKind, 5628 ExprValueKind &valueKind, CXXCastPath &BasePath); 5629 5630 // CheckVectorCast - check type constraints for vectors. 5631 // Since vectors are an extension, there are no C standard reference for this. 5632 // We allow casting between vectors and integer datatypes of the same size. 5633 // returns true if the cast is invalid 5634 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 5635 CastKind &Kind); 5636 5637 // CheckExtVectorCast - check type constraints for extended vectors. 5638 // Since vectors are an extension, there are no C standard reference for this. 5639 // We allow casting between vectors and integer datatypes of the same size, 5640 // or vectors and the element type of that vector. 5641 // returns the cast expr 5642 ExprResult CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *CastExpr, 5643 CastKind &Kind); 5644 5645 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style 5646 /// cast under C++ semantics. 5647 ExprResult CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK, 5648 Expr *CastExpr, CastKind &Kind, 5649 CXXCastPath &BasePath, bool FunctionalStyle); 5650 5651 /// \brief Checks for valid expressions which can be cast to an ObjC 5652 /// pointer without needing a bridge cast. 5653 bool ValidObjCARCNoBridgeCastExpr(Expr *&Exp, QualType castType); 5654 5655 /// \brief Checks for invalid conversions and casts between 5656 /// retainable pointers and other pointer kinds. 5657 void CheckObjCARCConversion(SourceRange castRange, QualType castType, 5658 Expr *&op, CheckedConversionKind CCK); 5659 5660 bool CheckObjCARCUnavailableWeakConversion(QualType castType, 5661 QualType ExprType); 5662 5663 /// checkRetainCycles - Check whether an Objective-C message send 5664 /// might create an obvious retain cycle. 5665 void checkRetainCycles(ObjCMessageExpr *msg); 5666 void checkRetainCycles(Expr *receiver, Expr *argument); 5667 5668 /// checkUnsafeAssigns - Check whether +1 expr is being assigned 5669 /// to weak/__unsafe_unretained type. 5670 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); 5671 5672 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned 5673 /// to weak/__unsafe_unretained expression. 5674 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); 5675 5676 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 5677 /// \param Method - May be null. 5678 /// \param [out] ReturnType - The return type of the send. 5679 /// \return true iff there were any incompatible types. 5680 bool CheckMessageArgumentTypes(QualType ReceiverType, 5681 Expr **Args, unsigned NumArgs, Selector Sel, 5682 ObjCMethodDecl *Method, bool isClassMessage, 5683 bool isSuperMessage, 5684 SourceLocation lbrac, SourceLocation rbrac, 5685 QualType &ReturnType, ExprValueKind &VK); 5686 5687 /// \brief Determine the result of a message send expression based on 5688 /// the type of the receiver, the method expected to receive the message, 5689 /// and the form of the message send. 5690 QualType getMessageSendResultType(QualType ReceiverType, 5691 ObjCMethodDecl *Method, 5692 bool isClassMessage, bool isSuperMessage); 5693 5694 /// \brief If the given expression involves a message send to a method 5695 /// with a related result type, emit a note describing what happened. 5696 void EmitRelatedResultTypeNote(const Expr *E); 5697 5698 /// CheckBooleanCondition - Diagnose problems involving the use of 5699 /// the given expression as a boolean condition (e.g. in an if 5700 /// statement). Also performs the standard function and array 5701 /// decays, possibly changing the input variable. 5702 /// 5703 /// \param Loc - A location associated with the condition, e.g. the 5704 /// 'if' keyword. 5705 /// \return true iff there were any errors 5706 ExprResult CheckBooleanCondition(Expr *CondExpr, SourceLocation Loc); 5707 5708 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 5709 Expr *SubExpr); 5710 5711 /// DiagnoseAssignmentAsCondition - Given that an expression is 5712 /// being used as a boolean condition, warn if it's an assignment. 5713 void DiagnoseAssignmentAsCondition(Expr *E); 5714 5715 /// \brief Redundant parentheses over an equality comparison can indicate 5716 /// that the user intended an assignment used as condition. 5717 void DiagnoseEqualityWithExtraParens(ParenExpr *parenE); 5718 5719 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 5720 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 5721 5722 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 5723 /// the specified width and sign. If an overflow occurs, detect it and emit 5724 /// the specified diagnostic. 5725 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 5726 unsigned NewWidth, bool NewSign, 5727 SourceLocation Loc, unsigned DiagID); 5728 5729 /// Checks that the Objective-C declaration is declared in the global scope. 5730 /// Emits an error and marks the declaration as invalid if it's not declared 5731 /// in the global scope. 5732 bool CheckObjCDeclScope(Decl *D); 5733 5734 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, 5735 /// and reports the appropriate diagnostics. Returns false on success. 5736 /// Can optionally return the value of the expression. 5737 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); 5738 5739 /// VerifyBitField - verifies that a bit field expression is an ICE and has 5740 /// the correct width, and that the field type is valid. 5741 /// Returns false on success. 5742 /// Can optionally return whether the bit-field is of width 0 5743 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 5744 QualType FieldTy, const Expr *BitWidth, 5745 bool *ZeroWidth = 0); 5746 5747 /// \name Code completion 5748 //@{ 5749 /// \brief Describes the context in which code completion occurs. 5750 enum ParserCompletionContext { 5751 /// \brief Code completion occurs at top-level or namespace context. 5752 PCC_Namespace, 5753 /// \brief Code completion occurs within a class, struct, or union. 5754 PCC_Class, 5755 /// \brief Code completion occurs within an Objective-C interface, protocol, 5756 /// or category. 5757 PCC_ObjCInterface, 5758 /// \brief Code completion occurs within an Objective-C implementation or 5759 /// category implementation 5760 PCC_ObjCImplementation, 5761 /// \brief Code completion occurs within the list of instance variables 5762 /// in an Objective-C interface, protocol, category, or implementation. 5763 PCC_ObjCInstanceVariableList, 5764 /// \brief Code completion occurs following one or more template 5765 /// headers. 5766 PCC_Template, 5767 /// \brief Code completion occurs following one or more template 5768 /// headers within a class. 5769 PCC_MemberTemplate, 5770 /// \brief Code completion occurs within an expression. 5771 PCC_Expression, 5772 /// \brief Code completion occurs within a statement, which may 5773 /// also be an expression or a declaration. 5774 PCC_Statement, 5775 /// \brief Code completion occurs at the beginning of the 5776 /// initialization statement (or expression) in a for loop. 5777 PCC_ForInit, 5778 /// \brief Code completion occurs within the condition of an if, 5779 /// while, switch, or for statement. 5780 PCC_Condition, 5781 /// \brief Code completion occurs within the body of a function on a 5782 /// recovery path, where we do not have a specific handle on our position 5783 /// in the grammar. 5784 PCC_RecoveryInFunction, 5785 /// \brief Code completion occurs where only a type is permitted. 5786 PCC_Type, 5787 /// \brief Code completion occurs in a parenthesized expression, which 5788 /// might also be a type cast. 5789 PCC_ParenthesizedExpression, 5790 /// \brief Code completion occurs within a sequence of declaration 5791 /// specifiers within a function, method, or block. 5792 PCC_LocalDeclarationSpecifiers 5793 }; 5794 5795 void CodeCompleteOrdinaryName(Scope *S, 5796 ParserCompletionContext CompletionContext); 5797 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 5798 bool AllowNonIdentifiers, 5799 bool AllowNestedNameSpecifiers); 5800 5801 struct CodeCompleteExpressionData; 5802 void CodeCompleteExpression(Scope *S, 5803 const CodeCompleteExpressionData &Data); 5804 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 5805 SourceLocation OpLoc, 5806 bool IsArrow); 5807 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 5808 void CodeCompleteTag(Scope *S, unsigned TagSpec); 5809 void CodeCompleteTypeQualifiers(DeclSpec &DS); 5810 void CodeCompleteCase(Scope *S); 5811 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs); 5812 void CodeCompleteInitializer(Scope *S, Decl *D); 5813 void CodeCompleteReturn(Scope *S); 5814 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 5815 5816 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 5817 bool EnteringContext); 5818 void CodeCompleteUsing(Scope *S); 5819 void CodeCompleteUsingDirective(Scope *S); 5820 void CodeCompleteNamespaceDecl(Scope *S); 5821 void CodeCompleteNamespaceAliasDecl(Scope *S); 5822 void CodeCompleteOperatorName(Scope *S); 5823 void CodeCompleteConstructorInitializer(Decl *Constructor, 5824 CXXCtorInitializer** Initializers, 5825 unsigned NumInitializers); 5826 5827 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl, 5828 bool InInterface); 5829 void CodeCompleteObjCAtVisibility(Scope *S); 5830 void CodeCompleteObjCAtStatement(Scope *S); 5831 void CodeCompleteObjCAtExpression(Scope *S); 5832 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 5833 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl); 5834 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl); 5835 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 5836 bool IsParameter); 5837 void CodeCompleteObjCMessageReceiver(Scope *S); 5838 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 5839 IdentifierInfo **SelIdents, 5840 unsigned NumSelIdents, 5841 bool AtArgumentExpression); 5842 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 5843 IdentifierInfo **SelIdents, 5844 unsigned NumSelIdents, 5845 bool AtArgumentExpression, 5846 bool IsSuper = false); 5847 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver, 5848 IdentifierInfo **SelIdents, 5849 unsigned NumSelIdents, 5850 bool AtArgumentExpression, 5851 ObjCInterfaceDecl *Super = 0); 5852 void CodeCompleteObjCForCollection(Scope *S, 5853 DeclGroupPtrTy IterationVar); 5854 void CodeCompleteObjCSelector(Scope *S, 5855 IdentifierInfo **SelIdents, 5856 unsigned NumSelIdents); 5857 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 5858 unsigned NumProtocols); 5859 void CodeCompleteObjCProtocolDecl(Scope *S); 5860 void CodeCompleteObjCInterfaceDecl(Scope *S); 5861 void CodeCompleteObjCSuperclass(Scope *S, 5862 IdentifierInfo *ClassName, 5863 SourceLocation ClassNameLoc); 5864 void CodeCompleteObjCImplementationDecl(Scope *S); 5865 void CodeCompleteObjCInterfaceCategory(Scope *S, 5866 IdentifierInfo *ClassName, 5867 SourceLocation ClassNameLoc); 5868 void CodeCompleteObjCImplementationCategory(Scope *S, 5869 IdentifierInfo *ClassName, 5870 SourceLocation ClassNameLoc); 5871 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl); 5872 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 5873 IdentifierInfo *PropertyName, 5874 Decl *ObjCImpDecl); 5875 void CodeCompleteObjCMethodDecl(Scope *S, 5876 bool IsInstanceMethod, 5877 ParsedType ReturnType, 5878 Decl *IDecl); 5879 void CodeCompleteObjCMethodDeclSelector(Scope *S, 5880 bool IsInstanceMethod, 5881 bool AtParameterName, 5882 ParsedType ReturnType, 5883 IdentifierInfo **SelIdents, 5884 unsigned NumSelIdents); 5885 void CodeCompletePreprocessorDirective(bool InConditional); 5886 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 5887 void CodeCompletePreprocessorMacroName(bool IsDefinition); 5888 void CodeCompletePreprocessorExpression(); 5889 void CodeCompletePreprocessorMacroArgument(Scope *S, 5890 IdentifierInfo *Macro, 5891 MacroInfo *MacroInfo, 5892 unsigned Argument); 5893 void CodeCompleteNaturalLanguage(); 5894 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 5895 SmallVectorImpl<CodeCompletionResult> &Results); 5896 //@} 5897 5898 //===--------------------------------------------------------------------===// 5899 // Extra semantic analysis beyond the C type system 5900 5901public: 5902 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 5903 unsigned ByteNo) const; 5904 5905private: 5906 void CheckArrayAccess(const Expr *E); 5907 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); 5908 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); 5909 5910 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall); 5911 bool CheckObjCString(Expr *Arg); 5912 5913 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 5914 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 5915 5916 bool SemaBuiltinVAStart(CallExpr *TheCall); 5917 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 5918 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 5919 5920public: 5921 // Used by C++ template instantiation. 5922 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 5923 5924private: 5925 bool SemaBuiltinPrefetch(CallExpr *TheCall); 5926 bool SemaBuiltinObjectSize(CallExpr *TheCall); 5927 bool SemaBuiltinLongjmp(CallExpr *TheCall); 5928 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 5929 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 5930 llvm::APSInt &Result); 5931 5932 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, 5933 bool HasVAListArg, unsigned format_idx, 5934 unsigned firstDataArg, bool isPrintf); 5935 5936 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 5937 const CallExpr *TheCall, bool HasVAListArg, 5938 unsigned format_idx, unsigned firstDataArg, 5939 bool isPrintf); 5940 5941 void CheckNonNullArguments(const NonNullAttr *NonNull, 5942 const Expr * const *ExprArgs, 5943 SourceLocation CallSiteLoc); 5944 5945 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg, 5946 unsigned format_idx, unsigned firstDataArg, 5947 bool isPrintf); 5948 5949 /// \brief Enumeration used to describe which of the memory setting or copying 5950 /// functions is being checked by \c CheckMemsetcpymoveArguments(). 5951 enum CheckedMemoryFunction { 5952 CMF_Memset, 5953 CMF_Memcpy, 5954 CMF_Memmove 5955 }; 5956 5957 void CheckMemsetcpymoveArguments(const CallExpr *Call, 5958 CheckedMemoryFunction CMF, 5959 IdentifierInfo *FnName); 5960 5961 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 5962 SourceLocation ReturnLoc); 5963 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); 5964 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 5965 5966 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 5967 Expr *Init); 5968 5969 /// \brief The parser's current scope. 5970 /// 5971 /// The parser maintains this state here. 5972 Scope *CurScope; 5973 5974protected: 5975 friend class Parser; 5976 friend class InitializationSequence; 5977 friend class ASTReader; 5978 friend class ASTWriter; 5979 5980public: 5981 /// \brief Retrieve the parser's current scope. 5982 /// 5983 /// This routine must only be used when it is certain that semantic analysis 5984 /// and the parser are in precisely the same context, which is not the case 5985 /// when, e.g., we are performing any kind of template instantiation. 5986 /// Therefore, the only safe places to use this scope are in the parser 5987 /// itself and in routines directly invoked from the parser and *never* from 5988 /// template substitution or instantiation. 5989 Scope *getCurScope() const { return CurScope; } 5990}; 5991 5992/// \brief RAII object that enters a new expression evaluation context. 5993class EnterExpressionEvaluationContext { 5994 Sema &Actions; 5995 5996public: 5997 EnterExpressionEvaluationContext(Sema &Actions, 5998 Sema::ExpressionEvaluationContext NewContext) 5999 : Actions(Actions) { 6000 Actions.PushExpressionEvaluationContext(NewContext); 6001 } 6002 6003 ~EnterExpressionEvaluationContext() { 6004 Actions.PopExpressionEvaluationContext(); 6005 } 6006}; 6007 6008} // end namespace clang 6009 6010#endif 6011