119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall//===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 94ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// 104ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \file 114ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief This file defines the classes used to store parsed information about 124ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// declaration-specifiers and declarators. 134ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// 144ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \verbatim 154ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// static const int volatile x, *y, *(*(*z)[10])(const void *x); 164ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// ------------------------- - -- --------------------------- 174ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// declaration-specifiers \ | / 184ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// declarators 194ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \endverbatim 204ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2319510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#ifndef LLVM_CLANG_SEMA_DECLSPEC_H 2419510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#define LLVM_CLANG_SEMA_DECLSPEC_H 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 265f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 278b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl#include "clang/Basic/ExceptionSpecificationType.h" 2801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/Lambda.h" 298f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner#include "clang/Basic/OperatorKinds.h" 30ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor#include "clang/Basic/Specifiers.h" 3130a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Lex/Token.h" 3230a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Sema/AttributeList.h" 3330a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Sema/Ownership.h" 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 35aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 36075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara#include "llvm/Support/ErrorHandling.h" 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 392e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor class ASTContext; 402e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor class TypeLoc; 4143af76e845c95be160c088ec11ba3c43e2527fa8Sebastian Redl class LangOptions; 42d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie class DiagnosticsEngine; 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class IdentifierInfo; 4414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor class NamespaceAliasDecl; 452e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor class NamespaceDecl; 46ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall class NestedNameSpecifier; 47c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor class NestedNameSpecifierLoc; 48f85e193739c953358c865005855253af4f68a497John McCall class ObjCDeclSpec; 498f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner class Preprocessor; 50b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne class Sema; 518f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner class Declarator; 52314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor struct TemplateIdAnnotation; 53595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin 544ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief Represents a C++ nested-name-specifier or a global scope specifier. 554ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// 564ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// These can be in 3 states: 57595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 1) Not present, identified by isEmpty() 58595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 2) Present, identified by isNotEmpty() 59595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 2.a) Valid, idenified by isValid() 60595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 2.b) Invalid, identified by isInvalid(). 61595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 62595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// isSet() is deprecated because it mostly corresponded to "valid" but was 63595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// often used as if it meant "present". 64595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 65595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// The actual scope is described by getScopeRep(). 66aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCallclass CXXScopeSpec { 675f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor SourceRange Range; 685f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor NestedNameSpecifierLocBuilder Builder; 69aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 70c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregorpublic: 71aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall const SourceRange &getRange() const { return Range; } 72aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall void setRange(const SourceRange &R) { Range = R; } 73aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); } 74aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); } 75aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall SourceLocation getBeginLoc() const { return Range.getBegin(); } 76aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall SourceLocation getEndLoc() const { return Range.getEnd(); } 77aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 785f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor /// \brief Retrieve the representation of the nested-name-specifier. 795f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor NestedNameSpecifier *getScopeRep() const { 805f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor return Builder.getRepresentation(); 815f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor } 82aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 832e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \brief Extend the current nested-name-specifier by another 842e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// nested-name-specifier component of the form 'type::'. 852e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 862e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param Context The AST context in which this nested-name-specifier 872e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// resides. 882e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 892e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param TemplateKWLoc The location of the 'template' keyword, if present. 902e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 912e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param TL The TypeLoc that describes the type preceding the '::'. 922e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 932e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param ColonColonLoc The location of the trailing '::'. 942e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, 952e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor SourceLocation ColonColonLoc); 962e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor 972e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \brief Extend the current nested-name-specifier by another 982e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// nested-name-specifier component of the form 'identifier::'. 992e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 1002e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param Context The AST context in which this nested-name-specifier 1012e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// resides. 1022e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 1032e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param Identifier The identifier. 1042e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 1052e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param IdentifierLoc The location of the identifier. 1062e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 1072e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param ColonColonLoc The location of the trailing '::'. 1082e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor void Extend(ASTContext &Context, IdentifierInfo *Identifier, 1092e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor SourceLocation IdentifierLoc, SourceLocation ColonColonLoc); 1102e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor 1112e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \brief Extend the current nested-name-specifier by another 11214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// nested-name-specifier component of the form 'namespace::'. 1132e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 1142e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param Context The AST context in which this nested-name-specifier 1152e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// resides. 1162e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 1172e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param Namespace The namespace. 1182e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 11914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// \param NamespaceLoc The location of the namespace name. 1202e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// 1212e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \param ColonColonLoc The location of the trailing '::'. 1222e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor void Extend(ASTContext &Context, NamespaceDecl *Namespace, 1232e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor SourceLocation NamespaceLoc, SourceLocation ColonColonLoc); 1242e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor 12514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// \brief Extend the current nested-name-specifier by another 12614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// nested-name-specifier component of the form 'namespace-alias::'. 12714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// 12814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// \param Context The AST context in which this nested-name-specifier 12914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// resides. 13014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// 13114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// \param Alias The namespace alias. 13214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// 13314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// \param AliasLoc The location of the namespace alias 13414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// name. 13514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// 13614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// \param ColonColonLoc The location of the trailing '::'. 13714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor void Extend(ASTContext &Context, NamespaceAliasDecl *Alias, 13814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor SourceLocation AliasLoc, SourceLocation ColonColonLoc); 13914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 1402e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \brief Turn this (empty) nested-name-specifier into the global 1412e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// nested-name-specifier '::'. 1422e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc); 1432e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor 144c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// \brief Make a new nested-name-specifier from incomplete source-location 145c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// information. 146c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// 147c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// FIXME: This routine should be used very, very rarely, in cases where we 148c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// need to synthesize a nested-name-specifier. Most code should instead use 149c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// \c Adopt() with a proper \c NestedNameSpecifierLoc. 150c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, 151c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor SourceRange R); 152c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor 153c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// \brief Adopt an existing nested-name-specifier (with source-range 154c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// information). 155c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor void Adopt(NestedNameSpecifierLoc Other); 1569ddba32f25c0315cd3a6c7b63e0275b27cc1d973Douglas Gregor 157c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// \brief Retrieve a nested-name-specifier with location information, copied 158c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// into the given AST context. 159c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// 160c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// \param Context The context into which this nested-name-specifier will be 161c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// copied. 162c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const; 163c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor 1649dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall /// \brief Retrieve the location of the name in the last qualifier 1654ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// in this nested name specifier. 1664ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// 1674ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// For example, the location of \c bar 1684ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// in 1694ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \verbatim 1704ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \::foo::bar<0>:: 1714ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// ^~~ 1724ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \endverbatim 1739dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall SourceLocation getLastQualifierNameLoc() const; 1749dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall 175595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// No scope specifier. 176aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall bool isEmpty() const { return !Range.isValid(); } 177595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// A scope specifier is present, but may be valid or invalid. 178aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall bool isNotEmpty() const { return !isEmpty(); } 179aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 180fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// An error occurred during parsing of the scope specifier. 1816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isInvalid() const { return isNotEmpty() && getScopeRep() == nullptr; } 182595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// A scope specifier is present, and it refers to a real scope. 1836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isValid() const { return isNotEmpty() && getScopeRep() != nullptr; } 184aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 1852e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /// \brief Indicate that this nested-name-specifier is invalid. 1862e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor void SetInvalid(SourceRange R) { 1872e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor assert(R.isValid() && "Must have a valid source range"); 1882e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor if (Range.getBegin().isInvalid()) 1892e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor Range.setBegin(R.getBegin()); 1902e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor Range.setEnd(R.getEnd()); 1915f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor Builder.Clear(); 1922e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor } 1932e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor 194595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// Deprecated. Some call sites intend isNotEmpty() while others intend 195595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// isValid(). 1966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isSet() const { return getScopeRep() != nullptr; } 197aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 198aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall void clear() { 199aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall Range = SourceRange(); 2005f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor Builder.Clear(); 201aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall } 202c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor 203c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// \brief Retrieve the data associated with the source-location information. 2045f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor char *location_data() const { return Builder.getBuffer().first; } 205c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor 206c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// \brief Retrieve the size of the data associated with source-location 207c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor /// information. 2085f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor unsigned location_size() const { return Builder.getBuffer().second; } 209aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall}; 210aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 2114ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief Captures information about "declaration specifiers". 2124ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// 2134ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// "Declaration specifiers" encompasses storage-class-specifiers, 2144ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// type-specifiers, type-qualifiers, and function-specifiers. 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclSpec { 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2174ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief storage-class-specifier 2184ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \note The order of these enumerators is important for diagnostics. 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum SCS { 220160b5630aa781ac348303e1ae088d27016637778Douglas Gregor SCS_unspecified = 0, 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_typedef, 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_extern, 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_static, 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_auto, 225d6326c6fe586ba178734c49ba33a2c1af021822cSteve Naroff SCS_register, 226669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl SCS_private_extern, 227669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl SCS_mutable 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 229dc17384581e37436582a007be4d9185bcf7003ecEnea Zaffanella 230dc17384581e37436582a007be4d9185bcf7003ecEnea Zaffanella // Import thread storage class specifier enumeration and constants. 231dc17384581e37436582a007be4d9185bcf7003ecEnea Zaffanella // These can be combined with SCS_extern and SCS_static. 232dc17384581e37436582a007be4d9185bcf7003ecEnea Zaffanella typedef ThreadStorageClassSpecifier TSCS; 233dc17384581e37436582a007be4d9185bcf7003ecEnea Zaffanella static const TSCS TSCS_unspecified = clang::TSCS_unspecified; 234dc17384581e37436582a007be4d9185bcf7003ecEnea Zaffanella static const TSCS TSCS___thread = clang::TSCS___thread; 235dc17384581e37436582a007be4d9185bcf7003ecEnea Zaffanella static const TSCS TSCS_thread_local = clang::TSCS_thread_local; 236dc17384581e37436582a007be4d9185bcf7003ecEnea Zaffanella static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local; 2371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 238ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Import type specifier width enumeration and constants. 239ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor typedef TypeSpecifierWidth TSW; 240ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSW TSW_unspecified = clang::TSW_unspecified; 241ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSW TSW_short = clang::TSW_short; 242ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSW TSW_long = clang::TSW_long; 243ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSW TSW_longlong = clang::TSW_longlong; 244ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TSC { 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TSC_unspecified, 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TSC_imaginary, 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TSC_complex 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 251ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Import type specifier sign enumeration and constants. 252ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor typedef TypeSpecifierSign TSS; 253ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSS TSS_unspecified = clang::TSS_unspecified; 254ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSS TSS_signed = clang::TSS_signed; 255ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSS TSS_unsigned = clang::TSS_unsigned; 256ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 257ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Import type specifier type enumeration and constants. 258ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor typedef TypeSpecifierType TST; 259ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_unspecified = clang::TST_unspecified; 260ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_void = clang::TST_void; 261ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_char = clang::TST_char; 262ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_wchar = clang::TST_wchar; 263ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_char16 = clang::TST_char16; 264ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_char32 = clang::TST_char32; 265ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_int = clang::TST_int; 2665a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith static const TST TST_int128 = clang::TST_int128; 267aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov static const TST TST_half = clang::TST_half; 268ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_float = clang::TST_float; 269ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_double = clang::TST_double; 270ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_bool = clang::TST_bool; 271ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_decimal32 = clang::TST_decimal32; 272ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_decimal64 = clang::TST_decimal64; 273ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_decimal128 = clang::TST_decimal128; 274ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_enum = clang::TST_enum; 275ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_union = clang::TST_union; 276ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_struct = clang::TST_struct; 2776666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos static const TST TST_interface = clang::TST_interface; 278ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_class = clang::TST_class; 279ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_typename = clang::TST_typename; 280ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_typeofType = clang::TST_typeofType; 281ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_typeofExpr = clang::TST_typeofExpr; 282ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_decltype = clang::TST_decltype; 283a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith static const TST TST_decltype_auto = clang::TST_decltype_auto; 284ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt static const TST TST_underlyingType = clang::TST_underlyingType; 285ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_auto = clang::TST_auto; 286a5fc472b353b88be3b4981da946fb01f5a5cc0c6John McCall static const TST TST_unknown_anytype = clang::TST_unknown_anytype; 287b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman static const TST TST_atomic = clang::TST_atomic; 288ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_error = clang::TST_error; 2891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-qualifiers 2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ. 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TQ_unspecified = 0, 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TQ_const = 1, 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TQ_restrict = 2, 2954cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith TQ_volatile = 4, 2964cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith // This has no corresponding Qualifiers::TQ value, because it's not treated 2974cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith // as a qualifier in our type system. 2984cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith TQ_atomic = 8 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParsedSpecifiers - Flags to query which specifiers were applied. This is 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned by getParsedSpecifiers. 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParsedSpecifiers { 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_None = 0, 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_StorageClassSpecifier = 1, 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_TypeSpecifier = 2, 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_TypeQualifier = 4, 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_FunctionSpecifier = 8 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 3101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // storage-class-specifier 3132efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner /*SCS*/unsigned StorageClassSpec : 3; 314ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith /*TSCS*/unsigned ThreadStorageClassSpec : 2; 3157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned SCS_extern_in_linkage_spec : 1; 3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-specifier 3182efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner /*TSW*/unsigned TypeSpecWidth : 2; 3192efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner /*TSC*/unsigned TypeSpecComplex : 2; 3202efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner /*TSS*/unsigned TypeSpecSign : 2; 321b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei /*TST*/unsigned TypeSpecType : 6; 3227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned TypeAltiVecVector : 1; 3237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned TypeAltiVecPixel : 1; 3247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned TypeAltiVecBool : 1; 3257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned TypeSpecOwned : 1; 326402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-qualifiers 3284cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith unsigned TypeQualifiers : 4; // Bitwise OR of TQ. 3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // function-specifier 3317f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned FS_inline_specified : 1; 332d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov unsigned FS_forceinline_specified: 1; 3337f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned FS_virtual_specified : 1; 3347f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned FS_explicit_specified : 1; 335de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith unsigned FS_noreturn_specified : 1; 3361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 337f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson // friend-specifier 3387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned Friend_specified : 1; 3391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3402ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl // constexpr-specifier 3417f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned Constexpr_specified : 1; 3422ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl 343b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall union { 344b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall UnionParsedType TypeRep; 345b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Decl *DeclRep; 346b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *ExprRep; 347b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall }; 3481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // attributes. 3507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes Attrs; 3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 352aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall // Scope specifier for the type spec, if applicable. 353aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall CXXScopeSpec TypeScope; 354aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // List of protocol qualifiers for objective-c classes. Used for 35628c0b7df574599d4c19a4c09ca61bb3d70a338ccChris Lattner // protocol-qualified interfaces "NString<foo>" and protocol-qualified id 35728c0b7df574599d4c19a4c09ca61bb3d70a338ccChris Lattner // "id<foo>". 358d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl * const *ProtocolQualifiers; 359ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner unsigned NumProtocolQualifiers; 36071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation ProtocolLAngleLoc; 36171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation *ProtocolLocs; 3621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // SourceLocation info. These are null if the item wasn't specified or if 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // the setting was synthesized. 36581c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceRange Range; 3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 367ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc; 36882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc; 3690daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union, 3700daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// typename, then this is the location of the named type (if present); 3710daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and 3720daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// TSTNameLoc provides source range info for tag types. 3730daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara SourceLocation TSTNameLoc; 374cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceRange TypeofParensRange; 3754cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc; 376de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc; 377d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov SourceLocation FS_forceinlineLoc; 3788d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc; 3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 380ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor WrittenBuiltinSpecs writtenBS; 381ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor void SaveWrittenBuiltinSpecs(); 382ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 383f85e193739c953358c865005855253af4f68a497John McCall ObjCDeclSpec *ObjCQualifiers; 384f85e193739c953358c865005855253af4f68a497John McCall 385b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static bool isTypeRep(TST T) { 386db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt return (T == TST_typename || T == TST_typeofType || 387b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman T == TST_underlyingType || T == TST_atomic); 388b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 389b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static bool isExprRep(TST T) { 390b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return (T == TST_typeofExpr || T == TST_decltype); 391b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 39266cff7257698d5528632917d38f9a3037bb1506dDavid Blaikie 39366cff7257698d5528632917d38f9a3037bb1506dDavid Blaikie DeclSpec(const DeclSpec &) LLVM_DELETED_FUNCTION; 39466cff7257698d5528632917d38f9a3037bb1506dDavid Blaikie void operator=(const DeclSpec &) LLVM_DELETED_FUNCTION; 39566cff7257698d5528632917d38f9a3037bb1506dDavid Blaikiepublic: 396b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static bool isDeclRep(TST T) { 397b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return (T == TST_enum || T == TST_struct || 3986666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos T == TST_interface || T == TST_union || 3996666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos T == TST_class); 400b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 401b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 4020b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec(AttributeFactory &attrFactory) 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : StorageClassSpec(SCS_unspecified), 404ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith ThreadStorageClassSpec(TSCS_unspecified), 40535f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara SCS_extern_in_linkage_spec(false), 4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeSpecWidth(TSW_unspecified), 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeSpecComplex(TSC_unspecified), 4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeSpecSign(TSS_unspecified), 4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeSpecType(TST_unspecified), 41082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson TypeAltiVecVector(false), 41182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson TypeAltiVecPixel(false), 412788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner TypeAltiVecBool(false), 413402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor TypeSpecOwned(false), 41451e11f743e7478e94218b3c28283454dae1c6533Richard Smith TypeQualifiers(TQ_unspecified), 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FS_inline_specified(false), 416d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov FS_forceinline_specified(false), 417b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_virtual_specified(false), 418b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_explicit_specified(false), 419de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith FS_noreturn_specified(false), 420f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson Friend_specified(false), 4212ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl Constexpr_specified(false), 4220b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall Attrs(attrFactory), 4236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ProtocolQualifiers(nullptr), 42471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis NumProtocolQualifiers(0), 4256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ProtocolLocs(nullptr), 426f85e193739c953358c865005855253af4f68a497John McCall writtenBS(), 4276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ObjCQualifiers(nullptr) { 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~DeclSpec() { 430ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner delete [] ProtocolQualifiers; 43171b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis delete [] ProtocolLocs; 4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // storage-class-specifier 4342efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; } 435ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith TSCS getThreadStorageClassSpec() const { 436ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith return (TSCS)ThreadStorageClassSpec; 437ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith } 43835f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; } 43935f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara void setExternInLinkageSpec(bool Value) { 44035f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara SCS_extern_in_linkage_spec = Value; 44135f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara } 4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; } 444ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith SourceLocation getThreadStorageClassSpecLoc() const { 445ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith return ThreadStorageClassSpecLoc; 446ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith } 4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ClearStorageClassSpecs() { 449ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith StorageClassSpec = DeclSpec::SCS_unspecified; 450ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith ThreadStorageClassSpec = DeclSpec::TSCS_unspecified; 45135f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara SCS_extern_in_linkage_spec = false; 452ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith StorageClassSpecLoc = SourceLocation(); 453ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith ThreadStorageClassSpecLoc = SourceLocation(); 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 456f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling void ClearTypeSpecType() { 457f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling TypeSpecType = DeclSpec::TST_unspecified; 458f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling TypeSpecOwned = false; 459f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling TSTLoc = SourceLocation(); 460f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling } 461f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-specifier 4632efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; } 4642efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; } 4652efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; } 4662efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner TST getTypeSpecType() const { return (TST)TypeSpecType; } 46782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool isTypeAltiVecVector() const { return TypeAltiVecVector; } 46882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; } 469788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner bool isTypeAltiVecBool() const { return TypeAltiVecBool; } 470402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor bool isTypeSpecOwned() const { return TypeSpecOwned; } 471b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType getRepAsType() const { 472b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type"); 473b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return TypeRep; 474b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 475b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Decl *getRepAsDecl() const { 476b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl"); 477b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return DeclRep; 478b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 479b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *getRepAsExpr() const { 480b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr"); 481b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ExprRep; 482b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 483aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall CXXScopeSpec &getTypeSpecScope() { return TypeScope; } 484aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; } 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 486aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar const SourceRange &getSourceRange() const LLVM_READONLY { return Range; } 487aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 488aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 4893d4144f32ea4c24aaf48cbff4f476c1446ba2641Daniel Dunbar 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; } 4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; } 4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getTypeSpecSignLoc() const { return TSSLoc; } 4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; } 49482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson SourceLocation getAltiVecLoc() const { return AltiVecLoc; } 4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4960daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara SourceLocation getTypeSpecTypeNameLoc() const { 4970daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename); 4980daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara return TSTNameLoc; 4990daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara } 5000daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara 501cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceRange getTypeofParensRange() const { return TypeofParensRange; } 502cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; } 503cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 504a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith bool containsPlaceholderType() const { 505a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith return TypeSpecType == TST_auto || TypeSpecType == TST_decltype_auto; 506a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith } 507a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith 508f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling bool hasTagDefinition() const; 509f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling 5104ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Turn a type-specifier-type into a string like "_Bool" or "union". 511651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines static const char *getSpecifierName(DeclSpec::TST T, 512651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 51332d335e63bd287e5c9297532171284cdf4c7888cJohn McCall static const char *getSpecifierName(DeclSpec::TQ Q); 51432d335e63bd287e5c9297532171284cdf4c7888cJohn McCall static const char *getSpecifierName(DeclSpec::TSS S); 51532d335e63bd287e5c9297532171284cdf4c7888cJohn McCall static const char *getSpecifierName(DeclSpec::TSC C); 51632d335e63bd287e5c9297532171284cdf4c7888cJohn McCall static const char *getSpecifierName(DeclSpec::TSW W); 5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getSpecifierName(DeclSpec::SCS S); 518ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith static const char *getSpecifierName(DeclSpec::TSCS S); 5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-qualifiers 5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getTypeQualifiers - Return a set of TQs. 5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getTypeQualifiers() const { return TypeQualifiers; } 5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getConstSpecLoc() const { return TQ_constLoc; } 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; } 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; } 5274cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; } 5281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5297604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor /// \brief Clear out all of the type qualifiers. 5307604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor void ClearTypeQualifiers() { 5317604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor TypeQualifiers = 0; 5327604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor TQ_constLoc = SourceLocation(); 5337604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor TQ_restrictLoc = SourceLocation(); 5347604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor TQ_volatileLoc = SourceLocation(); 5354cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith TQ_atomicLoc = SourceLocation(); 5367604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor } 5377604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor 5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // function-specifier 539d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov bool isInlineSpecified() const { 540d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov return FS_inline_specified | FS_forceinline_specified; 541d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov } 542d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov SourceLocation getInlineSpecLoc() const { 543d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc; 544d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov } 545b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor 546b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor bool isVirtualSpecified() const { return FS_virtual_specified; } 547b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; } 548b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor 549b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor bool isExplicitSpecified() const { return FS_explicit_specified; } 550b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; } 551b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor 552de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith bool isNoreturnSpecified() const { return FS_noreturn_specified; } 553de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; } 554de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ClearFunctionSpecs() { 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FS_inline_specified = false; 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FS_inlineLoc = SourceLocation(); 558d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov FS_forceinline_specified = false; 559d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov FS_forceinlineLoc = SourceLocation(); 560b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_virtual_specified = false; 561b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_virtualLoc = SourceLocation(); 562b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_explicit_specified = false; 563b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_explicitLoc = SourceLocation(); 564de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith FS_noreturn_specified = false; 565de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith FS_noreturnLoc = SourceLocation(); 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5684ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Return true if any type-specifier has been found. 5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool hasTypeSpecifier() const { 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypeSpecType() != DeclSpec::TST_unspecified || 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getTypeSpecWidth() != DeclSpec::TSW_unspecified || 5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getTypeSpecComplex() != DeclSpec::TSC_unspecified || 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getTypeSpecSign() != DeclSpec::TSS_unspecified; 5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5764ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Return a bitmask of which flavors of specifiers this 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DeclSpec includes. 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getParsedSpecifiers() const; 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5802a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner /// isEmpty - Return true if this declaration specifier is completely empty: 5812a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner /// no tokens were parsed in the production of it. 5822a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner bool isEmpty() const { 5832a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner return getParsedSpecifiers() == DeclSpec::PQ_None; 5842a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner } 5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58681c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); } 58781c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); } 5881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 589fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// These methods set the specified attribute of the DeclSpec and 590fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// return false if there was no error. If an error occurs (for 591fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// example, if we tried to set "auto" on a spec with "extern" 592fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// already set), they return true and set PrevSpec and DiagID 593fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// such that 594fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// Diag(Loc, DiagID) << PrevSpec; 595fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// will yield a useful result. 596fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// 597fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// TODO: use a more general approach that still allows these 598fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// diagnostics to be ignored when desired. 599b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, 600651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const char *&PrevSpec, unsigned &DiagID, 601651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 602ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, 603ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith const char *&PrevSpec, unsigned &DiagID); 604fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec, 605651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned &DiagID, const PrintingPolicy &Policy); 606fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, 607fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 608fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec, 609fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 611651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned &DiagID, const PrintingPolicy &Policy); 612b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 613651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned &DiagID, ParsedType Rep, 614651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 615b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 616651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned &DiagID, Decl *Rep, bool Owned, 617651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 6180daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, 6190daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara SourceLocation TagNameLoc, const char *&PrevSpec, 620651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned &DiagID, ParsedType Rep, 621651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 6220daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, 6230daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara SourceLocation TagNameLoc, const char *&PrevSpec, 624651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned &DiagID, Decl *Rep, bool Owned, 625651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 6260daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara 627b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 628651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned &DiagID, Expr *Rep, 629651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &policy); 63082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, 631651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const char *&PrevSpec, unsigned &DiagID, 632651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 63382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, 634651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const char *&PrevSpec, unsigned &DiagID, 635651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 6363e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, 637651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const char *&PrevSpec, unsigned &DiagID, 638651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 639ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor bool SetTypeSpecError(); 640b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void UpdateDeclRep(Decl *Rep) { 641b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isDeclRep((TST) TypeSpecType)); 642b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall DeclRep = Rep; 643b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 644b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void UpdateTypeRep(ParsedType Rep) { 645b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isTypeRep((TST) TypeSpecType)); 646b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TypeRep = Rep; 647b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 648b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void UpdateExprRep(Expr *Rep) { 649b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isExprRep((TST) TypeSpecType)); 650b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ExprRep = Rep; 651b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, 654d654f2d722d4cb6366edcb8f27e99745fcbae486Richard Smith unsigned &DiagID, const LangOptions &Lang); 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 656d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, 657d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov unsigned &DiagID); 658d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, 659d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov unsigned &DiagID); 660d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, 661d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov unsigned &DiagID); 662d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, 663d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov unsigned &DiagID); 664d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, 665d1fa81ccbce1ba2d8f467e7c2800250b81ea2e35Serge Pavlov unsigned &DiagID); 6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 667fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, 668fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 6698d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, 6708d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor unsigned &DiagID); 6712ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, 6722ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl unsigned &DiagID); 6732ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl 674908116859ed8c166c1c0712992e504edd0c5a6e1Anders Carlsson bool isFriendSpecified() const { return Friend_specified; } 67566e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson SourceLocation getFriendSpecLoc() const { return FriendLoc; } 676908116859ed8c166c1c0712992e504edd0c5a6e1Anders Carlsson 6778d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); } 6788d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; } 6798d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor 6802ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl bool isConstexprSpecified() const { return Constexpr_specified; } 6812ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; } 6822ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl 68369730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith void ClearConstexprSpec() { 68469730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith Constexpr_specified = false; 68569730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith ConstexprLoc = SourceLocation(); 68669730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith } 68769730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith 6880b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributePool &getAttributePool() const { 6890b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall return Attrs.getPool(); 6900b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall } 6910b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 6924ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Concatenates two attribute lists. 6934ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// The GCC attribute syntax allows for the following: 6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 6964ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \code 6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// short __attribute__(( unused, deprecated )) 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// int __attribute__(( may_alias, aligned(16) )) var; 6994ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \endcode 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This declares 4 attributes using 2 lists. The following syntax is 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// also allowed and equivalent to the previous declaration. 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 7044ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \code 7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// short __attribute__((unused)) __attribute__((deprecated)) 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// int __attribute__((may_alias)) __attribute__((aligned(16))) var; 7074ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \endcode 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 7097f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void addAttributes(AttributeList *AL) { 7100b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall Attrs.addAll(AL); 7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7127f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 7137f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall bool hasAttributes() const { return !Attrs.empty(); } 7147f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 7157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &getAttributes() { return Attrs; } 7167f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall const ParsedAttributes &getAttributes() const { return Attrs; } 7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void takeAttributesFrom(ParsedAttributes &attrs) { 7190b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall Attrs.takeAllFrom(attrs); 7207654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner } 7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 722d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall typedef Decl * const *ProtocolQualifierListTy; 723ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner ProtocolQualifierListTy getProtocolQualifiers() const { 7244b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return ProtocolQualifiers; 7254b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 72671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation *getProtocolLocs() const { return ProtocolLocs; } 7277654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner unsigned getNumProtocolQualifiers() const { 728ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner return NumProtocolQualifiers; 7294b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 73071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; } 731d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void setProtocolQualifiers(Decl * const *Protos, unsigned NP, 73271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation *ProtoLocs, 733e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis SourceLocation LAngleLoc); 7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Finish - This does final analysis of the declspec, issuing diagnostics for 7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// things like "_Imaginary" (lacking an FP type). After calling this method, 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DeclSpec is guaranteed self-consistent, even if an error occurred. 738651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void Finish(DiagnosticsEngine &D, Preprocessor &PP, 739651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const PrintingPolicy &Policy); 740a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl 741ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const { 742ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return writtenBS; 743ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 744ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 745f85e193739c953358c865005855253af4f68a497John McCall ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; } 746f85e193739c953358c865005855253af4f68a497John McCall void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; } 747f85e193739c953358c865005855253af4f68a497John McCall 7484ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Checks if this DeclSpec can stand alone, without a Declarator. 7494ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// 7504ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// Only tag declspecs can stand alone. 751a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl bool isMissingDeclaratorOk(); 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7544ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief Captures information about "declaration specifiers" specific to 7554ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// Objective-C. 756a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCDeclSpec { 75719d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanianpublic: 75809e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// ObjCDeclQualifier - Qualifier used on types in method 75909e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// declarations. Not all combinations are sensible. Parameters 76009e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// can be one of { in, out, inout } with one of { bycopy, byref }. 76109e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// Returns can either be { oneway } or not. 76209e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// 76309e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// This should be kept in sync with Decl::ObjCDeclQualifier. 764a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek enum ObjCDeclQualifier { 76519d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_None = 0x0, 76619d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_In = 0x1, 76719d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Inout = 0x2, 76819d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Out = 0x4, 76919d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Bycopy = 0x8, 77019d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Byref = 0x10, 77119d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Oneway = 0x20 77219d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian }; 7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 774564576b225386cbff375351597dd5e2a92872d38Fariborz Jahanian /// PropertyAttributeKind - list of property attributes. 77509e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall enum ObjCPropertyAttributeKind { 77609e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall DQ_PR_noattr = 0x0, 7771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_readonly = 0x01, 7781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_getter = 0x02, 7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_assign = 0x04, 7801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_readwrite = 0x08, 78182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian DQ_PR_retain = 0x10, 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_copy = 0x20, 78382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian DQ_PR_nonatomic = 0x40, 78445937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian DQ_PR_setter = 0x80, 785f85e193739c953358c865005855253af4f68a497John McCall DQ_PR_atomic = 0x100, 786f85e193739c953358c865005855253af4f68a497John McCall DQ_PR_weak = 0x200, 787f85e193739c953358c865005855253af4f68a497John McCall DQ_PR_strong = 0x400, 788f85e193739c953358c865005855253af4f68a497John McCall DQ_PR_unsafe_unretained = 0x800 78982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian }; 7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 792e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner ObjCDeclSpec() 793e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr), 7946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines GetterName(nullptr), SetterName(nullptr) { } 795a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; } 796e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner void setObjCDeclQualifier(ObjCDeclQualifier DQVal) { 797e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal); 798e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner } 7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 800e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner ObjCPropertyAttributeKind getPropertyAttributes() const { 801e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner return ObjCPropertyAttributeKind(PropertyAttributes); 802e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner } 8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) { 8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PropertyAttributes = 805e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal); 80682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian } 8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 80882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian const IdentifierInfo *getGetterName() const { return GetterName; } 80982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian IdentifierInfo *getGetterName() { return GetterName; } 81082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian void setGetterName(IdentifierInfo *name) { GetterName = name; } 8111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian const IdentifierInfo *getSetterName() const { return SetterName; } 81382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian IdentifierInfo *getSetterName() { return SetterName; } 81482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian void setSetterName(IdentifierInfo *name) { SetterName = name; } 815cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall 81619d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanianprivate: 817ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // FIXME: These two are unrelated and mutually exclusive. So perhaps 818ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // we can put them in a union to reflect their mutual exclusivity 81982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian // (space saving is negligible). 820a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclQualifier objcDeclQualifier : 6; 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 822ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind 823f85e193739c953358c865005855253af4f68a497John McCall unsigned PropertyAttributes : 12; 824651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines IdentifierInfo *GetterName; // getter name or NULL if no getter 825651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines IdentifierInfo *SetterName; // setter name or NULL if no setter 82619d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian}; 827eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 8283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \brief Represents a C++ unqualified-id that has been parsed. 8293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorclass UnqualifiedId { 8303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorprivate: 831d11aa850a955027578ff47ab7e266ccf9173b5c2Dmitri Gribenko UnqualifiedId(const UnqualifiedId &Other) LLVM_DELETED_FUNCTION; 832d11aa850a955027578ff47ab7e266ccf9173b5c2Dmitri Gribenko const UnqualifiedId &operator=(const UnqualifiedId &) LLVM_DELETED_FUNCTION; 833d11aa850a955027578ff47ab7e266ccf9173b5c2Dmitri Gribenko 8343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorpublic: 8353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Describes the kind of unqualified-id parsed. 8363f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor enum IdKind { 8373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief An identifier. 8383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_Identifier, 8393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief An overloaded operator name, e.g., operator+. 8403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_OperatorFunctionId, 8413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief A conversion function name, e.g., operator int. 8423f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_ConversionFunctionId, 8430486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \brief A user-defined literal name, e.g., operator "" _i. 8440486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt IK_LiteralOperatorId, 8453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief A constructor name. 8463f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_ConstructorName, 8470efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief A constructor named via a template-id. 8480efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor IK_ConstructorTemplateId, 8493f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief A destructor name. 8503f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_DestructorName, 8513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief A template-id, e.g., f<int>. 85298a5403ecf1d2b60ae8cbf43e54194bd762cacaaFariborz Jahanian IK_TemplateId, 85398a5403ecf1d2b60ae8cbf43e54194bd762cacaaFariborz Jahanian /// \brief An implicit 'self' parameter 85498a5403ecf1d2b60ae8cbf43e54194bd762cacaaFariborz Jahanian IK_ImplicitSelfParam 8553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } Kind; 8563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 857e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher struct OFI { 858e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher /// \brief The kind of overloaded operator. 859e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher OverloadedOperatorKind Operator; 860e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher 861e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher /// \brief The source locations of the individual tokens that name 862e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher /// the operator, e.g., the "new", "[", and "]" tokens in 863e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher /// operator new []. 864e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher /// 865e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher /// Different operators have different numbers of tokens in their name, 866e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher /// up to three. Any remaining source locations in this array will be 867e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher /// set to an invalid value for operators with fewer than three tokens. 868e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher unsigned SymbolLocations[3]; 869e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher }; 870e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher 8713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Anonymous union that holds extra data associated with the 8723f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// parsed unqualified-id. 8733f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor union { 8740486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind 8750486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// == IK_UserLiteralId, the identifier suffix. 8763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Identifier; 8773f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 8783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator 8793f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// that we parsed. 880e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher struct OFI OperatorFunctionId; 8813f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 8823f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief When Kind == IK_ConversionFunctionId, the type that the 8833f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// conversion function names. 884b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall UnionParsedType ConversionFunctionId; 8853f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 8863f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief When Kind == IK_ConstructorName, the class-name of the type 8873f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// whose constructor is being referenced. 888b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall UnionParsedType ConstructorName; 8893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 8903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief When Kind == IK_DestructorName, the type referred to by the 8913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// class-name. 892b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall UnionParsedType DestructorName; 8933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 8940efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId, 8950efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// the template-id annotation that contains the template name and 8960efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template arguments. 8973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateIdAnnotation *TemplateId; 8983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor }; 8993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief The location of the first token that describes this unqualified-id, 9013f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// which will be the location of the identifier, "operator" keyword, 9023f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// tilde (for a destructor), or the template name of a template-id. 9033f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation StartLocation; 9043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9053f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief The location of the last token that describes this unqualified-id. 9063f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation EndLocation; 9073f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines UnqualifiedId() : Kind(IK_Identifier), Identifier(nullptr) { } 90998a5403ecf1d2b60ae8cbf43e54194bd762cacaaFariborz Jahanian 9103f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Clear out this unqualified-id, setting it to default (invalid) 9113f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// state. 912e2010ee042f3a370b15fda7872b86c914ffad4d2Benjamin Kramer void clear() { 913e2010ee042f3a370b15fda7872b86c914ffad4d2Benjamin Kramer Kind = IK_Identifier; 9146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Identifier = nullptr; 915e2010ee042f3a370b15fda7872b86c914ffad4d2Benjamin Kramer StartLocation = SourceLocation(); 916e2010ee042f3a370b15fda7872b86c914ffad4d2Benjamin Kramer EndLocation = SourceLocation(); 917e2010ee042f3a370b15fda7872b86c914ffad4d2Benjamin Kramer } 9183f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Determine whether this unqualified-id refers to a valid name. 9203f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool isValid() const { return StartLocation.isValid(); } 9213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Determine whether this unqualified-id refers to an invalid name. 9233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool isInvalid() const { return !isValid(); } 9243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Determine what kind of name we have. 9263f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdKind getKind() const { return Kind; } 92798a5403ecf1d2b60ae8cbf43e54194bd762cacaaFariborz Jahanian void setKind(IdKind kind) { Kind = kind; } 9283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as an identifier. 9303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param Id the parsed identifier. 9323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param IdLoc the location of the parsed identifier. 933014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) { 9343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Kind = IK_Identifier; 935014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor Identifier = const_cast<IdentifierInfo *>(Id); 9363f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation = EndLocation = IdLoc; 9373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 9383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as an 9403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// operator-function-id. 9413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9423f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param OperatorLoc the location of the 'operator' keyword. 9433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9443f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param Op the overloaded operator. 9453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9463f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param SymbolLocations the locations of the individual operator symbols 9473f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// in the operator. 9483f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor void setOperatorFunctionId(SourceLocation OperatorLoc, 9493f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor OverloadedOperatorKind Op, 9503f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation SymbolLocations[3]); 9513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as a 9533f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// conversion-function-id. 9543f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param OperatorLoc the location of the 'operator' keyword. 9563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9573f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param Ty the type to which this conversion function is converting. 9583f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9593f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param EndLoc the location of the last token that makes up the type name. 9603f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor void setConversionFunctionId(SourceLocation OperatorLoc, 961b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty, 9623f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation EndLoc) { 9633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Kind = IK_ConversionFunctionId; 9643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation = OperatorLoc; 9653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor EndLocation = EndLoc; 9663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor ConversionFunctionId = Ty; 9673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 9680486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt 9690486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \brief Specific that this unqualified-id was parsed as a 9700486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// literal-operator-id. 9710486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// 9720486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \param Id the parsed identifier. 9730486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// 9740486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \param OpLoc the location of the 'operator' keyword. 9750486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// 9760486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \param IdLoc the location of the identifier. 9770486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc, 9780486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt SourceLocation IdLoc) { 9790486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt Kind = IK_LiteralOperatorId; 9800486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt Identifier = const_cast<IdentifierInfo *>(Id); 9810486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt StartLocation = OpLoc; 9820486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt EndLocation = IdLoc; 9830486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt } 9843f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 9853f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as a constructor name. 9863f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9873f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param ClassType the class type referred to by the constructor name. 9883f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param ClassNameLoc the location of the class name. 9903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 9913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param EndLoc the location of the last token that makes up the type name. 992b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void setConstructorName(ParsedType ClassType, 9933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation ClassNameLoc, 9943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation EndLoc) { 9953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Kind = IK_ConstructorName; 9963f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation = ClassNameLoc; 9973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor EndLocation = EndLoc; 9983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor ConstructorName = ClassType; 9993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 10003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 10010efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Specify that this unqualified-id was parsed as a 10020efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that names a constructor. 10030efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// 10040efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \param TemplateId the template-id annotation that describes the parsed 10050efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id. This UnqualifiedId instance will take ownership of the 10060efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \p TemplateId and will free it on destruction. 10070efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor void setConstructorTemplateId(TemplateIdAnnotation *TemplateId); 10080efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 10093f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as a destructor name. 10103f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 10113f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param TildeLoc the location of the '~' that introduces the destructor 10123f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// name. 10133f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 10143f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param ClassType the name of the class referred to by the destructor name. 1015b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void setDestructorName(SourceLocation TildeLoc, 1016b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ClassType, 10173f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation EndLoc) { 10183f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Kind = IK_DestructorName; 10193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation = TildeLoc; 10203f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor EndLocation = EndLoc; 10213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor DestructorName = ClassType; 10223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 10233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 10243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as a template-id. 10253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 10263f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param TemplateId the template-id annotation that describes the parsed 10273f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// template-id. This UnqualifiedId instance will take ownership of the 10283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \p TemplateId and will free it on destruction. 1029314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor void setTemplateId(TemplateIdAnnotation *TemplateId); 10303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 10313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Return the source range that covers this unqualified-id. 1032aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 10333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return SourceRange(StartLocation, EndLocation); 10343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 1035aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { return StartLocation; } 1036aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { return EndLocation; } 10373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor}; 10384ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett 10394ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief A set of tokens that has been cached for later parsing. 1040686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<Token, 4> CachedTokens; 104172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 10424ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief One instance of this struct is used for each type in a 10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// declarator that is parsed. 10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// This is intended to be a small value object. 10465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerstruct DeclaratorChunk { 10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum { 1048075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren 10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } Kind; 1050f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Loc - The place where this type was defined. 10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// EndLoc - If valid, the place where this chunck ends. 10547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation EndLoc; 10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10567f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct TypeInfoCommon { 10577f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall AttributeList *AttrList; 10587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall }; 10597f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 10607f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct PointerTypeInfo : TypeInfoCommon { 10614cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith /// The type qualifiers: const/volatile/restrict/atomic. 10624cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith unsigned TypeQuals : 4; 1063d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 1064d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth /// The location of the const-qualifier, if any. 1065d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth unsigned ConstQualLoc; 1066d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 1067d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth /// The location of the volatile-qualifier, if any. 1068d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth unsigned VolatileQualLoc; 1069d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 1070d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth /// The location of the restrict-qualifier, if any. 1071d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth unsigned RestrictQualLoc; 1072d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 10734cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith /// The location of the _Atomic-qualifier, if any. 10744cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith unsigned AtomicQualLoc; 10754cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith 10767654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner void destroy() { 10777654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner } 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct ReferenceTypeInfo : TypeInfoCommon { 10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// The type qualifier: restrict. [GNU] C++ extension 108205532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl bool HasRestrict : 1; 108305532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl /// True if this is an lvalue reference, false if it's an rvalue reference. 108405532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl bool LValueRef : 1; 10857654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner void destroy() { 10867654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner } 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct ArrayTypeInfo : TypeInfoCommon { 10904cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith /// The type qualifiers for the array: const/volatile/restrict/_Atomic. 10914cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith unsigned TypeQuals : 4; 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// True if this dimension included the 'static' keyword. 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool hasStatic : 1; 10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// True if this dimension was [*]. In this case, NumElts is null. 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isStar : 1; 10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This is the size of the array, or null if [] or [*] was specified. 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Since the parser is multi-purpose, and we don't want to impose a root 11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression class on all clients, NumElts is untyped. 1102ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Expr *NumElts; 11037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void destroy() {} 11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParamInfo - An array of paraminfo objects is allocated whenever a function 1108651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// declarator is parsed. There are two interesting styles of parameters 1109651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// here: 11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// K&R-style identifier lists and parameter type lists. K&R-style identifier 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lists will have information about the identifier, but no type information. 11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Parameter type lists will have type info (if the actions module provides 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'. 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer struct ParamInfo { 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Ident; 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation IdentLoc; 1117d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param; 111872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 111972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgTokens - When the parameter's default argument 112072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// cannot be parsed immediately (because it occurs within the 112172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// declaration of a member function), it will be stored here as a 112272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// sequence of tokens to be parsed once the class definition is 112372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// complete. Non-NULL indicates that there is a default argument. 11245af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner CachedTokens *DefaultArgTokens; 112572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParamInfo() {} 1127b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner ParamInfo(IdentifierInfo *ident, SourceLocation iloc, 1128d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *param, 11296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines CachedTokens *DefArgTokens = nullptr) 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Ident(ident), IdentLoc(iloc), Param(param), 113172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor DefaultArgTokens(DefArgTokens) {} 11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1133ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl 1134ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl struct TypeAndRange { 1135b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty; 1136ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl SourceRange Range; 1137ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl }; 1138ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl 11397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct FunctionTypeInfo : TypeInfoCommon { 11405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasPrototype - This is true if the function had at least one typed 1141651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// parameter. If the function is () or (a,b,c), then it has no prototype, 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and is treated as a K&R-style function. 11437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned hasPrototype : 1; 11447dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 1145965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor /// isVariadic - If this function has a prototype, and if that 1146965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor /// proto ends with ',...)', this is true. When true, EllipsisLoc 1147965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor /// contains the location of the ellipsis. 11487f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned isVariadic : 1; 11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1150b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith /// Can this declaration be a constructor-style initializer? 1151b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith unsigned isAmbiguous : 1; 1152b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith 115383f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// \brief Whether the ref-qualifier (if any) is an lvalue reference. 115483f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// Otherwise, it's an rvalue reference. 115583f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor unsigned RefQualifierIsLValueRef : 1; 115659c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 1157971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// The type qualifiers: const/volatile/restrict. 11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// The qualifier bitmask values are the same as in QualType. 1159971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 1160971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 11616e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// ExceptionSpecType - An ExceptionSpecificationType value. 11626e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl unsigned ExceptionSpecType : 3; 11637dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 1164651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// DeleteParams - If this is true, we need to delete[] Params. 1165651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned DeleteParams : 1; 11665af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner 116754655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith /// HasTrailingReturnType - If this is true, a trailing return type was 116854655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith /// specified. 116954655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith unsigned HasTrailingReturnType : 1; 117054655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith 117159c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara /// The location of the left parenthesis in the source. 117259c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara unsigned LParenLoc; 117359c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 11747dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl /// When isVariadic is true, the location of the ellipsis in the source. 11757dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl unsigned EllipsisLoc; 11767dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 117759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara /// The location of the right parenthesis in the source. 117859c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara unsigned RParenLoc; 117959c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 1180651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// NumParams - This is the number of formal parameters specified by the 11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// declarator. 1182651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned NumParams; 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11846e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// NumExceptions - This is the number of types in the dynamic-exception- 11856e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// decl, if the function has one. 11867dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl unsigned NumExceptions; 11877dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 118883f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// \brief The location of the ref-qualifier, if any. 118983f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// 119083f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// If this is an invalid location, there is no ref-qualifier. 119183f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor unsigned RefQualifierLoc; 11926e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl 119343f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /// \brief The location of the const-qualifier, if any. 119443f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /// 119543f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /// If this is an invalid location, there is no const-qualifier. 119643f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor unsigned ConstQualifierLoc; 119743f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor 119843f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /// \brief The location of the volatile-qualifier, if any. 119943f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /// 120043f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /// If this is an invalid location, there is no volatile-qualifier. 120143f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor unsigned VolatileQualifierLoc; 120243f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor 120390ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor /// \brief The location of the 'mutable' qualifer in a lambda-declarator, if 120490ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor /// any. 120590ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor unsigned MutableLoc; 120690ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor 1207b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith /// \brief The location of the keyword introducing the spec, if any. 12086e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl unsigned ExceptionSpecLoc; 12093cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl 1210651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// Params - This is a pointer to a new[]'d array of ParamInfo objects that 1211651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// describe the parameters specified by this function declarator. null if 1212651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// there are no parameters specified. 1213651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ParamInfo *Params; 12147dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 12156e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl union { 12166e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// \brief Pointer to a new[]'d array of TypeAndRange objects that 12176e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// contain the types in the function's dynamic exception specification 12186e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// and their locations, if there is one. 12196e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl TypeAndRange *Exceptions; 12206e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl 12216e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// \brief Pointer to the expression in the noexcept-specifier of this 12226e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// function, if it has one. 12236e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl Expr *NoexceptExpr; 12246e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl }; 12257dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 12264ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief If HasTrailingReturnType is true, this is the trailing return 12274ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// type specified. 122854655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith UnionParsedType TrailingReturnType; 1229dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 1230651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Reset the parameter list to having zero parameters. 12314ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// 12324ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// This is used in various places for error recovery. 1233651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void freeParams() { 12346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines for (unsigned I = 0; I < NumParams; ++I) { 12356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines delete Params[I].DefaultArgTokens; 12366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Params[I].DefaultArgTokens = nullptr; 12376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines } 1238651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (DeleteParams) { 1239651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines delete[] Params; 1240651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines DeleteParams = false; 12411833a83368bda46b76388069e52b27f12e60dc9cChris Lattner } 1242651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines NumParams = 0; 12431833a83368bda46b76388069e52b27f12e60dc9cChris Lattner } 12447dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void destroy() { 1246651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (DeleteParams) 1247651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines delete[] Params; 12486e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl if (getExceptionSpecType() == EST_Dynamic) 12496e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl delete[] Exceptions; 12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1251965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor 1252004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner /// isKNRPrototype - Return true if this is a K&R style identifier list, 1253004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner /// like "void foo(a,b,c)". In a function definition, this will be followed 1254651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// by the parameter type definitions. 1255651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; } 125659c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 125759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation getLParenLoc() const { 125859c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara return SourceLocation::getFromRawEncoding(LParenLoc); 125959c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara } 126059c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 1261965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor SourceLocation getEllipsisLoc() const { 1262965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor return SourceLocation::getFromRawEncoding(EllipsisLoc); 1263965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor } 126459c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 126559c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation getRParenLoc() const { 126659c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara return SourceLocation::getFromRawEncoding(RParenLoc); 126759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara } 126859c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 12696e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl SourceLocation getExceptionSpecLoc() const { 12706e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl return SourceLocation::getFromRawEncoding(ExceptionSpecLoc); 12713cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl } 12726e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl 127383f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// \brief Retrieve the location of the ref-qualifier, if any. 127483f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor SourceLocation getRefQualifierLoc() const { 127583f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor return SourceLocation::getFromRawEncoding(RefQualifierLoc); 127683f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor } 12776e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl 127843f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /// \brief Retrieve the location of the ref-qualifier, if any. 127943f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor SourceLocation getConstQualifierLoc() const { 128043f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor return SourceLocation::getFromRawEncoding(ConstQualifierLoc); 128143f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor } 128243f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor 128343f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor /// \brief Retrieve the location of the ref-qualifier, if any. 128443f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor SourceLocation getVolatileQualifierLoc() const { 128543f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor return SourceLocation::getFromRawEncoding(VolatileQualifierLoc); 128643f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor } 128743f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor 128890ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor /// \brief Retrieve the location of the 'mutable' qualifier, if any. 128990ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor SourceLocation getMutableLoc() const { 129090ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor return SourceLocation::getFromRawEncoding(MutableLoc); 129190ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor } 129290ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor 129383f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// \brief Determine whether this function declaration contains a 129483f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// ref-qualifier. 129583f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); } 12966e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl 129790ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor /// \brief Determine whether this lambda-declarator contains a 'mutable' 129890ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor /// qualifier. 129990ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor bool hasMutableQualifier() const { return getMutableLoc().isValid(); } 130090ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor 13016e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /// \brief Get the type of exception specification this function has. 13026e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl ExceptionSpecificationType getExceptionSpecType() const { 13036e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 13046e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl } 130554655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith 130654655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith /// \brief Determine whether this function declarator had a 130754655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith /// trailing-return-type. 130854655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith bool hasTrailingReturnType() const { return HasTrailingReturnType; } 130954655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith 131054655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith /// \brief Get the trailing-return-type for this function declarator. 131154655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith ParsedType getTrailingReturnType() const { return TrailingReturnType; } 13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 13135618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 13147f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct BlockPointerTypeInfo : TypeInfoCommon { 13155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff /// For now, sema will catch these as invalid. 13164cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith /// The type qualifiers: const/volatile/restrict/_Atomic. 13174cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith unsigned TypeQuals : 4; 13187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 131975b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump void destroy() { 132075b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump } 13215618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff }; 13225618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 13237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct MemberPointerTypeInfo : TypeInfoCommon { 13244cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith /// The type qualifiers: const/volatile/restrict/_Atomic. 13254cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith unsigned TypeQuals : 4; 1326f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // CXXScopeSpec has a constructor, so it can't be a direct member. 1327f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // So we need some pointer-aligned storage and a bit of trickery. 1328f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl union { 1329f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void *Aligner; 1330f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl char Mem[sizeof(CXXScopeSpec)]; 1331f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } ScopeMem; 1332f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl CXXScopeSpec &Scope() { 1333f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem); 1334f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1335f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const CXXScopeSpec &Scope() const { 1336f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem); 1337f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1338f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void destroy() { 1339f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Scope().~CXXScopeSpec(); 1340f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1341f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl }; 1342f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer union { 1344711c52bb20d0c69063b52a99826fb7d2835501f1John McCall TypeInfoCommon Common; 1345f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointerTypeInfo Ptr; 1346f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ReferenceTypeInfo Ref; 1347f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ArrayTypeInfo Arr; 1348f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl FunctionTypeInfo Fun; 1349f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl BlockPointerTypeInfo Cls; 1350f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypeInfo Mem; 13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1352f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 13535af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner void destroy() { 13545af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner switch (Kind) { 1355f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Function: return Fun.destroy(); 1356f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Pointer: return Ptr.destroy(); 1357f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::BlockPointer: return Cls.destroy(); 1358f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Reference: return Ref.destroy(); 1359f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Array: return Arr.destroy(); 1360f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::MemberPointer: return Mem.destroy(); 1361075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Paren: return; 13625af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner } 13635af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner } 1364f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 13654ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief If there are attributes applied to this declaratorchunk, return 1366e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner /// them. 1367e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner const AttributeList *getAttrs() const { 1368711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return Common.AttrList; 1369e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner } 1370f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1371711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *&getAttrListRef() { 1372711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return Common.AttrList; 1373711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 1374f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 13754ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Return a DeclaratorChunk for a pointer. 13767654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, 1377d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation ConstQualLoc, 1378d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation VolatileQualLoc, 13790b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation RestrictQualLoc) { 13805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclaratorChunk I; 1381d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth I.Kind = Pointer; 1382d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth I.Loc = Loc; 1383d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth I.Ptr.TypeQuals = TypeQuals; 1384d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth I.Ptr.ConstQualLoc = ConstQualLoc.getRawEncoding(); 1385d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding(); 1386d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding(); 13876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines I.Ptr.AttrList = nullptr; 13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return I; 13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13914ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Return a DeclaratorChunk for a reference. 13927654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, 13937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall bool lvalue) { 13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclaratorChunk I; 13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Kind = Reference; 13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Loc = Loc; 13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0; 139805532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl I.Ref.LValueRef = lvalue; 13996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines I.Ref.AttrList = nullptr; 14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return I; 14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14034ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Return a DeclaratorChunk for an array. 14047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall static DeclaratorChunk getArray(unsigned TypeQuals, 14057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall bool isStatic, bool isStar, Expr *NumElts, 14067e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation LBLoc, SourceLocation RBLoc) { 14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclaratorChunk I; 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Kind = Array; 14097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor I.Loc = LBLoc; 14107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor I.EndLoc = RBLoc; 14116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines I.Arr.AttrList = nullptr; 14125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Arr.TypeQuals = TypeQuals; 14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Arr.hasStatic = isStatic; 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Arr.isStar = isStar; 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Arr.NumElts = NumElts; 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return I; 14175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14195af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. 14205af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// "TheDeclarator" is the declarator that this will be added to. 14216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines static DeclaratorChunk getFunction(bool HasProto, 14226bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool IsAmbiguous, 142359c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation LParenLoc, 1424651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ParamInfo *Params, unsigned NumParams, 142559c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation EllipsisLoc, 142659c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation RParenLoc, 142759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara unsigned TypeQuals, 142883f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor bool RefQualifierIsLvalueRef, 142983f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor SourceLocation RefQualifierLoc, 143043f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor SourceLocation ConstQualifierLoc, 143143f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor SourceLocation VolatileQualifierLoc, 143290ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor SourceLocation MutableLoc, 14336e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl ExceptionSpecificationType ESpecType, 14346e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl SourceLocation ESpecLoc, 1435b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType *Exceptions, 1436ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl SourceRange *ExceptionRanges, 143782bf01061b97404fed8c422fc0eda0a380689cc9Argyrios Kyrtzidis unsigned NumExceptions, 14386e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl Expr *NoexceptExpr, 1439796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara SourceLocation LocalRangeBegin, 1440796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara SourceLocation LocalRangeEnd, 1441dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor Declarator &TheDeclarator, 144254655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith TypeResult TrailingReturnType = 144354655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith TypeResult()); 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14454ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Return a DeclaratorChunk for a block. 14460b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall static DeclaratorChunk getBlockPointer(unsigned TypeQuals, 14470b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation Loc) { 14485618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff DeclaratorChunk I; 14495618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff I.Kind = BlockPointer; 14505618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff I.Loc = Loc; 14515618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff I.Cls.TypeQuals = TypeQuals; 14526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines I.Cls.AttrList = nullptr; 14535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return I; 14545618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 1455f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1456f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, 1457f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl unsigned TypeQuals, 14580b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation Loc) { 1459f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl DeclaratorChunk I; 1460f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl I.Kind = MemberPointer; 1461f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl I.Loc = Loc; 1462f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl I.Mem.TypeQuals = TypeQuals; 14636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines I.Mem.AttrList = nullptr; 1464f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS); 1465f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return I; 1466f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1467075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 14684ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Return a DeclaratorChunk for a paren. 1469075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static DeclaratorChunk getParen(SourceLocation LParenLoc, 1470075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara SourceLocation RParenLoc) { 1471075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara DeclaratorChunk I; 1472075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara I.Kind = Paren; 1473075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara I.Loc = LParenLoc; 1474075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara I.EndLoc = RParenLoc; 14756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines I.Common.AttrList = nullptr; 1476075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return I; 1477075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1478075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1479b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall bool isParen() const { 1480b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall return Kind == Paren; 1481b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall } 14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 148445fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor/// \brief Described the kind of function definition (if any) provided for 148545fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor/// a function. 148645fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregorenum FunctionDefinitionKind { 148745fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FDK_Declaration, 148845fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FDK_Definition, 148945fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FDK_Defaulted, 149045fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FDK_Deleted 149145fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor}; 14924ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett 14934ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief Information about one declarator, including the parsed type 14944ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// information and the identifier. 14954ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// 14964ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// When the declarator is fully formed, this is turned into the appropriate 14974ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// Decl object. 14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 14995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Declarators come in two types: normal declarators and abstract declarators. 15005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Abstract declarators are used when parsing types, and don't have an 15015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// identifier. Normal declarators do have ID's. 15025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1503e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner/// Instances of this class should be a transient object that lives on the 1504e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner/// stack, not objects that are allocated in large quantities on the heap. 15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Declarator { 15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15072d3dfd70eee48005f253b72d288e0eb4ed754fe0Zhongxing Xu enum TheContext { 15085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileContext, // File scope declaration. 15095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PrototypeContext, // Within a function prototype. 1510cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ObjCResultContext, // An ObjC method result type. 1511cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ObjCParameterContext,// An ObjC method parameter type. 15125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer KNRTypeListContext, // K&R type definition list for formals. 15135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeNameContext, // Abstract declarator for types. 15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MemberContext, // Struct/Union field. 15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BlockContext, // Declaration within a block in a function. 151671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis ForContext, // Declaration within first part of a for loop. 151726236e8b7507017fded05da3474d842e802a1679Douglas Gregor ConditionContext, // Condition declaration in a C++ if/switch/while/for. 1518a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl TemplateParamContext,// Within a template parameter list. 15190b8c98f3ddf83adcb9e9d98b68ce38e970cdee73Argyrios Kyrtzidis CXXNewContext, // C++ new-expression. 152098eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump CXXCatchContext, // C++ catch exception-declaration 152117b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis ObjCCatchContext, // Objective-C catch exception-declaration 152214f78f4a11df4c06667e2cbb87eeb179e4cb46feRichard Smith BlockLiteralContext, // Block literal declarator. 1523f88c400085eac7068399d0a01dbad89f8c579f07Eli Friedman LambdaExprContext, // Lambda-expression declarator. 1524fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali LambdaExprParameterContext, // Lambda-expression parameter declarator. 152514f78f4a11df4c06667e2cbb87eeb179e4cb46feRichard Smith ConversionIdContext, // C++ conversion-type-id. 15267796eb5643244f3134834253ce5ea89107ac21c1Richard Smith TrailingReturnContext, // C++11 trailing-type-specifier. 1527162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TemplateTypeArgContext, // Template type argument. 15287796eb5643244f3134834253ce5ea89107ac21c1Richard Smith AliasDeclContext, // C++11 alias-declaration. 15297796eb5643244f3134834253ce5ea89107ac21c1Richard Smith AliasTemplateContext // C++11 alias-declaration template. 15305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 153142a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 15335af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner const DeclSpec &DS; 15345af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner CXXScopeSpec SS; 15353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId Name; 1536ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl SourceRange Range; 1537ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 15384ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Where we are parsing this declarator. 15395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TheContext Context; 154042a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DeclTypeInfo - This holds each type that the declarator includes as it is 15425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// parsed. This is pushed from the identifier out, which means that element 15435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #0 will be the most closely bound to the identifier, and 15445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DeclTypeInfo.back() will be the least closely bound. 1545686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<DeclaratorChunk, 8> DeclTypeInfo; 15465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1547ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// InvalidType - Set by Sema::GetTypeForDeclarator(). 154873a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis bool InvalidType : 1; 154973a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis 155073a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis /// GroupingParens - Set by Parser::ParseParenDeclarator(). 155173a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis bool GroupingParens : 1; 1552e1223f7246c2c297f7b62816fd8c6a0a14151977Steve Naroff 155345fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor /// FunctionDefinition - Is this Declarator for a function or member 155445fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor /// definition and, if so, what kind? 155545fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor /// 155645fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor /// Actually a FunctionDefinitionKind. 155745fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor unsigned FunctionDefinition : 2; 15582c712f50cd56eaf3662989b556e9c6b1e8fcd11aKaelyn Uhrain 15594ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Is this Declarator a redeclaration? 15602c712f50cd56eaf3662989b556e9c6b1e8fcd11aKaelyn Uhrain bool Redeclaration : 1; 15612c712f50cd56eaf3662989b556e9c6b1e8fcd11aKaelyn Uhrain 1562ad017fa7a4df7389d245d02a49b3c79ed70bedb9Bill Wendling /// Attrs - Attributes. 15630b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes Attrs; 15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15654ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief The asm label, if specified. 1566b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *AsmLabel; 156742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 15685af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// InlineParams - This is a local array used for the first function decl 15695af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// chunk to avoid going to the heap for the common case when we have one 15705af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// function chunk in the declarator. 15715af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner DeclaratorChunk::ParamInfo InlineParams[16]; 15725af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner bool InlineParamsUsed; 1573ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 15744ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief true if the declaration is preceded by \c __extension__. 157591a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor bool Extension : 1; 157691a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor 15777984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith /// \brief If this is the second or subsequent declarator in this declaration, 15787984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith /// the location of the comma before this declarator. 15797984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith SourceLocation CommaLoc; 15807984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith 1581a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor /// \brief If provided, the source location of the ellipsis used to describe 1582a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor /// this declarator as a parameter pack. 1583a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor SourceLocation EllipsisLoc; 1584a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor 158543af76e845c95be160c088ec11ba3c43e2527fa8Sebastian Redl friend struct DeclaratorChunk; 1586ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 15875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1588e1449e51016fa7868d241c9e451253929d188bb9Argyrios Kyrtzidis Declarator(const DeclSpec &ds, TheContext C) 15893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor : DS(ds), Range(ds.getSourceRange()), Context(C), 1590ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error), 159145fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor GroupingParens(false), FunctionDefinition(FDK_Declaration), 159245fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor Redeclaration(false), 15936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Attrs(ds.getAttributePool().getFactory()), AsmLabel(nullptr), 15942c712f50cd56eaf3662989b556e9c6b1e8fcd11aKaelyn Uhrain InlineParamsUsed(false), Extension(false) { 15955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Declarator() { 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer clear(); 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getDeclSpec - Return the declaration-specifier that this declarator was 16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// declared with. 1602985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner const DeclSpec &getDeclSpec() const { return DS; } 16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1604985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// getMutableDeclSpec - Return a non-const version of the DeclSpec. This 1605985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// should be used with extreme care: declspecs can often be shared between 1606985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// multiple declarators, so mutating the DeclSpec affects all of the 1607985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// Declarators. This should only be done when the declspec is known to not 1608985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// be shared or when in error recovery etc. 1609e1449e51016fa7868d241c9e451253929d188bb9Argyrios Kyrtzidis DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); } 1610985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner 16110b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributePool &getAttributePool() const { 16120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall return Attrs.getPool(); 16130b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall } 16140b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 1615eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// getCXXScopeSpec - Return the C++ scope specifier (global scope or 1616eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// nested-name-specifier) that is part of the declarator-id. 1617eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis const CXXScopeSpec &getCXXScopeSpec() const { return SS; } 1618eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis CXXScopeSpec &getCXXScopeSpec() { return SS; } 1619eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 16203f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Retrieve the name specified by this declarator. 16213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &getName() { return Name; } 16223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TheContext getContext() const { return Context; } 162442a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 1625c05a94b7accd4035bf5d5897c434c445b22da855John McCall bool isPrototypeContext() const { 1626cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall return (Context == PrototypeContext || 1627cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Context == ObjCParameterContext || 1628fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali Context == ObjCResultContext || 1629fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali Context == LambdaExprParameterContext); 1630c05a94b7accd4035bf5d5897c434c445b22da855John McCall } 1631c05a94b7accd4035bf5d5897c434c445b22da855John McCall 16324ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Get the source range that spans this declarator. 1633aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar const SourceRange &getSourceRange() const LLVM_READONLY { return Range; } 1634aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 1635aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 1636ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 1637ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void SetSourceRange(SourceRange R) { Range = R; } 1638ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// SetRangeBegin - Set the start of the source range to Loc, unless it's 1639ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// invalid. 1640ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void SetRangeBegin(SourceLocation Loc) { 1641ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!Loc.isInvalid()) 1642ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range.setBegin(Loc); 1643ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl } 1644ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid. 1645ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void SetRangeEnd(SourceLocation Loc) { 1646ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!Loc.isInvalid()) 1647ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range.setEnd(Loc); 1648ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl } 1649ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// ExtendWithDeclSpec - Extend the declarator source range to include the 1650ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// given declspec, unless its location is invalid. Adopts the range start if 1651ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// the current range start is invalid. 1652ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void ExtendWithDeclSpec(const DeclSpec &DS) { 1653ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl const SourceRange &SR = DS.getSourceRange(); 1654ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (Range.getBegin().isInvalid()) 1655ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range.setBegin(SR.getBegin()); 1656ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!SR.getEnd().isInvalid()) 1657ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range.setEnd(SR.getEnd()); 1658ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl } 1659ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 16604ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Reset the contents of this Declarator. 16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void clear() { 1662eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis SS.clear(); 16633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Name.clear(); 1664ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range = DS.getSourceRange(); 1665db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor 16665af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i) 16675af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner DeclTypeInfo[i].destroy(); 16685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclTypeInfo.clear(); 16690b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall Attrs.clear(); 16706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines AsmLabel = nullptr; 16715af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner InlineParamsUsed = false; 16727984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith CommaLoc = SourceLocation(); 16737984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith EllipsisLoc = SourceLocation(); 16745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// mayOmitIdentifier - Return true if the identifier is either optional or 16771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// not allowed. This is true for typenames, prototypes, and template 167826236e8b7507017fded05da3474d842e802a1679Douglas Gregor /// parameter lists. 16795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool mayOmitIdentifier() const { 1680c05a94b7accd4035bf5d5897c434c445b22da855John McCall switch (Context) { 1681c05a94b7accd4035bf5d5897c434c445b22da855John McCall case FileContext: 1682c05a94b7accd4035bf5d5897c434c445b22da855John McCall case KNRTypeListContext: 1683c05a94b7accd4035bf5d5897c434c445b22da855John McCall case MemberContext: 1684c05a94b7accd4035bf5d5897c434c445b22da855John McCall case BlockContext: 1685c05a94b7accd4035bf5d5897c434c445b22da855John McCall case ForContext: 1686c05a94b7accd4035bf5d5897c434c445b22da855John McCall case ConditionContext: 1687c05a94b7accd4035bf5d5897c434c445b22da855John McCall return false; 1688c05a94b7accd4035bf5d5897c434c445b22da855John McCall 1689c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TypeNameContext: 1690162e1c1b487352434552147967c3dd296ebee2f7Richard Smith case AliasDeclContext: 16913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith case AliasTemplateContext: 1692c05a94b7accd4035bf5d5897c434c445b22da855John McCall case PrototypeContext: 1693fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali case LambdaExprParameterContext: 1694cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall case ObjCParameterContext: 1695cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall case ObjCResultContext: 1696c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TemplateParamContext: 16970b8c98f3ddf83adcb9e9d98b68ce38e970cdee73Argyrios Kyrtzidis case CXXNewContext: 1698c05a94b7accd4035bf5d5897c434c445b22da855John McCall case CXXCatchContext: 169917b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis case ObjCCatchContext: 1700c05a94b7accd4035bf5d5897c434c445b22da855John McCall case BlockLiteralContext: 1701f88c400085eac7068399d0a01dbad89f8c579f07Eli Friedman case LambdaExprContext: 170214f78f4a11df4c06667e2cbb87eeb179e4cb46feRichard Smith case ConversionIdContext: 1703c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TemplateTypeArgContext: 17047796eb5643244f3134834253ce5ea89107ac21c1Richard Smith case TrailingReturnContext: 1705c05a94b7accd4035bf5d5897c434c445b22da855John McCall return true; 1706c05a94b7accd4035bf5d5897c434c445b22da855John McCall } 1707c05a94b7accd4035bf5d5897c434c445b22da855John McCall llvm_unreachable("unknown context kind!"); 17085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// mayHaveIdentifier - Return true if the identifier is either optional or 17115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// required. This is true for normal declarators and prototypes, but not 17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// typenames. 17135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool mayHaveIdentifier() const { 1714c05a94b7accd4035bf5d5897c434c445b22da855John McCall switch (Context) { 1715c05a94b7accd4035bf5d5897c434c445b22da855John McCall case FileContext: 1716c05a94b7accd4035bf5d5897c434c445b22da855John McCall case KNRTypeListContext: 1717c05a94b7accd4035bf5d5897c434c445b22da855John McCall case MemberContext: 1718c05a94b7accd4035bf5d5897c434c445b22da855John McCall case BlockContext: 1719c05a94b7accd4035bf5d5897c434c445b22da855John McCall case ForContext: 1720c05a94b7accd4035bf5d5897c434c445b22da855John McCall case ConditionContext: 1721c05a94b7accd4035bf5d5897c434c445b22da855John McCall case PrototypeContext: 1722fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali case LambdaExprParameterContext: 1723c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TemplateParamContext: 1724c05a94b7accd4035bf5d5897c434c445b22da855John McCall case CXXCatchContext: 172517b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis case ObjCCatchContext: 1726c05a94b7accd4035bf5d5897c434c445b22da855John McCall return true; 1727c05a94b7accd4035bf5d5897c434c445b22da855John McCall 1728c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TypeNameContext: 17290b8c98f3ddf83adcb9e9d98b68ce38e970cdee73Argyrios Kyrtzidis case CXXNewContext: 1730162e1c1b487352434552147967c3dd296ebee2f7Richard Smith case AliasDeclContext: 17313e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith case AliasTemplateContext: 1732cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall case ObjCParameterContext: 1733cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall case ObjCResultContext: 1734c05a94b7accd4035bf5d5897c434c445b22da855John McCall case BlockLiteralContext: 1735f88c400085eac7068399d0a01dbad89f8c579f07Eli Friedman case LambdaExprContext: 173614f78f4a11df4c06667e2cbb87eeb179e4cb46feRichard Smith case ConversionIdContext: 1737c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TemplateTypeArgContext: 17387796eb5643244f3134834253ce5ea89107ac21c1Richard Smith case TrailingReturnContext: 1739c05a94b7accd4035bf5d5897c434c445b22da855John McCall return false; 1740c05a94b7accd4035bf5d5897c434c445b22da855John McCall } 1741c05a94b7accd4035bf5d5897c434c445b22da855John McCall llvm_unreachable("unknown context kind!"); 17425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 174373a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis 1744a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith /// diagnoseIdentifier - Return true if the identifier is prohibited and 1745a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith /// should be diagnosed (because it cannot be anything else). 1746a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith bool diagnoseIdentifier() const { 1747a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith switch (Context) { 1748a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case FileContext: 1749a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case KNRTypeListContext: 1750a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case MemberContext: 1751a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case BlockContext: 1752a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case ForContext: 1753a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case ConditionContext: 1754a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case PrototypeContext: 1755fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali case LambdaExprParameterContext: 1756a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case TemplateParamContext: 1757a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case CXXCatchContext: 1758a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case ObjCCatchContext: 1759a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case TypeNameContext: 1760a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case ConversionIdContext: 1761a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case ObjCParameterContext: 1762a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case ObjCResultContext: 1763a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case BlockLiteralContext: 1764a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case CXXNewContext: 1765a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case LambdaExprContext: 1766a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith return false; 1767a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith 1768a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case AliasDeclContext: 1769a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case AliasTemplateContext: 1770a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case TemplateTypeArgContext: 1771a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith case TrailingReturnContext: 1772a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith return true; 1773a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith } 1774a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith llvm_unreachable("unknown context kind!"); 1775a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith } 1776a38253c3e7dbd2b5aadb0556845dc3848168b904Richard Smith 177773a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be 177873a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis /// followed by a C++ direct initializer, e.g. "int x(1);". 177973a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis bool mayBeFollowedByCXXDirectInit() const { 1780c05a94b7accd4035bf5d5897c434c445b22da855John McCall if (hasGroupingParens()) return false; 1781c05a94b7accd4035bf5d5897c434c445b22da855John McCall 1782cb7709c06027448c754dd03e2e521d82d04818bfRichard Smith if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) 1783cb7709c06027448c754dd03e2e521d82d04818bfRichard Smith return false; 1784cb7709c06027448c754dd03e2e521d82d04818bfRichard Smith 1785cb7709c06027448c754dd03e2e521d82d04818bfRichard Smith if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern && 1786cb7709c06027448c754dd03e2e521d82d04818bfRichard Smith Context != FileContext) 1787cb7709c06027448c754dd03e2e521d82d04818bfRichard Smith return false; 1788cb7709c06027448c754dd03e2e521d82d04818bfRichard Smith 178952f10d5f474741d2226630f576d44f1bf946d40aRichard Smith // Special names can't have direct initializers. 179052f10d5f474741d2226630f576d44f1bf946d40aRichard Smith if (Name.getKind() != UnqualifiedId::IK_Identifier) 179152f10d5f474741d2226630f576d44f1bf946d40aRichard Smith return false; 179252f10d5f474741d2226630f576d44f1bf946d40aRichard Smith 1793c05a94b7accd4035bf5d5897c434c445b22da855John McCall switch (Context) { 1794c05a94b7accd4035bf5d5897c434c445b22da855John McCall case FileContext: 1795c05a94b7accd4035bf5d5897c434c445b22da855John McCall case BlockContext: 1796c05a94b7accd4035bf5d5897c434c445b22da855John McCall case ForContext: 1797c05a94b7accd4035bf5d5897c434c445b22da855John McCall return true; 1798c05a94b7accd4035bf5d5897c434c445b22da855John McCall 17990635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith case ConditionContext: 18000635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith // This may not be followed by a direct initializer, but it can't be a 18010635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith // function declaration either, and we'd prefer to perform a tentative 18020635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith // parse in order to produce the right diagnostic. 18030635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith return true; 18040635aa75ab48c9c3b4269d266305aba77b6ec58eRichard Smith 1805c05a94b7accd4035bf5d5897c434c445b22da855John McCall case KNRTypeListContext: 1806c05a94b7accd4035bf5d5897c434c445b22da855John McCall case MemberContext: 1807c05a94b7accd4035bf5d5897c434c445b22da855John McCall case PrototypeContext: 1808fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali case LambdaExprParameterContext: 1809cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall case ObjCParameterContext: 1810cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall case ObjCResultContext: 1811c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TemplateParamContext: 1812c05a94b7accd4035bf5d5897c434c445b22da855John McCall case CXXCatchContext: 181317b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis case ObjCCatchContext: 1814c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TypeNameContext: 18150b8c98f3ddf83adcb9e9d98b68ce38e970cdee73Argyrios Kyrtzidis case CXXNewContext: 1816162e1c1b487352434552147967c3dd296ebee2f7Richard Smith case AliasDeclContext: 18173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith case AliasTemplateContext: 1818c05a94b7accd4035bf5d5897c434c445b22da855John McCall case BlockLiteralContext: 1819f88c400085eac7068399d0a01dbad89f8c579f07Eli Friedman case LambdaExprContext: 182014f78f4a11df4c06667e2cbb87eeb179e4cb46feRichard Smith case ConversionIdContext: 1821c05a94b7accd4035bf5d5897c434c445b22da855John McCall case TemplateTypeArgContext: 18227796eb5643244f3134834253ce5ea89107ac21c1Richard Smith case TrailingReturnContext: 1823c05a94b7accd4035bf5d5897c434c445b22da855John McCall return false; 1824c05a94b7accd4035bf5d5897c434c445b22da855John McCall } 1825c05a94b7accd4035bf5d5897c434c445b22da855John McCall llvm_unreachable("unknown context kind!"); 182673a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis } 18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPastIdentifier - Return true if we have parsed beyond the point where 18295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the 18303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool isPastIdentifier() const { return Name.isValid(); } 183110bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor 183210bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor /// hasName - Whether this declarator has a name, which might be an 183310bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor /// identifier (accessible via getIdentifier()) or some kind of 183410bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor /// special C++ name (constructor, destructor, etc.). 18353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool hasName() const { 18363f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier; 183742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor } 183842a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 18393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *getIdentifier() const { 18403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Name.getKind() == UnqualifiedId::IK_Identifier) 18413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return Name.Identifier; 18423f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 18436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 1844e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor } 18453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation getIdentifierLoc() const { return Name.StartLocation; } 1846ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 18473f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Set the name of this declarator to be the given identifier. 18483f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) { 18493f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Name.setIdentifier(Id, IdLoc); 1850db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor } 18513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 1852ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to 1853ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// EndLoc, which should be the last token of the chunk. 18540b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall void AddTypeInfo(const DeclaratorChunk &TI, 18550b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes &attrs, 18560b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation EndLoc) { 18575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclTypeInfo.push_back(TI); 18580b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclTypeInfo.back().getAttrListRef() = attrs.getList(); 18590b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall getAttributePool().takeAllFrom(attrs.getPool()); 18600b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 1861ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!EndLoc.isInvalid()) 1862ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl SetRangeEnd(EndLoc); 18635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1864ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 18654ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Add a new innermost chunk to this declarator. 1866711c52bb20d0c69063b52a99826fb7d2835501f1John McCall void AddInnermostTypeInfo(const DeclaratorChunk &TI) { 1867711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclTypeInfo.insert(DeclTypeInfo.begin(), TI); 1868711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 1869711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 18704ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Return the number of types applied to this declarator. 18715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); } 18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Return the specified TypeInfo from this declarator. TypeInfo #0 is 18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// closest to the identifier. 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DeclaratorChunk &getTypeObject(unsigned i) const { 18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 18775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return DeclTypeInfo[i]; 18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclaratorChunk &getTypeObject(unsigned i) { 18805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return DeclTypeInfo[i]; 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18843cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith void DropFirstTypeObject() { 18858ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl assert(!DeclTypeInfo.empty() && "No type chunks to drop."); 18868ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl DeclTypeInfo.front().destroy(); 18878ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl DeclTypeInfo.erase(DeclTypeInfo.begin()); 18888ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl } 18898ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl 1890b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall /// Return the innermost (closest to the declarator) chunk of this 1891b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall /// declarator that is not a parens chunk, or null if there are no 1892b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall /// non-parens chunks. 1893b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall const DeclaratorChunk *getInnermostNonParenChunk() const { 1894b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 1895b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall if (!DeclTypeInfo[i].isParen()) 1896b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall return &DeclTypeInfo[i]; 1897b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall } 18986bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 1899b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall } 1900b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall 1901b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall /// Return the outermost (furthest from the declarator) chunk of 1902b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall /// this declarator that is not a parens chunk, or null if there are 1903b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall /// no non-parens chunks. 1904b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall const DeclaratorChunk *getOutermostNonParenChunk() const { 1905b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall for (unsigned i = DeclTypeInfo.size(), i_end = 0; i != i_end; --i) { 1906b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall if (!DeclTypeInfo[i-1].isParen()) 1907b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall return &DeclTypeInfo[i-1]; 1908b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall } 19096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 1910b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall } 1911b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall 19127a614d8380297fcd2bc23986241905d97222948cRichard Smith /// isArrayOfUnknownBound - This method returns true if the declarator 19137a614d8380297fcd2bc23986241905d97222948cRichard Smith /// is a declarator for an array of unknown bound (looking through 19147a614d8380297fcd2bc23986241905d97222948cRichard Smith /// parentheses). 19157a614d8380297fcd2bc23986241905d97222948cRichard Smith bool isArrayOfUnknownBound() const { 1916b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall const DeclaratorChunk *chunk = getInnermostNonParenChunk(); 1917b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall return (chunk && chunk->Kind == DeclaratorChunk::Array && 1918b2381b1c91ac5dc2407e98f36e3a6ba93d771791John McCall !chunk->Arr.NumElts); 19197a614d8380297fcd2bc23986241905d97222948cRichard Smith } 19207a614d8380297fcd2bc23986241905d97222948cRichard Smith 1921075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// isFunctionDeclarator - This method returns true if the declarator 1922075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// is a function declarator (looking through parentheses). 1923075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// If true is returned, then the reference type parameter idx is 1924075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// assigned with the index of the declaration chunk. 1925075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara bool isFunctionDeclarator(unsigned& idx) const { 1926075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 1927075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara switch (DeclTypeInfo[i].Kind) { 1928075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Function: 1929075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara idx = i; 1930075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return true; 1931075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Paren: 1932075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara continue; 1933075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Pointer: 1934075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Reference: 1935075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Array: 1936075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::BlockPointer: 1937075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::MemberPointer: 1938075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return false; 1939075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1940075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara llvm_unreachable("Invalid type chunk"); 1941075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1942075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return false; 1943075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1944075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 19455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isFunctionDeclarator - Once this declarator is fully parsed and formed, 1946075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// this method returns true if the identifier is a function declarator 1947075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// (looking through parentheses). 19485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFunctionDeclarator() const { 1949075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara unsigned index; 1950075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return isFunctionDeclarator(index); 1951075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1952075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1953075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// getFunctionTypeInfo - Retrieves the function type info object 1954075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// (looking through parentheses). 1955075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() { 1956075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara assert(isFunctionDeclarator() && "Not a function declarator!"); 19575aea91b09bdb36fba4e36c2766f3d5f9127d1e61Douglas Gregor unsigned index = 0; 1958075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara isFunctionDeclarator(index); 1959075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return DeclTypeInfo[index].Fun; 1960075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1961075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1962075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// getFunctionTypeInfo - Retrieves the function type info object 1963075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// (looking through parentheses). 1964075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const { 1965075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return const_cast<Declarator*>(this)->getFunctionTypeInfo(); 19665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1968555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor /// \brief Determine whether the declaration that will be produced from 1969555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor /// this declaration will be a function. 1970555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor /// 1971555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor /// A declaration can declare a function even if the declarator itself 1972555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor /// isn't a function declarator, if the type specifier refers to a function 1973555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor /// type. This routine checks for both cases. 1974555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor bool isDeclarationOfFunction() const; 19753cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith 19763cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith /// \brief Return true if this declaration appears in a context where a 19773cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith /// function declarator would be a function declaration. 19783cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith bool isFunctionDeclarationContext() const { 19793a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) 19803a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith return false; 19813a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith 19823a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith switch (Context) { 19833a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case FileContext: 19843a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case MemberContext: 19853a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case BlockContext: 19863a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith return true; 19873a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith 19883a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case ForContext: 19893a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case ConditionContext: 19903a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case KNRTypeListContext: 19913a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case TypeNameContext: 19923a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case AliasDeclContext: 19933a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case AliasTemplateContext: 19943a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case PrototypeContext: 1995fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali case LambdaExprParameterContext: 19963a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case ObjCParameterContext: 19973a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case ObjCResultContext: 19983a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case TemplateParamContext: 19993a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case CXXNewContext: 20003a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case CXXCatchContext: 20013a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case ObjCCatchContext: 20023a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case BlockLiteralContext: 20033a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case LambdaExprContext: 200414f78f4a11df4c06667e2cbb87eeb179e4cb46feRichard Smith case ConversionIdContext: 20053a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case TemplateTypeArgContext: 20063a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith case TrailingReturnContext: 20073a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith return false; 20083a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith } 20093a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith llvm_unreachable("unknown context kind!"); 20103a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith } 20113cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith 20123cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith /// \brief Return true if a function declarator at this position would be a 20133cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith /// function declaration. 20143cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith bool isFunctionDeclaratorAFunctionDeclaration() const { 20153cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith if (!isFunctionDeclarationContext()) 20163cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith return false; 20173cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith 20183cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith for (unsigned I = 0, N = getNumTypeObjects(); I != N; ++I) 20193cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith if (getTypeObject(I).Kind != DeclaratorChunk::Paren) 20203cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith return false; 20213cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith 20223cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith return true; 20233cdbbdc53241907939486ba4a9b0c9b5655419c3Richard Smith } 20243a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5Richard Smith 20250b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall /// takeAttributes - Takes attributes from the given parsed-attributes 20260b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall /// set and add them to this declarator. 20270b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall /// 2028aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner /// These examples both add 3 attributes to "var": 2029aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner /// short int var __attribute__((aligned(16),common,deprecated)); 2030aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner /// short int x, __attribute__((aligned(16)) var 2031aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner /// __attribute__((common,deprecated)); 20325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2033ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// Also extends the range of the declarator. 20340b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) { 20350b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall Attrs.takeAllFrom(attrs); 20361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20370b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall if (!lastLoc.isInvalid()) 20380b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SetRangeEnd(lastLoc); 20397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 20410b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall const AttributeList *getAttributes() const { return Attrs.getList(); } 20420b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributeList *getAttributes() { return Attrs.getList(); } 2043914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar 20440b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributeList *&getAttrListRef() { return Attrs.getListRef(); } 2045711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 2046478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn /// hasAttributes - do we contain any attributes? 2047478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn bool hasAttributes() const { 20487f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getAttributes() || getDeclSpec().hasAttributes()) return true; 2049478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i) 2050478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn if (getTypeObject(i).getAttrs()) 2051478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn return true; 2052478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn return false; 2053478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn } 2054478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn 205552b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han /// \brief Return a source range list of C++11 attributes associated 205652b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han /// with the declarator. 20576b9240e058bf3451685df73fc8ce181b3046e92bCraig Topper void getCXX11AttributeRanges(SmallVectorImpl<SourceRange> &Ranges) { 205852b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han AttributeList *AttrList = Attrs.getList(); 205952b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han while (AttrList) { 20604e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith if (AttrList->isCXX11Attribute()) 206152b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han Ranges.push_back(AttrList->getRange()); 206252b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han AttrList = AttrList->getNext(); 206352b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han } 206452b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han } 206552b501cd723d56efe3ad2ab708c2b75530fe6caaMichael Han 2066b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void setAsmLabel(Expr *E) { AsmLabel = E; } 2067b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *getAsmLabel() const { return AsmLabel; } 2068914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar 206991a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor void setExtension(bool Val = true) { Extension = Val; } 207091a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor bool getExtension() const { return Extension; } 207191a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor 2072eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattner void setInvalidType(bool Val = true) { InvalidType = Val; } 20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isInvalidType() const { 20741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error; 2075cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor } 207673a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis 207773a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis void setGroupingParens(bool flag) { GroupingParens = flag; } 207873a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis bool hasGroupingParens() const { return GroupingParens; } 20797984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith 20807984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith bool isFirstDeclarator() const { return !CommaLoc.isValid(); } 20817984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith SourceLocation getCommaLoc() const { return CommaLoc; } 20827984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith void setCommaLoc(SourceLocation CL) { CommaLoc = CL; } 20837984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith 2084a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor bool hasEllipsis() const { return EllipsisLoc.isValid(); } 2085a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 2086a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; } 20872c712f50cd56eaf3662989b556e9c6b1e8fcd11aKaelyn Uhrain 208845fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor void setFunctionDefinitionKind(FunctionDefinitionKind Val) { 208945fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FunctionDefinition = Val; 209045fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor } 209145fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor 209245fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor bool isFunctionDefinition() const { 209345fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor return getFunctionDefinitionKind() != FDK_Declaration; 209445fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor } 209545fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor 209645fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FunctionDefinitionKind getFunctionDefinitionKind() const { 209745fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor return (FunctionDefinitionKind)FunctionDefinition; 209845fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor } 20992c712f50cd56eaf3662989b556e9c6b1e8fcd11aKaelyn Uhrain 2100d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner /// Returns true if this declares a real member and not a friend. 2101d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner bool isFirstDeclarationOfMember() { 2102d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner return getContext() == MemberContext && !getDeclSpec().isFriendSpecified(); 2103d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner } 2104d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner 2105d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner /// Returns true if this declares a static member. This cannot be called on a 2106d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner /// declarator outside of a MemberContext because we won't know until 2107d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner /// redeclaration time if the decl is static. 2108d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner bool isStaticMember(); 2109d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner 21102c712f50cd56eaf3662989b556e9c6b1e8fcd11aKaelyn Uhrain void setRedeclaration(bool Val) { Redeclaration = Val; } 21112c712f50cd56eaf3662989b556e9c6b1e8fcd11aKaelyn Uhrain bool isRedeclaration() const { return Redeclaration; } 21125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21144ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief This little struct is used to capture information about 2115e13594279a952537ac903325efff57e3edca79d9Chris Lattner/// structure field declarators, which is basically just a bitfield size. 2116e13594279a952537ac903325efff57e3edca79d9Chris Lattnerstruct FieldDeclarator { 2117e13594279a952537ac903325efff57e3edca79d9Chris Lattner Declarator D; 2118b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *BitfieldSize; 2119f66a0dda541cd859a928193efba6dc5d7ba8fe54Eli Friedman explicit FieldDeclarator(const DeclSpec &DS) 21206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines : D(DS, Declarator::MemberContext), BitfieldSize(nullptr) { } 2121e13594279a952537ac903325efff57e3edca79d9Chris Lattner}; 2122b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 21234ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief Represents a C++11 virt-specifier-seq. 2124b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonclass VirtSpecifiers { 2125b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonpublic: 2126cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson enum Specifier { 2127b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson VS_None = 0, 2128b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson VS_Override = 1, 21297121bdb91b86f6053765bda18dd0a8a118929aceDavid Majnemer VS_Final = 2, 21307121bdb91b86f6053765bda18dd0a8a118929aceDavid Majnemer VS_Sealed = 4 2131b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson }; 2132b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 2133b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson VirtSpecifiers() : Specifiers(0) { } 2134b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 2135cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson bool SetSpecifier(Specifier VS, SourceLocation Loc, 213646127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson const char *&PrevSpec); 2137b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 2138651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool isUnset() const { return Specifiers == 0; } 2139651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2140aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson bool isOverrideSpecified() const { return Specifiers & VS_Override; } 2141aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson SourceLocation getOverrideLoc() const { return VS_overrideLoc; } 2142aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson 21437121bdb91b86f6053765bda18dd0a8a118929aceDavid Majnemer bool isFinalSpecified() const { return Specifiers & (VS_Final | VS_Sealed); } 21447121bdb91b86f6053765bda18dd0a8a118929aceDavid Majnemer bool isFinalSpelledSealed() const { return Specifiers & VS_Sealed; } 2145aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson SourceLocation getFinalLoc() const { return VS_finalLoc; } 2146aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson 21474867347e82648d3baf09524b98b09c297a5a198fNico Weber void clear() { Specifiers = 0; } 21484867347e82648d3baf09524b98b09c297a5a198fNico Weber 2149ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson static const char *getSpecifierName(Specifier VS); 2150ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson 2151f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor SourceLocation getLastLocation() const { return LastLocation; } 2152f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor 2153b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonprivate: 2154b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson unsigned Specifiers; 2155b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 2156b1f39680a2e3bce508dba0600665860e5ba5fb70Anders Carlsson SourceLocation VS_overrideLoc, VS_finalLoc; 2157f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor SourceLocation LastLocation; 2158b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson}; 2159b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 21604ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett/// \brief Represents a complete lambda introducer. 2161ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregorstruct LambdaIntroducer { 21626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// \brief An individual capture in a lambda introducer. 21636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines struct LambdaCapture { 21646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LambdaCaptureKind Kind; 21656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation Loc; 21666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines IdentifierInfo *Id; 21676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation EllipsisLoc; 21686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ExprResult Init; 21696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParsedType InitCaptureType; 21706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc, 21716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines IdentifierInfo *Id, SourceLocation EllipsisLoc, 21726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ExprResult Init, ParsedType InitCaptureType) 21736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc), Init(Init), 21746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines InitCaptureType(InitCaptureType) {} 21756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines }; 21766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 2177ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor SourceRange Range; 21783ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor SourceLocation DefaultLoc; 2179ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaCaptureDefault Default; 2180cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<LambdaCapture, 4> Captures; 2181ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 2182ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaIntroducer() 2183ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor : Default(LCD_None) {} 2184ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 21854ae383f1d5c6505cdc60005cecfc20afc2ca7817James Dennett /// \brief Append a capture in a lambda introducer. 2186ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor void addCapture(LambdaCaptureKind Kind, 2187ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor SourceLocation Loc, 21882434dcfb022778b06cfd257d830d0249680b87cfBill Wendling IdentifierInfo* Id, 21892434dcfb022778b06cfd257d830d0249680b87cfBill Wendling SourceLocation EllipsisLoc, 21902434dcfb022778b06cfd257d830d0249680b87cfBill Wendling ExprResult Init, 21912434dcfb022778b06cfd257d830d0249680b87cfBill Wendling ParsedType InitCaptureType) { 21922434dcfb022778b06cfd257d830d0249680b87cfBill Wendling Captures.push_back(LambdaCapture(Kind, Loc, Id, EllipsisLoc, Init, 21932434dcfb022778b06cfd257d830d0249680b87cfBill Wendling InitCaptureType)); 2194ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor } 2195ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor}; 2196ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 219737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff} // end namespace clang 21985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2200