Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- AttributeList.cpp --------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the AttributeList class implementation |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Parse/AttributeList.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 15 | using namespace clang; |
| 16 | |
| 17 | AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc, |
| 18 | IdentifierInfo *pName, SourceLocation pLoc, |
| 19 | Action::ExprTy **elist, unsigned numargs, |
| 20 | AttributeList *n) |
| 21 | : AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc), |
| 22 | NumArgs(numargs), Next(n) { |
| 23 | Args = new Action::ExprTy*[numargs]; |
| 24 | for (unsigned i = 0; i != numargs; ++i) |
| 25 | Args[i] = elist[i]; |
| 26 | } |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 27 | |
| 28 | AttributeList::~AttributeList() { |
| 29 | if (Args) { |
| 30 | // FIXME: before we delete the vector, we need to make sure the Expr's |
| 31 | // have been deleted. Since Action::ExprTy is "void", we are dependent |
| 32 | // on the actions module for actually freeing the memory. The specific |
| 33 | // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType, |
| 34 | // ParseField, ParseTag. Once these routines have freed the expression, |
| 35 | // they should zero out the Args slot (to indicate the memory has been |
| 36 | // freed). If any element of the vector is non-null, we should assert. |
| 37 | delete [] Args; |
| 38 | } |
| 39 | delete Next; |
| 40 | } |
| 41 | |
| 42 | AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { |
| 43 | const char *Str = Name->getName(); |
| 44 | unsigned Len = Name->getLength(); |
| 45 | |
| 46 | // Normalize the attribute name, __foo__ becomes foo. |
| 47 | if (Len > 4 && Str[0] == '_' && Str[1] == '_' && |
| 48 | Str[Len - 2] == '_' && Str[Len - 1] == '_') { |
| 49 | Str += 2; |
| 50 | Len -= 4; |
| 51 | } |
Ted Kremenek | aecb383 | 2008-02-27 20:43:06 +0000 | [diff] [blame] | 52 | |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 53 | switch (Len) { |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 54 | case 4: |
| 55 | if (!memcmp(Str, "weak", 4)) return AT_weak; |
| 56 | if (!memcmp(Str, "pure", 4)) return AT_pure; |
| 57 | break; |
| 58 | case 6: |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 59 | if (!memcmp(Str, "packed", 6)) return AT_packed; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 60 | if (!memcmp(Str, "malloc", 6)) return AT_malloc; |
| 61 | if (!memcmp(Str, "format", 6)) return AT_format; |
| 62 | if (!memcmp(Str, "unused", 6)) return AT_unused; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 63 | break; |
| 64 | case 7: |
| 65 | if (!memcmp(Str, "aligned", 7)) return AT_aligned; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 66 | if (!memcmp(Str, "nothrow", 7)) return AT_nothrow; |
| 67 | if (!memcmp(Str, "nonnull", 7)) return AT_nonnull; |
Nate Begeman | 440b456 | 2008-03-07 20:04:22 +0000 | [diff] [blame] | 68 | if (!memcmp(Str, "stdcall", 7)) return AT_stdcall; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 69 | break; |
Nate Begeman | c398f0b | 2008-02-21 19:30:49 +0000 | [diff] [blame] | 70 | case 8: |
| 71 | if (!memcmp(Str, "annotate", 8)) return AT_annotate; |
Ted Kremenek | aecb383 | 2008-02-27 20:43:06 +0000 | [diff] [blame] | 72 | if (!memcmp(Str, "noreturn", 8)) return AT_noreturn; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 73 | if (!memcmp(Str, "noinline", 8)) return AT_noinline; |
Nate Begeman | 440b456 | 2008-03-07 20:04:22 +0000 | [diff] [blame] | 74 | if (!memcmp(Str, "fastcall", 8)) return AT_fastcall; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 75 | break; |
| 76 | case 9: |
| 77 | if (!memcmp(Str, "dllimport", 9)) return AT_dllimport; |
| 78 | if (!memcmp(Str, "dllexport", 9)) return AT_dllexport; |
Nate Begeman | c398f0b | 2008-02-21 19:30:49 +0000 | [diff] [blame] | 79 | break; |
Chris Lattner | 7e669b2 | 2008-02-29 16:48:43 +0000 | [diff] [blame] | 80 | case 10: |
| 81 | if (!memcmp(Str, "deprecated", 10)) return AT_deprecated; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 82 | if (!memcmp(Str, "visibility", 10)) return AT_visibility; |
Chris Lattner | 7e669b2 | 2008-02-29 16:48:43 +0000 | [diff] [blame] | 83 | break; |
| 84 | case 11: |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 85 | if (!memcmp(Str, "vector_size", 11)) return AT_vector_size; |
| 86 | break; |
| 87 | case 13: |
| 88 | if (!memcmp(Str, "address_space", 13)) return AT_address_space; |
| 89 | break; |
| 90 | case 15: |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame^] | 91 | if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 92 | break; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 93 | case 18: |
| 94 | if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result; |
| 95 | break; |
| 96 | } |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 97 | return UnknownAttribute; |
| 98 | } |