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