Attr.h revision 9fe8c74a93ac8e92512615c5f83e7a328b3b0544
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    return 0;
720b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattner  }
730b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattner  void operator delete(void* data) throw() {
74b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Attrs cannot be released with regular 'delete'.");
750b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattner  }
761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntpublic:
78cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  // Forward so that the regular new and delete do not hide global ones.
79cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void* operator new(size_t Bytes, ASTContext &C,
80cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt                     size_t Alignment = 16) throw() {
81cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return ::operator new(Bytes, C, Alignment);
82cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  }
83cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void operator delete(void *Ptr, ASTContext &C,
84a87cdc03f4014545a8440110c1f4f68701100576Eli Friedman                       size_t Alignment) throw() {
85cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return ::operator delete(Ptr, C, Alignment);
86cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  }
87cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt
880b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattnerprotected:
89ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  Attr(attr::Kind AK, SourceRange R)
90ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis    : Range(R), AttrKind(AK), Inherited(false) {}
91cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt
92cc5814732edc0c382d0136ab57ec6149566043e2Chris Lattnerpublic:
931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
94cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  attr::Kind getKind() const {
95cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return static_cast<attr::Kind>(AttrKind);
96d406bf0e8c17012110a8476d03c6f9a97b56ecf7Anders Carlsson  }
971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  SourceLocation getLocation() const { return Range.getBegin(); }
99ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  SourceRange getRange() const { return Range; }
100ffcc3105d223899740e79f3f8199f3881df4d1deArgyrios Kyrtzidis  void setRange(SourceRange R) { Range = R; }
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102192e7f7e7f0493f7cdfda1d752e6de340d4e3ffePeter Collingbourne  bool isInherited() const { return Inherited; }
103192e7f7e7f0493f7cdfda1d752e6de340d4e3ffePeter Collingbourne
1049f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor  // Clone this attribute.
1059f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor  virtual Attr* clone(ASTContext &C) const = 0;
1069f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor
107d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson  // Implement isa/cast/dyncast/etc.
108d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson  static bool classof(const Attr *) { return true; }
109d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson};
110387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt
111a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourneclass InheritableAttr : public Attr {
112a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourneprotected:
113768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis  InheritableAttr(attr::Kind AK, SourceRange R)
114768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis    : Attr(AK, R) {}
115a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne
116a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbournepublic:
117a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  void setInherited(bool I) { Inherited = I; }
118a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne
119a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  // Implement isa/cast/dyncast/etc.
120a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  static bool classof(const Attr *A) {
121a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne    return A->getKind() <= attr::LAST_INHERITABLE;
122a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  }
123a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne  static bool classof(const InheritableAttr *) { return true; }
124a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne};
125a97d70b7ea9633e8cbf976510d7a9ea66f4ac96cPeter Collingbourne
126eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCallclass InheritableParamAttr : public InheritableAttr {
127eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCallprotected:
128768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis  InheritableParamAttr(attr::Kind AK, SourceRange R)
129768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis    : InheritableAttr(AK, R) {}
130eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall
131eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCallpublic:
132eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall  // Implement isa/cast/dyncast/etc.
133eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall  static bool classof(const Attr *A) {
134eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall    return A->getKind() <= attr::LAST_INHERITABLE_PARAM;
135eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall  }
136eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall  static bool classof(const InheritableParamAttr *) { return true; }
137eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall};
138eca5d22c16eb784e5f35ca816fa22e0c0e060417John McCall
139387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt#include "clang/AST/Attrs.inc"
1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
141cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// AttrVec - A vector of Attr, which is how they are stored on the AST.
142686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<Attr*, 2> AttrVec;
143686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<const Attr*, 2> ConstAttrVec;
144dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
145cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// DestroyAttrs - Destroy the contents of an AttrVec.
146cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline void DestroyAttrs (AttrVec& V, ASTContext &C) {
147cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
148dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
149cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// specific_attr_iterator - Iterates over a subrange of an AttrVec, only
150cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// providing attributes that are of a specifc type.
151cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename SpecificAttr>
152cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntclass specific_attr_iterator {
153cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// Current - The current, underlying iterator.
154cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// In order to ensure we don't dereference an invalid iterator unless
155cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// specifically requested, we don't necessarily advance this all the
156cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// way. Instead, we advance it when an operation is requested; if the
157cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// operation is acting on what should be a past-the-end iterator,
158cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// then we offer no guarantees, but this way we do not dererence a
159cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  /// past-the-end iterator when we move to a past-the-end position.
160cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  mutable AttrVec::const_iterator Current;
161dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
162cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void AdvanceToNext() const {
1639594675cc1eb52a054de13c4a21e466643847480Chris Lattner    while (!isa<SpecificAttr>(*Current))
164cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt      ++Current;
165dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
166dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
167cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void AdvanceToNext(AttrVec::const_iterator I) const {
1689594675cc1eb52a054de13c4a21e466643847480Chris Lattner    while (Current != I && !isa<SpecificAttr>(*Current))
169cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt      ++Current;
170dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
171dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
172dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenekpublic:
173cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef SpecificAttr*             value_type;
174cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef SpecificAttr*             reference;
175cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef SpecificAttr*             pointer;
176cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef std::forward_iterator_tag iterator_category;
177cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  typedef std::ptrdiff_t            difference_type;
178dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
179cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator() : Current() { }
180cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  explicit specific_attr_iterator(AttrVec::const_iterator i) : Current(i) { }
181dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
182cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  reference operator*() const {
183cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    AdvanceToNext();
1849594675cc1eb52a054de13c4a21e466643847480Chris Lattner    return cast<SpecificAttr>(*Current);
185dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
186cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  pointer operator->() const {
187cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    AdvanceToNext();
1889594675cc1eb52a054de13c4a21e466643847480Chris Lattner    return cast<SpecificAttr>(*Current);
189dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
190dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
191cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator& operator++() {
192cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    ++Current;
193cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return *this;
194dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
195cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator operator++(int) {
196cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    specific_attr_iterator Tmp(*this);
197cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    ++(*this);
198cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return Tmp;
199dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
200dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
201cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  friend bool operator==(specific_attr_iterator Left,
202cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt                         specific_attr_iterator Right) {
203cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    if (Left.Current < Right.Current)
204cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt      Left.AdvanceToNext(Right.Current);
205cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    else
206cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt      Right.AdvanceToNext(Left.Current);
207cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return Left.Current == Right.Current;
208dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
209cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  friend bool operator!=(specific_attr_iterator Left,
210cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt                         specific_attr_iterator Right) {
211cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return !(Left == Right);
212dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek  }
213dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek};
214dd0e490c24aeade2c59ca4cae171199f6af9f02eTed Kremenek
215cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename T>
216cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline specific_attr_iterator<T> specific_attr_begin(const AttrVec& vec) {
217cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  return specific_attr_iterator<T>(vec.begin());
218cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
219cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename T>
220cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline specific_attr_iterator<T> specific_attr_end(const AttrVec& vec) {
221cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  return specific_attr_iterator<T>(vec.end());
222cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
22382d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov
224cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename T>
225cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline bool hasSpecificAttr(const AttrVec& vec) {
226cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  return specific_attr_begin<T>(vec) != specific_attr_end<T>(vec);
227cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
228cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunttemplate <typename T>
229cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline T *getSpecificAttr(const AttrVec& vec) {
230cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator<T> i = specific_attr_begin<T>(vec);
231cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  if (i != specific_attr_end<T>(vec))
232cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return *i;
233cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  else
234cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    return 0;
235cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
2365a0164d6ab843ca61437ec59a504365cb1c98f43Charles Davis
237cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// getMaxAlignment - Returns the highest alignment value found among
238cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt/// AlignedAttrs in an AttrVec, or 0 if there are none.
239cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Huntinline unsigned getMaxAttrAlignment(const AttrVec& V, ASTContext &Ctx) {
240cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  unsigned Align = 0;
241cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  specific_attr_iterator<AlignedAttr> i(V.begin()), e(V.end());
242cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  for(; i != e; ++i)
243cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt    Align = std::max(Align, i->getAlignment(Ctx));
244cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  return Align;
245cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt}
2461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
247d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson}  // end namespace clang
248d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson
249d429cd459aef723fa0e7a44ac957d4c2256e241cAnders Carlsson#endif
250