2009-06-02 17:58:47 +00:00
|
|
|
//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the AttributeList class implementation
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-09-17 15:54:40 +00:00
|
|
|
#include "clang/Sema/AttributeList.h"
|
2012-08-15 20:02:54 +00:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2011-05-02 19:39:53 +00:00
|
|
|
#include "clang/AST/Expr.h"
|
2009-06-02 17:58:47 +00:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2012-08-15 20:02:54 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2013-04-08 18:45:10 +00:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2009-06-02 17:58:47 +00:00
|
|
|
using namespace clang;
|
|
|
|
|
2013-12-22 00:07:40 +00:00
|
|
|
IdentifierLoc *IdentifierLoc::create(ASTContext &Ctx, SourceLocation Loc,
|
|
|
|
IdentifierInfo *Ident) {
|
|
|
|
IdentifierLoc *Result = new (Ctx) IdentifierLoc;
|
|
|
|
Result->Loc = Loc;
|
|
|
|
Result->Ident = Ident;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2011-05-02 19:39:53 +00:00
|
|
|
size_t AttributeList::allocated_size() const {
|
|
|
|
if (IsAvailability) return AttributeFactory::AvailabilityAllocSize;
|
2012-08-19 10:33:04 +00:00
|
|
|
else if (IsTypeTagForDatatype)
|
|
|
|
return AttributeFactory::TypeTagForDatatypeAllocSize;
|
2013-06-10 20:45:12 +00:00
|
|
|
else if (IsProperty)
|
|
|
|
return AttributeFactory::PropertyAllocSize;
|
2013-12-22 00:07:40 +00:00
|
|
|
return (sizeof(AttributeList) + NumArgs * sizeof(ArgsUnion));
|
2011-05-02 19:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AttributeFactory::AttributeFactory() {
|
|
|
|
// Go ahead and configure all the inline capacity. This is just a memset.
|
|
|
|
FreeLists.resize(InlineFreeListsCapacity);
|
|
|
|
}
|
|
|
|
AttributeFactory::~AttributeFactory() {}
|
|
|
|
|
|
|
|
static size_t getFreeListIndexForSize(size_t size) {
|
|
|
|
assert(size >= sizeof(AttributeList));
|
|
|
|
assert((size % sizeof(void*)) == 0);
|
|
|
|
return ((size - sizeof(AttributeList)) / sizeof(void*));
|
|
|
|
}
|
|
|
|
|
|
|
|
void *AttributeFactory::allocate(size_t size) {
|
|
|
|
// Check for a previously reclaimed attribute.
|
|
|
|
size_t index = getFreeListIndexForSize(size);
|
|
|
|
if (index < FreeLists.size()) {
|
|
|
|
if (AttributeList *attr = FreeLists[index]) {
|
|
|
|
FreeLists[index] = attr->NextInPool;
|
|
|
|
return attr;
|
|
|
|
}
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2011-05-02 19:39:53 +00:00
|
|
|
|
|
|
|
// Otherwise, allocate something new.
|
|
|
|
return Alloc.Allocate(size, llvm::AlignOf<AttributeFactory>::Alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeFactory::reclaimPool(AttributeList *cur) {
|
|
|
|
assert(cur && "reclaiming empty pool!");
|
|
|
|
do {
|
|
|
|
// Read this here, because we're going to overwrite NextInPool
|
|
|
|
// when we toss 'cur' into the appropriate queue.
|
|
|
|
AttributeList *next = cur->NextInPool;
|
|
|
|
|
|
|
|
size_t size = cur->allocated_size();
|
|
|
|
size_t freeListIndex = getFreeListIndexForSize(size);
|
|
|
|
|
|
|
|
// Expand FreeLists to the appropriate size, if required.
|
|
|
|
if (freeListIndex >= FreeLists.size())
|
|
|
|
FreeLists.resize(freeListIndex+1);
|
|
|
|
|
|
|
|
// Add 'cur' to the appropriate free-list.
|
|
|
|
cur->NextInPool = FreeLists[freeListIndex];
|
|
|
|
FreeLists[freeListIndex] = cur;
|
|
|
|
|
|
|
|
cur = next;
|
|
|
|
} while (cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributePool::takePool(AttributeList *pool) {
|
|
|
|
assert(pool);
|
|
|
|
|
|
|
|
// Fast path: this pool is empty.
|
|
|
|
if (!Head) {
|
|
|
|
Head = pool;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reverse the pool onto the current head. This optimizes for the
|
|
|
|
// pattern of pulling a lot of pools into a single pool.
|
|
|
|
do {
|
|
|
|
AttributeList *next = pool->NextInPool;
|
|
|
|
pool->NextInPool = Head;
|
|
|
|
Head = pool;
|
|
|
|
pool = next;
|
|
|
|
} while (pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeList *
|
|
|
|
AttributePool::createIntegerAttribute(ASTContext &C, IdentifierInfo *Name,
|
|
|
|
SourceLocation TokLoc, int Arg) {
|
2013-12-22 00:07:40 +00:00
|
|
|
ArgsUnion IArg = IntegerLiteral::Create(C, llvm::APInt(32, (uint64_t) Arg),
|
2011-05-02 19:39:53 +00:00
|
|
|
C.IntTy, TokLoc);
|
2013-12-22 00:07:40 +00:00
|
|
|
return create(Name, TokLoc, 0, TokLoc, &IArg, 1, AttributeList::AS_GNU);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 20:02:54 +00:00
|
|
|
#include "clang/Sema/AttrParsedAttrKinds.inc"
|
|
|
|
|
|
|
|
AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name,
|
|
|
|
const IdentifierInfo *ScopeName,
|
|
|
|
Syntax SyntaxUsed) {
|
2011-10-20 21:14:49 +00:00
|
|
|
StringRef AttrName = Name->getName();
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
// Normalize the attribute name, __foo__ becomes foo.
|
2012-04-14 14:01:31 +00:00
|
|
|
if (AttrName.startswith("__") && AttrName.endswith("__") &&
|
|
|
|
AttrName.size() >= 4)
|
2009-10-23 14:22:18 +00:00
|
|
|
AttrName = AttrName.substr(2, AttrName.size() - 4);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2012-08-15 20:02:54 +00:00
|
|
|
SmallString<64> Buf;
|
|
|
|
if (ScopeName)
|
|
|
|
Buf += ScopeName->getName();
|
|
|
|
// Ensure that in the case of C++11 attributes, we look for '::foo' if it is
|
|
|
|
// unscoped.
|
|
|
|
if (ScopeName || SyntaxUsed == AS_CXX11)
|
|
|
|
Buf += "::";
|
|
|
|
Buf += AttrName;
|
|
|
|
|
|
|
|
return ::getAttrKind(Buf);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2013-04-08 18:45:10 +00:00
|
|
|
|
|
|
|
unsigned AttributeList::getAttributeSpellingListIndex() const {
|
|
|
|
// Both variables will be used in tablegen generated
|
|
|
|
// attribute spell list index matching code.
|
|
|
|
StringRef Name = AttrName->getName();
|
|
|
|
StringRef Scope = ScopeName ? ScopeName->getName() : "";
|
|
|
|
|
|
|
|
#include "clang/Sema/AttrSpellingListIndex.inc"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-22 00:07:40 +00:00
|
|
|
struct ParsedAttrInfo {
|
|
|
|
unsigned NumArgs : 4;
|
|
|
|
unsigned OptArgs : 4;
|
|
|
|
unsigned HasCustomParsing : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
#include "clang/Sema/AttrParsedAttrImpl.inc"
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ParsedAttrInfo &getInfo(const AttributeList &A) {
|
|
|
|
return AttrInfoMap[A.getKind()];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned AttributeList::getMinArgs() const {
|
|
|
|
return getInfo(*this).NumArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned AttributeList::getMaxArgs() const {
|
|
|
|
return getMinArgs() + getInfo(*this).OptArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AttributeList::hasCustomParsing() const {
|
|
|
|
return getInfo(*this).HasCustomParsing;
|
|
|
|
}
|