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" |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 15 | #include "clang/Basic/IdentifierTable.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | using namespace clang; |
| 17 | |
| 18 | AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc, |
| 19 | IdentifierInfo *pName, SourceLocation pLoc, |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 20 | ActionBase::ExprTy **ExprList, unsigned numArgs, |
Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 21 | AttributeList *n, bool declspec) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | : AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc), |
Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 23 | NumArgs(numArgs), Next(n), DeclspecAttribute(declspec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 005b235 | 2009-02-19 06:25:12 +0000 | [diff] [blame] | 25 | if (numArgs == 0) |
| 26 | Args = 0; |
| 27 | else { |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 28 | Args = new ActionBase::ExprTy*[numArgs]; |
Chris Lattner | 005b235 | 2009-02-19 06:25:12 +0000 | [diff] [blame] | 29 | memcpy(Args, ExprList, numArgs*sizeof(Args[0])); |
| 30 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 31 | } |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 32 | |
| 33 | AttributeList::~AttributeList() { |
| 34 | if (Args) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 35 | // FIXME: before we delete the vector, we need to make sure the Expr's |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 36 | // have been deleted. Since ActionBase::ExprTy is "void", we are dependent |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 37 | // on the actions module for actually freeing the memory. The specific |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType, |
| 39 | // ParseField, ParseTag. Once these routines have freed the expression, |
| 40 | // they should zero out the Args slot (to indicate the memory has been |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 41 | // freed). If any element of the vector is non-null, we should assert. |
| 42 | delete [] Args; |
| 43 | } |
| 44 | delete Next; |
| 45 | } |
| 46 | |
| 47 | AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame^] | 48 | llvm::StringRef AttrName = Name->getName(); |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 49 | |
| 50 | // Normalize the attribute name, __foo__ becomes foo. |
Daniel Dunbar | 4f90d8d | 2009-10-17 18:12:29 +0000 | [diff] [blame] | 51 | if (AttrName.startswith("__") && AttrName.endswith("__")) |
| 52 | AttrName = AttrName.substr(2, AttrName.size() - 4); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | |
Daniel Dunbar | 3068ae0 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 54 | // FIXME: Hand generating this is neither smart nor efficient. |
Daniel Dunbar | 4f90d8d | 2009-10-17 18:12:29 +0000 | [diff] [blame] | 55 | const char *Str = AttrName.data(); |
| 56 | switch (AttrName.size()) { |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 57 | case 4: |
| 58 | if (!memcmp(Str, "weak", 4)) return AT_weak; |
| 59 | if (!memcmp(Str, "pure", 4)) return AT_pure; |
Eli Friedman | 3c0eb16 | 2008-05-27 03:33:27 +0000 | [diff] [blame] | 60 | if (!memcmp(Str, "mode", 4)) return AT_mode; |
Daniel Dunbar | b805dad | 2009-02-13 19:23:53 +0000 | [diff] [blame] | 61 | if (!memcmp(Str, "used", 4)) return AT_used; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 62 | break; |
Nuno Lopes | d4cbda6 | 2008-06-08 15:45:52 +0000 | [diff] [blame] | 63 | case 5: |
| 64 | if (!memcmp(Str, "alias", 5)) return AT_alias; |
Anders Carlsson | c41ec23 | 2009-02-14 04:12:57 +0000 | [diff] [blame] | 65 | if (!memcmp(Str, "const", 5)) return AT_const; |
Nuno Lopes | d4cbda6 | 2008-06-08 15:45:52 +0000 | [diff] [blame] | 66 | break; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 67 | case 6: |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 68 | if (!memcmp(Str, "packed", 6)) return AT_packed; |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 69 | if (!memcmp(Str, "malloc", 6)) return AT_malloc; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 70 | if (!memcmp(Str, "format", 6)) return AT_format; |
| 71 | if (!memcmp(Str, "unused", 6)) return AT_unused; |
Steve Naroff | 9eae576 | 2008-09-18 16:44:58 +0000 | [diff] [blame] | 72 | if (!memcmp(Str, "blocks", 6)) return AT_blocks; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 73 | break; |
| 74 | case 7: |
| 75 | if (!memcmp(Str, "aligned", 7)) return AT_aligned; |
Anders Carlsson | f6e35d0 | 2009-01-31 01:16:18 +0000 | [diff] [blame] | 76 | if (!memcmp(Str, "cleanup", 7)) return AT_cleanup; |
Anders Carlsson | d87df37 | 2009-02-13 06:46:13 +0000 | [diff] [blame] | 77 | if (!memcmp(Str, "nodebug", 7)) return AT_nodebug; |
Daniel Dunbar | 17f194f | 2009-02-12 17:28:23 +0000 | [diff] [blame] | 78 | if (!memcmp(Str, "nonnull", 7)) return AT_nonnull; |
| 79 | if (!memcmp(Str, "nothrow", 7)) return AT_nothrow; |
| 80 | if (!memcmp(Str, "objc_gc", 7)) return AT_objc_gc; |
Fariborz Jahanian | ee76033 | 2009-03-27 18:38:55 +0000 | [diff] [blame] | 81 | if (!memcmp(Str, "regparm", 7)) return AT_regparm; |
Daniel Dunbar | 17f194f | 2009-02-12 17:28:23 +0000 | [diff] [blame] | 82 | if (!memcmp(Str, "section", 7)) return AT_section; |
| 83 | if (!memcmp(Str, "stdcall", 7)) return AT_stdcall; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 84 | break; |
Nate Begeman | c398f0b | 2008-02-21 19:30:49 +0000 | [diff] [blame] | 85 | case 8: |
| 86 | if (!memcmp(Str, "annotate", 8)) return AT_annotate; |
Ted Kremenek | aecb383 | 2008-02-27 20:43:06 +0000 | [diff] [blame] | 87 | if (!memcmp(Str, "noreturn", 8)) return AT_noreturn; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 88 | if (!memcmp(Str, "noinline", 8)) return AT_noinline; |
Nate Begeman | 440b456 | 2008-03-07 20:04:22 +0000 | [diff] [blame] | 89 | if (!memcmp(Str, "fastcall", 8)) return AT_fastcall; |
Ted Kremenek | f135e80 | 2008-07-15 22:38:34 +0000 | [diff] [blame] | 90 | if (!memcmp(Str, "iboutlet", 8)) return AT_IBOutlet; |
Anders Carlsson | 7709182 | 2008-10-05 18:05:59 +0000 | [diff] [blame] | 91 | if (!memcmp(Str, "sentinel", 8)) return AT_sentinel; |
Fariborz Jahanian | fa23c1d | 2009-01-13 23:34:40 +0000 | [diff] [blame] | 92 | if (!memcmp(Str, "NSObject", 8)) return AT_nsobject; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 93 | break; |
| 94 | case 9: |
| 95 | if (!memcmp(Str, "dllimport", 9)) return AT_dllimport; |
| 96 | if (!memcmp(Str, "dllexport", 9)) return AT_dllexport; |
Chris Lattner | d35fd5d | 2009-02-14 08:12:47 +0000 | [diff] [blame] | 97 | if (!memcmp(Str, "may_alias", 9)) return IgnoredAttribute; // FIXME: TBAA |
Nate Begeman | c398f0b | 2008-02-21 19:30:49 +0000 | [diff] [blame] | 98 | break; |
Chris Lattner | 7e669b2 | 2008-02-29 16:48:43 +0000 | [diff] [blame] | 99 | case 10: |
| 100 | if (!memcmp(Str, "deprecated", 10)) return AT_deprecated; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 101 | if (!memcmp(Str, "visibility", 10)) return AT_visibility; |
Daniel Dunbar | 3068ae0 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 102 | if (!memcmp(Str, "destructor", 10)) return AT_destructor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | if (!memcmp(Str, "format_arg", 10)) return AT_format_arg; |
Chris Lattner | cf2a721 | 2009-04-20 19:12:28 +0000 | [diff] [blame] | 104 | if (!memcmp(Str, "gnu_inline", 10)) return AT_gnu_inline; |
Chris Lattner | 7e669b2 | 2008-02-29 16:48:43 +0000 | [diff] [blame] | 105 | break; |
| 106 | case 11: |
Daniel Dunbar | 6e775db | 2009-03-06 06:39:57 +0000 | [diff] [blame] | 107 | if (!memcmp(Str, "weak_import", 11)) return AT_weak_import; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 108 | if (!memcmp(Str, "vector_size", 11)) return AT_vector_size; |
Daniel Dunbar | 3068ae0 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 109 | if (!memcmp(Str, "constructor", 11)) return AT_constructor; |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 110 | if (!memcmp(Str, "unavailable", 11)) return AT_unavailable; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 111 | break; |
Douglas Gregor | f9201e0 | 2009-02-11 23:02:49 +0000 | [diff] [blame] | 112 | case 12: |
| 113 | if (!memcmp(Str, "overloadable", 12)) return AT_overloadable; |
| 114 | break; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 115 | case 13: |
| 116 | if (!memcmp(Str, "address_space", 13)) return AT_address_space; |
Daniel Dunbar | af668b0 | 2008-10-28 00:17:57 +0000 | [diff] [blame] | 117 | if (!memcmp(Str, "always_inline", 13)) return AT_always_inline; |
Nate Begeman | 6f3d838 | 2009-06-26 06:32:41 +0000 | [diff] [blame] | 118 | if (!memcmp(Str, "vec_type_hint", 13)) return IgnoredAttribute; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 119 | break; |
Chris Lattner | 0db29ec | 2009-02-14 08:09:34 +0000 | [diff] [blame] | 120 | case 14: |
| 121 | if (!memcmp(Str, "objc_exception", 14)) return AT_objc_exception; |
| 122 | break; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 123 | case 15: |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 124 | if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type; |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 125 | break; |
Nuno Lopes | 27ae6c6 | 2008-04-25 09:32:00 +0000 | [diff] [blame] | 126 | case 17: |
| 127 | if (!memcmp(Str, "transparent_union", 17)) return AT_transparent_union; |
Ted Kremenek | b725232 | 2009-04-10 00:01:14 +0000 | [diff] [blame] | 128 | if (!memcmp(Str, "analyzer_noreturn", 17)) return AT_analyzer_noreturn; |
Nuno Lopes | 27ae6c6 | 2008-04-25 09:32:00 +0000 | [diff] [blame] | 129 | break; |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 130 | case 18: |
| 131 | if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result; |
| 132 | break; |
Ted Kremenek | 91ad269 | 2009-05-09 03:08:29 +0000 | [diff] [blame] | 133 | case 19: |
| 134 | if (!memcmp(Str, "ns_returns_retained", 19)) return AT_ns_returns_retained; |
| 135 | if (!memcmp(Str, "cf_returns_retained", 19)) return AT_cf_returns_retained; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 136 | break; |
Nate Begeman | 6f3d838 | 2009-06-26 06:32:41 +0000 | [diff] [blame] | 137 | case 20: |
| 138 | if (!memcmp(Str, "reqd_work_group_size", 20)) return AT_reqd_wg_size; |
Ted Kremenek | 0fc169e | 2009-04-24 23:09:54 +0000 | [diff] [blame] | 139 | case 22: |
Chris Lattner | 5e20448 | 2009-04-25 18:44:54 +0000 | [diff] [blame] | 140 | if (!memcmp(Str, "no_instrument_function", 22)) |
| 141 | return AT_no_instrument_function; |
Ted Kremenek | 0fc169e | 2009-04-24 23:09:54 +0000 | [diff] [blame] | 142 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | } |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 144 | return UnknownAttribute; |
| 145 | } |