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