1 //===--- SemaInternal.h - Internal Sema Interfaces --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides common API and #includes for the internal
11 // implementation of Sema.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_SEMA_SEMA_INTERNAL_H
16 #define LLVM_CLANG_SEMA_SEMA_INTERNAL_H
18 #include "clang/AST/ASTContext.h"
19 #include "clang/Sema/Sema.h"
20 #include "clang/Sema/SemaDiagnostic.h"
24 inline PartialDiagnostic Sema::PDiag(unsigned DiagID) {
25 return PartialDiagnostic(DiagID, Context.getDiagAllocator());
29 // This requires the variable to be non-dependent and the initializer
\r
30 // to not be value dependent.
\r
31 inline bool IsVariableAConstantExpression(VarDecl *Var, ASTContext &Context) {
\r
32 const VarDecl *DefVD = 0;
\r
33 return !isa<ParmVarDecl>(Var) &&
\r
34 Var->isUsableInConstantExpressions(Context) &&
\r
35 Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE();
\r
38 // Directly mark a variable odr-used. Given a choice, prefer to use
\r
39 // MarkVariableReferenced since it does additional checks and then
\r
40 // calls MarkVarDeclODRUsed.
\r
41 // If the variable must be captured:
\r
42 // - if FunctionScopeIndexToStopAt is null, capture it in the CurContext
\r
43 // - else capture it in the DeclContext that maps to the
\r
44 // *FunctionScopeIndexToStopAt on the FunctionScopeInfo stack.
\r
45 inline void MarkVarDeclODRUsed(VarDecl *Var,
\r
46 SourceLocation Loc, Sema &SemaRef,
\r
47 const unsigned *const FunctionScopeIndexToStopAt) {
\r
48 // Keep track of used but undefined variables.
\r
49 // FIXME: We shouldn't suppress this warning for static data members.
\r
50 if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly &&
\r
51 !Var->isExternallyVisible() &&
\r
52 !(Var->isStaticDataMember() && Var->hasInit())) {
\r
53 SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()];
\r
54 if (old.isInvalid()) old = Loc;
\r
56 QualType CaptureType, DeclRefType;
\r
57 SemaRef.tryCaptureVariable(Var, Loc, Sema::TryCapture_Implicit,
\r
58 /*EllipsisLoc*/ SourceLocation(),
\r
59 /*BuildAndDiagnose*/ true,
\r
60 CaptureType, DeclRefType,
\r
61 FunctionScopeIndexToStopAt);
\r
63 Var->markUsed(SemaRef.Context);
\r