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