Steve Naroff | b8371e1 | 2007-06-09 03:39:29 +0000 | [diff] [blame] | 1 | //===--- AttributeList.cpp --------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 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. |
Steve Naroff | b8371e1 | 2007-06-09 03:39:29 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the AttributeList class implementation |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 14 | #include "clang/Sema/AttributeList.h" |
Chris Lattner | 7e0fe44 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 15 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringSwitch.h" |
Steve Naroff | b8371e1 | 2007-06-09 03:39:29 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Ted Kremenek | 5eec2b0 | 2010-11-10 05:59:39 +0000 | [diff] [blame] | 19 | AttributeList::AttributeList(llvm::BumpPtrAllocator &Alloc, |
| 20 | IdentifierInfo *aName, SourceLocation aLoc, |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 21 | IdentifierInfo *sName, SourceLocation sLoc, |
Steve Naroff | b8371e1 | 2007-06-09 03:39:29 +0000 | [diff] [blame] | 22 | IdentifierInfo *pName, SourceLocation pLoc, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 23 | Expr **ExprList, unsigned numArgs, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 24 | bool declspec, bool cxx0x) |
Ted Kremenek | 5eec2b0 | 2010-11-10 05:59:39 +0000 | [diff] [blame] | 25 | : AttrName(aName), AttrLoc(aLoc), ScopeName(sName), |
| 26 | ScopeLoc(sLoc), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 27 | ParmName(pName), ParmLoc(pLoc), NumArgs(numArgs), Next(0), |
Abramo Bagnara | 5009937 | 2010-04-30 13:10:51 +0000 | [diff] [blame] | 28 | DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 29 | |
Chris Lattner | b5d8416 | 2009-02-19 06:25:12 +0000 | [diff] [blame] | 30 | if (numArgs == 0) |
| 31 | Args = 0; |
| 32 | else { |
Ted Kremenek | 5eec2b0 | 2010-11-10 05:59:39 +0000 | [diff] [blame] | 33 | // Allocate the Args array using the BumpPtrAllocator. |
| 34 | Args = Alloc.Allocate<Expr*>(numArgs); |
Chris Lattner | b5d8416 | 2009-02-19 06:25:12 +0000 | [diff] [blame] | 35 | memcpy(Args, ExprList, numArgs*sizeof(Args[0])); |
| 36 | } |
Steve Naroff | b8371e1 | 2007-06-09 03:39:29 +0000 | [diff] [blame] | 37 | } |
Chris Lattner | f18c743 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 38 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame^] | 39 | AttributeList::AttributeList(llvm::BumpPtrAllocator &Alloc, |
| 40 | IdentifierInfo *AttrName, SourceLocation AttrLoc, |
| 41 | IdentifierInfo *ScopeName, SourceLocation ScopeLoc, |
| 42 | IdentifierInfo *ParmName, SourceLocation ParmLoc, |
| 43 | const AvailabilityChange &Introduced, |
| 44 | const AvailabilityChange &Deprecated, |
| 45 | const AvailabilityChange &Obsoleted, |
| 46 | bool declspec, bool cxx0x) |
| 47 | : AttrName(AttrName), AttrLoc(AttrLoc), ScopeName(ScopeName), |
| 48 | ScopeLoc(ScopeLoc), ParmName(ParmName), ParmLoc(ParmLoc), |
| 49 | Args(0), NumArgs(0), Next(0), |
| 50 | DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), |
| 51 | AvailabilityIntroduced(Introduced), |
| 52 | AvailabilityDeprecated(Deprecated), |
| 53 | AvailabilityObsoleted(Obsoleted), |
| 54 | Invalid(false) { |
| 55 | } |
| 56 | |
Chris Lattner | f18c743 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 57 | AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { |
Daniel Dunbar | 07d0785 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 58 | llvm::StringRef AttrName = Name->getName(); |
Chris Lattner | f18c743 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 59 | |
| 60 | // Normalize the attribute name, __foo__ becomes foo. |
Daniel Dunbar | 5bf78579 | 2009-10-17 18:12:29 +0000 | [diff] [blame] | 61 | if (AttrName.startswith("__") && AttrName.endswith("__")) |
| 62 | AttrName = AttrName.substr(2, AttrName.size() - 4); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 64 | return llvm::StringSwitch<AttributeList::Kind>(AttrName) |
| 65 | .Case("weak", AT_weak) |
Rafael Espindola | c18086a | 2010-02-23 22:00:30 +0000 | [diff] [blame] | 66 | .Case("weakref", AT_weakref) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 67 | .Case("pure", AT_pure) |
| 68 | .Case("mode", AT_mode) |
| 69 | .Case("used", AT_used) |
| 70 | .Case("alias", AT_alias) |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 71 | .Case("align", AT_aligned) |
Eli Friedman | e4310c8 | 2009-11-09 18:38:53 +0000 | [diff] [blame] | 72 | .Case("cdecl", AT_cdecl) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 73 | .Case("const", AT_const) |
Gabor Greif | eef3197 | 2010-10-15 08:26:25 +0000 | [diff] [blame] | 74 | .Case("__const", AT_const) // some GCC headers do contain this spelling |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 75 | .Case("blocks", AT_blocks) |
Alexis Hunt | 54a0254 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 76 | .Case("format", AT_format) |
Alexis Hunt | 54a0254 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 77 | .Case("malloc", AT_malloc) |
| 78 | .Case("packed", AT_packed) |
| 79 | .Case("unused", AT_unused) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 80 | .Case("aligned", AT_aligned) |
| 81 | .Case("cleanup", AT_cleanup) |
Daniel Dunbar | 8caf641 | 2010-09-29 18:20:25 +0000 | [diff] [blame] | 82 | .Case("naked", AT_naked) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 83 | .Case("nodebug", AT_nodebug) |
| 84 | .Case("nonnull", AT_nonnull) |
| 85 | .Case("nothrow", AT_nothrow) |
| 86 | .Case("objc_gc", AT_objc_gc) |
| 87 | .Case("regparm", AT_regparm) |
| 88 | .Case("section", AT_section) |
| 89 | .Case("stdcall", AT_stdcall) |
| 90 | .Case("annotate", AT_annotate) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 91 | .Case("fastcall", AT_fastcall) |
Ted Kremenek | 06be968 | 2010-02-17 02:37:45 +0000 | [diff] [blame] | 92 | .Case("ibaction", AT_IBAction) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 93 | .Case("iboutlet", AT_IBOutlet) |
Ted Kremenek | 26bde77 | 2010-05-19 17:38:06 +0000 | [diff] [blame] | 94 | .Case("iboutletcollection", AT_IBOutletCollection) |
Alexis Hunt | 54a0254 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 95 | .Case("noreturn", AT_noreturn) |
| 96 | .Case("noinline", AT_noinline) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 97 | .Case("sentinel", AT_sentinel) |
| 98 | .Case("NSObject", AT_nsobject) |
| 99 | .Case("dllimport", AT_dllimport) |
| 100 | .Case("dllexport", AT_dllexport) |
Dan Gohman | bbb7d62 | 2010-11-17 00:03:07 +0000 | [diff] [blame] | 101 | .Case("may_alias", AT_may_alias) |
Alexis Hunt | 54a0254 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 102 | .Case("base_check", AT_base_check) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 103 | .Case("deprecated", AT_deprecated) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame^] | 104 | .Case("availability", AT_availability) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 105 | .Case("visibility", AT_visibility) |
| 106 | .Case("destructor", AT_destructor) |
| 107 | .Case("format_arg", AT_format_arg) |
| 108 | .Case("gnu_inline", AT_gnu_inline) |
| 109 | .Case("weak_import", AT_weak_import) |
John Thompson | cdb847ba | 2010-08-09 21:53:52 +0000 | [diff] [blame] | 110 | .Case("vecreturn", AT_vecreturn) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 111 | .Case("vector_size", AT_vector_size) |
| 112 | .Case("constructor", AT_constructor) |
| 113 | .Case("unavailable", AT_unavailable) |
| 114 | .Case("overloadable", AT_overloadable) |
| 115 | .Case("address_space", AT_address_space) |
Peter Collingbourne | 599cb8e | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 116 | .Case("opencl_image_access", AT_opencl_image_access) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 117 | .Case("always_inline", AT_always_inline) |
Chris Lattner | a9396af | 2010-04-12 02:18:49 +0000 | [diff] [blame] | 118 | .Case("returns_twice", IgnoredAttribute) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 119 | .Case("vec_type_hint", IgnoredAttribute) |
| 120 | .Case("objc_exception", AT_objc_exception) |
John McCall | 86bc21f | 2011-03-02 11:33:24 +0000 | [diff] [blame] | 121 | .Case("objc_method_family", AT_objc_method_family) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 122 | .Case("ext_vector_type", AT_ext_vector_type) |
Bob Wilson | 118baf7 | 2010-11-16 00:32:24 +0000 | [diff] [blame] | 123 | .Case("neon_vector_type", AT_neon_vector_type) |
| 124 | .Case("neon_polyvector_type", AT_neon_polyvector_type) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 125 | .Case("transparent_union", AT_transparent_union) |
| 126 | .Case("analyzer_noreturn", AT_analyzer_noreturn) |
| 127 | .Case("warn_unused_result", AT_warn_unused_result) |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 128 | .Case("carries_dependency", AT_carries_dependency) |
John McCall | ed43393 | 2011-01-25 03:31:58 +0000 | [diff] [blame] | 129 | .Case("ns_consumed", AT_ns_consumed) |
| 130 | .Case("ns_consumes_self", AT_ns_consumes_self) |
| 131 | .Case("ns_returns_autoreleased", AT_ns_returns_autoreleased) |
Ted Kremenek | d9c6663 | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 132 | .Case("ns_returns_not_retained", AT_ns_returns_not_retained) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 133 | .Case("ns_returns_retained", AT_ns_returns_retained) |
John McCall | ed43393 | 2011-01-25 03:31:58 +0000 | [diff] [blame] | 134 | .Case("cf_consumed", AT_cf_consumed) |
Ted Kremenek | d9c6663 | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 135 | .Case("cf_returns_not_retained", AT_cf_returns_not_retained) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 136 | .Case("cf_returns_retained", AT_cf_returns_retained) |
Ted Kremenek | d21139a | 2010-07-31 01:52:11 +0000 | [diff] [blame] | 137 | .Case("ownership_returns", AT_ownership_returns) |
| 138 | .Case("ownership_holds", AT_ownership_holds) |
| 139 | .Case("ownership_takes", AT_ownership_takes) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 140 | .Case("reqd_work_group_size", AT_reqd_wg_size) |
Fariborz Jahanian | ef5f621 | 2010-06-18 21:44:06 +0000 | [diff] [blame] | 141 | .Case("init_priority", AT_init_priority) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 142 | .Case("no_instrument_function", AT_no_instrument_function) |
Douglas Gregor | a941dca | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 143 | .Case("thiscall", AT_thiscall) |
Chris Lattner | 0ddd0ae | 2011-02-18 17:05:55 +0000 | [diff] [blame] | 144 | .Case("bounded", IgnoredAttribute) // OpenBSD |
Dawn Perchik | 335e16b | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 145 | .Case("pascal", AT_pascal) |
Douglas Gregor | a941dca | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 146 | .Case("__cdecl", AT_cdecl) |
| 147 | .Case("__stdcall", AT_stdcall) |
| 148 | .Case("__fastcall", AT_fastcall) |
| 149 | .Case("__thiscall", AT_thiscall) |
Dawn Perchik | 335e16b | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 150 | .Case("__pascal", AT_pascal) |
Peter Collingbourne | 6ab610c | 2010-12-01 03:15:31 +0000 | [diff] [blame] | 151 | .Case("constant", AT_constant) |
| 152 | .Case("device", AT_device) |
| 153 | .Case("global", AT_global) |
| 154 | .Case("host", AT_host) |
| 155 | .Case("shared", AT_shared) |
Peter Collingbourne | 827301e | 2010-12-12 23:03:07 +0000 | [diff] [blame] | 156 | .Case("launch_bounds", AT_launch_bounds) |
Eric Christopher | 8a2ee39 | 2010-12-02 02:45:55 +0000 | [diff] [blame] | 157 | .Case("common", AT_common) |
| 158 | .Case("nocommon", AT_nocommon) |
Peter Collingbourne | 7ce13fc | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 159 | .Case("opencl_kernel_function", AT_opencl_kernel_function) |
Francois Pichet | a83957a | 2010-12-19 06:50:37 +0000 | [diff] [blame] | 160 | .Case("uuid", AT_uuid) |
Douglas Gregor | 9826173 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 161 | .Default(UnknownAttribute); |
Chris Lattner | f18c743 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 162 | } |