blob: 344ce9e90e554615e1a4ddcb066a0903426804db [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"
Douglas Gregorfc3bb492009-10-29 05:26:58 +000016#include "llvm/ADT/StringSwitch.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000017using namespace clang;
18
19AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
20 IdentifierInfo *pName, SourceLocation pLoc,
Chris Lattner8f823d22009-04-11 18:48:18 +000021 ActionBase::ExprTy **ExprList, unsigned numArgs,
Eli Friedmana23b4852009-06-08 07:21:15 +000022 AttributeList *n, bool declspec)
Reid Spencer5f016e22007-07-11 17:01:13 +000023 : AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc),
Eli Friedmana23b4852009-06-08 07:21:15 +000024 NumArgs(numArgs), Next(n), DeclspecAttribute(declspec) {
Mike Stump1eb44332009-09-09 15:08:12 +000025
Chris Lattner005b2352009-02-19 06:25:12 +000026 if (numArgs == 0)
27 Args = 0;
28 else {
Chris Lattner8f823d22009-04-11 18:48:18 +000029 Args = new ActionBase::ExprTy*[numArgs];
Chris Lattner005b2352009-02-19 06:25:12 +000030 memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
31 }
Reid Spencer5f016e22007-07-11 17:01:13 +000032}
Chris Lattner23351912008-02-20 23:14:47 +000033
34AttributeList::~AttributeList() {
35 if (Args) {
Mike Stump1eb44332009-09-09 15:08:12 +000036 // FIXME: before we delete the vector, we need to make sure the Expr's
Chris Lattner8f823d22009-04-11 18:48:18 +000037 // have been deleted. Since ActionBase::ExprTy is "void", we are dependent
Chris Lattner23351912008-02-20 23:14:47 +000038 // on the actions module for actually freeing the memory. The specific
Mike Stump1eb44332009-09-09 15:08:12 +000039 // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
40 // ParseField, ParseTag. Once these routines have freed the expression,
41 // they should zero out the Args slot (to indicate the memory has been
Chris Lattner23351912008-02-20 23:14:47 +000042 // freed). If any element of the vector is non-null, we should assert.
43 delete [] Args;
44 }
45 delete Next;
46}
47
48AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
Daniel Dunbar01eb9b92009-10-18 21:17:35 +000049 llvm::StringRef AttrName = Name->getName();
Chris Lattner23351912008-02-20 23:14:47 +000050
51 // Normalize the attribute name, __foo__ becomes foo.
Daniel Dunbar4f90d8d2009-10-17 18:12:29 +000052 if (AttrName.startswith("__") && AttrName.endswith("__"))
53 AttrName = AttrName.substr(2, AttrName.size() - 4);
Mike Stump1eb44332009-09-09 15:08:12 +000054
Daniel Dunbar3068ae02008-07-31 22:40:48 +000055 // FIXME: Hand generating this is neither smart nor efficient.
Douglas Gregorfc3bb492009-10-29 05:26:58 +000056 return llvm::StringSwitch<AttributeList::Kind>(AttrName)
57 .Case("weak", AT_weak)
58 .Case("pure", AT_pure)
59 .Case("mode", AT_mode)
60 .Case("used", AT_used)
61 .Case("alias", AT_alias)
62 .Case("const", AT_const)
63 .Case("packed", AT_packed)
64 .Case("malloc", AT_malloc)
65 .Case("format", AT_format)
66 .Case("unused", AT_unused)
67 .Case("blocks", AT_blocks)
68 .Case("aligned", AT_aligned)
69 .Case("cleanup", AT_cleanup)
70 .Case("nodebug", AT_nodebug)
71 .Case("nonnull", AT_nonnull)
72 .Case("nothrow", AT_nothrow)
73 .Case("objc_gc", AT_objc_gc)
74 .Case("regparm", AT_regparm)
75 .Case("section", AT_section)
76 .Case("stdcall", AT_stdcall)
77 .Case("annotate", AT_annotate)
78 .Case("noreturn", AT_noreturn)
79 .Case("noinline", AT_noinline)
80 .Case("fastcall", AT_fastcall)
81 .Case("iboutlet", AT_IBOutlet)
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
87 .Case("deprecated", AT_deprecated)
88 .Case("visibility", AT_visibility)
89 .Case("destructor", AT_destructor)
90 .Case("format_arg", AT_format_arg)
91 .Case("gnu_inline", AT_gnu_inline)
92 .Case("weak_import", AT_weak_import)
93 .Case("vector_size", AT_vector_size)
94 .Case("constructor", AT_constructor)
95 .Case("unavailable", AT_unavailable)
96 .Case("overloadable", AT_overloadable)
97 .Case("address_space", AT_address_space)
98 .Case("always_inline", AT_always_inline)
99 .Case("vec_type_hint", IgnoredAttribute)
100 .Case("objc_exception", AT_objc_exception)
101 .Case("ext_vector_type", AT_ext_vector_type)
102 .Case("transparent_union", AT_transparent_union)
103 .Case("analyzer_noreturn", AT_analyzer_noreturn)
104 .Case("warn_unused_result", AT_warn_unused_result)
105 .Case("ns_returns_retained", AT_ns_returns_retained)
106 .Case("cf_returns_retained", AT_cf_returns_retained)
107 .Case("reqd_work_group_size", AT_reqd_wg_size)
108 .Case("no_instrument_function", AT_no_instrument_function)
109 .Default(UnknownAttribute);
Chris Lattner23351912008-02-20 23:14:47 +0000110}