blob: 43722ad0dc9b2ec43fb5d9c9a744de4c6cc55827 [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,
Sean Huntbbd37c62009-11-21 08:43:09 +000020 IdentifierInfo *sName, SourceLocation sLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +000021 IdentifierInfo *pName, SourceLocation pLoc,
Chris Lattner8f823d22009-04-11 18:48:18 +000022 ActionBase::ExprTy **ExprList, unsigned numArgs,
Sean Huntbbd37c62009-11-21 08:43:09 +000023 AttributeList *n, bool declspec, bool cxx0x)
24 : AttrName(aName), AttrLoc(aLoc), ScopeName(sName), ScopeLoc(sLoc),
25 ParmName(pName), ParmLoc(pLoc), NumArgs(numArgs), Next(n),
26 DeclspecAttribute(declspec), CXX0XAttribute(cxx0x) {
Mike Stump1eb44332009-09-09 15:08:12 +000027
Chris Lattner005b2352009-02-19 06:25:12 +000028 if (numArgs == 0)
29 Args = 0;
30 else {
Chris Lattner8f823d22009-04-11 18:48:18 +000031 Args = new ActionBase::ExprTy*[numArgs];
Chris Lattner005b2352009-02-19 06:25:12 +000032 memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
33 }
Reid Spencer5f016e22007-07-11 17:01:13 +000034}
Chris Lattner23351912008-02-20 23:14:47 +000035
36AttributeList::~AttributeList() {
37 if (Args) {
Mike Stump1eb44332009-09-09 15:08:12 +000038 // FIXME: before we delete the vector, we need to make sure the Expr's
Chris Lattner8f823d22009-04-11 18:48:18 +000039 // have been deleted. Since ActionBase::ExprTy is "void", we are dependent
Chris Lattner23351912008-02-20 23:14:47 +000040 // on the actions module for actually freeing the memory. The specific
Mike Stump1eb44332009-09-09 15:08:12 +000041 // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
42 // ParseField, ParseTag. Once these routines have freed the expression,
43 // they should zero out the Args slot (to indicate the memory has been
Chris Lattner23351912008-02-20 23:14:47 +000044 // freed). If any element of the vector is non-null, we should assert.
45 delete [] Args;
46 }
47 delete Next;
48}
49
50AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
Daniel Dunbar01eb9b92009-10-18 21:17:35 +000051 llvm::StringRef AttrName = Name->getName();
Chris Lattner23351912008-02-20 23:14:47 +000052
53 // Normalize the attribute name, __foo__ becomes foo.
Daniel Dunbar4f90d8d2009-10-17 18:12:29 +000054 if (AttrName.startswith("__") && AttrName.endswith("__"))
55 AttrName = AttrName.substr(2, AttrName.size() - 4);
Mike Stump1eb44332009-09-09 15:08:12 +000056
Daniel Dunbar3068ae02008-07-31 22:40:48 +000057 // FIXME: Hand generating this is neither smart nor efficient.
Douglas Gregorfc3bb492009-10-29 05:26:58 +000058 return llvm::StringSwitch<AttributeList::Kind>(AttrName)
59 .Case("weak", AT_weak)
60 .Case("pure", AT_pure)
61 .Case("mode", AT_mode)
62 .Case("used", AT_used)
63 .Case("alias", AT_alias)
Sean Huntbbd37c62009-11-21 08:43:09 +000064 .Case("align", AT_aligned)
65 .Case("final", AT_final)
Eli Friedman8f4c59e2009-11-09 18:38:53 +000066 .Case("cdecl", AT_cdecl)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000067 .Case("const", AT_const)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000068 .Case("blocks", AT_blocks)
Sean Hunt7725e672009-11-25 04:20:27 +000069 .Case("format", AT_format)
70 .Case("hiding", AT_hiding)
71 .Case("malloc", AT_malloc)
72 .Case("packed", AT_packed)
73 .Case("unused", AT_unused)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000074 .Case("aligned", AT_aligned)
75 .Case("cleanup", AT_cleanup)
76 .Case("nodebug", AT_nodebug)
77 .Case("nonnull", AT_nonnull)
78 .Case("nothrow", AT_nothrow)
79 .Case("objc_gc", AT_objc_gc)
80 .Case("regparm", AT_regparm)
81 .Case("section", AT_section)
82 .Case("stdcall", AT_stdcall)
83 .Case("annotate", AT_annotate)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000084 .Case("fastcall", AT_fastcall)
Ted Kremenekefbddd22010-02-17 02:37:45 +000085 .Case("ibaction", AT_IBAction)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000086 .Case("iboutlet", AT_IBOutlet)
Sean Hunt7725e672009-11-25 04:20:27 +000087 .Case("noreturn", AT_noreturn)
88 .Case("noinline", AT_noinline)
89 .Case("override", AT_override)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000090 .Case("sentinel", AT_sentinel)
91 .Case("NSObject", AT_nsobject)
92 .Case("dllimport", AT_dllimport)
93 .Case("dllexport", AT_dllexport)
94 .Case("may_alias", IgnoredAttribute) // FIXME: TBAA
Sean Hunt7725e672009-11-25 04:20:27 +000095 .Case("base_check", AT_base_check)
Douglas Gregorfc3bb492009-10-29 05:26:58 +000096 .Case("deprecated", AT_deprecated)
97 .Case("visibility", AT_visibility)
98 .Case("destructor", AT_destructor)
99 .Case("format_arg", AT_format_arg)
100 .Case("gnu_inline", AT_gnu_inline)
101 .Case("weak_import", AT_weak_import)
102 .Case("vector_size", AT_vector_size)
103 .Case("constructor", AT_constructor)
104 .Case("unavailable", AT_unavailable)
105 .Case("overloadable", AT_overloadable)
106 .Case("address_space", AT_address_space)
107 .Case("always_inline", AT_always_inline)
108 .Case("vec_type_hint", IgnoredAttribute)
109 .Case("objc_exception", AT_objc_exception)
110 .Case("ext_vector_type", AT_ext_vector_type)
111 .Case("transparent_union", AT_transparent_union)
112 .Case("analyzer_noreturn", AT_analyzer_noreturn)
113 .Case("warn_unused_result", AT_warn_unused_result)
Sean Huntbbd37c62009-11-21 08:43:09 +0000114 .Case("carries_dependency", AT_carries_dependency)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000115 .Case("ns_returns_not_retained", AT_ns_returns_not_retained)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000116 .Case("ns_returns_retained", AT_ns_returns_retained)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000117 .Case("cf_returns_not_retained", AT_cf_returns_not_retained)
Douglas Gregorfc3bb492009-10-29 05:26:58 +0000118 .Case("cf_returns_retained", AT_cf_returns_retained)
119 .Case("reqd_work_group_size", AT_reqd_wg_size)
120 .Case("no_instrument_function", AT_no_instrument_function)
121 .Default(UnknownAttribute);
Chris Lattner23351912008-02-20 23:14:47 +0000122}