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 inline bool
FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo & FTI)29 FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI) {
30 return FTI.NumParams == 1 && !FTI.isVariadic &&
31 FTI.Params[0].Ident == nullptr && FTI.Params[0].Param &&
32 cast<ParmVarDecl>(FTI.Params[0].Param)->getType()->isVoidType();
33 }
34
35 inline bool
FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo & FTI)36 FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI) {
37 // Assume FTI is well-formed.
38 return FTI.NumParams && !FTIHasSingleVoidParameter(FTI);
39 }
40
41 // This requires the variable to be non-dependent and the initializer
42 // to not be value dependent.
IsVariableAConstantExpression(VarDecl * Var,ASTContext & Context)43 inline bool IsVariableAConstantExpression(VarDecl *Var, ASTContext &Context) {
44 const VarDecl *DefVD = nullptr;
45 return !isa<ParmVarDecl>(Var) &&
46 Var->isUsableInConstantExpressions(Context) &&
47 Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE();
48 }
49
50 // Directly mark a variable odr-used. Given a choice, prefer to use
51 // MarkVariableReferenced since it does additional checks and then
52 // calls MarkVarDeclODRUsed.
53 // If the variable must be captured:
54 // - if FunctionScopeIndexToStopAt is null, capture it in the CurContext
55 // - else capture it in the DeclContext that maps to the
56 // *FunctionScopeIndexToStopAt on the FunctionScopeInfo stack.
MarkVarDeclODRUsed(VarDecl * Var,SourceLocation Loc,Sema & SemaRef,const unsigned * const FunctionScopeIndexToStopAt)57 inline void MarkVarDeclODRUsed(VarDecl *Var,
58 SourceLocation Loc, Sema &SemaRef,
59 const unsigned *const FunctionScopeIndexToStopAt) {
60 // Keep track of used but undefined variables.
61 // FIXME: We shouldn't suppress this warning for static data members.
62 if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly &&
63 !Var->isExternallyVisible() &&
64 !(Var->isStaticDataMember() && Var->hasInit())) {
65 SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()];
66 if (old.isInvalid()) old = Loc;
67 }
68 QualType CaptureType, DeclRefType;
69 SemaRef.tryCaptureVariable(Var, Loc, Sema::TryCapture_Implicit,
70 /*EllipsisLoc*/ SourceLocation(),
71 /*BuildAndDiagnose*/ true,
72 CaptureType, DeclRefType,
73 FunctionScopeIndexToStopAt);
74
75 Var->markUsed(SemaRef.Context);
76 }
77
78 /// Return a DLL attribute from the declaration.
getDLLAttr(Decl * D)79 inline InheritableAttr *getDLLAttr(Decl *D) {
80 assert(!(D->hasAttr<DLLImportAttr>() && D->hasAttr<DLLExportAttr>()) &&
81 "A declaration cannot be both dllimport and dllexport.");
82 if (auto *Import = D->getAttr<DLLImportAttr>())
83 return Import;
84 if (auto *Export = D->getAttr<DLLExportAttr>())
85 return Export;
86 return nullptr;
87 }
88
89 }
90
91 #endif
92