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