1212795Sdim//===--- SemaInternal.h - Internal Sema Interfaces --------------*- C++ -*-===// 2212795Sdim// 3212795Sdim// The LLVM Compiler Infrastructure 4212795Sdim// 5212795Sdim// This file is distributed under the University of Illinois Open Source 6212795Sdim// License. See LICENSE.TXT for details. 7212795Sdim// 8212795Sdim//===----------------------------------------------------------------------===// 9212795Sdim// 10212795Sdim// This file provides common API and #includes for the internal 11212795Sdim// implementation of Sema. 12212795Sdim// 13212795Sdim//===----------------------------------------------------------------------===// 14212795Sdim 15212795Sdim#ifndef LLVM_CLANG_SEMA_SEMA_INTERNAL_H 16212795Sdim#define LLVM_CLANG_SEMA_SEMA_INTERNAL_H 17212795Sdim 18252723Sdim#include "clang/AST/ASTContext.h" 19212795Sdim#include "clang/Sema/Sema.h" 20212795Sdim#include "clang/Sema/SemaDiagnostic.h" 21212795Sdim 22212795Sdimnamespace clang { 23212795Sdim 24212795Sdiminline PartialDiagnostic Sema::PDiag(unsigned DiagID) { 25212795Sdim return PartialDiagnostic(DiagID, Context.getDiagAllocator()); 26212795Sdim} 27263509Sdim 28263509Sdim 29263509Sdim// This requires the variable to be non-dependent and the initializer 30263509Sdim// to not be value dependent. 31263509Sdiminline bool IsVariableAConstantExpression(VarDecl *Var, ASTContext &Context) { 32263509Sdim const VarDecl *DefVD = 0; 33263509Sdim return !isa<ParmVarDecl>(Var) && 34263509Sdim Var->isUsableInConstantExpressions(Context) && 35263509Sdim Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE(); 36263509Sdim} 37263509Sdim 38263509Sdim// Directly mark a variable odr-used. Given a choice, prefer to use 39263509Sdim// MarkVariableReferenced since it does additional checks and then 40263509Sdim// calls MarkVarDeclODRUsed. 41263509Sdim// If the variable must be captured: 42263509Sdim// - if FunctionScopeIndexToStopAt is null, capture it in the CurContext 43263509Sdim// - else capture it in the DeclContext that maps to the 44263509Sdim// *FunctionScopeIndexToStopAt on the FunctionScopeInfo stack. 45263509Sdiminline void MarkVarDeclODRUsed(VarDecl *Var, 46263509Sdim SourceLocation Loc, Sema &SemaRef, 47263509Sdim const unsigned *const FunctionScopeIndexToStopAt) { 48263509Sdim // Keep track of used but undefined variables. 49263509Sdim // FIXME: We shouldn't suppress this warning for static data members. 50263509Sdim if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly && 51263509Sdim !Var->isExternallyVisible() && 52263509Sdim !(Var->isStaticDataMember() && Var->hasInit())) { 53263509Sdim SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()]; 54263509Sdim if (old.isInvalid()) old = Loc; 55263509Sdim } 56263509Sdim QualType CaptureType, DeclRefType; 57263509Sdim SemaRef.tryCaptureVariable(Var, Loc, Sema::TryCapture_Implicit, 58263509Sdim /*EllipsisLoc*/ SourceLocation(), 59263509Sdim /*BuildAndDiagnose*/ true, 60263509Sdim CaptureType, DeclRefType, 61263509Sdim FunctionScopeIndexToStopAt); 62263509Sdim 63263509Sdim Var->markUsed(SemaRef.Context); 64212795Sdim} 65263509Sdim} 66212795Sdim 67212795Sdim#endif 68