AttributeList.cpp revision 212795
1212795Sdim//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
2212795Sdim//
3212795Sdim//                     The LLVM Compiler Infrastructure
4212795Sdim//
5212795Sdim// This file is distributed under the University of Illinois Open Source
6212795Sdim// License. See LICENSE.TXT for details.
7212795Sdim//
8212795Sdim//===----------------------------------------------------------------------===//
9212795Sdim//
10212795Sdim// This file defines the AttributeList class implementation
11212795Sdim//
12212795Sdim//===----------------------------------------------------------------------===//
13212795Sdim
14212795Sdim#include "clang/Sema/AttributeList.h"
15212795Sdim#include "clang/Basic/IdentifierTable.h"
16212795Sdim#include "llvm/ADT/StringSwitch.h"
17212795Sdimusing namespace clang;
18212795Sdim
19212795SdimAttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
20212795Sdim                             IdentifierInfo *sName, SourceLocation sLoc,
21212795Sdim                             IdentifierInfo *pName, SourceLocation pLoc,
22212795Sdim                             Expr **ExprList, unsigned numArgs,
23212795Sdim                             AttributeList *n, bool declspec, bool cxx0x)
24212795Sdim  : AttrName(aName), AttrLoc(aLoc), ScopeName(sName), ScopeLoc(sLoc),
25212795Sdim    ParmName(pName), ParmLoc(pLoc), NumArgs(numArgs), Next(n),
26212795Sdim    DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false) {
27212795Sdim
28212795Sdim  if (numArgs == 0)
29212795Sdim    Args = 0;
30212795Sdim  else {
31212795Sdim    Args = new Expr*[numArgs];
32212795Sdim    memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
33212795Sdim  }
34212795Sdim}
35212795Sdim
36212795SdimAttributeList::~AttributeList() {
37212795Sdim  if (Args) {
38212795Sdim    // FIXME: before we delete the vector, we need to make sure the Expr's
39212795Sdim    // have been deleted. Since ActionBase::ExprTy is "void", we are dependent
40212795Sdim    // on the actions module for actually freeing the memory. The specific
41212795Sdim    // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
42212795Sdim    // ParseField, ParseTag. Once these routines have freed the expression,
43212795Sdim    // they should zero out the Args slot (to indicate the memory has been
44212795Sdim    // freed). If any element of the vector is non-null, we should assert.
45212795Sdim    delete [] Args;
46212795Sdim  }
47212795Sdim  delete Next;
48212795Sdim}
49212795Sdim
50212795SdimAttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
51212795Sdim  llvm::StringRef AttrName = Name->getName();
52212795Sdim
53212795Sdim  // Normalize the attribute name, __foo__ becomes foo.
54212795Sdim  if (AttrName.startswith("__") && AttrName.endswith("__"))
55212795Sdim    AttrName = AttrName.substr(2, AttrName.size() - 4);
56212795Sdim
57212795Sdim  return llvm::StringSwitch<AttributeList::Kind>(AttrName)
58212795Sdim    .Case("weak", AT_weak)
59212795Sdim    .Case("weakref", AT_weakref)
60212795Sdim    .Case("pure", AT_pure)
61212795Sdim    .Case("mode", AT_mode)
62212795Sdim    .Case("used", AT_used)
63212795Sdim    .Case("alias", AT_alias)
64212795Sdim    .Case("align", AT_aligned)
65212795Sdim    .Case("final", AT_final)
66212795Sdim    .Case("cdecl", AT_cdecl)
67212795Sdim    .Case("const", AT_const)
68212795Sdim    .Case("blocks", AT_blocks)
69212795Sdim    .Case("format", AT_format)
70212795Sdim    .Case("hiding", AT_hiding)
71212795Sdim    .Case("malloc", AT_malloc)
72212795Sdim    .Case("packed", AT_packed)
73212795Sdim    .Case("unused", AT_unused)
74212795Sdim    .Case("aligned", AT_aligned)
75212795Sdim    .Case("cleanup", AT_cleanup)
76212795Sdim    .Case("nodebug", AT_nodebug)
77212795Sdim    .Case("nonnull", AT_nonnull)
78212795Sdim    .Case("nothrow", AT_nothrow)
79212795Sdim    .Case("objc_gc", AT_objc_gc)
80212795Sdim    .Case("regparm", AT_regparm)
81212795Sdim    .Case("section", AT_section)
82212795Sdim    .Case("stdcall", AT_stdcall)
83212795Sdim    .Case("annotate", AT_annotate)
84212795Sdim    .Case("fastcall", AT_fastcall)
85212795Sdim    .Case("ibaction", AT_IBAction)
86212795Sdim    .Case("iboutlet", AT_IBOutlet)
87212795Sdim    .Case("iboutletcollection", AT_IBOutletCollection)
88212795Sdim    .Case("noreturn", AT_noreturn)
89212795Sdim    .Case("noinline", AT_noinline)
90212795Sdim    .Case("override", AT_override)
91212795Sdim    .Case("sentinel", AT_sentinel)
92212795Sdim    .Case("NSObject", AT_nsobject)
93212795Sdim    .Case("dllimport", AT_dllimport)
94212795Sdim    .Case("dllexport", AT_dllexport)
95212795Sdim    .Case("may_alias", IgnoredAttribute) // FIXME: TBAA
96212795Sdim    .Case("base_check", AT_base_check)
97212795Sdim    .Case("deprecated", AT_deprecated)
98212795Sdim    .Case("visibility", AT_visibility)
99212795Sdim    .Case("destructor", AT_destructor)
100212795Sdim    .Case("format_arg", AT_format_arg)
101212795Sdim    .Case("gnu_inline", AT_gnu_inline)
102212795Sdim    .Case("weak_import", AT_weak_import)
103212795Sdim    .Case("vecreturn", AT_vecreturn)
104212795Sdim    .Case("vector_size", AT_vector_size)
105212795Sdim    .Case("constructor", AT_constructor)
106212795Sdim    .Case("unavailable", AT_unavailable)
107212795Sdim    .Case("overloadable", AT_overloadable)
108212795Sdim    .Case("address_space", AT_address_space)
109212795Sdim    .Case("always_inline", AT_always_inline)
110212795Sdim    .Case("returns_twice", IgnoredAttribute)
111212795Sdim    .Case("vec_type_hint", IgnoredAttribute)
112212795Sdim    .Case("objc_exception", AT_objc_exception)
113212795Sdim    .Case("ext_vector_type", AT_ext_vector_type)
114212795Sdim    .Case("transparent_union", AT_transparent_union)
115212795Sdim    .Case("analyzer_noreturn", AT_analyzer_noreturn)
116212795Sdim    .Case("warn_unused_result", AT_warn_unused_result)
117212795Sdim    .Case("carries_dependency", AT_carries_dependency)
118212795Sdim    .Case("ns_returns_not_retained", AT_ns_returns_not_retained)
119212795Sdim    .Case("ns_returns_retained", AT_ns_returns_retained)
120212795Sdim    .Case("cf_returns_not_retained", AT_cf_returns_not_retained)
121212795Sdim    .Case("cf_returns_retained", AT_cf_returns_retained)
122212795Sdim    .Case("ownership_returns", AT_ownership_returns)
123212795Sdim    .Case("ownership_holds", AT_ownership_holds)
124212795Sdim    .Case("ownership_takes", AT_ownership_takes)
125212795Sdim    .Case("reqd_work_group_size", AT_reqd_wg_size)
126212795Sdim    .Case("init_priority", AT_init_priority)
127212795Sdim    .Case("no_instrument_function", AT_no_instrument_function)
128212795Sdim    .Case("thiscall", AT_thiscall)
129212795Sdim    .Case("pascal", AT_pascal)
130212795Sdim    .Case("__cdecl", AT_cdecl)
131212795Sdim    .Case("__stdcall", AT_stdcall)
132212795Sdim    .Case("__fastcall", AT_fastcall)
133212795Sdim    .Case("__thiscall", AT_thiscall)
134212795Sdim    .Case("__pascal", AT_pascal)
135212795Sdim    .Default(UnknownAttribute);
136212795Sdim}
137