blob: 1663fd58a99791fe0a128772c09c78447f82d20d [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the AttributeList class implementation
11//
12//===----------------------------------------------------------------------===//
13
John McCall19510852010-08-20 18:27:03 +000014#include "clang/Sema/AttributeList.h"
Chris Lattner8f823d22009-04-11 18:48:18 +000015#include "clang/Basic/IdentifierTable.h"
Douglas Gregorfc3bb492009-10-29 05:26:58 +000016#include "llvm/ADT/StringSwitch.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000017using namespace clang;
18
Ted Kremenek8113ecf2010-11-10 05:59:39 +000019AttributeList::AttributeList(llvm::BumpPtrAllocator &Alloc,
20 IdentifierInfo *aName, SourceLocation aLoc,
Sean Huntbbd37c62009-11-21 08:43:09 +000021 IdentifierInfo *sName, SourceLocation sLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +000022 IdentifierInfo *pName, SourceLocation pLoc,
John McCallb3d87482010-08-24 05:47:05 +000023 Expr **ExprList, unsigned numArgs,
John McCall7f040a92010-12-24 02:08:15 +000024 bool declspec, bool cxx0x)
Ted Kremenek8113ecf2010-11-10 05:59:39 +000025 : AttrName(aName), AttrLoc(aLoc), ScopeName(sName),
26 ScopeLoc(sLoc),
John McCall7f040a92010-12-24 02:08:15 +000027 ParmName(pName), ParmLoc(pLoc), NumArgs(numArgs), Next(0),
Abramo Bagnarae215f722010-04-30 13:10:51 +000028 DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false) {
Mike Stump1eb44332009-09-09 15:08:12 +000029
Chris Lattner005b2352009-02-19 06:25:12 +000030 if (numArgs == 0)
31 Args = 0;
32 else {
Ted Kremenek8113ecf2010-11-10 05:59:39 +000033 // Allocate the Args array using the BumpPtrAllocator.
34 Args = Alloc.Allocate<Expr*>(numArgs);
Chris Lattner005b2352009-02-19 06:25:12 +000035 memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
36 }
Reid Spencer5f016e22007-07-11 17:01:13 +000037}
Chris Lattner23351912008-02-20 23:14:47 +000038
Chris Lattner23351912008-02-20 23:14:47 +000039AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
Daniel Dunbar01eb9b92009-10-18 21:17:35 +000040 llvm::StringRef AttrName = Name->getName();
Chris Lattner23351912008-02-20 23:14:47 +000041
42 // Normalize the attribute name, __foo__ becomes foo.
Daniel Dunbar4f90d8d2009-10-17 18:12:29 +000043 if (AttrName.startswith("__") && AttrName.endswith("__"))
44 AttrName = AttrName.substr(2, AttrName.size() - 4);
Mike Stump1eb44332009-09-09 15:08:12 +000045
Douglas Gregorfc3bb492009-10-29 05:26:58 +000046 return llvm::StringSwitch<AttributeList::Kind>(AttrName)
47 .Case("weak", AT_weak)
Rafael Espindola11e8ce72010-02-23 22:00:30 +000048 .Case("weakref", AT_weakref)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000049 .Case("pure", AT_pure)
50 .Case("mode", AT_mode)
51 .Case("used", AT_used)
52 .Case("alias", AT_alias)
Sean Huntbbd37c62009-11-21 08:43:09 +000053 .Case("align", AT_aligned)
Eli Friedman8f4c59e2009-11-09 18:38:53 +000054 .Case("cdecl", AT_cdecl)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000055 .Case("const", AT_const)
Gabor Greifc5127ed2010-10-15 08:26:25 +000056 .Case("__const", AT_const) // some GCC headers do contain this spelling
Douglas Gregorfc3bb492009-10-29 05:26:58 +000057 .Case("blocks", AT_blocks)
Sean Hunt7725e672009-11-25 04:20:27 +000058 .Case("format", AT_format)
Sean Hunt7725e672009-11-25 04:20:27 +000059 .Case("malloc", AT_malloc)
60 .Case("packed", AT_packed)
61 .Case("unused", AT_unused)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000062 .Case("aligned", AT_aligned)
63 .Case("cleanup", AT_cleanup)
Daniel Dunbardd0cb222010-09-29 18:20:25 +000064 .Case("naked", AT_naked)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000065 .Case("nodebug", AT_nodebug)
66 .Case("nonnull", AT_nonnull)
67 .Case("nothrow", AT_nothrow)
68 .Case("objc_gc", AT_objc_gc)
69 .Case("regparm", AT_regparm)
70 .Case("section", AT_section)
71 .Case("stdcall", AT_stdcall)
72 .Case("annotate", AT_annotate)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000073 .Case("fastcall", AT_fastcall)
Ted Kremenekefbddd22010-02-17 02:37:45 +000074 .Case("ibaction", AT_IBAction)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000075 .Case("iboutlet", AT_IBOutlet)
Ted Kremenek857e9182010-05-19 17:38:06 +000076 .Case("iboutletcollection", AT_IBOutletCollection)
Sean Hunt7725e672009-11-25 04:20:27 +000077 .Case("noreturn", AT_noreturn)
78 .Case("noinline", AT_noinline)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000079 .Case("sentinel", AT_sentinel)
80 .Case("NSObject", AT_nsobject)
81 .Case("dllimport", AT_dllimport)
82 .Case("dllexport", AT_dllexport)
Dan Gohman34c26302010-11-17 00:03:07 +000083 .Case("may_alias", AT_may_alias)
Sean Hunt7725e672009-11-25 04:20:27 +000084 .Case("base_check", AT_base_check)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000085 .Case("deprecated", AT_deprecated)
86 .Case("visibility", AT_visibility)
87 .Case("destructor", AT_destructor)
88 .Case("format_arg", AT_format_arg)
89 .Case("gnu_inline", AT_gnu_inline)
90 .Case("weak_import", AT_weak_import)
John Thompson35cc9622010-08-09 21:53:52 +000091 .Case("vecreturn", AT_vecreturn)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000092 .Case("vector_size", AT_vector_size)
93 .Case("constructor", AT_constructor)
94 .Case("unavailable", AT_unavailable)
95 .Case("overloadable", AT_overloadable)
96 .Case("address_space", AT_address_space)
97 .Case("always_inline", AT_always_inline)
Chris Lattner9f6c7722010-04-12 02:18:49 +000098 .Case("returns_twice", IgnoredAttribute)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000099 .Case("vec_type_hint", IgnoredAttribute)
100 .Case("objc_exception", AT_objc_exception)
John McCalld5313b02011-03-02 11:33:24 +0000101 .Case("objc_method_family", AT_objc_method_family)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000102 .Case("ext_vector_type", AT_ext_vector_type)
Bob Wilson4211bb62010-11-16 00:32:24 +0000103 .Case("neon_vector_type", AT_neon_vector_type)
104 .Case("neon_polyvector_type", AT_neon_polyvector_type)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000105 .Case("transparent_union", AT_transparent_union)
106 .Case("analyzer_noreturn", AT_analyzer_noreturn)
107 .Case("warn_unused_result", AT_warn_unused_result)
Sean Huntbbd37c62009-11-21 08:43:09 +0000108 .Case("carries_dependency", AT_carries_dependency)
John McCallc7ad3812011-01-25 03:31:58 +0000109 .Case("ns_consumed", AT_ns_consumed)
110 .Case("ns_consumes_self", AT_ns_consumes_self)
111 .Case("ns_returns_autoreleased", AT_ns_returns_autoreleased)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000112 .Case("ns_returns_not_retained", AT_ns_returns_not_retained)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000113 .Case("ns_returns_retained", AT_ns_returns_retained)
John McCallc7ad3812011-01-25 03:31:58 +0000114 .Case("cf_consumed", AT_cf_consumed)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000115 .Case("cf_returns_not_retained", AT_cf_returns_not_retained)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000116 .Case("cf_returns_retained", AT_cf_returns_retained)
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000117 .Case("ownership_returns", AT_ownership_returns)
118 .Case("ownership_holds", AT_ownership_holds)
119 .Case("ownership_takes", AT_ownership_takes)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000120 .Case("reqd_work_group_size", AT_reqd_wg_size)
Fariborz Jahanian521f12d2010-06-18 21:44:06 +0000121 .Case("init_priority", AT_init_priority)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000122 .Case("no_instrument_function", AT_no_instrument_function)
Douglas Gregorf813a2c2010-05-18 16:57:00 +0000123 .Case("thiscall", AT_thiscall)
Chris Lattnercd5b3062011-02-18 17:05:55 +0000124 .Case("bounded", IgnoredAttribute) // OpenBSD
Dawn Perchik52fc3142010-09-03 01:29:35 +0000125 .Case("pascal", AT_pascal)
Douglas Gregorf813a2c2010-05-18 16:57:00 +0000126 .Case("__cdecl", AT_cdecl)
127 .Case("__stdcall", AT_stdcall)
128 .Case("__fastcall", AT_fastcall)
129 .Case("__thiscall", AT_thiscall)
Dawn Perchik52fc3142010-09-03 01:29:35 +0000130 .Case("__pascal", AT_pascal)
Peter Collingbourneced76712010-12-01 03:15:31 +0000131 .Case("constant", AT_constant)
132 .Case("device", AT_device)
133 .Case("global", AT_global)
134 .Case("host", AT_host)
135 .Case("shared", AT_shared)
Peter Collingbourne7b381982010-12-12 23:03:07 +0000136 .Case("launch_bounds", AT_launch_bounds)
Eric Christophera6cf1e72010-12-02 02:45:55 +0000137 .Case("common", AT_common)
138 .Case("nocommon", AT_nocommon)
Peter Collingbournef315fa82011-02-14 01:42:53 +0000139 .Case("opencl_kernel_function", AT_opencl_kernel_function)
Francois Pichet11542142010-12-19 06:50:37 +0000140 .Case("uuid", AT_uuid)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000141 .Default(UnknownAttribute);
Chris Lattner23351912008-02-20 23:14:47 +0000142}