blob: 2ee41bc3eb8d8f05cffb4661e1d84d4867942bb7 [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
14#include "clang/Parse/AttributeList.h"
Chris Lattner8f823d22009-04-11 18:48:18 +000015#include "clang/Basic/IdentifierTable.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016using namespace clang;
17
18AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
19 IdentifierInfo *pName, SourceLocation pLoc,
Chris Lattner8f823d22009-04-11 18:48:18 +000020 ActionBase::ExprTy **ExprList, unsigned numArgs,
Eli Friedmana23b4852009-06-08 07:21:15 +000021 AttributeList *n, bool declspec)
Reid Spencer5f016e22007-07-11 17:01:13 +000022 : AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc),
Eli Friedmana23b4852009-06-08 07:21:15 +000023 NumArgs(numArgs), Next(n), DeclspecAttribute(declspec) {
Mike Stump1eb44332009-09-09 15:08:12 +000024
Chris Lattner005b2352009-02-19 06:25:12 +000025 if (numArgs == 0)
26 Args = 0;
27 else {
Chris Lattner8f823d22009-04-11 18:48:18 +000028 Args = new ActionBase::ExprTy*[numArgs];
Chris Lattner005b2352009-02-19 06:25:12 +000029 memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
30 }
Reid Spencer5f016e22007-07-11 17:01:13 +000031}
Chris Lattner23351912008-02-20 23:14:47 +000032
33AttributeList::~AttributeList() {
34 if (Args) {
Mike Stump1eb44332009-09-09 15:08:12 +000035 // FIXME: before we delete the vector, we need to make sure the Expr's
Chris Lattner8f823d22009-04-11 18:48:18 +000036 // have been deleted. Since ActionBase::ExprTy is "void", we are dependent
Chris Lattner23351912008-02-20 23:14:47 +000037 // on the actions module for actually freeing the memory. The specific
Mike Stump1eb44332009-09-09 15:08:12 +000038 // 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 Lattner23351912008-02-20 23:14:47 +000041 // freed). If any element of the vector is non-null, we should assert.
42 delete [] Args;
43 }
44 delete Next;
45}
46
47AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
48 const char *Str = Name->getName();
49 unsigned Len = Name->getLength();
50
51 // Normalize the attribute name, __foo__ becomes foo.
52 if (Len > 4 && Str[0] == '_' && Str[1] == '_' &&
53 Str[Len - 2] == '_' && Str[Len - 1] == '_') {
54 Str += 2;
55 Len -= 4;
56 }
Mike Stump1eb44332009-09-09 15:08:12 +000057
Daniel Dunbar3068ae02008-07-31 22:40:48 +000058 // FIXME: Hand generating this is neither smart nor efficient.
Chris Lattner23351912008-02-20 23:14:47 +000059 switch (Len) {
Chris Lattnerddee4232008-03-03 03:28:21 +000060 case 4:
61 if (!memcmp(Str, "weak", 4)) return AT_weak;
62 if (!memcmp(Str, "pure", 4)) return AT_pure;
Eli Friedman3c0eb162008-05-27 03:33:27 +000063 if (!memcmp(Str, "mode", 4)) return AT_mode;
Daniel Dunbarb805dad2009-02-13 19:23:53 +000064 if (!memcmp(Str, "used", 4)) return AT_used;
Chris Lattnerddee4232008-03-03 03:28:21 +000065 break;
Nuno Lopesd4cbda62008-06-08 15:45:52 +000066 case 5:
67 if (!memcmp(Str, "alias", 5)) return AT_alias;
Anders Carlssonc41ec232009-02-14 04:12:57 +000068 if (!memcmp(Str, "const", 5)) return AT_const;
Nuno Lopesd4cbda62008-06-08 15:45:52 +000069 break;
Chris Lattnerddee4232008-03-03 03:28:21 +000070 case 6:
Chris Lattner23351912008-02-20 23:14:47 +000071 if (!memcmp(Str, "packed", 6)) return AT_packed;
Ryan Flynn76168e22009-08-09 20:07:29 +000072 if (!memcmp(Str, "malloc", 6)) return AT_malloc;
Chris Lattnerddee4232008-03-03 03:28:21 +000073 if (!memcmp(Str, "format", 6)) return AT_format;
74 if (!memcmp(Str, "unused", 6)) return AT_unused;
Steve Naroff9eae5762008-09-18 16:44:58 +000075 if (!memcmp(Str, "blocks", 6)) return AT_blocks;
Chris Lattner23351912008-02-20 23:14:47 +000076 break;
77 case 7:
78 if (!memcmp(Str, "aligned", 7)) return AT_aligned;
Anders Carlssonf6e35d02009-01-31 01:16:18 +000079 if (!memcmp(Str, "cleanup", 7)) return AT_cleanup;
Anders Carlssond87df372009-02-13 06:46:13 +000080 if (!memcmp(Str, "nodebug", 7)) return AT_nodebug;
Daniel Dunbar17f194f2009-02-12 17:28:23 +000081 if (!memcmp(Str, "nonnull", 7)) return AT_nonnull;
82 if (!memcmp(Str, "nothrow", 7)) return AT_nothrow;
83 if (!memcmp(Str, "objc_gc", 7)) return AT_objc_gc;
Fariborz Jahanianee760332009-03-27 18:38:55 +000084 if (!memcmp(Str, "regparm", 7)) return AT_regparm;
Daniel Dunbar17f194f2009-02-12 17:28:23 +000085 if (!memcmp(Str, "section", 7)) return AT_section;
86 if (!memcmp(Str, "stdcall", 7)) return AT_stdcall;
Chris Lattner23351912008-02-20 23:14:47 +000087 break;
Nate Begemanc398f0b2008-02-21 19:30:49 +000088 case 8:
89 if (!memcmp(Str, "annotate", 8)) return AT_annotate;
Ted Kremenekaecb3832008-02-27 20:43:06 +000090 if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
Chris Lattnerddee4232008-03-03 03:28:21 +000091 if (!memcmp(Str, "noinline", 8)) return AT_noinline;
Nate Begeman440b4562008-03-07 20:04:22 +000092 if (!memcmp(Str, "fastcall", 8)) return AT_fastcall;
Ted Kremenekf135e802008-07-15 22:38:34 +000093 if (!memcmp(Str, "iboutlet", 8)) return AT_IBOutlet;
Anders Carlsson77091822008-10-05 18:05:59 +000094 if (!memcmp(Str, "sentinel", 8)) return AT_sentinel;
Fariborz Jahanianfa23c1d2009-01-13 23:34:40 +000095 if (!memcmp(Str, "NSObject", 8)) return AT_nsobject;
Chris Lattnerddee4232008-03-03 03:28:21 +000096 break;
97 case 9:
98 if (!memcmp(Str, "dllimport", 9)) return AT_dllimport;
99 if (!memcmp(Str, "dllexport", 9)) return AT_dllexport;
Chris Lattnerd35fd5d2009-02-14 08:12:47 +0000100 if (!memcmp(Str, "may_alias", 9)) return IgnoredAttribute; // FIXME: TBAA
Nate Begemanc398f0b2008-02-21 19:30:49 +0000101 break;
Chris Lattner7e669b22008-02-29 16:48:43 +0000102 case 10:
103 if (!memcmp(Str, "deprecated", 10)) return AT_deprecated;
Chris Lattnerddee4232008-03-03 03:28:21 +0000104 if (!memcmp(Str, "visibility", 10)) return AT_visibility;
Daniel Dunbar3068ae02008-07-31 22:40:48 +0000105 if (!memcmp(Str, "destructor", 10)) return AT_destructor;
Mike Stump1eb44332009-09-09 15:08:12 +0000106 if (!memcmp(Str, "format_arg", 10)) return AT_format_arg;
Chris Lattnercf2a7212009-04-20 19:12:28 +0000107 if (!memcmp(Str, "gnu_inline", 10)) return AT_gnu_inline;
Chris Lattner7e669b22008-02-29 16:48:43 +0000108 break;
109 case 11:
Daniel Dunbar6e775db2009-03-06 06:39:57 +0000110 if (!memcmp(Str, "weak_import", 11)) return AT_weak_import;
Chris Lattner23351912008-02-20 23:14:47 +0000111 if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
Daniel Dunbar3068ae02008-07-31 22:40:48 +0000112 if (!memcmp(Str, "constructor", 11)) return AT_constructor;
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +0000113 if (!memcmp(Str, "unavailable", 11)) return AT_unavailable;
Chris Lattner23351912008-02-20 23:14:47 +0000114 break;
Douglas Gregorf9201e02009-02-11 23:02:49 +0000115 case 12:
116 if (!memcmp(Str, "overloadable", 12)) return AT_overloadable;
117 break;
Chris Lattner23351912008-02-20 23:14:47 +0000118 case 13:
119 if (!memcmp(Str, "address_space", 13)) return AT_address_space;
Daniel Dunbaraf668b02008-10-28 00:17:57 +0000120 if (!memcmp(Str, "always_inline", 13)) return AT_always_inline;
Nate Begeman6f3d8382009-06-26 06:32:41 +0000121 if (!memcmp(Str, "vec_type_hint", 13)) return IgnoredAttribute;
Chris Lattner23351912008-02-20 23:14:47 +0000122 break;
Chris Lattner0db29ec2009-02-14 08:09:34 +0000123 case 14:
124 if (!memcmp(Str, "objc_exception", 14)) return AT_objc_exception;
125 break;
Chris Lattner23351912008-02-20 23:14:47 +0000126 case 15:
Nate Begeman213541a2008-04-18 23:10:10 +0000127 if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
Chris Lattner23351912008-02-20 23:14:47 +0000128 break;
Nuno Lopes27ae6c62008-04-25 09:32:00 +0000129 case 17:
130 if (!memcmp(Str, "transparent_union", 17)) return AT_transparent_union;
Ted Kremenekb7252322009-04-10 00:01:14 +0000131 if (!memcmp(Str, "analyzer_noreturn", 17)) return AT_analyzer_noreturn;
Nuno Lopes27ae6c62008-04-25 09:32:00 +0000132 break;
Chris Lattnerddee4232008-03-03 03:28:21 +0000133 case 18:
134 if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result;
135 break;
Ted Kremenek91ad2692009-05-09 03:08:29 +0000136 case 19:
137 if (!memcmp(Str, "ns_returns_retained", 19)) return AT_ns_returns_retained;
138 if (!memcmp(Str, "cf_returns_retained", 19)) return AT_cf_returns_retained;
Mike Stump1eb44332009-09-09 15:08:12 +0000139 break;
Nate Begeman6f3d8382009-06-26 06:32:41 +0000140 case 20:
141 if (!memcmp(Str, "reqd_work_group_size", 20)) return AT_reqd_wg_size;
Ted Kremenek0fc169e2009-04-24 23:09:54 +0000142 case 22:
Chris Lattner5e204482009-04-25 18:44:54 +0000143 if (!memcmp(Str, "no_instrument_function", 22))
144 return AT_no_instrument_function;
Ted Kremenek0fc169e2009-04-24 23:09:54 +0000145 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000146 }
Chris Lattner23351912008-02-20 23:14:47 +0000147 return UnknownAttribute;
148}