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
18249423Sdim#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}
27263508Sdim
28263508Sdim
29263508Sdim// This requires the variable to be non-dependent and the initializer
30263508Sdim// to not be value dependent.
31263508Sdiminline bool IsVariableAConstantExpression(VarDecl *Var, ASTContext &Context) {
32263508Sdim  const VarDecl *DefVD = 0;
33263508Sdim  return !isa<ParmVarDecl>(Var) &&
34263508Sdim    Var->isUsableInConstantExpressions(Context) &&
35263508Sdim    Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE();
36263508Sdim}
37263508Sdim
38263508Sdim// Directly mark a variable odr-used. Given a choice, prefer to use
39263508Sdim// MarkVariableReferenced since it does additional checks and then
40263508Sdim// calls MarkVarDeclODRUsed.
41263508Sdim// If the variable must be captured:
42263508Sdim//  - if FunctionScopeIndexToStopAt is null, capture it in the CurContext
43263508Sdim//  - else capture it in the DeclContext that maps to the
44263508Sdim//    *FunctionScopeIndexToStopAt on the FunctionScopeInfo stack.
45263508Sdiminline void MarkVarDeclODRUsed(VarDecl *Var,
46263508Sdim    SourceLocation Loc, Sema &SemaRef,
47263508Sdim    const unsigned *const FunctionScopeIndexToStopAt) {
48263508Sdim  // Keep track of used but undefined variables.
49263508Sdim  // FIXME: We shouldn't suppress this warning for static data members.
50263508Sdim  if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly &&
51263508Sdim    !Var->isExternallyVisible() &&
52263508Sdim    !(Var->isStaticDataMember() && Var->hasInit())) {
53263508Sdim      SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()];
54263508Sdim      if (old.isInvalid()) old = Loc;
55263508Sdim  }
56263508Sdim  QualType CaptureType, DeclRefType;
57263508Sdim  SemaRef.tryCaptureVariable(Var, Loc, Sema::TryCapture_Implicit,
58263508Sdim    /*EllipsisLoc*/ SourceLocation(),
59263508Sdim    /*BuildAndDiagnose*/ true,
60263508Sdim    CaptureType, DeclRefType,
61263508Sdim    FunctionScopeIndexToStopAt);
62263508Sdim
63263508Sdim  Var->markUsed(SemaRef.Context);
64212795Sdim}
65263508Sdim}
66212795Sdim
67212795Sdim#endif
68