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 | |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 14 | #include "clang/Sema/AttributeList.h" |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 15 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringSwitch.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Ted Kremenek | 8113ecf | 2010-11-10 05:59:39 +0000 | [diff] [blame^] | 19 | AttributeList::AttributeList(llvm::BumpPtrAllocator &Alloc, |
| 20 | IdentifierInfo *aName, SourceLocation aLoc, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 21 | IdentifierInfo *sName, SourceLocation sLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | IdentifierInfo *pName, SourceLocation pLoc, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 23 | Expr **ExprList, unsigned numArgs, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 24 | AttributeList *n, bool declspec, bool cxx0x) |
Ted Kremenek | 8113ecf | 2010-11-10 05:59:39 +0000 | [diff] [blame^] | 25 | : AttrName(aName), AttrLoc(aLoc), ScopeName(sName), |
| 26 | ScopeLoc(sLoc), |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 27 | ParmName(pName), ParmLoc(pLoc), NumArgs(numArgs), Next(n), |
Abramo Bagnara | e215f72 | 2010-04-30 13:10:51 +0000 | [diff] [blame] | 28 | DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 29 | |
Chris Lattner | 005b235 | 2009-02-19 06:25:12 +0000 | [diff] [blame] | 30 | if (numArgs == 0) |
| 31 | Args = 0; |
| 32 | else { |
Ted Kremenek | 8113ecf | 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 | 005b235 | 2009-02-19 06:25:12 +0000 | [diff] [blame] | 35 | memcpy(Args, ExprList, numArgs*sizeof(Args[0])); |
| 36 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 37 | } |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 38 | |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 39 | AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 40 | llvm::StringRef AttrName = Name->getName(); |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 41 | |
| 42 | // Normalize the attribute name, __foo__ becomes foo. |
Daniel Dunbar | 4f90d8d | 2009-10-17 18:12:29 +0000 | [diff] [blame] | 43 | if (AttrName.startswith("__") && AttrName.endswith("__")) |
| 44 | AttrName = AttrName.substr(2, AttrName.size() - 4); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 46 | return llvm::StringSwitch<AttributeList::Kind>(AttrName) |
| 47 | .Case("weak", AT_weak) |
Rafael Espindola | 11e8ce7 | 2010-02-23 22:00:30 +0000 | [diff] [blame] | 48 | .Case("weakref", AT_weakref) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 49 | .Case("pure", AT_pure) |
| 50 | .Case("mode", AT_mode) |
| 51 | .Case("used", AT_used) |
| 52 | .Case("alias", AT_alias) |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 53 | .Case("align", AT_aligned) |
| 54 | .Case("final", AT_final) |
Eli Friedman | 8f4c59e | 2009-11-09 18:38:53 +0000 | [diff] [blame] | 55 | .Case("cdecl", AT_cdecl) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 56 | .Case("const", AT_const) |
Gabor Greif | c5127ed | 2010-10-15 08:26:25 +0000 | [diff] [blame] | 57 | .Case("__const", AT_const) // some GCC headers do contain this spelling |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 58 | .Case("blocks", AT_blocks) |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 59 | .Case("format", AT_format) |
| 60 | .Case("hiding", AT_hiding) |
| 61 | .Case("malloc", AT_malloc) |
| 62 | .Case("packed", AT_packed) |
| 63 | .Case("unused", AT_unused) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 64 | .Case("aligned", AT_aligned) |
| 65 | .Case("cleanup", AT_cleanup) |
Daniel Dunbar | dd0cb22 | 2010-09-29 18:20:25 +0000 | [diff] [blame] | 66 | .Case("naked", AT_naked) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 67 | .Case("nodebug", AT_nodebug) |
| 68 | .Case("nonnull", AT_nonnull) |
| 69 | .Case("nothrow", AT_nothrow) |
| 70 | .Case("objc_gc", AT_objc_gc) |
| 71 | .Case("regparm", AT_regparm) |
| 72 | .Case("section", AT_section) |
| 73 | .Case("stdcall", AT_stdcall) |
| 74 | .Case("annotate", AT_annotate) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 75 | .Case("fastcall", AT_fastcall) |
Ted Kremenek | efbddd2 | 2010-02-17 02:37:45 +0000 | [diff] [blame] | 76 | .Case("ibaction", AT_IBAction) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 77 | .Case("iboutlet", AT_IBOutlet) |
Ted Kremenek | 857e918 | 2010-05-19 17:38:06 +0000 | [diff] [blame] | 78 | .Case("iboutletcollection", AT_IBOutletCollection) |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 79 | .Case("noreturn", AT_noreturn) |
| 80 | .Case("noinline", AT_noinline) |
| 81 | .Case("override", AT_override) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 82 | .Case("sentinel", AT_sentinel) |
| 83 | .Case("NSObject", AT_nsobject) |
| 84 | .Case("dllimport", AT_dllimport) |
| 85 | .Case("dllexport", AT_dllexport) |
| 86 | .Case("may_alias", IgnoredAttribute) // FIXME: TBAA |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 87 | .Case("base_check", AT_base_check) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 88 | .Case("deprecated", AT_deprecated) |
| 89 | .Case("visibility", AT_visibility) |
| 90 | .Case("destructor", AT_destructor) |
| 91 | .Case("format_arg", AT_format_arg) |
| 92 | .Case("gnu_inline", AT_gnu_inline) |
| 93 | .Case("weak_import", AT_weak_import) |
John Thompson | 35cc962 | 2010-08-09 21:53:52 +0000 | [diff] [blame] | 94 | .Case("vecreturn", AT_vecreturn) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 95 | .Case("vector_size", AT_vector_size) |
| 96 | .Case("constructor", AT_constructor) |
| 97 | .Case("unavailable", AT_unavailable) |
| 98 | .Case("overloadable", AT_overloadable) |
| 99 | .Case("address_space", AT_address_space) |
| 100 | .Case("always_inline", AT_always_inline) |
Chris Lattner | 9f6c772 | 2010-04-12 02:18:49 +0000 | [diff] [blame] | 101 | .Case("returns_twice", IgnoredAttribute) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 102 | .Case("vec_type_hint", IgnoredAttribute) |
| 103 | .Case("objc_exception", AT_objc_exception) |
| 104 | .Case("ext_vector_type", AT_ext_vector_type) |
| 105 | .Case("transparent_union", AT_transparent_union) |
| 106 | .Case("analyzer_noreturn", AT_analyzer_noreturn) |
| 107 | .Case("warn_unused_result", AT_warn_unused_result) |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 108 | .Case("carries_dependency", AT_carries_dependency) |
Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 109 | .Case("ns_returns_not_retained", AT_ns_returns_not_retained) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 110 | .Case("ns_returns_retained", AT_ns_returns_retained) |
Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 111 | .Case("cf_returns_not_retained", AT_cf_returns_not_retained) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 112 | .Case("cf_returns_retained", AT_cf_returns_retained) |
Ted Kremenek | dd0e490 | 2010-07-31 01:52:11 +0000 | [diff] [blame] | 113 | .Case("ownership_returns", AT_ownership_returns) |
| 114 | .Case("ownership_holds", AT_ownership_holds) |
| 115 | .Case("ownership_takes", AT_ownership_takes) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 116 | .Case("reqd_work_group_size", AT_reqd_wg_size) |
Fariborz Jahanian | 521f12d | 2010-06-18 21:44:06 +0000 | [diff] [blame] | 117 | .Case("init_priority", AT_init_priority) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 118 | .Case("no_instrument_function", AT_no_instrument_function) |
Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 119 | .Case("thiscall", AT_thiscall) |
Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 120 | .Case("pascal", AT_pascal) |
Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 121 | .Case("__cdecl", AT_cdecl) |
| 122 | .Case("__stdcall", AT_stdcall) |
| 123 | .Case("__fastcall", AT_fastcall) |
| 124 | .Case("__thiscall", AT_thiscall) |
Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 125 | .Case("__pascal", AT_pascal) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 126 | .Default(UnknownAttribute); |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 127 | } |