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);
68 if (
const auto *BD = dyn_cast<BlockDecl>(D))
69 return BD->getNumParams();
79 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
80 return FD->getParamDecl(Idx);
81 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
82 return MD->getParamDecl(Idx);
83 if (
const auto *BD = dyn_cast<BlockDecl>(D))
84 return BD->getParamDecl(Idx);
89 if (
const auto *DD = dyn_cast<DeclaratorDecl>(D))
90 TSI = DD->getTypeSourceInfo();
91 else if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
92 TSI = TD->getTypeSourceInfo();
100 TL = PTL.getPointeeLoc();
102 TL = MPTL.getPointeeLoc();
104 TL = RTL.getPointeeLoc();
106 TL = BPTL.getPointeeLoc();
109 if (Idx < FPTL.getNumParams())
110 return FPTL.getParam(Idx);
118 if (
const auto *BD = dyn_cast<BlockDecl>(D))
119 return BD->getParamDecl(Idx)->getType();
126 return PVD->getSourceRange();
132 return FnTy->getReturnType();
137 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
138 return FD->getReturnTypeSourceRange();
139 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
140 return MD->getReturnTypeSourceRange();
147 if (
const auto *BD = dyn_cast<BlockDecl>(D))
148 return BD->isVariadic();
153 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
154 return MethodDecl->isInstance();
159 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
160 return MethodDecl->isImplicitObjectMemberFunction();
166template <
typename AttrTy>
168 if (
const auto *A = D->
getAttr<AttrTy>()) {
169 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
172 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
178template <
typename AttrTy>
180 if (
const auto *A = D->
getAttr<AttrTy>()) {
184 Diag(A->getLocation(), diag::note_conflicting_attribute);
190template <
typename... DiagnosticArgs>
191const SemaBase::SemaDiagnosticBuilder &
196template <
typename T,
typename... DiagnosticArgs>
197const SemaBase::SemaDiagnosticBuilder &
199 DiagnosticArgs &&...ExtraArgs) {
201 std::forward<DiagnosticArgs>(ExtraArgs)...);
206template <
typename AttrType>
216template <
typename AttrType,
typename... DiagnosticArgs>
219 bool PassesCheck,
unsigned DiagID,
220 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-...
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.
unsigned getFunctionOrMethodNumParams(const Decl *D)
getFunctionOrMethodNumParams - Return number of function or method parameters.
U cast(CodeGen::Address addr)
SourceRange getFunctionOrMethodParamRange(const Decl *D, unsigned Idx)