2009-06-02 17:58:47 +00:00
|
|
|
//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the AttributeList class implementation
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Parse/AttributeList.h"
|
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2009-11-04 15:04:32 +00:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2009-06-02 17:58:47 +00:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
|
2009-12-01 11:08:04 +00:00
|
|
|
IdentifierInfo *sName, SourceLocation sLoc,
|
2009-06-02 17:58:47 +00:00
|
|
|
IdentifierInfo *pName, SourceLocation pLoc,
|
|
|
|
ActionBase::ExprTy **ExprList, unsigned numArgs,
|
2009-12-01 11:08:04 +00:00
|
|
|
AttributeList *n, bool declspec, bool cxx0x)
|
|
|
|
: AttrName(aName), AttrLoc(aLoc), ScopeName(sName), ScopeLoc(sLoc),
|
|
|
|
ParmName(pName), ParmLoc(pLoc), NumArgs(numArgs), Next(n),
|
2010-05-04 16:12:48 +00:00
|
|
|
DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false) {
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
if (numArgs == 0)
|
|
|
|
Args = 0;
|
|
|
|
else {
|
|
|
|
Args = new ActionBase::ExprTy*[numArgs];
|
|
|
|
memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeList::~AttributeList() {
|
|
|
|
if (Args) {
|
2009-10-14 18:03:49 +00:00
|
|
|
// FIXME: before we delete the vector, we need to make sure the Expr's
|
2009-06-02 17:58:47 +00:00
|
|
|
// have been deleted. Since ActionBase::ExprTy is "void", we are dependent
|
|
|
|
// on the actions module for actually freeing the memory. The specific
|
2009-10-14 18:03:49 +00:00
|
|
|
// hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
|
|
|
|
// ParseField, ParseTag. Once these routines have freed the expression,
|
|
|
|
// they should zero out the Args slot (to indicate the memory has been
|
2009-06-02 17:58:47 +00:00
|
|
|
// freed). If any element of the vector is non-null, we should assert.
|
|
|
|
delete [] Args;
|
|
|
|
}
|
|
|
|
delete Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
|
2009-10-23 14:22:18 +00:00
|
|
|
llvm::StringRef AttrName = Name->getName();
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
// Normalize the attribute name, __foo__ becomes foo.
|
2009-10-23 14:22:18 +00:00
|
|
|
if (AttrName.startswith("__") && AttrName.endswith("__"))
|
|
|
|
AttrName = AttrName.substr(2, AttrName.size() - 4);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-11-04 15:04:32 +00:00
|
|
|
return llvm::StringSwitch<AttributeList::Kind>(AttrName)
|
|
|
|
.Case("weak", AT_weak)
|
2010-03-03 17:28:16 +00:00
|
|
|
.Case("weakref", AT_weakref)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("pure", AT_pure)
|
|
|
|
.Case("mode", AT_mode)
|
|
|
|
.Case("used", AT_used)
|
|
|
|
.Case("alias", AT_alias)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("align", AT_aligned)
|
|
|
|
.Case("final", AT_final)
|
2009-11-18 14:59:57 +00:00
|
|
|
.Case("cdecl", AT_cdecl)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("const", AT_const)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("blocks", AT_blocks)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("format", AT_format)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("hiding", AT_hiding)
|
|
|
|
.Case("malloc", AT_malloc)
|
|
|
|
.Case("packed", AT_packed)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("unused", AT_unused)
|
|
|
|
.Case("aligned", AT_aligned)
|
|
|
|
.Case("cleanup", AT_cleanup)
|
|
|
|
.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-03-03 17:28:16 +00:00
|
|
|
.Case("ibaction", AT_IBAction)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("iboutlet", AT_IBOutlet)
|
2010-05-27 15:17:06 +00:00
|
|
|
.Case("iboutletcollection", AT_IBOutletCollection)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("noreturn", AT_noreturn)
|
|
|
|
.Case("noinline", AT_noinline)
|
|
|
|
.Case("override", AT_override)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("sentinel", AT_sentinel)
|
|
|
|
.Case("NSObject", AT_nsobject)
|
|
|
|
.Case("dllimport", AT_dllimport)
|
|
|
|
.Case("dllexport", AT_dllexport)
|
|
|
|
.Case("may_alias", IgnoredAttribute) // FIXME: TBAA
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("base_check", AT_base_check)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("deprecated", AT_deprecated)
|
|
|
|
.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)
|
|
|
|
.Case("vector_size", AT_vector_size)
|
|
|
|
.Case("constructor", AT_constructor)
|
|
|
|
.Case("unavailable", AT_unavailable)
|
|
|
|
.Case("overloadable", AT_overloadable)
|
|
|
|
.Case("address_space", AT_address_space)
|
|
|
|
.Case("always_inline", AT_always_inline)
|
2010-05-04 16:12:48 +00:00
|
|
|
.Case("returns_twice", IgnoredAttribute)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("vec_type_hint", IgnoredAttribute)
|
|
|
|
.Case("objc_exception", AT_objc_exception)
|
|
|
|
.Case("ext_vector_type", AT_ext_vector_type)
|
|
|
|
.Case("transparent_union", AT_transparent_union)
|
|
|
|
.Case("analyzer_noreturn", AT_analyzer_noreturn)
|
|
|
|
.Case("warn_unused_result", AT_warn_unused_result)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("carries_dependency", AT_carries_dependency)
|
2010-03-03 17:28:16 +00:00
|
|
|
.Case("ns_returns_not_retained", AT_ns_returns_not_retained)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("ns_returns_retained", AT_ns_returns_retained)
|
2010-03-03 17:28:16 +00:00
|
|
|
.Case("cf_returns_not_retained", AT_cf_returns_not_retained)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("cf_returns_retained", AT_cf_returns_retained)
|
|
|
|
.Case("reqd_work_group_size", AT_reqd_wg_size)
|
2010-07-13 17:21:42 +00:00
|
|
|
.Case("init_priority", AT_init_priority)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("no_instrument_function", AT_no_instrument_function)
|
2010-05-27 15:17:06 +00:00
|
|
|
.Case("thiscall", AT_thiscall)
|
|
|
|
.Case("__cdecl", AT_cdecl)
|
|
|
|
.Case("__stdcall", AT_stdcall)
|
|
|
|
.Case("__fastcall", AT_fastcall)
|
|
|
|
.Case("__thiscall", AT_thiscall)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Default(UnknownAttribute);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|