clang: lib/Sema/ParsedAttr.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

19#include "llvm/ADT/SmallVector.h"

20#include

21#include

22#include

23

24using namespace clang;

25

32}

33

34size_t ParsedAttr::allocated_size() const {

36 else if (IsTypeTagForDatatype)

38 else if (IsProperty)

40 else if (HasParsedType)

47}

48

50

51 FreeLists.resize(InlineFreeListsCapacity);

52}

54

57 assert((size % sizeof(void*)) == 0);

58 return ((size - sizeof(ParsedAttr)) / sizeof(void *));

59}

60

61void *AttributeFactory::allocate(size_t size) {

62

64 if (index < FreeLists.size() && !FreeLists[index].empty()) {

66 FreeLists[index].pop_back();

68 }

69

70

72}

73

75 size_t size = Attr->allocated_size();

77

78

79 if (freeListIndex >= FreeLists.size())

80 FreeLists.resize(freeListIndex + 1);

81

82#ifndef NDEBUG

83

85#endif

86

87

88 FreeLists[freeListIndex].push_back(Attr);

89}

90

91void AttributeFactory::reclaimPool(AttributePool &cur) {

93 deallocate(AL);

94}

95

96void AttributePool::takePool(AttributePool &pool) {

97 Attrs.insert(Attrs.end(), pool.Attrs.begin(), pool.Attrs.end());

98 pool.Attrs.clear();

99}

100

102 assert(&Pool != this && "AttributePool can't take attributes from itself");

103 llvm::for_each(List.AttrList, [&Pool](ParsedAttr *A) { Pool.remove(A); });

104 Attrs.insert(Attrs.end(), List.AttrList.begin(), List.AttrList.end());

105}

106

107namespace {

108

109#include "clang/Sema/AttrParsedAttrImpl.inc"

110

111}

112

114

115 if ((size_t)A.getParsedKind() < std::size(AttrInfoMap))

117

118

122 return IgnoredParsedAttrInfo;

123

124

125

126

131

133 if (Ptr->hasSpelling(SyntaxUsed, FullName))

134 return *Ptr;

135

136

139 return DefaultParsedAttrInfo;

140}

141

144}

145

147

150}

151

154}

155

158}

159

162}

163

166}

167

170}

171

174 return checkAttributeMatchRuleAppliesTo(D, MatchRule);

175}

176

179 SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool>> &MatchRules)

180 const {

182}

183

186 return true;

187 S.Diag(getLoc(), diag::warn_attribute_ignored) << *this;

188 return false;

189}

190

193}

194

196

198

201

202

203

204

207 bool TargetSpecificSpellingExists =

208 !HasSpelling ||

210

212}

213

215

218}

219

222

223

224 return false;

225

227

228

229

230

231

232

233

234

235

236

238 case AT_AddressSpace:

239 case AT_OpenCLPrivateAddressSpace:

240 case AT_OpenCLGlobalAddressSpace:

241 case AT_OpenCLGlobalDeviceAddressSpace:

242 case AT_OpenCLGlobalHostAddressSpace:

243 case AT_OpenCLLocalAddressSpace:

244 case AT_OpenCLConstantAddressSpace:

245 case AT_OpenCLGenericAddressSpace:

246 case AT_NeonPolyVectorType:

247 case AT_NeonVectorType:

248 case AT_ArmMveStrictPolymorphism:

249 case AT_BTFTypeTag:

250 case AT_ObjCGC:

251 case AT_MatrixType:

252 return true;

253 default:

254 return false;

255 }

256}

257

259

262}

263

265

266

267

268

270}

271

274}

275

278}

279

281

283}

284

285template

287 unsigned Num, unsigned Diag,

288 Compare Comp) {

291 return false;

292 }

293 return true;

294}

295

298 diag::err_attribute_wrong_number_arguments,

299 std::not_equal_to());

300}

303 diag::err_attribute_too_few_arguments,

304 std::less());

305}

308 diag::err_attribute_too_many_arguments,

309 std::greater());

310}

311

315

316

317 Result.takeAllFrom(Second);

319 if (First.Range.getBegin().isValid())

320 Result.Range.setBegin(First.Range.getBegin());

321 else

325 else

326 Result.Range.setEnd(First.Range.getEnd());

327}

Defines the clang::ASTContext interface.

Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.

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.

llvm::MachO::Target Target

static bool checkAttributeNumArgsImpl(Sema &S, const ParsedAttr &AL, unsigned Num, unsigned Diag, Compare Comp)

static size_t getFreeListIndexForSize(size_t size)

static unsigned getNumAttributeArgs(const ParsedAttr &AL)

__DEVICE__ void * memset(void *__a, int __b, size_t __c)

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

Attr - This represents one attribute.

std::string getNormalizedFullName() const

Gets the normalized full name, which consists of both scope and name and with surrounding underscores...

Syntax

The style used to specify an attribute.

@ AS_Keyword

__ptr16, alignas(...), etc.

@ AS_ContextSensitiveKeyword

Context-sensitive version of a keyword attribute.

unsigned getAttributeSpellingListIndex() const

bool isRegularKeywordAttribute() const

SourceLocation getLoc() const

bool isStandardAttributeSyntax() const

The attribute is spelled [[]] in either C or C++ mode, including standard attributes spelled with a k...

Kind getParsedKind() const

A factory, from which one makes pools, from which one creates individual attributes which are dealloc...

@ TypeTagForDatatypeAllocSize

void takeFrom(ParsedAttributesView &List, AttributePool &Pool)

Removes the attributes from List, which are owned by Pool, and adds them at the end of this Attribute...

Decl - This represents one declaration (or definition), e.g.

One of these records is kept for each identifier that is lexed.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

ParsedAttr - Represents a syntactic attribute.

bool isTargetSpecificAttr() const

bool hasCustomParsing() const

unsigned getSemanticSpelling() const

If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...

bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const

bool isKnownToGCC() const

bool existsInTarget(const TargetInfo &Target) const

unsigned getMinArgs() const

bool checkExactlyNumArgs(class Sema &S, unsigned Num) const

Check if the attribute has exactly as many args as Num.

bool hasParsedType() const

bool hasVariadicArg() const

const ParsedAttrInfo & getInfo() const

void handleAttrWithDelayedArgs(Sema &S, Decl *D) const

bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const

bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const

bool acceptsExprPack() const

bool isSupportedByPragmaAttribute() const

unsigned getNumArgs() const

getNumArgs - Return the number of actual arguments to this attribute.

bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const

Check if the attribute has at least as many args as Num.

unsigned getNumArgMembers() const

unsigned getMaxArgs() const

bool slidesFromDeclToDeclSpecLegacyBehavior() const

Returns whether a [[]] attribute, if specified ahead of a declaration, should be applied to the decl-...

void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool > > &MatchRules) const

bool isParamExpr(size_t N) const

bool diagnoseLangOpts(class Sema &S) const

bool checkAtMostNumArgs(class Sema &S, unsigned Num) const

Check if the attribute has at most as many args as Num.

ParsedAttributes - A collection of parsed attributes.

SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)

Emit a diagnostic.

Sema - This implements semantic analysis and AST building for C.

const LangOptions & getLangOpts() const

Encodes a location in the source.

bool isValid() const

Return true if this is a valid SourceLocation object.

SourceLocation getEnd() const

SourceLocation getBegin() const

Stmt - This represents one statement.

Exposes information about the current target.

Defines the clang::TargetInfo interface.

const internal::VariadicAllOfMatcher< Attr > attr

Matches attributes.

SubjectMatchRule

A list of all the recognized kinds of attributes.

The JSON file list parser is used to communicate input to InstallAPI.

llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion

A union of the various pointer types that can be passed to an ParsedAttr as an argument.

void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &Second, ParsedAttributes &Result)

Consumes the attributes from First and Second and concatenates them into Result.

@ Result

The result type of a method or function.

const std::list< std::unique_ptr< ParsedAttrInfo > > & getAttributePluginInstances()

OpaquePtr< QualType > ParsedType

An opaque type for threading parsed type information through the parser.

Wraps an identifier and optional source location for the identifier.

static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)

static ArrayRef< const ParsedAttrInfo * > getAllBuiltin()

unsigned IsKnownToGCC

True if this attribute has any spellings that are known to gcc.

unsigned HasCustomParsing

True if the parsing does not match the semantic content.

unsigned IsType

True if this attribute applies to types.

unsigned IsTargetSpecific

True if this attribute is only available for certain targets.

unsigned IsSupportedByPragmaAttribute

True if this attribute is supported by #pragma clang attribute.

unsigned NumArgs

The number of required arguments of this attribute.

virtual bool diagAppertainsToStmt(Sema &S, const ParsedAttr &Attr, const Stmt *St) const

Check if this attribute appertains to St, and issue a diagnostic if not.

virtual unsigned spellingIndexToSemanticSpelling(const ParsedAttr &Attr) const

Convert the spelling index of Attr to a semantic spelling enum value.

static const ParsedAttrInfo & get(const AttributeCommonInfo &A)

virtual bool isParamExpr(size_t N) const

Returns true if the specified parameter index for this attribute in Attr.td is an ExprArgument or Var...

virtual void getPragmaAttributeMatchRules(llvm::SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool > > &Rules, const LangOptions &LangOpts) const

Populate Rules with the match rules of this attribute.

virtual bool existsInTarget(const TargetInfo &Target) const

Check if this attribute is allowed when compiling for the given target.

virtual bool spellingExistsInTarget(const TargetInfo &Target, const unsigned SpellingListIndex) const

Check if this attribute's spelling is allowed when compiling for the given target.

virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr, const Decl *D) const

Check if this attribute appertains to D, and issue a diagnostic if not.

unsigned OptArgs

The number of optional arguments of this attributes.

virtual bool diagMutualExclusion(Sema &S, const ParsedAttr &A, const Decl *D) const

Check if the given attribute is mutually exclusive with other attributes already applied to the given...

unsigned IsStmt

True if this attribute applies to statements.

unsigned NumArgMembers

The number of non-fake arguments specified in the attribute definition.

Describes the trailing object for Availability attribute in ParsedAttr.