add a method to AttributeList that converts an identifier to an enum.

llvm-svn: 47412
This commit is contained in:
Chris Lattner 2008-02-20 23:14:47 +00:00
parent fe988eba4b
commit f18c743222
2 changed files with 59 additions and 14 deletions

View File

@ -24,3 +24,48 @@ AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
for (unsigned i = 0; i != numargs; ++i)
Args[i] = elist[i];
}
AttributeList::~AttributeList() {
if (Args) {
// FIXME: before we delete the vector, we need to make sure the Expr's
// have been deleted. Since Action::ExprTy is "void", we are dependent
// on the actions module for actually freeing the memory. The specific
// hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
// ParseField, ParseTag. Once these routines have freed the expression,
// they should zero out the Args slot (to indicate the memory has been
// freed). If any element of the vector is non-null, we should assert.
delete [] Args;
}
delete Next;
}
AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
const char *Str = Name->getName();
unsigned Len = Name->getLength();
// Normalize the attribute name, __foo__ becomes foo.
if (Len > 4 && Str[0] == '_' && Str[1] == '_' &&
Str[Len - 2] == '_' && Str[Len - 1] == '_') {
Str += 2;
Len -= 4;
}
switch (Len) {
case 6:
if (!memcmp(Str, "packed", 6)) return AT_packed;
break;
case 7:
if (!memcmp(Str, "aligned", 7)) return AT_aligned;
break;
case 11:
if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
break;
case 13:
if (!memcmp(Str, "address_space", 13)) return AT_address_space;
break;
case 15:
if (!memcmp(Str, "ocu_vector_type", 15)) return AT_ocu_vector_type;
break;
}
return UnknownAttribute;
}

View File

@ -18,7 +18,7 @@
#include <cassert>
namespace clang {
/// AttributeList - Represents GCC's __attribute__ declaration. There are
/// 4 forms of this construct...they are:
///
@ -39,24 +39,24 @@ public:
AttributeList(IdentifierInfo *AttrName, SourceLocation AttrLoc,
IdentifierInfo *ParmName, SourceLocation ParmLoc,
Action::ExprTy **args, unsigned numargs, AttributeList *Next);
~AttributeList() {
if (Args) {
// FIXME: before we delete the vector, we need to make sure the Expr's
// have been deleted. Since Action::ExprTy is "void", we are dependent
// on the actions module for actually freeing the memory. The specific
// hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
// ParseField, ParseTag. Once these routines have freed the expression,
// they should zero out the Args slot (to indicate the memory has been
// freed). If any element of the vector is non-null, we should assert.
delete [] Args;
}
delete Next;
}
~AttributeList();
enum Kind {
UnknownAttribute,
AT_vector_size,
AT_ocu_vector_type,
AT_address_space,
AT_aligned,
AT_packed
};
IdentifierInfo *getAttributeName() const { return AttrName; }
SourceLocation getAttributeLoc() const { return AttrLoc; }
IdentifierInfo *getParameterName() const { return ParmName; }
Kind getKind() const { return getKind(getAttributeName()); }
static Kind getKind(const IdentifierInfo *Name);
AttributeList *getNext() const { return Next; }
void setNext(AttributeList *N) { Next = N; }