blob: 2a765d212486a6c28a3e1609c13a45a4990276b1 [file] [log] [blame]
Chris Lattner289ab7b2006-11-08 06:54:53 +00001//===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===//
Chris Lattnerb9093cd2006-08-04 04:39:53 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerb9093cd2006-08-04 04:39:53 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner289ab7b2006-11-08 06:54:53 +000010// This file implements semantic analysis for declaration specifiers.
Chris Lattnerb9093cd2006-08-04 04:39:53 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner288e86ff12006-11-11 23:03:42 +000014#include "clang/Parse/DeclSpec.h"
Chris Lattner60f36222009-01-29 05:15:15 +000015#include "clang/Parse/ParseDiagnostic.h"
Douglas Gregore3e01a22009-04-01 22:41:11 +000016#include "clang/Lex/Preprocessor.h"
Chris Lattnerda48a8e2006-08-04 05:25:55 +000017#include "clang/Basic/LangOptions.h"
Chris Lattner1ce41ed2009-01-20 19:11:22 +000018#include "llvm/ADT/STLExtras.h"
Douglas Gregor52537682009-03-19 00:18:19 +000019#include <cstring>
Chris Lattnerb9093cd2006-08-04 04:39:53 +000020using namespace clang;
21
Chris Lattner3b0f3ef2008-11-22 08:32:36 +000022
23static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc,
24 SourceManager &SrcMgr, unsigned DiagID) {
25 return D.Report(FullSourceLoc(Loc, SrcMgr), DiagID);
26}
27
Chris Lattner1ce41ed2009-01-20 19:11:22 +000028/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
29/// "TheDeclarator" is the declarator that this will be added to.
30DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic,
Douglas Gregor94349fd2009-02-18 07:07:28 +000031 SourceLocation EllipsisLoc,
Chris Lattner1ce41ed2009-01-20 19:11:22 +000032 ParamInfo *ArgInfo,
33 unsigned NumArgs,
34 unsigned TypeQuals,
Sebastian Redl2b9cacb2009-04-29 17:30:04 +000035 bool hasExceptionSpec,
36 bool hasAnyExceptionSpec,
37 ActionBase::TypeTy **Exceptions,
38 unsigned NumExceptions,
Chris Lattner1ce41ed2009-01-20 19:11:22 +000039 SourceLocation Loc,
40 Declarator &TheDeclarator) {
41 DeclaratorChunk I;
Sebastian Redl2b9cacb2009-04-29 17:30:04 +000042 I.Kind = Function;
43 I.Loc = Loc;
44 I.Fun.hasPrototype = hasProto;
45 I.Fun.isVariadic = isVariadic;
46 I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding();
47 I.Fun.DeleteArgInfo = false;
48 I.Fun.TypeQuals = TypeQuals;
49 I.Fun.NumArgs = NumArgs;
50 I.Fun.ArgInfo = 0;
51 I.Fun.hasExceptionSpec = hasExceptionSpec;
52 I.Fun.hasAnyExceptionSpec = hasAnyExceptionSpec;
53 I.Fun.NumExceptions = NumExceptions;
54 I.Fun.Exceptions = 0;
55
Chris Lattner1ce41ed2009-01-20 19:11:22 +000056 // new[] an argument array if needed.
57 if (NumArgs) {
58 // If the 'InlineParams' in Declarator is unused and big enough, put our
59 // parameter list there (in an effort to avoid new/delete traffic). If it
60 // is already used (consider a function returning a function pointer) or too
61 // small (function taking too many arguments), go to the heap.
62 if (!TheDeclarator.InlineParamsUsed &&
63 NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
64 I.Fun.ArgInfo = TheDeclarator.InlineParams;
65 I.Fun.DeleteArgInfo = false;
66 TheDeclarator.InlineParamsUsed = true;
67 } else {
68 I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs];
69 I.Fun.DeleteArgInfo = true;
70 }
71 memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
72 }
Sebastian Redl2b9cacb2009-04-29 17:30:04 +000073 // new[] an exception array if needed
74 if (NumExceptions) {
75 I.Fun.Exceptions = new ActionBase::TypeTy*[NumExceptions];
76 memcpy(I.Fun.Exceptions, Exceptions,
77 sizeof(ActionBase::TypeTy*)*NumExceptions);
78 }
Chris Lattner1ce41ed2009-01-20 19:11:22 +000079 return I;
80}
Chris Lattner3b0f3ef2008-11-22 08:32:36 +000081
Chris Lattnerb9093cd2006-08-04 04:39:53 +000082/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
Chris Lattnere0c51162009-02-27 18:35:46 +000083/// declaration specifier includes.
Chris Lattnerb9093cd2006-08-04 04:39:53 +000084///
85unsigned DeclSpec::getParsedSpecifiers() const {
86 unsigned Res = 0;
Chris Lattnerf63f89a2006-08-05 03:28:50 +000087 if (StorageClassSpec != SCS_unspecified ||
88 SCS_thread_specified)
Chris Lattnerb9093cd2006-08-04 04:39:53 +000089 Res |= PQ_StorageClassSpecifier;
Mike Stump65643c62008-06-19 19:52:46 +000090
Chris Lattner4d8f8732006-11-28 05:05:08 +000091 if (TypeQualifiers != TQ_unspecified)
Chris Lattnerb9093cd2006-08-04 04:39:53 +000092 Res |= PQ_TypeQualifier;
93
Chris Lattnerf055d432006-11-28 04:28:12 +000094 if (hasTypeSpecifier())
Chris Lattnerb9093cd2006-08-04 04:39:53 +000095 Res |= PQ_TypeSpecifier;
96
Douglas Gregor61956c42008-10-31 09:07:45 +000097 if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified)
Chris Lattnerb9093cd2006-08-04 04:39:53 +000098 Res |= PQ_FunctionSpecifier;
99 return Res;
100}
101
Chris Lattner7bd11fe2007-01-23 04:35:33 +0000102const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) {
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000103 switch (S) {
104 default: assert(0 && "Unknown typespec!");
105 case DeclSpec::SCS_unspecified: return "unspecified";
106 case DeclSpec::SCS_typedef: return "typedef";
107 case DeclSpec::SCS_extern: return "extern";
108 case DeclSpec::SCS_static: return "static";
109 case DeclSpec::SCS_auto: return "auto";
110 case DeclSpec::SCS_register: return "register";
Eli Friedmand5c0eed2009-04-19 20:27:55 +0000111 case DeclSpec::SCS_private_extern: return "__private_extern__";
Sebastian Redlccdfaba2008-11-14 23:42:31 +0000112 case DeclSpec::SCS_mutable: return "mutable";
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000113 }
114}
115
Steve Naroffab468cb2008-02-12 04:08:59 +0000116bool DeclSpec::BadSpecifier(SCS S, const char *&PrevSpec) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000117 PrevSpec = getSpecifierName(S);
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000118 return true;
119}
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000120
Steve Naroffab468cb2008-02-12 04:08:59 +0000121bool DeclSpec::BadSpecifier(TSW W, const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000122 switch (W) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000123 case TSW_unspecified: PrevSpec = "unspecified"; break;
124 case TSW_short: PrevSpec = "short"; break;
125 case TSW_long: PrevSpec = "long"; break;
126 case TSW_longlong: PrevSpec = "long long"; break;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000127 }
128 return true;
129}
130
Steve Naroffab468cb2008-02-12 04:08:59 +0000131bool DeclSpec::BadSpecifier(TSC C, const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000132 switch (C) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000133 case TSC_unspecified: PrevSpec = "unspecified"; break;
134 case TSC_imaginary: PrevSpec = "imaginary"; break;
135 case TSC_complex: PrevSpec = "complex"; break;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000136 }
137 return true;
138}
139
140
Steve Naroffab468cb2008-02-12 04:08:59 +0000141bool DeclSpec::BadSpecifier(TSS S, const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000142 switch (S) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000143 case TSS_unspecified: PrevSpec = "unspecified"; break;
144 case TSS_signed: PrevSpec = "signed"; break;
145 case TSS_unsigned: PrevSpec = "unsigned"; break;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000146 }
147 return true;
148}
149
Chris Lattner69680ea2007-01-23 04:34:43 +0000150const char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000151 switch (T) {
Chris Lattner839713c2006-08-04 06:15:52 +0000152 default: assert(0 && "Unknown typespec!");
153 case DeclSpec::TST_unspecified: return "unspecified";
154 case DeclSpec::TST_void: return "void";
155 case DeclSpec::TST_char: return "char";
Argyrios Kyrtzidis40e9e482008-08-09 16:51:54 +0000156 case DeclSpec::TST_wchar: return "wchar_t";
Chris Lattner839713c2006-08-04 06:15:52 +0000157 case DeclSpec::TST_int: return "int";
158 case DeclSpec::TST_float: return "float";
159 case DeclSpec::TST_double: return "double";
160 case DeclSpec::TST_bool: return "_Bool";
161 case DeclSpec::TST_decimal32: return "_Decimal32";
162 case DeclSpec::TST_decimal64: return "_Decimal64";
163 case DeclSpec::TST_decimal128: return "_Decimal128";
Chris Lattnerda72c822006-08-13 22:16:42 +0000164 case DeclSpec::TST_enum: return "enum";
Chris Lattner861a2262008-04-13 18:59:07 +0000165 case DeclSpec::TST_class: return "class";
Chris Lattnerda72c822006-08-13 22:16:42 +0000166 case DeclSpec::TST_union: return "union";
167 case DeclSpec::TST_struct: return "struct";
Douglas Gregor9817f4a2009-02-09 15:09:02 +0000168 case DeclSpec::TST_typename: return "type-name";
Steve Naroffad373bd2007-07-31 12:34:36 +0000169 case DeclSpec::TST_typeofType:
170 case DeclSpec::TST_typeofExpr: return "typeof";
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000171 }
Chris Lattner839713c2006-08-04 06:15:52 +0000172}
173
Steve Naroffab468cb2008-02-12 04:08:59 +0000174bool DeclSpec::BadSpecifier(TST T, const char *&PrevSpec) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000175 PrevSpec = getSpecifierName(T);
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000176 return true;
177}
178
Steve Naroffab468cb2008-02-12 04:08:59 +0000179bool DeclSpec::BadSpecifier(TQ T, const char *&PrevSpec) {
Chris Lattnerda48a8e2006-08-04 05:25:55 +0000180 switch (T) {
181 case DeclSpec::TQ_unspecified: PrevSpec = "unspecified"; break;
182 case DeclSpec::TQ_const: PrevSpec = "const"; break;
183 case DeclSpec::TQ_restrict: PrevSpec = "restrict"; break;
184 case DeclSpec::TQ_volatile: PrevSpec = "volatile"; break;
185 }
186 return true;
187}
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000188
Chris Lattner4d8f8732006-11-28 05:05:08 +0000189bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc,
190 const char *&PrevSpec) {
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000191 if (StorageClassSpec != SCS_unspecified)
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000192 return BadSpecifier((SCS)StorageClassSpec, PrevSpec);
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000193 StorageClassSpec = S;
Chris Lattner4d8f8732006-11-28 05:05:08 +0000194 StorageClassSpecLoc = Loc;
Sebastian Redlccdfaba2008-11-14 23:42:31 +0000195 assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield");
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000196 return false;
197}
198
Chris Lattner4d8f8732006-11-28 05:05:08 +0000199bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc,
200 const char *&PrevSpec) {
Chris Lattner353f5742006-11-28 04:50:12 +0000201 if (SCS_thread_specified) {
202 PrevSpec = "__thread";
203 return true;
204 }
205 SCS_thread_specified = true;
Chris Lattner4d8f8732006-11-28 05:05:08 +0000206 SCS_threadLoc = Loc;
Chris Lattner353f5742006-11-28 04:50:12 +0000207 return false;
208}
209
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000210
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000211/// These methods set the specified attribute of the DeclSpec, but return true
212/// and ignore the request if invalid (e.g. "extern" then "auto" is
213/// specified).
Chris Lattnerb20e8942006-11-28 05:30:29 +0000214bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc,
215 const char *&PrevSpec) {
Chris Lattner353f5742006-11-28 04:50:12 +0000216 if (TypeSpecWidth != TSW_unspecified &&
217 // Allow turning long -> long long.
218 (W != TSW_longlong || TypeSpecWidth != TSW_long))
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000219 return BadSpecifier((TSW)TypeSpecWidth, PrevSpec);
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000220 TypeSpecWidth = W;
Chris Lattnerb20e8942006-11-28 05:30:29 +0000221 TSWLoc = Loc;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000222 return false;
223}
224
Chris Lattnerb20e8942006-11-28 05:30:29 +0000225bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc,
226 const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000227 if (TypeSpecComplex != TSC_unspecified)
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000228 return BadSpecifier((TSC)TypeSpecComplex, PrevSpec);
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000229 TypeSpecComplex = C;
Chris Lattnerb20e8942006-11-28 05:30:29 +0000230 TSCLoc = Loc;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000231 return false;
232}
233
Chris Lattnerb20e8942006-11-28 05:30:29 +0000234bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc,
235 const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000236 if (TypeSpecSign != TSS_unspecified)
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000237 return BadSpecifier((TSS)TypeSpecSign, PrevSpec);
Chris Lattnerdeb42f52006-08-04 05:26:52 +0000238 TypeSpecSign = S;
Chris Lattnerb20e8942006-11-28 05:30:29 +0000239 TSSLoc = Loc;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000240 return false;
241}
242
Chris Lattnerb20e8942006-11-28 05:30:29 +0000243bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
Douglas Gregord6ab8742009-05-28 23:31:59 +0000244 const char *&PrevSpec, void *Rep,
245 bool Owned) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000246 if (TypeSpecType != TST_unspecified)
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000247 return BadSpecifier((TST)TypeSpecType, PrevSpec);
Chris Lattnerdeb42f52006-08-04 05:26:52 +0000248 TypeSpecType = T;
Chris Lattnerb9d572a2007-01-23 04:58:34 +0000249 TypeRep = Rep;
Chris Lattnerb20e8942006-11-28 05:30:29 +0000250 TSTLoc = Loc;
Douglas Gregord6ab8742009-05-28 23:31:59 +0000251 TypeSpecOwned = Owned;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000252 return false;
253}
254
Douglas Gregorcd72ba92009-02-06 22:42:48 +0000255bool DeclSpec::SetTypeSpecError() {
256 TypeSpecType = TST_error;
257 TypeRep = 0;
258 TSTLoc = SourceLocation();
259 return false;
260}
261
Chris Lattner60809f52006-11-28 05:18:46 +0000262bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
Chris Lattnerda48a8e2006-08-04 05:25:55 +0000263 const LangOptions &Lang) {
264 // Duplicates turn into warnings pre-C99.
265 if ((TypeQualifiers & T) && !Lang.C99)
266 return BadSpecifier(T, PrevSpec);
267 TypeQualifiers |= T;
Chris Lattner60809f52006-11-28 05:18:46 +0000268
269 switch (T) {
270 default: assert(0 && "Unknown type qualifier!");
271 case TQ_const: TQ_constLoc = Loc; break;
272 case TQ_restrict: TQ_restrictLoc = Loc; break;
273 case TQ_volatile: TQ_volatileLoc = Loc; break;
274 }
Chris Lattnerda48a8e2006-08-04 05:25:55 +0000275 return false;
276}
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000277
Chris Lattner1b22eed2006-11-28 05:12:07 +0000278bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec){
Chris Lattnera925dc62006-11-28 04:33:46 +0000279 // 'inline inline' is ok.
280 FS_inline_specified = true;
Chris Lattner1b22eed2006-11-28 05:12:07 +0000281 FS_inlineLoc = Loc;
Chris Lattnera925dc62006-11-28 04:33:46 +0000282 return false;
283}
284
Douglas Gregor61956c42008-10-31 09:07:45 +0000285bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec){
286 // 'virtual virtual' is ok.
287 FS_virtual_specified = true;
288 FS_virtualLoc = Loc;
289 return false;
290}
291
292bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec){
293 // 'explicit explicit' is ok.
294 FS_explicit_specified = true;
295 FS_explicitLoc = Loc;
296 return false;
297}
298
Anders Carlssoncd8db412009-05-06 04:46:28 +0000299bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec) {
300 if (Friend_specified) {
301 PrevSpec = "friend";
302 return true;
303 }
304
305 Friend_specified = true;
306 FriendLoc = Loc;
307 return false;
308}
Chris Lattnera925dc62006-11-28 04:33:46 +0000309
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000310/// Finish - This does final analysis of the declspec, rejecting things like
311/// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
312/// diag::NUM_DIAGNOSTICS if there is no error. After calling this method,
313/// DeclSpec is guaranteed self-consistent, even if an error occurred.
Douglas Gregore3e01a22009-04-01 22:41:11 +0000314void DeclSpec::Finish(Diagnostic &D, Preprocessor &PP) {
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000315 // Check the type specifier components first.
Douglas Gregore3e01a22009-04-01 22:41:11 +0000316 SourceManager &SrcMgr = PP.getSourceManager();
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000317
Argyrios Kyrtzidis40e9e482008-08-09 16:51:54 +0000318 // signed/unsigned are only valid with int/char/wchar_t.
Chris Lattner839713c2006-08-04 06:15:52 +0000319 if (TypeSpecSign != TSS_unspecified) {
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000320 if (TypeSpecType == TST_unspecified)
321 TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
Argyrios Kyrtzidis40e9e482008-08-09 16:51:54 +0000322 else if (TypeSpecType != TST_int &&
323 TypeSpecType != TST_char && TypeSpecType != TST_wchar) {
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000324 Diag(D, TSSLoc, SrcMgr, diag::err_invalid_sign_spec)
325 << getSpecifierName((TST)TypeSpecType);
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000326 // signed double -> double.
Chris Lattner839713c2006-08-04 06:15:52 +0000327 TypeSpecSign = TSS_unspecified;
328 }
329 }
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000330
Chris Lattner839713c2006-08-04 06:15:52 +0000331 // Validate the width of the type.
332 switch (TypeSpecWidth) {
333 case TSW_unspecified: break;
334 case TSW_short: // short int
335 case TSW_longlong: // long long int
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000336 if (TypeSpecType == TST_unspecified)
337 TypeSpecType = TST_int; // short -> short int, long long -> long long int.
338 else if (TypeSpecType != TST_int) {
Ted Kremenekd4e5fba2007-12-11 21:27:55 +0000339 Diag(D, TSWLoc, SrcMgr,
Chris Lattner36982e42007-05-16 17:49:37 +0000340 TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000341 : diag::err_invalid_longlong_spec)
342 << getSpecifierName((TST)TypeSpecType);
Chris Lattner839713c2006-08-04 06:15:52 +0000343 TypeSpecType = TST_int;
344 }
345 break;
346 case TSW_long: // long double, long int
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000347 if (TypeSpecType == TST_unspecified)
348 TypeSpecType = TST_int; // long -> long int.
349 else if (TypeSpecType != TST_int && TypeSpecType != TST_double) {
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000350 Diag(D, TSWLoc, SrcMgr, diag::err_invalid_long_spec)
351 << getSpecifierName((TST)TypeSpecType);
Chris Lattner839713c2006-08-04 06:15:52 +0000352 TypeSpecType = TST_int;
353 }
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000354 break;
Chris Lattner839713c2006-08-04 06:15:52 +0000355 }
356
Chris Lattner0e894622006-08-13 19:58:17 +0000357 // TODO: if the implementation does not implement _Complex or _Imaginary,
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000358 // disallow their use. Need information about the backend.
359 if (TypeSpecComplex != TSC_unspecified) {
360 if (TypeSpecType == TST_unspecified) {
Douglas Gregore3e01a22009-04-01 22:41:11 +0000361 Diag(D, TSCLoc, SrcMgr, diag::ext_plain_complex)
362 << CodeModificationHint::CreateInsertion(
363 PP.getLocForEndOfToken(getTypeSpecComplexLoc()),
364 " double");
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000365 TypeSpecType = TST_double; // _Complex -> _Complex double.
366 } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000367 // Note that this intentionally doesn't include _Complex _Bool.
Ted Kremenekd4e5fba2007-12-11 21:27:55 +0000368 Diag(D, TSTLoc, SrcMgr, diag::ext_integer_complex);
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000369 } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000370 Diag(D, TSCLoc, SrcMgr, diag::err_invalid_complex_spec)
371 << getSpecifierName((TST)TypeSpecType);
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000372 TypeSpecComplex = TSC_unspecified;
373 }
374 }
Chris Lattner8e90ef62006-08-05 03:30:45 +0000375
376 // Okay, now we can infer the real type.
Chris Lattner8e90ef62006-08-05 03:30:45 +0000377
Chris Lattner0e894622006-08-13 19:58:17 +0000378 // TODO: return "auto function" and other bad things based on the real type.
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000379
Chris Lattner1ae23292006-08-04 06:42:31 +0000380 // 'data definition has no type or storage class'?
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000381}
Daniel Dunbarc74b5cc2008-08-11 03:45:03 +0000382
Sebastian Redla2b5e312008-12-28 15:28:59 +0000383bool DeclSpec::isMissingDeclaratorOk() {
384 TST tst = getTypeSpecType();
385 return (tst == TST_union
386 || tst == TST_struct
387 || tst == TST_class
388 || tst == TST_enum
Douglas Gregorc6f58fe2009-01-12 22:49:06 +0000389 ) && getTypeRep() != 0 && StorageClassSpec != DeclSpec::SCS_typedef;
Sebastian Redla2b5e312008-12-28 15:28:59 +0000390}