13#ifndef LLVM_CLANG_SEMA_ATTR_H
14#define LLVM_CLANG_SEMA_ATTR_H
28#include "llvm/Support/Casting.h"
36 return (D->
getFunctionType() !=
nullptr) || llvm::isa<ObjCMethodDecl>(D);
67 bool IncludeThis =
false) {
70 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
71 return FD->getNumParamsIncludingThis();
74 if (
const auto *BD = dyn_cast<BlockDecl>(D))
75 return BD->getNumParams();
85 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
86 return FD->getParamDecl(Idx);
87 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
88 return MD->getParamDecl(Idx);
89 if (
const auto *BD = dyn_cast<BlockDecl>(D))
90 return BD->getParamDecl(Idx);
95 if (
const auto *DD = dyn_cast<DeclaratorDecl>(D))
96 TSI = DD->getTypeSourceInfo();
97 else if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
98 TSI = TD->getTypeSourceInfo();
106 TL = PTL.getPointeeLoc();
108 TL = MPTL.getPointeeLoc();
110 TL = RTL.getPointeeLoc();
112 TL = BPTL.getPointeeLoc();
115 if (Idx < FPTL.getNumParams())
116 return FPTL.getParam(Idx);
124 if (
const auto *BD = dyn_cast<BlockDecl>(D))
125 return BD->getParamDecl(Idx)->getType();
132 return PVD->getSourceRange();
138 return FnTy->getReturnType();
143 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
144 return FD->getReturnTypeSourceRange();
145 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
146 return MD->getReturnTypeSourceRange();
153 if (
const auto *BD = dyn_cast<BlockDecl>(D))
154 return BD->isVariadic();
159 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
160 return MethodDecl->isInstance();
165 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
166 return MethodDecl->isImplicitObjectMemberFunction();
172template <
typename AttrTy>
174 if (
const auto *A = D->
getAttr<AttrTy>()) {
175 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
178 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
184template <
typename AttrTy>
186 if (
const auto *A = D->
getAttr<AttrTy>()) {
190 Diag(A->getLocation(), diag::note_conflicting_attribute);
196template <
typename... DiagnosticArgs>
197const SemaBase::SemaDiagnosticBuilder &
202template <
typename T,
typename... DiagnosticArgs>
203const SemaBase::SemaDiagnosticBuilder &
205 DiagnosticArgs &&...ExtraArgs) {
207 std::forward<DiagnosticArgs>(ExtraArgs)...);
212template <
typename AttrType>
222template <
typename AttrType,
typename... DiagnosticArgs>
225 bool PassesCheck,
unsigned DiagID,
226 DiagnosticArgs &&...ExtraArgs) {
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Defines the clang::SourceLocation class and associated facilities.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
Attr - This represents one attribute.
SourceLocation getLocation() const
bool isRegularKeywordAttribute() const
SourceLocation getLoc() const
Wrapper for source info for block pointers.
Decl - This represents one declaration (or definition), e.g.
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible.
SourceLocation getBeginLoc() const LLVM_READONLY
FunctionType - C99 6.7.5.3 - Function Declarators.
Wrapper for source info for member pointers.
Represents a parameter to a function.
ParsedAttr - Represents a syntactic attribute.
Wrapper for source info for pointers.
A (possibly-)qualified type.
A generic diagnostic builder for errors which may or may not be deferred.
ASTContext & getASTContext() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
A trivial tuple used to represent a source range.
Base wrapper for a particular "section" of type source info.
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
const SemaBase::SemaDiagnosticBuilder & appendDiagnostics(const SemaBase::SemaDiagnosticBuilder &Bldr)
void handleSimpleAttributeOrDiagnose(SemaBase &S, Decl *D, const AttributeCommonInfo &CI, bool PassesCheck, unsigned DiagID, DiagnosticArgs &&...ExtraArgs)
Add an attribute AttrType to declaration D, provided that PassesCheck is true.
bool hasDeclarator(const Decl *D)
Return true if the given decl has a declarator that should have been processed by Sema::GetTypeForDec...
QualType getFunctionOrMethodResultType(const Decl *D)
bool isInstanceMethod(const Decl *D)
const ParmVarDecl * getFunctionOrMethodParam(const Decl *D, unsigned Idx)
getFunctionOrMethodParam - Return parameter declaration for the given index of the passed Decl,...
bool checkAttrMutualExclusion(SemaBase &S, Decl *D, const ParsedAttr &AL)
Diagnose mutually exclusive attributes when present on a given declaration.
SourceRange getFunctionOrMethodResultSourceRange(const Decl *D)
bool isFunctionOrMethodOrBlockForAttrSubject(const Decl *D)
Return true if the given decl has function type (function or function-typed variable) or an Objective...
QualType getFunctionOrMethodParamType(const Decl *D, unsigned Idx)
const FunctionProtoType * T
bool isFunctionOrMethodVariadic(const Decl *D)
bool isFuncOrMethodForAttrSubject(const Decl *D)
isFuncOrMethodForAttrSubject - Return true if the given decl has function type (function or function-...
unsigned getFunctionOrMethodNumParams(const Decl *D, bool IncludeThis=false)
getFunctionOrMethodNumParams - Return number of function or method parameters, optionally including t...
void handleSimpleAttribute(SemaBase &S, Decl *D, const AttributeCommonInfo &CI)
Applies the given attribute to the Decl without performing any additional semantic checking.
bool hasImplicitObjectParameter(const Decl *D)
bool hasFunctionProto(const Decl *D)
hasFunctionProto - Return true if the given decl has a argument information.
U cast(CodeGen::Address addr)
SourceRange getFunctionOrMethodParamRange(const Decl *D, unsigned Idx)