blob: 46914f68040299318b6c40bbdb48e1b950938ada [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for declaration specifiers.
11//
12//===----------------------------------------------------------------------===//
13
John McCall19510852010-08-20 18:27:03 +000014#include "clang/Sema/DeclSpec.h"
Douglas Gregorc34348a2011-02-24 17:54:50 +000015#include "clang/AST/ASTContext.h"
Reid Klecknerd1a32c32013-10-08 00:58:57 +000016#include "clang/AST/DeclCXX.h"
Douglas Gregor555f57e2011-06-25 00:56:27 +000017#include "clang/AST/Expr.h"
Douglas Gregor2e4c34a2011-02-24 00:17:56 +000018#include "clang/AST/NestedNameSpecifier.h"
19#include "clang/AST/TypeLoc.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "clang/Basic/LangOptions.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000021#include "clang/Lex/Preprocessor.h"
22#include "clang/Parse/ParseDiagnostic.h" // FIXME: remove this back-dependency!
23#include "clang/Sema/LocInfoType.h"
24#include "clang/Sema/ParsedTemplate.h"
25#include "clang/Sema/Sema.h"
26#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner5af2f352009-01-20 19:11:22 +000027#include "llvm/ADT/STLExtras.h"
Richard Smithec642442013-04-12 22:46:28 +000028#include "llvm/ADT/SmallString.h"
John McCall32d335e2009-08-03 18:47:27 +000029#include "llvm/Support/ErrorHandling.h"
Douglas Gregore4e5b052009-03-19 00:18:19 +000030#include <cstring>
Reid Spencer5f016e22007-07-11 17:01:13 +000031using namespace clang;
32
Chris Lattner254be6a2008-11-22 08:32:36 +000033
David Blaikied6471f72011-09-25 23:23:43 +000034static DiagnosticBuilder Diag(DiagnosticsEngine &D, SourceLocation Loc,
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000035 unsigned DiagID) {
36 return D.Report(Loc, DiagID);
Chris Lattner254be6a2008-11-22 08:32:36 +000037}
38
Douglas Gregor314b97f2009-11-10 19:49:08 +000039
40void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) {
41 assert(TemplateId && "NULL template-id annotation?");
42 Kind = IK_TemplateId;
43 this->TemplateId = TemplateId;
44 StartLocation = TemplateId->TemplateNameLoc;
45 EndLocation = TemplateId->RAngleLoc;
46}
47
Douglas Gregor0efc2c12010-01-13 17:31:36 +000048void UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) {
49 assert(TemplateId && "NULL template-id annotation?");
50 Kind = IK_ConstructorTemplateId;
51 this->TemplateId = TemplateId;
52 StartLocation = TemplateId->TemplateNameLoc;
53 EndLocation = TemplateId->RAngleLoc;
54}
55
Douglas Gregor2e4c34a2011-02-24 00:17:56 +000056void CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc,
57 TypeLoc TL, SourceLocation ColonColonLoc) {
Douglas Gregor5f791bb2011-02-28 23:58:31 +000058 Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc);
Douglas Gregor2e4c34a2011-02-24 00:17:56 +000059 if (Range.getBegin().isInvalid())
60 Range.setBegin(TL.getBeginLoc());
61 Range.setEnd(ColonColonLoc);
Douglas Gregorc34348a2011-02-24 17:54:50 +000062
Douglas Gregor5f791bb2011-02-28 23:58:31 +000063 assert(Range == Builder.getSourceRange() &&
Douglas Gregorc34348a2011-02-24 17:54:50 +000064 "NestedNameSpecifierLoc range computation incorrect");
Douglas Gregor2e4c34a2011-02-24 00:17:56 +000065}
66
67void CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier,
68 SourceLocation IdentifierLoc,
69 SourceLocation ColonColonLoc) {
Douglas Gregor5f791bb2011-02-28 23:58:31 +000070 Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc);
71
Douglas Gregor2e4c34a2011-02-24 00:17:56 +000072 if (Range.getBegin().isInvalid())
73 Range.setBegin(IdentifierLoc);
74 Range.setEnd(ColonColonLoc);
Douglas Gregorc34348a2011-02-24 17:54:50 +000075
Douglas Gregor5f791bb2011-02-28 23:58:31 +000076 assert(Range == Builder.getSourceRange() &&
Douglas Gregorc34348a2011-02-24 17:54:50 +000077 "NestedNameSpecifierLoc range computation incorrect");
Douglas Gregor2e4c34a2011-02-24 00:17:56 +000078}
79
80void CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace,
81 SourceLocation NamespaceLoc,
82 SourceLocation ColonColonLoc) {
Douglas Gregor5f791bb2011-02-28 23:58:31 +000083 Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc);
84
Douglas Gregor2e4c34a2011-02-24 00:17:56 +000085 if (Range.getBegin().isInvalid())
86 Range.setBegin(NamespaceLoc);
87 Range.setEnd(ColonColonLoc);
Douglas Gregorc34348a2011-02-24 17:54:50 +000088
Douglas Gregor5f791bb2011-02-28 23:58:31 +000089 assert(Range == Builder.getSourceRange() &&
Douglas Gregorc34348a2011-02-24 17:54:50 +000090 "NestedNameSpecifierLoc range computation incorrect");
Douglas Gregor2e4c34a2011-02-24 00:17:56 +000091}
92
Douglas Gregor14aba762011-02-24 02:36:08 +000093void CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
94 SourceLocation AliasLoc,
95 SourceLocation ColonColonLoc) {
Douglas Gregor5f791bb2011-02-28 23:58:31 +000096 Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc);
97
Douglas Gregor14aba762011-02-24 02:36:08 +000098 if (Range.getBegin().isInvalid())
99 Range.setBegin(AliasLoc);
100 Range.setEnd(ColonColonLoc);
Douglas Gregorc34348a2011-02-24 17:54:50 +0000101
Douglas Gregor5f791bb2011-02-28 23:58:31 +0000102 assert(Range == Builder.getSourceRange() &&
Douglas Gregorc34348a2011-02-24 17:54:50 +0000103 "NestedNameSpecifierLoc range computation incorrect");
Douglas Gregor14aba762011-02-24 02:36:08 +0000104}
105
Douglas Gregor2e4c34a2011-02-24 00:17:56 +0000106void CXXScopeSpec::MakeGlobal(ASTContext &Context,
107 SourceLocation ColonColonLoc) {
Douglas Gregor5f791bb2011-02-28 23:58:31 +0000108 Builder.MakeGlobal(Context, ColonColonLoc);
109
Douglas Gregor2e4c34a2011-02-24 00:17:56 +0000110 Range = SourceRange(ColonColonLoc);
Douglas Gregorc34348a2011-02-24 17:54:50 +0000111
Douglas Gregor5f791bb2011-02-28 23:58:31 +0000112 assert(Range == Builder.getSourceRange() &&
Douglas Gregorc34348a2011-02-24 17:54:50 +0000113 "NestedNameSpecifierLoc range computation incorrect");
114}
115
116void CXXScopeSpec::MakeTrivial(ASTContext &Context,
117 NestedNameSpecifier *Qualifier, SourceRange R) {
Douglas Gregor5f791bb2011-02-28 23:58:31 +0000118 Builder.MakeTrivial(Context, Qualifier, R);
Douglas Gregorc34348a2011-02-24 17:54:50 +0000119 Range = R;
Douglas Gregorc34348a2011-02-24 17:54:50 +0000120}
121
122void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) {
123 if (!Other) {
124 Range = SourceRange();
Douglas Gregor5f791bb2011-02-28 23:58:31 +0000125 Builder.Clear();
Douglas Gregorc34348a2011-02-24 17:54:50 +0000126 return;
127 }
Douglas Gregor5f791bb2011-02-28 23:58:31 +0000128
Douglas Gregorc34348a2011-02-24 17:54:50 +0000129 Range = Other.getSourceRange();
Douglas Gregor5f791bb2011-02-28 23:58:31 +0000130 Builder.Adopt(Other);
Douglas Gregorc34348a2011-02-24 17:54:50 +0000131}
132
John McCall9dc71d22011-07-06 06:57:57 +0000133SourceLocation CXXScopeSpec::getLastQualifierNameLoc() const {
134 if (!Builder.getRepresentation())
135 return SourceLocation();
136 return Builder.getTemporary().getLocalBeginLoc();
137}
138
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000139NestedNameSpecifierLoc
140CXXScopeSpec::getWithLocInContext(ASTContext &Context) const {
Douglas Gregorb46ae392011-03-03 21:48:55 +0000141 if (!Builder.getRepresentation())
Douglas Gregorc34348a2011-02-24 17:54:50 +0000142 return NestedNameSpecifierLoc();
143
Douglas Gregor5f791bb2011-02-28 23:58:31 +0000144 return Builder.getWithLocInContext(Context);
Douglas Gregor2e4c34a2011-02-24 00:17:56 +0000145}
146
Chris Lattner5af2f352009-01-20 19:11:22 +0000147/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
148/// "TheDeclarator" is the declarator that this will be added to.
Abramo Bagnara59c0a812012-10-04 21:42:10 +0000149DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto,
Richard Smithb9c62612012-07-30 21:30:52 +0000150 bool isAmbiguous,
Abramo Bagnara59c0a812012-10-04 21:42:10 +0000151 SourceLocation LParenLoc,
Chris Lattner5af2f352009-01-20 19:11:22 +0000152 ParamInfo *ArgInfo,
153 unsigned NumArgs,
Abramo Bagnara59c0a812012-10-04 21:42:10 +0000154 SourceLocation EllipsisLoc,
155 SourceLocation RParenLoc,
Chris Lattner5af2f352009-01-20 19:11:22 +0000156 unsigned TypeQuals,
Douglas Gregor83f51722011-01-26 03:43:54 +0000157 bool RefQualifierIsLvalueRef,
158 SourceLocation RefQualifierLoc,
Douglas Gregor43f51032011-10-19 06:04:55 +0000159 SourceLocation ConstQualifierLoc,
160 SourceLocation
161 VolatileQualifierLoc,
Douglas Gregor90ebed02011-07-13 21:47:47 +0000162 SourceLocation MutableLoc,
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000163 ExceptionSpecificationType
164 ESpecType,
165 SourceLocation ESpecLoc,
John McCallb3d87482010-08-24 05:47:05 +0000166 ParsedType *Exceptions,
Sebastian Redlef65f062009-05-29 18:02:33 +0000167 SourceRange *ExceptionRanges,
Sebastian Redl7dc81342009-04-29 17:30:04 +0000168 unsigned NumExceptions,
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000169 Expr *NoexceptExpr,
Abramo Bagnara796aa442011-03-12 11:17:06 +0000170 SourceLocation LocalRangeBegin,
171 SourceLocation LocalRangeEnd,
Douglas Gregordab60ad2010-10-01 18:44:50 +0000172 Declarator &TheDeclarator,
Richard Smith54655be2012-06-12 01:51:59 +0000173 TypeResult TrailingReturnType) {
Richard Smith4cf4a5e2013-03-28 01:55:44 +0000174 assert(!(TypeQuals & DeclSpec::TQ_atomic) &&
175 "function cannot have _Atomic qualifier");
176
Chris Lattner5af2f352009-01-20 19:11:22 +0000177 DeclaratorChunk I;
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000178 I.Kind = Function;
Abramo Bagnara796aa442011-03-12 11:17:06 +0000179 I.Loc = LocalRangeBegin;
180 I.EndLoc = LocalRangeEnd;
John McCall0b7e6782011-03-24 11:26:52 +0000181 I.Fun.AttrList = 0;
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000182 I.Fun.hasPrototype = hasProto;
Abramo Bagnara59c0a812012-10-04 21:42:10 +0000183 I.Fun.isVariadic = EllipsisLoc.isValid();
Richard Smithb9c62612012-07-30 21:30:52 +0000184 I.Fun.isAmbiguous = isAmbiguous;
Abramo Bagnara59c0a812012-10-04 21:42:10 +0000185 I.Fun.LParenLoc = LParenLoc.getRawEncoding();
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000186 I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding();
Abramo Bagnara59c0a812012-10-04 21:42:10 +0000187 I.Fun.RParenLoc = RParenLoc.getRawEncoding();
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000188 I.Fun.DeleteArgInfo = false;
189 I.Fun.TypeQuals = TypeQuals;
190 I.Fun.NumArgs = NumArgs;
191 I.Fun.ArgInfo = 0;
Douglas Gregor83f51722011-01-26 03:43:54 +0000192 I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000193 I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding();
Douglas Gregor43f51032011-10-19 06:04:55 +0000194 I.Fun.ConstQualifierLoc = ConstQualifierLoc.getRawEncoding();
195 I.Fun.VolatileQualifierLoc = VolatileQualifierLoc.getRawEncoding();
Douglas Gregor90ebed02011-07-13 21:47:47 +0000196 I.Fun.MutableLoc = MutableLoc.getRawEncoding();
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000197 I.Fun.ExceptionSpecType = ESpecType;
198 I.Fun.ExceptionSpecLoc = ESpecLoc.getRawEncoding();
199 I.Fun.NumExceptions = 0;
200 I.Fun.Exceptions = 0;
201 I.Fun.NoexceptExpr = 0;
Richard Smith54655be2012-06-12 01:51:59 +0000202 I.Fun.HasTrailingReturnType = TrailingReturnType.isUsable() ||
203 TrailingReturnType.isInvalid();
204 I.Fun.TrailingReturnType = TrailingReturnType.get();
Sebastian Redl7dc81342009-04-29 17:30:04 +0000205
Chris Lattner5af2f352009-01-20 19:11:22 +0000206 // new[] an argument array if needed.
207 if (NumArgs) {
208 // If the 'InlineParams' in Declarator is unused and big enough, put our
209 // parameter list there (in an effort to avoid new/delete traffic). If it
210 // is already used (consider a function returning a function pointer) or too
211 // small (function taking too many arguments), go to the heap.
Mike Stump1eb44332009-09-09 15:08:12 +0000212 if (!TheDeclarator.InlineParamsUsed &&
Chris Lattner5af2f352009-01-20 19:11:22 +0000213 NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
214 I.Fun.ArgInfo = TheDeclarator.InlineParams;
215 I.Fun.DeleteArgInfo = false;
216 TheDeclarator.InlineParamsUsed = true;
217 } else {
218 I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs];
219 I.Fun.DeleteArgInfo = true;
220 }
221 memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
222 }
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000223
224 // Check what exception specification information we should actually store.
225 switch (ESpecType) {
226 default: break; // By default, save nothing.
227 case EST_Dynamic:
228 // new[] an exception array if needed
229 if (NumExceptions) {
230 I.Fun.NumExceptions = NumExceptions;
231 I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
232 for (unsigned i = 0; i != NumExceptions; ++i) {
233 I.Fun.Exceptions[i].Ty = Exceptions[i];
234 I.Fun.Exceptions[i].Range = ExceptionRanges[i];
235 }
Sebastian Redlef65f062009-05-29 18:02:33 +0000236 }
Sebastian Redl6e5d3192011-03-05 22:42:13 +0000237 break;
238
239 case EST_ComputedNoexcept:
240 I.Fun.NoexceptExpr = NoexceptExpr;
241 break;
Sebastian Redl7dc81342009-04-29 17:30:04 +0000242 }
Chris Lattner5af2f352009-01-20 19:11:22 +0000243 return I;
244}
Chris Lattner254be6a2008-11-22 08:32:36 +0000245
Douglas Gregor555f57e2011-06-25 00:56:27 +0000246bool Declarator::isDeclarationOfFunction() const {
Richard Smith1ab0d902011-06-25 02:28:38 +0000247 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
248 switch (DeclTypeInfo[i].Kind) {
249 case DeclaratorChunk::Function:
250 return true;
251 case DeclaratorChunk::Paren:
252 continue;
253 case DeclaratorChunk::Pointer:
254 case DeclaratorChunk::Reference:
255 case DeclaratorChunk::Array:
256 case DeclaratorChunk::BlockPointer:
257 case DeclaratorChunk::MemberPointer:
258 return false;
259 }
260 llvm_unreachable("Invalid type chunk");
Richard Smith1ab0d902011-06-25 02:28:38 +0000261 }
Douglas Gregor555f57e2011-06-25 00:56:27 +0000262
263 switch (DS.getTypeSpecType()) {
Eli Friedmanb001de72011-10-06 23:00:33 +0000264 case TST_atomic:
Douglas Gregor555f57e2011-06-25 00:56:27 +0000265 case TST_auto:
266 case TST_bool:
267 case TST_char:
268 case TST_char16:
269 case TST_char32:
270 case TST_class:
271 case TST_decimal128:
272 case TST_decimal32:
273 case TST_decimal64:
274 case TST_double:
275 case TST_enum:
276 case TST_error:
277 case TST_float:
Anton Korobeynikovaa4a99b2011-10-14 23:23:15 +0000278 case TST_half:
Douglas Gregor555f57e2011-06-25 00:56:27 +0000279 case TST_int:
Richard Smith5a5a9712012-04-04 06:24:32 +0000280 case TST_int128:
Douglas Gregor555f57e2011-06-25 00:56:27 +0000281 case TST_struct:
Joao Matos6666ed42012-08-31 18:45:21 +0000282 case TST_interface:
Douglas Gregor555f57e2011-06-25 00:56:27 +0000283 case TST_union:
284 case TST_unknown_anytype:
285 case TST_unspecified:
286 case TST_void:
287 case TST_wchar:
Guy Benyeib13621d2012-12-18 14:38:23 +0000288 case TST_image1d_t:
289 case TST_image1d_array_t:
290 case TST_image1d_buffer_t:
291 case TST_image2d_t:
292 case TST_image2d_array_t:
293 case TST_image3d_t:
Guy Benyei21f18c42013-02-07 10:55:47 +0000294 case TST_sampler_t:
Guy Benyeie6b9d802013-01-20 12:31:11 +0000295 case TST_event_t:
Douglas Gregor555f57e2011-06-25 00:56:27 +0000296 return false;
297
Richard Smitha2c36462013-04-26 16:15:35 +0000298 case TST_decltype_auto:
299 // This must have an initializer, so can't be a function declaration,
300 // even if the initializer has function type.
301 return false;
302
Douglas Gregor555f57e2011-06-25 00:56:27 +0000303 case TST_decltype:
304 case TST_typeofExpr:
305 if (Expr *E = DS.getRepAsExpr())
306 return E->getType()->isFunctionType();
307 return false;
308
309 case TST_underlyingType:
310 case TST_typename:
311 case TST_typeofType: {
312 QualType QT = DS.getRepAsType().get();
313 if (QT.isNull())
314 return false;
315
316 if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
317 QT = LIT->getType();
318
319 if (QT.isNull())
320 return false;
321
322 return QT->isFunctionType();
323 }
324 }
David Blaikie7530c032012-01-17 06:56:22 +0000325
326 llvm_unreachable("Invalid TypeSpecType!");
Douglas Gregor555f57e2011-06-25 00:56:27 +0000327}
328
Reid Klecknerd1a32c32013-10-08 00:58:57 +0000329bool Declarator::isStaticMember() {
330 assert(getContext() == MemberContext);
331 return getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
332 CXXMethodDecl::isStaticOverloadedOperator(
333 getName().OperatorFunctionId.Operator);
334}
335
Reid Spencer5f016e22007-07-11 17:01:13 +0000336/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
Chris Lattner2a327d12009-02-27 18:35:46 +0000337/// declaration specifier includes.
Reid Spencer5f016e22007-07-11 17:01:13 +0000338///
339unsigned DeclSpec::getParsedSpecifiers() const {
340 unsigned Res = 0;
341 if (StorageClassSpec != SCS_unspecified ||
Richard Smithec642442013-04-12 22:46:28 +0000342 ThreadStorageClassSpec != TSCS_unspecified)
Reid Spencer5f016e22007-07-11 17:01:13 +0000343 Res |= PQ_StorageClassSpecifier;
Mike Stumpd4204332008-06-19 19:52:46 +0000344
Reid Spencer5f016e22007-07-11 17:01:13 +0000345 if (TypeQualifiers != TQ_unspecified)
346 Res |= PQ_TypeQualifier;
Mike Stump1eb44332009-09-09 15:08:12 +0000347
Reid Spencer5f016e22007-07-11 17:01:13 +0000348 if (hasTypeSpecifier())
349 Res |= PQ_TypeSpecifier;
Mike Stump1eb44332009-09-09 15:08:12 +0000350
Richard Smithde03c152013-01-17 22:16:11 +0000351 if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified ||
352 FS_noreturn_specified)
Reid Spencer5f016e22007-07-11 17:01:13 +0000353 Res |= PQ_FunctionSpecifier;
354 return Res;
355}
356
John McCallfec54012009-08-03 20:12:06 +0000357template <class T> static bool BadSpecifier(T TNew, T TPrev,
358 const char *&PrevSpec,
Aaron Ballmanc8286202012-08-28 20:55:40 +0000359 unsigned &DiagID,
360 bool IsExtension = true) {
John McCall32d335e2009-08-03 18:47:27 +0000361 PrevSpec = DeclSpec::getSpecifierName(TPrev);
Aaron Ballmanc8286202012-08-28 20:55:40 +0000362 if (TNew != TPrev)
363 DiagID = diag::err_invalid_decl_spec_combination;
364 else
365 DiagID = IsExtension ? diag::ext_duplicate_declspec :
366 diag::warn_duplicate_declspec;
John McCall32d335e2009-08-03 18:47:27 +0000367 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000368}
John McCall32d335e2009-08-03 18:47:27 +0000369
Reid Spencer5f016e22007-07-11 17:01:13 +0000370const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) {
371 switch (S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000372 case DeclSpec::SCS_unspecified: return "unspecified";
373 case DeclSpec::SCS_typedef: return "typedef";
374 case DeclSpec::SCS_extern: return "extern";
375 case DeclSpec::SCS_static: return "static";
376 case DeclSpec::SCS_auto: return "auto";
377 case DeclSpec::SCS_register: return "register";
Eli Friedman63054b32009-04-19 20:27:55 +0000378 case DeclSpec::SCS_private_extern: return "__private_extern__";
Sebastian Redl669d5d72008-11-14 23:42:31 +0000379 case DeclSpec::SCS_mutable: return "mutable";
Reid Spencer5f016e22007-07-11 17:01:13 +0000380 }
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000381 llvm_unreachable("Unknown typespec!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000382}
383
Richard Smithec642442013-04-12 22:46:28 +0000384const char *DeclSpec::getSpecifierName(DeclSpec::TSCS S) {
385 switch (S) {
386 case DeclSpec::TSCS_unspecified: return "unspecified";
387 case DeclSpec::TSCS___thread: return "__thread";
388 case DeclSpec::TSCS_thread_local: return "thread_local";
389 case DeclSpec::TSCS__Thread_local: return "_Thread_local";
390 }
391 llvm_unreachable("Unknown typespec!");
392}
393
John McCall32d335e2009-08-03 18:47:27 +0000394const char *DeclSpec::getSpecifierName(TSW W) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000395 switch (W) {
John McCall32d335e2009-08-03 18:47:27 +0000396 case TSW_unspecified: return "unspecified";
397 case TSW_short: return "short";
398 case TSW_long: return "long";
399 case TSW_longlong: return "long long";
Reid Spencer5f016e22007-07-11 17:01:13 +0000400 }
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000401 llvm_unreachable("Unknown typespec!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000402}
403
John McCall32d335e2009-08-03 18:47:27 +0000404const char *DeclSpec::getSpecifierName(TSC C) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000405 switch (C) {
John McCall32d335e2009-08-03 18:47:27 +0000406 case TSC_unspecified: return "unspecified";
407 case TSC_imaginary: return "imaginary";
408 case TSC_complex: return "complex";
Reid Spencer5f016e22007-07-11 17:01:13 +0000409 }
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000410 llvm_unreachable("Unknown typespec!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000411}
412
413
John McCall32d335e2009-08-03 18:47:27 +0000414const char *DeclSpec::getSpecifierName(TSS S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000415 switch (S) {
John McCall32d335e2009-08-03 18:47:27 +0000416 case TSS_unspecified: return "unspecified";
417 case TSS_signed: return "signed";
418 case TSS_unsigned: return "unsigned";
Reid Spencer5f016e22007-07-11 17:01:13 +0000419 }
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000420 llvm_unreachable("Unknown typespec!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000421}
422
423const char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
424 switch (T) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000425 case DeclSpec::TST_unspecified: return "unspecified";
426 case DeclSpec::TST_void: return "void";
427 case DeclSpec::TST_char: return "char";
Argyrios Kyrtzidis64c438a2008-08-09 16:51:54 +0000428 case DeclSpec::TST_wchar: return "wchar_t";
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000429 case DeclSpec::TST_char16: return "char16_t";
430 case DeclSpec::TST_char32: return "char32_t";
Reid Spencer5f016e22007-07-11 17:01:13 +0000431 case DeclSpec::TST_int: return "int";
Richard Smith5a5a9712012-04-04 06:24:32 +0000432 case DeclSpec::TST_int128: return "__int128";
Anton Korobeynikovaa4a99b2011-10-14 23:23:15 +0000433 case DeclSpec::TST_half: return "half";
Reid Spencer5f016e22007-07-11 17:01:13 +0000434 case DeclSpec::TST_float: return "float";
435 case DeclSpec::TST_double: return "double";
436 case DeclSpec::TST_bool: return "_Bool";
437 case DeclSpec::TST_decimal32: return "_Decimal32";
438 case DeclSpec::TST_decimal64: return "_Decimal64";
439 case DeclSpec::TST_decimal128: return "_Decimal128";
440 case DeclSpec::TST_enum: return "enum";
Chris Lattner99dc9142008-04-13 18:59:07 +0000441 case DeclSpec::TST_class: return "class";
Reid Spencer5f016e22007-07-11 17:01:13 +0000442 case DeclSpec::TST_union: return "union";
443 case DeclSpec::TST_struct: return "struct";
Joao Matos6666ed42012-08-31 18:45:21 +0000444 case DeclSpec::TST_interface: return "__interface";
Douglas Gregor1a51b4a2009-02-09 15:09:02 +0000445 case DeclSpec::TST_typename: return "type-name";
Steve Naroffd1861fd2007-07-31 12:34:36 +0000446 case DeclSpec::TST_typeofType:
447 case DeclSpec::TST_typeofExpr: return "typeof";
John McCall32d335e2009-08-03 18:47:27 +0000448 case DeclSpec::TST_auto: return "auto";
449 case DeclSpec::TST_decltype: return "(decltype)";
Richard Smitha2c36462013-04-26 16:15:35 +0000450 case DeclSpec::TST_decltype_auto: return "decltype(auto)";
Sean Huntca63c202011-05-24 22:41:36 +0000451 case DeclSpec::TST_underlyingType: return "__underlying_type";
John McCalla5fc4722011-04-09 22:50:59 +0000452 case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
Eli Friedmanb001de72011-10-06 23:00:33 +0000453 case DeclSpec::TST_atomic: return "_Atomic";
Guy Benyeib13621d2012-12-18 14:38:23 +0000454 case DeclSpec::TST_image1d_t: return "image1d_t";
455 case DeclSpec::TST_image1d_array_t: return "image1d_array_t";
456 case DeclSpec::TST_image1d_buffer_t: return "image1d_buffer_t";
457 case DeclSpec::TST_image2d_t: return "image2d_t";
458 case DeclSpec::TST_image2d_array_t: return "image2d_array_t";
459 case DeclSpec::TST_image3d_t: return "image3d_t";
Guy Benyei21f18c42013-02-07 10:55:47 +0000460 case DeclSpec::TST_sampler_t: return "sampler_t";
Guy Benyeie6b9d802013-01-20 12:31:11 +0000461 case DeclSpec::TST_event_t: return "event_t";
John McCall32d335e2009-08-03 18:47:27 +0000462 case DeclSpec::TST_error: return "(error)";
Reid Spencer5f016e22007-07-11 17:01:13 +0000463 }
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000464 llvm_unreachable("Unknown typespec!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000465}
466
John McCall32d335e2009-08-03 18:47:27 +0000467const char *DeclSpec::getSpecifierName(TQ T) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000468 switch (T) {
John McCall32d335e2009-08-03 18:47:27 +0000469 case DeclSpec::TQ_unspecified: return "unspecified";
470 case DeclSpec::TQ_const: return "const";
471 case DeclSpec::TQ_restrict: return "restrict";
472 case DeclSpec::TQ_volatile: return "volatile";
Richard Smith4cf4a5e2013-03-28 01:55:44 +0000473 case DeclSpec::TQ_atomic: return "_Atomic";
Reid Spencer5f016e22007-07-11 17:01:13 +0000474 }
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000475 llvm_unreachable("Unknown typespec!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000476}
477
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000478bool DeclSpec::SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
John McCallfec54012009-08-03 20:12:06 +0000479 const char *&PrevSpec,
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000480 unsigned &DiagID) {
Tanya Lattner5e94d6f2012-06-19 23:09:52 +0000481 // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class
482 // specifiers are not supported.
Peter Collingbournee2f82f72011-02-11 19:59:54 +0000483 // It seems sensible to prohibit private_extern too
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000484 // The cl_clang_storage_class_specifiers extension enables support for
485 // these storage-class specifiers.
Tanya Lattner5e94d6f2012-06-19 23:09:52 +0000486 // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class
487 // specifiers are not supported."
David Blaikie4e4d0842012-03-11 07:00:24 +0000488 if (S.getLangOpts().OpenCL &&
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000489 !S.getOpenCLOptions().cl_clang_storage_class_specifiers) {
490 switch (SC) {
Peter Collingbournee2f82f72011-02-11 19:59:54 +0000491 case SCS_extern:
492 case SCS_private_extern:
Tanya Lattner5e94d6f2012-06-19 23:09:52 +0000493 case SCS_static:
494 if (S.getLangOpts().OpenCLVersion < 120) {
495 DiagID = diag::err_not_opencl_storage_class_specifier;
496 PrevSpec = getSpecifierName(SC);
497 return true;
498 }
499 break;
Peter Collingbournee2f82f72011-02-11 19:59:54 +0000500 case SCS_auto:
501 case SCS_register:
Peter Collingbournee2f82f72011-02-11 19:59:54 +0000502 DiagID = diag::err_not_opencl_storage_class_specifier;
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000503 PrevSpec = getSpecifierName(SC);
Peter Collingbournee2f82f72011-02-11 19:59:54 +0000504 return true;
505 default:
506 break;
507 }
508 }
509
Abramo Bagnara35f9a192010-07-30 16:47:02 +0000510 if (StorageClassSpec != SCS_unspecified) {
Richard Smitha2c36462013-04-26 16:15:35 +0000511 // Maybe this is an attempt to use C++11 'auto' outside of C++11 mode.
Richard Smith8f4fb192011-09-04 19:54:14 +0000512 bool isInvalid = true;
David Blaikie4e4d0842012-03-11 07:00:24 +0000513 if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) {
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000514 if (SC == SCS_auto)
Richard Smith8f4fb192011-09-04 19:54:14 +0000515 return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID);
516 if (StorageClassSpec == SCS_auto) {
517 isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc,
518 PrevSpec, DiagID);
519 assert(!isInvalid && "auto SCS -> TST recovery failed");
520 }
521 }
522
Abramo Bagnara35f9a192010-07-30 16:47:02 +0000523 // Changing storage class is allowed only if the previous one
524 // was the 'extern' that is part of a linkage specification and
525 // the new storage class is 'typedef'.
Richard Smith8f4fb192011-09-04 19:54:14 +0000526 if (isInvalid &&
527 !(SCS_extern_in_linkage_spec &&
Abramo Bagnara35f9a192010-07-30 16:47:02 +0000528 StorageClassSpec == SCS_extern &&
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000529 SC == SCS_typedef))
530 return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID);
Abramo Bagnara35f9a192010-07-30 16:47:02 +0000531 }
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000532 StorageClassSpec = SC;
Reid Spencer5f016e22007-07-11 17:01:13 +0000533 StorageClassSpecLoc = Loc;
Peter Collingbourneb8b0e752011-10-06 03:01:00 +0000534 assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
Reid Spencer5f016e22007-07-11 17:01:13 +0000535 return false;
536}
537
Richard Smithec642442013-04-12 22:46:28 +0000538bool DeclSpec::SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
John McCallfec54012009-08-03 20:12:06 +0000539 const char *&PrevSpec,
540 unsigned &DiagID) {
Richard Smithec642442013-04-12 22:46:28 +0000541 if (ThreadStorageClassSpec != TSCS_unspecified)
542 return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID);
543
544 ThreadStorageClassSpec = TSC;
545 ThreadStorageClassSpecLoc = Loc;
Reid Spencer5f016e22007-07-11 17:01:13 +0000546 return false;
547}
548
Reid Spencer5f016e22007-07-11 17:01:13 +0000549/// These methods set the specified attribute of the DeclSpec, but return true
550/// and ignore the request if invalid (e.g. "extern" then "auto" is
551/// specified).
552bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc,
John McCallfec54012009-08-03 20:12:06 +0000553 const char *&PrevSpec,
554 unsigned &DiagID) {
Abramo Bagnara2553eaf2011-03-06 22:21:56 +0000555 // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
556 // for 'long long' we will keep the source location of the first 'long'.
557 if (TypeSpecWidth == TSW_unspecified)
558 TSWLoc = Loc;
559 // Allow turning long -> long long.
560 else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
John McCallfec54012009-08-03 20:12:06 +0000561 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
Reid Spencer5f016e22007-07-11 17:01:13 +0000562 TypeSpecWidth = W;
Chris Lattner788b0fd2010-06-23 06:00:24 +0000563 if (TypeAltiVecVector && !TypeAltiVecBool &&
564 ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) {
John Thompson82287d12010-02-05 00:12:22 +0000565 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
566 DiagID = diag::warn_vector_long_decl_spec_combination;
567 return true;
568 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000569 return false;
570}
571
Mike Stump1eb44332009-09-09 15:08:12 +0000572bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc,
John McCallfec54012009-08-03 20:12:06 +0000573 const char *&PrevSpec,
574 unsigned &DiagID) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000575 if (TypeSpecComplex != TSC_unspecified)
John McCallfec54012009-08-03 20:12:06 +0000576 return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
Reid Spencer5f016e22007-07-11 17:01:13 +0000577 TypeSpecComplex = C;
578 TSCLoc = Loc;
579 return false;
580}
581
Mike Stump1eb44332009-09-09 15:08:12 +0000582bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc,
John McCallfec54012009-08-03 20:12:06 +0000583 const char *&PrevSpec,
584 unsigned &DiagID) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000585 if (TypeSpecSign != TSS_unspecified)
John McCallfec54012009-08-03 20:12:06 +0000586 return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID);
Reid Spencer5f016e22007-07-11 17:01:13 +0000587 TypeSpecSign = S;
588 TSSLoc = Loc;
589 return false;
590}
591
592bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
John McCallfec54012009-08-03 20:12:06 +0000593 const char *&PrevSpec,
594 unsigned &DiagID,
John McCallb3d87482010-08-24 05:47:05 +0000595 ParsedType Rep) {
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000596 return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep);
597}
598
599bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
600 SourceLocation TagNameLoc,
601 const char *&PrevSpec,
602 unsigned &DiagID,
603 ParsedType Rep) {
John McCallb3d87482010-08-24 05:47:05 +0000604 assert(isTypeRep(T) && "T does not store a type");
605 assert(Rep && "no type provided!");
606 if (TypeSpecType != TST_unspecified) {
607 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
608 DiagID = diag::err_invalid_decl_spec_combination;
609 return true;
610 }
611 TypeSpecType = T;
612 TypeRep = Rep;
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000613 TSTLoc = TagKwLoc;
614 TSTNameLoc = TagNameLoc;
John McCallb3d87482010-08-24 05:47:05 +0000615 TypeSpecOwned = false;
616 return false;
617}
618
619bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
620 const char *&PrevSpec,
621 unsigned &DiagID,
622 Expr *Rep) {
623 assert(isExprRep(T) && "T does not store an expr");
624 assert(Rep && "no expression provided!");
625 if (TypeSpecType != TST_unspecified) {
626 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
627 DiagID = diag::err_invalid_decl_spec_combination;
628 return true;
629 }
630 TypeSpecType = T;
631 ExprRep = Rep;
632 TSTLoc = Loc;
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000633 TSTNameLoc = Loc;
John McCallb3d87482010-08-24 05:47:05 +0000634 TypeSpecOwned = false;
635 return false;
636}
637
638bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
639 const char *&PrevSpec,
640 unsigned &DiagID,
641 Decl *Rep, bool Owned) {
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000642 return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned);
643}
644
645bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
646 SourceLocation TagNameLoc,
647 const char *&PrevSpec,
648 unsigned &DiagID,
649 Decl *Rep, bool Owned) {
John McCallb3d87482010-08-24 05:47:05 +0000650 assert(isDeclRep(T) && "T does not store a decl");
651 // Unlike the other cases, we don't assert that we actually get a decl.
652
653 if (TypeSpecType != TST_unspecified) {
654 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
655 DiagID = diag::err_invalid_decl_spec_combination;
656 return true;
657 }
658 TypeSpecType = T;
659 DeclRep = Rep;
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000660 TSTLoc = TagKwLoc;
661 TSTNameLoc = TagNameLoc;
Douglas Gregor86a87302013-05-14 23:22:32 +0000662 TypeSpecOwned = Owned && Rep != 0;
John McCallb3d87482010-08-24 05:47:05 +0000663 return false;
664}
665
666bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
667 const char *&PrevSpec,
668 unsigned &DiagID) {
669 assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) &&
670 "rep required for these type-spec kinds!");
John McCallfec54012009-08-03 20:12:06 +0000671 if (TypeSpecType != TST_unspecified) {
672 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
673 DiagID = diag::err_invalid_decl_spec_combination;
674 return true;
675 }
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000676 TSTLoc = Loc;
677 TSTNameLoc = Loc;
Chris Lattner788b0fd2010-06-23 06:00:24 +0000678 if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) {
679 TypeAltiVecBool = true;
Chris Lattner788b0fd2010-06-23 06:00:24 +0000680 return false;
681 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000682 TypeSpecType = T;
John McCallb3d87482010-08-24 05:47:05 +0000683 TypeSpecOwned = false;
Chris Lattner788b0fd2010-06-23 06:00:24 +0000684 if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) {
John Thompson82287d12010-02-05 00:12:22 +0000685 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
Chris Lattner788b0fd2010-06-23 06:00:24 +0000686 DiagID = diag::err_invalid_vector_decl_spec;
John Thompson82287d12010-02-05 00:12:22 +0000687 return true;
688 }
689 return false;
690}
691
692bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
693 const char *&PrevSpec, unsigned &DiagID) {
694 if (TypeSpecType != TST_unspecified) {
695 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
696 DiagID = diag::err_invalid_vector_decl_spec_combination;
697 return true;
698 }
699 TypeAltiVecVector = isAltiVecVector;
700 AltiVecLoc = Loc;
701 return false;
702}
703
704bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
705 const char *&PrevSpec, unsigned &DiagID) {
Chris Lattner788b0fd2010-06-23 06:00:24 +0000706 if (!TypeAltiVecVector || TypeAltiVecPixel ||
707 (TypeSpecType != TST_unspecified)) {
John Thompson82287d12010-02-05 00:12:22 +0000708 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
709 DiagID = diag::err_invalid_pixel_decl_spec_combination;
710 return true;
711 }
John Thompson82287d12010-02-05 00:12:22 +0000712 TypeAltiVecPixel = isAltiVecPixel;
713 TSTLoc = Loc;
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000714 TSTNameLoc = Loc;
Reid Spencer5f016e22007-07-11 17:01:13 +0000715 return false;
716}
717
Bill Schmidt3e3d20b2013-07-03 20:54:09 +0000718bool DeclSpec::SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
719 const char *&PrevSpec, unsigned &DiagID) {
720 if (!TypeAltiVecVector || TypeAltiVecBool ||
721 (TypeSpecType != TST_unspecified)) {
722 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
723 DiagID = diag::err_invalid_vector_bool_decl_spec;
724 return true;
725 }
726 TypeAltiVecBool = isAltiVecBool;
727 TSTLoc = Loc;
728 TSTNameLoc = Loc;
729 return false;
730}
731
Douglas Gregorddc29e12009-02-06 22:42:48 +0000732bool DeclSpec::SetTypeSpecError() {
733 TypeSpecType = TST_error;
John McCall9e46b8c2010-08-26 17:22:34 +0000734 TypeSpecOwned = false;
Douglas Gregorddc29e12009-02-06 22:42:48 +0000735 TSTLoc = SourceLocation();
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000736 TSTNameLoc = SourceLocation();
Douglas Gregorddc29e12009-02-06 22:42:48 +0000737 return false;
738}
739
Reid Spencer5f016e22007-07-11 17:01:13 +0000740bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
Richard Smithd654f2d2012-10-17 23:31:46 +0000741 unsigned &DiagID, const LangOptions &Lang) {
742 // Duplicates are permitted in C99, but are not permitted in C++. However,
743 // since this is likely not what the user intended, we will always warn. We
744 // do not need to set the qualifier's location since we already have it.
Aaron Ballmanc8286202012-08-28 20:55:40 +0000745 if (TypeQualifiers & T) {
Aaron Ballmana14f4002012-08-29 12:35:14 +0000746 bool IsExtension = true;
Richard Smithd654f2d2012-10-17 23:31:46 +0000747 if (Lang.C99)
Aaron Ballmana14f4002012-08-29 12:35:14 +0000748 IsExtension = false;
Aaron Ballmanc8286202012-08-28 20:55:40 +0000749 return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension);
750 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000751 TypeQualifiers |= T;
Mike Stump1eb44332009-09-09 15:08:12 +0000752
Reid Spencer5f016e22007-07-11 17:01:13 +0000753 switch (T) {
Richard Smith4cf4a5e2013-03-28 01:55:44 +0000754 case TQ_unspecified: break;
755 case TQ_const: TQ_constLoc = Loc; return false;
756 case TQ_restrict: TQ_restrictLoc = Loc; return false;
757 case TQ_volatile: TQ_volatileLoc = Loc; return false;
758 case TQ_atomic: TQ_atomicLoc = Loc; return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000759 }
Richard Smith4cf4a5e2013-03-28 01:55:44 +0000760
761 llvm_unreachable("Unknown type qualifier!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000762}
763
Chad Rosier22aa6902012-12-21 22:24:43 +0000764bool DeclSpec::setFunctionSpecInline(SourceLocation Loc) {
Chad Rosier67a0f6e2012-12-21 22:38:37 +0000765 // 'inline inline' is ok.
Reid Spencer5f016e22007-07-11 17:01:13 +0000766 FS_inline_specified = true;
767 FS_inlineLoc = Loc;
768 return false;
769}
770
Chad Rosier22aa6902012-12-21 22:24:43 +0000771bool DeclSpec::setFunctionSpecVirtual(SourceLocation Loc) {
Chad Rosier67a0f6e2012-12-21 22:38:37 +0000772 // 'virtual virtual' is ok.
Douglas Gregorb48fe382008-10-31 09:07:45 +0000773 FS_virtual_specified = true;
774 FS_virtualLoc = Loc;
775 return false;
776}
777
Chad Rosier22aa6902012-12-21 22:24:43 +0000778bool DeclSpec::setFunctionSpecExplicit(SourceLocation Loc) {
Douglas Gregorb48fe382008-10-31 09:07:45 +0000779 // 'explicit explicit' is ok.
780 FS_explicit_specified = true;
781 FS_explicitLoc = Loc;
782 return false;
783}
784
Richard Smithde03c152013-01-17 22:16:11 +0000785bool DeclSpec::setFunctionSpecNoreturn(SourceLocation Loc) {
786 // '_Noreturn _Noreturn' is ok.
787 FS_noreturn_specified = true;
788 FS_noreturnLoc = Loc;
789 return false;
790}
791
John McCallfec54012009-08-03 20:12:06 +0000792bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
793 unsigned &DiagID) {
Anders Carlssonf47f7a12009-05-06 04:46:28 +0000794 if (Friend_specified) {
795 PrevSpec = "friend";
John McCallfec54012009-08-03 20:12:06 +0000796 DiagID = diag::ext_duplicate_declspec;
Anders Carlssonf47f7a12009-05-06 04:46:28 +0000797 return true;
798 }
John McCallfec54012009-08-03 20:12:06 +0000799
Anders Carlssonf47f7a12009-05-06 04:46:28 +0000800 Friend_specified = true;
801 FriendLoc = Loc;
802 return false;
803}
Reid Spencer5f016e22007-07-11 17:01:13 +0000804
Douglas Gregor8d267c52011-09-09 02:06:17 +0000805bool DeclSpec::setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
806 unsigned &DiagID) {
807 if (isModulePrivateSpecified()) {
808 PrevSpec = "__module_private__";
809 DiagID = diag::ext_duplicate_declspec;
810 return true;
811 }
812
813 ModulePrivateLoc = Loc;
814 return false;
815}
816
Sebastian Redl2ac67232009-11-05 15:47:02 +0000817bool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
818 unsigned &DiagID) {
819 // 'constexpr constexpr' is ok.
820 Constexpr_specified = true;
821 ConstexprLoc = Loc;
822 return false;
823}
824
John McCalld226f652010-08-21 09:40:31 +0000825void DeclSpec::setProtocolQualifiers(Decl * const *Protos,
Argyrios Kyrtzidise3a535b2009-09-29 19:42:11 +0000826 unsigned NP,
827 SourceLocation *ProtoLocs,
828 SourceLocation LAngleLoc) {
829 if (NP == 0) return;
David Greenec23e69d2013-01-15 22:09:39 +0000830 Decl **ProtoQuals = new Decl*[NP];
831 memcpy(ProtoQuals, Protos, sizeof(Decl*)*NP);
832 ProtocolQualifiers = ProtoQuals;
Argyrios Kyrtzidise3a535b2009-09-29 19:42:11 +0000833 ProtocolLocs = new SourceLocation[NP];
Argyrios Kyrtzidise3a535b2009-09-29 19:42:11 +0000834 memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP);
835 NumProtocolQualifiers = NP;
836 ProtocolLAngleLoc = LAngleLoc;
837}
838
Douglas Gregorddf889a2010-01-18 18:04:31 +0000839void DeclSpec::SaveWrittenBuiltinSpecs() {
840 writtenBS.Sign = getTypeSpecSign();
841 writtenBS.Width = getTypeSpecWidth();
842 writtenBS.Type = getTypeSpecType();
843 // Search the list of attributes for the presence of a mode attribute.
844 writtenBS.ModeAttr = false;
John McCall7f040a92010-12-24 02:08:15 +0000845 AttributeList* attrs = getAttributes().getList();
Douglas Gregorddf889a2010-01-18 18:04:31 +0000846 while (attrs) {
Sean Hunt8e083e72012-06-19 23:57:03 +0000847 if (attrs->getKind() == AttributeList::AT_Mode) {
Douglas Gregorddf889a2010-01-18 18:04:31 +0000848 writtenBS.ModeAttr = true;
849 break;
850 }
851 attrs = attrs->getNext();
852 }
853}
854
Reid Spencer5f016e22007-07-11 17:01:13 +0000855/// Finish - This does final analysis of the declspec, rejecting things like
856/// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
857/// diag::NUM_DIAGNOSTICS if there is no error. After calling this method,
858/// DeclSpec is guaranteed self-consistent, even if an error occurred.
David Blaikied6471f72011-09-25 23:23:43 +0000859void DeclSpec::Finish(DiagnosticsEngine &D, Preprocessor &PP) {
Douglas Gregorddf889a2010-01-18 18:04:31 +0000860 // Before possibly changing their values, save specs as written.
861 SaveWrittenBuiltinSpecs();
862
Reid Spencer5f016e22007-07-11 17:01:13 +0000863 // Check the type specifier components first.
864
Richard Smitha2c36462013-04-26 16:15:35 +0000865 // If decltype(auto) is used, no other type specifiers are permitted.
866 if (TypeSpecType == TST_decltype_auto &&
867 (TypeSpecWidth != TSW_unspecified ||
868 TypeSpecComplex != TSC_unspecified ||
869 TypeSpecSign != TSS_unspecified ||
870 TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
871 TypeQualifiers)) {
Benjamin Kramerc6a31772013-04-27 15:07:53 +0000872 const unsigned NumLocs = 8;
Richard Smitha2c36462013-04-26 16:15:35 +0000873 SourceLocation ExtraLocs[NumLocs] = {
874 TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
875 TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc
876 };
877 FixItHint Hints[NumLocs];
878 SourceLocation FirstLoc;
879 for (unsigned I = 0; I != NumLocs; ++I) {
880 if (!ExtraLocs[I].isInvalid()) {
881 if (FirstLoc.isInvalid() ||
882 PP.getSourceManager().isBeforeInTranslationUnit(ExtraLocs[I],
883 FirstLoc))
884 FirstLoc = ExtraLocs[I];
885 Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]);
886 }
887 }
888 TypeSpecWidth = TSW_unspecified;
889 TypeSpecComplex = TSC_unspecified;
890 TypeSpecSign = TSS_unspecified;
891 TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false;
892 TypeQualifiers = 0;
893 Diag(D, TSTLoc, diag::err_decltype_auto_cannot_be_combined)
894 << Hints[0] << Hints[1] << Hints[2] << Hints[3]
895 << Hints[4] << Hints[5] << Hints[6] << Hints[7];
896 }
897
Chris Lattner788b0fd2010-06-23 06:00:24 +0000898 // Validate and finalize AltiVec vector declspec.
899 if (TypeAltiVecVector) {
900 if (TypeAltiVecBool) {
901 // Sign specifiers are not allowed with vector bool. (PIM 2.1)
902 if (TypeSpecSign != TSS_unspecified) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000903 Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec)
Chris Lattner788b0fd2010-06-23 06:00:24 +0000904 << getSpecifierName((TSS)TypeSpecSign);
905 }
906
907 // Only char/int are valid with vector bool. (PIM 2.1)
Duncan Sands2e964a922010-06-23 19:34:52 +0000908 if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) &&
909 (TypeSpecType != TST_int)) || TypeAltiVecPixel) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000910 Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec)
Chris Lattner788b0fd2010-06-23 06:00:24 +0000911 << (TypeAltiVecPixel ? "__pixel" :
912 getSpecifierName((TST)TypeSpecType));
913 }
914
915 // Only 'short' is valid with vector bool. (PIM 2.1)
916 if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short))
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000917 Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec)
Chris Lattner788b0fd2010-06-23 06:00:24 +0000918 << getSpecifierName((TSW)TypeSpecWidth);
919
920 // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
921 if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) ||
922 (TypeSpecWidth != TSW_unspecified))
923 TypeSpecSign = TSS_unsigned;
924 }
925
926 if (TypeAltiVecPixel) {
927 //TODO: perform validation
928 TypeSpecType = TST_int;
929 TypeSpecSign = TSS_unsigned;
930 TypeSpecWidth = TSW_short;
John McCall9e46b8c2010-08-26 17:22:34 +0000931 TypeSpecOwned = false;
Chris Lattner788b0fd2010-06-23 06:00:24 +0000932 }
933 }
934
Argyrios Kyrtzidis64c438a2008-08-09 16:51:54 +0000935 // signed/unsigned are only valid with int/char/wchar_t.
Reid Spencer5f016e22007-07-11 17:01:13 +0000936 if (TypeSpecSign != TSS_unspecified) {
937 if (TypeSpecType == TST_unspecified)
938 TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
Richard Smith5a5a9712012-04-04 06:24:32 +0000939 else if (TypeSpecType != TST_int && TypeSpecType != TST_int128 &&
Argyrios Kyrtzidis64c438a2008-08-09 16:51:54 +0000940 TypeSpecType != TST_char && TypeSpecType != TST_wchar) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000941 Diag(D, TSSLoc, diag::err_invalid_sign_spec)
Chris Lattner254be6a2008-11-22 08:32:36 +0000942 << getSpecifierName((TST)TypeSpecType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000943 // signed double -> double.
944 TypeSpecSign = TSS_unspecified;
945 }
946 }
947
948 // Validate the width of the type.
949 switch (TypeSpecWidth) {
950 case TSW_unspecified: break;
951 case TSW_short: // short int
952 case TSW_longlong: // long long int
953 if (TypeSpecType == TST_unspecified)
954 TypeSpecType = TST_int; // short -> short int, long long -> long long int.
955 else if (TypeSpecType != TST_int) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000956 Diag(D, TSWLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000957 TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec
Chris Lattner254be6a2008-11-22 08:32:36 +0000958 : diag::err_invalid_longlong_spec)
959 << getSpecifierName((TST)TypeSpecType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000960 TypeSpecType = TST_int;
John McCall9e46b8c2010-08-26 17:22:34 +0000961 TypeSpecOwned = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000962 }
963 break;
964 case TSW_long: // long double, long int
965 if (TypeSpecType == TST_unspecified)
966 TypeSpecType = TST_int; // long -> long int.
967 else if (TypeSpecType != TST_int && TypeSpecType != TST_double) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000968 Diag(D, TSWLoc, diag::err_invalid_long_spec)
Chris Lattner254be6a2008-11-22 08:32:36 +0000969 << getSpecifierName((TST)TypeSpecType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000970 TypeSpecType = TST_int;
John McCall9e46b8c2010-08-26 17:22:34 +0000971 TypeSpecOwned = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000972 }
973 break;
974 }
Mike Stump1eb44332009-09-09 15:08:12 +0000975
Reid Spencer5f016e22007-07-11 17:01:13 +0000976 // TODO: if the implementation does not implement _Complex or _Imaginary,
977 // disallow their use. Need information about the backend.
978 if (TypeSpecComplex != TSC_unspecified) {
979 if (TypeSpecType == TST_unspecified) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000980 Diag(D, TSCLoc, diag::ext_plain_complex)
Douglas Gregor849b2432010-03-31 17:46:05 +0000981 << FixItHint::CreateInsertion(
Douglas Gregor9b3064b2009-04-01 22:41:11 +0000982 PP.getLocForEndOfToken(getTypeSpecComplexLoc()),
983 " double");
Reid Spencer5f016e22007-07-11 17:01:13 +0000984 TypeSpecType = TST_double; // _Complex -> _Complex double.
985 } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
986 // Note that this intentionally doesn't include _Complex _Bool.
David Blaikie4e4d0842012-03-11 07:00:24 +0000987 if (!PP.getLangOpts().CPlusPlus)
Eli Friedman7ead5c72012-01-10 04:58:17 +0000988 Diag(D, TSTLoc, diag::ext_integer_complex);
Reid Spencer5f016e22007-07-11 17:01:13 +0000989 } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000990 Diag(D, TSCLoc, diag::err_invalid_complex_spec)
Chris Lattner254be6a2008-11-22 08:32:36 +0000991 << getSpecifierName((TST)TypeSpecType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000992 TypeSpecComplex = TSC_unspecified;
993 }
994 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000995
Richard Smithec642442013-04-12 22:46:28 +0000996 // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and
997 // _Thread_local can only appear with the 'static' and 'extern' storage class
998 // specifiers. We also allow __private_extern__ as an extension.
999 if (ThreadStorageClassSpec != TSCS_unspecified) {
1000 switch (StorageClassSpec) {
1001 case SCS_unspecified:
1002 case SCS_extern:
1003 case SCS_private_extern:
1004 case SCS_static:
1005 break;
1006 default:
1007 if (PP.getSourceManager().isBeforeInTranslationUnit(
1008 getThreadStorageClassSpecLoc(), getStorageClassSpecLoc()))
1009 Diag(D, getStorageClassSpecLoc(),
1010 diag::err_invalid_decl_spec_combination)
1011 << DeclSpec::getSpecifierName(getThreadStorageClassSpec())
1012 << SourceRange(getThreadStorageClassSpecLoc());
1013 else
1014 Diag(D, getThreadStorageClassSpecLoc(),
1015 diag::err_invalid_decl_spec_combination)
1016 << DeclSpec::getSpecifierName(getStorageClassSpec())
1017 << SourceRange(getStorageClassSpecLoc());
1018 // Discard the thread storage class specifier to recover.
1019 ThreadStorageClassSpec = TSCS_unspecified;
1020 ThreadStorageClassSpecLoc = SourceLocation();
1021 }
1022 }
1023
Richard Smith8f4fb192011-09-04 19:54:14 +00001024 // If no type specifier was provided and we're parsing a language where
1025 // the type specifier is not optional, but we got 'auto' as a storage
1026 // class specifier, then assume this is an attempt to use C++0x's 'auto'
1027 // type specifier.
Richard Smith58eb3702013-04-30 22:43:51 +00001028 if (PP.getLangOpts().CPlusPlus &&
Richard Smith8f4fb192011-09-04 19:54:14 +00001029 TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) {
1030 TypeSpecType = TST_auto;
Rafael Espindolad2615cc2013-04-03 19:27:57 +00001031 StorageClassSpec = SCS_unspecified;
Richard Smith8f4fb192011-09-04 19:54:14 +00001032 TSTLoc = TSTNameLoc = StorageClassSpecLoc;
1033 StorageClassSpecLoc = SourceLocation();
1034 }
1035 // Diagnose if we've recovered from an ill-formed 'auto' storage class
Richard Smitha2c36462013-04-26 16:15:35 +00001036 // specifier in a pre-C++11 dialect of C++.
Richard Smith80ad52f2013-01-02 11:42:31 +00001037 if (!PP.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto)
Richard Smith8f4fb192011-09-04 19:54:14 +00001038 Diag(D, TSTLoc, diag::ext_auto_type_specifier);
Richard Smith80ad52f2013-01-02 11:42:31 +00001039 if (PP.getLangOpts().CPlusPlus && !PP.getLangOpts().CPlusPlus11 &&
Richard Smith8f4fb192011-09-04 19:54:14 +00001040 StorageClassSpec == SCS_auto)
1041 Diag(D, StorageClassSpecLoc, diag::warn_auto_storage_class)
1042 << FixItHint::CreateRemoval(StorageClassSpecLoc);
Richard Smith841804b2011-10-17 23:06:20 +00001043 if (TypeSpecType == TST_char16 || TypeSpecType == TST_char32)
1044 Diag(D, TSTLoc, diag::warn_cxx98_compat_unicode_type)
1045 << (TypeSpecType == TST_char16 ? "char16_t" : "char32_t");
Richard Smith841804b2011-10-17 23:06:20 +00001046 if (Constexpr_specified)
1047 Diag(D, ConstexprLoc, diag::warn_cxx98_compat_constexpr);
Richard Smith8f4fb192011-09-04 19:54:14 +00001048
John McCall67d1a672009-08-06 02:15:43 +00001049 // C++ [class.friend]p6:
1050 // No storage-class-specifier shall appear in the decl-specifier-seq
1051 // of a friend declaration.
Richard Smithec642442013-04-12 22:46:28 +00001052 if (isFriendSpecified() &&
1053 (getStorageClassSpec() || getThreadStorageClassSpec())) {
1054 SmallString<32> SpecName;
1055 SourceLocation SCLoc;
1056 FixItHint StorageHint, ThreadHint;
John McCall67d1a672009-08-06 02:15:43 +00001057
Richard Smithec642442013-04-12 22:46:28 +00001058 if (DeclSpec::SCS SC = getStorageClassSpec()) {
1059 SpecName = getSpecifierName(SC);
1060 SCLoc = getStorageClassSpecLoc();
1061 StorageHint = FixItHint::CreateRemoval(SCLoc);
1062 }
1063
1064 if (DeclSpec::TSCS TSC = getThreadStorageClassSpec()) {
1065 if (!SpecName.empty()) SpecName += " ";
1066 SpecName += getSpecifierName(TSC);
1067 SCLoc = getThreadStorageClassSpecLoc();
1068 ThreadHint = FixItHint::CreateRemoval(SCLoc);
1069 }
John McCall67d1a672009-08-06 02:15:43 +00001070
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +00001071 Diag(D, SCLoc, diag::err_friend_storage_spec)
Richard Smithec642442013-04-12 22:46:28 +00001072 << SpecName << StorageHint << ThreadHint;
John McCall67d1a672009-08-06 02:15:43 +00001073
1074 ClearStorageClassSpecs();
1075 }
1076
Douglas Gregor6274d302011-09-09 21:14:29 +00001077 assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
1078
Reid Spencer5f016e22007-07-11 17:01:13 +00001079 // Okay, now we can infer the real type.
Mike Stump1eb44332009-09-09 15:08:12 +00001080
Reid Spencer5f016e22007-07-11 17:01:13 +00001081 // TODO: return "auto function" and other bad things based on the real type.
Mike Stump1eb44332009-09-09 15:08:12 +00001082
Reid Spencer5f016e22007-07-11 17:01:13 +00001083 // 'data definition has no type or storage class'?
1084}
Daniel Dunbare4858a62008-08-11 03:45:03 +00001085
Sebastian Redla4ed0d82008-12-28 15:28:59 +00001086bool DeclSpec::isMissingDeclaratorOk() {
1087 TST tst = getTypeSpecType();
John McCallb3d87482010-08-24 05:47:05 +00001088 return isDeclRep(tst) && getRepAsDecl() != 0 &&
1089 StorageClassSpec != DeclSpec::SCS_typedef;
Sebastian Redla4ed0d82008-12-28 15:28:59 +00001090}
Douglas Gregor3f9a0562009-11-03 01:35:08 +00001091
Douglas Gregor3f9a0562009-11-03 01:35:08 +00001092void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc,
1093 OverloadedOperatorKind Op,
1094 SourceLocation SymbolLocations[3]) {
1095 Kind = IK_OperatorFunctionId;
1096 StartLocation = OperatorLoc;
1097 EndLocation = OperatorLoc;
1098 OperatorFunctionId.Operator = Op;
1099 for (unsigned I = 0; I != 3; ++I) {
1100 OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding();
1101
1102 if (SymbolLocations[I].isValid())
1103 EndLocation = SymbolLocations[I];
1104 }
1105}
Anders Carlssonb971dbd2011-01-17 03:05:47 +00001106
Anders Carlssoncc54d592011-01-22 16:56:46 +00001107bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc,
Anders Carlsson46127a92011-01-22 15:58:16 +00001108 const char *&PrevSpec) {
Douglas Gregorf5251602011-03-08 17:10:18 +00001109 LastLocation = Loc;
1110
Anders Carlssonb971dbd2011-01-17 03:05:47 +00001111 if (Specifiers & VS) {
1112 PrevSpec = getSpecifierName(VS);
1113 return true;
1114 }
1115
1116 Specifiers |= VS;
1117
1118 switch (VS) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001119 default: llvm_unreachable("Unknown specifier!");
Anders Carlssonb971dbd2011-01-17 03:05:47 +00001120 case VS_Override: VS_overrideLoc = Loc; break;
David Majnemer7121bdb2013-10-18 00:33:31 +00001121 case VS_Sealed:
Anders Carlssonb971dbd2011-01-17 03:05:47 +00001122 case VS_Final: VS_finalLoc = Loc; break;
Anders Carlssonb971dbd2011-01-17 03:05:47 +00001123 }
Anders Carlsson46127a92011-01-22 15:58:16 +00001124
Anders Carlssonb971dbd2011-01-17 03:05:47 +00001125 return false;
1126}
1127
Anders Carlssoncc54d592011-01-22 16:56:46 +00001128const char *VirtSpecifiers::getSpecifierName(Specifier VS) {
Anders Carlssonc46bb7d2011-01-22 15:11:37 +00001129 switch (VS) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001130 default: llvm_unreachable("Unknown specifier");
Anders Carlssonc46bb7d2011-01-22 15:11:37 +00001131 case VS_Override: return "override";
1132 case VS_Final: return "final";
David Majnemer7121bdb2013-10-18 00:33:31 +00001133 case VS_Sealed: return "sealed";
Anders Carlssonc46bb7d2011-01-22 15:11:37 +00001134 }
1135}