clang  3.7.0
DeclSpec.cpp
Go to the documentation of this file.
1 //===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements semantic analysis for declaration specifiers.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/Sema/DeclSpec.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/Expr.h"
19 #include "clang/AST/TypeLoc.h"
21 #include "clang/Basic/TargetInfo.h"
22 #include "clang/Lex/Preprocessor.h"
23 #include "clang/Parse/ParseDiagnostic.h" // FIXME: remove this back-dependency!
24 #include "clang/Sema/LocInfoType.h"
26 #include "clang/Sema/Sema.h"
28 #include "llvm/ADT/STLExtras.h"
29 #include "llvm/ADT/SmallString.h"
30 #include "llvm/Support/ErrorHandling.h"
31 #include <cstring>
32 using namespace clang;
33 
34 
36  unsigned DiagID) {
37  return D.Report(Loc, DiagID);
38 }
39 
40 
42  assert(TemplateId && "NULL template-id annotation?");
44  this->TemplateId = TemplateId;
45  StartLocation = TemplateId->TemplateNameLoc;
46  EndLocation = TemplateId->RAngleLoc;
47 }
48 
50  assert(TemplateId && "NULL template-id annotation?");
52  this->TemplateId = TemplateId;
53  StartLocation = TemplateId->TemplateNameLoc;
54  EndLocation = TemplateId->RAngleLoc;
55 }
56 
58  TypeLoc TL, SourceLocation ColonColonLoc) {
59  Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc);
60  if (Range.getBegin().isInvalid())
61  Range.setBegin(TL.getBeginLoc());
62  Range.setEnd(ColonColonLoc);
63 
64  assert(Range == Builder.getSourceRange() &&
65  "NestedNameSpecifierLoc range computation incorrect");
66 }
67 
70  SourceLocation ColonColonLoc) {
71  Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc);
72 
73  if (Range.getBegin().isInvalid())
74  Range.setBegin(IdentifierLoc);
75  Range.setEnd(ColonColonLoc);
76 
77  assert(Range == Builder.getSourceRange() &&
78  "NestedNameSpecifierLoc range computation incorrect");
79 }
80 
82  SourceLocation NamespaceLoc,
83  SourceLocation ColonColonLoc) {
84  Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc);
85 
86  if (Range.getBegin().isInvalid())
87  Range.setBegin(NamespaceLoc);
88  Range.setEnd(ColonColonLoc);
89 
90  assert(Range == Builder.getSourceRange() &&
91  "NestedNameSpecifierLoc range computation incorrect");
92 }
93 
95  SourceLocation AliasLoc,
96  SourceLocation ColonColonLoc) {
97  Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc);
98 
99  if (Range.getBegin().isInvalid())
100  Range.setBegin(AliasLoc);
101  Range.setEnd(ColonColonLoc);
102 
103  assert(Range == Builder.getSourceRange() &&
104  "NestedNameSpecifierLoc range computation incorrect");
105 }
106 
108  SourceLocation ColonColonLoc) {
109  Builder.MakeGlobal(Context, ColonColonLoc);
110 
111  Range = SourceRange(ColonColonLoc);
112 
113  assert(Range == Builder.getSourceRange() &&
114  "NestedNameSpecifierLoc range computation incorrect");
115 }
116 
118  SourceLocation SuperLoc,
119  SourceLocation ColonColonLoc) {
120  Builder.MakeSuper(Context, RD, SuperLoc, ColonColonLoc);
121 
122  Range.setBegin(SuperLoc);
123  Range.setEnd(ColonColonLoc);
124 
125  assert(Range == Builder.getSourceRange() &&
126  "NestedNameSpecifierLoc range computation incorrect");
127 }
128 
130  NestedNameSpecifier *Qualifier, SourceRange R) {
131  Builder.MakeTrivial(Context, Qualifier, R);
132  Range = R;
133 }
134 
136  if (!Other) {
137  Range = SourceRange();
138  Builder.Clear();
139  return;
140  }
141 
142  Range = Other.getSourceRange();
143  Builder.Adopt(Other);
144 }
145 
147  if (!Builder.getRepresentation())
148  return SourceLocation();
149  return Builder.getTemporary().getLocalBeginLoc();
150 }
151 
154  if (!Builder.getRepresentation())
155  return NestedNameSpecifierLoc();
156 
157  return Builder.getWithLocInContext(Context);
158 }
159 
160 /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
161 /// "TheDeclarator" is the declarator that this will be added to.
163  bool isAmbiguous,
164  SourceLocation LParenLoc,
165  ParamInfo *Params,
166  unsigned NumParams,
167  SourceLocation EllipsisLoc,
168  SourceLocation RParenLoc,
169  unsigned TypeQuals,
170  bool RefQualifierIsLvalueRef,
171  SourceLocation RefQualifierLoc,
172  SourceLocation ConstQualifierLoc,
174  VolatileQualifierLoc,
176  RestrictQualifierLoc,
177  SourceLocation MutableLoc,
179  ESpecType,
180  SourceLocation ESpecLoc,
181  ParsedType *Exceptions,
182  SourceRange *ExceptionRanges,
183  unsigned NumExceptions,
184  Expr *NoexceptExpr,
185  CachedTokens *ExceptionSpecTokens,
186  SourceLocation LocalRangeBegin,
187  SourceLocation LocalRangeEnd,
188  Declarator &TheDeclarator,
189  TypeResult TrailingReturnType) {
190  assert(!(TypeQuals & DeclSpec::TQ_atomic) &&
191  "function cannot have _Atomic qualifier");
192 
193  DeclaratorChunk I;
194  I.Kind = Function;
195  I.Loc = LocalRangeBegin;
196  I.EndLoc = LocalRangeEnd;
197  I.Fun.AttrList = nullptr;
198  I.Fun.hasPrototype = hasProto;
199  I.Fun.isVariadic = EllipsisLoc.isValid();
200  I.Fun.isAmbiguous = isAmbiguous;
201  I.Fun.LParenLoc = LParenLoc.getRawEncoding();
202  I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding();
203  I.Fun.RParenLoc = RParenLoc.getRawEncoding();
204  I.Fun.DeleteParams = false;
205  I.Fun.TypeQuals = TypeQuals;
206  I.Fun.NumParams = NumParams;
207  I.Fun.Params = nullptr;
208  I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
209  I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding();
210  I.Fun.ConstQualifierLoc = ConstQualifierLoc.getRawEncoding();
211  I.Fun.VolatileQualifierLoc = VolatileQualifierLoc.getRawEncoding();
212  I.Fun.RestrictQualifierLoc = RestrictQualifierLoc.getRawEncoding();
213  I.Fun.MutableLoc = MutableLoc.getRawEncoding();
214  I.Fun.ExceptionSpecType = ESpecType;
215  I.Fun.ExceptionSpecLoc = ESpecLoc.getRawEncoding();
216  I.Fun.NumExceptions = 0;
217  I.Fun.Exceptions = nullptr;
218  I.Fun.NoexceptExpr = nullptr;
219  I.Fun.HasTrailingReturnType = TrailingReturnType.isUsable() ||
220  TrailingReturnType.isInvalid();
221  I.Fun.TrailingReturnType = TrailingReturnType.get();
222 
223  assert(I.Fun.TypeQuals == TypeQuals && "bitfield overflow");
224  assert(I.Fun.ExceptionSpecType == ESpecType && "bitfield overflow");
225 
226  // new[] a parameter array if needed.
227  if (NumParams) {
228  // If the 'InlineParams' in Declarator is unused and big enough, put our
229  // parameter list there (in an effort to avoid new/delete traffic). If it
230  // is already used (consider a function returning a function pointer) or too
231  // small (function with too many parameters), go to the heap.
232  if (!TheDeclarator.InlineParamsUsed &&
233  NumParams <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
234  I.Fun.Params = TheDeclarator.InlineParams;
235  I.Fun.DeleteParams = false;
236  TheDeclarator.InlineParamsUsed = true;
237  } else {
238  I.Fun.Params = new DeclaratorChunk::ParamInfo[NumParams];
239  I.Fun.DeleteParams = true;
240  }
241  memcpy(I.Fun.Params, Params, sizeof(Params[0]) * NumParams);
242  }
243 
244  // Check what exception specification information we should actually store.
245  switch (ESpecType) {
246  default: break; // By default, save nothing.
247  case EST_Dynamic:
248  // new[] an exception array if needed
249  if (NumExceptions) {
250  I.Fun.NumExceptions = NumExceptions;
251  I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
252  for (unsigned i = 0; i != NumExceptions; ++i) {
253  I.Fun.Exceptions[i].Ty = Exceptions[i];
254  I.Fun.Exceptions[i].Range = ExceptionRanges[i];
255  }
256  }
257  break;
258 
260  I.Fun.NoexceptExpr = NoexceptExpr;
261  break;
262 
263  case EST_Unparsed:
264  I.Fun.ExceptionSpecTokens = ExceptionSpecTokens;
265  break;
266  }
267  return I;
268 }
269 
271  for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
272  switch (DeclTypeInfo[i].Kind) {
274  return true;
276  continue;
282  return false;
283  }
284  llvm_unreachable("Invalid type chunk");
285  }
286 
287  switch (DS.getTypeSpecType()) {
288  case TST_atomic:
289  case TST_auto:
290  case TST_bool:
291  case TST_char:
292  case TST_char16:
293  case TST_char32:
294  case TST_class:
295  case TST_decimal128:
296  case TST_decimal32:
297  case TST_decimal64:
298  case TST_double:
299  case TST_enum:
300  case TST_error:
301  case TST_float:
302  case TST_half:
303  case TST_int:
304  case TST_int128:
305  case TST_struct:
306  case TST_interface:
307  case TST_union:
308  case TST_unknown_anytype:
309  case TST_unspecified:
310  case TST_void:
311  case TST_wchar:
312  return false;
313 
314  case TST_decltype_auto:
315  // This must have an initializer, so can't be a function declaration,
316  // even if the initializer has function type.
317  return false;
318 
319  case TST_decltype:
320  case TST_typeofExpr:
321  if (Expr *E = DS.getRepAsExpr())
322  return E->getType()->isFunctionType();
323  return false;
324 
325  case TST_underlyingType:
326  case TST_typename:
327  case TST_typeofType: {
328  QualType QT = DS.getRepAsType().get();
329  if (QT.isNull())
330  return false;
331 
332  if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
333  QT = LIT->getType();
334 
335  if (QT.isNull())
336  return false;
337 
338  return QT->isFunctionType();
339  }
340  }
341 
342  llvm_unreachable("Invalid TypeSpecType!");
343 }
344 
346  assert(getContext() == MemberContext);
350  getName().OperatorFunctionId.Operator));
351 }
352 
354  if (!TypeSpecOwned)
355  return false;
356  return cast<TagDecl>(getRepAsDecl())->isCompleteDefinition();
357 }
358 
359 /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
360 /// declaration specifier includes.
361 ///
363  unsigned Res = 0;
364  if (StorageClassSpec != SCS_unspecified ||
365  ThreadStorageClassSpec != TSCS_unspecified)
367 
368  if (TypeQualifiers != TQ_unspecified)
369  Res |= PQ_TypeQualifier;
370 
371  if (hasTypeSpecifier())
372  Res |= PQ_TypeSpecifier;
373 
374  if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified ||
375  FS_noreturn_specified || FS_forceinline_specified)
376  Res |= PQ_FunctionSpecifier;
377  return Res;
378 }
379 
380 template <class T> static bool BadSpecifier(T TNew, T TPrev,
381  const char *&PrevSpec,
382  unsigned &DiagID,
383  bool IsExtension = true) {
384  PrevSpec = DeclSpec::getSpecifierName(TPrev);
385  if (TNew != TPrev)
386  DiagID = diag::err_invalid_decl_spec_combination;
387  else
388  DiagID = IsExtension ? diag::ext_duplicate_declspec :
389  diag::warn_duplicate_declspec;
390  return true;
391 }
392 
394  switch (S) {
395  case DeclSpec::SCS_unspecified: return "unspecified";
396  case DeclSpec::SCS_typedef: return "typedef";
397  case DeclSpec::SCS_extern: return "extern";
398  case DeclSpec::SCS_static: return "static";
399  case DeclSpec::SCS_auto: return "auto";
400  case DeclSpec::SCS_register: return "register";
401  case DeclSpec::SCS_private_extern: return "__private_extern__";
402  case DeclSpec::SCS_mutable: return "mutable";
403  }
404  llvm_unreachable("Unknown typespec!");
405 }
406 
408  switch (S) {
409  case DeclSpec::TSCS_unspecified: return "unspecified";
410  case DeclSpec::TSCS___thread: return "__thread";
411  case DeclSpec::TSCS_thread_local: return "thread_local";
412  case DeclSpec::TSCS__Thread_local: return "_Thread_local";
413  }
414  llvm_unreachable("Unknown typespec!");
415 }
416 
418  switch (W) {
419  case TSW_unspecified: return "unspecified";
420  case TSW_short: return "short";
421  case TSW_long: return "long";
422  case TSW_longlong: return "long long";
423  }
424  llvm_unreachable("Unknown typespec!");
425 }
426 
428  switch (C) {
429  case TSC_unspecified: return "unspecified";
430  case TSC_imaginary: return "imaginary";
431  case TSC_complex: return "complex";
432  }
433  llvm_unreachable("Unknown typespec!");
434 }
435 
436 
438  switch (S) {
439  case TSS_unspecified: return "unspecified";
440  case TSS_signed: return "signed";
441  case TSS_unsigned: return "unsigned";
442  }
443  llvm_unreachable("Unknown typespec!");
444 }
445 
447  const PrintingPolicy &Policy) {
448  switch (T) {
449  case DeclSpec::TST_unspecified: return "unspecified";
450  case DeclSpec::TST_void: return "void";
451  case DeclSpec::TST_char: return "char";
452  case DeclSpec::TST_wchar: return Policy.MSWChar ? "__wchar_t" : "wchar_t";
453  case DeclSpec::TST_char16: return "char16_t";
454  case DeclSpec::TST_char32: return "char32_t";
455  case DeclSpec::TST_int: return "int";
456  case DeclSpec::TST_int128: return "__int128";
457  case DeclSpec::TST_half: return "half";
458  case DeclSpec::TST_float: return "float";
459  case DeclSpec::TST_double: return "double";
460  case DeclSpec::TST_bool: return Policy.Bool ? "bool" : "_Bool";
461  case DeclSpec::TST_decimal32: return "_Decimal32";
462  case DeclSpec::TST_decimal64: return "_Decimal64";
463  case DeclSpec::TST_decimal128: return "_Decimal128";
464  case DeclSpec::TST_enum: return "enum";
465  case DeclSpec::TST_class: return "class";
466  case DeclSpec::TST_union: return "union";
467  case DeclSpec::TST_struct: return "struct";
468  case DeclSpec::TST_interface: return "__interface";
469  case DeclSpec::TST_typename: return "type-name";
471  case DeclSpec::TST_typeofExpr: return "typeof";
472  case DeclSpec::TST_auto: return "auto";
473  case DeclSpec::TST_decltype: return "(decltype)";
474  case DeclSpec::TST_decltype_auto: return "decltype(auto)";
475  case DeclSpec::TST_underlyingType: return "__underlying_type";
476  case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
477  case DeclSpec::TST_atomic: return "_Atomic";
478  case DeclSpec::TST_error: return "(error)";
479  }
480  llvm_unreachable("Unknown typespec!");
481 }
482 
484  switch (T) {
485  case DeclSpec::TQ_unspecified: return "unspecified";
486  case DeclSpec::TQ_const: return "const";
487  case DeclSpec::TQ_restrict: return "restrict";
488  case DeclSpec::TQ_volatile: return "volatile";
489  case DeclSpec::TQ_atomic: return "_Atomic";
490  }
491  llvm_unreachable("Unknown typespec!");
492 }
493 
495  const char *&PrevSpec,
496  unsigned &DiagID,
497  const PrintingPolicy &Policy) {
498  // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class
499  // specifiers are not supported.
500  // It seems sensible to prohibit private_extern too
501  // The cl_clang_storage_class_specifiers extension enables support for
502  // these storage-class specifiers.
503  // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class
504  // specifiers are not supported."
505  if (S.getLangOpts().OpenCL &&
506  !S.getOpenCLOptions().cl_clang_storage_class_specifiers) {
507  switch (SC) {
508  case SCS_extern:
509  case SCS_private_extern:
510  case SCS_static:
511  if (S.getLangOpts().OpenCLVersion < 120) {
512  DiagID = diag::err_opencl_unknown_type_specifier;
513  PrevSpec = getSpecifierName(SC);
514  return true;
515  }
516  break;
517  case SCS_auto:
518  case SCS_register:
519  DiagID = diag::err_opencl_unknown_type_specifier;
520  PrevSpec = getSpecifierName(SC);
521  return true;
522  default:
523  break;
524  }
525  }
526 
527  if (StorageClassSpec != SCS_unspecified) {
528  // Maybe this is an attempt to use C++11 'auto' outside of C++11 mode.
529  bool isInvalid = true;
530  if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) {
531  if (SC == SCS_auto)
532  return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID, Policy);
533  if (StorageClassSpec == SCS_auto) {
534  isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc,
535  PrevSpec, DiagID, Policy);
536  assert(!isInvalid && "auto SCS -> TST recovery failed");
537  }
538  }
539 
540  // Changing storage class is allowed only if the previous one
541  // was the 'extern' that is part of a linkage specification and
542  // the new storage class is 'typedef'.
543  if (isInvalid &&
544  !(SCS_extern_in_linkage_spec &&
545  StorageClassSpec == SCS_extern &&
546  SC == SCS_typedef))
547  return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID);
548  }
549  StorageClassSpec = SC;
550  StorageClassSpecLoc = Loc;
551  assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
552  return false;
553 }
554 
556  const char *&PrevSpec,
557  unsigned &DiagID) {
558  if (ThreadStorageClassSpec != TSCS_unspecified)
559  return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID);
560 
561  ThreadStorageClassSpec = TSC;
562  ThreadStorageClassSpecLoc = Loc;
563  return false;
564 }
565 
566 /// These methods set the specified attribute of the DeclSpec, but return true
567 /// and ignore the request if invalid (e.g. "extern" then "auto" is
568 /// specified).
570  const char *&PrevSpec,
571  unsigned &DiagID,
572  const PrintingPolicy &Policy) {
573  // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
574  // for 'long long' we will keep the source location of the first 'long'.
575  if (TypeSpecWidth == TSW_unspecified)
576  TSWLoc = Loc;
577  // Allow turning long -> long long.
578  else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
579  return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
580  TypeSpecWidth = W;
581  return false;
582 }
583 
585  const char *&PrevSpec,
586  unsigned &DiagID) {
587  if (TypeSpecComplex != TSC_unspecified)
588  return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
589  TypeSpecComplex = C;
590  TSCLoc = Loc;
591  return false;
592 }
593 
595  const char *&PrevSpec,
596  unsigned &DiagID) {
597  if (TypeSpecSign != TSS_unspecified)
598  return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID);
599  TypeSpecSign = S;
600  TSSLoc = Loc;
601  return false;
602 }
603 
605  const char *&PrevSpec,
606  unsigned &DiagID,
607  ParsedType Rep,
608  const PrintingPolicy &Policy) {
609  return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Policy);
610 }
611 
613  SourceLocation TagNameLoc,
614  const char *&PrevSpec,
615  unsigned &DiagID,
616  ParsedType Rep,
617  const PrintingPolicy &Policy) {
618  assert(isTypeRep(T) && "T does not store a type");
619  assert(Rep && "no type provided!");
620  if (TypeSpecType != TST_unspecified) {
621  PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
622  DiagID = diag::err_invalid_decl_spec_combination;
623  return true;
624  }
625  TypeSpecType = T;
626  TypeRep = Rep;
627  TSTLoc = TagKwLoc;
628  TSTNameLoc = TagNameLoc;
629  TypeSpecOwned = false;
630  return false;
631 }
632 
634  const char *&PrevSpec,
635  unsigned &DiagID,
636  Expr *Rep,
637  const PrintingPolicy &Policy) {
638  assert(isExprRep(T) && "T does not store an expr");
639  assert(Rep && "no expression provided!");
640  if (TypeSpecType != TST_unspecified) {
641  PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
642  DiagID = diag::err_invalid_decl_spec_combination;
643  return true;
644  }
645  TypeSpecType = T;
646  ExprRep = Rep;
647  TSTLoc = Loc;
648  TSTNameLoc = Loc;
649  TypeSpecOwned = false;
650  return false;
651 }
652 
654  const char *&PrevSpec,
655  unsigned &DiagID,
656  Decl *Rep, bool Owned,
657  const PrintingPolicy &Policy) {
658  return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned, Policy);
659 }
660 
662  SourceLocation TagNameLoc,
663  const char *&PrevSpec,
664  unsigned &DiagID,
665  Decl *Rep, bool Owned,
666  const PrintingPolicy &Policy) {
667  assert(isDeclRep(T) && "T does not store a decl");
668  // Unlike the other cases, we don't assert that we actually get a decl.
669 
670  if (TypeSpecType != TST_unspecified) {
671  PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
672  DiagID = diag::err_invalid_decl_spec_combination;
673  return true;
674  }
675  TypeSpecType = T;
676  DeclRep = Rep;
677  TSTLoc = TagKwLoc;
678  TSTNameLoc = TagNameLoc;
679  TypeSpecOwned = Owned && Rep != nullptr;
680  return false;
681 }
682 
684  const char *&PrevSpec,
685  unsigned &DiagID,
686  const PrintingPolicy &Policy) {
687  assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) &&
688  "rep required for these type-spec kinds!");
689  if (TypeSpecType != TST_unspecified) {
690  PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
691  DiagID = diag::err_invalid_decl_spec_combination;
692  return true;
693  }
694  TSTLoc = Loc;
695  TSTNameLoc = Loc;
696  if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) {
697  TypeAltiVecBool = true;
698  return false;
699  }
700  TypeSpecType = T;
701  TypeSpecOwned = false;
702  return false;
703 }
704 
705 bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
706  const char *&PrevSpec, unsigned &DiagID,
707  const PrintingPolicy &Policy) {
708  if (TypeSpecType != TST_unspecified) {
709  PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
710  DiagID = diag::err_invalid_vector_decl_spec_combination;
711  return true;
712  }
713  TypeAltiVecVector = isAltiVecVector;
714  AltiVecLoc = Loc;
715  return false;
716 }
717 
718 bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
719  const char *&PrevSpec, unsigned &DiagID,
720  const PrintingPolicy &Policy) {
721  if (!TypeAltiVecVector || TypeAltiVecPixel ||
722  (TypeSpecType != TST_unspecified)) {
723  PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
724  DiagID = diag::err_invalid_pixel_decl_spec_combination;
725  return true;
726  }
727  TypeAltiVecPixel = isAltiVecPixel;
728  TSTLoc = Loc;
729  TSTNameLoc = Loc;
730  return false;
731 }
732 
733 bool DeclSpec::SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
734  const char *&PrevSpec, unsigned &DiagID,
735  const PrintingPolicy &Policy) {
736  if (!TypeAltiVecVector || TypeAltiVecBool ||
737  (TypeSpecType != TST_unspecified)) {
738  PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
739  DiagID = diag::err_invalid_vector_bool_decl_spec;
740  return true;
741  }
742  TypeAltiVecBool = isAltiVecBool;
743  TSTLoc = Loc;
744  TSTNameLoc = Loc;
745  return false;
746 }
747 
749  TypeSpecType = TST_error;
750  TypeSpecOwned = false;
751  TSTLoc = SourceLocation();
752  TSTNameLoc = SourceLocation();
753  return false;
754 }
755 
756 bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
757  unsigned &DiagID, const LangOptions &Lang) {
758  // Duplicates are permitted in C99 onwards, but are not permitted in C89 or
759  // C++. However, since this is likely not what the user intended, we will
760  // always warn. We do not need to set the qualifier's location since we
761  // already have it.
762  if (TypeQualifiers & T) {
763  bool IsExtension = true;
764  if (Lang.C99)
765  IsExtension = false;
766  return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension);
767  }
768  TypeQualifiers |= T;
769 
770  switch (T) {
771  case TQ_unspecified: break;
772  case TQ_const: TQ_constLoc = Loc; return false;
773  case TQ_restrict: TQ_restrictLoc = Loc; return false;
774  case TQ_volatile: TQ_volatileLoc = Loc; return false;
775  case TQ_atomic: TQ_atomicLoc = Loc; return false;
776  }
777 
778  llvm_unreachable("Unknown type qualifier!");
779 }
780 
781 bool DeclSpec::setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
782  unsigned &DiagID) {
783  // 'inline inline' is ok. However, since this is likely not what the user
784  // intended, we will always warn, similar to duplicates of type qualifiers.
785  if (FS_inline_specified) {
786  DiagID = diag::warn_duplicate_declspec;
787  PrevSpec = "inline";
788  return true;
789  }
790  FS_inline_specified = true;
791  FS_inlineLoc = Loc;
792  return false;
793 }
794 
795 bool DeclSpec::setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec,
796  unsigned &DiagID) {
797  if (FS_forceinline_specified) {
798  DiagID = diag::warn_duplicate_declspec;
799  PrevSpec = "__forceinline";
800  return true;
801  }
802  FS_forceinline_specified = true;
803  FS_forceinlineLoc = Loc;
804  return false;
805 }
806 
808  const char *&PrevSpec,
809  unsigned &DiagID) {
810  // 'virtual virtual' is ok, but warn as this is likely not what the user
811  // intended.
812  if (FS_virtual_specified) {
813  DiagID = diag::warn_duplicate_declspec;
814  PrevSpec = "virtual";
815  return true;
816  }
817  FS_virtual_specified = true;
818  FS_virtualLoc = Loc;
819  return false;
820 }
821 
823  const char *&PrevSpec,
824  unsigned &DiagID) {
825  // 'explicit explicit' is ok, but warn as this is likely not what the user
826  // intended.
827  if (FS_explicit_specified) {
828  DiagID = diag::warn_duplicate_declspec;
829  PrevSpec = "explicit";
830  return true;
831  }
832  FS_explicit_specified = true;
833  FS_explicitLoc = Loc;
834  return false;
835 }
836 
838  const char *&PrevSpec,
839  unsigned &DiagID) {
840  // '_Noreturn _Noreturn' is ok, but warn as this is likely not what the user
841  // intended.
842  if (FS_noreturn_specified) {
843  DiagID = diag::warn_duplicate_declspec;
844  PrevSpec = "_Noreturn";
845  return true;
846  }
847  FS_noreturn_specified = true;
848  FS_noreturnLoc = Loc;
849  return false;
850 }
851 
852 bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
853  unsigned &DiagID) {
854  if (Friend_specified) {
855  PrevSpec = "friend";
856  // Keep the later location, so that we can later diagnose ill-formed
857  // declarations like 'friend class X friend;'. Per [class.friend]p3,
858  // 'friend' must be the first token in a friend declaration that is
859  // not a function declaration.
860  FriendLoc = Loc;
861  DiagID = diag::warn_duplicate_declspec;
862  return true;
863  }
864 
865  Friend_specified = true;
866  FriendLoc = Loc;
867  return false;
868 }
869 
870 bool DeclSpec::setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
871  unsigned &DiagID) {
872  if (isModulePrivateSpecified()) {
873  PrevSpec = "__module_private__";
874  DiagID = diag::ext_duplicate_declspec;
875  return true;
876  }
877 
878  ModulePrivateLoc = Loc;
879  return false;
880 }
881 
882 bool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
883  unsigned &DiagID) {
884  // 'constexpr constexpr' is ok, but warn as this is likely not what the user
885  // intended.
886  if (Constexpr_specified) {
887  DiagID = diag::warn_duplicate_declspec;
888  PrevSpec = "constexpr";
889  return true;
890  }
891  Constexpr_specified = true;
892  ConstexprLoc = Loc;
893  return false;
894 }
895 
896 bool DeclSpec::SetConceptSpec(SourceLocation Loc, const char *&PrevSpec,
897  unsigned &DiagID) {
898  if (Concept_specified) {
899  DiagID = diag::ext_duplicate_declspec;
900  PrevSpec = "concept";
901  return true;
902  }
903  Concept_specified = true;
904  ConceptLoc = Loc;
905  return false;
906 }
907 
908 void DeclSpec::SaveWrittenBuiltinSpecs() {
909  writtenBS.Sign = getTypeSpecSign();
910  writtenBS.Width = getTypeSpecWidth();
911  writtenBS.Type = getTypeSpecType();
912  // Search the list of attributes for the presence of a mode attribute.
913  writtenBS.ModeAttr = false;
914  AttributeList* attrs = getAttributes().getList();
915  while (attrs) {
916  if (attrs->getKind() == AttributeList::AT_Mode) {
917  writtenBS.ModeAttr = true;
918  break;
919  }
920  attrs = attrs->getNext();
921  }
922 }
923 
924 /// Finish - This does final analysis of the declspec, rejecting things like
925 /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
926 /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method,
927 /// DeclSpec is guaranteed self-consistent, even if an error occurred.
929  // Before possibly changing their values, save specs as written.
930  SaveWrittenBuiltinSpecs();
931 
932  // Check the type specifier components first.
933 
934  // If decltype(auto) is used, no other type specifiers are permitted.
935  if (TypeSpecType == TST_decltype_auto &&
936  (TypeSpecWidth != TSW_unspecified ||
937  TypeSpecComplex != TSC_unspecified ||
938  TypeSpecSign != TSS_unspecified ||
939  TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
940  TypeQualifiers)) {
941  const unsigned NumLocs = 8;
942  SourceLocation ExtraLocs[NumLocs] = {
943  TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
944  TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc
945  };
946  FixItHint Hints[NumLocs];
947  SourceLocation FirstLoc;
948  for (unsigned I = 0; I != NumLocs; ++I) {
949  if (!ExtraLocs[I].isInvalid()) {
950  if (FirstLoc.isInvalid() ||
952  FirstLoc))
953  FirstLoc = ExtraLocs[I];
954  Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]);
955  }
956  }
957  TypeSpecWidth = TSW_unspecified;
958  TypeSpecComplex = TSC_unspecified;
959  TypeSpecSign = TSS_unspecified;
960  TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false;
961  TypeQualifiers = 0;
962  Diag(D, TSTLoc, diag::err_decltype_auto_cannot_be_combined)
963  << Hints[0] << Hints[1] << Hints[2] << Hints[3]
964  << Hints[4] << Hints[5] << Hints[6] << Hints[7];
965  }
966 
967  // Validate and finalize AltiVec vector declspec.
968  if (TypeAltiVecVector) {
969  if (TypeAltiVecBool) {
970  // Sign specifiers are not allowed with vector bool. (PIM 2.1)
971  if (TypeSpecSign != TSS_unspecified) {
972  Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec)
973  << getSpecifierName((TSS)TypeSpecSign);
974  }
975 
976  // Only char/int are valid with vector bool. (PIM 2.1)
977  if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) &&
978  (TypeSpecType != TST_int)) || TypeAltiVecPixel) {
979  Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec)
980  << (TypeAltiVecPixel ? "__pixel" :
981  getSpecifierName((TST)TypeSpecType, Policy));
982  }
983 
984  // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
985  if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short) &&
986  (TypeSpecWidth != TSW_longlong))
987  Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec)
988  << getSpecifierName((TSW)TypeSpecWidth);
989 
990  // vector bool long long requires VSX support or ZVector.
991  if ((TypeSpecWidth == TSW_longlong) &&
992  (!PP.getTargetInfo().hasFeature("vsx")) &&
993  (!PP.getTargetInfo().hasFeature("power8-vector")) &&
994  !PP.getLangOpts().ZVector)
995  Diag(D, TSTLoc, diag::err_invalid_vector_long_long_decl_spec);
996 
997  // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
998  if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) ||
999  (TypeSpecWidth != TSW_unspecified))
1000  TypeSpecSign = TSS_unsigned;
1001  } else if (TypeSpecType == TST_double) {
1002  // vector long double and vector long long double are never allowed.
1003  // vector double is OK for Power7 and later, and ZVector.
1004  if (TypeSpecWidth == TSW_long || TypeSpecWidth == TSW_longlong)
1005  Diag(D, TSWLoc, diag::err_invalid_vector_long_double_decl_spec);
1006  else if (!PP.getTargetInfo().hasFeature("vsx") &&
1007  !PP.getLangOpts().ZVector)
1008  Diag(D, TSTLoc, diag::err_invalid_vector_double_decl_spec);
1009  } else if (TypeSpecType == TST_float) {
1010  // vector float is unsupported for ZVector.
1011  if (PP.getLangOpts().ZVector)
1012  Diag(D, TSTLoc, diag::err_invalid_vector_float_decl_spec);
1013  } else if (TypeSpecWidth == TSW_long) {
1014  // vector long is unsupported for ZVector and deprecated for AltiVec.
1015  if (PP.getLangOpts().ZVector)
1016  Diag(D, TSWLoc, diag::err_invalid_vector_long_decl_spec);
1017  else
1018  Diag(D, TSWLoc, diag::warn_vector_long_decl_spec_combination)
1019  << getSpecifierName((TST)TypeSpecType, Policy);
1020  }
1021 
1022  if (TypeAltiVecPixel) {
1023  //TODO: perform validation
1024  TypeSpecType = TST_int;
1025  TypeSpecSign = TSS_unsigned;
1026  TypeSpecWidth = TSW_short;
1027  TypeSpecOwned = false;
1028  }
1029  }
1030 
1031  // signed/unsigned are only valid with int/char/wchar_t.
1032  if (TypeSpecSign != TSS_unspecified) {
1033  if (TypeSpecType == TST_unspecified)
1034  TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
1035  else if (TypeSpecType != TST_int && TypeSpecType != TST_int128 &&
1036  TypeSpecType != TST_char && TypeSpecType != TST_wchar) {
1037  Diag(D, TSSLoc, diag::err_invalid_sign_spec)
1038  << getSpecifierName((TST)TypeSpecType, Policy);
1039  // signed double -> double.
1040  TypeSpecSign = TSS_unspecified;
1041  }
1042  }
1043 
1044  // Validate the width of the type.
1045  switch (TypeSpecWidth) {
1046  case TSW_unspecified: break;
1047  case TSW_short: // short int
1048  case TSW_longlong: // long long int
1049  if (TypeSpecType == TST_unspecified)
1050  TypeSpecType = TST_int; // short -> short int, long long -> long long int.
1051  else if (TypeSpecType != TST_int) {
1052  Diag(D, TSWLoc,
1053  TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec
1054  : diag::err_invalid_longlong_spec)
1055  << getSpecifierName((TST)TypeSpecType, Policy);
1056  TypeSpecType = TST_int;
1057  TypeSpecOwned = false;
1058  }
1059  break;
1060  case TSW_long: // long double, long int
1061  if (TypeSpecType == TST_unspecified)
1062  TypeSpecType = TST_int; // long -> long int.
1063  else if (TypeSpecType != TST_int && TypeSpecType != TST_double) {
1064  Diag(D, TSWLoc, diag::err_invalid_long_spec)
1065  << getSpecifierName((TST)TypeSpecType, Policy);
1066  TypeSpecType = TST_int;
1067  TypeSpecOwned = false;
1068  }
1069  break;
1070  }
1071 
1072  // TODO: if the implementation does not implement _Complex or _Imaginary,
1073  // disallow their use. Need information about the backend.
1074  if (TypeSpecComplex != TSC_unspecified) {
1075  if (TypeSpecType == TST_unspecified) {
1076  Diag(D, TSCLoc, diag::ext_plain_complex)
1079  " double");
1080  TypeSpecType = TST_double; // _Complex -> _Complex double.
1081  } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
1082  // Note that this intentionally doesn't include _Complex _Bool.
1083  if (!PP.getLangOpts().CPlusPlus)
1084  Diag(D, TSTLoc, diag::ext_integer_complex);
1085  } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
1086  Diag(D, TSCLoc, diag::err_invalid_complex_spec)
1087  << getSpecifierName((TST)TypeSpecType, Policy);
1088  TypeSpecComplex = TSC_unspecified;
1089  }
1090  }
1091 
1092  // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and
1093  // _Thread_local can only appear with the 'static' and 'extern' storage class
1094  // specifiers. We also allow __private_extern__ as an extension.
1095  if (ThreadStorageClassSpec != TSCS_unspecified) {
1096  switch (StorageClassSpec) {
1097  case SCS_unspecified:
1098  case SCS_extern:
1099  case SCS_private_extern:
1100  case SCS_static:
1101  break;
1102  default:
1106  diag::err_invalid_decl_spec_combination)
1109  else
1111  diag::err_invalid_decl_spec_combination)
1114  // Discard the thread storage class specifier to recover.
1115  ThreadStorageClassSpec = TSCS_unspecified;
1116  ThreadStorageClassSpecLoc = SourceLocation();
1117  }
1118  }
1119 
1120  // If no type specifier was provided and we're parsing a language where
1121  // the type specifier is not optional, but we got 'auto' as a storage
1122  // class specifier, then assume this is an attempt to use C++0x's 'auto'
1123  // type specifier.
1124  if (PP.getLangOpts().CPlusPlus &&
1125  TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) {
1126  TypeSpecType = TST_auto;
1127  StorageClassSpec = SCS_unspecified;
1128  TSTLoc = TSTNameLoc = StorageClassSpecLoc;
1129  StorageClassSpecLoc = SourceLocation();
1130  }
1131  // Diagnose if we've recovered from an ill-formed 'auto' storage class
1132  // specifier in a pre-C++11 dialect of C++.
1133  if (!PP.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto)
1134  Diag(D, TSTLoc, diag::ext_auto_type_specifier);
1135  if (PP.getLangOpts().CPlusPlus && !PP.getLangOpts().CPlusPlus11 &&
1136  StorageClassSpec == SCS_auto)
1137  Diag(D, StorageClassSpecLoc, diag::warn_auto_storage_class)
1138  << FixItHint::CreateRemoval(StorageClassSpecLoc);
1139  if (TypeSpecType == TST_char16 || TypeSpecType == TST_char32)
1140  Diag(D, TSTLoc, diag::warn_cxx98_compat_unicode_type)
1141  << (TypeSpecType == TST_char16 ? "char16_t" : "char32_t");
1142  if (Constexpr_specified)
1143  Diag(D, ConstexprLoc, diag::warn_cxx98_compat_constexpr);
1144 
1145  // C++ [class.friend]p6:
1146  // No storage-class-specifier shall appear in the decl-specifier-seq
1147  // of a friend declaration.
1148  if (isFriendSpecified() &&
1150  SmallString<32> SpecName;
1151  SourceLocation SCLoc;
1152  FixItHint StorageHint, ThreadHint;
1153 
1154  if (DeclSpec::SCS SC = getStorageClassSpec()) {
1155  SpecName = getSpecifierName(SC);
1156  SCLoc = getStorageClassSpecLoc();
1157  StorageHint = FixItHint::CreateRemoval(SCLoc);
1158  }
1159 
1161  if (!SpecName.empty()) SpecName += " ";
1162  SpecName += getSpecifierName(TSC);
1163  SCLoc = getThreadStorageClassSpecLoc();
1164  ThreadHint = FixItHint::CreateRemoval(SCLoc);
1165  }
1166 
1167  Diag(D, SCLoc, diag::err_friend_decl_spec)
1168  << SpecName << StorageHint << ThreadHint;
1169 
1171  }
1172 
1173  // C++11 [dcl.fct.spec]p5:
1174  // The virtual specifier shall be used only in the initial
1175  // declaration of a non-static class member function;
1176  // C++11 [dcl.fct.spec]p6:
1177  // The explicit specifier shall be used only in the declaration of
1178  // a constructor or conversion function within its class
1179  // definition;
1181  StringRef Keyword;
1182  SourceLocation SCLoc;
1183 
1184  if (isVirtualSpecified()) {
1185  Keyword = "virtual";
1186  SCLoc = getVirtualSpecLoc();
1187  } else {
1188  Keyword = "explicit";
1189  SCLoc = getExplicitSpecLoc();
1190  }
1191 
1192  FixItHint Hint = FixItHint::CreateRemoval(SCLoc);
1193  Diag(D, SCLoc, diag::err_friend_decl_spec)
1194  << Keyword << Hint;
1195 
1196  FS_virtual_specified = FS_explicit_specified = false;
1197  FS_virtualLoc = FS_explicitLoc = SourceLocation();
1198  }
1199 
1200  assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
1201 
1202  // Okay, now we can infer the real type.
1203 
1204  // TODO: return "auto function" and other bad things based on the real type.
1205 
1206  // 'data definition has no type or storage class'?
1207 }
1208 
1210  TST tst = getTypeSpecType();
1211  return isDeclRep(tst) && getRepAsDecl() != nullptr &&
1212  StorageClassSpec != DeclSpec::SCS_typedef;
1213 }
1214 
1217  SourceLocation SymbolLocations[3]) {
1219  StartLocation = OperatorLoc;
1220  EndLocation = OperatorLoc;
1222  for (unsigned I = 0; I != 3; ++I) {
1223  OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding();
1224 
1225  if (SymbolLocations[I].isValid())
1226  EndLocation = SymbolLocations[I];
1227  }
1228 }
1229 
1231  const char *&PrevSpec) {
1232  if (!FirstLocation.isValid())
1233  FirstLocation = Loc;
1234  LastLocation = Loc;
1235  LastSpecifier = VS;
1236 
1237  if (Specifiers & VS) {
1238  PrevSpec = getSpecifierName(VS);
1239  return true;
1240  }
1241 
1242  Specifiers |= VS;
1243 
1244  switch (VS) {
1245  default: llvm_unreachable("Unknown specifier!");
1246  case VS_Override: VS_overrideLoc = Loc; break;
1247  case VS_Sealed:
1248  case VS_Final: VS_finalLoc = Loc; break;
1249  }
1250 
1251  return false;
1252 }
1253 
1255  switch (VS) {
1256  default: llvm_unreachable("Unknown specifier");
1257  case VS_Override: return "override";
1258  case VS_Final: return "final";
1259  case VS_Sealed: return "sealed";
1260  }
1261 }
SourceLocation getThreadStorageClassSpecLoc() const
Definition: DeclSpec.h:452
SourceManager & getSourceManager() const
Definition: Preprocessor.h:682
Defines the clang::ASTContext interface.
unsigned MutableLoc
The location of the 'mutable' qualifer in a lambda-declarator, if any.
Definition: DeclSpec.h:1256
NestedNameSpecifier * getRepresentation() const
Retrieve the representation of the nested-name-specifier.
unsigned RefQualifierIsLValueRef
Whether the ref-qualifier (if any) is an lvalue reference. Otherwise, it's an rvalue reference...
Definition: DeclSpec.h:1201
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:117
bool isInvalid() const
Definition: Ownership.h:159
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
SourceLocation getExplicitSpecLoc() const
Definition: DeclSpec.h:560
TSW getTypeSpecWidth() const
Definition: DeclSpec.h:471
static const TSS TSS_unsigned
Definition: DeclSpec.h:273
unsigned RestrictQualifierLoc
The location of the restrict-qualifier, if any.
Definition: DeclSpec.h:1252
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
Definition: DeclSpec.h:943
TheContext getContext() const
Definition: DeclSpec.h:1697
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
static const TST TST_wchar
Definition: DeclSpec.h:280
Decl * getRepAsDecl() const
Definition: DeclSpec.h:485
const LangOptions & getLangOpts() const
Definition: Sema.h:1019
UnionParsedType TypeRep
Definition: DeclSpec.h:365
unsigned MSWChar
When true, print the built-in wchar_t type as __wchar_t. For use in Microsoft mode when wchar_t is no...
static const TST TST_typeofExpr
Definition: DeclSpec.h:299
static const TST TST_char16
Definition: DeclSpec.h:281
bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:882
unsigned EllipsisLoc
When isVariadic is true, the location of the ellipsis in the source.
Definition: DeclSpec.h:1221
SCS getStorageClassSpec() const
Definition: DeclSpec.h:442
PtrTy get() const
Definition: Ownership.h:163
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1118
One instance of this struct is used for each type in a declarator that is parsed. ...
Definition: DeclSpec.h:1086
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:400
SourceLocation EndLoc
EndLoc - If valid, the place where this chunck ends.
Definition: DeclSpec.h:1094
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
Definition: DeclSpec.cpp:446
static const char * getSpecifierName(Specifier VS)
Definition: DeclSpec.cpp:1254
bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:733
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
unsigned RefQualifierLoc
The location of the ref-qualifier, if any.
Definition: DeclSpec.h:1237
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:135
static const TSCS TSCS_unspecified
Definition: DeclSpec.h:251
static const TST TST_underlyingType
Definition: DeclSpec.h:302
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1572
bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:822
TypeSpecifierType
Specifies the kind of type.
Definition: Specifiers.h:39
static const TST TST_interface
Definition: DeclSpec.h:295
static const TST TST_char
Definition: DeclSpec.h:279
void setBegin(SourceLocation b)
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:35
void Finish(DiagnosticsEngine &D, Preprocessor &PP, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:928
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
OpenCLOptions & getOpenCLOptions()
Definition: Sema.h:1020
Information about a template-id annotation token.
static const TST TST_unknown_anytype
Definition: DeclSpec.h:304
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:40
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
TemplateIdAnnotation * TemplateId
When Kind == IK_TemplateId or IK_ConstructorTemplateId, the template-id annotation that contains the ...
Definition: DeclSpec.h:937
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
Definition: DeclSpec.h:1274
void setConstructorTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id that names a constructor.
Definition: DeclSpec.cpp:49
static const TST TST_decimal32
Definition: DeclSpec.h:289
unsigned ExceptionSpecLoc
The location of the keyword introducing the spec, if any.
Definition: DeclSpec.h:1259
AttributeList * getList() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
A C++ nested-name-specifier augmented with source location information.
TypeSpecifierSign
Specifies the signedness of a type, e.g., signed or unsigned.
Definition: Specifiers.h:32
unsigned VolatileQualifierLoc
The location of the volatile-qualifier, if any.
Definition: DeclSpec.h:1247
TSS getTypeSpecSign() const
Definition: DeclSpec.h:473
static const TST TST_class
Definition: DeclSpec.h:296
OverloadedOperatorKind Operator
The kind of overloaded operator.
Definition: DeclSpec.h:899
static const TST TST_double
Definition: DeclSpec.h:287
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
Definition: DeclSpec.h:920
bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:807
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:679
static const TST TST_error
Definition: DeclSpec.h:306
static const TST TST_enum
Definition: DeclSpec.h:292
static const TSW TSW_unspecified
Definition: DeclSpec.h:258
void ClearStorageClassSpecs()
Definition: DeclSpec.h:456
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:718
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:170
bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:795
SCS
storage-class-specifier
Definition: DeclSpec.h:237
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:852
unsigned RParenLoc
The location of the right parenthesis in the source.
Definition: DeclSpec.h:1224
bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:837
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
const TargetInfo & getTargetInfo() const
Definition: Preprocessor.h:680
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
Definition: DeclSpec.cpp:41
bool isInvalid() const
static const TST TST_float
Definition: DeclSpec.h:286
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covered by this nested-name-specifier.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:258
static const TSW TSW_long
Definition: DeclSpec.h:260
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:866
TST getTypeSpecType() const
Definition: DeclSpec.h:474
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Definition: DeclSpec.cpp:129
Kind getKind() const
Holds a QualType and a TypeSourceInfo* that came out of a declarator parsing.
Definition: LocInfoType.h:29
bool isTypeRep() const
Definition: DeclSpec.h:479
ASTContext * Context
static bool isDeclRep(TST T)
Definition: DeclSpec.h:409
Defines the clang::LangOptions interface.
bool isDeclarationOfFunction() const
Determine whether the declaration that will be produced from this declaration will be a function...
Definition: DeclSpec.cpp:270
SourceLocation getTypeSpecComplexLoc() const
Definition: DeclSpec.h:501
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
unsigned SymbolLocations[3]
The source locations of the individual tokens that name the operator, e.g., the "new", "[", and "]" tokens in operator new [].
Definition: DeclSpec.h:908
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the clang::Preprocessor interface.
static const TST TST_decimal64
Definition: DeclSpec.h:290
Defines the clang::TypeLoc interface and its subclasses.
CachedTokens * ExceptionSpecTokens
Pointer to the cached tokens for an exception-specification that has not yet been parsed...
Definition: DeclSpec.h:1278
bool hasTypeSpecifier() const
Return true if any type-specifier has been found.
Definition: DeclSpec.h:579
SourceLocation Loc
Loc - The place where this type was defined.
Definition: DeclSpec.h:1092
static const TST TST_int
Definition: DeclSpec.h:283
bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:594
static const TST TST_half
Definition: DeclSpec.h:285
Wraps an identifier and optional source location for the identifier.
Definition: AttributeList.h:50
SourceLocation getStorageClassSpecLoc() const
Definition: DeclSpec.h:451
static bool BadSpecifier(T TNew, T TPrev, const char *&PrevSpec, unsigned &DiagID, bool IsExtension=true)
Definition: DeclSpec.cpp:380
static const TSW TSW_short
Definition: DeclSpec.h:259
bool isVirtualSpecified() const
Definition: DeclSpec.h:556
UnionParsedType TrailingReturnType
If HasTrailingReturnType is true, this is the trailing return type specified.
Definition: DeclSpec.h:1283
bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:569
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
Definition: DeclSpec.h:960
TypeAndRange * Exceptions
Pointer to a new[]'d array of TypeAndRange objects that contain the types in the function's dynamic e...
Definition: DeclSpec.h:1270
static const TST TST_char32
Definition: DeclSpec.h:282
unsigned Bool
Whether we can use 'bool' rather than '_Bool', even if the language doesn't actually have 'bool' (bec...
SourceLocation getLastQualifierNameLoc() const
Retrieve the location of the name in the last qualifier in this nested name specifier.
Definition: DeclSpec.cpp:146
bool SetConceptSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:896
Kind
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
An overloaded operator name, e.g., operator+.
Definition: DeclSpec.h:880
Expr * getRepAsExpr() const
Definition: DeclSpec.h:489
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
Definition: DeclSpec.h:1695
bool isValid() const
Return true if this is a valid SourceLocation object.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Definition: DeclSpec.cpp:153
NestedNameSpecifierLoc getTemporary() const
Retrieve a nested-name-specifier with location information based on the information in this builder...
FunctionTypeInfo Fun
Definition: DeclSpec.h:1410
static const TST TST_union
Definition: DeclSpec.h:293
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:494
ParsedType getRepAsType() const
Definition: DeclSpec.h:481
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
static const TSS TSS_signed
Definition: DeclSpec.h:272
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, unsigned TypeQuals, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation ConstQualifierLoc, SourceLocation VolatileQualifierLoc, SourceLocation RestrictQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceLocation ESpecLoc, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult())
Definition: DeclSpec.cpp:162
SourceLocation getVirtualSpecLoc() const
Definition: DeclSpec.h:557
static const TST TST_typeofType
Definition: DeclSpec.h:298
SourceLocation getBegin() const
PtrTy get() const
Definition: Ownership.h:74
bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const LangOptions &Lang)
Definition: DeclSpec.cpp:756
bool isStaticMember()
Definition: DeclSpec.cpp:345
bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:705
Decl * DeclRep
Definition: DeclSpec.h:366
A constructor named via a template-id.
Definition: DeclSpec.h:888
static const TST TST_decltype_auto
Definition: DeclSpec.h:301
bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:870
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK)
Definition: DeclCXX.h:1748
TSCS getThreadStorageClassSpec() const
Definition: DeclSpec.h:443
static const TSS TSS_unspecified
Definition: DeclSpec.h:271
static const TST TST_decltype
Definition: DeclSpec.h:300
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
static const TST TST_auto
Definition: DeclSpec.h:303
bool isFriendSpecified() const
Definition: DeclSpec.h:686
static const TST TST_void
Definition: DeclSpec.h:278
static const TST TST_int128
Definition: DeclSpec.h:284
unsigned DeleteParams
DeleteParams - If this is true, we need to delete[] Params.
Definition: DeclSpec.h:1211
bool isMissingDeclaratorOk()
Checks if this DeclSpec can stand alone, without a Declarator.
Definition: DeclSpec.cpp:1209
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:104
bool hasTagDefinition() const
Definition: DeclSpec.cpp:353
unsigned ConstQualifierLoc
The location of the const-qualifier, if any.
Definition: DeclSpec.h:1242
static const TST TST_unspecified
Definition: DeclSpec.h:277
enum clang::DeclaratorChunk::@184 Kind
static DiagnosticBuilder Diag(DiagnosticsEngine &D, SourceLocation Loc, unsigned DiagID)
Definition: DeclSpec.cpp:35
bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec)
Definition: DeclSpec.cpp:1230
static const TST TST_decimal128
Definition: DeclSpec.h:291
static const TSCS TSCS___thread
Definition: DeclSpec.h:252
unsigned LParenLoc
The location of the left parenthesis in the source.
Definition: DeclSpec.h:1218
bool isFunctionType() const
Definition: Type.h:5229
bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:555
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
Definition: DeclSpec.cpp:1215
static const TST TST_typename
Definition: DeclSpec.h:297
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
static bool isInvalid(SourceLocation Loc, bool *Invalid)
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:78
A template-id, e.g., f<int>.
Definition: DeclSpec.h:892
bool isUsable() const
Definition: Ownership.h:160
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:683
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
Definition: DeclSpec.cpp:57
unsigned ExceptionSpecType
ExceptionSpecType - An ExceptionSpecificationType value.
Definition: DeclSpec.h:1208
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition: Specifiers.h:160
bool isExplicitSpecified() const
Definition: DeclSpec.h:559
void setEnd(SourceLocation e)
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
static const TSCS TSCS_thread_local
Definition: DeclSpec.h:253
TypeSpecifierWidth
Specifies the width of a type, e.g., short, long, or long long.
Definition: Specifiers.h:24
static const TST TST_bool
Definition: DeclSpec.h:288
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:107
Defines the clang::TargetInfo interface.
Expr * ExprRep
Definition: DeclSpec.h:367
static const TSW TSW_longlong
Definition: DeclSpec.h:261
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
Definition: DeclSpec.cpp:362
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
static const TST TST_atomic
Definition: DeclSpec.h:305
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
static const TST TST_struct
Definition: DeclSpec.h:294
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:52
AttributeList * getNext() const
A trivial tuple used to represent a source range.
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:584
bool SetTypeSpecError()
Definition: DeclSpec.cpp:748
bool isModulePrivateSpecified() const
Definition: DeclSpec.h:689
Represents a C++ namespace alias.
Definition: DeclCXX.h:2662
SourceLocation EndLocation
The location of the last token that describes this unqualified-id.
Definition: DeclSpec.h:946
static const TSCS TSCS__Thread_local
Definition: DeclSpec.h:254
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
Definition: Type.h:633
enum clang::UnqualifiedId::IdKind Kind
ParsedAttributes & getAttributes()
Definition: DeclSpec.h:735
const DeclSpec & getDeclSpec() const
Definition: DeclSpec.h:1676
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:96
void Clear()
Clear out this builder, and prepare it to build another nested-name-specifier with source-location in...
bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:781
unsigned isAmbiguous
Can this declaration be a constructor-style initializer?
Definition: DeclSpec.h:1197