AttributeList.cpp revision cd5b306f1b79c8a82fb0bdb4cf353021ea452fed
1//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the AttributeList class implementation
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Sema/AttributeList.h"
15#include "clang/Basic/IdentifierTable.h"
16#include "llvm/ADT/StringSwitch.h"
17using namespace clang;
18
19AttributeList::AttributeList(llvm::BumpPtrAllocator &Alloc,
20                             IdentifierInfo *aName, SourceLocation aLoc,
21                             IdentifierInfo *sName, SourceLocation sLoc,
22                             IdentifierInfo *pName, SourceLocation pLoc,
23                             Expr **ExprList, unsigned numArgs,
24                             bool declspec, bool cxx0x)
25  : AttrName(aName), AttrLoc(aLoc), ScopeName(sName),
26    ScopeLoc(sLoc),
27    ParmName(pName), ParmLoc(pLoc), NumArgs(numArgs), Next(0),
28    DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false) {
29
30  if (numArgs == 0)
31    Args = 0;
32  else {
33    // Allocate the Args array using the BumpPtrAllocator.
34    Args = Alloc.Allocate<Expr*>(numArgs);
35    memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
36  }
37}
38
39AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
40  llvm::StringRef AttrName = Name->getName();
41
42  // Normalize the attribute name, __foo__ becomes foo.
43  if (AttrName.startswith("__") && AttrName.endswith("__"))
44    AttrName = AttrName.substr(2, AttrName.size() - 4);
45
46  return llvm::StringSwitch<AttributeList::Kind>(AttrName)
47    .Case("weak", AT_weak)
48    .Case("weakref", AT_weakref)
49    .Case("pure", AT_pure)
50    .Case("mode", AT_mode)
51    .Case("used", AT_used)
52    .Case("alias", AT_alias)
53    .Case("align", AT_aligned)
54    .Case("cdecl", AT_cdecl)
55    .Case("const", AT_const)
56    .Case("__const", AT_const) // some GCC headers do contain this spelling
57    .Case("blocks", AT_blocks)
58    .Case("format", AT_format)
59    .Case("malloc", AT_malloc)
60    .Case("packed", AT_packed)
61    .Case("unused", AT_unused)
62    .Case("aligned", AT_aligned)
63    .Case("cleanup", AT_cleanup)
64    .Case("naked", AT_naked)
65    .Case("nodebug", AT_nodebug)
66    .Case("nonnull", AT_nonnull)
67    .Case("nothrow", AT_nothrow)
68    .Case("objc_gc", AT_objc_gc)
69    .Case("regparm", AT_regparm)
70    .Case("section", AT_section)
71    .Case("stdcall", AT_stdcall)
72    .Case("annotate", AT_annotate)
73    .Case("fastcall", AT_fastcall)
74    .Case("ibaction", AT_IBAction)
75    .Case("iboutlet", AT_IBOutlet)
76    .Case("iboutletcollection", AT_IBOutletCollection)
77    .Case("noreturn", AT_noreturn)
78    .Case("noinline", AT_noinline)
79    .Case("sentinel", AT_sentinel)
80    .Case("NSObject", AT_nsobject)
81    .Case("dllimport", AT_dllimport)
82    .Case("dllexport", AT_dllexport)
83    .Case("may_alias", AT_may_alias)
84    .Case("base_check", AT_base_check)
85    .Case("deprecated", AT_deprecated)
86    .Case("visibility", AT_visibility)
87    .Case("destructor", AT_destructor)
88    .Case("format_arg", AT_format_arg)
89    .Case("gnu_inline", AT_gnu_inline)
90    .Case("weak_import", AT_weak_import)
91    .Case("vecreturn", AT_vecreturn)
92    .Case("vector_size", AT_vector_size)
93    .Case("constructor", AT_constructor)
94    .Case("unavailable", AT_unavailable)
95    .Case("overloadable", AT_overloadable)
96    .Case("address_space", AT_address_space)
97    .Case("always_inline", AT_always_inline)
98    .Case("returns_twice", IgnoredAttribute)
99    .Case("vec_type_hint", IgnoredAttribute)
100    .Case("objc_exception", AT_objc_exception)
101    .Case("ext_vector_type", AT_ext_vector_type)
102    .Case("neon_vector_type", AT_neon_vector_type)
103    .Case("neon_polyvector_type", AT_neon_polyvector_type)
104    .Case("transparent_union", AT_transparent_union)
105    .Case("analyzer_noreturn", AT_analyzer_noreturn)
106    .Case("warn_unused_result", AT_warn_unused_result)
107    .Case("carries_dependency", AT_carries_dependency)
108    .Case("ns_consumed", AT_ns_consumed)
109    .Case("ns_consumes_self", AT_ns_consumes_self)
110    .Case("ns_returns_autoreleased", AT_ns_returns_autoreleased)
111    .Case("ns_returns_not_retained", AT_ns_returns_not_retained)
112    .Case("ns_returns_retained", AT_ns_returns_retained)
113    .Case("cf_consumed", AT_cf_consumed)
114    .Case("cf_returns_not_retained", AT_cf_returns_not_retained)
115    .Case("cf_returns_retained", AT_cf_returns_retained)
116    .Case("ownership_returns", AT_ownership_returns)
117    .Case("ownership_holds", AT_ownership_holds)
118    .Case("ownership_takes", AT_ownership_takes)
119    .Case("reqd_work_group_size", AT_reqd_wg_size)
120    .Case("init_priority", AT_init_priority)
121    .Case("no_instrument_function", AT_no_instrument_function)
122    .Case("thiscall", AT_thiscall)
123    .Case("bounded", IgnoredAttribute)       // OpenBSD
124    .Case("pascal", AT_pascal)
125    .Case("__cdecl", AT_cdecl)
126    .Case("__stdcall", AT_stdcall)
127    .Case("__fastcall", AT_fastcall)
128    .Case("__thiscall", AT_thiscall)
129    .Case("__pascal", AT_pascal)
130    .Case("constant", AT_constant)
131    .Case("device", AT_device)
132    .Case("global", AT_global)
133    .Case("host", AT_host)
134    .Case("shared", AT_shared)
135    .Case("launch_bounds", AT_launch_bounds)
136    .Case("common", AT_common)
137    .Case("nocommon", AT_nocommon)
138    .Case("opencl_kernel_function", AT_opencl_kernel_function)
139    .Case("uuid", AT_uuid)
140    .Default(UnknownAttribute);
141}
142