Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements semantic analysis for declaration specifiers. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
John McCall | 1951085 | 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 | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 16 | #include "clang/Sema/LocInfoType.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 19 | #include "clang/AST/Expr.h" |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 20 | #include "clang/AST/NestedNameSpecifier.h" |
| 21 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 22 | #include "clang/Lex/Preprocessor.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 23 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/STLExtras.h" |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 26 | #include <cstring> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 27 | using namespace clang; |
| 28 | |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 29 | |
| 30 | static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc, |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 31 | unsigned DiagID) { |
| 32 | return D.Report(Loc, DiagID); |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Douglas Gregor | 314b97f | 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 | 0efc2c1 | 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 | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 52 | void CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc, |
| 53 | TypeLoc TL, SourceLocation ColonColonLoc) { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 54 | Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc); |
Douglas Gregor | 2e4c34a | 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 | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 58 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 59 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 60 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 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 | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 66 | Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc); |
| 67 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 68 | if (Range.getBegin().isInvalid()) |
| 69 | Range.setBegin(IdentifierLoc); |
| 70 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 72 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 73 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 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 | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 79 | Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc); |
| 80 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 81 | if (Range.getBegin().isInvalid()) |
| 82 | Range.setBegin(NamespaceLoc); |
| 83 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 84 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 85 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 86 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Douglas Gregor | 14aba76 | 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 | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 92 | Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc); |
| 93 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 94 | if (Range.getBegin().isInvalid()) |
| 95 | Range.setBegin(AliasLoc); |
| 96 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 97 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 98 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 99 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 102 | void CXXScopeSpec::MakeGlobal(ASTContext &Context, |
| 103 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 104 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 105 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 106 | Range = SourceRange(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 107 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 108 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 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 | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 114 | Builder.MakeTrivial(Context, Qualifier, R); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 115 | Range = R; |
Douglas Gregor | c34348a | 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 | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 121 | Builder.Clear(); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 122 | return; |
| 123 | } |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 125 | Range = Other.getSourceRange(); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 126 | Builder.Adopt(Other); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 129 | NestedNameSpecifierLoc |
| 130 | CXXScopeSpec::getWithLocInContext(ASTContext &Context) const { |
Douglas Gregor | b46ae39 | 2011-03-03 21:48:55 +0000 | [diff] [blame] | 131 | if (!Builder.getRepresentation()) |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 132 | return NestedNameSpecifierLoc(); |
| 133 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 134 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Chris Lattner | 5af2f35 | 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 | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 139 | DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic, |
Douglas Gregor | 965acbb | 2009-02-18 07:07:28 +0000 | [diff] [blame] | 140 | SourceLocation EllipsisLoc, |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 141 | ParamInfo *ArgInfo, |
| 142 | unsigned NumArgs, |
| 143 | unsigned TypeQuals, |
Douglas Gregor | 83f5172 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 144 | bool RefQualifierIsLvalueRef, |
| 145 | SourceLocation RefQualifierLoc, |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 146 | ExceptionSpecificationType |
| 147 | ESpecType, |
| 148 | SourceLocation ESpecLoc, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 149 | ParsedType *Exceptions, |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 150 | SourceRange *ExceptionRanges, |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 151 | unsigned NumExceptions, |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 152 | Expr *NoexceptExpr, |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 153 | SourceLocation LocalRangeBegin, |
| 154 | SourceLocation LocalRangeEnd, |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 155 | Declarator &TheDeclarator, |
| 156 | ParsedType TrailingReturnType) { |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 157 | DeclaratorChunk I; |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 158 | I.Kind = Function; |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 159 | I.Loc = LocalRangeBegin; |
| 160 | I.EndLoc = LocalRangeEnd; |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 161 | I.Fun.AttrList = 0; |
Sebastian Redl | 6e5d319 | 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 | 83f5172 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 169 | I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef; |
Sebastian Redl | 6e5d319 | 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 | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 176 | I.Fun.TrailingReturnType = TrailingReturnType.getAsOpaquePtr(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 177 | |
Chris Lattner | 5af2f35 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 | if (!TheDeclarator.InlineParamsUsed && |
Chris Lattner | 5af2f35 | 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 | 6e5d319 | 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 | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 208 | } |
Sebastian Redl | 6e5d319 | 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 | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 214 | } |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 215 | return I; |
| 216 | } |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 217 | |
Douglas Gregor | 555f57e | 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 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 271 | /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this |
Chris Lattner | 2a327d1 | 2009-02-27 18:35:46 +0000 | [diff] [blame] | 272 | /// declaration specifier includes. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 273 | /// |
| 274 | unsigned DeclSpec::getParsedSpecifiers() const { |
| 275 | unsigned Res = 0; |
| 276 | if (StorageClassSpec != SCS_unspecified || |
| 277 | SCS_thread_specified) |
| 278 | Res |= PQ_StorageClassSpecifier; |
Mike Stump | d420433 | 2008-06-19 19:52:46 +0000 | [diff] [blame] | 279 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 280 | if (TypeQualifiers != TQ_unspecified) |
| 281 | Res |= PQ_TypeQualifier; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 283 | if (hasTypeSpecifier()) |
| 284 | Res |= PQ_TypeSpecifier; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 286 | if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 287 | Res |= PQ_FunctionSpecifier; |
| 288 | return Res; |
| 289 | } |
| 290 | |
John McCall | fec5401 | 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 | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 294 | PrevSpec = DeclSpec::getSpecifierName(TPrev); |
John McCall | fec5401 | 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 | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 297 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 298 | } |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 299 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 300 | const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) { |
| 301 | switch (S) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +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 | 63054b3 | 2009-04-19 20:27:55 +0000 | [diff] [blame] | 308 | case DeclSpec::SCS_private_extern: return "__private_extern__"; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 309 | case DeclSpec::SCS_mutable: return "mutable"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 310 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 311 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 312 | } |
| 313 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 314 | const char *DeclSpec::getSpecifierName(TSW W) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 315 | switch (W) { |
John McCall | 32d335e | 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"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 320 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 321 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 322 | } |
| 323 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 324 | const char *DeclSpec::getSpecifierName(TSC C) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 325 | switch (C) { |
John McCall | 32d335e | 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"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 329 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 330 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 334 | const char *DeclSpec::getSpecifierName(TSS S) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 335 | switch (S) { |
John McCall | 32d335e | 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"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 339 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 340 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | const char *DeclSpec::getSpecifierName(DeclSpec::TST T) { |
| 344 | switch (T) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +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 | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 348 | case DeclSpec::TST_wchar: return "wchar_t"; |
Alisdair Meredith | f5c209d | 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"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +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"; |
| 358 | case DeclSpec::TST_enum: return "enum"; |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 359 | case DeclSpec::TST_class: return "class"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 360 | case DeclSpec::TST_union: return "union"; |
| 361 | case DeclSpec::TST_struct: return "struct"; |
Douglas Gregor | 1a51b4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 362 | case DeclSpec::TST_typename: return "type-name"; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 363 | case DeclSpec::TST_typeofType: |
| 364 | case DeclSpec::TST_typeofExpr: return "typeof"; |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 365 | case DeclSpec::TST_auto: return "auto"; |
| 366 | case DeclSpec::TST_decltype: return "(decltype)"; |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 367 | case DeclSpec::TST_underlyingType: return "__underlying_type"; |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 368 | case DeclSpec::TST_unknown_anytype: return "__unknown_anytype"; |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 369 | case DeclSpec::TST_error: return "(error)"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 370 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 371 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 372 | } |
| 373 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 374 | const char *DeclSpec::getSpecifierName(TQ T) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 375 | switch (T) { |
John McCall | 32d335e | 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"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 380 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 381 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 385 | const char *&PrevSpec, |
Peter Collingbourne | e2f82f7 | 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 | 35f9a19 | 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 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 414 | StorageClassSpec = S; |
| 415 | StorageClassSpecLoc = Loc; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 416 | assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 417 | return false; |
| 418 | } |
| 419 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 421 | const char *&PrevSpec, |
| 422 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 423 | if (SCS_thread_specified) { |
| 424 | PrevSpec = "__thread"; |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 425 | DiagID = diag::ext_duplicate_declspec; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 426 | return true; |
| 427 | } |
| 428 | SCS_thread_specified = true; |
| 429 | SCS_threadLoc = Loc; |
| 430 | return false; |
| 431 | } |
| 432 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +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). |
| 436 | bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 437 | const char *&PrevSpec, |
| 438 | unsigned &DiagID) { |
Abramo Bagnara | 2553eaf | 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 | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 445 | return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 446 | TypeSpecWidth = W; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 447 | if (TypeAltiVecVector && !TypeAltiVecBool && |
| 448 | ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) { |
John Thompson | 82287d1 | 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 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 453 | return false; |
| 454 | } |
| 455 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 456 | bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 457 | const char *&PrevSpec, |
| 458 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 459 | if (TypeSpecComplex != TSC_unspecified) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 460 | return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 461 | TypeSpecComplex = C; |
| 462 | TSCLoc = Loc; |
| 463 | return false; |
| 464 | } |
| 465 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 467 | const char *&PrevSpec, |
| 468 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 469 | if (TypeSpecSign != TSS_unspecified) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 470 | return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 471 | TypeSpecSign = S; |
| 472 | TSSLoc = Loc; |
| 473 | return false; |
| 474 | } |
| 475 | |
| 476 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 477 | const char *&PrevSpec, |
| 478 | unsigned &DiagID, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 479 | ParsedType Rep) { |
Abramo Bagnara | 0daaf32 | 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 | b3d8748 | 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 | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 497 | TSTLoc = TagKwLoc; |
| 498 | TSTNameLoc = TagNameLoc; |
John McCall | b3d8748 | 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 | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 517 | TSTNameLoc = Loc; |
John McCall | b3d8748 | 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 | 0daaf32 | 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 | b3d8748 | 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 | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 544 | TSTLoc = TagKwLoc; |
| 545 | TSTNameLoc = TagNameLoc; |
John McCall | b3d8748 | 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 | fec5401 | 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 | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 560 | TSTLoc = Loc; |
| 561 | TSTNameLoc = Loc; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 562 | if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) { |
| 563 | TypeAltiVecBool = true; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 564 | return false; |
| 565 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 566 | TypeSpecType = T; |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 567 | TypeSpecOwned = false; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 568 | if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 569 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 570 | DiagID = diag::err_invalid_vector_decl_spec; |
John Thompson | 82287d1 | 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 | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 590 | if (!TypeAltiVecVector || TypeAltiVecPixel || |
| 591 | (TypeSpecType != TST_unspecified)) { |
John Thompson | 82287d1 | 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 | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 596 | TypeAltiVecPixel = isAltiVecPixel; |
| 597 | TSTLoc = Loc; |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 598 | TSTNameLoc = Loc; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 599 | return false; |
| 600 | } |
| 601 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 602 | bool DeclSpec::SetTypeSpecError() { |
| 603 | TypeSpecType = TST_error; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 604 | TypeSpecOwned = false; |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 605 | TSTLoc = SourceLocation(); |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 606 | TSTNameLoc = SourceLocation(); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 607 | return false; |
| 608 | } |
| 609 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 610 | bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 611 | unsigned &DiagID, const LangOptions &Lang) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 612 | // Duplicates turn into warnings pre-C99. |
| 613 | if ((TypeQualifiers & T) && !Lang.C99) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 614 | return BadSpecifier(T, T, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 615 | TypeQualifiers |= T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 616 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +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 | } |
| 623 | return false; |
| 624 | } |
| 625 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 626 | bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, |
| 627 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 628 | // 'inline inline' is ok. |
| 629 | FS_inline_specified = true; |
| 630 | FS_inlineLoc = Loc; |
| 631 | return false; |
| 632 | } |
| 633 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 634 | bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, |
| 635 | unsigned &DiagID) { |
Douglas Gregor | b48fe38 | 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 | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 642 | bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, |
| 643 | unsigned &DiagID) { |
Douglas Gregor | b48fe38 | 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 | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 650 | bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, |
| 651 | unsigned &DiagID) { |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 652 | if (Friend_specified) { |
| 653 | PrevSpec = "friend"; |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 654 | DiagID = diag::ext_duplicate_declspec; |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 655 | return true; |
| 656 | } |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 657 | |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 658 | Friend_specified = true; |
| 659 | FriendLoc = Loc; |
| 660 | return false; |
| 661 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 662 | |
Sebastian Redl | 2ac6723 | 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 | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 671 | void DeclSpec::setProtocolQualifiers(Decl * const *Protos, |
Argyrios Kyrtzidis | e3a535b | 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 | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 676 | ProtocolQualifiers = new Decl*[NP]; |
Argyrios Kyrtzidis | e3a535b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 677 | ProtocolLocs = new SourceLocation[NP]; |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 678 | memcpy((void*)ProtocolQualifiers, Protos, sizeof(Decl*)*NP); |
Argyrios Kyrtzidis | e3a535b | 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 | ddf889a | 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 | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 690 | AttributeList* attrs = getAttributes().getList(); |
Douglas Gregor | ddf889a | 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 | 35f9a19 | 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 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +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 | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 713 | void DeclSpec::Finish(Diagnostic &D, Preprocessor &PP) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 714 | // Before possibly changing their values, save specs as written. |
| 715 | SaveWrittenBuiltinSpecs(); |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 716 | SaveStorageSpecifierAsWritten(); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 717 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 718 | // Check the type specifier components first. |
| 719 | |
Chris Lattner | 788b0fd | 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 | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 725 | Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 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 | 2e964a92 | 2010-06-23 19:34:52 +0000 | [diff] [blame] | 730 | if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) && |
| 731 | (TypeSpecType != TST_int)) || TypeAltiVecPixel) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 732 | Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 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 | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 739 | Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 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 | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 753 | TypeSpecOwned = false; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 757 | // signed/unsigned are only valid with int/char/wchar_t. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 758 | if (TypeSpecSign != TSS_unspecified) { |
| 759 | if (TypeSpecType == TST_unspecified) |
| 760 | TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 761 | else if (TypeSpecType != TST_int && |
| 762 | TypeSpecType != TST_char && TypeSpecType != TST_wchar) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 763 | Diag(D, TSSLoc, diag::err_invalid_sign_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 764 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 765 | // signed double -> double. |
| 766 | TypeSpecSign = TSS_unspecified; |
| 767 | } |
| 768 | } |
| 769 | |
| 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 |
| 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 | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 778 | Diag(D, TSWLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 779 | TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 780 | : diag::err_invalid_longlong_spec) |
| 781 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 782 | TypeSpecType = TST_int; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 783 | TypeSpecOwned = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 784 | } |
| 785 | break; |
| 786 | case TSW_long: // long double, long int |
| 787 | if (TypeSpecType == TST_unspecified) |
| 788 | TypeSpecType = TST_int; // long -> long int. |
| 789 | else if (TypeSpecType != TST_int && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 790 | Diag(D, TSWLoc, diag::err_invalid_long_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 791 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 792 | TypeSpecType = TST_int; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 793 | TypeSpecOwned = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 794 | } |
| 795 | break; |
| 796 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 797 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 798 | // TODO: if the implementation does not implement _Complex or _Imaginary, |
| 799 | // disallow their use. Need information about the backend. |
| 800 | if (TypeSpecComplex != TSC_unspecified) { |
| 801 | if (TypeSpecType == TST_unspecified) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 802 | Diag(D, TSCLoc, diag::ext_plain_complex) |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 803 | << FixItHint::CreateInsertion( |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 804 | PP.getLocForEndOfToken(getTypeSpecComplexLoc()), |
| 805 | " double"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 806 | TypeSpecType = TST_double; // _Complex -> _Complex double. |
| 807 | } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) { |
| 808 | // Note that this intentionally doesn't include _Complex _Bool. |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 809 | Diag(D, TSTLoc, diag::ext_integer_complex); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 810 | } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 811 | Diag(D, TSCLoc, diag::err_invalid_complex_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 812 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 813 | TypeSpecComplex = TSC_unspecified; |
| 814 | } |
| 815 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 816 | |
John McCall | 67d1a67 | 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 | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 827 | Diag(D, SCLoc, diag::err_friend_storage_spec) |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 828 | << SpecName |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 829 | << FixItHint::CreateRemoval(SourceRange(SCLoc, SCEndLoc)); |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 830 | |
| 831 | ClearStorageClassSpecs(); |
| 832 | } |
| 833 | |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 834 | assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType)); |
| 835 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 836 | // Okay, now we can infer the real type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 838 | // TODO: return "auto function" and other bad things based on the real type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 840 | // 'data definition has no type or storage class'? |
| 841 | } |
Daniel Dunbar | e4858a6 | 2008-08-11 03:45:03 +0000 | [diff] [blame] | 842 | |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 843 | bool DeclSpec::isMissingDeclaratorOk() { |
| 844 | TST tst = getTypeSpecType(); |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 845 | return isDeclRep(tst) && getRepAsDecl() != 0 && |
| 846 | StorageClassSpec != DeclSpec::SCS_typedef; |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 847 | } |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 848 | |
| 849 | void UnqualifiedId::clear() { |
Douglas Gregor | 3f9a056 | 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 | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 870 | |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 871 | bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc, |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 872 | const char *&PrevSpec) { |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 873 | LastLocation = Loc; |
| 874 | |
Anders Carlsson | b971dbd | 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 | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 886 | } |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 887 | |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 888 | return false; |
| 889 | } |
| 890 | |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 891 | const char *VirtSpecifiers::getSpecifierName(Specifier VS) { |
Anders Carlsson | c46bb7d | 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 | c46bb7d | 2011-01-22 15:11:37 +0000 | [diff] [blame] | 896 | } |
| 897 | } |