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