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