Chris Lattner | 289ab7b | 2006-11-08 06:54:53 +0000 | [diff] [blame] | 1 | //===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===// |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 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. |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 289ab7b | 2006-11-08 06:54:53 +0000 | [diff] [blame] | 10 | // This file implements semantic analysis for declaration specifiers. |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 14 | #include "clang/Parse/ParseDiagnostic.h" // FIXME: remove this back-dependency! |
| 15 | #include "clang/Sema/DeclSpec.h" |
Douglas Gregor | c15b0cf | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 16 | #include "clang/Sema/LocInfoType.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | c15b0cf | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 19 | #include "clang/AST/Expr.h" |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 20 | #include "clang/AST/NestedNameSpecifier.h" |
| 21 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 22 | #include "clang/Lex/Preprocessor.h" |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 23 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/STLExtras.h" |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 5253768 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 26 | #include <cstring> |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 27 | using namespace clang; |
| 28 | |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 29 | |
| 30 | static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc, |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 31 | unsigned DiagID) { |
| 32 | return D.Report(Loc, DiagID); |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Douglas Gregor | b53edfb | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 35 | |
| 36 | void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) { |
| 37 | assert(TemplateId && "NULL template-id annotation?"); |
| 38 | Kind = IK_TemplateId; |
| 39 | this->TemplateId = TemplateId; |
| 40 | StartLocation = TemplateId->TemplateNameLoc; |
| 41 | EndLocation = TemplateId->RAngleLoc; |
| 42 | } |
| 43 | |
Douglas Gregor | 9de54ea | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 44 | void UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) { |
| 45 | assert(TemplateId && "NULL template-id annotation?"); |
| 46 | Kind = IK_ConstructorTemplateId; |
| 47 | this->TemplateId = TemplateId; |
| 48 | StartLocation = TemplateId->TemplateNameLoc; |
| 49 | EndLocation = TemplateId->RAngleLoc; |
| 50 | } |
| 51 | |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 52 | void CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc, |
| 53 | TypeLoc TL, SourceLocation ColonColonLoc) { |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 54 | Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 55 | if (Range.getBegin().isInvalid()) |
| 56 | Range.setBegin(TL.getBeginLoc()); |
| 57 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 58 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 59 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 60 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier, |
| 64 | SourceLocation IdentifierLoc, |
| 65 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 66 | Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc); |
| 67 | |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 68 | if (Range.getBegin().isInvalid()) |
| 69 | Range.setBegin(IdentifierLoc); |
| 70 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 72 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 73 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace, |
| 77 | SourceLocation NamespaceLoc, |
| 78 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 79 | Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc); |
| 80 | |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 81 | if (Range.getBegin().isInvalid()) |
| 82 | Range.setBegin(NamespaceLoc); |
| 83 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 84 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 85 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 86 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 89 | void CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias, |
| 90 | SourceLocation AliasLoc, |
| 91 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 92 | Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc); |
| 93 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 94 | if (Range.getBegin().isInvalid()) |
| 95 | Range.setBegin(AliasLoc); |
| 96 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 97 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 98 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 99 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 102 | void CXXScopeSpec::MakeGlobal(ASTContext &Context, |
| 103 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 104 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 105 | |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 106 | Range = SourceRange(ColonColonLoc); |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 107 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 108 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 109 | "NestedNameSpecifierLoc range computation incorrect"); |
| 110 | } |
| 111 | |
| 112 | void CXXScopeSpec::MakeTrivial(ASTContext &Context, |
| 113 | NestedNameSpecifier *Qualifier, SourceRange R) { |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 114 | Builder.MakeTrivial(Context, Qualifier, R); |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 115 | Range = R; |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) { |
| 119 | if (!Other) { |
| 120 | Range = SourceRange(); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 121 | Builder.Clear(); |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 122 | return; |
| 123 | } |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 125 | Range = Other.getSourceRange(); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 126 | Builder.Adopt(Other); |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 129 | NestedNameSpecifierLoc |
| 130 | CXXScopeSpec::getWithLocInContext(ASTContext &Context) const { |
Douglas Gregor | 2b1ca9e | 2011-03-03 21:48:55 +0000 | [diff] [blame] | 131 | if (!Builder.getRepresentation()) |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 132 | return NestedNameSpecifierLoc(); |
| 133 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 134 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 137 | /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. |
| 138 | /// "TheDeclarator" is the declarator that this will be added to. |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 139 | DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic, |
Douglas Gregor | 94349fd | 2009-02-18 07:07:28 +0000 | [diff] [blame] | 140 | SourceLocation EllipsisLoc, |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 141 | ParamInfo *ArgInfo, |
| 142 | unsigned NumArgs, |
| 143 | unsigned TypeQuals, |
Douglas Gregor | 5499235 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 144 | bool RefQualifierIsLvalueRef, |
| 145 | SourceLocation RefQualifierLoc, |
Sebastian Redl | 802a453 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 146 | ExceptionSpecificationType |
| 147 | ESpecType, |
| 148 | SourceLocation ESpecLoc, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 149 | ParsedType *Exceptions, |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 150 | SourceRange *ExceptionRanges, |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 151 | unsigned NumExceptions, |
Sebastian Redl | 802a453 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 152 | Expr *NoexceptExpr, |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 153 | SourceLocation LocalRangeBegin, |
| 154 | SourceLocation LocalRangeEnd, |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 155 | Declarator &TheDeclarator, |
| 156 | ParsedType TrailingReturnType) { |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 157 | DeclaratorChunk I; |
Sebastian Redl | 802a453 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 158 | I.Kind = Function; |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 159 | I.Loc = LocalRangeBegin; |
| 160 | I.EndLoc = LocalRangeEnd; |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 161 | I.Fun.AttrList = 0; |
Sebastian Redl | 802a453 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 162 | I.Fun.hasPrototype = hasProto; |
| 163 | I.Fun.isVariadic = isVariadic; |
| 164 | I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding(); |
| 165 | I.Fun.DeleteArgInfo = false; |
| 166 | I.Fun.TypeQuals = TypeQuals; |
| 167 | I.Fun.NumArgs = NumArgs; |
| 168 | I.Fun.ArgInfo = 0; |
Douglas Gregor | 5499235 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 169 | I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef; |
Sebastian Redl | 802a453 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 170 | I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding(); |
| 171 | I.Fun.ExceptionSpecType = ESpecType; |
| 172 | I.Fun.ExceptionSpecLoc = ESpecLoc.getRawEncoding(); |
| 173 | I.Fun.NumExceptions = 0; |
| 174 | I.Fun.Exceptions = 0; |
| 175 | I.Fun.NoexceptExpr = 0; |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 176 | I.Fun.TrailingReturnType = TrailingReturnType.getAsOpaquePtr(); |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 177 | |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 178 | // new[] an argument array if needed. |
| 179 | if (NumArgs) { |
| 180 | // If the 'InlineParams' in Declarator is unused and big enough, put our |
| 181 | // parameter list there (in an effort to avoid new/delete traffic). If it |
| 182 | // is already used (consider a function returning a function pointer) or too |
| 183 | // small (function taking too many arguments), go to the heap. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 | if (!TheDeclarator.InlineParamsUsed && |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 185 | NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) { |
| 186 | I.Fun.ArgInfo = TheDeclarator.InlineParams; |
| 187 | I.Fun.DeleteArgInfo = false; |
| 188 | TheDeclarator.InlineParamsUsed = true; |
| 189 | } else { |
| 190 | I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs]; |
| 191 | I.Fun.DeleteArgInfo = true; |
| 192 | } |
| 193 | memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs); |
| 194 | } |
Sebastian Redl | 802a453 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 195 | |
| 196 | // Check what exception specification information we should actually store. |
| 197 | switch (ESpecType) { |
| 198 | default: break; // By default, save nothing. |
| 199 | case EST_Dynamic: |
| 200 | // new[] an exception array if needed |
| 201 | if (NumExceptions) { |
| 202 | I.Fun.NumExceptions = NumExceptions; |
| 203 | I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions]; |
| 204 | for (unsigned i = 0; i != NumExceptions; ++i) { |
| 205 | I.Fun.Exceptions[i].Ty = Exceptions[i]; |
| 206 | I.Fun.Exceptions[i].Range = ExceptionRanges[i]; |
| 207 | } |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 208 | } |
Sebastian Redl | 802a453 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 209 | break; |
| 210 | |
| 211 | case EST_ComputedNoexcept: |
| 212 | I.Fun.NoexceptExpr = NoexceptExpr; |
| 213 | break; |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 214 | } |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 215 | return I; |
| 216 | } |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 217 | |
Douglas Gregor | c15b0cf | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 218 | bool Declarator::isDeclarationOfFunction() const { |
| 219 | if (isFunctionDeclarator()) |
| 220 | return true; |
| 221 | |
| 222 | switch (DS.getTypeSpecType()) { |
| 223 | case TST_auto: |
| 224 | case TST_bool: |
| 225 | case TST_char: |
| 226 | case TST_char16: |
| 227 | case TST_char32: |
| 228 | case TST_class: |
| 229 | case TST_decimal128: |
| 230 | case TST_decimal32: |
| 231 | case TST_decimal64: |
| 232 | case TST_double: |
| 233 | case TST_enum: |
| 234 | case TST_error: |
| 235 | case TST_float: |
| 236 | case TST_int: |
| 237 | case TST_struct: |
| 238 | case TST_union: |
| 239 | case TST_unknown_anytype: |
| 240 | case TST_unspecified: |
| 241 | case TST_void: |
| 242 | case TST_wchar: |
| 243 | return false; |
| 244 | |
| 245 | case TST_decltype: |
| 246 | case TST_typeofExpr: |
| 247 | if (Expr *E = DS.getRepAsExpr()) |
| 248 | return E->getType()->isFunctionType(); |
| 249 | return false; |
| 250 | |
| 251 | case TST_underlyingType: |
| 252 | case TST_typename: |
| 253 | case TST_typeofType: { |
| 254 | QualType QT = DS.getRepAsType().get(); |
| 255 | if (QT.isNull()) |
| 256 | return false; |
| 257 | |
| 258 | if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) |
| 259 | QT = LIT->getType(); |
| 260 | |
| 261 | if (QT.isNull()) |
| 262 | return false; |
| 263 | |
| 264 | return QT->isFunctionType(); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return false; |
| 269 | } |
| 270 | |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 271 | /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this |
Chris Lattner | e0c5116 | 2009-02-27 18:35:46 +0000 | [diff] [blame] | 272 | /// declaration specifier includes. |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 273 | /// |
| 274 | unsigned DeclSpec::getParsedSpecifiers() const { |
| 275 | unsigned Res = 0; |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 276 | if (StorageClassSpec != SCS_unspecified || |
| 277 | SCS_thread_specified) |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 278 | Res |= PQ_StorageClassSpecifier; |
Mike Stump | 65643c6 | 2008-06-19 19:52:46 +0000 | [diff] [blame] | 279 | |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 280 | if (TypeQualifiers != TQ_unspecified) |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 281 | Res |= PQ_TypeQualifier; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Chris Lattner | f055d43 | 2006-11-28 04:28:12 +0000 | [diff] [blame] | 283 | if (hasTypeSpecifier()) |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 284 | Res |= PQ_TypeSpecifier; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
Douglas Gregor | 61956c4 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 286 | if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified) |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 287 | Res |= PQ_FunctionSpecifier; |
| 288 | return Res; |
| 289 | } |
| 290 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 291 | template <class T> static bool BadSpecifier(T TNew, T TPrev, |
| 292 | const char *&PrevSpec, |
| 293 | unsigned &DiagID) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 294 | PrevSpec = DeclSpec::getSpecifierName(TPrev); |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 295 | DiagID = (TNew == TPrev ? diag::ext_duplicate_declspec |
| 296 | : diag::err_invalid_decl_spec_combination); |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 297 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 298 | } |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 299 | |
Chris Lattner | 7bd11fe | 2007-01-23 04:35:33 +0000 | [diff] [blame] | 300 | const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) { |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 301 | switch (S) { |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 302 | case DeclSpec::SCS_unspecified: return "unspecified"; |
| 303 | case DeclSpec::SCS_typedef: return "typedef"; |
| 304 | case DeclSpec::SCS_extern: return "extern"; |
| 305 | case DeclSpec::SCS_static: return "static"; |
| 306 | case DeclSpec::SCS_auto: return "auto"; |
| 307 | case DeclSpec::SCS_register: return "register"; |
Eli Friedman | d5c0eed | 2009-04-19 20:27:55 +0000 | [diff] [blame] | 308 | case DeclSpec::SCS_private_extern: return "__private_extern__"; |
Sebastian Redl | ccdfaba | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 309 | case DeclSpec::SCS_mutable: return "mutable"; |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 310 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 311 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 312 | } |
| 313 | |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 314 | const char *DeclSpec::getSpecifierName(TSW W) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 315 | switch (W) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 316 | case TSW_unspecified: return "unspecified"; |
| 317 | case TSW_short: return "short"; |
| 318 | case TSW_long: return "long"; |
| 319 | case TSW_longlong: return "long long"; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 320 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 321 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 322 | } |
| 323 | |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 324 | const char *DeclSpec::getSpecifierName(TSC C) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 325 | switch (C) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 326 | case TSC_unspecified: return "unspecified"; |
| 327 | case TSC_imaginary: return "imaginary"; |
| 328 | case TSC_complex: return "complex"; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 329 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 330 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 334 | const char *DeclSpec::getSpecifierName(TSS S) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 335 | switch (S) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 336 | case TSS_unspecified: return "unspecified"; |
| 337 | case TSS_signed: return "signed"; |
| 338 | case TSS_unsigned: return "unsigned"; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 339 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 340 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Chris Lattner | 69680ea | 2007-01-23 04:34:43 +0000 | [diff] [blame] | 343 | const char *DeclSpec::getSpecifierName(DeclSpec::TST T) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 344 | switch (T) { |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 345 | case DeclSpec::TST_unspecified: return "unspecified"; |
| 346 | case DeclSpec::TST_void: return "void"; |
| 347 | case DeclSpec::TST_char: return "char"; |
Argyrios Kyrtzidis | 40e9e48 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 348 | case DeclSpec::TST_wchar: return "wchar_t"; |
Alisdair Meredith | a9ad47d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 349 | case DeclSpec::TST_char16: return "char16_t"; |
| 350 | case DeclSpec::TST_char32: return "char32_t"; |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 351 | case DeclSpec::TST_int: return "int"; |
| 352 | case DeclSpec::TST_float: return "float"; |
| 353 | case DeclSpec::TST_double: return "double"; |
| 354 | case DeclSpec::TST_bool: return "_Bool"; |
| 355 | case DeclSpec::TST_decimal32: return "_Decimal32"; |
| 356 | case DeclSpec::TST_decimal64: return "_Decimal64"; |
| 357 | case DeclSpec::TST_decimal128: return "_Decimal128"; |
Chris Lattner | da72c82 | 2006-08-13 22:16:42 +0000 | [diff] [blame] | 358 | case DeclSpec::TST_enum: return "enum"; |
Chris Lattner | 861a226 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 359 | case DeclSpec::TST_class: return "class"; |
Chris Lattner | da72c82 | 2006-08-13 22:16:42 +0000 | [diff] [blame] | 360 | case DeclSpec::TST_union: return "union"; |
| 361 | case DeclSpec::TST_struct: return "struct"; |
Douglas Gregor | 9817f4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 362 | case DeclSpec::TST_typename: return "type-name"; |
Steve Naroff | ad373bd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 363 | case DeclSpec::TST_typeofType: |
| 364 | case DeclSpec::TST_typeofExpr: return "typeof"; |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 365 | case DeclSpec::TST_auto: return "auto"; |
| 366 | case DeclSpec::TST_decltype: return "(decltype)"; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 367 | case DeclSpec::TST_underlyingType: return "__underlying_type"; |
John McCall | 3943973 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 368 | case DeclSpec::TST_unknown_anytype: return "__unknown_anytype"; |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 369 | case DeclSpec::TST_error: return "(error)"; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 370 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 371 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 372 | } |
| 373 | |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 374 | const char *DeclSpec::getSpecifierName(TQ T) { |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 375 | switch (T) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 376 | case DeclSpec::TQ_unspecified: return "unspecified"; |
| 377 | case DeclSpec::TQ_const: return "const"; |
| 378 | case DeclSpec::TQ_restrict: return "restrict"; |
| 379 | case DeclSpec::TQ_volatile: return "volatile"; |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 380 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 381 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 382 | } |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 383 | |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 384 | bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 385 | const char *&PrevSpec, |
Peter Collingbourne | de32b20 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 386 | unsigned &DiagID, |
| 387 | const LangOptions &Lang) { |
| 388 | // OpenCL prohibits extern, auto, register, and static |
| 389 | // It seems sensible to prohibit private_extern too |
| 390 | if (Lang.OpenCL) { |
| 391 | switch (S) { |
| 392 | case SCS_extern: |
| 393 | case SCS_private_extern: |
| 394 | case SCS_auto: |
| 395 | case SCS_register: |
| 396 | case SCS_static: |
| 397 | DiagID = diag::err_not_opencl_storage_class_specifier; |
| 398 | PrevSpec = getSpecifierName(S); |
| 399 | return true; |
| 400 | default: |
| 401 | break; |
| 402 | } |
| 403 | } |
| 404 | |
Abramo Bagnara | ed5b689 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 405 | if (StorageClassSpec != SCS_unspecified) { |
| 406 | // Changing storage class is allowed only if the previous one |
| 407 | // was the 'extern' that is part of a linkage specification and |
| 408 | // the new storage class is 'typedef'. |
| 409 | if (!(SCS_extern_in_linkage_spec && |
| 410 | StorageClassSpec == SCS_extern && |
| 411 | S == SCS_typedef)) |
| 412 | return BadSpecifier(S, (SCS)StorageClassSpec, PrevSpec, DiagID); |
| 413 | } |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 414 | StorageClassSpec = S; |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 415 | StorageClassSpecLoc = Loc; |
Sebastian Redl | ccdfaba | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 416 | assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield"); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 417 | return false; |
| 418 | } |
| 419 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 421 | const char *&PrevSpec, |
| 422 | unsigned &DiagID) { |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 423 | if (SCS_thread_specified) { |
| 424 | PrevSpec = "__thread"; |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 425 | DiagID = diag::ext_duplicate_declspec; |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 426 | return true; |
| 427 | } |
| 428 | SCS_thread_specified = true; |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 429 | SCS_threadLoc = Loc; |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 430 | return false; |
| 431 | } |
| 432 | |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 433 | /// These methods set the specified attribute of the DeclSpec, but return true |
| 434 | /// and ignore the request if invalid (e.g. "extern" then "auto" is |
| 435 | /// specified). |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 436 | bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 437 | const char *&PrevSpec, |
| 438 | unsigned &DiagID) { |
Abramo Bagnara | ead67d9 | 2011-03-06 22:21:56 +0000 | [diff] [blame] | 439 | // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that |
| 440 | // for 'long long' we will keep the source location of the first 'long'. |
| 441 | if (TypeSpecWidth == TSW_unspecified) |
| 442 | TSWLoc = Loc; |
| 443 | // Allow turning long -> long long. |
| 444 | else if (W != TSW_longlong || TypeSpecWidth != TSW_long) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 445 | return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 446 | TypeSpecWidth = W; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 447 | if (TypeAltiVecVector && !TypeAltiVecBool && |
| 448 | ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 449 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 450 | DiagID = diag::warn_vector_long_decl_spec_combination; |
| 451 | return true; |
| 452 | } |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 453 | return false; |
| 454 | } |
| 455 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 456 | bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 457 | const char *&PrevSpec, |
| 458 | unsigned &DiagID) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 459 | if (TypeSpecComplex != TSC_unspecified) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 460 | return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 461 | TypeSpecComplex = C; |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 462 | TSCLoc = Loc; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 463 | return false; |
| 464 | } |
| 465 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 467 | const char *&PrevSpec, |
| 468 | unsigned &DiagID) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 469 | if (TypeSpecSign != TSS_unspecified) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 470 | return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID); |
Chris Lattner | deb42f5 | 2006-08-04 05:26:52 +0000 | [diff] [blame] | 471 | TypeSpecSign = S; |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 472 | TSSLoc = Loc; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 473 | return false; |
| 474 | } |
| 475 | |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 476 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 477 | const char *&PrevSpec, |
| 478 | unsigned &DiagID, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 479 | ParsedType Rep) { |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 480 | return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep); |
| 481 | } |
| 482 | |
| 483 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, |
| 484 | SourceLocation TagNameLoc, |
| 485 | const char *&PrevSpec, |
| 486 | unsigned &DiagID, |
| 487 | ParsedType Rep) { |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 488 | assert(isTypeRep(T) && "T does not store a type"); |
| 489 | assert(Rep && "no type provided!"); |
| 490 | if (TypeSpecType != TST_unspecified) { |
| 491 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 492 | DiagID = diag::err_invalid_decl_spec_combination; |
| 493 | return true; |
| 494 | } |
| 495 | TypeSpecType = T; |
| 496 | TypeRep = Rep; |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 497 | TSTLoc = TagKwLoc; |
| 498 | TSTNameLoc = TagNameLoc; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 499 | TypeSpecOwned = false; |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 504 | const char *&PrevSpec, |
| 505 | unsigned &DiagID, |
| 506 | Expr *Rep) { |
| 507 | assert(isExprRep(T) && "T does not store an expr"); |
| 508 | assert(Rep && "no expression provided!"); |
| 509 | if (TypeSpecType != TST_unspecified) { |
| 510 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 511 | DiagID = diag::err_invalid_decl_spec_combination; |
| 512 | return true; |
| 513 | } |
| 514 | TypeSpecType = T; |
| 515 | ExprRep = Rep; |
| 516 | TSTLoc = Loc; |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 517 | TSTNameLoc = Loc; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 518 | TypeSpecOwned = false; |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 523 | const char *&PrevSpec, |
| 524 | unsigned &DiagID, |
| 525 | Decl *Rep, bool Owned) { |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 526 | return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned); |
| 527 | } |
| 528 | |
| 529 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, |
| 530 | SourceLocation TagNameLoc, |
| 531 | const char *&PrevSpec, |
| 532 | unsigned &DiagID, |
| 533 | Decl *Rep, bool Owned) { |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 534 | assert(isDeclRep(T) && "T does not store a decl"); |
| 535 | // Unlike the other cases, we don't assert that we actually get a decl. |
| 536 | |
| 537 | if (TypeSpecType != TST_unspecified) { |
| 538 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 539 | DiagID = diag::err_invalid_decl_spec_combination; |
| 540 | return true; |
| 541 | } |
| 542 | TypeSpecType = T; |
| 543 | DeclRep = Rep; |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 544 | TSTLoc = TagKwLoc; |
| 545 | TSTNameLoc = TagNameLoc; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 546 | TypeSpecOwned = Owned; |
| 547 | return false; |
| 548 | } |
| 549 | |
| 550 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 551 | const char *&PrevSpec, |
| 552 | unsigned &DiagID) { |
| 553 | assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) && |
| 554 | "rep required for these type-spec kinds!"); |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 555 | if (TypeSpecType != TST_unspecified) { |
| 556 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 557 | DiagID = diag::err_invalid_decl_spec_combination; |
| 558 | return true; |
| 559 | } |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 560 | TSTLoc = Loc; |
| 561 | TSTNameLoc = Loc; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 562 | if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) { |
| 563 | TypeAltiVecBool = true; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 564 | return false; |
| 565 | } |
Chris Lattner | deb42f5 | 2006-08-04 05:26:52 +0000 | [diff] [blame] | 566 | TypeSpecType = T; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 567 | TypeSpecOwned = false; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 568 | if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 569 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 570 | DiagID = diag::err_invalid_vector_decl_spec; |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 571 | return true; |
| 572 | } |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, |
| 577 | const char *&PrevSpec, unsigned &DiagID) { |
| 578 | if (TypeSpecType != TST_unspecified) { |
| 579 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 580 | DiagID = diag::err_invalid_vector_decl_spec_combination; |
| 581 | return true; |
| 582 | } |
| 583 | TypeAltiVecVector = isAltiVecVector; |
| 584 | AltiVecLoc = Loc; |
| 585 | return false; |
| 586 | } |
| 587 | |
| 588 | bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, |
| 589 | const char *&PrevSpec, unsigned &DiagID) { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 590 | if (!TypeAltiVecVector || TypeAltiVecPixel || |
| 591 | (TypeSpecType != TST_unspecified)) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 592 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 593 | DiagID = diag::err_invalid_pixel_decl_spec_combination; |
| 594 | return true; |
| 595 | } |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 596 | TypeAltiVecPixel = isAltiVecPixel; |
| 597 | TSTLoc = Loc; |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 598 | TSTNameLoc = Loc; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 599 | return false; |
| 600 | } |
| 601 | |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 602 | bool DeclSpec::SetTypeSpecError() { |
| 603 | TypeSpecType = TST_error; |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 604 | TypeSpecOwned = false; |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 605 | TSTLoc = SourceLocation(); |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 606 | TSTNameLoc = SourceLocation(); |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 607 | return false; |
| 608 | } |
| 609 | |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 610 | bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 611 | unsigned &DiagID, const LangOptions &Lang) { |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 612 | // Duplicates turn into warnings pre-C99. |
| 613 | if ((TypeQualifiers & T) && !Lang.C99) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 614 | return BadSpecifier(T, T, PrevSpec, DiagID); |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 615 | TypeQualifiers |= T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 616 | |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 617 | switch (T) { |
| 618 | default: assert(0 && "Unknown type qualifier!"); |
| 619 | case TQ_const: TQ_constLoc = Loc; break; |
| 620 | case TQ_restrict: TQ_restrictLoc = Loc; break; |
| 621 | case TQ_volatile: TQ_volatileLoc = Loc; break; |
| 622 | } |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 623 | return false; |
| 624 | } |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 625 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 626 | bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, |
| 627 | unsigned &DiagID) { |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 628 | // 'inline inline' is ok. |
| 629 | FS_inline_specified = true; |
Chris Lattner | 1b22eed | 2006-11-28 05:12:07 +0000 | [diff] [blame] | 630 | FS_inlineLoc = Loc; |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 631 | return false; |
| 632 | } |
| 633 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 634 | bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, |
| 635 | unsigned &DiagID) { |
Douglas Gregor | 61956c4 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 636 | // 'virtual virtual' is ok. |
| 637 | FS_virtual_specified = true; |
| 638 | FS_virtualLoc = Loc; |
| 639 | return false; |
| 640 | } |
| 641 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 642 | bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, |
| 643 | unsigned &DiagID) { |
Douglas Gregor | 61956c4 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 644 | // 'explicit explicit' is ok. |
| 645 | FS_explicit_specified = true; |
| 646 | FS_explicitLoc = Loc; |
| 647 | return false; |
| 648 | } |
| 649 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 650 | bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, |
| 651 | unsigned &DiagID) { |
Anders Carlsson | cd8db41 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 652 | if (Friend_specified) { |
| 653 | PrevSpec = "friend"; |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 654 | DiagID = diag::ext_duplicate_declspec; |
Anders Carlsson | cd8db41 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 655 | return true; |
| 656 | } |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 657 | |
Anders Carlsson | cd8db41 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 658 | Friend_specified = true; |
| 659 | FriendLoc = Loc; |
| 660 | return false; |
| 661 | } |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 662 | |
Sebastian Redl | 39c2a8b | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 663 | bool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, |
| 664 | unsigned &DiagID) { |
| 665 | // 'constexpr constexpr' is ok. |
| 666 | Constexpr_specified = true; |
| 667 | ConstexprLoc = Loc; |
| 668 | return false; |
| 669 | } |
| 670 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 671 | void DeclSpec::setProtocolQualifiers(Decl * const *Protos, |
Argyrios Kyrtzidis | 5ec645b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 672 | unsigned NP, |
| 673 | SourceLocation *ProtoLocs, |
| 674 | SourceLocation LAngleLoc) { |
| 675 | if (NP == 0) return; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 676 | ProtocolQualifiers = new Decl*[NP]; |
Argyrios Kyrtzidis | 5ec645b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 677 | ProtocolLocs = new SourceLocation[NP]; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 678 | memcpy((void*)ProtocolQualifiers, Protos, sizeof(Decl*)*NP); |
Argyrios Kyrtzidis | 5ec645b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 679 | memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP); |
| 680 | NumProtocolQualifiers = NP; |
| 681 | ProtocolLAngleLoc = LAngleLoc; |
| 682 | } |
| 683 | |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 684 | void DeclSpec::SaveWrittenBuiltinSpecs() { |
| 685 | writtenBS.Sign = getTypeSpecSign(); |
| 686 | writtenBS.Width = getTypeSpecWidth(); |
| 687 | writtenBS.Type = getTypeSpecType(); |
| 688 | // Search the list of attributes for the presence of a mode attribute. |
| 689 | writtenBS.ModeAttr = false; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 690 | AttributeList* attrs = getAttributes().getList(); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 691 | while (attrs) { |
| 692 | if (attrs->getKind() == AttributeList::AT_mode) { |
| 693 | writtenBS.ModeAttr = true; |
| 694 | break; |
| 695 | } |
| 696 | attrs = attrs->getNext(); |
| 697 | } |
| 698 | } |
| 699 | |
Abramo Bagnara | ed5b689 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 700 | void DeclSpec::SaveStorageSpecifierAsWritten() { |
| 701 | if (SCS_extern_in_linkage_spec && StorageClassSpec == SCS_extern) |
| 702 | // If 'extern' is part of a linkage specification, |
| 703 | // then it is not a storage class "as written". |
| 704 | StorageClassSpecAsWritten = SCS_unspecified; |
| 705 | else |
| 706 | StorageClassSpecAsWritten = StorageClassSpec; |
| 707 | } |
| 708 | |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 709 | /// Finish - This does final analysis of the declspec, rejecting things like |
| 710 | /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or |
| 711 | /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method, |
| 712 | /// DeclSpec is guaranteed self-consistent, even if an error occurred. |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 713 | void DeclSpec::Finish(Diagnostic &D, Preprocessor &PP) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 714 | // Before possibly changing their values, save specs as written. |
| 715 | SaveWrittenBuiltinSpecs(); |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 716 | SaveStorageSpecifierAsWritten(); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 717 | |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 718 | // Check the type specifier components first. |
| 719 | |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 720 | // Validate and finalize AltiVec vector declspec. |
| 721 | if (TypeAltiVecVector) { |
| 722 | if (TypeAltiVecBool) { |
| 723 | // Sign specifiers are not allowed with vector bool. (PIM 2.1) |
| 724 | if (TypeSpecSign != TSS_unspecified) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 725 | Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 726 | << getSpecifierName((TSS)TypeSpecSign); |
| 727 | } |
| 728 | |
| 729 | // Only char/int are valid with vector bool. (PIM 2.1) |
Duncan Sands | d3e231e | 2010-06-23 19:34:52 +0000 | [diff] [blame] | 730 | if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) && |
| 731 | (TypeSpecType != TST_int)) || TypeAltiVecPixel) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 732 | Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 733 | << (TypeAltiVecPixel ? "__pixel" : |
| 734 | getSpecifierName((TST)TypeSpecType)); |
| 735 | } |
| 736 | |
| 737 | // Only 'short' is valid with vector bool. (PIM 2.1) |
| 738 | if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short)) |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 739 | Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 740 | << getSpecifierName((TSW)TypeSpecWidth); |
| 741 | |
| 742 | // Elements of vector bool are interpreted as unsigned. (PIM 2.1) |
| 743 | if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) || |
| 744 | (TypeSpecWidth != TSW_unspecified)) |
| 745 | TypeSpecSign = TSS_unsigned; |
| 746 | } |
| 747 | |
| 748 | if (TypeAltiVecPixel) { |
| 749 | //TODO: perform validation |
| 750 | TypeSpecType = TST_int; |
| 751 | TypeSpecSign = TSS_unsigned; |
| 752 | TypeSpecWidth = TSW_short; |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 753 | TypeSpecOwned = false; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
Argyrios Kyrtzidis | 40e9e48 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 757 | // signed/unsigned are only valid with int/char/wchar_t. |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 758 | if (TypeSpecSign != TSS_unspecified) { |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 759 | if (TypeSpecType == TST_unspecified) |
| 760 | TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. |
Argyrios Kyrtzidis | 40e9e48 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 761 | else if (TypeSpecType != TST_int && |
| 762 | TypeSpecType != TST_char && TypeSpecType != TST_wchar) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 763 | Diag(D, TSSLoc, diag::err_invalid_sign_spec) |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 764 | << getSpecifierName((TST)TypeSpecType); |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 765 | // signed double -> double. |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 766 | TypeSpecSign = TSS_unspecified; |
| 767 | } |
| 768 | } |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 769 | |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 770 | // Validate the width of the type. |
| 771 | switch (TypeSpecWidth) { |
| 772 | case TSW_unspecified: break; |
| 773 | case TSW_short: // short int |
| 774 | case TSW_longlong: // long long int |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 775 | if (TypeSpecType == TST_unspecified) |
| 776 | TypeSpecType = TST_int; // short -> short int, long long -> long long int. |
| 777 | else if (TypeSpecType != TST_int) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 778 | Diag(D, TSWLoc, |
Chris Lattner | 36982e4 | 2007-05-16 17:49:37 +0000 | [diff] [blame] | 779 | TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 780 | : diag::err_invalid_longlong_spec) |
| 781 | << getSpecifierName((TST)TypeSpecType); |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 782 | TypeSpecType = TST_int; |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 783 | TypeSpecOwned = false; |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 784 | } |
| 785 | break; |
| 786 | case TSW_long: // long double, long int |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 787 | if (TypeSpecType == TST_unspecified) |
| 788 | TypeSpecType = TST_int; // long -> long int. |
| 789 | else if (TypeSpecType != TST_int && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 790 | Diag(D, TSWLoc, diag::err_invalid_long_spec) |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 791 | << getSpecifierName((TST)TypeSpecType); |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 792 | TypeSpecType = TST_int; |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 793 | TypeSpecOwned = false; |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 794 | } |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 795 | break; |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 796 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 797 | |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 798 | // TODO: if the implementation does not implement _Complex or _Imaginary, |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 799 | // disallow their use. Need information about the backend. |
| 800 | if (TypeSpecComplex != TSC_unspecified) { |
| 801 | if (TypeSpecType == TST_unspecified) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 802 | Diag(D, TSCLoc, diag::ext_plain_complex) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 803 | << FixItHint::CreateInsertion( |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 804 | PP.getLocForEndOfToken(getTypeSpecComplexLoc()), |
| 805 | " double"); |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 806 | TypeSpecType = TST_double; // _Complex -> _Complex double. |
| 807 | } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) { |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 808 | // Note that this intentionally doesn't include _Complex _Bool. |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 809 | Diag(D, TSTLoc, diag::ext_integer_complex); |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 810 | } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 811 | Diag(D, TSCLoc, diag::err_invalid_complex_spec) |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 812 | << getSpecifierName((TST)TypeSpecType); |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 813 | TypeSpecComplex = TSC_unspecified; |
| 814 | } |
| 815 | } |
Chris Lattner | 8e90ef6 | 2006-08-05 03:30:45 +0000 | [diff] [blame] | 816 | |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 817 | // C++ [class.friend]p6: |
| 818 | // No storage-class-specifier shall appear in the decl-specifier-seq |
| 819 | // of a friend declaration. |
| 820 | if (isFriendSpecified() && getStorageClassSpec()) { |
| 821 | DeclSpec::SCS SC = getStorageClassSpec(); |
| 822 | const char *SpecName = getSpecifierName(SC); |
| 823 | |
| 824 | SourceLocation SCLoc = getStorageClassSpecLoc(); |
| 825 | SourceLocation SCEndLoc = SCLoc.getFileLocWithOffset(strlen(SpecName)); |
| 826 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 827 | Diag(D, SCLoc, diag::err_friend_storage_spec) |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 828 | << SpecName |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 829 | << FixItHint::CreateRemoval(SourceRange(SCLoc, SCEndLoc)); |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 830 | |
| 831 | ClearStorageClassSpecs(); |
| 832 | } |
| 833 | |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 834 | assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType)); |
| 835 | |
Chris Lattner | 8e90ef6 | 2006-08-05 03:30:45 +0000 | [diff] [blame] | 836 | // Okay, now we can infer the real type. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 838 | // TODO: return "auto function" and other bad things based on the real type. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | |
Chris Lattner | 1ae2329 | 2006-08-04 06:42:31 +0000 | [diff] [blame] | 840 | // 'data definition has no type or storage class'? |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 841 | } |
Daniel Dunbar | c74b5cc | 2008-08-11 03:45:03 +0000 | [diff] [blame] | 842 | |
Sebastian Redl | a2b5e31 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 843 | bool DeclSpec::isMissingDeclaratorOk() { |
| 844 | TST tst = getTypeSpecType(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 845 | return isDeclRep(tst) && getRepAsDecl() != 0 && |
| 846 | StorageClassSpec != DeclSpec::SCS_typedef; |
Sebastian Redl | a2b5e31 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 847 | } |
Douglas Gregor | 7861a80 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 848 | |
| 849 | void UnqualifiedId::clear() { |
Douglas Gregor | 7861a80 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 850 | Kind = IK_Identifier; |
| 851 | Identifier = 0; |
| 852 | StartLocation = SourceLocation(); |
| 853 | EndLocation = SourceLocation(); |
| 854 | } |
| 855 | |
| 856 | void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc, |
| 857 | OverloadedOperatorKind Op, |
| 858 | SourceLocation SymbolLocations[3]) { |
| 859 | Kind = IK_OperatorFunctionId; |
| 860 | StartLocation = OperatorLoc; |
| 861 | EndLocation = OperatorLoc; |
| 862 | OperatorFunctionId.Operator = Op; |
| 863 | for (unsigned I = 0; I != 3; ++I) { |
| 864 | OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding(); |
| 865 | |
| 866 | if (SymbolLocations[I].isValid()) |
| 867 | EndLocation = SymbolLocations[I]; |
| 868 | } |
| 869 | } |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 870 | |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 871 | bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc, |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 872 | const char *&PrevSpec) { |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 873 | LastLocation = Loc; |
| 874 | |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 875 | if (Specifiers & VS) { |
| 876 | PrevSpec = getSpecifierName(VS); |
| 877 | return true; |
| 878 | } |
| 879 | |
| 880 | Specifiers |= VS; |
| 881 | |
| 882 | switch (VS) { |
| 883 | default: assert(0 && "Unknown specifier!"); |
| 884 | case VS_Override: VS_overrideLoc = Loc; break; |
| 885 | case VS_Final: VS_finalLoc = Loc; break; |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 886 | } |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 887 | |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 888 | return false; |
| 889 | } |
| 890 | |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 891 | const char *VirtSpecifiers::getSpecifierName(Specifier VS) { |
Anders Carlsson | a6d3501 | 2011-01-22 15:11:37 +0000 | [diff] [blame] | 892 | switch (VS) { |
| 893 | default: assert(0 && "Unknown specifier"); |
| 894 | case VS_Override: return "override"; |
| 895 | case VS_Final: return "final"; |
Anders Carlsson | a6d3501 | 2011-01-22 15:11:37 +0000 | [diff] [blame] | 896 | } |
| 897 | } |