clang: include/clang/Sema/Attr.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_CLANG_SEMA_ATTR_H
14#define LLVM_CLANG_SEMA_ATTR_H
15
27#include "llvm/Support/Casting.h"
28
30
31
32
33
35 return (D->getFunctionType() != nullptr) || llvm::isa(D);
36}
37
38
39
42}
43
44
45
47
50}
51
52
53
54
57 return isa(FnTy);
59}
60
61
62
63
66 return cast(FnTy)->getNumParams();
67 if (const auto *BD = dyn_cast(D))
68 return BD->getNumParams();
69 return cast(D)->param_size();
70}
71
73 unsigned Idx) {
74 if (const auto *FD = dyn_cast(D))
75 return FD->getParamDecl(Idx);
76 if (const auto *MD = dyn_cast(D))
77 return MD->getParamDecl(Idx);
78 if (const auto *BD = dyn_cast(D))
79 return BD->getParamDecl(Idx);
80 return nullptr;
81}
82
85 return cast(FnTy)->getParamType(Idx);
86 if (const auto *BD = dyn_cast(D))
87 return BD->getParamDecl(Idx)->getType();
88
89 return cast(D)->parameters()[Idx]->getType();
90}
91
94 return PVD->getSourceRange();
96}
97
100 return FnTy->getReturnType();
101 return cast(D)->getReturnType();
102}
103
105 if (const auto *FD = dyn_cast(D))
106 return FD->getReturnTypeSourceRange();
107 if (const auto *MD = dyn_cast(D))
108 return MD->getReturnTypeSourceRange();
110}
111
114 return cast(FnTy)->isVariadic();
115 if (const auto *BD = dyn_cast(D))
116 return BD->isVariadic();
117 return cast(D)->isVariadic();
118}
119
121 if (const auto *MethodDecl = dyn_cast(D))
122 return MethodDecl->isInstance();
123 return false;
124}
125
126
127
128template
130 if (const auto *A = D->getAttr()) {
131 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
132 << AL << A
134 S.Diag(A->getLocation(), diag::note_conflicting_attribute);
135 return true;
136 }
137 return false;
138}
139
140template
142 if (const auto *A = D->getAttr()) {
143 S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible)
144 << &AL << A
146 Diag(A->getLocation(), diag::note_conflicting_attribute);
147 return true;
148 }
149 return false;
150}
151
152template <typename... DiagnosticArgs>
153const SemaBase::SemaDiagnosticBuilder &
155 return Bldr;
156}
157
158template <typename T, typename... DiagnosticArgs>
159const SemaBase::SemaDiagnosticBuilder &
161 DiagnosticArgs &&...ExtraArgs) {
163 std::forward(ExtraArgs)...);
164}
165
166
167
168template
172}
173
174
175
176
177
178template <typename AttrType, typename... DiagnosticArgs>
181 bool PassesCheck, unsigned DiagID,
182 DiagnosticArgs &&...ExtraArgs) {
183 if (!PassesCheck) {
185 appendDiagnostics(DB, std::forward(ExtraArgs)...);
186 return;
187 }
188 handleSimpleAttribute(S, D, CI);
189}
190
191}
192#endif
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)