blob: 954e93e056a97ee74674991869492f7ffaa18ddc [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the AttributeList class implementation
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/AttributeList.h"
Chris Lattner4b009652007-07-25 00:24:17 +000015using namespace clang;
16
17AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
18 IdentifierInfo *pName, SourceLocation pLoc,
Sebastian Redl0c986032009-02-09 18:23:29 +000019 Action::ExprTy **elist, unsigned numargs,
Chris Lattner4b009652007-07-25 00:24:17 +000020 AttributeList *n)
21 : AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc),
22 NumArgs(numargs), Next(n) {
23 Args = new Action::ExprTy*[numargs];
24 for (unsigned i = 0; i != numargs; ++i)
25 Args[i] = elist[i];
26}
Chris Lattnerd243eb42008-02-20 23:14:47 +000027
28AttributeList::~AttributeList() {
29 if (Args) {
30 // FIXME: before we delete the vector, we need to make sure the Expr's
31 // have been deleted. Since Action::ExprTy is "void", we are dependent
32 // on the actions module for actually freeing the memory. The specific
33 // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
34 // ParseField, ParseTag. Once these routines have freed the expression,
35 // they should zero out the Args slot (to indicate the memory has been
36 // freed). If any element of the vector is non-null, we should assert.
37 delete [] Args;
38 }
39 delete Next;
40}
41
42AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
43 const char *Str = Name->getName();
44 unsigned Len = Name->getLength();
45
46 // Normalize the attribute name, __foo__ becomes foo.
47 if (Len > 4 && Str[0] == '_' && Str[1] == '_' &&
48 Str[Len - 2] == '_' && Str[Len - 1] == '_') {
49 Str += 2;
50 Len -= 4;
51 }
Ted Kremenek4e5bb122008-07-15 22:26:48 +000052
Daniel Dunbar8716a012008-07-31 22:40:48 +000053 // FIXME: Hand generating this is neither smart nor efficient.
Chris Lattnerd243eb42008-02-20 23:14:47 +000054 switch (Len) {
Chris Lattner402b3372008-03-03 03:28:21 +000055 case 4:
56 if (!memcmp(Str, "weak", 4)) return AT_weak;
57 if (!memcmp(Str, "pure", 4)) return AT_pure;
Eli Friedman86ad5222008-05-27 03:33:27 +000058 if (!memcmp(Str, "mode", 4)) return AT_mode;
Chris Lattner402b3372008-03-03 03:28:21 +000059 break;
Nuno Lopes78534382008-06-08 15:45:52 +000060 case 5:
61 if (!memcmp(Str, "alias", 5)) return AT_alias;
62 break;
Chris Lattner402b3372008-03-03 03:28:21 +000063 case 6:
Chris Lattnerd243eb42008-02-20 23:14:47 +000064 if (!memcmp(Str, "packed", 6)) return AT_packed;
Chris Lattner402b3372008-03-03 03:28:21 +000065 if (!memcmp(Str, "malloc", 6)) return AT_malloc;
66 if (!memcmp(Str, "format", 6)) return AT_format;
67 if (!memcmp(Str, "unused", 6)) return AT_unused;
Steve Naroffe1cecba2008-09-18 16:44:58 +000068 if (!memcmp(Str, "blocks", 6)) return AT_blocks;
Chris Lattnerd243eb42008-02-20 23:14:47 +000069 break;
70 case 7:
71 if (!memcmp(Str, "aligned", 7)) return AT_aligned;
Chris Lattner402b3372008-03-03 03:28:21 +000072 if (!memcmp(Str, "nothrow", 7)) return AT_nothrow;
73 if (!memcmp(Str, "nonnull", 7)) return AT_nonnull;
Anders Carlssond83141a52008-08-23 23:22:21 +000074 if (!memcmp(Str, "objc_gc", 7)) return AT_objc_gc;
Nate Begemand75d28b2008-03-07 20:04:22 +000075 if (!memcmp(Str, "stdcall", 7)) return AT_stdcall;
Anders Carlsson677e38f2009-01-31 01:16:18 +000076 if (!memcmp(Str, "cleanup", 7)) return AT_cleanup;
Chris Lattnerd243eb42008-02-20 23:14:47 +000077 break;
Nate Begeman754d3fc2008-02-21 19:30:49 +000078 case 8:
79 if (!memcmp(Str, "annotate", 8)) return AT_annotate;
Ted Kremenek13bfae62008-02-27 20:43:06 +000080 if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
Chris Lattner402b3372008-03-03 03:28:21 +000081 if (!memcmp(Str, "noinline", 8)) return AT_noinline;
Nate Begemand75d28b2008-03-07 20:04:22 +000082 if (!memcmp(Str, "fastcall", 8)) return AT_fastcall;
Ted Kremenekec695ed2008-07-15 22:38:34 +000083 if (!memcmp(Str, "iboutlet", 8)) return AT_IBOutlet;
Anders Carlsson244d99b2008-10-05 18:05:59 +000084 if (!memcmp(Str, "sentinel", 8)) return AT_sentinel;
Fariborz Jahanian82f54962009-01-13 23:34:40 +000085 if (!memcmp(Str, "NSObject", 8)) return AT_nsobject;
Chris Lattner402b3372008-03-03 03:28:21 +000086 break;
87 case 9:
88 if (!memcmp(Str, "dllimport", 9)) return AT_dllimport;
89 if (!memcmp(Str, "dllexport", 9)) return AT_dllexport;
Nate Begeman754d3fc2008-02-21 19:30:49 +000090 break;
Chris Lattneree4c3bf2008-02-29 16:48:43 +000091 case 10:
92 if (!memcmp(Str, "deprecated", 10)) return AT_deprecated;
Chris Lattner402b3372008-03-03 03:28:21 +000093 if (!memcmp(Str, "visibility", 10)) return AT_visibility;
Daniel Dunbar8716a012008-07-31 22:40:48 +000094 if (!memcmp(Str, "destructor", 10)) return AT_destructor;
Chris Lattneree4c3bf2008-02-29 16:48:43 +000095 break;
96 case 11:
Chris Lattnerd243eb42008-02-20 23:14:47 +000097 if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
Daniel Dunbar8716a012008-07-31 22:40:48 +000098 if (!memcmp(Str, "constructor", 11)) return AT_constructor;
Fariborz Jahanian8f9b1b22008-12-17 01:07:27 +000099 if (!memcmp(Str, "unavailable", 11)) return AT_unavailable;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000100 break;
Douglas Gregorfcb19192009-02-11 23:02:49 +0000101 case 12:
102 if (!memcmp(Str, "overloadable", 12)) return AT_overloadable;
103 break;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000104 case 13:
105 if (!memcmp(Str, "address_space", 13)) return AT_address_space;
Daniel Dunbar0a2da712008-10-28 00:17:57 +0000106 if (!memcmp(Str, "always_inline", 13)) return AT_always_inline;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000107 break;
108 case 15:
Nate Begemanaf6ed502008-04-18 23:10:10 +0000109 if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000110 break;
Nuno Lopes463ec842008-04-25 09:32:00 +0000111 case 17:
112 if (!memcmp(Str, "transparent_union", 17)) return AT_transparent_union;
113 break;
Chris Lattner402b3372008-03-03 03:28:21 +0000114 case 18:
115 if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result;
116 break;
117 }
Chris Lattnerd243eb42008-02-20 23:14:47 +0000118 return UnknownAttribute;
119}