blob: 9cee6abebbdfdf5a986ce96f22893aa0c51e5835 [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,
Chris Lattnerd5c4de72009-02-19 06:25:12 +000019 Action::ExprTy **ExprList, unsigned numArgs,
Chris Lattner4b009652007-07-25 00:24:17 +000020 AttributeList *n)
21 : AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc),
Chris Lattnerd5c4de72009-02-19 06:25:12 +000022 NumArgs(numArgs), Next(n) {
23
24 if (numArgs == 0)
25 Args = 0;
26 else {
27 Args = new Action::ExprTy*[numArgs];
28 memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
29 }
Chris Lattner4b009652007-07-25 00:24:17 +000030}
Chris Lattnerd243eb42008-02-20 23:14:47 +000031
32AttributeList::~AttributeList() {
33 if (Args) {
34 // FIXME: before we delete the vector, we need to make sure the Expr's
35 // have been deleted. Since Action::ExprTy is "void", we are dependent
36 // on the actions module for actually freeing the memory. The specific
37 // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
38 // ParseField, ParseTag. Once these routines have freed the expression,
39 // they should zero out the Args slot (to indicate the memory has been
40 // freed). If any element of the vector is non-null, we should assert.
41 delete [] Args;
42 }
43 delete Next;
44}
45
46AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
47 const char *Str = Name->getName();
48 unsigned Len = Name->getLength();
49
50 // Normalize the attribute name, __foo__ becomes foo.
51 if (Len > 4 && Str[0] == '_' && Str[1] == '_' &&
52 Str[Len - 2] == '_' && Str[Len - 1] == '_') {
53 Str += 2;
54 Len -= 4;
55 }
Ted Kremenek4e5bb122008-07-15 22:26:48 +000056
Daniel Dunbar8716a012008-07-31 22:40:48 +000057 // FIXME: Hand generating this is neither smart nor efficient.
Chris Lattnerd243eb42008-02-20 23:14:47 +000058 switch (Len) {
Chris Lattner402b3372008-03-03 03:28:21 +000059 case 4:
60 if (!memcmp(Str, "weak", 4)) return AT_weak;
61 if (!memcmp(Str, "pure", 4)) return AT_pure;
Eli Friedman86ad5222008-05-27 03:33:27 +000062 if (!memcmp(Str, "mode", 4)) return AT_mode;
Daniel Dunbarb88b4f72009-02-13 19:23:53 +000063 if (!memcmp(Str, "used", 4)) return AT_used;
Chris Lattner402b3372008-03-03 03:28:21 +000064 break;
Nuno Lopes78534382008-06-08 15:45:52 +000065 case 5:
66 if (!memcmp(Str, "alias", 5)) return AT_alias;
Anders Carlssona9aa1202009-02-14 04:12:57 +000067 if (!memcmp(Str, "const", 5)) return AT_const;
Nuno Lopes78534382008-06-08 15:45:52 +000068 break;
Chris Lattner402b3372008-03-03 03:28:21 +000069 case 6:
Chris Lattnerd243eb42008-02-20 23:14:47 +000070 if (!memcmp(Str, "packed", 6)) return AT_packed;
Chris Lattner83f6cc52009-02-14 08:12:47 +000071 if (!memcmp(Str, "malloc", 6)) return IgnoredAttribute; // FIXME: noalias.
Chris Lattner402b3372008-03-03 03:28:21 +000072 if (!memcmp(Str, "format", 6)) return AT_format;
73 if (!memcmp(Str, "unused", 6)) return AT_unused;
Steve Naroffe1cecba2008-09-18 16:44:58 +000074 if (!memcmp(Str, "blocks", 6)) return AT_blocks;
Chris Lattnerd243eb42008-02-20 23:14:47 +000075 break;
76 case 7:
77 if (!memcmp(Str, "aligned", 7)) return AT_aligned;
Anders Carlsson677e38f2009-01-31 01:16:18 +000078 if (!memcmp(Str, "cleanup", 7)) return AT_cleanup;
Anders Carlssonf607f532009-02-13 06:46:13 +000079 if (!memcmp(Str, "nodebug", 7)) return AT_nodebug;
Daniel Dunbar97509722009-02-12 17:28:23 +000080 if (!memcmp(Str, "nonnull", 7)) return AT_nonnull;
81 if (!memcmp(Str, "nothrow", 7)) return AT_nothrow;
82 if (!memcmp(Str, "objc_gc", 7)) return AT_objc_gc;
83 if (!memcmp(Str, "section", 7)) return AT_section;
84 if (!memcmp(Str, "stdcall", 7)) return AT_stdcall;
Chris Lattnerd243eb42008-02-20 23:14:47 +000085 break;
Nate Begeman754d3fc2008-02-21 19:30:49 +000086 case 8:
87 if (!memcmp(Str, "annotate", 8)) return AT_annotate;
Ted Kremenek13bfae62008-02-27 20:43:06 +000088 if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
Chris Lattner402b3372008-03-03 03:28:21 +000089 if (!memcmp(Str, "noinline", 8)) return AT_noinline;
Nate Begemand75d28b2008-03-07 20:04:22 +000090 if (!memcmp(Str, "fastcall", 8)) return AT_fastcall;
Ted Kremenekec695ed2008-07-15 22:38:34 +000091 if (!memcmp(Str, "iboutlet", 8)) return AT_IBOutlet;
Anders Carlsson244d99b2008-10-05 18:05:59 +000092 if (!memcmp(Str, "sentinel", 8)) return AT_sentinel;
Fariborz Jahanian82f54962009-01-13 23:34:40 +000093 if (!memcmp(Str, "NSObject", 8)) return AT_nsobject;
Chris Lattner402b3372008-03-03 03:28:21 +000094 break;
95 case 9:
96 if (!memcmp(Str, "dllimport", 9)) return AT_dllimport;
97 if (!memcmp(Str, "dllexport", 9)) return AT_dllexport;
Chris Lattner83f6cc52009-02-14 08:12:47 +000098 if (!memcmp(Str, "may_alias", 9)) return IgnoredAttribute; // FIXME: TBAA
Nate Begeman754d3fc2008-02-21 19:30:49 +000099 break;
Chris Lattneree4c3bf2008-02-29 16:48:43 +0000100 case 10:
101 if (!memcmp(Str, "deprecated", 10)) return AT_deprecated;
Chris Lattner402b3372008-03-03 03:28:21 +0000102 if (!memcmp(Str, "visibility", 10)) return AT_visibility;
Daniel Dunbar8716a012008-07-31 22:40:48 +0000103 if (!memcmp(Str, "destructor", 10)) return AT_destructor;
Chris Lattner83f6cc52009-02-14 08:12:47 +0000104 if (!memcmp(Str, "format_arg", 10))
105 return IgnoredAttribute; // FIXME: printf format string checking.
Chris Lattneree4c3bf2008-02-29 16:48:43 +0000106 break;
107 case 11:
Daniel Dunbar42e41392009-03-06 06:39:57 +0000108 if (!memcmp(Str, "weak_import", 11)) return AT_weak_import;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000109 if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
Daniel Dunbar8716a012008-07-31 22:40:48 +0000110 if (!memcmp(Str, "constructor", 11)) return AT_constructor;
Fariborz Jahanian8f9b1b22008-12-17 01:07:27 +0000111 if (!memcmp(Str, "unavailable", 11)) return AT_unavailable;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000112 break;
Douglas Gregorfcb19192009-02-11 23:02:49 +0000113 case 12:
114 if (!memcmp(Str, "overloadable", 12)) return AT_overloadable;
115 break;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000116 case 13:
117 if (!memcmp(Str, "address_space", 13)) return AT_address_space;
Daniel Dunbar0a2da712008-10-28 00:17:57 +0000118 if (!memcmp(Str, "always_inline", 13)) return AT_always_inline;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000119 break;
Chris Lattnera9b98462009-02-14 08:09:34 +0000120 case 14:
121 if (!memcmp(Str, "objc_exception", 14)) return AT_objc_exception;
122 break;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000123 case 15:
Nate Begemanaf6ed502008-04-18 23:10:10 +0000124 if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
Chris Lattnerd243eb42008-02-20 23:14:47 +0000125 break;
Nuno Lopes463ec842008-04-25 09:32:00 +0000126 case 17:
127 if (!memcmp(Str, "transparent_union", 17)) return AT_transparent_union;
128 break;
Chris Lattner402b3372008-03-03 03:28:21 +0000129 case 18:
130 if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result;
131 break;
132 }
Chris Lattnerd243eb42008-02-20 23:14:47 +0000133 return UnknownAttribute;
134}