1d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//===--- Attr.h - Classes for representing expressions ----------*- C++ -*-===//
2d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//
3d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//                     The LLVM Compiler Infrastructure
4d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//
5d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson// This file is distributed under the University of Illinois Open Source
6d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson// License. See LICENSE.TXT for details.
7d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//
8d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//===----------------------------------------------------------------------===//
9d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//
10d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//  This file defines the Attr interface and subclasses.
11d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//
12d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson//===----------------------------------------------------------------------===//
13d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson
1481226601148d7e7c187b96c6ef86e83df204f59fAnders Carlsson#ifndef LLVM_CLANG_AST_ATTR_H
1581226601148d7e7c187b96c6ef86e83df204f59fAnders Carlsson#define LLVM_CLANG_AST_ATTR_H
16d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson
179594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "clang/Basic/LLVM.h"
18387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt#include "clang/Basic/AttrKinds.h"
19a8fb24fa3151567056f6125999cea69e39604f35Fariborz Jahanian#include "clang/AST/Type.h"
20cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt#include "clang/Basic/SourceLocation.h"
210a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor#include "clang/Basic/VersionTuple.h"
229594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "llvm/ADT/SmallVector.h"
239594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "llvm/ADT/StringRef.h"
249594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "llvm/ADT/StringSwitch.h"
259fe8c74a93ac8e92512615c5f83e7a328b3b0544David Blaikie#include "llvm/Support/ErrorHandling.h"
26baa66fc389ca0a9f11e0c864304bcfd89de39439Anders Carlsson#include <cassert>
27ea7e97e14f2f1f9817d2ae8a25ec6ea652e5287fArgyrios Kyrtzidis#include <cstring>
28eb2b2a3f1898f146c6e153a64ec58ec5e1750bd2Ted Kremenek#include <algorithm>
29adf21bdb3d17acfdb74657fcbc5035a404c6c8f4Anders Carlsson
30d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlssonnamespace clang {
31cc5814732edc0c382d0136ab57ec6149566043e2Chris Lattner  class ASTContext;
32857e918a8a40deb128840308a318bf623d68295fTed Kremenek  class IdentifierInfo;
33857e918a8a40deb128840308a318bf623d68295fTed Kremenek  class ObjCInterfaceDecl;
344ced79f0971592e6e7122037de69ee9ae534ce72Chandler Carruth  class Expr;
35a8fb24fa3151567056f6125999cea69e39604f35Fariborz Jahanian  class QualType;
36cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  class FunctionDecl;
37cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  class TypeSourceInfo;
389f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor}
399f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor
409509108b3dde280dca1999b5c054f5b789581e68Chris Lattner// Defined in ASTContext.h
414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadvoid *operator new(size_t Bytes, const clang::ASTContext &C,
429f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor                   size_t Alignment = 16) throw ();
43cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt// FIXME: Being forced to not have a default argument here due to redeclaration
44cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt//        rules on default arguments sucks
454ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadvoid *operator new[](size_t Bytes, const clang::ASTContext &C,
46cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt                     size_t Alignment) throw ();
479f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor
489509108b3dde280dca1999b5c054f5b789581e68Chris Lattner// It is good practice to pair new/delete operators.  Also, MSVC gives many
499509108b3dde280dca1999b5c054f5b789581e68Chris Lattner// warnings if a matching delete overload is not declared, even though the
509509108b3dde280dca1999b5c054f5b789581e68Chris Lattner// throw() spec guarantees it will not be implicitly called.
514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadvoid operator delete(void *Ptr, const clang::ASTContext &C, size_t)
529509108b3dde280dca1999b5c054f5b789581e68Chris Lattner              throw ();
534ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadvoid operator delete[](void *Ptr, const clang::ASTContext &C, size_t)
54cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt              throw ();
559509108b3dde280dca1999b5c054f5b789581e68Chris Lattner
569f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregornamespace clang {
57d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson
58d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson/// Attr - This represents one attribute.
59d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlssonclass Attr {
60d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlssonprivate:
61ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  SourceRange Range;
62cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  unsigned AttrKind : 16;
632f402708e62f89fb875442802e3d3f20fc909d33Anton Korobeynikov
64d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlssonprotected:
65a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  bool Inherited : 1;
66a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne
671de22a26c0e126b08edb2eda9d9091c021d96dc6Douglas Gregor  virtual ~Attr();
681de22a26c0e126b08edb2eda9d9091c021d96dc6Douglas Gregor
690b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattner  void* operator new(size_t bytes) throw() {
70b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Attrs cannot be allocated with regular 'new'.");
710b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattner  }
720b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattner  void operator delete(void* data) throw() {
73b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Attrs cannot be released with regular 'delete'.");
740b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattner  }
751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntpublic:
77cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  // Forward so that the regular new and delete do not hide global ones.
78cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void* operator new(size_t Bytes, ASTContext &C,
79cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt                     size_t Alignment = 16) throw() {
80cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return ::operator new(Bytes, C, Alignment);
81cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  }
82cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void operator delete(void *Ptr, ASTContext &C,
83a87cdc03f4014545a8440110c1f4f68701100576Eli Friedman                       size_t Alignment) throw() {
84cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return ::operator delete(Ptr, C, Alignment);
85cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  }
86cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt
870b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattnerprotected:
88ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  Attr(attr::Kind AK, SourceRange R)
89ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis    : Range(R), AttrKind(AK), Inherited(false) {}
90cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt
91cc5814732edc0c382d0136ab57ec6149566043e2Chris Lattnerpublic:
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
93cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  attr::Kind getKind() const {
94cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return static_cast<attr::Kind>(AttrKind);
95d406bf0e8c17012110a8476d03c6f9a97b56ecf7Anders Carlsson  }
961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  SourceLocation getLocation() const { return Range.getBegin(); }
98ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  SourceRange getRange() const { return Range; }
99ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  void setRange(SourceRange R) { Range = R; }
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101192e7f7e7f0493f7cdfda1d752e6de340d4e3ffePeter Collingbourne  bool isInherited() const { return Inherited; }
102192e7f7e7f0493f7cdfda1d752e6de340d4e3ffePeter Collingbourne
1039f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor  // Clone this attribute.
1049f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor  virtual Attr* clone(ASTContext &C) const = 0;
1059f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor
106d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson  // Implement isa/cast/dyncast/etc.
107d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson  static bool classof(const Attr *) { return true; }
108d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson};
109387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt
110a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourneclass InheritableAttr : public Attr {
111a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourneprotected:
112768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis  InheritableAttr(attr::Kind AK, SourceRange R)
113768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis    : Attr(AK, R) {}
114a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne
115a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbournepublic:
116a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  void setInherited(bool I) { Inherited = I; }
117a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne
118a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  // Implement isa/cast/dyncast/etc.
119a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  static bool classof(const Attr *A) {
120a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne    return A->getKind() <= attr::LAST_INHERITABLE;
121a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  }
122a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  static bool classof(const InheritableAttr *) { return true; }
123a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne};
124a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne
125eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCallclass InheritableParamAttr : public InheritableAttr {
126eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCallprotected:
127768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis  InheritableParamAttr(attr::Kind AK, SourceRange R)
128768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis    : InheritableAttr(AK, R) {}
129eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall
130eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCallpublic:
131eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall  // Implement isa/cast/dyncast/etc.
132eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall  static bool classof(const Attr *A) {
133eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall    return A->getKind() <= attr::LAST_INHERITABLE_PARAM;
134eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall  }
135eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall  static bool classof(const InheritableParamAttr *) { return true; }
136eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall};
137eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall
138387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt#include "clang/AST/Attrs.inc"
1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
140cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// AttrVec - A vector of Attr, which is how they are stored on the AST.
141686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<Attr*, 2> AttrVec;
142686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<const Attr*, 2> ConstAttrVec;
143dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
144cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// DestroyAttrs - Destroy the contents of an AttrVec.
145cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline void DestroyAttrs (AttrVec& V, ASTContext &C) {
146cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
147dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
148cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// specific_attr_iterator - Iterates over a subrange of an AttrVec, only
149cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// providing attributes that are of a specifc type.
150cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename SpecificAttr>
151cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntclass specific_attr_iterator {
152cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// Current - The current, underlying iterator.
153cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// In order to ensure we don't dereference an invalid iterator unless
154cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// specifically requested, we don't necessarily advance this all the
155cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// way. Instead, we advance it when an operation is requested; if the
156cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// operation is acting on what should be a past-the-end iterator,
157cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// then we offer no guarantees, but this way we do not dererence a
158cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// past-the-end iterator when we move to a past-the-end position.
159cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  mutable AttrVec::const_iterator Current;
160dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
161cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void AdvanceToNext() const {
1629594675cc1eb52a054de13c4a21e466643847480Chris Lattner    while (!isa<SpecificAttr>(*Current))
163cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt      ++Current;
164dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
165dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
166cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void AdvanceToNext(AttrVec::const_iterator I) const {
1679594675cc1eb52a054de13c4a21e466643847480Chris Lattner    while (Current != I && !isa<SpecificAttr>(*Current))
168cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt      ++Current;
169dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
170dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
171dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenekpublic:
172cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef SpecificAttr*             value_type;
173cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef SpecificAttr*             reference;
174cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef SpecificAttr*             pointer;
175cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef std::forward_iterator_tag iterator_category;
176cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef std::ptrdiff_t            difference_type;
177dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
178cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator() : Current() { }
179cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  explicit specific_attr_iterator(AttrVec::const_iterator i) : Current(i) { }
180dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
181cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  reference operator*() const {
182cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    AdvanceToNext();
1839594675cc1eb52a054de13c4a21e466643847480Chris Lattner    return cast<SpecificAttr>(*Current);
184dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
185cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  pointer operator->() const {
186cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    AdvanceToNext();
1879594675cc1eb52a054de13c4a21e466643847480Chris Lattner    return cast<SpecificAttr>(*Current);
188dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
189dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
190cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator& operator++() {
191cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    ++Current;
192cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return *this;
193dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
194cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator operator++(int) {
195cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    specific_attr_iterator Tmp(*this);
196cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    ++(*this);
197cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return Tmp;
198dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
199dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
200cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  friend bool operator==(specific_attr_iterator Left,
201cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt                         specific_attr_iterator Right) {
202cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    if (Left.Current < Right.Current)
203cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt      Left.AdvanceToNext(Right.Current);
204cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    else
205cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt      Right.AdvanceToNext(Left.Current);
206cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return Left.Current == Right.Current;
207dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
208cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  friend bool operator!=(specific_attr_iterator Left,
209cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt                         specific_attr_iterator Right) {
210cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return !(Left == Right);
211dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
212dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek};
213dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
214cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename T>
215cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline specific_attr_iterator<T> specific_attr_begin(const AttrVec& vec) {
216cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  return specific_attr_iterator<T>(vec.begin());
217cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
218cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename T>
219cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline specific_attr_iterator<T> specific_attr_end(const AttrVec& vec) {
220cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  return specific_attr_iterator<T>(vec.end());
221cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
22282d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov
223cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename T>
224cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline bool hasSpecificAttr(const AttrVec& vec) {
225cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  return specific_attr_begin<T>(vec) != specific_attr_end<T>(vec);
226cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
227cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename T>
228cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline T *getSpecificAttr(const AttrVec& vec) {
229cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator<T> i = specific_attr_begin<T>(vec);
230cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  if (i != specific_attr_end<T>(vec))
231cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return *i;
232cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  else
233cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return 0;
234cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
2355a0164d6ab843ca61437ec59a504365cb1c98f43Charles Davis
236cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// getMaxAlignment - Returns the highest alignment value found among
237cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// AlignedAttrs in an AttrVec, or 0 if there are none.
238cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline unsigned getMaxAttrAlignment(const AttrVec& V, ASTContext &Ctx) {
239cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  unsigned Align = 0;
240cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator<AlignedAttr> i(V.begin()), e(V.end());
241cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  for(; i != e; ++i)
242cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    Align = std::max(Align, i->getAlignment(Ctx));
243cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  return Align;
244cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
2451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
246d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson}  // end namespace clang
247d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson
248d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson#endif
249