15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===//
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//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file implements semantic analysis for declaration specifiers.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1419510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Parse/ParseDiagnostic.h" // FIXME: remove this back-dependency!
1519510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h"
16555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor#include "clang/Sema/LocInfoType.h"
1719510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/ParsedTemplate.h"
18841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith#include "clang/Sema/SemaDiagnostic.h"
19b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne#include "clang/Sema/Sema.h"
20c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor#include "clang/AST/ASTContext.h"
21555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor#include "clang/AST/Expr.h"
222e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
232e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor#include "clang/AST/TypeLoc.h"
249b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor#include "clang/Lex/Preprocessor.h"
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/LangOptions.h"
265af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner#include "llvm/ADT/STLExtras.h"
2732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall#include "llvm/Support/ErrorHandling.h"
28e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include <cstring>
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang;
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
31254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner
32d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikiestatic DiagnosticBuilder Diag(DiagnosticsEngine &D, SourceLocation Loc,
3333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis                              unsigned DiagID) {
3433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  return D.Report(Loc, DiagID);
35254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner}
36254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner
37314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor
38314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregorvoid UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) {
39314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  assert(TemplateId && "NULL template-id annotation?");
40314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  Kind = IK_TemplateId;
41314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  this->TemplateId = TemplateId;
42314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  StartLocation = TemplateId->TemplateNameLoc;
43314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  EndLocation = TemplateId->RAngleLoc;
44314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor}
45314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor
460efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregorvoid UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) {
470efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  assert(TemplateId && "NULL template-id annotation?");
480efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  Kind = IK_ConstructorTemplateId;
490efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  this->TemplateId = TemplateId;
500efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  StartLocation = TemplateId->TemplateNameLoc;
510efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  EndLocation = TemplateId->RAngleLoc;
520efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor}
530efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor
542e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregorvoid CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc,
552e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          TypeLoc TL, SourceLocation ColonColonLoc) {
565f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc);
572e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  if (Range.getBegin().isInvalid())
582e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    Range.setBegin(TL.getBeginLoc());
592e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  Range.setEnd(ColonColonLoc);
60c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
615f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
62c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
632e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor}
642e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
652e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregorvoid CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier,
662e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          SourceLocation IdentifierLoc,
672e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          SourceLocation ColonColonLoc) {
685f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc);
695f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor
702e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  if (Range.getBegin().isInvalid())
712e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    Range.setBegin(IdentifierLoc);
722e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  Range.setEnd(ColonColonLoc);
73c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
745f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
75c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
762e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor}
772e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
782e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregorvoid CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace,
792e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          SourceLocation NamespaceLoc,
802e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          SourceLocation ColonColonLoc) {
815f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc);
825f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor
832e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  if (Range.getBegin().isInvalid())
842e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    Range.setBegin(NamespaceLoc);
852e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  Range.setEnd(ColonColonLoc);
86c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
875f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
88c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
892e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor}
902e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
9114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregorvoid CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
9214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor                          SourceLocation AliasLoc,
9314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor                          SourceLocation ColonColonLoc) {
945f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc);
955f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor
9614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  if (Range.getBegin().isInvalid())
9714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor    Range.setBegin(AliasLoc);
9814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  Range.setEnd(ColonColonLoc);
99c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1005f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
101c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
10214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor}
10314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor
1042e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregorvoid CXXScopeSpec::MakeGlobal(ASTContext &Context,
1052e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                              SourceLocation ColonColonLoc) {
1065f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.MakeGlobal(Context, ColonColonLoc);
107c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1085f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Range = SourceRange(ColonColonLoc);
109c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1105f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
111c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
112c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor}
113c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
114c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregorvoid CXXScopeSpec::MakeTrivial(ASTContext &Context,
115c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor                               NestedNameSpecifier *Qualifier, SourceRange R) {
1165f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.MakeTrivial(Context, Qualifier, R);
117c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  Range = R;
118c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor}
119c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
120c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregorvoid CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) {
121c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  if (!Other) {
122c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor    Range = SourceRange();
1235f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor    Builder.Clear();
124c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor    return;
125c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  }
1265f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor
127c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  Range = Other.getSourceRange();
1285f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Adopt(Other);
129c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor}
130c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1319dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCallSourceLocation CXXScopeSpec::getLastQualifierNameLoc() const {
1329dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall  if (!Builder.getRepresentation())
1339dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall    return SourceLocation();
1349dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall  return Builder.getTemporary().getLocalBeginLoc();
1359dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall}
1369dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall
137c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc
138c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorCXXScopeSpec::getWithLocInContext(ASTContext &Context) const {
139b46ae3964ba02535276c71332396e9a7bad2dfa5Douglas Gregor  if (!Builder.getRepresentation())
140c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor    return NestedNameSpecifierLoc();
141c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1425f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  return Builder.getWithLocInContext(Context);
1432e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor}
1442e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
1455af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
1465af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner/// "TheDeclarator" is the declarator that this will be added to.
1470b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCallDeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic,
148b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith                                             bool isAmbiguous,
149965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor                                             SourceLocation EllipsisLoc,
1505af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner                                             ParamInfo *ArgInfo,
1515af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner                                             unsigned NumArgs,
1525af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner                                             unsigned TypeQuals,
15383f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor                                             bool RefQualifierIsLvalueRef,
15483f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor                                             SourceLocation RefQualifierLoc,
15543f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor                                             SourceLocation ConstQualifierLoc,
15643f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor                                             SourceLocation
15743f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor                                                 VolatileQualifierLoc,
15890ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor                                             SourceLocation MutableLoc,
1596e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                             ExceptionSpecificationType
1606e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                                 ESpecType,
1616e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                             SourceLocation ESpecLoc,
162b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                             ParsedType *Exceptions,
163ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl                                             SourceRange *ExceptionRanges,
1647dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl                                             unsigned NumExceptions,
1656e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                             Expr *NoexceptExpr,
166796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara                                             SourceLocation LocalRangeBegin,
167796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara                                             SourceLocation LocalRangeEnd,
168dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor                                             Declarator &TheDeclarator,
16954655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith                                             TypeResult TrailingReturnType) {
1705af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  DeclaratorChunk I;
1716e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Kind                        = Function;
172796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  I.Loc                         = LocalRangeBegin;
173796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  I.EndLoc                      = LocalRangeEnd;
1740b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  I.Fun.AttrList                = 0;
1756e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.hasPrototype            = hasProto;
1766e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.isVariadic              = isVariadic;
177b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith  I.Fun.isAmbiguous             = isAmbiguous;
1786e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.EllipsisLoc             = EllipsisLoc.getRawEncoding();
1796e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.DeleteArgInfo           = false;
1806e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.TypeQuals               = TypeQuals;
1816e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.NumArgs                 = NumArgs;
1826e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.ArgInfo                 = 0;
18383f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor  I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
1846e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.RefQualifierLoc         = RefQualifierLoc.getRawEncoding();
18543f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor  I.Fun.ConstQualifierLoc       = ConstQualifierLoc.getRawEncoding();
18643f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor  I.Fun.VolatileQualifierLoc    = VolatileQualifierLoc.getRawEncoding();
18790ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor  I.Fun.MutableLoc              = MutableLoc.getRawEncoding();
1886e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.ExceptionSpecType       = ESpecType;
1896e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.ExceptionSpecLoc        = ESpecLoc.getRawEncoding();
1906e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.NumExceptions           = 0;
1916e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.Exceptions              = 0;
1926e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.NoexceptExpr            = 0;
19354655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith  I.Fun.HasTrailingReturnType   = TrailingReturnType.isUsable() ||
19454655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith                                  TrailingReturnType.isInvalid();
19554655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith  I.Fun.TrailingReturnType      = TrailingReturnType.get();
1967dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
1975af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  // new[] an argument array if needed.
1985af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  if (NumArgs) {
1995af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    // If the 'InlineParams' in Declarator is unused and big enough, put our
2005af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    // parameter list there (in an effort to avoid new/delete traffic).  If it
2015af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    // is already used (consider a function returning a function pointer) or too
2025af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    // small (function taking too many arguments), go to the heap.
2031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (!TheDeclarator.InlineParamsUsed &&
2045af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner        NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
2055af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      I.Fun.ArgInfo = TheDeclarator.InlineParams;
2065af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      I.Fun.DeleteArgInfo = false;
2075af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      TheDeclarator.InlineParamsUsed = true;
2085af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    } else {
2095af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs];
2105af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      I.Fun.DeleteArgInfo = true;
2115af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    }
2125af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
2135af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  }
2146e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
2156e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  // Check what exception specification information we should actually store.
2166e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  switch (ESpecType) {
2176e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  default: break; // By default, save nothing.
2186e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  case EST_Dynamic:
2196e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    // new[] an exception array if needed
2206e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    if (NumExceptions) {
2216e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      I.Fun.NumExceptions = NumExceptions;
2226e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
2236e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      for (unsigned i = 0; i != NumExceptions; ++i) {
2246e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl        I.Fun.Exceptions[i].Ty = Exceptions[i];
2256e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl        I.Fun.Exceptions[i].Range = ExceptionRanges[i];
2266e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      }
227ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl    }
2286e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    break;
2296e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
2306e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  case EST_ComputedNoexcept:
2316e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    I.Fun.NoexceptExpr = NoexceptExpr;
2326e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    break;
2337dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl  }
2345af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  return I;
2355af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner}
236254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner
237555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregorbool Declarator::isDeclarationOfFunction() const {
2381ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith  for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
2391ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    switch (DeclTypeInfo[i].Kind) {
2401ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Function:
2411ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith      return true;
2421ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Paren:
2431ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith      continue;
2441ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Pointer:
2451ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Reference:
2461ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Array:
2471ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::BlockPointer:
2481ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::MemberPointer:
2491ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith      return false;
2501ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    }
2511ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    llvm_unreachable("Invalid type chunk");
2521ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith  }
253555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
254555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor  switch (DS.getTypeSpecType()) {
255b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    case TST_atomic:
256555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_auto:
257555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_bool:
258555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_char:
259555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_char16:
260555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_char32:
261555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_class:
262555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_decimal128:
263555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_decimal32:
264555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_decimal64:
265555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_double:
266555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_enum:
267555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_error:
268555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_float:
269aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov    case TST_half:
270555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_int:
2715a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith    case TST_int128:
272555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_struct:
2736666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos    case TST_interface:
274555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_union:
275555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_unknown_anytype:
276555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_unspecified:
277555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_void:
278555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_wchar:
279555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      return false;
280555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
281555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_decltype:
282555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_typeofExpr:
283555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      if (Expr *E = DS.getRepAsExpr())
284555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor        return E->getType()->isFunctionType();
285555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      return false;
286555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
287555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_underlyingType:
288555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_typename:
289555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_typeofType: {
290555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      QualType QT = DS.getRepAsType().get();
291555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      if (QT.isNull())
292555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor        return false;
293555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
294555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
295555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor        QT = LIT->getType();
296555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
297555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      if (QT.isNull())
298555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor        return false;
299555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
300555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      return QT->isFunctionType();
301555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    }
302555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor  }
3037530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie
3047530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie  llvm_unreachable("Invalid TypeSpecType!");
305555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor}
306555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
3082a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner/// declaration specifier includes.
3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerunsigned DeclSpec::getParsedSpecifiers() const {
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Res = 0;
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (StorageClassSpec != SCS_unspecified ||
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      SCS_thread_specified)
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Res |= PQ_StorageClassSpecifier;
315d42043333a6d6bd35d641efe44b9b40819169384Mike Stump
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeQualifiers != TQ_unspecified)
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Res |= PQ_TypeQualifier;
3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (hasTypeSpecifier())
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Res |= PQ_TypeSpecifier;
3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
322b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified)
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Res |= PQ_FunctionSpecifier;
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return Res;
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
327fec54013fcd0eb72642741584ca04c1bc292bef8John McCalltemplate <class T> static bool BadSpecifier(T TNew, T TPrev,
328fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                            const char *&PrevSpec,
329c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman                                            unsigned &DiagID,
330c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman                                            bool IsExtension = true) {
33132d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  PrevSpec = DeclSpec::getSpecifierName(TPrev);
332c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  if (TNew != TPrev)
333c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman    DiagID = diag::err_invalid_decl_spec_combination;
334c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  else
335c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman    DiagID = IsExtension ? diag::ext_duplicate_declspec :
336c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman                           diag::warn_duplicate_declspec;
33732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  return true;
3381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
33932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *DeclSpec::getSpecifierName(DeclSpec::SCS S) {
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (S) {
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_unspecified: return "unspecified";
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_typedef:     return "typedef";
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_extern:      return "extern";
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_static:      return "static";
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_auto:        return "auto";
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_register:    return "register";
34863054b39a27ff333487e88247d495a444838b44aEli Friedman  case DeclSpec::SCS_private_extern: return "__private_extern__";
349669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl  case DeclSpec::SCS_mutable:     return "mutable";
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3519f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
35432d335e63bd287e5c9297532171284cdf4c7888cJohn McCallconst char *DeclSpec::getSpecifierName(TSW W) {
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (W) {
35632d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSW_unspecified: return "unspecified";
35732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSW_short:       return "short";
35832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSW_long:        return "long";
35932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSW_longlong:    return "long long";
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3619f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
36432d335e63bd287e5c9297532171284cdf4c7888cJohn McCallconst char *DeclSpec::getSpecifierName(TSC C) {
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (C) {
36632d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSC_unspecified: return "unspecified";
36732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSC_imaginary:   return "imaginary";
36832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSC_complex:     return "complex";
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3709f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
37432d335e63bd287e5c9297532171284cdf4c7888cJohn McCallconst char *DeclSpec::getSpecifierName(TSS S) {
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (S) {
37632d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSS_unspecified: return "unspecified";
37732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSS_signed:      return "signed";
37832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSS_unsigned:    return "unsigned";
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3809f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (T) {
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_unspecified: return "unspecified";
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_void:        return "void";
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_char:        return "char";
38864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis  case DeclSpec::TST_wchar:       return "wchar_t";
389f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  case DeclSpec::TST_char16:      return "char16_t";
390f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  case DeclSpec::TST_char32:      return "char32_t";
3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_int:         return "int";
3925a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith  case DeclSpec::TST_int128:      return "__int128";
393aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  case DeclSpec::TST_half:        return "half";
3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_float:       return "float";
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_double:      return "double";
3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_bool:        return "_Bool";
3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_decimal32:   return "_Decimal32";
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_decimal64:   return "_Decimal64";
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_decimal128:  return "_Decimal128";
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_enum:        return "enum";
40199dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner  case DeclSpec::TST_class:       return "class";
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_union:       return "union";
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_struct:      return "struct";
4046666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos  case DeclSpec::TST_interface:   return "__interface";
4051a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor  case DeclSpec::TST_typename:    return "type-name";
406d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  case DeclSpec::TST_typeofType:
407d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  case DeclSpec::TST_typeofExpr:  return "typeof";
40832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TST_auto:        return "auto";
40932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TST_decltype:    return "(decltype)";
410ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  case DeclSpec::TST_underlyingType: return "__underlying_type";
411a5fc472b353b88be3b4981da946fb01f5a5cc0c6John McCall  case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
412b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  case DeclSpec::TST_atomic: return "_Atomic";
41332d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TST_error:       return "(error)";
4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4159f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
41832d335e63bd287e5c9297532171284cdf4c7888cJohn McCallconst char *DeclSpec::getSpecifierName(TQ T) {
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (T) {
42032d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TQ_unspecified: return "unspecified";
42132d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TQ_const:       return "const";
42232d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TQ_restrict:    return "restrict";
42332d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TQ_volatile:    return "volatile";
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4259f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
428b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbournebool DeclSpec::SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
429fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                   const char *&PrevSpec,
430b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne                                   unsigned &DiagID) {
4315e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner  // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class
4325e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner  // specifiers are not supported.
433e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne  // It seems sensible to prohibit private_extern too
434b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne  // The cl_clang_storage_class_specifiers extension enables support for
435b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne  // these storage-class specifiers.
4365e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner  // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class
4375e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner  // specifiers are not supported."
4384e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (S.getLangOpts().OpenCL &&
439b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne      !S.getOpenCLOptions().cl_clang_storage_class_specifiers) {
440b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne    switch (SC) {
441e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    case SCS_extern:
442e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    case SCS_private_extern:
4435e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner    case SCS_static:
4445e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner        if (S.getLangOpts().OpenCLVersion < 120) {
4455e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner          DiagID   = diag::err_not_opencl_storage_class_specifier;
4465e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner          PrevSpec = getSpecifierName(SC);
4475e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner          return true;
4485e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner        }
4495e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner        break;
450e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    case SCS_auto:
451e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    case SCS_register:
452e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne      DiagID   = diag::err_not_opencl_storage_class_specifier;
453b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne      PrevSpec = getSpecifierName(SC);
454e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne      return true;
455e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    default:
456e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne      break;
457e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    }
458e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne  }
459e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne
46035f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  if (StorageClassSpec != SCS_unspecified) {
4618f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    // Maybe this is an attempt to use C++0x 'auto' outside of C++0x mode.
4628f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    bool isInvalid = true;
4634e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) {
464b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne      if (SC == SCS_auto)
4658f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith        return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID);
4668f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      if (StorageClassSpec == SCS_auto) {
4678f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith        isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc,
4688f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith                                    PrevSpec, DiagID);
4698f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith        assert(!isInvalid && "auto SCS -> TST recovery failed");
4708f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      }
4718f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    }
4728f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith
47335f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    // Changing storage class is allowed only if the previous one
47435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    // was the 'extern' that is part of a linkage specification and
47535f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    // the new storage class is 'typedef'.
4768f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    if (isInvalid &&
4778f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith        !(SCS_extern_in_linkage_spec &&
47835f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara          StorageClassSpec == SCS_extern &&
479b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne          SC == SCS_typedef))
480b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne      return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID);
48135f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  }
482b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne  StorageClassSpec = SC;
4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  StorageClassSpecLoc = Loc;
484b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne  assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc,
489fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                         const char *&PrevSpec,
490fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                         unsigned &DiagID) {
4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (SCS_thread_specified) {
4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PrevSpec = "__thread";
493fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    DiagID = diag::ext_duplicate_declspec;
4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return true;
4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SCS_thread_specified = true;
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SCS_threadLoc = Loc;
4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// These methods set the specified attribute of the DeclSpec, but return true
5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// and ignore the request if invalid (e.g. "extern" then "auto" is
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified).
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc,
505fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                const char *&PrevSpec,
506fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                unsigned &DiagID) {
5072553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
5082553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  // for 'long long' we will keep the source location of the first 'long'.
5092553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  if (TypeSpecWidth == TSW_unspecified)
5102553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara    TSWLoc = Loc;
5112553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  // Allow turning long -> long long.
5122553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
513fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSpecWidth = W;
515788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (TypeAltiVecVector && !TypeAltiVecBool &&
516788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) {
51782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
51882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    DiagID = diag::warn_vector_long_decl_spec_combination;
51982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    return true;
52082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc,
525fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                  const char *&PrevSpec,
526fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                  unsigned &DiagID) {
5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeSpecComplex != TSC_unspecified)
528fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSpecComplex = C;
5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TSCLoc = Loc;
5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc,
535fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               const char *&PrevSpec,
536fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               unsigned &DiagID) {
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeSpecSign != TSS_unspecified)
538fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID);
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSpecSign = S;
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TSSLoc = Loc;
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
545fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               const char *&PrevSpec,
546fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               unsigned &DiagID,
547b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               ParsedType Rep) {
5480daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep);
5490daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara}
5500daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara
5510daaf32723ac78549c507c2a68a5300502703673Abramo Bagnarabool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
5520daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               SourceLocation TagNameLoc,
5530daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               const char *&PrevSpec,
5540daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               unsigned &DiagID,
5550daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               ParsedType Rep) {
556b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(isTypeRep(T) && "T does not store a type");
557b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(Rep && "no type provided!");
558b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  if (TypeSpecType != TST_unspecified) {
559b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
560b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    DiagID = diag::err_invalid_decl_spec_combination;
561b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return true;
562b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
563b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecType = T;
564b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeRep = Rep;
5650daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTLoc = TagKwLoc;
5660daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = TagNameLoc;
567b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecOwned = false;
568b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return false;
569b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall}
570b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
571b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallbool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
572b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               const char *&PrevSpec,
573b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               unsigned &DiagID,
574b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               Expr *Rep) {
575b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(isExprRep(T) && "T does not store an expr");
576b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(Rep && "no expression provided!");
577b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  if (TypeSpecType != TST_unspecified) {
578b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
579b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    DiagID = diag::err_invalid_decl_spec_combination;
580b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return true;
581b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
582b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecType = T;
583b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ExprRep = Rep;
584b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TSTLoc = Loc;
5850daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = Loc;
586b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecOwned = false;
587b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return false;
588b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall}
589b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
590b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallbool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
591b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               const char *&PrevSpec,
592b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               unsigned &DiagID,
593b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               Decl *Rep, bool Owned) {
5940daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned);
5950daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara}
5960daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara
5970daaf32723ac78549c507c2a68a5300502703673Abramo Bagnarabool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
5980daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               SourceLocation TagNameLoc,
5990daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               const char *&PrevSpec,
6000daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               unsigned &DiagID,
6010daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               Decl *Rep, bool Owned) {
602b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(isDeclRep(T) && "T does not store a decl");
603b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  // Unlike the other cases, we don't assert that we actually get a decl.
604b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
605b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  if (TypeSpecType != TST_unspecified) {
606b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
607b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    DiagID = diag::err_invalid_decl_spec_combination;
608b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return true;
609b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
610b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecType = T;
611b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  DeclRep = Rep;
6120daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTLoc = TagKwLoc;
6130daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = TagNameLoc;
614b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecOwned = Owned;
615b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return false;
616b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall}
617b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
618b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallbool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
619b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               const char *&PrevSpec,
620b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               unsigned &DiagID) {
621b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) &&
622b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall         "rep required for these type-spec kinds!");
623fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  if (TypeSpecType != TST_unspecified) {
624fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
625fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    DiagID = diag::err_invalid_decl_spec_combination;
626fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    return true;
627fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  }
6280daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTLoc = Loc;
6290daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = Loc;
630788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) {
631788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    TypeAltiVecBool = true;
632788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    return false;
633788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  }
6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSpecType = T;
635b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecOwned = false;
636788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) {
63782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
638788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    DiagID = diag::err_invalid_vector_decl_spec;
63982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    return true;
64082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
64182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  return false;
64282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson}
64382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
64482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompsonbool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
64582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                          const char *&PrevSpec, unsigned &DiagID) {
64682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  if (TypeSpecType != TST_unspecified) {
64782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
64882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    DiagID = diag::err_invalid_vector_decl_spec_combination;
64982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    return true;
65082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
65182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  TypeAltiVecVector = isAltiVecVector;
65282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  AltiVecLoc = Loc;
65382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  return false;
65482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson}
65582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
65682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompsonbool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
65782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                          const char *&PrevSpec, unsigned &DiagID) {
658788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (!TypeAltiVecVector || TypeAltiVecPixel ||
659788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      (TypeSpecType != TST_unspecified)) {
66082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
66182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    DiagID = diag::err_invalid_pixel_decl_spec_combination;
66282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    return true;
66382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
66482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  TypeAltiVecPixel = isAltiVecPixel;
66582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  TSTLoc = Loc;
6660daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = Loc;
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
670ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregorbool DeclSpec::SetTypeSpecError() {
671ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  TypeSpecType = TST_error;
6729e46b8cfb3e6c6feab5664744f52f06a40f9566bJohn McCall  TypeSpecOwned = false;
673ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  TSTLoc = SourceLocation();
6740daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = SourceLocation();
675ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  return false;
676ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor}
677ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
67942926a065572a63610f651bb1589fe1217e2e0a7Richard Smith                           unsigned &DiagID, const LangOptions &Lang,
68042926a065572a63610f651bb1589fe1217e2e0a7Richard Smith                           bool IsTypeSpec) {
68142926a065572a63610f651bb1589fe1217e2e0a7Richard Smith  // Duplicates are permitted in C99, and are permitted in C++11 unless the
682c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  // cv-qualifier appears as a type-specifier.  However, since this is likely
683c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  // not what the user intended, we will always warn.  We do not need to set the
684c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  // qualifier's location since we already have it.
685c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  if (TypeQualifiers & T) {
686a14f400e4c4239b92137fc8aab1ac4700a209591Aaron Ballman    bool IsExtension = true;
687c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman    if (Lang.C99 || (Lang.CPlusPlus0x && !IsTypeSpec))
688a14f400e4c4239b92137fc8aab1ac4700a209591Aaron Ballman      IsExtension = false;
689c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman    return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension);
690c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  }
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeQualifiers |= T;
6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (T) {
694b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  default: llvm_unreachable("Unknown type qualifier!");
6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TQ_const:    TQ_constLoc = Loc; break;
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TQ_restrict: TQ_restrictLoc = Loc; break;
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TQ_volatile: TQ_volatileLoc = Loc; break;
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
702fec54013fcd0eb72642741584ca04c1bc292bef8John McCallbool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
703fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                     unsigned &DiagID) {
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // 'inline inline' is ok.
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FS_inline_specified = true;
7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FS_inlineLoc = Loc;
7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
710fec54013fcd0eb72642741584ca04c1bc292bef8John McCallbool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
711fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                      unsigned &DiagID) {
712b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  // 'virtual virtual' is ok.
713b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  FS_virtual_specified = true;
714b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  FS_virtualLoc = Loc;
715b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  return false;
716b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor}
717b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor
718fec54013fcd0eb72642741584ca04c1bc292bef8John McCallbool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
719fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                       unsigned &DiagID) {
720b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  // 'explicit explicit' is ok.
721b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  FS_explicit_specified = true;
722b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  FS_explicitLoc = Loc;
723b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  return false;
724b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor}
725b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor
726fec54013fcd0eb72642741584ca04c1bc292bef8John McCallbool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
727fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                             unsigned &DiagID) {
728f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  if (Friend_specified) {
729f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson    PrevSpec = "friend";
730fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    DiagID = diag::ext_duplicate_declspec;
731f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson    return true;
732f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  }
733fec54013fcd0eb72642741584ca04c1bc292bef8John McCall
734f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  Friend_specified = true;
735f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  FriendLoc = Loc;
736f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  return false;
737f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson}
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7398d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregorbool DeclSpec::setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
7408d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor                                    unsigned &DiagID) {
7418d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  if (isModulePrivateSpecified()) {
7428d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor    PrevSpec = "__module_private__";
7438d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor    DiagID = diag::ext_duplicate_declspec;
7448d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor    return true;
7458d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  }
7468d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
7478d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  ModulePrivateLoc = Loc;
7488d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  return false;
7498d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor}
7508d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
7512ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redlbool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
7522ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl                                unsigned &DiagID) {
7532ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  // 'constexpr constexpr' is ok.
7542ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  Constexpr_specified = true;
7552ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  ConstexprLoc = Loc;
7562ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  return false;
7572ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl}
7582ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl
759d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid DeclSpec::setProtocolQualifiers(Decl * const *Protos,
760e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis                                     unsigned NP,
761e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis                                     SourceLocation *ProtoLocs,
762e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis                                     SourceLocation LAngleLoc) {
763e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  if (NP == 0) return;
764d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  ProtocolQualifiers = new Decl*[NP];
765e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  ProtocolLocs = new SourceLocation[NP];
766d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  memcpy((void*)ProtocolQualifiers, Protos, sizeof(Decl*)*NP);
767e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP);
768e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  NumProtocolQualifiers = NP;
769e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  ProtocolLAngleLoc = LAngleLoc;
770e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis}
771e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis
772ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorvoid DeclSpec::SaveWrittenBuiltinSpecs() {
773ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  writtenBS.Sign = getTypeSpecSign();
774ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  writtenBS.Width = getTypeSpecWidth();
775ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  writtenBS.Type = getTypeSpecType();
776ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  // Search the list of attributes for the presence of a mode attribute.
777ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  writtenBS.ModeAttr = false;
7787f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  AttributeList* attrs = getAttributes().getList();
779ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  while (attrs) {
7808e083e71d48f7f4d6ef40c00531c2e14df745486Sean Hunt    if (attrs->getKind() == AttributeList::AT_Mode) {
781ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      writtenBS.ModeAttr = true;
782ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      break;
783ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    }
784ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    attrs = attrs->getNext();
785ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
786ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor}
787ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
78835f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnaravoid DeclSpec::SaveStorageSpecifierAsWritten() {
78935f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  if (SCS_extern_in_linkage_spec && StorageClassSpec == SCS_extern)
79035f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    // If 'extern' is part of a linkage specification,
79135f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    // then it is not a storage class "as written".
79235f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    StorageClassSpecAsWritten = SCS_unspecified;
79335f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  else
79435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    StorageClassSpecAsWritten = StorageClassSpec;
79535f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara}
79635f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Finish - This does final analysis of the declspec, rejecting things like
7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// "_Imaginary" (lacking an FP type).  This returns a diagnostic to issue or
7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// diag::NUM_DIAGNOSTICS if there is no error.  After calling this method,
8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclSpec is guaranteed self-consistent, even if an error occurred.
801d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikievoid DeclSpec::Finish(DiagnosticsEngine &D, Preprocessor &PP) {
802ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  // Before possibly changing their values, save specs as written.
803ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  SaveWrittenBuiltinSpecs();
80416573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor  SaveStorageSpecifierAsWritten();
805ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Check the type specifier components first.
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
808788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  // Validate and finalize AltiVec vector declspec.
809788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (TypeAltiVecVector) {
810788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    if (TypeAltiVecBool) {
811788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      // Sign specifiers are not allowed with vector bool. (PIM 2.1)
812788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      if (TypeSpecSign != TSS_unspecified) {
81333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis        Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec)
814788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner          << getSpecifierName((TSS)TypeSpecSign);
815788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      }
816788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
817788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      // Only char/int are valid with vector bool. (PIM 2.1)
8182e964a922c0826a1216d101df315432c6a0a78f6Duncan Sands      if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) &&
8192e964a922c0826a1216d101df315432c6a0a78f6Duncan Sands           (TypeSpecType != TST_int)) || TypeAltiVecPixel) {
82033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis        Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec)
821788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner          << (TypeAltiVecPixel ? "__pixel" :
822788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner                                 getSpecifierName((TST)TypeSpecType));
823788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      }
824788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
825788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      // Only 'short' is valid with vector bool. (PIM 2.1)
826788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short))
82733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis        Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec)
828788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner          << getSpecifierName((TSW)TypeSpecWidth);
829788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
830788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
831788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) ||
832788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner          (TypeSpecWidth != TSW_unspecified))
833788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner        TypeSpecSign = TSS_unsigned;
834788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    }
835788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
836788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    if (TypeAltiVecPixel) {
837788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      //TODO: perform validation
838788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      TypeSpecType = TST_int;
839788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      TypeSpecSign = TSS_unsigned;
840788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      TypeSpecWidth = TSW_short;
8419e46b8cfb3e6c6feab5664744f52f06a40f9566bJohn McCall      TypeSpecOwned = false;
842788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    }
843788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  }
844788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
84564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis  // signed/unsigned are only valid with int/char/wchar_t.
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeSpecSign != TSS_unspecified) {
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (TypeSpecType == TST_unspecified)
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
8495a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith    else if (TypeSpecType != TST_int  && TypeSpecType != TST_int128 &&
85064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis             TypeSpecType != TST_char && TypeSpecType != TST_wchar) {
85133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSSLoc, diag::err_invalid_sign_spec)
852254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner        << getSpecifierName((TST)TypeSpecType);
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // signed double -> double.
8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecSign = TSS_unspecified;
8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Validate the width of the type.
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (TypeSpecWidth) {
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TSW_unspecified: break;
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TSW_short:    // short int
8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TSW_longlong: // long long int
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (TypeSpecType == TST_unspecified)
8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int; // short -> short int, long long -> long long int.
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (TypeSpecType != TST_int) {
86633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSWLoc,
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec
868254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner                                      : diag::err_invalid_longlong_spec)
869254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner        <<  getSpecifierName((TST)TypeSpecType);
8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int;
8719e46b8cfb3e6c6feab5664744f52f06a40f9566bJohn McCall      TypeSpecOwned = false;
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TSW_long:  // long double, long int
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (TypeSpecType == TST_unspecified)
8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int;  // long -> long int.
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (TypeSpecType != TST_int && TypeSpecType != TST_double) {
87833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSWLoc, diag::err_invalid_long_spec)
879254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner        << getSpecifierName((TST)TypeSpecType);
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int;
8819e46b8cfb3e6c6feab5664744f52f06a40f9566bJohn McCall      TypeSpecOwned = false;
8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // TODO: if the implementation does not implement _Complex or _Imaginary,
8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // disallow their use.  Need information about the backend.
8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeSpecComplex != TSC_unspecified) {
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (TypeSpecType == TST_unspecified) {
89033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSCLoc, diag::ext_plain_complex)
891849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor        << FixItHint::CreateInsertion(
8929b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor                              PP.getLocForEndOfToken(getTypeSpecComplexLoc()),
8939b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor                                                 " double");
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_double;   // _Complex -> _Complex double.
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // Note that this intentionally doesn't include _Complex _Bool.
8974e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie      if (!PP.getLangOpts().CPlusPlus)
8987ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman        Diag(D, TSTLoc, diag::ext_integer_complex);
8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
90033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSCLoc, diag::err_invalid_complex_spec)
901254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner        << getSpecifierName((TST)TypeSpecType);
9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecComplex = TSC_unspecified;
9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9068f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // If no type specifier was provided and we're parsing a language where
9078f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // the type specifier is not optional, but we got 'auto' as a storage
9088f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // class specifier, then assume this is an attempt to use C++0x's 'auto'
9098f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // type specifier.
9108f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // FIXME: Does Microsoft really support implicit int in C++?
9114e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (PP.getLangOpts().CPlusPlus && !PP.getLangOpts().MicrosoftExt &&
9128f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) {
9138f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    TypeSpecType = TST_auto;
9148f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    StorageClassSpec = StorageClassSpecAsWritten = SCS_unspecified;
9158f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    TSTLoc = TSTNameLoc = StorageClassSpecLoc;
9168f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    StorageClassSpecLoc = SourceLocation();
9178f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  }
9188f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // Diagnose if we've recovered from an ill-formed 'auto' storage class
9198f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // specifier in a pre-C++0x dialect of C++.
9204e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (!PP.getLangOpts().CPlusPlus0x && TypeSpecType == TST_auto)
9218f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    Diag(D, TSTLoc, diag::ext_auto_type_specifier);
9224e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (PP.getLangOpts().CPlusPlus && !PP.getLangOpts().CPlusPlus0x &&
9238f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      StorageClassSpec == SCS_auto)
9248f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    Diag(D, StorageClassSpecLoc, diag::warn_auto_storage_class)
9258f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      << FixItHint::CreateRemoval(StorageClassSpecLoc);
926841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith  if (TypeSpecType == TST_char16 || TypeSpecType == TST_char32)
927841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith    Diag(D, TSTLoc, diag::warn_cxx98_compat_unicode_type)
928841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith      << (TypeSpecType == TST_char16 ? "char16_t" : "char32_t");
929841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith  if (Constexpr_specified)
930841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith    Diag(D, ConstexprLoc, diag::warn_cxx98_compat_constexpr);
9318f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith
93267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  // C++ [class.friend]p6:
93367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  //   No storage-class-specifier shall appear in the decl-specifier-seq
93467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  //   of a friend declaration.
93567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  if (isFriendSpecified() && getStorageClassSpec()) {
93667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    DeclSpec::SCS SC = getStorageClassSpec();
93767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    const char *SpecName = getSpecifierName(SC);
93867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
93967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    SourceLocation SCLoc = getStorageClassSpecLoc();
940a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis    SourceLocation SCEndLoc = SCLoc.getLocWithOffset(strlen(SpecName));
94167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
94233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    Diag(D, SCLoc, diag::err_friend_storage_spec)
94367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall      << SpecName
944849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor      << FixItHint::CreateRemoval(SourceRange(SCLoc, SCEndLoc));
94567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
94667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    ClearStorageClassSpecs();
94767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  }
94867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
9496274d30d77870393d83a404dd223b8005f2b8cd5Douglas Gregor  assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
9506274d30d77870393d83a404dd223b8005f2b8cd5Douglas Gregor
9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Okay, now we can infer the real type.
9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // TODO: return "auto function" and other bad things based on the real type.
9541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // 'data definition has no type or storage class'?
9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
957e4858a65a93fb36c099d8dd2ea0a98e33e77687eDaniel Dunbar
958a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redlbool DeclSpec::isMissingDeclaratorOk() {
959a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  TST tst = getTypeSpecType();
960b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return isDeclRep(tst) && getRepAsDecl() != 0 &&
961b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    StorageClassSpec != DeclSpec::SCS_typedef;
962a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl}
9633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
9643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorvoid UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc,
9653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                          OverloadedOperatorKind Op,
9663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                          SourceLocation SymbolLocations[3]) {
9673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  Kind = IK_OperatorFunctionId;
9683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  StartLocation = OperatorLoc;
9693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  EndLocation = OperatorLoc;
9703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  OperatorFunctionId.Operator = Op;
9713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  for (unsigned I = 0; I != 3; ++I) {
9723f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding();
9733f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
9743f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    if (SymbolLocations[I].isValid())
9753f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      EndLocation = SymbolLocations[I];
9763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  }
9773f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor}
978b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
979cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlssonbool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc,
98046127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson                                  const char *&PrevSpec) {
981f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor  LastLocation = Loc;
982f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor
983b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  if (Specifiers & VS) {
984b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    PrevSpec = getSpecifierName(VS);
985b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    return true;
986b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  }
987b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
988b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  Specifiers |= VS;
989b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
990b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  switch (VS) {
991b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  default: llvm_unreachable("Unknown specifier!");
992b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  case VS_Override: VS_overrideLoc = Loc; break;
993b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  case VS_Final:    VS_finalLoc = Loc; break;
994b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  }
99546127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson
996b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  return false;
997b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson}
998b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
999cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlssonconst char *VirtSpecifiers::getSpecifierName(Specifier VS) {
1000c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson  switch (VS) {
1001b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  default: llvm_unreachable("Unknown specifier");
1002c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson  case VS_Override: return "override";
1003c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson  case VS_Final: return "final";
1004c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson  }
1005c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson}
1006