13#ifndef LLVM_CLANG_SEMA_ATTR_H
14#define LLVM_CLANG_SEMA_ATTR_H
27#include "llvm/Support/Casting.h"
48 return isa<DeclaratorDecl>(
D) || isa<BlockDecl>(
D) ||
49 isa<TypedefNameDecl>(
D) || isa<ObjCPropertyDecl>(
D);
57 return isa<FunctionProtoType>(FnTy);
58 return isa<ObjCMethodDecl>(
D) || isa<BlockDecl>(
D);
66 return cast<FunctionProtoType>(FnTy)->getNumParams();
67 if (
const auto *BD = dyn_cast<BlockDecl>(
D))
68 return BD->getNumParams();
69 return cast<ObjCMethodDecl>(
D)->param_size();
74 if (
const auto *FD = dyn_cast<FunctionDecl>(
D))
75 return FD->getParamDecl(Idx);
76 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D))
77 return MD->getParamDecl(Idx);
78 if (
const auto *BD = dyn_cast<BlockDecl>(
D))
79 return BD->getParamDecl(Idx);
85 return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
86 if (
const auto *BD = dyn_cast<BlockDecl>(
D))
87 return BD->getParamDecl(Idx)->getType();
89 return cast<ObjCMethodDecl>(
D)->parameters()[Idx]->getType();
94 return PVD->getSourceRange();
100 return FnTy->getReturnType();
101 return cast<ObjCMethodDecl>(
D)->getReturnType();
105 if (
const auto *FD = dyn_cast<FunctionDecl>(
D))
106 return FD->getReturnTypeSourceRange();
107 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D))
108 return MD->getReturnTypeSourceRange();
114 return cast<FunctionProtoType>(FnTy)->isVariadic();
115 if (
const auto *BD = dyn_cast<BlockDecl>(
D))
116 return BD->isVariadic();
117 return cast<ObjCMethodDecl>(
D)->isVariadic();
121 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(
D))
122 return MethodDecl->isInstance();
128template <
typename AttrTy>
130 if (
const auto *A =
D->
getAttr<AttrTy>()) {
131 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
134 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
140template <
typename AttrTy>
142 if (
const auto *A =
D->
getAttr<AttrTy>()) {
146 Diag(A->getLocation(), diag::note_conflicting_attribute);
152template <
typename... DiagnosticArgs>
153const SemaBase::SemaDiagnosticBuilder &
158template <
typename T,
typename... DiagnosticArgs>
159const SemaBase::SemaDiagnosticBuilder &
161 DiagnosticArgs &&...ExtraArgs) {
163 std::forward<DiagnosticArgs>(ExtraArgs)...);
168template <
typename AttrType>
178template <
typename AttrType,
typename... DiagnosticArgs>
181 bool PassesCheck,
unsigned DiagID,
182 DiagnosticArgs &&...ExtraArgs) {
188 handleSimpleAttribute<AttrType>(S,
D, CI);
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.
C Language Family Type Representation.
Attr - This represents one attribute.
SourceLocation getLocation() const
bool isRegularKeywordAttribute() const
SourceLocation getLoc() const
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.
Represents a parameter to a function.
ParsedAttr - Represents a syntactic attribute.
A (possibly-)qualified type.
A generic diagnostic builder for errors which may or may not be deferred.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
ASTContext & getASTContext() const
A trivial tuple used to represent a source range.
The JSON file list parser is used to communicate input to InstallAPI.
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)
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)
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.
const FunctionProtoType * T
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.
SourceRange getFunctionOrMethodParamRange(const Decl *D, unsigned Idx)