2007-06-09 11:39:29 +08:00
|
|
|
//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-09 11:39:29 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the AttributeList class implementation
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-08-21 02:27:03 +08:00
|
|
|
#include "clang/Sema/AttributeList.h"
|
2009-04-12 02:48:18 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2009-10-29 13:26:58 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2007-06-09 11:39:29 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2010-11-10 13:59:39 +08:00
|
|
|
AttributeList::AttributeList(llvm::BumpPtrAllocator &Alloc,
|
|
|
|
IdentifierInfo *aName, SourceLocation aLoc,
|
2009-11-21 16:43:09 +08:00
|
|
|
IdentifierInfo *sName, SourceLocation sLoc,
|
2007-06-09 11:39:29 +08:00
|
|
|
IdentifierInfo *pName, SourceLocation pLoc,
|
2010-08-24 13:47:05 +08:00
|
|
|
Expr **ExprList, unsigned numArgs,
|
2010-12-24 10:08:15 +08:00
|
|
|
bool declspec, bool cxx0x)
|
2010-11-10 13:59:39 +08:00
|
|
|
: AttrName(aName), AttrLoc(aLoc), ScopeName(sName),
|
|
|
|
ScopeLoc(sLoc),
|
2010-12-24 10:08:15 +08:00
|
|
|
ParmName(pName), ParmLoc(pLoc), NumArgs(numArgs), Next(0),
|
2010-04-30 21:10:51 +08:00
|
|
|
DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-19 14:25:12 +08:00
|
|
|
if (numArgs == 0)
|
|
|
|
Args = 0;
|
|
|
|
else {
|
2010-11-10 13:59:39 +08:00
|
|
|
// Allocate the Args array using the BumpPtrAllocator.
|
|
|
|
Args = Alloc.Allocate<Expr*>(numArgs);
|
2009-02-19 14:25:12 +08:00
|
|
|
memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
|
|
|
|
}
|
2007-06-09 11:39:29 +08:00
|
|
|
}
|
2008-02-21 07:14:47 +08:00
|
|
|
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
AttributeList::AttributeList(llvm::BumpPtrAllocator &Alloc,
|
|
|
|
IdentifierInfo *AttrName, SourceLocation AttrLoc,
|
|
|
|
IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
|
|
|
|
IdentifierInfo *ParmName, SourceLocation ParmLoc,
|
|
|
|
const AvailabilityChange &Introduced,
|
|
|
|
const AvailabilityChange &Deprecated,
|
|
|
|
const AvailabilityChange &Obsoleted,
|
|
|
|
bool declspec, bool cxx0x)
|
|
|
|
: AttrName(AttrName), AttrLoc(AttrLoc), ScopeName(ScopeName),
|
|
|
|
ScopeLoc(ScopeLoc), ParmName(ParmName), ParmLoc(ParmLoc),
|
|
|
|
Args(0), NumArgs(0), Next(0),
|
|
|
|
DeclspecAttribute(declspec), CXX0XAttribute(cxx0x),
|
|
|
|
AvailabilityIntroduced(Introduced),
|
|
|
|
AvailabilityDeprecated(Deprecated),
|
|
|
|
AvailabilityObsoleted(Obsoleted),
|
|
|
|
Invalid(false) {
|
|
|
|
}
|
|
|
|
|
2008-02-21 07:14:47 +08:00
|
|
|
AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
|
2009-10-19 05:17:35 +08:00
|
|
|
llvm::StringRef AttrName = Name->getName();
|
2008-02-21 07:14:47 +08:00
|
|
|
|
|
|
|
// Normalize the attribute name, __foo__ becomes foo.
|
2009-10-18 02:12:29 +08:00
|
|
|
if (AttrName.startswith("__") && AttrName.endswith("__"))
|
|
|
|
AttrName = AttrName.substr(2, AttrName.size() - 4);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-10-29 13:26:58 +08:00
|
|
|
return llvm::StringSwitch<AttributeList::Kind>(AttrName)
|
|
|
|
.Case("weak", AT_weak)
|
2010-02-24 06:00:30 +08:00
|
|
|
.Case("weakref", AT_weakref)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("pure", AT_pure)
|
|
|
|
.Case("mode", AT_mode)
|
|
|
|
.Case("used", AT_used)
|
|
|
|
.Case("alias", AT_alias)
|
2009-11-21 16:43:09 +08:00
|
|
|
.Case("align", AT_aligned)
|
2009-11-10 02:38:53 +08:00
|
|
|
.Case("cdecl", AT_cdecl)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("const", AT_const)
|
2010-10-15 16:26:25 +08:00
|
|
|
.Case("__const", AT_const) // some GCC headers do contain this spelling
|
2009-11-25 12:20:27 +08:00
|
|
|
.Case("blocks", AT_blocks)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("format", AT_format)
|
2009-11-25 12:20:27 +08:00
|
|
|
.Case("malloc", AT_malloc)
|
|
|
|
.Case("packed", AT_packed)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("unused", AT_unused)
|
|
|
|
.Case("aligned", AT_aligned)
|
|
|
|
.Case("cleanup", AT_cleanup)
|
2010-09-30 02:20:25 +08:00
|
|
|
.Case("naked", AT_naked)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("nodebug", AT_nodebug)
|
|
|
|
.Case("nonnull", AT_nonnull)
|
|
|
|
.Case("nothrow", AT_nothrow)
|
|
|
|
.Case("objc_gc", AT_objc_gc)
|
|
|
|
.Case("regparm", AT_regparm)
|
|
|
|
.Case("section", AT_section)
|
|
|
|
.Case("stdcall", AT_stdcall)
|
|
|
|
.Case("annotate", AT_annotate)
|
|
|
|
.Case("fastcall", AT_fastcall)
|
2010-02-17 10:37:45 +08:00
|
|
|
.Case("ibaction", AT_IBAction)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("iboutlet", AT_IBOutlet)
|
2010-05-20 01:38:06 +08:00
|
|
|
.Case("iboutletcollection", AT_IBOutletCollection)
|
2009-11-25 12:20:27 +08:00
|
|
|
.Case("noreturn", AT_noreturn)
|
|
|
|
.Case("noinline", AT_noinline)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("sentinel", AT_sentinel)
|
|
|
|
.Case("NSObject", AT_nsobject)
|
|
|
|
.Case("dllimport", AT_dllimport)
|
|
|
|
.Case("dllexport", AT_dllexport)
|
2010-11-17 08:03:07 +08:00
|
|
|
.Case("may_alias", AT_may_alias)
|
2009-11-25 12:20:27 +08:00
|
|
|
.Case("base_check", AT_base_check)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("deprecated", AT_deprecated)
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
.Case("availability", AT_availability)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("visibility", AT_visibility)
|
|
|
|
.Case("destructor", AT_destructor)
|
|
|
|
.Case("format_arg", AT_format_arg)
|
|
|
|
.Case("gnu_inline", AT_gnu_inline)
|
|
|
|
.Case("weak_import", AT_weak_import)
|
2010-08-10 05:53:52 +08:00
|
|
|
.Case("vecreturn", AT_vecreturn)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("vector_size", AT_vector_size)
|
|
|
|
.Case("constructor", AT_constructor)
|
|
|
|
.Case("unavailable", AT_unavailable)
|
|
|
|
.Case("overloadable", AT_overloadable)
|
|
|
|
.Case("address_space", AT_address_space)
|
2011-03-19 06:38:29 +08:00
|
|
|
.Case("opencl_image_access", AT_opencl_image_access)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("always_inline", AT_always_inline)
|
2010-04-12 10:18:49 +08:00
|
|
|
.Case("returns_twice", IgnoredAttribute)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("vec_type_hint", IgnoredAttribute)
|
|
|
|
.Case("objc_exception", AT_objc_exception)
|
2011-03-02 19:33:24 +08:00
|
|
|
.Case("objc_method_family", AT_objc_method_family)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("ext_vector_type", AT_ext_vector_type)
|
2010-11-16 08:32:24 +08:00
|
|
|
.Case("neon_vector_type", AT_neon_vector_type)
|
|
|
|
.Case("neon_polyvector_type", AT_neon_polyvector_type)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("transparent_union", AT_transparent_union)
|
|
|
|
.Case("analyzer_noreturn", AT_analyzer_noreturn)
|
|
|
|
.Case("warn_unused_result", AT_warn_unused_result)
|
2009-11-21 16:43:09 +08:00
|
|
|
.Case("carries_dependency", AT_carries_dependency)
|
2011-01-25 11:31:58 +08:00
|
|
|
.Case("ns_consumed", AT_ns_consumed)
|
|
|
|
.Case("ns_consumes_self", AT_ns_consumes_self)
|
|
|
|
.Case("ns_returns_autoreleased", AT_ns_returns_autoreleased)
|
2010-02-18 08:05:45 +08:00
|
|
|
.Case("ns_returns_not_retained", AT_ns_returns_not_retained)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("ns_returns_retained", AT_ns_returns_retained)
|
2011-01-25 11:31:58 +08:00
|
|
|
.Case("cf_consumed", AT_cf_consumed)
|
2010-02-18 08:05:45 +08:00
|
|
|
.Case("cf_returns_not_retained", AT_cf_returns_not_retained)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("cf_returns_retained", AT_cf_returns_retained)
|
2010-07-31 09:52:11 +08:00
|
|
|
.Case("ownership_returns", AT_ownership_returns)
|
|
|
|
.Case("ownership_holds", AT_ownership_holds)
|
|
|
|
.Case("ownership_takes", AT_ownership_takes)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("reqd_work_group_size", AT_reqd_wg_size)
|
2010-06-19 05:44:06 +08:00
|
|
|
.Case("init_priority", AT_init_priority)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Case("no_instrument_function", AT_no_instrument_function)
|
2010-05-19 00:57:00 +08:00
|
|
|
.Case("thiscall", AT_thiscall)
|
2011-02-19 01:05:55 +08:00
|
|
|
.Case("bounded", IgnoredAttribute) // OpenBSD
|
2010-09-03 09:29:35 +08:00
|
|
|
.Case("pascal", AT_pascal)
|
2010-05-19 00:57:00 +08:00
|
|
|
.Case("__cdecl", AT_cdecl)
|
|
|
|
.Case("__stdcall", AT_stdcall)
|
|
|
|
.Case("__fastcall", AT_fastcall)
|
|
|
|
.Case("__thiscall", AT_thiscall)
|
2010-09-03 09:29:35 +08:00
|
|
|
.Case("__pascal", AT_pascal)
|
2010-12-01 11:15:31 +08:00
|
|
|
.Case("constant", AT_constant)
|
|
|
|
.Case("device", AT_device)
|
|
|
|
.Case("global", AT_global)
|
|
|
|
.Case("host", AT_host)
|
|
|
|
.Case("shared", AT_shared)
|
2010-12-13 07:03:07 +08:00
|
|
|
.Case("launch_bounds", AT_launch_bounds)
|
2010-12-02 10:45:55 +08:00
|
|
|
.Case("common", AT_common)
|
|
|
|
.Case("nocommon", AT_nocommon)
|
2011-02-14 09:42:53 +08:00
|
|
|
.Case("opencl_kernel_function", AT_opencl_kernel_function)
|
2010-12-19 14:50:37 +08:00
|
|
|
.Case("uuid", AT_uuid)
|
2009-10-29 13:26:58 +08:00
|
|
|
.Default(UnknownAttribute);
|
2008-02-21 07:14:47 +08:00
|
|
|
}
|