Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements semantic analysis for declaration specifiers. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Parse/DeclSpec.h" |
Daniel Dunbar | e4858a6 | 2008-08-11 03:45:03 +0000 | [diff] [blame] | 15 | #include "clang/Basic/Diagnostic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 20 | |
| 21 | static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc, |
| 22 | SourceManager &SrcMgr, unsigned DiagID) { |
| 23 | return D.Report(FullSourceLoc(Loc, SrcMgr), DiagID); |
| 24 | } |
| 25 | |
| 26 | |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 27 | /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. |
| 28 | /// "TheDeclarator" is the declarator that this will be added to. |
| 29 | DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic, |
| 30 | ParamInfo *ArgInfo, |
| 31 | unsigned NumArgs, |
| 32 | unsigned TypeQuals, |
| 33 | SourceLocation Loc, |
| 34 | Declarator &TheDeclarator) { |
| 35 | DeclaratorChunk I; |
| 36 | I.Kind = Function; |
| 37 | I.Loc = Loc; |
| 38 | I.Fun.hasPrototype = hasProto; |
| 39 | I.Fun.isVariadic = isVariadic; |
| 40 | I.Fun.DeleteArgInfo = false; |
| 41 | I.Fun.TypeQuals = TypeQuals; |
| 42 | I.Fun.NumArgs = NumArgs; |
| 43 | I.Fun.ArgInfo = 0; |
| 44 | |
| 45 | // new[] an argument array if needed. |
| 46 | if (NumArgs) { |
| 47 | // If the 'InlineParams' in Declarator is unused and big enough, put our |
| 48 | // parameter list there (in an effort to avoid new/delete traffic). If it |
| 49 | // is already used (consider a function returning a function pointer) or too |
| 50 | // small (function taking too many arguments), go to the heap. |
| 51 | if (!TheDeclarator.InlineParamsUsed && |
| 52 | NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) { |
| 53 | I.Fun.ArgInfo = TheDeclarator.InlineParams; |
| 54 | I.Fun.DeleteArgInfo = false; |
| 55 | TheDeclarator.InlineParamsUsed = true; |
| 56 | } else { |
| 57 | I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs]; |
| 58 | I.Fun.DeleteArgInfo = true; |
| 59 | } |
| 60 | memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs); |
| 61 | } |
| 62 | return I; |
| 63 | } |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 64 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 65 | /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this |
| 66 | /// |
| 67 | unsigned DeclSpec::getParsedSpecifiers() const { |
| 68 | unsigned Res = 0; |
| 69 | if (StorageClassSpec != SCS_unspecified || |
| 70 | SCS_thread_specified) |
| 71 | Res |= PQ_StorageClassSpecifier; |
Mike Stump | d420433 | 2008-06-19 19:52:46 +0000 | [diff] [blame] | 72 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 73 | if (TypeQualifiers != TQ_unspecified) |
| 74 | Res |= PQ_TypeQualifier; |
| 75 | |
| 76 | if (hasTypeSpecifier()) |
| 77 | Res |= PQ_TypeSpecifier; |
| 78 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 79 | if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 80 | Res |= PQ_FunctionSpecifier; |
| 81 | return Res; |
| 82 | } |
| 83 | |
| 84 | const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) { |
| 85 | switch (S) { |
| 86 | default: assert(0 && "Unknown typespec!"); |
| 87 | case DeclSpec::SCS_unspecified: return "unspecified"; |
| 88 | case DeclSpec::SCS_typedef: return "typedef"; |
| 89 | case DeclSpec::SCS_extern: return "extern"; |
| 90 | case DeclSpec::SCS_static: return "static"; |
| 91 | case DeclSpec::SCS_auto: return "auto"; |
| 92 | case DeclSpec::SCS_register: return "register"; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 93 | case DeclSpec::SCS_mutable: return "mutable"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 97 | bool DeclSpec::BadSpecifier(SCS S, const char *&PrevSpec) { |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 98 | PrevSpec = getSpecifierName(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 99 | return true; |
| 100 | } |
| 101 | |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 102 | bool DeclSpec::BadSpecifier(TSW W, const char *&PrevSpec) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 103 | switch (W) { |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 104 | case TSW_unspecified: PrevSpec = "unspecified"; break; |
| 105 | case TSW_short: PrevSpec = "short"; break; |
| 106 | case TSW_long: PrevSpec = "long"; break; |
| 107 | case TSW_longlong: PrevSpec = "long long"; break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 108 | } |
| 109 | return true; |
| 110 | } |
| 111 | |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 112 | bool DeclSpec::BadSpecifier(TSC C, const char *&PrevSpec) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 113 | switch (C) { |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 114 | case TSC_unspecified: PrevSpec = "unspecified"; break; |
| 115 | case TSC_imaginary: PrevSpec = "imaginary"; break; |
| 116 | case TSC_complex: PrevSpec = "complex"; break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 117 | } |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 122 | bool DeclSpec::BadSpecifier(TSS S, const char *&PrevSpec) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 123 | switch (S) { |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 124 | case TSS_unspecified: PrevSpec = "unspecified"; break; |
| 125 | case TSS_signed: PrevSpec = "signed"; break; |
| 126 | case TSS_unsigned: PrevSpec = "unsigned"; break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 127 | } |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | const char *DeclSpec::getSpecifierName(DeclSpec::TST T) { |
| 132 | switch (T) { |
| 133 | default: assert(0 && "Unknown typespec!"); |
| 134 | case DeclSpec::TST_unspecified: return "unspecified"; |
| 135 | case DeclSpec::TST_void: return "void"; |
| 136 | case DeclSpec::TST_char: return "char"; |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 137 | case DeclSpec::TST_wchar: return "wchar_t"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 138 | case DeclSpec::TST_int: return "int"; |
| 139 | case DeclSpec::TST_float: return "float"; |
| 140 | case DeclSpec::TST_double: return "double"; |
| 141 | case DeclSpec::TST_bool: return "_Bool"; |
| 142 | case DeclSpec::TST_decimal32: return "_Decimal32"; |
| 143 | case DeclSpec::TST_decimal64: return "_Decimal64"; |
| 144 | case DeclSpec::TST_decimal128: return "_Decimal128"; |
| 145 | case DeclSpec::TST_enum: return "enum"; |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 146 | case DeclSpec::TST_class: return "class"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 147 | case DeclSpec::TST_union: return "union"; |
| 148 | case DeclSpec::TST_struct: return "struct"; |
| 149 | case DeclSpec::TST_typedef: return "typedef"; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 150 | case DeclSpec::TST_typeofType: |
| 151 | case DeclSpec::TST_typeofExpr: return "typeof"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 155 | bool DeclSpec::BadSpecifier(TST T, const char *&PrevSpec) { |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 156 | PrevSpec = getSpecifierName(T); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 157 | return true; |
| 158 | } |
| 159 | |
Steve Naroff | 9532414 | 2008-02-12 04:08:59 +0000 | [diff] [blame] | 160 | bool DeclSpec::BadSpecifier(TQ T, const char *&PrevSpec) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 161 | switch (T) { |
| 162 | case DeclSpec::TQ_unspecified: PrevSpec = "unspecified"; break; |
| 163 | case DeclSpec::TQ_const: PrevSpec = "const"; break; |
| 164 | case DeclSpec::TQ_restrict: PrevSpec = "restrict"; break; |
| 165 | case DeclSpec::TQ_volatile: PrevSpec = "volatile"; break; |
| 166 | } |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc, |
| 171 | const char *&PrevSpec) { |
| 172 | if (StorageClassSpec != SCS_unspecified) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 173 | return BadSpecifier((SCS)StorageClassSpec, PrevSpec); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 174 | StorageClassSpec = S; |
| 175 | StorageClassSpecLoc = Loc; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 176 | assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 177 | return false; |
| 178 | } |
| 179 | |
| 180 | bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc, |
| 181 | const char *&PrevSpec) { |
| 182 | if (SCS_thread_specified) { |
| 183 | PrevSpec = "__thread"; |
| 184 | return true; |
| 185 | } |
| 186 | SCS_thread_specified = true; |
| 187 | SCS_threadLoc = Loc; |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | |
| 192 | /// These methods set the specified attribute of the DeclSpec, but return true |
| 193 | /// and ignore the request if invalid (e.g. "extern" then "auto" is |
| 194 | /// specified). |
| 195 | bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, |
| 196 | const char *&PrevSpec) { |
| 197 | if (TypeSpecWidth != TSW_unspecified && |
| 198 | // Allow turning long -> long long. |
| 199 | (W != TSW_longlong || TypeSpecWidth != TSW_long)) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 200 | return BadSpecifier((TSW)TypeSpecWidth, PrevSpec); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 201 | TypeSpecWidth = W; |
| 202 | TSWLoc = Loc; |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, |
| 207 | const char *&PrevSpec) { |
| 208 | if (TypeSpecComplex != TSC_unspecified) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 209 | return BadSpecifier((TSC)TypeSpecComplex, PrevSpec); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 210 | TypeSpecComplex = C; |
| 211 | TSCLoc = Loc; |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, |
| 216 | const char *&PrevSpec) { |
| 217 | if (TypeSpecSign != TSS_unspecified) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 218 | return BadSpecifier((TSS)TypeSpecSign, PrevSpec); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 219 | TypeSpecSign = S; |
| 220 | TSSLoc = Loc; |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
Argyrios Kyrtzidis | 39caa08 | 2008-08-01 10:35:27 +0000 | [diff] [blame] | 225 | const char *&PrevSpec, Action::TypeTy *Rep) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 226 | if (TypeSpecType != TST_unspecified) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 227 | return BadSpecifier((TST)TypeSpecType, PrevSpec); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 228 | TypeSpecType = T; |
| 229 | TypeRep = Rep; |
| 230 | TSTLoc = Loc; |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, |
| 235 | const LangOptions &Lang) { |
| 236 | // Duplicates turn into warnings pre-C99. |
| 237 | if ((TypeQualifiers & T) && !Lang.C99) |
| 238 | return BadSpecifier(T, PrevSpec); |
| 239 | TypeQualifiers |= T; |
| 240 | |
| 241 | switch (T) { |
| 242 | default: assert(0 && "Unknown type qualifier!"); |
| 243 | case TQ_const: TQ_constLoc = Loc; break; |
| 244 | case TQ_restrict: TQ_restrictLoc = Loc; break; |
| 245 | case TQ_volatile: TQ_volatileLoc = Loc; break; |
| 246 | } |
| 247 | return false; |
| 248 | } |
| 249 | |
| 250 | bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec){ |
| 251 | // 'inline inline' is ok. |
| 252 | FS_inline_specified = true; |
| 253 | FS_inlineLoc = Loc; |
| 254 | return false; |
| 255 | } |
| 256 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 257 | bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec){ |
| 258 | // 'virtual virtual' is ok. |
| 259 | FS_virtual_specified = true; |
| 260 | FS_virtualLoc = Loc; |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec){ |
| 265 | // 'explicit explicit' is ok. |
| 266 | FS_explicit_specified = true; |
| 267 | FS_explicitLoc = Loc; |
| 268 | return false; |
| 269 | } |
| 270 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 271 | |
| 272 | /// Finish - This does final analysis of the declspec, rejecting things like |
| 273 | /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or |
| 274 | /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method, |
| 275 | /// DeclSpec is guaranteed self-consistent, even if an error occurred. |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 276 | void DeclSpec::Finish(Diagnostic &D, SourceManager& SrcMgr, |
| 277 | const LangOptions &Lang) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 278 | // Check the type specifier components first. |
| 279 | |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 280 | // signed/unsigned are only valid with int/char/wchar_t. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 281 | if (TypeSpecSign != TSS_unspecified) { |
| 282 | if (TypeSpecType == TST_unspecified) |
| 283 | TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 284 | else if (TypeSpecType != TST_int && |
| 285 | TypeSpecType != TST_char && TypeSpecType != TST_wchar) { |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 286 | Diag(D, TSSLoc, SrcMgr, diag::err_invalid_sign_spec) |
| 287 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 288 | // signed double -> double. |
| 289 | TypeSpecSign = TSS_unspecified; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | // Validate the width of the type. |
| 294 | switch (TypeSpecWidth) { |
| 295 | case TSW_unspecified: break; |
| 296 | case TSW_short: // short int |
| 297 | case TSW_longlong: // long long int |
| 298 | if (TypeSpecType == TST_unspecified) |
| 299 | TypeSpecType = TST_int; // short -> short int, long long -> long long int. |
| 300 | else if (TypeSpecType != TST_int) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 301 | Diag(D, TSWLoc, SrcMgr, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 302 | TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 303 | : diag::err_invalid_longlong_spec) |
| 304 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 305 | TypeSpecType = TST_int; |
| 306 | } |
| 307 | break; |
| 308 | case TSW_long: // long double, long int |
| 309 | if (TypeSpecType == TST_unspecified) |
| 310 | TypeSpecType = TST_int; // long -> long int. |
| 311 | else if (TypeSpecType != TST_int && TypeSpecType != TST_double) { |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 312 | Diag(D, TSWLoc, SrcMgr, diag::err_invalid_long_spec) |
| 313 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 314 | TypeSpecType = TST_int; |
| 315 | } |
| 316 | break; |
| 317 | } |
| 318 | |
| 319 | // TODO: if the implementation does not implement _Complex or _Imaginary, |
| 320 | // disallow their use. Need information about the backend. |
| 321 | if (TypeSpecComplex != TSC_unspecified) { |
| 322 | if (TypeSpecType == TST_unspecified) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 323 | Diag(D, TSCLoc, SrcMgr, diag::ext_plain_complex); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 324 | TypeSpecType = TST_double; // _Complex -> _Complex double. |
| 325 | } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) { |
| 326 | // Note that this intentionally doesn't include _Complex _Bool. |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 327 | Diag(D, TSTLoc, SrcMgr, diag::ext_integer_complex); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 328 | } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) { |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 329 | Diag(D, TSCLoc, SrcMgr, diag::err_invalid_complex_spec) |
| 330 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 331 | TypeSpecComplex = TSC_unspecified; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | // Verify __thread. |
| 336 | if (SCS_thread_specified) { |
| 337 | if (StorageClassSpec == SCS_unspecified) { |
| 338 | StorageClassSpec = SCS_extern; // '__thread int' -> 'extern __thread int' |
| 339 | } else if (StorageClassSpec != SCS_extern && |
| 340 | StorageClassSpec != SCS_static) { |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 341 | Diag(D, getStorageClassSpecLoc(), SrcMgr, diag::err_invalid_thread_spec) |
| 342 | << getSpecifierName((SCS)StorageClassSpec); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 343 | SCS_thread_specified = false; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | // Okay, now we can infer the real type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 348 | |
| 349 | // TODO: return "auto function" and other bad things based on the real type. |
| 350 | |
| 351 | // 'data definition has no type or storage class'? |
| 352 | } |
Daniel Dunbar | e4858a6 | 2008-08-11 03:45:03 +0000 | [diff] [blame] | 353 | |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 354 | bool DeclSpec::isMissingDeclaratorOk() { |
| 355 | TST tst = getTypeSpecType(); |
| 356 | return (tst == TST_union |
| 357 | || tst == TST_struct |
| 358 | || tst == TST_class |
| 359 | || tst == TST_enum |
Douglas Gregor | 4920f1f | 2009-01-12 22:49:06 +0000 | [diff] [blame] | 360 | ) && getTypeRep() != 0 && StorageClassSpec != DeclSpec::SCS_typedef; |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 361 | } |