]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/clang/include/clang/Sema/SemaInternal.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / clang / include / clang / Sema / SemaInternal.h
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
24 inline PartialDiagnostic Sema::PDiag(unsigned DiagID) {
25   return PartialDiagnostic(DiagID, Context.getDiagAllocator());
26 }
27 \r
28 \r
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
36 }\r
37 \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
55   }\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
62 \r
63   Var->markUsed(SemaRef.Context);\r
64 }
65 }
66
67 #endif