Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- AttributeList.cpp --------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the AttributeList class implementation |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Parse/AttributeList.h" |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 15 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringSwitch.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
| 19 | AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame^] | 20 | IdentifierInfo *sName, SourceLocation sLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | IdentifierInfo *pName, SourceLocation pLoc, |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 22 | ActionBase::ExprTy **ExprList, unsigned numArgs, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame^] | 23 | 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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 005b235 | 2009-02-19 06:25:12 +0000 | [diff] [blame] | 28 | if (numArgs == 0) |
| 29 | Args = 0; |
| 30 | else { |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 31 | Args = new ActionBase::ExprTy*[numArgs]; |
Chris Lattner | 005b235 | 2009-02-19 06:25:12 +0000 | [diff] [blame] | 32 | memcpy(Args, ExprList, numArgs*sizeof(Args[0])); |
| 33 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 34 | } |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 35 | |
| 36 | AttributeList::~AttributeList() { |
| 37 | if (Args) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | // FIXME: before we delete the vector, we need to make sure the Expr's |
Chris Lattner | 8f823d2 | 2009-04-11 18:48:18 +0000 | [diff] [blame] | 39 | // have been deleted. Since ActionBase::ExprTy is "void", we are dependent |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 40 | // on the actions module for actually freeing the memory. The specific |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | // 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 Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 44 | // freed). If any element of the vector is non-null, we should assert. |
| 45 | delete [] Args; |
| 46 | } |
| 47 | delete Next; |
| 48 | } |
| 49 | |
| 50 | AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 51 | llvm::StringRef AttrName = Name->getName(); |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 52 | |
| 53 | // Normalize the attribute name, __foo__ becomes foo. |
Daniel Dunbar | 4f90d8d | 2009-10-17 18:12:29 +0000 | [diff] [blame] | 54 | if (AttrName.startswith("__") && AttrName.endswith("__")) |
| 55 | AttrName = AttrName.substr(2, AttrName.size() - 4); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | |
Daniel Dunbar | 3068ae0 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 57 | // FIXME: Hand generating this is neither smart nor efficient. |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 58 | 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 Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame^] | 64 | .Case("align", AT_aligned) |
| 65 | .Case("final", AT_final) |
Eli Friedman | 8f4c59e | 2009-11-09 18:38:53 +0000 | [diff] [blame] | 66 | .Case("cdecl", AT_cdecl) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 67 | .Case("const", AT_const) |
| 68 | .Case("packed", AT_packed) |
| 69 | .Case("malloc", AT_malloc) |
| 70 | .Case("format", AT_format) |
| 71 | .Case("unused", AT_unused) |
| 72 | .Case("blocks", AT_blocks) |
| 73 | .Case("aligned", AT_aligned) |
| 74 | .Case("cleanup", AT_cleanup) |
| 75 | .Case("nodebug", AT_nodebug) |
| 76 | .Case("nonnull", AT_nonnull) |
| 77 | .Case("nothrow", AT_nothrow) |
| 78 | .Case("objc_gc", AT_objc_gc) |
| 79 | .Case("regparm", AT_regparm) |
| 80 | .Case("section", AT_section) |
| 81 | .Case("stdcall", AT_stdcall) |
| 82 | .Case("annotate", AT_annotate) |
| 83 | .Case("noreturn", AT_noreturn) |
| 84 | .Case("noinline", AT_noinline) |
| 85 | .Case("fastcall", AT_fastcall) |
| 86 | .Case("iboutlet", AT_IBOutlet) |
| 87 | .Case("sentinel", AT_sentinel) |
| 88 | .Case("NSObject", AT_nsobject) |
| 89 | .Case("dllimport", AT_dllimport) |
| 90 | .Case("dllexport", AT_dllexport) |
| 91 | .Case("may_alias", IgnoredAttribute) // FIXME: TBAA |
| 92 | .Case("deprecated", AT_deprecated) |
| 93 | .Case("visibility", AT_visibility) |
| 94 | .Case("destructor", AT_destructor) |
| 95 | .Case("format_arg", AT_format_arg) |
| 96 | .Case("gnu_inline", AT_gnu_inline) |
| 97 | .Case("weak_import", AT_weak_import) |
| 98 | .Case("vector_size", AT_vector_size) |
| 99 | .Case("constructor", AT_constructor) |
| 100 | .Case("unavailable", AT_unavailable) |
| 101 | .Case("overloadable", AT_overloadable) |
| 102 | .Case("address_space", AT_address_space) |
| 103 | .Case("always_inline", AT_always_inline) |
| 104 | .Case("vec_type_hint", IgnoredAttribute) |
| 105 | .Case("objc_exception", AT_objc_exception) |
| 106 | .Case("ext_vector_type", AT_ext_vector_type) |
| 107 | .Case("transparent_union", AT_transparent_union) |
| 108 | .Case("analyzer_noreturn", AT_analyzer_noreturn) |
| 109 | .Case("warn_unused_result", AT_warn_unused_result) |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame^] | 110 | .Case("carries_dependency", AT_carries_dependency) |
Douglas Gregor | fc3bb49 | 2009-10-29 05:26:58 +0000 | [diff] [blame] | 111 | .Case("ns_returns_retained", AT_ns_returns_retained) |
| 112 | .Case("cf_returns_retained", AT_cf_returns_retained) |
| 113 | .Case("reqd_work_group_size", AT_reqd_wg_size) |
| 114 | .Case("no_instrument_function", AT_no_instrument_function) |
| 115 | .Default(UnknownAttribute); |
Chris Lattner | 2335191 | 2008-02-20 23:14:47 +0000 | [diff] [blame] | 116 | } |